Skip to content

Commit

Permalink
Fixes #15978 - Fix host-collection content cmds (#452)
Browse files Browse the repository at this point in the history
host-collection [package|package-group|erratum] [install|update|remove]

This change is needed due to host unification. The api changes slightly
to ensure bulk host operations go through the Foreman API rather than
the Katello api.
  • Loading branch information
akofink committed Sep 23, 2016
1 parent afa1377 commit 71e64a8
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 6 deletions.
15 changes: 10 additions & 5 deletions lib/hammer_cli_katello/host_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,26 +150,31 @@ class RemoveHostCommand < HammerCLIKatello::SingleResourceCommand

autoload_subcommands

class ContentBaseCommand < DeleteCommand
resource :systems_bulk_actions
class ContentBaseCommand < Command
resource :hosts_bulk_actions

option "--id", "HOST_COLLECTION_ID", _("Host Collection ID"),
:attribute_name => :option_host_collection_id
option "--name", "HOST_COLLECTION_NAME", _("Host Collection Name"),
:attribute_name => :option_host_collection_name

build_options do |o|
o.without(:content_type, :content, :ids, :search)
o.expand(:all).including(:organizations)
end

def request_params
params = super
params['content'] = content
params['content_type'] = content_type
params['included'] = { :search => "host_collection_ids:#{params['id']}" }
params['included'] = { search: "host_collection_id=\"#{option_host_collection_id}\"" }
params.delete('id')
params
end

def resolver
api = HammerCLI::Connection.get("foreman").api
custom_resolver = Class.new(HammerCLIKatello::IdResolver) do
def systems_bulk_action_id(options)
def hosts_bulk_action_id(options)
host_collection_id(options)
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/data/3.2/foreman_api.json

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions test/functional/host_collection/content_install_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
require_relative '../test_helper'
require 'hammer_cli_katello/host_collection'

module HammerCLIKatello
describe HostCollection::InstallContentBaseCommand do
it 'installs packages to hosts in a host collection' do
api_expects(:hosts_bulk_actions, :install_content) do |p|
p['organization_id'] == 1 &&
p['included'] == { search: "host_collection_id=\"3\"" } &&
p['content'] == ['wget']
end

run_cmd(%w(host-collection package install --id 3 --packages wget --organization-id 1))
end

it 'installs package groups to hosts in a host collection' do
api_expects(:hosts_bulk_actions, :install_content) do |p|
p['organization_id'] == 1 &&
p['included'] == { search: "host_collection_id=\"3\"" } &&
p['content'] == ['birds']
end

run_cmd(%w(host-collection package-group install --id 3
--package-groups birds --organization-id 1))
end

it 'installs erratum to hosts in a host collection' do
api_expects(:hosts_bulk_actions, :install_content) do |p|
p['organization_id'] == 1 &&
p['included'] == { search: "host_collection_id=\"3\"" } &&
p['content'] == ['Bird_Erratum']
end

run_cmd(%w(host-collection erratum install --id 3 --errata Bird_Erratum --organization-id 1))
end
end
end
27 changes: 27 additions & 0 deletions test/functional/host_collection/content_remove_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require_relative '../test_helper'
require 'hammer_cli_katello/host_collection'

module HammerCLIKatello
describe HostCollection::RemoveContentBaseCommand do
it 'removes packages from hosts in a host collection' do
api_expects(:hosts_bulk_actions, :remove_content) do |p|
p['organization_id'] == 1 &&
p['included'] == { search: "host_collection_id=\"3\"" } &&
p['content'] == ['wget']
end

run_cmd(%w(host-collection package remove --id 3 --packages wget --organization-id 1))
end

it 'removes package groups from hosts in a host collection' do
api_expects(:hosts_bulk_actions, :remove_content) do |p|
p['organization_id'] == 1 &&
p['included'] == { search: "host_collection_id=\"3\"" } &&
p['content'] == ['birds']
end

run_cmd(%w(host-collection package-group remove --id 3
--package-groups birds --organization-id 1))
end
end
end
27 changes: 27 additions & 0 deletions test/functional/host_collection/content_update_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require_relative '../test_helper'
require 'hammer_cli_katello/host_collection'

module HammerCLIKatello
describe HostCollection::UpdateContentBaseCommand do
it 'updates packages on hosts in a host collection' do
api_expects(:hosts_bulk_actions, :update_content) do |p|
p['organization_id'] == 1 &&
p['included'] == { search: "host_collection_id=\"3\"" } &&
p['content'] == ['wget']
end

run_cmd(%w(host-collection package update --id 3 --packages wget --organization-id 1))
end

it 'updates package groups on hosts in a host collection' do
api_expects(:hosts_bulk_actions, :update_content) do |p|
p['organization_id'] == 1 &&
p['included'] == { search: "host_collection_id=\"3\"" } &&
p['content'] == ['birds']
end

run_cmd(%w(host-collection package-group update --id 3
--package-groups birds --organization-id 1))
end
end
end

0 comments on commit 71e64a8

Please sign in to comment.