Project

General

Profile

« Previous | Next » 

Revision f8878229

Added by Partha Aji about 10 years ago

Code for Org Create orchestration

View differences:

app/lib/actions/candlepin/environment/create.rb
#
# Copyright 2014 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public
# License as published by the Free Software Foundation; either version
# 2 of the License (GPLv2) or (at your option) any later version.
# There is NO WARRANTY for this software, express or implied,
# including the implied warranties of MERCHANTABILITY,
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
# have received a copy of GPLv2 along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
module Actions
module Candlepin
module Environment
class Create < Candlepin::Abstract
input_format do
param :organization_label
param :cp_id
param :name
param :description
end
def run
::Katello::Resources::Candlepin::Environment.create(input['organization_label'],
input['cp_id'],
input['name'],
input['description'])
end
end
end
end
end
app/lib/actions/candlepin/owner/create.rb
#
# Copyright 2014 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public
# License as published by the Free Software Foundation; either version
# 2 of the License (GPLv2) or (at your option) any later version.
# There is NO WARRANTY for this software, express or implied,
# including the implied warranties of MERCHANTABILITY,
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
# have received a copy of GPLv2 along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
module Actions
module Candlepin
module Owner
class Create < Candlepin::Abstract
input_format do
param :name
param :label
end
def run
output[:response] = ::Katello::Resources::Candlepin::Owner.create(input[:label], input[:name])
end
end
end
end
end
app/lib/actions/headpin/content_view/create.rb
#
# Copyright 2013 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public
# License as published by the Free Software Foundation; either version
# 2 of the License (GPLv2) or (at your option) any later version.
# There is NO WARRANTY for this software, express or implied,
# including the implied warranties of MERCHANTABILITY,
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
# have received a copy of GPLv2 along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
module Actions
module Headpin
module ContentView
class Create < Actions::Base
def plan(content_view)
content_view.disable_auto_reindex! if ::Katello.config.use_elasticsearch
content_view.save!
plan_action(ElasticSearch::Reindex, content_view) if ::Katello.config.use_elasticsearch
end
def humanized_name
_("Create")
end
end
end
end
end
app/lib/actions/headpin/content_view/environment_create.rb
#
# Copyright 2013 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public
# License as published by the Free Software Foundation; either version
# 2 of the License (GPLv2) or (at your option) any later version.
# There is NO WARRANTY for this software, express or implied,
# including the implied warranties of MERCHANTABILITY,
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
# have received a copy of GPLv2 along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
module Actions
module Headpin
module ContentView
class EnvironmentCreate < Actions::Base
def plan(content_view_environment)
content_view_environment.save!
if ::Katello.config.use_cp
content_view = content_view_environment.content_view
plan_action(Candlepin::Environment::Create,
'organization_label' => content_view.organization.label,
'cp_id' => content_view_environment.cp_id,
'name' => content_view_environment.label,
'description' => content_view.description)
end
end
def humanized_name
_("Create")
end
end
end
end
end
app/lib/actions/headpin/environment/library_create.rb
#
# Copyright 2013 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public
# License as published by the Free Software Foundation; either version
# 2 of the License (GPLv2) or (at your option) any later version.
# There is NO WARRANTY for this software, express or implied,
# including the implied warranties of MERCHANTABILITY,
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
# have received a copy of GPLv2 along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
module Actions
module Headpin
module Environment
class LibraryCreate < Actions::Base
def plan(library_env)
library_env.save!
library_view = ::Katello::ContentView.create!(:default => true,
:name => "Default Organization View",
:organization => library_env.organization)
library_view_env = library_view.add_environment(library_env)
::Katello::ContentViewVersion.create! do |v|
v.content_view = library_view
v.version = 1
v.content_view_version_environments.build(:environment => library_env)
end
plan_action(Headpin::ContentView::Create, library_view)
plan_action(Headpin::ContentView::EnvironmentCreate, library_view_env)
end
def humanized_name
_("Create")
end
input_format do
param :name, String
param :label, String
param :organization_label, String
end
end
end
end
end
app/lib/actions/headpin/organization/create.rb
#
# Copyright 2014 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public
# License as published by the Free Software Foundation; either version
# 2 of the License (GPLv2) or (at your option) any later version.
# There is NO WARRANTY for this software, express or implied,
# including the implied warranties of MERCHANTABILITY,
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
# have received a copy of GPLv2 along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
module Actions
module Headpin
module Organization
class Create < Actions::EntryAction
def plan(organization)
organization.disable_auto_reindex! if ::Katello.config.use_elasticsearch
cp_create = nil
sequence do
if ::Katello.config.use_cp
cp_create = plan_action(Candlepin::Owner::Create,
label: organization.label,
name: organization.name)
end
organization.providers.first.save!
plan_action(Environment::LibraryCreate, organization.library)
organization.save!
end
if cp_create
action_subject organization, label: cp_create.output[:response][:key]
else
action_subject organization
end
plan_action(ElasticSearch::Reindex, organization) if ::Katello.config.use_elasticsearch
end
def humanized_name
_("Create")
end
end
end
end
end
app/models/katello/concerns/organization_extensions.rb
include Glue::Candlepin::Owner if Katello.config.use_cp
include Glue if Katello.config.use_cp
include Glue::Event
def create_event
Headpin::Actions::OrgCreate
end
def destroy_event
Headpin::Actions::OrgDestroy
def create_action
sync_action!
::Actions::Headpin::Organization::Create
end
include AsyncOrchestration
app/models/katello/content_view.rb
include Authorization::ContentView
include Glue::ElasticSearch::ContentView if Katello.config.use_elasticsearch
include Glue::Event
def create_event
Katello::Actions::ContentViewCreate
end
before_destroy :confirm_not_promoted # RAILS3458: this needs to come before associations
belongs_to :content_view_definition, :class_name => "Katello::ContentViewDefinition", :inverse_of => :content_views
app/models/katello/content_view_definition.rb
version = ContentViewVersion.new(:version => 1, :content_view => view)
version.environments << organization.library
version.save!
ForemanTasks.sync_task(::Actions::Headpin::ContentView::Create, view)
if options[:async]
async_task = self.async(:organization => self.organization,
app/models/katello/content_view_environment.rb
class ContentViewEnvironment < Katello::Model
self.include_root_in_json = false
include ForemanTasks::Concerns::ActionSubject
include Glue::Candlepin::Environment if Katello.config.use_cp
include Glue if Katello.config.use_cp
app/models/katello/content_view_version.rb
private
def add_environment(env)
content_view.add_environment(env) if content_view.content_view_versions.in_environment(env).count == 0
if content_view.content_view_versions.in_environment(env).empty?
env = content_view.add_environment(env)
ForemanTasks.sync_task(::Actions::Headpin::ContentView::EnvironmentCreate, env)
end
end
def remove_environment(env)
app/models/katello/glue/candlepin/environment.rb
base.send :include, InstanceMethods
base.class_eval do
before_save :save_environment_orchestration
before_destroy :destroy_environment_orchestration
end
end
module InstanceMethods
def set_environment
Resources::Candlepin::Environment.find(self.cp_id)
Rails.logger.info _("Candlepin environment already exists: %s") % self.cp_id
true
rescue RestClient::ResourceNotFound
Rails.logger.info _("Creating environment in candlepin: %s") % self.label
Resources::Candlepin::Environment.create(self.content_view.organization.label, self.cp_id, self.label,
self.content_view.description)
true
rescue => e
Rails.logger.error _("Failed to create candlepin environment %s") %
"#{self.label}: #{e}, #{e.backtrace.join("\n")}"
fail e
end
def candlepin_info
Resources::Candlepin::Environment.find(self.cp_id)
end
......
fail e
end
def save_environment_orchestration
case self.orchestration_for
when :create
post_queue.create(:name => "candlepin environment for content view: #{self.content_view.label}",
:priority => 3,
:action => [self, :set_environment])
end
end
def destroy_environment_orchestration
post_queue.create(:name => "candlepin environment for content view: #{self.content_view.label}",
:priority => 4,
app/models/katello/glue/candlepin/owner.rb
base.send :include, InstanceMethods
base.class_eval do
before_save :save_owner_orchestration
before_destroy :destroy_owner_orchestration
validates :label,
......
hash
end
def set_owner
Rails.logger.debug _("Creating an owner in candlepin: %s") % name
Katello::Resources::Candlepin::Owner.create(label, name)
rescue => e
Rails.logger.error _("Failed to create candlepin owner %s") % "#{name}: #{e}, #{e.backtrace.join("\n")}"
raise e
end
def del_owner
Rails.logger.debug _("Deleting owner in candlepin: %s") % name
Resources::Candlepin::Owner.destroy(label)
......
raise e
end
def save_owner_orchestration
case self.orchestration_for
when :create
pre_queue.create(:name => "candlepin owner for organization: #{self.name}", :priority => 3, :action => [self, :set_owner])
end
end
def destroy_owner_orchestration
pre_queue.create(:name => "candlepin systems for organization: #{self.name}", :priority => 2, :action => [self, :del_systems])
pre_queue.create(:name => "candlepin providers for organization: #{self.name}", :priority => 3, :action => [self, :del_providers])
app/models/katello/kt_environment.rb
module Katello
class KTEnvironment < Katello::Model
self.include_root_in_json = false
include Authorization::Environment
include Glue::ElasticSearch::Environment if Katello.config.use_elasticsearch
include Glue if Katello.config.use_cp || Katello.config.use_pulp
include Glue::Event
def create_event
Katello::Actions::EnvironmentCreate
end
def destroy_event
Katello::Actions::EnvironmentDestroy
end
self.table_name = "katello_environments"
include Ext::LabelFromName
include Ext::PermissionTagCleanup
......
validates_with Validators::PriorValidator
validates_with Validators::PathDescendentsValidator
after_create :create_default_content_view_version
after_destroy :unset_users_with_default
ERROR_CLASS_NAME = "Environment"
......
end
end
def create_default_content_view_version
if library?
# Sadly this has to be created here, if it is created in the org
# it will not actually exist when we go to create library and so
# we can't look it up via a query (org.default_content_view)
content_view = self.organization.default_content_view
if content_view.nil?
content_view = Katello::ContentView.new(:default => true, :name => "Default Organization View",
:organization => self.organization)
end
if content_view.version(self).nil?
version = ContentViewVersion.new(:content_view => content_view,
:version => 1)
version.environments << self
version.save!
content_view.save! #save content_view, since ContentViewEnvironment was added
end
end
end
def delete_core_environments
# For each content view associated with this lifecycle environment, there may be
# a puppet environment (in the core/Foreman), so let's delete those
spec/helpers/application_info_helper_spec.rb
context '.can_read_system_info?' do
before(:each) do
Resources::Candlepin::Owner.stubs(:create_user).returns(true)
Resources::Candlepin::Owner.expects(:create).once.returns({})
disable_env_orchestration
disable_user_orchestration
Organization.any_instance.stubs(:ensure_not_in_transaction!)
Resources::Candlepin::Owner.expects(:create).once.returns({})
::Actions::ElasticSearch::Reindex.any_instance.stubs(:finalize)
Katello.config[:warden] = 'ldap'
Katello.config[:validate_ldap] = false
User.stubs(:cp_oauth_header).returns("abc123")
as_admin do
User.current.stubs(:remote_id).returns(User.current.login)
@org = Organization.create!(:name => "Haskell_Curry_Inc",
:label => "haskell_curry_inc"
)
spec/helpers/organization_helper_methods.rb
module Katello
module OrganizationHelperMethods
include OrchestrationHelper
def new_test_org user=nil
disable_org_orchestration
suffix = Organization.count + 1
......
end
def create_environment(attrs)
User.current.remote_id = User.current.login
env = KTEnvironment.create!(attrs)
if block_given?
yield env
spec/models/gpg_key_spec.rb
let(:organization) do
disable_org_orchestration
as_admin do
User.current.stubs(:remote_id).returns(User.current.login)
Organization.create!(:name => "Duh", :label => "ahaha")
end
end
spec/models/model_spec_helper.rb
end
def disable_org_orchestration
::Actions::ElasticSearch::Reindex.any_instance.stubs(:finalize)
Resources::Candlepin::Owner.stubs(:create).returns({})
Resources::Candlepin::Owner.stubs(:create_user).returns(true)
Resources::Candlepin::Owner.stubs(:destroy).returns(true)
Resources::Candlepin::Owner.stubs(:get_ueber_cert).returns({ :cert => CERT, :key => KEY })
Organization.any_instance.stubs(:ensure_not_in_transaction!)
disable_env_orchestration # env is orchestrated with org - we disable this as well
end
def disable_env_orchestration
disable_foreman_tasks_hooks(KTEnvironment)
Resources::Candlepin::Environment.stubs(:create).returns({})
Resources::Candlepin::Environment.stubs(:destroy).returns({})
Resources::Candlepin::Environment.stubs(:find).returns({ :environmentContent => [] })
spec/models/organization_spec.rb
before(:each) do
Resources::Candlepin::Owner.stubs(:create_user).returns(true)
Resources::Candlepin::Owner.expects(:create).at_least_once.returns({})
::Actions::ElasticSearch::Reindex.any_instance.stubs(:finalize)
disable_env_orchestration
@organization = Organization.create(:name => 'test_org_name', :label=>'test_org_label')
Organization.any_instance.stubs(:ensure_not_in_transaction!)
@organization = Organization.create!(:name => 'test_org_name', :label=>'test_org_label')
end
describe "organization validation" do
spec/models/product_spec.rb
disable_product_orchestration
as_admin do
User.current.stubs(:remote_id).returns(User.current.login)
@organization = Organization.find_or_create_by_label!(:name=>ProductTestData::ORG_ID, :label => 'admin-org-37070')
end
test/actions/candlepin/environment_test.rb
#
# Copyright 2013 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public
# License as published by the Free Software Foundation; either version
# 2 of the License (GPLv2) or (at your option) any later version.
# There is NO WARRANTY for this software, express or implied,
# including the implied warranties of MERCHANTABILITY,
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
# have received a copy of GPLv2 along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
require 'katello_test_helper'
module Katello
namespace = ::Actions::Candlepin::Environment
describe namespace do
include Dynflow::Testing
include Support::Actions::RemoteAction
before do
stub_remote_user
end
describe 'Create' do
let(:action_class) { ::Actions::Candlepin::Environment::Create }
let(:label) { "foo"}
let(:name) { "boo"}
let(:cp_id) {"foo_boo"}
let(:description) {"great gatsby"}
let(:planned_action) do
create_and_plan_action(action_class,
organization_label: label,
name: name,
cp_id: cp_id,
description: description)
end
it 'runs' do
::Katello::Resources::Candlepin::Environment.expects(:create).with(label, cp_id, name, description)
run_action planned_action
end
end
end
end
test/actions/candlepin/owner_test.rb
#
# Copyright 2013 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public
# License as published by the Free Software Foundation; either version
# 2 of the License (GPLv2) or (at your option) any later version.
# There is NO WARRANTY for this software, express or implied,
# including the implied warranties of MERCHANTABILITY,
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
# have received a copy of GPLv2 along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
require 'katello_test_helper'
module Katello
namespace = ::Actions::Candlepin::Owner
describe namespace do
include Dynflow::Testing
include Support::Actions::RemoteAction
before do
stub_remote_user
end
describe 'Create' do
let(:action_class) { ::Actions::Candlepin::Owner::Create }
let(:label) { "foo"}
let(:name) { "boo"}
let(:planned_action) do
create_and_plan_action action_class, label: label, name: name
end
it 'runs' do
::Katello::Resources::Candlepin::Owner.expects(:create).with(label, name)
run_action planned_action
end
end
end
end
test/actions/headpin/content_view_environment_test.rb
#
# Copyright 2013 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public
# License as published by the Free Software Foundation; either version
# 2 of the License (GPLv2) or (at your option) any later version.
# There is NO WARRANTY for this software, express or implied,
# including the implied warranties of MERCHANTABILITY,
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
# have received a copy of GPLv2 along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
require 'katello_test_helper'
module Katello
describe ::Actions::Headpin::ContentView do
include Dynflow::Testing
include Support::Actions::Fixtures
include Support::Actions::RemoteAction
include FactoryGirl::Syntax::Methods
describe "Create" do
let(:action_class) { ::Actions::Headpin::ContentView::EnvironmentCreate }
let(:action) { create_action action_class }
let(:content_view_environment) do
katello_content_view_environments(:library_default_view_environment)
end
it 'plans' do
Katello::Configuration::Node.any_instance.stubs(:use_cp).returns(true)
content_view_environment.expects(:save!)
plan_action(action, content_view_environment)
content_view = content_view_environment.content_view
assert_action_planed_with(action,
::Actions::Candlepin::Environment::Create,
'organization_label' => content_view.organization.label,
'cp_id' => content_view_environment.cp_id,
'name' => content_view_environment.label,
'description' => content_view.description)
end
end
end
end
test/actions/headpin/content_view_test.rb
#
# Copyright 2013 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public
# License as published by the Free Software Foundation; either version
# 2 of the License (GPLv2) or (at your option) any later version.
# There is NO WARRANTY for this software, express or implied,
# including the implied warranties of MERCHANTABILITY,
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
# have received a copy of GPLv2 along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
require 'katello_test_helper'
module Katello
describe ::Actions::Headpin::ContentView do
include Dynflow::Testing
include Support::Actions::Fixtures
include Support::Actions::RemoteAction
include FactoryGirl::Syntax::Methods
describe "Create" do
let(:action_class) { ::Actions::Headpin::ContentView::Create }
let(:action) { create_action action_class }
let(:content_view) do
katello_content_views(:acme_default)
end
it 'plans' do
Katello::Configuration::Node.any_instance.stubs(:use_elasticsearch).returns(true)
content_view.expects(:save!)
content_view.expects(:disable_auto_reindex!)
plan_action(action, content_view)
assert_action_planed_with(action, ::Actions::ElasticSearch::Reindex, content_view)
end
end
end
end
test/actions/headpin/library_create_test.rb
#
# Copyright 2013 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public
# License as published by the Free Software Foundation; either version
# 2 of the License (GPLv2) or (at your option) any later version.
# There is NO WARRANTY for this software, express or implied,
# including the implied warranties of MERCHANTABILITY,
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
# have received a copy of GPLv2 along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
require 'katello_test_helper'
module Katello
describe ::Actions::Headpin::ContentView do
include Dynflow::Testing
include Support::Actions::Fixtures
include Support::Actions::RemoteAction
include FactoryGirl::Syntax::Methods
describe "Library Create" do
let(:action_class) { ::Actions::Headpin::Environment::LibraryCreate }
let(:action) { create_action action_class }
let(:library) do
katello_environments(:library)
end
let(:content_view) do
katello_content_views(:library_view)
end
let(:content_view_environment) do
katello_content_view_environments(:library_default_view_environment)
end
it 'plans' do
library.expects(:save!)
::Katello::ContentView.expects(:create!).returns(content_view).with do |arg_hash|
arg_hash[:default] == true
end
content_view.expects(:add_environment).once.with(library).returns(content_view_environment)
::Katello::ContentViewVersion.expects(:create!)
plan_action(action, library)
assert_action_planed_with(action,
::Actions::Headpin::ContentView::Create,
content_view)
assert_action_planed_with(action,
::Actions::Headpin::ContentView::EnvironmentCreate,
content_view_environment)
end
end
end
end
test/actions/headpin/organization_test.rb
#
# Copyright 2013 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public
# License as published by the Free Software Foundation; either version
# 2 of the License (GPLv2) or (at your option) any later version.
# There is NO WARRANTY for this software, express or implied,
# including the implied warranties of MERCHANTABILITY,
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
# have received a copy of GPLv2 along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
require 'katello_test_helper'
module Katello
describe ::Actions::Headpin::Organization do
include Dynflow::Testing
include Support::Actions::Fixtures
include Support::Actions::RemoteAction
include FactoryGirl::Syntax::Methods
describe "Create" do
let(:action_class) { ::Actions::Headpin::Organization::Create }
let(:action) { create_action action_class }
let(:organization) do
build(:katello_organization, :acme_corporation, :with_library)
end
it 'plans' do
provider = mock()
provider.expects(:save!).returns([])
organization.expects(:providers).returns([provider])
organization.expects(:save!)
organization.expects(:disable_auto_reindex!).returns
action.stubs(:action_subject).with(organization, any_parameters)
plan_action(action, organization)
assert_action_planed_with(action,
::Actions::Candlepin::Owner::Create,
label: organization.label,
name: organization.name)
assert_action_planed_with(action,
::Actions::Headpin::Environment::LibraryCreate,
organization.library)
assert_action_planed_with(action, ::Actions::ElasticSearch::Reindex, organization)
end
end
end
end
test/glue/candlepin/consumer_test.rb
@@dev_cve.cp_id = @@dev_cv.cp_environment_id @@dev
# Create the environment in candlepin
@@org.set_owner
@@dev_cve.set_environment
CandlepinOwnerSupport.set_owner(@@org)
User.current.remote_id = User.current.login
ForemanTasks.sync_task(::Actions::Headpin::ContentView::EnvironmentCreate, @@dev_cve)
end
def self.after_suite
test/glue/candlepin/provider_test.rb
@@org = Organization.find(@loaded_fixtures['taxonomies']['organization2']['id'])
@@provider = Provider.find(@loaded_fixtures['katello_providers']['candlepin_redhat']['id'])
@@org.set_owner
CandlepinOwnerSupport.set_owner(@@org)
end
def self.after_suite
test/katello_test_helper.rb
user ||= users(:admin)
user = User.find(user)
User.current = user
User.current.stubs(:remote_id).returns(User.current.login)
if permissions
permissions.call(Katello::AuthorizationSupportMethods::UserPermissionsGenerator.new(user))
end
......
def get_organization(org = nil)
saved_user = User.current
User.current = User.find(users(:admin))
org = org.nil? ? :empty_organization : org
organization = Organization.find(taxonomies(org.to_sym))
organization.setup_label_from_name
organization.save!
User.current = saved_user
organization
end
......
# include the concern again after Organization reloading
Organization.send :include, Katello::Concerns::OrganizationExtensions
Organization.class_eval do
def ensure_not_in_transaction!
end
end
end
@@model_service_cache[model] = cached_entry
test/models/content_view_test.rb
#
# Copyright 2013 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public
......
@library = KTEnvironment.find(katello_environments(:library).id)
@dev = KTEnvironment.find(katello_environments(:dev).id)
@default_view = ContentView.find(katello_content_views(:acme_default))
@library_view = ContentView.find(katello_content_views(:library_view))
@library_dev_view = ContentView.find(katello_content_views(:library_dev_view))
@default_view = ContentView.find(katello_content_views(:acme_default).id)
@library_view = ContentView.find(katello_content_views(:library_view).id)
@library_dev_view = ContentView.find(katello_content_views(:library_dev_view).id)
end
def test_create
......
content_view = @library_view
refute_includes content_view.environments, @dev
content_view.promote(@library, @dev)
assert_includes content_view.environments, @dev
refute_empty ContentViewEnvironment.where(:content_view_id => content_view,
:environment_id => @dev)
test/support/candlepin/owner_support.rb
@organization
end
def self.set_owner(org)
# TODO: this tests should move to actions tests once we
# have more actions in Dynflow. For now just peform the
# things that system.set_pulp_consumer did before.
User.current.remote_id = User.current.login
ForemanTasks.sync_task(::Actions::Candlepin::Owner::Create,
name: org.name, label: org.label)
end
def set_owner(org)
self.class.set_owner(org)
end
def self.create_organization(name, label)
@organization = Organization.new
@organization.name = name
@organization.label = label
@organization.description = 'New Organization'
Organization.stubs(:disable_auto_reindex!).returns
VCR.use_cassette('support/candlepin/organization', :match_requests_on => [:path, :params, :method, :body_json]) do
@organization.set_owner
set_owner(@organization)
end
rescue => e
puts e

Also available in: Unified diff