From 0cf4f3cfff99e892b435c9238d99c2cee6c7104b Mon Sep 17 00:00:00 2001 From: Erez Freiberger Date: Tue, 21 Nov 2017 12:26:45 +0200 Subject: [PATCH] read image acquiring status --- .../container_manager/scanning/job.rb | 6 +++++ .../container_manager/scanning/job_spec.rb | 27 +++++++++++++++---- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/app/models/manageiq/providers/kubernetes/container_manager/scanning/job.rb b/app/models/manageiq/providers/kubernetes/container_manager/scanning/job.rb index 8a6b816975..6019a8019a 100644 --- a/app/models/manageiq/providers/kubernetes/container_manager/scanning/job.rb +++ b/app/models/manageiq/providers/kubernetes/container_manager/scanning/job.rb @@ -145,6 +145,12 @@ def analyze _log.error("analyzing image-inspector metadata for #{options[:docker_image_id]} failed with error: #{e}") end + unless inspector_metadata&.ImageAcquireSuccess + msg = "image acquiring error: #{inspector_metadata.ImageAcquireError}" + _log.error(msg) + return queue_signal(:abort_job, msg, 'error') + end + verify_error = verify_scanned_image_id(inspector_metadata) if verify_error _log.error(verify_error) 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 2f3e730d06..2eb40a1a6e 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 @@ -74,16 +74,20 @@ def fetch_oscap_arf end class MockFailedImageInspectorClient < MockImageInspectorClient - def initialize(status, msg, *args) + def initialize(oscap_status, oscap_msg, image_acq_success = true, image_acq_error = "", *args) super(*args) - @status = status - @msg = msg + @oscap_status = oscap_status + @oscap_msg = oscap_msg + @image_acq_success = image_acq_success + @image_acq_error = image_acq_error end def fetch_metadata(*_args) os = super - os["OpenSCAP"] = OpenStruct.new("Status" => @status, - "ErrorMessage" => @msg) + os["OpenSCAP"] = OpenStruct.new("oscap_status" => @oscap_status, + "ErrorMessage" => @oscap_msg) + os["ImageAcquireSuccess"] = @image_acq_success + os["ImageAcquireError"] = @image_acq_error os end @@ -403,6 +407,19 @@ def create_pod_definition end end + context 'Image Acquiring Status' do + it 'Detects when image acquiring failed and reports the error' do + IMG_ACQ_ERR = "can't find image" + allow_any_instance_of(described_class).to receive_messages( + :image_inspector_client => MockFailedImageInspectorClient.new("Sucess", "", false, IMG_ACQ_ERR, IMAGE_ID) + ) + @job.signal(:start) + expect(@job.state).to eq 'finished' + expect(@job.status).to eq 'error' + expect(@job.message).to eq "image acquiring error: #{IMG_ACQ_ERR}" + end + end + context '#verify_scanned_image_id' do DOCKER_DAEMON_IMAGE_ID = '123456'.freeze