-
Notifications
You must be signed in to change notification settings - Fork 898
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15245 from masayag/find_datastore_within_provider
Select datastore by its association with the provider (cherry picked from commit ec5d106) https://bugzilla.redhat.com/show_bug.cgi?id=1462774
- Loading branch information
1 parent
d0843bc
commit 44b7dfe
Showing
2 changed files
with
63 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
spec/models/vm_or_template/operations/configuration_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
describe VmOrTemplate::Operations::Configuration do | ||
context "#raw_add_disk" do | ||
let(:disk_name) { "abc" } | ||
let(:disk_size) { "123" } | ||
|
||
context "when ext_management_system does not exist" do | ||
let(:vm) { FactoryGirl.create(:vm_or_template) } | ||
|
||
it "raises an exception when does not find ext_management_system" do | ||
message = "VM has no EMS, unable to add disk" | ||
expect { vm.raw_add_disk(disk_name, disk_size, {}) }.to raise_error(message) | ||
end | ||
end | ||
|
||
context "when ext_management_system exists" do | ||
let(:vm) { FactoryGirl.create(:vm_or_template, :ext_management_system => ems) } | ||
let(:ems) { FactoryGirl.create(:ext_management_system) } | ||
let(:storage_name) { "test_storage" } | ||
let(:storage) { FactoryGirl.create(:storage, :name => storage_name) } | ||
let(:storages) { double("storages") } | ||
let(:host) { double("host", :writable_storages => storages) } | ||
let(:hosts) { [host] } | ||
|
||
before do | ||
allow(ems).to receive(:hosts).and_return(hosts) | ||
end | ||
|
||
context "when storage exists" do | ||
it "adds a disk on the storage" do | ||
allow(storages).to receive(:find_by).with(:name => storage_name).and_return(storage) | ||
allow(ems).to receive(:authentication_status_ok?).and_return(true) | ||
allow(ems).to receive(:vm_add_disk) | ||
|
||
expected_options = { | ||
:diskName => disk_name, | ||
:diskSize => disk_size, | ||
:thinProvisioned => nil, | ||
:dependent => nil, | ||
:persistent => nil, | ||
:bootable => nil, | ||
:datastore => storage, | ||
:interface => nil | ||
} | ||
expect(vm).to receive(:run_command_via_parent).with(:vm_add_disk, expected_options).once | ||
vm.raw_add_disk(disk_name, disk_size, :datastore => storage_name) | ||
end | ||
end | ||
|
||
context "when storage does not exist" do | ||
it "raises an exception when doesn't find storage by its name" do | ||
allow(storages).to receive(:find_by).with(:name => storage_name).and_return(nil) | ||
|
||
message = "Datastore does not exist or cannot be accessed, unable to add disk" | ||
expect { vm.raw_add_disk(disk_name, disk_size, :datastore => storage_name) }.to raise_error(message) | ||
end | ||
end | ||
end | ||
end | ||
end |