Skip to content

Commit

Permalink
Fixes #37151 - Add --force flag to content overrides
Browse files Browse the repository at this point in the history
We only support enabled as a value on content overrides, adding a flag that makes the user add --force for anything other than enabled.
Increased the line length to 150 from discussions with Quinn on my last PR since Katello is at 200.
  • Loading branch information
chris1984 committed Dec 3, 2024
1 parent 93d8f61 commit 3006975
Show file tree
Hide file tree
Showing 16 changed files with 78 additions and 59 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Encoding:
Enabled: false

LineLength:
Max: 100
Max: 150

FormatString:
Enabled: false # we use % for i18n
Expand Down
2 changes: 0 additions & 2 deletions hammer_cli_katello.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ $LOAD_PATH.unshift(File.expand_path('../lib', __FILE__))

require 'hammer_cli_katello/version'

# rubocop:disable Layout/LineLength
begin
Dir["locale/**/*.po"].each do |po|
mo = po.sub(/hammer_cli_katello\.po$/, "LC_MESSAGES/hammer_cli_katello.mo")
Expand All @@ -15,7 +14,6 @@ begin
rescue => e
puts "#{e} not found"
end
# rubocop:enable Layout/LineLength

Gem::Specification.new do |gem|
gem.authors = [
Expand Down
2 changes: 1 addition & 1 deletion lib/hammer_cli_katello.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def self.exception_handler_class
'hammer_cli_katello/organization'
)

HammerCLI::MainCommand.lazy_subcommand!("alternate-content-source", _("Manipulate alternate content sources"), # rubocop:disable LineLength
HammerCLI::MainCommand.lazy_subcommand!("alternate-content-source", _("Manipulate alternate content sources"),
'HammerCLIKatello::AcsCommand',
'hammer_cli_katello/acs'
)
Expand Down
4 changes: 1 addition & 3 deletions lib/hammer_cli_katello/activation_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,8 @@ def request_params
end

def extend_data(data)
# rubocop:disable Layout/LineLength
# Hack to hide purpose addons if it's not set since it's not possible to hide the Fields::List values
data["purpose_addons"].length.positive? ? data["purpose_addons"] = data["purpose_addons"] : data["purpose_addons"] = nil
data["purpose_addons"] = data["purpose_addons"].length.positive? ? data["purpose_addons"] : nil
limit = data["unlimited_hosts"] ? _("Unlimited") : data["max_hosts"]

data["format_consumed"] = _("%{consumed} of %{limit}") %
Expand All @@ -118,7 +117,6 @@ def extend_data(data)
:limit => limit
}
data
# rubocop:enable Layout/LineLength
end

build_options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ class KickstartRepository < HammerCLI::CommandExtensions
raise _('Please provide --lifecycle-environment-id') unless env_id

raise _('Please provide --content-view-id') unless cv_id
# rubocop:disable LineLength
resource_hash['kickstart_repository_id'] = HammerCLIKatello::CommandExtensions::KickstartRepository.fetch_repo_id(
cv_id, env_id, cmd_obj.option_kickstart_repository
)
# rubocop:enable LineLength
end
end

Expand Down
7 changes: 7 additions & 0 deletions lib/hammer_cli_katello/content_override.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ def self.setup
success_message _("Updated content override.")
failure_message _("Could not update content override")

option "--force", "FORCE", _("Force the override. Required for overrides other than 'enabled'"),
:attribute_name => :option_force, default: false

option "--content-label", "CONTENT_LABEL", _("Label of the content"),
:attribute_name => :option_content_label, :required => true

Expand All @@ -28,6 +31,10 @@ def self.setup
if option(:option_remove).exist?
option(:option_value).rejected
elsif option(:option_value).exist?
if !@option_values['option_value'].casecmp('enabled').zero? &&
@option_values['option_force'] == false
raise ArgumentError, _("You must use --force to set a value other than 'enabled'")
end
option(:option_remove).rejected
end
end
Expand Down
2 changes: 0 additions & 2 deletions lib/hammer_cli_katello/content_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class ListCommand < HammerCLIKatello::ListCommand

class InfoCommand < HammerCLIKatello::InfoCommand
include OrganizationOptions
# rubocop:disable Layout/LineLength

output do
field :id, _("Id")
Expand Down Expand Up @@ -137,7 +136,6 @@ def extend_data(data)

build_options
end
# rubocop:enable Layout/LineLength

class CreateCommand < HammerCLIKatello::CreateCommand
success_message _("Content view created.")
Expand Down
2 changes: 0 additions & 2 deletions lib/hammer_cli_katello/content_view_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ class InfoCommand < HammerCLIKatello::InfoCommand
field :content, _('Type')
field :inclusion, _('Inclusion'), Fields::Boolean
field :original_packages, _('Original packages'), Fields::Boolean, hide_blank: true
# rubocop:disable Layout/LineLength
field :original_module_streams, _('Original module streams'), Fields::Boolean, hide_blank: true
# rubocop:enable Layout/LineLength
end
collection :rules, _("Rules"), hide_blank: true, hide_empty: true do
field :id, _('Id')
Expand Down
38 changes: 34 additions & 4 deletions test/functional/activation_key/content_override_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
before do
@cmd = %w(activation-key content-override)
end
it "attaches a content label" do
it "attaches a content override" do
label = "foo"
value = '1'
value = 'enabled'
id = 20
params = ["--id=#{id}", "--content-label=#{label}", "--value=#{value}"]
ex = api_expects(:activation_keys, :content_override) do |par|
Expand All @@ -23,9 +23,9 @@
assert_cmd(expected_result, result)
end

it "attaches a content label with name" do
it "attaches a content override with name" do
label = "foo"
value = '1'
value = 'enabled'
id = 20
name = 'protected'
params = ["--id=#{id}", "--content-label=#{label}", "--value=#{value}",
Expand All @@ -43,6 +43,36 @@
assert_cmd(expected_result, result)
end

it "attaches a content override with value other than enabled using --force" do
label = "foo"
value = '1'
id = 20
name = 'protected'
params = ["--id=#{id}", "--content-label=#{label}", "--value=#{value}",
"--override-name=#{name}", "--force"]
ex = api_expects(:activation_keys, :content_override) do |par|
par['id'] == id && par["content_overrides"][0]['content_label'] == label &&
par['content_overrides'][0]['value'] == value &&
par['content_overrides'][0]['name'] == name
end
ex.returns({})

expected_result = success_result("Updated content override.\n")

result = run_cmd(@cmd + params)
assert_cmd(expected_result, result)
end

it "does not attach a content override with value other than enabled without --force" do
api_expects_no_call
error_msg = "Could not update content override:\n" \
" You must use --force to set a value other than 'enabled'"

assert_failure run_cmd(%w(activation-key content-override --id=20 --content-label=foo --value=1 --override-name=protected)), error_msg
result = run_cmd(%w(activation-key content-override id=20 --content-label=foo --value=1 --override-name=protected))
assert_equal 64, result.exit_code
end

it "removes override" do
label = "foo"
id = 20
Expand Down
4 changes: 0 additions & 4 deletions test/functional/activation_key/list_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
end

ex.returns(empty_response)
# rubocop:disable Layout/LineLength
expected_result = success_result("---|------|------------|---------------------------|-------------------------------
ID | NAME | HOST LIMIT | CONTENT VIEW ENVIRONMENTS | MULTI CONTENT VIEW ENVIRONMENT
---|------|------------|---------------------------|-------------------------------
Expand All @@ -44,7 +43,6 @@
result = run_cmd(@cmd + params)
assert_cmd(expected_result, result)
end
# rubocop:enable Layout/LineLength

it "lists the activation-keys belonging to a lifecycle environment by name" do
params = ["--organization-id=#{org_id}", '--lifecycle-environment=test']
Expand All @@ -57,7 +55,6 @@
end

ex.returns(empty_response)
# rubocop:disable Layout/LineLength
expected_result = success_result("---|------|------------|---------------------------|-------------------------------
ID | NAME | HOST LIMIT | CONTENT VIEW ENVIRONMENTS | MULTI CONTENT VIEW ENVIRONMENT
---|------|------------|---------------------------|-------------------------------
Expand All @@ -66,5 +63,4 @@
result = run_cmd(@cmd + params)
assert_cmd(expected_result, result)
end
# rubocop:enable Layout/LineLength
end
6 changes: 0 additions & 6 deletions test/functional/content_export/list_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@
ex = api_expects(:content_exports, :index)

ex.returns(empty_response)
# rubocop:disable LineLength
expected_result = success_result('---|--------------------|------|------|----------------------|-------------------------|------------|-----------
ID | DESTINATION SERVER | PATH | TYPE | CONTENT VIEW VERSION | CONTENT VIEW VERSION ID | CREATED AT | UPDATED AT
---|--------------------|------|------|----------------------|-------------------------|------------|-----------
')
# rubocop:enable LineLength
result = run_cmd(%w(content-export list))
assert_cmd(expected_result, result)
end
Expand All @@ -38,12 +36,10 @@
ex = api_expects(:content_exports, :index)

ex.returns(empty_response)
# rubocop:disable LineLength
expected_result = success_result('---|--------------------|------|------|----------------------|-------------------------|------------|-----------
ID | DESTINATION SERVER | PATH | TYPE | CONTENT VIEW VERSION | CONTENT VIEW VERSION ID | CREATED AT | UPDATED AT
---|--------------------|------|------|----------------------|-------------------------|------------|-----------
')
# rubocop:enable LineLength
result = run_cmd(%w(content-export list --content-view-id=1))
assert_cmd(expected_result, result)
end
Expand All @@ -52,12 +48,10 @@
ex = api_expects(:content_exports, :index)

ex.returns(empty_response)
# rubocop:disable LineLength
expected_result = success_result('---|--------------------|------|------|----------------------|-------------------------|------------|-----------
ID | DESTINATION SERVER | PATH | TYPE | CONTENT VIEW VERSION | CONTENT VIEW VERSION ID | CREATED AT | UPDATED AT
---|--------------------|------|------|----------------------|-------------------------|------------|-----------
')
# rubocop:enable LineLength
result = run_cmd(%w(content-export list --content-view-version-id=1))
assert_cmd(expected_result, result)
end
Expand Down
6 changes: 0 additions & 6 deletions test/functional/content_import/list_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@

ex.returns(empty_response)

# rubocop:disable LineLength
expected_result = success_result('---|------|------|----------------------|-------------------------|------------|-----------
ID | PATH | TYPE | CONTENT VIEW VERSION | CONTENT VIEW VERSION ID | CREATED AT | UPDATED AT
---|------|------|----------------------|-------------------------|------------|-----------
')
# rubocop:enable LineLength
result = run_cmd(%w(content-import list))
assert_cmd(expected_result, result)
end
Expand All @@ -39,12 +37,10 @@
ex = api_expects(:content_imports, :index)

ex.returns(empty_response)
# rubocop:disable LineLength
expected_result = success_result('---|------|------|----------------------|-------------------------|------------|-----------
ID | PATH | TYPE | CONTENT VIEW VERSION | CONTENT VIEW VERSION ID | CREATED AT | UPDATED AT
---|------|------|----------------------|-------------------------|------------|-----------
')
# rubocop:enable LineLength
result = run_cmd(%w(content-import list --content-view-id=1))
assert_cmd(expected_result, result)
end
Expand All @@ -53,12 +49,10 @@
ex = api_expects(:content_imports, :index)

ex.returns(empty_response)
# rubocop:disable LineLength
expected_result = success_result('---|------|------|----------------------|-------------------------|------------|-----------
ID | PATH | TYPE | CONTENT VIEW VERSION | CONTENT VIEW VERSION ID | CREATED AT | UPDATED AT
---|------|------|----------------------|-------------------------|------------|-----------
')
# rubocop:enable LineLength
result = run_cmd(%w(content-import list --content-view-version-id=1))
assert_cmd(expected_result, result)
end
Expand Down
4 changes: 0 additions & 4 deletions test/functional/content_units/list_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,13 @@ module HammerCLIKatello
assert(r.err.include?("--product, --product-id is required"), "Invalid error message")
end

# rubocop:disable LineLength
it 'may be specified by name and product ID' do
expect_repository_search(2, 'repo1', 1)

api_expects(:generic_content_units, :index)
.with_params('content_type' => 'python_package', 'repository_id' => 1)
run_cmd(%w(content-units list --content-type python_package --repository repo1 --product-id 2))
end
# rubocop:enable LineLength
end

describe 'organization options' do
Expand Down Expand Up @@ -78,7 +76,6 @@ module HammerCLIKatello
end

describe 'content-view options' do
# rubocop:disable LineLength
it 'may be specified by ID' do
api_expects(:content_view_versions, :index)
.with_params('content_view_id' => 1, 'version' => '2.1')
Expand All @@ -100,7 +97,6 @@ module HammerCLIKatello
expected_error = "--organization-id, --organization, --organization-label is required"
assert(r.err.include?(expected_error), "Invalid error message")
end
# rubocop:enable LineLength
end
end
end
38 changes: 34 additions & 4 deletions test/functional/host/subscription/content_override_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
@cmd = %w(host subscription content-override)
end

it "attaches a content label" do
it "attaches a content override" do
label = "foo"
value = 'default'
value = 'enabled'
id = '20'
params = ["--host-id=#{id}", "--content-label=#{label}", "--value=#{value}"]
ex = api_expects(:host_subscriptions, :content_override, "content override") do |par|
Expand All @@ -27,9 +27,9 @@
assert_cmd(expected_result, result)
end

it "attaches a content label with name" do
it "attaches a content override with name" do
label = "foo"
value = '1'
value = 'enabled'
id = '20'
name = 'protected'
params = ["--host-id=#{id}", "--content-label=#{label}", "--value=#{value}",
Expand All @@ -47,6 +47,36 @@
assert_cmd(expected_result, result)
end

it "attaches a content override with value other than enabled using --force" do
label = "foo"
value = 'enabled'
id = '20'
name = 'protected'
params = ["--host-id=#{id}", "--content-label=#{label}", "--value=#{value}",
"--override-name=#{name}", "--force"]
ex = api_expects(:host_subscriptions, :content_override, "content override") do |par|
par['host_id'].to_s == id && par["content_overrides"][0]['content_label'] == label &&
par['content_overrides'][0]['value'] == value &&
par['content_overrides'][0]['name'] == name
end
ex.returns({})

expected_result = success_result("Updated content override.\n")

result = run_cmd(@cmd + params)
assert_cmd(expected_result, result)
end

it "attaches a content override with value other than enabled without --force" do
api_expects_no_call
error_msg = "Could not update content override:\n" \
" You must use --force to set a value other than 'enabled'"

assert_failure run_cmd(%w(host subscription content-override --host-id=20 --content-label=foo --value=1 --override-name=protected)), error_msg
result = run_cmd(%w(host subscription content-override --host-id=20 --content-label=foo --value=1 --override-name=protected))
assert_equal 64, result.exit_code
end

it "removes override" do
label = "foo"
id = '20'
Expand Down
2 changes: 0 additions & 2 deletions test/functional/repository/update_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ module HammerCLIKatello
.with_params('id' => upload_id, 'repository_id' => repo_id)

ex3.returns("")
# rubocop:disable LineLength
result = run_cmd(%W(repository update --id #{repo_id} --docker-tag #{tag_name} --docker-digest #{digest}))
# rubocop:enable LineLength
assert_equal(result.exit_code, 0)
end
end
Expand Down
Loading

0 comments on commit 3006975

Please sign in to comment.