-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Eligible storages for placement methods #578
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
:state => 'active', | ||
:status => 'Ok') | ||
end | ||
let(:user) { FactoryBot.create(:user_with_group) } | ||
let(:user) { FactoryBot.create(:user_with_group, :settings => {:display => {:timezone => 'UTC'}}) } | ||
let(:vm_template) { FactoryBot.create(:template_vmware, :ext_management_system => ems) } | ||
|
||
let(:svc_miq_provision) { MiqAeMethodService::MiqAeServiceMiqProvision.find(miq_provision.id) } | ||
|
@@ -48,11 +48,7 @@ | |
let(:host3) { FactoryBot.create(:host_vmware, :storages => [ro_storage, storages[2]], :vms => vms[2..4], :ext_management_system => ems) } | ||
let(:host4) { FactoryBot.create(:host_vmware, :storages => storages[0..2], :vms => vms[2..4], :ext_management_system => ems) } | ||
let(:host5) { FactoryBot.create(:host_vmware, :storages => [ro_storage, storages[2]], :vms => vms[2..4], :ext_management_system => ems) } | ||
|
||
let(:host_struct) do | ||
[MiqHashStruct.new(:id => host1.id, :evm_object_class => host1.class.base_class.name.to_sym), | ||
MiqHashStruct.new(:id => host2.id, :evm_object_class => host2.class.base_class.name.to_sym)] | ||
end | ||
let(:host_struct) { [host1, host2, host4] } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you look into the previous spec state, there was a hook, where were the |
||
|
||
let(:svc_host1) { MiqAeMethodService::MiqAeServiceHost.find(host1.id) } | ||
let(:svc_host2) { MiqAeMethodService::MiqAeServiceHost.find(host2.id) } | ||
|
@@ -70,14 +66,12 @@ | |
host4.ems_cluster = ems_cluster | ||
datacenter.with_relationship_type("ems_metadata") { datacenter.add_child(ems_cluster) } | ||
HostStorage.where(:host_id => host3.id, :storage_id => ro_storage.id).update(:read_only => true) | ||
allow_any_instance_of(ManageIQ::Providers::Vmware::InfraManager::ProvisionWorkflow) | ||
.to receive(:find_all_ems_of_type).with(Host).and_return(host_struct) | ||
end | ||
|
||
it "selects a host with fewer vms and a storage with more free space" do | ||
allow(svc_miq_provision).to receive(:eligible_hosts).and_return(svc_host_struct) | ||
allow(svc_miq_provision).to receive(:eligible_storages).and_return(svc_storages) | ||
|
||
expect(svc_miq_provision).to receive(:set_host).with(svc_host1) | ||
allow(svc_miq_provision).to receive(:set_storage) do |s| | ||
expect(svc_miq_provision).to receive(:set_storage) do |s| | ||
expect(s.id).to eq(svc_host1.storages[1].id) | ||
expect(s.name).to eq(svc_host1.storages[1].name) | ||
end | ||
|
@@ -86,12 +80,10 @@ | |
end | ||
|
||
context "with all storages accessible" do | ||
it "selects largest storage that is writable" do | ||
allow(svc_miq_provision).to receive(:eligible_hosts).and_return([svc_host3]) | ||
allow(svc_miq_provision).to receive(:eligible_storages).and_return(svc_host3.storages) | ||
let(:host_struct) { [host3] } | ||
|
||
expect(svc_miq_provision).to receive(:set_host).with(svc_host3) | ||
allow(svc_miq_provision).to receive(:set_storage) do |s| | ||
it "selects largest storage that is writable" do | ||
expect(svc_miq_provision).to receive(:set_storage) do |s| | ||
# ro_storage is larger but read-only, so it should select storages[2] | ||
expect(s.id).to eq(storages[2].id) | ||
expect(s.name).to eq(storages[2].name) | ||
|
@@ -102,35 +94,30 @@ | |
end | ||
|
||
context "with no storages accessible" do | ||
let(:host_struct) { [host5] } | ||
|
||
before do | ||
HostStorage.where(:host_id => host5.id, :storage_id => ro_storage.id).update(:accessible => false) | ||
HostStorage.where(:host_id => host5.id, :storage_id => storages[2].id).update(:accessible => false) | ||
end | ||
|
||
it "selects nothing" do | ||
allow(svc_miq_provision).to receive(:eligible_hosts).and_return([svc_host5]) | ||
allow(svc_miq_provision).to receive(:eligible_storages).and_return(svc_host5.storages) | ||
|
||
expect(svc_miq_provision).not_to receive(:set_host) | ||
allow(svc_miq_provision).to receive(:set_storage) do |s| | ||
# both ro_storage and storages[2] are inaccessible | ||
expect(s.id).to eq(nil) | ||
expect(s.name).to eq(nil) | ||
end | ||
# both ro_storage and storages[2] are inaccessible | ||
expect(svc_miq_provision).to_not receive(:set_storage) | ||
|
||
described_class.new(ae_service).main | ||
end | ||
end | ||
|
||
context "with the writable storage inaccessible" do | ||
let(:host_struct) { [host5] } | ||
|
||
before do | ||
HostStorage.where(:host_id => host5.id, :storage_id => storages[2].id).update(:accessible => false) | ||
end | ||
it "selects ro storage" do | ||
allow(svc_miq_provision).to receive(:eligible_hosts).and_return([svc_host5]) | ||
allow(svc_miq_provision).to receive(:eligible_storages).and_return(svc_host5.storages) | ||
|
||
expect(svc_miq_provision).to receive(:set_host).with(svc_host5) | ||
allow(svc_miq_provision).to receive(:set_storage) do |s| | ||
it "selects ro storage" do | ||
expect(svc_miq_provision).to receive(:set_storage) do |s| | ||
# storages[2] is inaccessible so it should select the ro | ||
expect(s.id).to eq(ro_storage.id) | ||
expect(s.name).to eq(ro_storage.name) | ||
|
@@ -145,11 +132,7 @@ | |
miq_provision.update_attributes(:options => options) | ||
storages[2].storage_profiles = [storage_profile] | ||
|
||
allow(svc_miq_provision).to receive(:eligible_hosts).and_return(svc_host_struct) | ||
allow(svc_miq_provision).to receive(:eligible_storages).and_return(svc_storages) | ||
|
||
expect(svc_miq_provision).to receive(:set_host).with(svc_host4) | ||
allow(svc_miq_provision).to receive(:set_storage) do |s| | ||
expect(svc_miq_provision).to receive(:set_storage) do |s| | ||
expect(s.id).to eq(svc_host4.storages[2].id) | ||
expect(s.name).to eq(svc_host4.storages[2].name) | ||
end | ||
|
@@ -164,14 +147,12 @@ | |
datacenter.add_child(host1) | ||
datacenter.add_child(host2) | ||
end | ||
allow_any_instance_of(MiqRequestWorkflow) | ||
.to receive(:find_all_ems_of_type).with(Host).and_return(host_struct) | ||
end | ||
|
||
it "selects a host with fewer vms and a storage with more free space" do | ||
allow(svc_miq_provision).to receive(:eligible_hosts).and_return(svc_host_struct) | ||
allow(svc_miq_provision).to receive(:eligible_storages).and_return(svc_storages) | ||
|
||
expect(svc_miq_provision).to receive(:set_host).with(svc_host1) | ||
allow(svc_miq_provision).to receive(:set_storage) do |s| | ||
expect(svc_miq_provision).to receive(:set_storage) do |s| | ||
expect(s.id).to eq(svc_host1.storages[1].id) | ||
expect(s.name).to eq(svc_host1.storages[1].name) | ||
end | ||
|
@@ -182,11 +163,7 @@ | |
it "selects a host not in maintenance" do | ||
host1.update_attributes(:maintenance => true) | ||
|
||
allow(svc_miq_provision).to receive(:eligible_hosts).and_return(svc_host_struct) | ||
allow(svc_miq_provision).to receive(:eligible_storages).and_return(svc_storages) | ||
|
||
expect(svc_miq_provision).to receive(:set_host).with(svc_host2) | ||
allow(svc_miq_provision).to receive(:set_storage) do |s| | ||
expect(svc_miq_provision).to receive(:set_storage) do |s| | ||
expect(s.id).to eq(svc_host2.storages[1].id) | ||
expect(s.name).to eq(svc_host2.storages[1].name) | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason for this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we are actually doing
eligible_resources
worflow, it is required to get the usertimezone
. You can see theget_timezone
method here: https://github.com/ManageIQ/manageiq/blob/master/app/models/user.rb#L231. I was choosing from 3 options there. 1) override this method with allow and return rspec methods 2) set the user timezone inside the config 3) set the server timezone. I picked the 2nd option.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you point me to where the
timezone
is required byeligible_resources
? Thanks.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the error output without setting the timezone. You can see the whole path here: