hammer_cli_foreman 2.4.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. checksums.yaml +4 -4
  2. data/doc/release_notes.md +40 -0
  3. data/lib/hammer_cli_foreman/architecture.rb +5 -5
  4. data/lib/hammer_cli_foreman/associating_commands.rb +0 -24
  5. data/lib/hammer_cli_foreman/bookmark.rb +5 -5
  6. data/lib/hammer_cli_foreman/combination.rb +3 -13
  7. data/lib/hammer_cli_foreman/command_extensions/ping.rb +21 -2
  8. data/lib/hammer_cli_foreman/command_extensions/subnet.rb +25 -10
  9. data/lib/hammer_cli_foreman/command_extensions/update_common.rb +14 -0
  10. data/lib/hammer_cli_foreman/command_extensions/user.rb +9 -5
  11. data/lib/hammer_cli_foreman/command_extensions.rb +1 -2
  12. data/lib/hammer_cli_foreman/commands.rb +17 -11
  13. data/lib/hammer_cli_foreman/compute_attribute.rb +1 -1
  14. data/lib/hammer_cli_foreman/compute_profile.rb +5 -5
  15. data/lib/hammer_cli_foreman/compute_resource/ovirt.rb +2 -1
  16. data/lib/hammer_cli_foreman/compute_resource.rb +23 -0
  17. data/lib/hammer_cli_foreman/config_report.rb +2 -0
  18. data/lib/hammer_cli_foreman/filter.rb +2 -2
  19. data/lib/hammer_cli_foreman/host.rb +1 -47
  20. data/lib/hammer_cli_foreman/hostgroup.rb +14 -58
  21. data/lib/hammer_cli_foreman/hosts/common_update_options.rb +10 -31
  22. data/lib/hammer_cli_foreman/id_resolver.rb +7 -68
  23. data/lib/hammer_cli_foreman/location.rb +0 -6
  24. data/lib/hammer_cli_foreman/mail_notification.rb +2 -2
  25. data/lib/hammer_cli_foreman/model.rb +5 -5
  26. data/lib/hammer_cli_foreman/operating_system.rb +10 -10
  27. data/lib/hammer_cli_foreman/option_builders.rb +84 -52
  28. data/lib/hammer_cli_foreman/option_sources/id_params.rb +41 -11
  29. data/lib/hammer_cli_foreman/option_sources/ids_params.rb +39 -7
  30. data/lib/hammer_cli_foreman/option_sources.rb +0 -1
  31. data/lib/hammer_cli_foreman/organization.rb +0 -6
  32. data/lib/hammer_cli_foreman/ping.rb +6 -1
  33. data/lib/hammer_cli_foreman/references.rb +0 -16
  34. data/lib/hammer_cli_foreman/registration.rb +18 -0
  35. data/lib/hammer_cli_foreman/settings.rb +3 -3
  36. data/lib/hammer_cli_foreman/smart_proxy.rb +7 -57
  37. data/lib/hammer_cli_foreman/template.rb +3 -15
  38. data/lib/hammer_cli_foreman/user.rb +4 -4
  39. data/lib/hammer_cli_foreman/usergroup.rb +5 -5
  40. data/lib/hammer_cli_foreman/version.rb +1 -1
  41. data/lib/hammer_cli_foreman.rb +3 -21
  42. data/lib/minitest/coverage_reporter.rb +1 -1
  43. data/locale/ca/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  44. data/locale/de/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  45. data/locale/en/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  46. data/locale/en_GB/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  47. data/locale/es/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  48. data/locale/fr/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  49. data/locale/it/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  50. data/locale/ja/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  51. data/locale/ko/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  52. data/locale/pt_BR/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  53. data/locale/ru/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  54. data/locale/zh_CN/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  55. data/locale/zh_TW/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  56. data/test/data/2.4/foreman_api.json +1 -0
  57. data/test/data/2.5/foreman_api.json +1 -0
  58. data/test/data/3.1/foreman_api.json +1 -0
  59. data/test/functional/architecture_test.rb +37 -5
  60. data/test/functional/bookmark_test.rb +5 -2
  61. data/test/functional/compute_attribute_test.rb +20 -20
  62. data/test/functional/compute_profile_test.rb +14 -1
  63. data/test/functional/compute_resource_test.rb +37 -0
  64. data/test/functional/filter_test.rb +2 -1
  65. data/test/functional/host_test.rb +65 -11
  66. data/test/functional/hostgroup/create_test.rb +11 -117
  67. data/test/functional/hostgroup/update_test.rb +11 -79
  68. data/test/functional/http_proxy_test.rb +12 -0
  69. data/test/functional/location_test.rb +13 -3
  70. data/test/functional/mail_notification_test.rb +3 -1
  71. data/test/functional/media_test.rb +11 -0
  72. data/test/functional/model_test.rb +3 -1
  73. data/test/functional/operating_system_test.rb +3 -1
  74. data/test/functional/personal_access_token_test.rb +4 -4
  75. data/test/functional/ping_test.rb +33 -0
  76. data/test/functional/realm_test.rb +11 -0
  77. data/test/functional/registration_test.rb +8 -0
  78. data/test/functional/report_template_test.rb +11 -0
  79. data/test/functional/settings_test.rb +4 -4
  80. data/test/functional/template_test.rb +87 -48
  81. data/test/functional/user_mail_notification_test.rb +3 -3
  82. data/test/functional/user_test.rb +11 -0
  83. data/test/functional/usergroup_test.rb +3 -1
  84. data/test/test_helper.rb +1 -1
  85. data/test/unit/apipie_resource_mock.rb +1 -39
  86. data/test/unit/architecture_test.rb +10 -10
  87. data/test/unit/bookmark_test.rb +10 -14
  88. data/test/unit/commands_test.rb +1 -2
  89. data/test/unit/compute_profile_test.rb +10 -10
  90. data/test/unit/config_report_test.rb +1 -0
  91. data/test/unit/helpers/command.rb +0 -8
  92. data/test/unit/host_test.rb +14 -61
  93. data/test/unit/hostgroup_test.rb +7 -26
  94. data/test/unit/id_resolver_test.rb +0 -28
  95. data/test/unit/mail_notification_test.rb +4 -4
  96. data/test/unit/model_test.rb +47 -47
  97. data/test/unit/operating_system_test.rb +10 -16
  98. data/test/unit/option_builders_test.rb +88 -83
  99. data/test/unit/settings_test.rb +4 -4
  100. data/test/unit/smart_proxy_test.rb +0 -12
  101. data/test/unit/usergroup_test.rb +10 -10
  102. metadata +115 -128
  103. data/lib/hammer_cli_foreman/command_extensions/puppet_environment.rb +0 -29
  104. data/lib/hammer_cli_foreman/command_extensions/puppet_environments.rb +0 -29
  105. data/lib/hammer_cli_foreman/config_group.rb +0 -45
  106. data/lib/hammer_cli_foreman/option_sources/puppet_environment_params.rb +0 -59
  107. data/lib/hammer_cli_foreman/puppet_class.rb +0 -61
  108. data/lib/hammer_cli_foreman/puppet_environment.rb +0 -65
  109. data/lib/hammer_cli_foreman/smart_class_parameter.rb +0 -189
  110. data/test/functional/config_group_test.rb +0 -50
  111. data/test/functional/proxy_test.rb +0 -86
  112. data/test/functional/smart_class_parameter_test.rb +0 -97
  113. data/test/reports/TEST-Minitest-Result.xml +0 -4344
  114. data/test/unit/config_group_test.rb +0 -82
  115. data/test/unit/puppet_class_test.rb +0 -72
  116. data/test/unit/puppet_environment_test.rb +0 -114
  117. data/test/unit/smart_class_parameter_test.rb +0 -113
@@ -1,65 +0,0 @@
1
- require 'hammer_cli'
2
- require 'hammer_cli_foreman/smart_class_parameter'
3
-
4
- module HammerCLIForeman
5
-
6
- class PuppetEnvironment < HammerCLIForeman::Command
7
-
8
- resource :environments
9
-
10
- class ListCommand < HammerCLIForeman::ListCommand
11
-
12
- output do
13
- field :id, _("Id")
14
- field :name, _("Name")
15
- end
16
-
17
- build_options
18
- end
19
-
20
-
21
- class InfoCommand < HammerCLIForeman::InfoCommand
22
- output ListCommand.output_definition do
23
- HammerCLIForeman::References.puppetclasses(self)
24
- HammerCLIForeman::References.taxonomies(self)
25
- HammerCLIForeman::References.timestamps(self)
26
- end
27
-
28
- build_options
29
- end
30
-
31
-
32
- class CreateCommand < HammerCLIForeman::CreateCommand
33
- success_message _("Environment created.")
34
- failure_message _("Could not create the environment")
35
-
36
- build_options
37
- end
38
-
39
-
40
- class UpdateCommand < HammerCLIForeman::UpdateCommand
41
- success_message _("Environment updated.")
42
- failure_message _("Could not update the environment")
43
-
44
- build_options
45
- end
46
-
47
-
48
- class DeleteCommand < HammerCLIForeman::DeleteCommand
49
- success_message _("Environment deleted.")
50
- failure_message _("Could not delete the environment")
51
-
52
- build_options
53
- end
54
-
55
- class SCParamsCommand < HammerCLIForeman::SmartClassParametersList
56
- build_options_for :environments
57
-
58
- extend_with(HammerCLIForeman::CommandExtensions::PuppetEnvironment.new)
59
- end
60
-
61
-
62
- autoload_subcommands
63
- end
64
-
65
- end
@@ -1,189 +0,0 @@
1
- module HammerCLIForeman
2
-
3
- class SmartClassParametersBriefList < HammerCLIForeman::ListCommand
4
- resource :smart_class_parameters, :index
5
- command_name 'sc-params'
6
-
7
- output do
8
- field :id, _("Id")
9
-
10
- field :parameter, _("Parameter")
11
- field :default_value, _("Default Value")
12
- field :override, _("Override")
13
- end
14
-
15
- def send_request
16
- res = super
17
- # FIXME: API returns doubled records, probably just if filtered by puppetclasses
18
- # it seems group by environment is missing
19
- # having the uniq to fix that
20
- HammerCLI::Output::RecordCollection.new(res.uniq, :meta => res.meta)
21
- end
22
-
23
- def self.build_options_for(resource)
24
- options = {}
25
- options[:without] = [:host_id, :puppetclass_id, :environment_id, :hostgroup_id]
26
- options[:expand] = {}
27
- options[:expand][:except] = ([:hosts, :puppetclasses, :environments, :hostgroups] - [resource])
28
- build_options(options)
29
- end
30
- end
31
-
32
- class SmartClassParametersList < SmartClassParametersBriefList
33
-
34
- output do
35
- field :puppetclass_name, _("Puppet class")
36
- field :puppetclass_id, _("Class Id"), Fields::Id
37
- end
38
- end
39
-
40
- class SmartClassParameter < HammerCLIForeman::Command
41
-
42
- resource :smart_class_parameters
43
-
44
- class ListCommand < HammerCLIForeman::ListCommand
45
-
46
- output SmartClassParametersList.output_definition
47
-
48
- def extend_data(res)
49
- res['parameter_type'] ||= 'string'
50
- res
51
- end
52
-
53
- build_options
54
-
55
- extend_with(HammerCLIForeman::CommandExtensions::PuppetEnvironment.new)
56
- end
57
-
58
- class InfoCommand < HammerCLIForeman::InfoCommand
59
-
60
- output ListCommand.output_definition do
61
- field :description, _("Description")
62
- field :parameter_type, _("Type")
63
- field :hidden_value?, _("Hidden Value?")
64
- field :omit, _("Omit"), Fields::Boolean
65
- field :required, _("Required")
66
-
67
- label _("Validator") do
68
- field :validator_type, _("Type")
69
- field :validator_rule, _("Rule")
70
- end
71
- label _("Override values") do
72
- field :merge_overrides, _("Merge overrides"), Fields::Boolean
73
- field :merge_default, _("Merge default value"), Fields::Boolean
74
- field :avoid_duplicates, _("Avoid duplicates"), Fields::Boolean
75
- field :override_value_order, _("Order"), Fields::LongText
76
-
77
- collection :override_values, _("Values") do
78
- field :id, _('Id')
79
- field :match, _('Match')
80
- field :value, _('Value')
81
- field :omit, _('Omit'), Fields::Boolean
82
- end
83
- end
84
- HammerCLIForeman::References.environments(self)
85
- HammerCLIForeman::References.timestamps(self)
86
- end
87
-
88
- def extend_data(res)
89
- res['parameter_type'] ||= 'string'
90
- res['omit'] ||= false
91
- res
92
- end
93
-
94
- build_options do |options|
95
- options.expand.including(:puppetclasses)
96
- end
97
-
98
- validate_options do
99
- if option(:option_name).exist?
100
- any(:option_puppetclass_name, :option_puppetclass_id).required
101
- end
102
- end
103
- end
104
-
105
- class UpdateCommand < HammerCLIForeman::UpdateCommand
106
-
107
- success_message _("Parameter updated.")
108
- failure_message _("Could not update the parameter")
109
-
110
- option '--default-value', 'VALUE', _('Value to use when there is no match')
111
-
112
- build_options do |options|
113
- options.expand.including(:puppetclasses)
114
- options.without(:parameter_type, :validator_type, :override, :required, :override_value_order)
115
- end
116
-
117
- option "--override", "OVERRIDE", _("Override this parameter"),
118
- :format => HammerCLI::Options::Normalizers::Bool.new
119
- option "--required", "REQUIRED", _("This parameter is required"),
120
- :format => HammerCLI::Options::Normalizers::Bool.new
121
- option "--parameter-type", "PARAMETER_TYPE", _("Type of the parameter"),
122
- :format => HammerCLI::Options::Normalizers::Enum.new(
123
- ['string', 'boolean', 'integer', 'real', 'array', 'hash', 'yaml', 'json'])
124
- option "--validator-type", "VALIDATOR_TYPE", _("Type of the validator"),
125
- :format => HammerCLI::Options::Normalizers::Enum.new(['regexp', 'list', ''])
126
- option "--override-value-order", "OVERRIDE_VALUE_ORDER", _("The order in which values are resolved"),
127
- :format => HammerCLI::Options::Normalizers::List.new
128
-
129
- validate_options do
130
- if option(:option_name).exist?
131
- any(:option_puppetclass_name, :option_puppetclass_id).required
132
- end
133
- end
134
-
135
- def request_params
136
- params = super
137
- override_order = params['smart_class_parameter']['override_value_order']
138
- params['smart_class_parameter']['override_value_order'] = override_order.join("\n") if override_order.is_a?(Array)
139
- params
140
- end
141
- end
142
-
143
- class AddMatcherCommand < HammerCLIForeman::CreateCommand
144
- resource :override_values
145
- command_name 'add-matcher'
146
-
147
- option '--value', 'VALUE', _('Override value, required if omit is false')
148
-
149
- success_message _("Override value created.")
150
- failure_message _("Could not create the override value")
151
-
152
- build_options do |options|
153
- options.expand.including(:puppetclasses)
154
- end
155
-
156
- validate_options do
157
- if option(:option_omit).value
158
- option(:option_value).rejected(:msg => _('Cannot use --value when --omit is true.'))
159
- end
160
-
161
- if option(:option_smart_class_parameter_name).exist?
162
- any(:option_puppetclass_name, :option_puppetclass_id).required
163
- end
164
- end
165
- end
166
-
167
- class RemoveMatcherCommand < HammerCLIForeman::DeleteCommand
168
- resource :override_values
169
- command_name 'remove-matcher'
170
-
171
- success_message _("Override value deleted.")
172
- failure_message _("Could not delete the override value")
173
-
174
- build_options do |options|
175
- options.expand.including(:puppetclasses)
176
- end
177
-
178
- validate_options do
179
- if option(:option_smart_class_parameter_name).exist?
180
- any(:option_puppetclass_name, :option_puppetclass_id).required
181
- end
182
- end
183
- end
184
-
185
- autoload_subcommands
186
-
187
- end
188
-
189
- end
@@ -1,50 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require File.join(File.dirname(__FILE__), 'test_helper')
4
-
5
- describe 'config_group' do
6
- describe 'list' do
7
- before do
8
- @cmd = %w[config-group list]
9
- @config_groups = [{
10
- id: 1,
11
- name: 'config-group-test',
12
- }]
13
- end
14
-
15
- it 'should return a list of config groups' do
16
- api_expects(:config_groups, :index, 'List config groups').returns(@config_groups)
17
-
18
- output = IndexMatcher.new([
19
- %w[ID NAME],
20
- %w[1 config-group-test]
21
- ])
22
- expected_result = success_result(output)
23
-
24
- result = run_cmd(@cmd)
25
- assert_cmd(expected_result, result)
26
- end
27
-
28
- it 'should run list command with defaults' do
29
- providers = { 'foreman' => HammerCLIForeman::Defaults.new(api_connection({}, '2.1')) }
30
- defaults = HammerCLI::Defaults.new(
31
- {
32
- organization_id: {
33
- provider: 'foreman'
34
- },
35
- location_id: {
36
- provider: 'foreman'
37
- }
38
- }
39
- )
40
- defaults.stubs(:write_to_file).returns(true)
41
- defaults.stubs(:providers).returns(providers)
42
- api_expects(:config_groups, :index, 'List config groups').returns(@config_groups)
43
-
44
- result = run_cmd(@cmd, { use_defaults: true, defaults: defaults })
45
- _(result.exit_code).must_equal HammerCLI::EX_OK
46
- end
47
- end
48
- end
49
-
50
-
@@ -1,86 +0,0 @@
1
- require File.join(File.dirname(__FILE__), 'test_helper')
2
-
3
- describe 'proxy' do
4
- describe 'import-classes' do
5
- let(:cmd) { ['proxy', 'import-classes'] }
6
- let(:params) { ['--id=83'] }
7
- let(:report) do
8
- {
9
- 'message' => 'Successfully updated environment and puppetclasses from the on-disk puppet installation',
10
- 'environments_with_new_puppetclasses' => 2,
11
- 'environments_updated_puppetclasses' => 0,
12
- 'environments_obsolete' => 0,
13
- 'environments_ignored' => 0,
14
- 'results' => [{
15
- 'name' => 'development',
16
- 'actions' => [ 'new', 'update' ],
17
- 'new_puppetclasses' => [
18
- 'motd',
19
- 'hammer'
20
- ],
21
- 'updated_puppetclasses' => [
22
- 'stdlib',
23
- 'vim'
24
- ]
25
- },{
26
- 'name' => 'production',
27
- 'actions' => [ 'obsolete', 'ignore' ],
28
- 'obsolete_puppetclasses' => [
29
- 'apache'
30
- ],
31
- 'ignored_puppetclasses' => [
32
- 'hammer'
33
- ]
34
- }]
35
- }
36
- end
37
- let(:no_change_report) do
38
- {
39
- 'message' => 'No changes to your environments detected'
40
- }
41
- end
42
-
43
- it 'prints detailed report' do
44
- api_expects(:smart_proxies, :import_puppetclasses, 'Import classes')
45
- .with_params('id' => '83')
46
- .returns(report)
47
-
48
- output = OutputMatcher.new([
49
- 'Result:',
50
- ' Successfully updated environment and puppetclasses from the on-disk puppet installation',
51
- 'Changed environments:',
52
- ' 1) development',
53
- ' New classes:',
54
- ' motd',
55
- ' hammer',
56
- ' Updated classes:',
57
- ' stdlib',
58
- ' vim',
59
- ' 2) production',
60
- ' Removed classes:',
61
- ' apache',
62
- ' Ignored classes:',
63
- ' hammer'
64
- ])
65
- expected_result = success_result(output)
66
-
67
- result = run_cmd(cmd + params)
68
- assert_cmd(expected_result, result)
69
- end
70
-
71
- it 'prints a message when nothig has changed' do
72
- api_expects(:smart_proxies, :import_puppetclasses, 'Import classes')
73
- .with_params('id' => '83')
74
- .returns(no_change_report)
75
-
76
- output = OutputMatcher.new([
77
- 'Result:',
78
- ' No changes to your environments detected'
79
- ])
80
- expected_result = success_result(output)
81
-
82
- result = run_cmd(cmd + params)
83
- assert_cmd(expected_result, result)
84
- end
85
- end
86
- end
@@ -1,97 +0,0 @@
1
- require File.join(File.dirname(__FILE__), 'test_helper')
2
-
3
-
4
- describe 'sc-params update' do
5
- let(:cmd) { %w(sc-param update) }
6
-
7
- it 'does not allow to update parameter name' do
8
- params = ['--id=1', '--new-name=name2']
9
-
10
- expected_result = usage_error_result(
11
- cmd,
12
- "Unrecognised option '--new-name'.",
13
- "Could not update the parameter"
14
- )
15
-
16
- api_expects_no_call
17
- result = run_cmd(cmd + params)
18
- assert_cmd(expected_result, result)
19
- end
20
-
21
- end
22
-
23
- describe 'sc-params add-matcher' do
24
- let(:cmd) { %w(sc-param add-matcher) }
25
- let(:override_value) { 'something' }
26
- let(:match) { 'domain = example.com' }
27
- let(:puppet_class) { { 'name' => 'motd', 'id' => '1' } }
28
- let(:parameter) { { 'name' => 'content', 'id' => '2' } }
29
- let(:base) { [
30
- '--puppet-class', puppet_class['name'],
31
- '--smart-class-parameter', parameter['name'],
32
- '--match', match
33
- ] }
34
-
35
- def api_expects_parameter_search(puppet_class, parameter)
36
- api_expects(:puppetclasses, :index, 'Find puppet class') do |par|
37
- par[:search] == %Q(name = "#{puppet_class['name']}")
38
- end.returns(index_response('motd' => [puppet_class]))
39
-
40
- api_expects(:smart_class_parameters, :index, 'Find smart parameter') do |par|
41
- par[:search] == %Q(key = "#{parameter['name']}") &&
42
- par[:puppetclass_id] == puppet_class['id']
43
- end.returns(index_response([parameter]))
44
- end
45
-
46
- it 'allows to set value' do
47
- params = ['--value', override_value]
48
- expected_result = success_result("Override value created.\n")
49
-
50
- api_expects_parameter_search(puppet_class, parameter)
51
-
52
- api_expects(:override_values, :create, 'Create override value').with_params(
53
- :smart_class_parameter_id => parameter['id'],
54
- :override_value => {
55
- :match => match,
56
- :value => override_value
57
- }
58
- )
59
-
60
- result = run_cmd(cmd + base + params)
61
- assert_cmd(expected_result, result)
62
- end
63
-
64
- it 'allows to set value with disabled puppet default' do
65
- params = ['--value', override_value, '--omit', false]
66
- expected_result = success_result("Override value created.\n")
67
-
68
- api_expects_parameter_search(puppet_class, parameter)
69
-
70
- api_expects(:override_values, :create, 'Create override value').with_params(
71
- :smart_class_parameter_id => parameter['id'],
72
- :override_value => {
73
- :match => match,
74
- :value => override_value,
75
- :omit => false
76
- }
77
- )
78
-
79
- result = run_cmd(cmd + base + params)
80
- assert_cmd(expected_result, result)
81
- end
82
-
83
- it 'does not allow to use puppet default and value at the same time' do
84
- params = ['--value', 'something', '--omit', true]
85
-
86
- expected_result = usage_error_result(
87
- cmd,
88
- "Cannot use --value when --omit is true.",
89
- 'Could not create the override value'
90
- )
91
-
92
- api_expects_parameter_search(puppet_class, parameter)
93
-
94
- result = run_cmd(cmd + base + params)
95
- assert_cmd(expected_result, result)
96
- end
97
- end