Skip to content

Commit

Permalink
add openshift_container_images to openshift provider
Browse files Browse the repository at this point in the history
also process ems_ref for openshift_container_images
  • Loading branch information
Erez Freiberger committed Jun 18, 2017
1 parent 10ff45a commit 6c2aa9f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/models/manageiq/providers/openshift/container_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class ManageIQ::Providers::Openshift::ContainerManager < ManageIQ::Providers::Co
require_nested :RefreshWorker
require_nested :Refresher

has_many :openshift_container_images, :foreign_key => :ems_id, :dependent => :destroy

def self.ems_type
@ems_type ||= "openshift".freeze
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ def parse_openshift_image(openshift_image)
ref = "#{ContainerImage::DOCKER_PULLABLE_PREFIX}#{id}"
new_result = parse_container_image(id, ref)

new_result[:ems_ref] = openshift_image.metadata.uid
new_result[:type] = 'OpenshiftContainerImage'

if openshift_image[:dockerImageManifest].present?
begin
json = JSON.parse(openshift_image[:dockerImageManifest])
Expand Down
13 changes: 13 additions & 0 deletions app/models/openshift_container_image.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class OpenshiftContainerImage < ContainerImage
acts_as_miq_taggable
include NewWithTypeStiMixin

def annotate_deny_execution(causing_policy)
ext_management_system.annotate(
"image",
digest,
"security.manageiq.org/failed-policy" => causing_policy,
"images.openshift.io/deny-execution" => "true"
)
end
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
describe ManageIQ::Providers::Openshift::ContainerManager::Refresher do
let(:all_images_count) { 40 } # including /oapi/v1/images data
let(:pod_images_count) { 12 } # only images mentioned by pods
let(:images_managed_by_openshift_count) { 32 } # only images from /oapi/v1/images
let(:images_NOT_managed_by_openshift_count) { 8 } # images only from pod and not /oapi/v1/images

before(:each) do
allow(MiqServer).to receive(:my_zone).and_return("default")
Expand Down Expand Up @@ -141,6 +143,8 @@ def assert_table_counts
expect(ContainerTemplate.count).to eq(26)
expect(ContainerImage.count).to eq(all_images_count)
expect(ContainerImage.joins(:containers).distinct.count).to eq(pod_images_count)
expect(OpenshiftContainerImage.count).to eq(images_managed_by_openshift_count)
expect(BasicContainerImage.count).to eq(images_NOT_managed_by_openshift_count)
end

def assert_ems
Expand Down

0 comments on commit 6c2aa9f

Please sign in to comment.