From ad6ad1cc82c5697c21141d68d77d1035b574a074 Mon Sep 17 00:00:00 2001 From: Mooli Tayer Date: Fri, 3 Mar 2017 15:22:06 +0200 Subject: [PATCH] remove queue serialization --- .../kubernetes/container_manager_mixin.rb | 9 +++-- spec/models/job_proxy_dispatcher_spec.rb | 2 +- spec/models/job_spec.rb | 2 +- .../container_manager/scanning/job_spec.rb | 37 +++++++++++++------ .../kubernetes/container_manager_spec.rb | 2 +- 5 files changed, 34 insertions(+), 18 deletions(-) diff --git a/app/models/manageiq/providers/kubernetes/container_manager_mixin.rb b/app/models/manageiq/providers/kubernetes/container_manager_mixin.rb index a301ceafdb2..ce4f0848e55 100644 --- a/app/models/manageiq/providers/kubernetes/container_manager_mixin.rb +++ b/app/models/manageiq/providers/kubernetes/container_manager_mixin.rb @@ -153,12 +153,13 @@ def scan_job_create(entity) check_policy_prevent(:request_containerimage_scan, entity, :raw_scan_job_create) end - def raw_scan_job_create(entity) + def raw_scan_job_create(target_class, target_id = nil) + target_class, target_id = target_class.class.name, target_class.id if target_class.kind_of?(ContainerImage) Job.create_job( "ManageIQ::Providers::Kubernetes::ContainerManager::Scanning::Job", :name => "Container image analysis", - :target_class => entity.class.name, - :target_id => entity.id, + :target_class => target_class, + :target_id => target_id, :zone => my_zone, :miq_server_host => MiqServer.my_server.hostname, :miq_server_guid => MiqServer.my_server.guid, @@ -174,7 +175,7 @@ def check_policy_prevent(policy_event, event_target, cb_method) :class_name => self.class.to_s, :instance_id => id, :method_name => :check_policy_prevent_callback, - :args => [cb_method, event_target], + :args => [cb_method, event_target.class.name, event_target.id], :server_guid => MiqServer.my_guid } enforce_policy(event_target, policy_event, {}, { :miq_callback => cb }) unless policy_event.nil? diff --git a/spec/models/job_proxy_dispatcher_spec.rb b/spec/models/job_proxy_dispatcher_spec.rb index 07cfc5875b4..aecc405a50b 100644 --- a/spec/models/job_proxy_dispatcher_spec.rb +++ b/spec/models/job_proxy_dispatcher_spec.rb @@ -176,7 +176,7 @@ context "with container and vms jobs" do before(:each) do @jobs = (@vms + @repo_vms).collect(&:scan) - @jobs += @container_images.map { |img| img.ext_management_system.raw_scan_job_create(img) } + @jobs += @container_images.map { |img| img.ext_management_system.raw_scan_job_create(img.class, img.id) } @dispatcher = JobProxyDispatcher.new end diff --git a/spec/models/job_spec.rb b/spec/models/job_spec.rb index 2e35dec9234..9d7921b4513 100644 --- a/spec/models/job_spec.rb +++ b/spec/models/job_spec.rb @@ -255,7 +255,7 @@ :container_image, :ext_management_system => @ems_k8s, :name => 'test', :image_ref => "docker://3629a651e6c11d7435937bdf41da11cf87863c03f2587fa788cf5cbfe8a11b9a" ) - @image_scan_job = @image.ext_management_system.raw_scan_job_create(@image) + @image_scan_job = @image.ext_management_system.raw_scan_job_create(@image.class, @image.id) end context "#target_entity" do diff --git a/spec/models/manageiq/providers/kubernetes/container_manager/scanning/job_spec.rb b/spec/models/manageiq/providers/kubernetes/container_manager/scanning/job_spec.rb index 64e95f5881c..f2cf98904b5 100644 --- a/spec/models/manageiq/providers/kubernetes/container_manager/scanning/job_spec.rb +++ b/spec/models/manageiq/providers/kubernetes/container_manager/scanning/job_spec.rb @@ -71,16 +71,31 @@ def fetch_oscap_arf @ems = FactoryGirl.create(:ems_kubernetes, :hostname => 'hostname') end - it "#initialize" do - image = FactoryGirl.create(:container_image, :ext_management_system => @ems) - job = @ems.raw_scan_job_create(image) - expect(job).to have_attributes( - :dispatch_status => "pending", - :state => "waiting_to_start", - :status => "ok", - :message => "process initiated", - :target_class => "ContainerImage" - ) + context "#initialize" do + it "Creates a new scan job" do + image = FactoryGirl.create(:container_image, :ext_management_system => @ems) + job = @ems.raw_scan_job_create(image.class, image.id) + expect(job).to have_attributes( + :dispatch_status => "pending", + :state => "waiting_to_start", + :status => "ok", + :message => "process initiated", + :target_class => "ContainerImage" + ) + end + + it "Is backward compatible with #13722" do + # https://github.com/ManageIQ/manageiq/pull/13722 + image = FactoryGirl.create(:container_image, :ext_management_system => @ems) + job = @ems.raw_scan_job_create(image) + expect(job).to have_attributes( + :dispatch_status => "pending", + :state => "waiting_to_start", + :status => "ok", + :message => "process initiated", + :target_class => "ContainerImage" + ) + end end end @@ -112,7 +127,7 @@ def fetch_oscap_arf @job.signal(:data, '') end - @job = @ems.raw_scan_job_create(@image) + @job = @ems.raw_scan_job_create(@image.class, @image.id) allow(MiqQueue).to receive(:put_unless_exists) do |args| @job.signal(*args[:args]) end diff --git a/spec/models/manageiq/providers/kubernetes/container_manager_spec.rb b/spec/models/manageiq/providers/kubernetes/container_manager_spec.rb index 1744c540478..cebdbf95cb9 100644 --- a/spec/models/manageiq/providers/kubernetes/container_manager_spec.rb +++ b/spec/models/manageiq/providers/kubernetes/container_manager_spec.rb @@ -92,7 +92,7 @@ it ".scan_job_create" do image = FactoryGirl.create(:container_image, :ext_management_system => @ems) - job = @ems.raw_scan_job_create(image) + job = @ems.raw_scan_job_create(image.class, image.id) expect(job.state).to eq("waiting_to_start") expect(job.status).to eq("ok")