|
1 | 1 | describe ManageIQ::Providers::Openstack::CloudManager::Provision::VolumeAttachment do |
2 | | - before do |
3 | | - @ems = FactoryBot.create(:ems_openstack_with_authentication) |
4 | | - @template = FactoryBot.create(:template_openstack, :ext_management_system => @ems) |
5 | | - @flavor = FactoryBot.create(:flavor_openstack) |
6 | | - @volume = FactoryBot.create(:cloud_volume_openstack) |
| 2 | + let(:ems) { FactoryBot.create(:ems_openstack_with_authentication) } |
| 3 | + let(:flavor) { FactoryBot.create(:flavor_openstack) } |
| 4 | + let(:template) { FactoryBot.create(:template_openstack, :ext_management_system => ems) } |
| 5 | + let(:volume) { FactoryBot.create(:cloud_volume_openstack) } |
| 6 | + let(:service) { double("volume service") } |
| 7 | + let(:task_options) { {:instance_type => flavor, :src_vm_id => template.id, :volumes => task_volumes} } |
| 8 | + let(:task_volumes) { [{:name => "custom_volume_1", :size => 2}] } |
| 9 | + let(:task) { FactoryBot.create(:miq_provision_openstack, :source => template, :state => 'pending', :status => 'Ok', :options => task_options) } |
7 | 10 |
|
| 11 | + before do |
8 | 12 | # We're storing objects in the instance_type, so we must permit loading this class |
9 | | - ActiveRecord.yaml_column_permitted_classes = YamlPermittedClasses.app_yaml_permitted_classes | [@flavor.class] |
10 | | - |
11 | | - @task = FactoryBot.create(:miq_provision_openstack, |
12 | | - :source => @template, |
13 | | - :state => 'pending', |
14 | | - :status => 'Ok', |
15 | | - :options => { |
16 | | - :instance_type => @flavor, |
17 | | - :src_vm_id => @template.id, |
18 | | - :volumes => [{:name => "custom_volume_1", :size => 2}] |
19 | | - }) |
| 13 | + ActiveRecord.yaml_column_permitted_classes = YamlPermittedClasses.app_yaml_permitted_classes | [flavor.class] |
20 | 14 | end |
21 | 15 |
|
22 | 16 | context "#configure_volumes" do |
23 | | - it "create volumes" do |
24 | | - service = double |
25 | | - allow(service).to receive_message_chain('volumes.create').and_return @volume |
26 | | - allow(@task.source.ext_management_system).to receive(:with_provider_connection)\ |
| 17 | + before do |
| 18 | + allow(service).to receive_message_chain(:volumes, :create).and_return(volume) |
| 19 | + allow(task.source.ext_management_system).to receive(:with_provider_connection) |
27 | 20 | .with({:service => 'volume', :tenant_name => nil}).and_yield(service) |
28 | | - allow(@task).to receive(:instance_type).and_return @flavor |
| 21 | + allow(task).to receive(:instance_type).and_return(flavor) |
| 22 | + end |
29 | 23 |
|
| 24 | + it "create volumes" do |
30 | 25 | default_volume = {:name => "root", :size => 1, :source_type => "image", :destination_type => "local", |
31 | 26 | :boot_index => 0, :delete_on_termination => true, :uuid => nil} |
32 | | - requested_volume = {:name => "custom_volume_1", :size => 2, :uuid => @volume.id, :source_type => "volume", |
| 27 | + requested_volume = {:name => "custom_volume_1", :size => 2, :uuid => volume.id, :source_type => "volume", |
33 | 28 | :destination_type => "volume"} |
34 | 29 |
|
35 | | - expect(@task.create_requested_volumes(@task.options[:volumes])).to eq [default_volume, requested_volume] |
| 30 | + expect(task.create_requested_volumes(task.options[:volumes])).to eq([default_volume, requested_volume]) |
| 31 | + end |
| 32 | + |
| 33 | + context "with a flavor that has no root disk" do |
| 34 | + let(:flavor) { FactoryBot.create(:flavor_openstack, :root_disk_size => 0) } |
| 35 | + |
| 36 | + it "sets the requested volume as a boot disk" do |
| 37 | + expected_volume = {:name => "custom_volume_1", :size => 2, :uuid => volume.id, :source_type => "volume", |
| 38 | + :destination_type => "volume", :boot_index => 0, :bootable => true, :imageRef => template.ems_ref} |
| 39 | + |
| 40 | + expect(task.create_requested_volumes(task.options[:volumes])).to eq([expected_volume]) |
| 41 | + end |
| 42 | + |
| 43 | + context "with multiple requested volumes" do |
| 44 | + let(:task_volumes) { [{:name => "custom_volume_1", :size => 2}, {:name => "custom_volume_2", :size => 4}] } |
| 45 | + |
| 46 | + it "only sets boot_index for first volumes" do |
| 47 | + expected_volume_1 = {:name => "custom_volume_1", :size => 2, :uuid => volume.id, :source_type => "volume", |
| 48 | + :destination_type => "volume", :boot_index => 0, :bootable => true, :imageRef => template.ems_ref} |
| 49 | + expected_volume_2 = {:name => "custom_volume_2", :size => 4, :uuid => volume.id, :source_type => "volume", |
| 50 | + :destination_type => "volume"} |
| 51 | + |
| 52 | + expect(task.create_requested_volumes(task.options[:volumes])).to eq([expected_volume_1, expected_volume_2]) |
| 53 | + end |
| 54 | + end |
36 | 55 | end |
37 | 56 | end |
38 | 57 |
|
39 | 58 | context "#check_volumes" do |
40 | 59 | it "status pending" do |
41 | 60 | pending_volume_attrs = {:source_type => "volume"} |
42 | | - service = double |
43 | | - allow(service).to receive_message_chain('volumes.get').and_return FactoryBot.build(:cloud_volume_openstack, |
44 | | - :status => "pending") |
45 | | - allow(@task.source.ext_management_system).to receive(:with_provider_connection)\ |
| 61 | + |
| 62 | + allow(service).to receive_message_chain('volumes.get') |
| 63 | + .and_return(FactoryBot.build(:cloud_volume_openstack, :status => "pending")) |
| 64 | + allow(task.source.ext_management_system).to receive(:with_provider_connection) |
46 | 65 | .with({:service => 'volume', :tenant_name => nil}).and_yield(service) |
47 | 66 |
|
48 | | - expect(@task.do_volume_creation_check([pending_volume_attrs])).to eq [false, "pending"] |
| 67 | + expect(task.do_volume_creation_check([pending_volume_attrs])).to eq([false, "pending"]) |
49 | 68 | end |
50 | 69 |
|
51 | 70 | it "check creation status available" do |
52 | 71 | pending_volume_attrs = {:source_type => "volume"} |
53 | | - service = double |
54 | | - allow(service).to receive_message_chain('volumes.get').and_return FactoryBot.build(:cloud_volume_openstack, |
55 | | - :status => "available") |
56 | | - allow(@task.source.ext_management_system).to receive(:with_provider_connection)\ |
| 72 | + |
| 73 | + allow(service).to receive_message_chain('volumes.get') |
| 74 | + .and_return(FactoryBot.build(:cloud_volume_openstack, :status => "available")) |
| 75 | + allow(task.source.ext_management_system).to receive(:with_provider_connection) |
57 | 76 | .with({:service => 'volume', :tenant_name => nil}).and_yield(service) |
58 | 77 |
|
59 | | - expect(@task.do_volume_creation_check([pending_volume_attrs])).to eq true |
| 78 | + expect(task.do_volume_creation_check([pending_volume_attrs])).to be_truthy |
60 | 79 | end |
61 | 80 |
|
62 | 81 | it "check creation status - not found" do |
63 | 82 | pending_volume_attrs = {:source_type => "volume"} |
64 | | - service = double |
65 | | - allow(service).to receive_message_chain('volumes.get').and_return nil |
66 | | - allow(@task.source.ext_management_system).to receive(:with_provider_connection)\ |
| 83 | + |
| 84 | + allow(service).to receive_message_chain('volumes.get').and_return(nil) |
| 85 | + allow(task.source.ext_management_system).to receive(:with_provider_connection) |
67 | 86 | .with({:service => 'volume', :tenant_name => nil}).and_yield(service) |
68 | 87 |
|
69 | | - expect(@task.do_volume_creation_check([pending_volume_attrs])).to eq [false, nil] |
| 88 | + expect(task.do_volume_creation_check([pending_volume_attrs])).to eq([false, nil]) |
70 | 89 | end |
71 | 90 |
|
72 | 91 | it "status error" do |
73 | 92 | pending_volume_attrs = {:source_type => "volume"} |
74 | | - service = double |
75 | | - allow(service).to receive_message_chain('volumes.get').and_return FactoryBot.build(:cloud_volume_openstack, |
76 | | - :status => "error") |
77 | | - allow(@task.source.ext_management_system).to receive(:with_provider_connection)\ |
| 93 | + |
| 94 | + allow(service).to receive_message_chain('volumes.get') |
| 95 | + .and_return(FactoryBot.build(:cloud_volume_openstack, :status => "error")) |
| 96 | + allow(task.source.ext_management_system).to receive(:with_provider_connection) |
78 | 97 | .with({:service => 'volume', :tenant_name => nil}).and_yield(service) |
79 | | - expect { @task.do_volume_creation_check([pending_volume_attrs]) }.to raise_error(MiqException::MiqProvisionError) |
| 98 | + |
| 99 | + expect { task.do_volume_creation_check([pending_volume_attrs]) }.to raise_error(MiqException::MiqProvisionError) |
80 | 100 | end |
81 | 101 | end |
82 | 102 | end |
0 commit comments