Skip to content

Commit

Permalink
Merge pull request #18209 from d-m-u/orch_stack_provisioning_set_user
Browse files Browse the repository at this point in the history
Add owner to orch stack model provisioning
  • Loading branch information
mkanoor authored Nov 16, 2018
2 parents ed18040 + 5621fd7 commit ee71bab
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/models/orchestration_stack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class OrchestrationStack < ApplicationRecord
include NewWithTypeStiMixin
include AsyncDeleteMixin
include ProcessTasksMixin
include OwnershipMixin
include RetirementMixin
include TenantIdentityMixin
include CustomActionsMixin
Expand All @@ -18,6 +19,7 @@ class OrchestrationStack < ApplicationRecord
has_ancestry

belongs_to :ext_management_system, :foreign_key => :ems_id
belongs_to :tenant

has_many :authentication_orchestration_stacks
has_many :authentications, :through => :authentication_orchestration_stacks
Expand Down Expand Up @@ -48,6 +50,8 @@ class OrchestrationStack < ApplicationRecord

virtual_column :stdout, :type => :string

before_validation :set_tenant_from_group

scope :without_type, ->(type) { where.not(:type => type) }

alias_method :orchestration_stack_parameters, :parameters
Expand Down Expand Up @@ -93,6 +97,10 @@ def stdout(format = nil)
format.nil? ? try(:raw_stdout) : try(:raw_stdout, format)
end

def set_tenant_from_group
self.tenant_id = miq_group.tenant_id if miq_group
end

private :directs_and_indirects

def self.create_stack(orchestration_manager, stack_name, template, options = {})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,32 @@
end
end

describe 'set_tenant_from_group' do
before { Tenant.seed }
let(:tenant1) { FactoryGirl.create(:tenant) }
let(:tenant2) { FactoryGirl.create(:tenant) }
let(:group1) { FactoryGirl.create(:miq_group, :tenant => tenant1) }
let(:group2) { FactoryGirl.create(:miq_group, :tenant => tenant2) }

it "assigns the tenant from the group" do
expect(FactoryGirl.create(:orchestration_stack, :miq_group => group1).tenant).to eq(tenant1)
end

it "assigns the tenant from the group_id" do
expect(FactoryGirl.create(:orchestration_stack, :miq_group_id => group1.id).tenant).to eq(tenant1)
end

it "assigns the tenant from the group over the tenant" do
expect(FactoryGirl.create(:orchestration_stack, :miq_group => group1, :tenant_id => tenant2).tenant).to eq(tenant1)
end

it "changes the tenant after changing the group" do
stack = FactoryGirl.create(:orchestration_stack, :miq_group => group1)
stack.update_attributes(:miq_group_id => group2.id)
expect(stack.tenant).to eq(tenant2)
end
end

describe 'direct_<resource> methods' do
it 'defines a set of methods for vms' do
expect(root_stack.direct_vms.size).to eq(1)
Expand Down

0 comments on commit ee71bab

Please sign in to comment.