Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

identify openshift images through command variable #15022

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/models/miq_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ def action_container_image_annotate_deny_execution(action, rec, inputs)
return
end

unless rec.digest.present?
unless !rec.ems_ref.blank?
Copy link
Member

@Fryguy Fryguy Jun 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unless + ! + blank? is a recipe for confusion... This is equivalent to if rec.ems_ref.blank?

MiqPolicy.logger.error("#{error_prefix} ContainerImage is not linked with an OpenShift image")
return
end
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20170605140212_add_ems_ref_to_container_image.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddEmsRefToContainerImage < ActiveRecord::Migration[5.0]
def change
add_column :container_images, :ems_ref, :string
end
end
1 change: 1 addition & 0 deletions db/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,7 @@ container_images:
- created_on
- old_ems_id
- deleted_on
- ems_ref
container_label_tag_mappings:
- id
- labeled_resource_type
Expand Down
26 changes: 26 additions & 0 deletions spec/models/miq_action_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,32 @@
end
end

context "#action_container_image_annotate_deny_execution" do
let(:action) { FactoryGirl.create(:miq_action, :name => "container_image_annotate_deny_execution") }
let(:ems) { FactoryGirl.create(:ems_openshift) }
let(:event) { FactoryGirl.create(:miq_event_definition, :name => "whatever") }

it "annotates openshift images" do
image = FactoryGirl.create(:container_image, :ems_ref => "123", :ext_management_system => ems)
expect(image).to receive(:annotate_deny_execution)
action.action_container_image_annotate_deny_execution(action,
image,
:policy => FactoryGirl.create(:miq_policy),
:event => event,
:synchronous => true)
end

it "doesn't annotates non provider images" do
image = FactoryGirl.create(:container_image, :ext_management_system => ems)
expect(image).not_to receive(:annotate_deny_execution)
action.action_container_image_annotate_deny_execution(action,
image,
:policy => FactoryGirl.create(:miq_policy),
:event => event,
:synchronous => true)
end
end

context '.create_default_actions' do
context 'seeding default actions from a file with 3 csv rows and some comments' do
before do
Expand Down