Skip to content

Commit

Permalink
Script for automated VCR re-record
Browse files Browse the repository at this point in the history
VCR recorded from minishift v1.9.0, --openshift-version v3.6.0 --metrics.
  • Loading branch information
cben committed Dec 10, 2017
1 parent 590dddb commit 8646c0c
Show file tree
Hide file tree
Showing 4 changed files with 2,685 additions and 2,932 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@

before(:each) do
allow(MiqServer).to receive(:my_zone).and_return("default")
hostname = 'host.example.com'
token = 'theToken'
# env vars for easier VCR recording, see test_objects_record.sh
hostname = ENV["API_HOST"] || "host.example.com"
token = ENV["API_TOKEN"] || "theToken"

@ems = FactoryGirl.create(
:ems_openshift,
:name => 'OpenShiftProvider',
:connection_configurations => [{:endpoint => {:role => :default,
:hostname => hostname,
:port => "8443"},
:name => "OpenShiftProvider",
:connection_configurations => [{:endpoint => {:role => :default,
:hostname => hostname,
:port => "8443",
:security_protocol => "ssl-without-validation"},
:authentication => {:role => :bearer,
:auth_key => token,
:userid => "_"}}]
Expand Down Expand Up @@ -95,34 +97,37 @@ def full_refresh_test
end

context "when refreshing an empty DB" do
# CREATING FIRST VCR
# To recreate the tested objects in OpenShift use the template file:
# spec/vcr_cassettes/manageiq/providers/openshift/container_manager/test_objects_template.yml
# And these commands to their equivalents:
# for ind in 0 1 2; do
# oc new-project my-project-$ind
# oc project my-project-$ind
# oc process -f ./test_objects_template.yml -v INDEX=$ind | oc create -f -
# oc start-build my-build-config-$ind
# done
# To recreate both VCRs used here, use the script:
# spec/vcr_cassettes/manageiq/providers/openshift/container_manager/test_objects_record.sh
# which creates my-project-{0,1,2}.

before(:each) do
VCR.use_cassette("#{described_class.name.underscore}_before_openshift_deletions",
:match_requests_on => [:path,]) do # , :record => :new_episodes) do
:match_requests_on => [:path,],
:record => ENV['RECORD_VCR'] == 'before_openshift_deletions' ? :new_episodes : :none) do
EmsRefresh.refresh(@ems)
end
end

let(:object_counts) do
# using strings instead of actual model classes for compact rspec diffs
{
'ContainerProject' => 10,
'ContainerImage' => 42,
'ContainerRoute' => 3,
'ContainerTemplate' => 20,
'ContainerReplicator' => 5,
'ContainerBuild' => 3,
'ContainerBuildPod' => 3,
'CustomAttribute' => 573,
'ContainerTemplateParameter' => 210,
}
end

it "saves the objects in the DB" do
expect(ContainerProject.count).to eq(8)
expect(ContainerImage.count).to eq(39)
expect(ContainerRoute.count).to eq(5)
expect(ContainerTemplate.count).to eq(33)
expect(ContainerReplicator.count).to eq(6)
expect(ContainerBuild.count).to eq(3)
expect(ContainerBuildPod.count).to eq(3)
expect(CustomAttribute.count).to eq(564)
expect(ContainerTemplateParameter.count).to eq(367)
actual_counts = object_counts.collect { |k, _| [k, k.constantize.count] }.to_h
expect(actual_counts).to eq(object_counts)

expect(ContainerRoute.find_by(:name => "my-route-2").labels.count).to eq(1)
expect(ContainerTemplate.find_by(:name => "my-template-2").container_template_parameters.count).to eq(1)
ContainerBuildPod.all.each do |cbp|
Expand All @@ -131,47 +136,44 @@ def full_refresh_test
end

context "when refreshing non empty DB" do
# CREATING SECOND VCR
# To delete the tested objects in OpenShift use the following commands:
# oc delete project my-project-0
# oc project my-project-1
# oc delete pod my-pod-1
# oc delete service my-service-1
# oc delete route my-route-1
# oc delete resourceQuota my-resource-quota-1
# oc delete limitRange my-limit-range-1
# oc delete persistentVolumeClaim my-persistentvolumeclaim-1
# oc delete template my-template-1
# oc delete build my-build-config-1
# oc delete buildconfig my-build-config
# oc delete rc/my-replicationcontroller-1
# oc project my-project-2
# oc label route my-route-2 key-route-label-
# oc edit template my-template-2 # remove the template parameters from the file and save it
# oc delete pod my-pod-2
# After deleting resources in the cluster:
# "my-project-0" - The whole project
# "my-project-1" - All resources inside the project
# "my-project-2" - "my-pod-2", label of "my-route-2", parameters of "my-template-2"

before(:each) do
skip('meaningless at this stage of re-recording') if ENV['RECORD_VCR'] == 'before_openshift_deletions'

VCR.use_cassette("#{described_class.name.underscore}_after_openshift_deletions",
:match_requests_on => [:path,]) do # , :record => :new_episodes) do
:match_requests_on => [:path,],
:record => (ENV['RECORD_VCR'] == 'after_openshift_deletions') ? :new_episodes : :none) do
EmsRefresh.refresh(@ems)
end
end

it "archives objects" do
expect(ContainerProject.count).to eq(8)
expect(ContainerProject.where(:deleted_on => nil).count).to eq(7)
expect(ContainerImage.count).to eq(38) # should be 39
expect(ContainerImage.where(:deleted_on => nil).count).to eq(38) # should be 39
expect(ContainerProject.count).to eq(object_counts['ContainerProject'])
expect(ContainerProject.active.count).to eq(object_counts['ContainerProject'] - 1)

pending("why graph refresh DELETES 1 image from DB? why old refresh archives 2?")
expect(ContainerImage.count).to eq(object_counts['ContainerImage'])
expect(ContainerImage.active.count).to eq(object_counts['ContainerImage'] - 1)
end

it "removes the deleted objects from the DB" do
expect(ContainerRoute.count).to eq(3)
expect(ContainerTemplate.count).to eq(31)
expect(ContainerReplicator.count).to eq(4)
expect(ContainerBuild.count).to eq(1)
expect(ContainerBuildPod.count).to eq(1)
expect(CustomAttribute.count).to eq(549)
expect(ContainerTemplateParameter.count).to eq(364)
# TODO: check whether these make sense
deleted = {
'ContainerRoute' => 2,
'ContainerTemplate' => 2,
'ContainerReplicator' => 2,
'ContainerBuild' => 2,
'ContainerBuildPod' => 2,
'CustomAttribute' => 15,
'ContainerTemplateParameter' => 3,
}
expected_counts = deleted.collect { |k, d| [k, object_counts[k] - d] }.to_h
actual_counts = expected_counts.collect { |k, _| [k, k.constantize.count] }.to_h
expect(actual_counts).to eq(expected_counts)

expect(ContainerTemplate.find_by(:name => "my-template-0")).to be_nil
expect(ContainerTemplate.find_by(:name => "my-template-1")).to be_nil
Expand All @@ -182,11 +184,11 @@ def full_refresh_test
expect(ContainerReplicator.find_by(:name => "my-replicationcontroller-0")).to be_nil
expect(ContainerReplicator.find_by(:name => "my-replicationcontroller-1")).to be_nil

expect(ContainerBuildPod.find_by(:name => "my-build-0")).to be_nil
expect(ContainerBuildPod.find_by(:name => "my-build-1")).to be_nil
expect(ContainerBuildPod.find_by(:name => "my-build-config-0-1")).to be_nil
expect(ContainerBuildPod.find_by(:name => "my-build-config-1-1")).to be_nil

expect(ContainerBuild.find_by(:name => "my-build-config", :namespace => "my-project-0")).to be_nil
expect(ContainerBuild.find_by(:name => "my-build-config", :namespace => "my-project-1")).to be_nil
expect(ContainerBuild.find_by(:name => "my-build-config-0", :namespace => "my-project-0")).to be_nil
expect(ContainerBuild.find_by(:name => "my-build-config-1", :namespace => "my-project-1")).to be_nil

expect(ContainerRoute.find_by(:name => "my-route-2").labels.count).to eq(0)
expect(ContainerTemplate.find_by(:name => "my-template-2").container_template_parameters.count).to eq(0)
Expand Down
Loading

0 comments on commit 8646c0c

Please sign in to comment.