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

Fixes #37865 - Add Multi environments to activation key info #958

Merged
merged 1 commit into from
Oct 21, 2024
Merged
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 hammer_cli_katello.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Gem::Specification.new do |gem|
"Zach Huntington-Meath"
]
gem.email = ['[email protected]']
gem.license = "GPL-3.0"
gem.license = "GPL-3.0-or-later"
gem.description = 'Hammer-CLI-Katello is a plugin for Hammer to provide' \
' connectivity to a Katello server.'
gem.summary = 'Katello commands for Hammer'
Expand Down
72 changes: 46 additions & 26 deletions lib/hammer_cli_katello/activation_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,9 @@ class ListCommand < HammerCLIKatello::ListCommand
field :id, _("Id")
field :name, _("Name")
field :format_consumed, _("Host Limit")
from :environment do
field :name, _("Lifecycle Environment")
end
from :content_view do
field :name, _("Content View")
end
field :content_view_environment_labels, _("Content View Environments"),
Fields::List, :max_width => 300
field :multi_content_view_environment, _("Multi Content View Environment"), Fields::Boolean
end

def extend_data(data)
Expand Down Expand Up @@ -56,41 +53,63 @@ def request_params
field :id, _("Id")
field :description, _("Description"), Fields::Field, :hide_blank => true
field :format_consumed, _("Host Limit")
field :auto_attach, _("Auto Attach")
field :multi_content_view_environment, _("Multi Content View Environment"), Fields::Boolean
field :release_version, _("Release Version"), Fields::Field, :hide_blank => true
field :content_view_environment_labels, _("Content View Environments"), Fields::Field

from :environment do
field :name, _("Lifecycle Environment")
collection :organization, _("Organization") do
field :id, _("Id"), Fields::Field, :hide_blank => true
field :name, _("Name"), Fields::Field, :hide_blank => true
end
from :content_view do
field :name, _("Content View")

collection :content_view_environments, _('Content View Environments') do
from :content_view do
label _("Content View") do
field :id, _("Id")
field :name, _("Name")
field :content_view_version, _("Version")
field :content_view_version_id, _("Content View version Id")
field :composite, _("Composite"), Fields::Boolean
field :content_view_environment_id, _("Content View Environment id"), Fields::Field
end
end
from :lifecycle_environment do
label _("Lifecycle environment") do
field :id, _("Id")
field :name, _("Name")
end
end
field :label, _("Label")
end

collection :hosts, _("Associated Hosts") do
field :id, _('Id')
field :name, _("Name")
collection :hosts, _("Associated Hosts"), hide_blank: true, hide_empty: true do
field :id, _('Id'), Fields::Field, :hide_blank => true
field :name, _("Name"), Fields::Field, :hide_blank => true
end

collection :host_collections, _("Host Collections") do
field :id, _("Id")
field :name, _("Name")
collection :host_collections, _("Host Collections"), hide_blank: true, hide_empty: true do
field :id, _("Id"), Fields::Field, :hide_blank => true
field :name, _("Name"), Fields::Field, :hide_blank => true
end

collection :content_overrides, _("Content Overrides") do
field :content_label, _("Content Label")
field :name, _("Name")
field :value, _("Value")
collection :content_overrides, _("Content Overrides"), hide_blank: true, hide_empty: true do
field :content_label, _("Content Label"), Fields::Field, :hide_blank => true
field :name, _("Name"), Fields::Field, :hide_blank => true
field :value, _("Value"), Fields::Field, :hide_blank => true
end

label _("System Purpose") do
field :service_level, _('Service Level')
field :purpose_usage, _('Purpose Usage')
field :purpose_role, _('Purpose Role')
field :purpose_addons, _('Purpose Addons'), Fields::List
label _("System Purpose"), hide_blank: true, hide_empty: true do
field :service_level, _('Service Level'), Fields::Field, :hide_blank => true
field :purpose_usage, _('Purpose Usage'), Fields::Field, :hide_blank => true
field :purpose_role, _('Purpose Role'), Fields::Field, :hide_blank => true
field :purpose_addons, _('Purpose Addons'), Fields::List, :hide_blank => true
end
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
limit = data["unlimited_hosts"] ? _("Unlimited") : data["max_hosts"]

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

build_options
Expand Down
1 change: 1 addition & 0 deletions test/data/4.14/foreman_api.json

Large diffs are not rendered by default.

44 changes: 43 additions & 1 deletion test/functional/activation_key/data/activation_key.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,47 @@
"name": "Library",
"id": 1
},
"purpose_addons": "Test Addon1, Test Addon2"
"purpose_addons": "Test Addon1, Test Addon2",
"multi_content_view_environment": true,
"organization": {
"name": "Default Organization",
"label": "Default_Organization",
"id": 1
},
"content_view_environments": [
{
"content_view": {
"id": 2,
"name": "RHEL-8",
"composite": false,
"content_view_version": "1.0",
"content_view_version_id": 4,
"content_view_version_latest": true,
"content_view_default": false
},
"lifecycle_environment": {
"id": 1,
"name": "Library",
"lifecycle_environment_library": true
},
"label": "Library/RHEL-8"
},
{
"content_view": {
"id": 4,
"name": "Zoo",
"composite": false,
"content_view_version": "1.0",
"content_view_version_id": 2,
"content_view_version_latest": true,
"content_view_default": false
},
"lifecycle_environment": {
"id": 2,
"name": "Dev",
"lifecycle_environment_library": false
},
"label": "Dev/Zoo"
}
]
}
30 changes: 28 additions & 2 deletions test/functional/activation_key/info_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,37 @@

result = run_cmd(@cmd + params)

expected_fields = [['Description', 'Activation key'],
expected_fields = [['Name', 'test key2'],
['Id', '1'],
['Description', 'Activation key'],
['Purpose Usage', 'Usage'],
['Purpose Role', 'Role'],
['Purpose Addons', 'Test Addon1, Test Addon2'],
['Lifecycle Environment', 'Library']]
['Multi Content View Environment', 'yes'],
['Organization', ''],
['Id', '1'],
['Name', 'Default Organization'],
['Content View Environments', ''],
['Content View', ''],
['Id', '2'],
['Name', 'RHEL-8'],
['Version', '1.0'],
['Content View version Id', '4'],
['Composite', 'no'],
['Lifecycle environment', ''],
['Id', '1'],
['Name', 'Library'],
['Label', 'Library/RHEL-8'],
['Content View', ''],
['Id', '4'],
['Name', 'Zoo'],
['Version', '1.0'],
['Content View version Id', '2'],
['Composite', 'no'],
['Lifecycle environment', ''],
['Id', '2'],
['Name', 'Dev'],
['Label', 'Dev/Zoo']]

expected_results = expected_fields.map { |field| success_result(FieldMatcher.new(*field)) }
expected_results.each { |expected| assert_cmd(expected, result) }
Expand Down
18 changes: 10 additions & 8 deletions test/functional/activation_key/list_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,16 @@
end

ex.returns(empty_response)

expected_result = success_result("---|------|------------|-----------------------|-------------
ID | NAME | HOST LIMIT | LIFECYCLE ENVIRONMENT | CONTENT VIEW
---|------|------------|-----------------------|-------------
# rubocop:disable Layout/LineLength
expected_result = success_result("---|------|------------|---------------------------|-------------------------------
ID | NAME | HOST LIMIT | CONTENT VIEW ENVIRONMENTS | MULTI CONTENT VIEW ENVIRONMENT
---|------|------------|---------------------------|-------------------------------
")

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 @@ -56,13 +57,14 @@
end

ex.returns(empty_response)

expected_result = success_result("---|------|------------|-----------------------|-------------
ID | NAME | HOST LIMIT | LIFECYCLE ENVIRONMENT | CONTENT VIEW
---|------|------------|-----------------------|-------------
# rubocop:disable Layout/LineLength
expected_result = success_result("---|------|------------|---------------------------|-------------------------------
ID | NAME | HOST LIMIT | CONTENT VIEW ENVIRONMENTS | MULTI CONTENT VIEW ENVIRONMENT
---|------|------------|---------------------------|-------------------------------
")

result = run_cmd(@cmd + params)
assert_cmd(expected_result, result)
end
# rubocop:enable Layout/LineLength
end
1 change: 0 additions & 1 deletion test/functional/repository/update_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ module HammerCLIKatello # rubocop:disable Metrics/ModuleLength
}
end
it "adds a tag to an image" do
skip "Until we https://projects.theforeman.org/issues/34817 is resolved"
ex = api_expects(:content_uploads, :create)
.with_params('repository_id' => repo_id, :size => 0)

Expand Down
2 changes: 1 addition & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
require 'hammer_cli'
require 'ostruct'

KATELLO_VERSION = Gem::Version.new(ENV['TEST_API_VERSION'] || '4.10')
KATELLO_VERSION = Gem::Version.new(ENV['TEST_API_VERSION'] || '4.14')

if HammerCLI.context[:api_connection]
HammerCLI.context[:api_connection].create('foreman') do
Expand Down