From 0761d05ffe8bd951a43e9888c623043e977c56ab Mon Sep 17 00:00:00 2001 From: Ladislav Smola Date: Fri, 11 Aug 2017 10:41:54 +0200 Subject: [PATCH] VCR specs need to test all refresh settings VCR specs need to test all refresh settings --- .../refresher_inventory_object_spec.rb | 17 +----- .../vcr_specs/refresher_other_region_spec.rb | 61 +++++++++---------- .../cloud_manager/vcr_specs/refresher_spec.rb | 41 ++++++------- .../vcr_specs/targeted_refresh_spec.rb | 17 +----- 4 files changed, 54 insertions(+), 82 deletions(-) diff --git a/spec/models/manageiq/providers/amazon/cloud_manager/vcr_specs/refresher_inventory_object_spec.rb b/spec/models/manageiq/providers/amazon/cloud_manager/vcr_specs/refresher_inventory_object_spec.rb index 951636871..51047a9e5 100644 --- a/spec/models/manageiq/providers/amazon/cloud_manager/vcr_specs/refresher_inventory_object_spec.rb +++ b/spec/models/manageiq/providers/amazon/cloud_manager/vcr_specs/refresher_inventory_object_spec.rb @@ -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 diff --git a/spec/models/manageiq/providers/amazon/cloud_manager/vcr_specs/refresher_other_region_spec.rb b/spec/models/manageiq/providers/amazon/cloud_manager/vcr_specs/refresher_other_region_spec.rb index 24cff9b52..57e2d85df 100644 --- a/spec/models/manageiq/providers/amazon/cloud_manager/vcr_specs/refresher_other_region_spec.rb +++ b/spec/models/manageiq/providers/amazon/cloud_manager/vcr_specs/refresher_other_region_spec.rb @@ -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 diff --git a/spec/models/manageiq/providers/amazon/cloud_manager/vcr_specs/refresher_spec.rb b/spec/models/manageiq/providers/amazon/cloud_manager/vcr_specs/refresher_spec.rb index 7ce9a4570..0f580d08b 100644 --- a/spec/models/manageiq/providers/amazon/cloud_manager/vcr_specs/refresher_spec.rb +++ b/spec/models/manageiq/providers/amazon/cloud_manager/vcr_specs/refresher_spec.rb @@ -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 diff --git a/spec/models/manageiq/providers/amazon/cloud_manager/vcr_specs/targeted_refresh_spec.rb b/spec/models/manageiq/providers/amazon/cloud_manager/vcr_specs/targeted_refresh_spec.rb index dff64ff95..fae87b9f2 100644 --- a/spec/models/manageiq/providers/amazon/cloud_manager/vcr_specs/targeted_refresh_spec.rb +++ b/spec/models/manageiq/providers/amazon/cloud_manager/vcr_specs/targeted_refresh_spec.rb @@ -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