Skip to content

Commit

Permalink
VCR specs need to test all refresh settings
Browse files Browse the repository at this point in the history
VCR specs need to test all refresh settings
  • Loading branch information
Ladas committed Aug 11, 2017
1 parent 9826239 commit 0761d05
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 82 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,10 @@
expect(described_class.ems_type).to eq(:ec2)
end

# Test all kinds of DTO refreshes, DTO refresh, DTO with recursive saving strategy
[{:inventory_object_refresh => true},
{:inventory_object_saving_strategy => :recursive, :inventory_object_refresh => true},].each do |inventory_object_settings|
context "with settings #{inventory_object_settings}" do
AwsRefresherSpecCommon::ALL_GRAPH_REFRESH_SETTINGS.each do |settings|
context "with settings #{settings}" do
before(:each) do
settings = OpenStruct.new
settings.inventory_object_saving_strategy = inventory_object_settings[:inventory_object_saving_strategy]
settings.inventory_object_refresh = inventory_object_settings[:inventory_object_refresh]
settings.get_private_images = true
settings.get_shared_images = true
settings.get_public_images = false
settings.ignore_terminated_instances = true

allow(Settings.ems_refresh).to receive(:ec2).and_return(settings)
allow(Settings.ems_refresh).to receive(:ec2_network).and_return(inventory_object_settings)
stub_refresh_settings(settings)
end

it "will perform a full refresh" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,37 @@
@ems = FactoryGirl.create(:ems_amazon_with_vcr_authentication, :provider_region => "us-west-1")
end

before(:each) do
settings = OpenStruct.new
settings.inventory_object_refresh = false
settings.get_private_images = true
settings.get_shared_images = true
settings.get_public_images = false

allow(Settings.ems_refresh).to receive(:ec2).and_return(settings)
allow(Settings.ems_refresh).to receive(:ec2_network).and_return(:inventory_object_refresh => false)
end

it "will perform a full refresh on another region" do
2.times do # Run twice to verify that a second run with existing data does not change anything
@ems.reload

VCR.use_cassette("#{described_class.name.underscore}_other_region") do
EmsRefresh.refresh(@ems)
EmsRefresh.refresh(@ems.network_manager)
EmsRefresh.refresh(@ems.ebs_storage_manager)

@ems.reload
assert_counts(table_counts_from_api)
AwsRefresherSpecCommon::ALL_OLD_REFRESH_SETTINGS.each do |settings|
context "with settings #{settings}" do
before(:each) do
stub_refresh_settings(settings)
end

assert_specific_flavor
assert_specific_az
assert_specific_floating_ip
assert_specific_key_pair
assert_specific_security_group
assert_specific_template
assert_specific_vm_powered_on
assert_specific_vm_in_other_region
assert_relationship_tree
assert_subnet_required
it "will perform a full refresh on another region" do
2.times do # Run twice to verify that a second run with existing data does not change anything
@ems.reload

VCR.use_cassette("#{described_class.name.underscore}_other_region") do
EmsRefresh.refresh(@ems)
EmsRefresh.refresh(@ems.network_manager)
EmsRefresh.refresh(@ems.ebs_storage_manager)

@ems.reload
assert_counts(table_counts_from_api)
end

assert_specific_flavor
assert_specific_az
assert_specific_floating_ip
assert_specific_key_pair
assert_specific_security_group
assert_specific_template
assert_specific_vm_powered_on
assert_specific_vm_in_other_region
assert_relationship_tree
assert_subnet_required
end
end
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,32 @@
@ems = FactoryGirl.create(:ems_amazon_with_vcr_authentication)
end

before(:each) do
settings = OpenStruct.new
settings.inventory_object_refresh = false
settings.get_private_images = true
settings.get_shared_images = true
settings.get_public_images = false

allow(Settings.ems_refresh).to receive(:ec2).and_return(settings)
allow(Settings.ems_refresh).to receive(:ec2_network).and_return(:inventory_object_refresh => false)
end

it ".ems_type" do
expect(described_class.ems_type).to eq(:ec2)
end

it "will perform a full refresh" do
2.times do # Run twice to verify that a second run with existing data does not change anything
@ems.reload
AwsRefresherSpecCommon::ALL_OLD_REFRESH_SETTINGS.each do |settings|
context "with settings #{settings}" do
before(:each) do
stub_refresh_settings(settings)
end

VCR.use_cassette(described_class.name.underscore) do
EmsRefresh.refresh(@ems)
EmsRefresh.refresh(@ems.network_manager)
EmsRefresh.refresh(@ems.ebs_storage_manager)
it "will perform a full refresh" do
2.times do # Run twice to verify that a second run with existing data does not change anything
@ems.reload

@ems.reload
assert_counts(table_counts_from_api)
end
VCR.use_cassette(described_class.name.underscore) do
EmsRefresh.refresh(@ems)
EmsRefresh.refresh(@ems.network_manager)
EmsRefresh.refresh(@ems.ebs_storage_manager)

@ems.reload
assert_counts(table_counts_from_api)
end

assert_common
assert_common
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,10 @@
@ems = FactoryGirl.create(:ems_amazon_with_vcr_authentication)
end

# Test all kinds of graph refreshes, graph refresh, graph with recursive saving strategy
[{:inventory_object_refresh => true},
{:inventory_object_saving_strategy => :recursive, :inventory_object_refresh => true},].each do |inventory_object_settings|
context "with settings #{inventory_object_settings}" do
AwsRefresherSpecCommon::ALL_GRAPH_REFRESH_SETTINGS.each do |settings|
context "with settings #{settings}" do
before(:each) do
settings = OpenStruct.new
settings.inventory_object_saving_strategy = inventory_object_settings[:inventory_object_saving_strategy]
settings.inventory_object_refresh = inventory_object_settings[:inventory_object_refresh]
settings.allow_targeted_refresh = true
settings.get_private_images = true
settings.get_shared_images = true
settings.get_public_images = false

allow(Settings.ems_refresh).to receive(:ec2).and_return(settings)

stub_refresh_settings(settings.merge(:allow_targeted_refresh => true))
# The flavors are not fetched from the API, they can go in only by appliance update, so must be in place after
# the full refresh, lets pre-create them in the DB.
create_flavors
Expand Down

0 comments on commit 0761d05

Please sign in to comment.