Skip to content

Commit

Permalink
read image acquiring status
Browse files Browse the repository at this point in the history
  • Loading branch information
Erez Freiberger committed Nov 21, 2017
1 parent ef60398 commit 0cf4f3c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 0cf4f3c

Please sign in to comment.