Skip to content

Commit

Permalink
Merge pull request #19087 from fdupont-redhat/v2v_dont_allow_ordering…
Browse files Browse the repository at this point in the history
…_finished_plan

[V2V] Prevent a finished transformation plan from starting

(cherry picked from commit 29aa3b6)

https://bugzilla.redhat.com/show_bug.cgi?id=1718858
  • Loading branch information
agrare authored and simaishi committed Aug 2, 2019
1 parent 1990eb4 commit f505efc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
3 changes: 2 additions & 1 deletion app/models/service_template_transformation_plan.rb
Expand Up @@ -24,7 +24,8 @@ def transformation_mapping_resource
end

def validate_order
true
# Service template should not be orderable if all VMs have already been migrated
vm_resources.reject { |res| res.resource.is_tagged_with?('transformation_status/migrated', :ns => '/managed') }.present?
end
alias orderable? validate_order

Expand Down
23 changes: 16 additions & 7 deletions spec/models/service_template_transformation_plan_spec.rb
Expand Up @@ -9,13 +9,6 @@
it { expect(subject.request_type).to eq("transformation_plan") }
end

describe '#validate_order' do
it 'always allows a plan to be ordered' do
expect(subject.validate_order).to be_truthy
expect(subject.orderable?).to be_truthy # alias
end
end

let(:transformation_mapping) { FactoryBot.create(:transformation_mapping) }
let(:transformation_mapping2) { FactoryBot.create(:transformation_mapping) }
let(:apst) { FactoryBot.create(:service_template_ansible_playbook) }
Expand Down Expand Up @@ -110,6 +103,22 @@
let(:miq_requests) { [FactoryBot.create(:service_template_transformation_plan_request, :request_state => "finished")] }
let(:miq_requests_with_in_progress_request) { [FactoryBot.create(:service_template_transformation_plan_request, :request_state => "active")] }

describe '#validate_order' do
let(:service_template) { described_class.create_catalog_item(catalog_item_options) }

it 'allows a plan to be ordered if all VMs have not been migrated' do
expect(service_template.validate_order).to be_truthy
expect(service_template.orderable?).to be_truthy # alias
end

it 'denies a plan from bring ordered if all VMs have been migrated' do
vm1.tag_add('transformation_status/migrated', :ns => '/managed')
vm2.tag_add('transformation_status/migrated', :ns => '/managed')
expect(service_template.validate_order).to be_falsey
expect(service_template.orderable?).to be_falsey # alias
end
end

describe '.public_service_templates' do
it 'display public service templates' do
st1 = FactoryBot.create(:service_template_transformation_plan)
Expand Down

0 comments on commit f505efc

Please sign in to comment.