hammer_cli_foreman 0.13.2 → 0.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/doc/release_notes.md +14 -5
  3. data/lib/hammer_cli_foreman.rb +6 -2
  4. data/lib/hammer_cli_foreman/api/interactive_basic_auth.rb +6 -1
  5. data/lib/hammer_cli_foreman/combination.rb +85 -0
  6. data/lib/hammer_cli_foreman/{report.rb → config_report.rb} +7 -9
  7. data/lib/hammer_cli_foreman/host.rb +49 -3
  8. data/lib/hammer_cli_foreman/id_resolver.rb +3 -2
  9. data/lib/hammer_cli_foreman/option_builders.rb +1 -11
  10. data/lib/hammer_cli_foreman/settings.rb +1 -0
  11. data/lib/hammer_cli_foreman/subnet.rb +22 -9
  12. data/lib/hammer_cli_foreman/template.rb +8 -0
  13. data/lib/hammer_cli_foreman/testing/api_expectations.rb +11 -0
  14. data/lib/hammer_cli_foreman/version.rb +1 -1
  15. data/locale/ca/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  16. data/locale/de/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  17. data/locale/en/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  18. data/locale/en_GB/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  19. data/locale/es/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  20. data/locale/fr/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  21. data/locale/it/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  22. data/locale/ja/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  23. data/locale/ko/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  24. data/locale/pt_BR/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  25. data/locale/ru/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  26. data/locale/zh_CN/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  27. data/locale/zh_TW/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  28. data/test/functional/host_test.rb +44 -15
  29. data/test/functional/settings_test.rb +37 -0
  30. data/test/functional/template_test.rb +35 -0
  31. data/test/functional/user_test.rb +82 -2
  32. data/test/unit/api/interactive_basic_auth_test.rb +10 -0
  33. data/test/unit/{report_test.rb → config_report_test.rb} +6 -6
  34. data/test/unit/host_test.rb +12 -3
  35. data/test/unit/settings_test.rb +45 -0
  36. data/test/unit/subnet_test.rb +8 -5
  37. metadata +12 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 299ecfde2e76d65fc4c7f1d5bdac72f5d51143b0
4
- data.tar.gz: 9b103faecf764289ef13d92c5eed3b2d2080cca6
3
+ metadata.gz: d9e0a20cb5bb0c548422b81c51845d180f0248a5
4
+ data.tar.gz: dd3d176d20d93db8fc965b34d3c3aff90e83a575
5
5
  SHA512:
6
- metadata.gz: 0e1c8af02919b59b4650ab43a2435af314b9c52371eb4c258015e2e06a61a0e3786d30a49fc54ca7e9b0738160c8a3f94d05b43d7077c84b76dd3d129bf57c49
7
- data.tar.gz: 942d83cbaf1b5d836ac3fc1cdfb8f6a37b52ea8695d8dbc49dfacbf86725c148e3c4b48b308f98bc1940901cd7dc7c68414091bc0141f857bd977d36fd7d78a4
6
+ metadata.gz: 0d7109efe44db2a67b8795a6914a9d518040eb8d8bb7f9c068c72382e3a3447fe43e82d1a1a154c585414378dfb56e988618c2895fe1b471d36614242ddbf2e2
7
+ data.tar.gz: 8eed5877f859165ee08e64275401c217f085ceb1d9794c32cc5f6eb5229818479f76c223efed758bc00e86c69ad19989432808091d8d6f274b4cdce03a68014e
data/doc/release_notes.md CHANGED
@@ -1,11 +1,20 @@
1
1
  Release notes
2
2
  =============
3
- ### 0.13.2 (2018-08-15)
4
- * Stop overriding apipie help for host flags ([#24490](http://projects.theforeman.org/issues/24490))
3
+ ### 0.14.0 (2018-08-27)
4
+ * Add template combinations commands ([#3969](http://projects.theforeman.org/issues/3969))
5
+ * Fix and extend tests for user update ([#23996](http://projects.theforeman.org/issues/23996))
5
6
  * Hammer asks for user password though -p option provided ([#23996](http://projects.theforeman.org/issues/23996))
6
-
7
- ### 0.13.1 (2018-07-18)
8
- * removed redundant info about OS from hostgroup ([#23722](http://projects.theforeman.org/issues/23722))
7
+ * Stop overriding apipie help for host flags ([PR #380](https://github.com/theforeman/hammer-cli-foreman/pull/380)) ([#24490](http://projects.theforeman.org/issues/24490))
8
+ * Hammer report info doesn't show logs resources and messages ([PR #375](https://github.com/theforeman/hammer-cli-foreman/pull/375)) ([#12189](http://projects.theforeman.org/issues/12189))
9
+ * Remove legacy code for Ruby < 2.0 ([#21360](http://projects.theforeman.org/issues/21360))
10
+ * Add disassociate command to host ([#15674](http://projects.theforeman.org/issues/15674))
11
+ * Align subnet translations in hammer with UI ([#9906](http://projects.theforeman.org/issues/9906))
12
+ * Propagate the error message from core ([#24285](http://projects.theforeman.org/issues/24285))
13
+ * Hammer uses /config_reports rather than /reports ([PR #374](https://github.com/theforeman/hammer-cli-foreman/pull/374)) ([#14510](http://projects.theforeman.org/issues/14510))
14
+ * Setting list should show full names ([#20360](http://projects.theforeman.org/issues/20360))
15
+ * Show cidr notation ([#22988](http://projects.theforeman.org/issues/22988))
16
+ * Removed redundant info about OS from hostgroup ([#23722](http://projects.theforeman.org/issues/23722))
17
+ * Add MTU to subnet info ([#23401](http://projects.theforeman.org/issues/23401))
9
18
 
10
19
  ### 0.13.0 (2018-05-09)
11
20
  * Listing all auth sources ([#19651](http://projects.theforeman.org/issues/19651))
@@ -102,7 +102,12 @@ module HammerCLIForeman
102
102
  )
103
103
 
104
104
  HammerCLI::MainCommand.lazy_subcommand('report', _("Browse and read reports"),
105
- 'HammerCLIForeman::Report', 'hammer_cli_foreman/report'
105
+ 'HammerCLIForeman::ConfigReport', 'hammer_cli_foreman/config_report',
106
+ :warning => _('%{report} command is deprecated and will be removed in one of the future versions. Please use %{config_report} command instead.') % {:report => 'report', :config_report => 'config-report'}
107
+ )
108
+
109
+ HammerCLI::MainCommand.lazy_subcommand('config-report', _("Browse and read reports"),
110
+ 'HammerCLIForeman::ConfigReport', 'hammer_cli_foreman/config_report'
106
111
  )
107
112
 
108
113
  HammerCLI::MainCommand.lazy_subcommand('role', _("Manage user roles"),
@@ -156,4 +161,3 @@ module HammerCLIForeman
156
161
  end
157
162
 
158
163
  end
159
-
@@ -14,7 +14,12 @@ module HammerCLIForeman
14
14
  def error(ex)
15
15
  if ex.is_a?(RestClient::Unauthorized)
16
16
  self.clear
17
- return UnauthorizedError.new(_("Invalid username or password."))
17
+ message = _("Invalid username or password.")
18
+ begin
19
+ message = JSON.parse(ex.response.body)['error']['message']
20
+ rescue
21
+ end
22
+ return UnauthorizedError.new(message)
18
23
  end
19
24
  end
20
25
 
@@ -0,0 +1,85 @@
1
+ module HammerCLIForeman
2
+ class Combination < HammerCLIForeman::Command
3
+ resource :template_combinations
4
+ command_name 'combination'
5
+ desc _("Manage template combinations")
6
+
7
+ module RequestParams
8
+ def request_params
9
+ combination_params = { 'hostgroup_id' => params['hostgroup_id'].to_s,
10
+ 'environment_id' => params['environment_id'].to_s }
11
+ super.merge('template_combination' => combination_params)
12
+ end
13
+ end
14
+
15
+
16
+ class InfoCombination < HammerCLIForeman::InfoCommand
17
+
18
+ output ListCommand.output_definition do
19
+ field :id, _('ID')
20
+ field :provisioning_template_id, _('Provisioning template ID')
21
+ field :provisioning_template_name, _('Provisioning template name')
22
+ field :hostgroup_id, _('Hostgroup ID')
23
+ field :hostgroup_name, _('Hostgroup name')
24
+ field :environment_id, _('Environment ID')
25
+ field :environment_name, _('Environment name')
26
+
27
+ HammerCLIForeman::References.taxonomies(self)
28
+ HammerCLIForeman::References.timestamps(self)
29
+
30
+ end
31
+ build_options do |o|
32
+ o.expand(:all).except(:config_templates,)
33
+ o.without(:config_template_id)
34
+ end
35
+ end
36
+
37
+ class ListCombination < HammerCLIForeman::ListCommand
38
+ output do
39
+ field :id, _('ID')
40
+ field nil, _('Provisioning Template'), Fields::SingleReference, :key => :provisioning_template
41
+ field nil, _('Hostgroup'), Fields::SingleReference, :key => :hostgroup
42
+ field nil, _('Environment'), Fields::SingleReference, :key => :environment
43
+ end
44
+
45
+ build_options do |o|
46
+ o.expand(:all).except(:config_templates, :hostgroups, :environments)
47
+ o.without(:config_template_id, :hostgroup_id, :environment_id)
48
+ end
49
+ end
50
+
51
+ class UpdateCombination < HammerCLIForeman::UpdateCommand
52
+ extend RequestParams
53
+
54
+ success_message _("Template combination updated.")
55
+ failure_message _("Could not update the template combination")
56
+
57
+ build_options do |o|
58
+ o.expand(:all).except(:config_templates,)
59
+ o.without(:config_template_id)
60
+ end
61
+ end
62
+
63
+ class CreateCombination < HammerCLIForeman::CreateCommand
64
+ extend RequestParams
65
+
66
+ success_message _("Template combination created.")
67
+ failure_message _("Could not create the template combination")
68
+
69
+ build_options do |o|
70
+ o.expand(:all).except(:config_templates,)
71
+ o.without(:config_template_id)
72
+ end
73
+ end
74
+
75
+ class DeleteCombination < HammerCLIForeman::DeleteCommand
76
+
77
+ success_message _("Template combination Deleted.")
78
+ failure_message _("Could not delete the template combination")
79
+
80
+ build_options
81
+ end
82
+
83
+ autoload_subcommands
84
+ end
85
+ end
@@ -1,8 +1,8 @@
1
1
  module HammerCLIForeman
2
2
 
3
- class Report < HammerCLIForeman::Command
3
+ class ConfigReport < HammerCLIForeman::Command
4
4
 
5
- resource :reports
5
+ resource :config_reports
6
6
 
7
7
  class ListCommand < HammerCLIForeman::ListCommand
8
8
 
@@ -57,13 +57,11 @@ module HammerCLIForeman
57
57
  end
58
58
  end
59
59
  field :logs, _("Logs"), Fields::Collection do
60
- from :log do
61
- from :source do
62
- field :source, _("Resource")
63
- end
64
- from :message do
65
- field :message, _("Message")
66
- end
60
+ from "source" do
61
+ field :source, _("Resource")
62
+ end
63
+ from "message" do
64
+ field :message, _("Message")
67
65
  end
68
66
  end
69
67
  end
@@ -1,5 +1,5 @@
1
1
  require 'hammer_cli_foreman/fact'
2
- require 'hammer_cli_foreman/report'
2
+ require 'hammer_cli_foreman/config_report'
3
3
  require 'hammer_cli_foreman/puppet_class'
4
4
  require 'hammer_cli_foreman/smart_class_parameter'
5
5
  require 'hammer_cli_foreman/smart_variable'
@@ -213,15 +213,50 @@ module HammerCLIForeman
213
213
  end
214
214
  end
215
215
 
216
+ class ConfigReportsCommand < HammerCLIForeman::ListCommand
217
+ command_name 'config-reports'
218
+ resource :config_reports, :index
219
+
220
+ option('--id', 'ID', _('Host id'), :referenced_resource => 'host')
221
+ option('--name', 'NAME', _('Host name'))
222
+
223
+ output HammerCLIForeman::ConfigReport::ListCommand.output_definition
224
+
225
+ def validate_options
226
+ validator.any(:option_name, :option_id).required
227
+ end
228
+
229
+ def request_params
230
+ params = super
231
+ search = []
232
+ search << params['search'] if params['search']
233
+
234
+ hostname = get_option_value('name')
235
+ search << %Q(host="#{hostname}") if hostname
236
+
237
+ host_id = get_option_value('id')
238
+ search << "host_id=#{host_id}" if host_id
239
+
240
+ params['search'] = search.join(' and ') unless search.empty?
241
+ params
242
+ end
243
+
244
+ build_options
245
+ end
216
246
 
217
247
  class ReportsCommand < HammerCLIForeman::ListCommand
218
248
  command_name "reports"
219
- resource :reports, :index
249
+ resource :config_reports, :index
220
250
 
221
251
  option('--id', "ID", _('Host id'), :referenced_resource => 'host')
222
252
  option('--name', "NAME", _('Host name'))
223
253
 
224
- output HammerCLIForeman::Report::ListCommand.output_definition
254
+ output HammerCLIForeman::ConfigReport::ListCommand.output_definition
255
+
256
+ def execute
257
+ warn _('%{reports} command is deprecated and will be removed in one of the future versions. Please use %{config_reports} command instead.') % {:reports => 'reports', :config_reports => 'config-reports'}
258
+ super
259
+ end
225
260
 
226
261
  def validate_options
227
262
  validator.any(:option_name, :option_id).required
@@ -428,6 +463,17 @@ module HammerCLIForeman
428
463
  build_options
429
464
  end
430
465
 
466
+ class DisassociateCommand < HammerCLIForeman::SingleResourceCommand
467
+ action :disassociate
468
+
469
+ command_name "disassociate"
470
+ desc _("Disassociate a host")
471
+ success_message _("The host has been disassociated from VM")
472
+ failure_message _("Failed to disassociated host from VM")
473
+
474
+ build_options
475
+ end
476
+
431
477
  autoload_subcommands
432
478
 
433
479
  subcommand 'interface', HammerCLIForeman::Interface.desc, HammerCLIForeman::Interface
@@ -53,7 +53,7 @@ module HammerCLIForeman
53
53
  :ptable => [ s_name(_("Partition table name")) ],
54
54
  :proxy => [ s_name(_("Proxy name")) ],
55
55
  :puppetclass => [ s_name(_("Puppet class name")) ],
56
- :report => [],
56
+ :config_report => [],
57
57
  :role => [ s_name(_("User role name")) ],
58
58
  :setting => [ s_name(_("Setting name"), :editable => false) ],
59
59
  :subnet => [ s_name(_("Subnet name")) ],
@@ -61,7 +61,8 @@ module HammerCLIForeman
61
61
  :user => [ s("login", _("User's login to search by")) ],
62
62
  :common_parameter => [ s_name(_("Common parameter name")) ],
63
63
  :smart_class_parameter => [ s_name(_("Smart class parameter name"), :editable => false) ],
64
- :smart_variable => [ s("variable", _("Smart variable name")) ]
64
+ :smart_variable => [ s("variable", _("Smart variable name")) ],
65
+ :template_combination => []
65
66
  }
66
67
  DEFAULT_SEARCHABLES = [ s_name(_("Name to search by")) ]
67
68
 
@@ -77,7 +77,7 @@ module HammerCLIForeman
77
77
  dependent_resources += @dependency_resolver.action_dependencies(action, :only_required => false, :recursive => false)
78
78
  dependent_resources += @dependency_resolver.action_dependencies(action, :only_required => true, :recursive => true)
79
79
 
80
- unique(dependent_resources).each do |dep_resource|
80
+ dependent_resources.uniq(&:name).each do |dep_resource|
81
81
  builders << DependentSearchablesOptionBuilder.new(dep_resource, @searchables)
82
82
  end
83
83
 
@@ -88,16 +88,6 @@ module HammerCLIForeman
88
88
 
89
89
  builders
90
90
  end
91
-
92
- protected
93
-
94
- def unique(resources)
95
- # ruby 1.8 hack - it does not support passing blocks to Array#uniq
96
- resources.inject({}) do |h, r|
97
- h.update(r.name => r)
98
- end.values
99
- end
100
-
101
91
  end
102
92
 
103
93
  class ForemanOptionBuilder < HammerCLI::OptionBuilderContainer
@@ -10,6 +10,7 @@ module HammerCLIForeman
10
10
  output do
11
11
  field :id, _('Id'), Fields::Id
12
12
  field :name, _('Name')
13
+ field :full_name, _('Full name')
13
14
  field :value, _('Value')
14
15
  field :description, _('Description')
15
16
  end
@@ -9,9 +9,11 @@ module HammerCLIForeman
9
9
  output do
10
10
  field :id, _("Id")
11
11
  field :name, _("Name")
12
- field :network, _("Network")
13
- field :mask, _("Mask")
12
+ field :network, _("Network Addr")
13
+ field :cidr, _("Network Prefix")
14
+ field :mask, _("Network Mask")
14
15
  field :vlanid, _("VLAN ID")
16
+ field :boot_mode, _("Boot Mode")
15
17
  end
16
18
 
17
19
  build_options
@@ -20,18 +22,29 @@ module HammerCLIForeman
20
22
 
21
23
  class InfoCommand < HammerCLIForeman::InfoCommand
22
24
 
23
- output ListCommand.output_definition do
25
+ output do
26
+ field :id, _("Id")
27
+ field :name, _("Name")
24
28
  field :description, _("Description"), Fields::LongText, :hide_blank => true
29
+ field :network_type, _("Protocol")
25
30
  field :priority, _("Priority")
26
- field :dns, _("DNS"), Fields::Reference, :details => :url
31
+ field :network, _("Network Addr")
32
+ field :cidr, _("Network Prefix")
33
+ field :mask, _("Network Mask")
34
+ field :gateway, _("Gateway Addr")
27
35
  field :dns_primary, _("Primary DNS")
28
36
  field :dns_secondary, _("Secondary DNS")
29
- field :tftp, _("TFTP"), Fields::Reference, :details => :url
30
- field :dhcp, _("DHCP"), Fields::Reference, :details => :url
37
+ label _("Smart Proxies") do
38
+ field :dns, _("DNS"), Fields::Reference, :details => :url
39
+ field :tftp, _("TFTP"), Fields::Reference, :details => :url
40
+ field :dhcp, _("DHCP"), Fields::Reference, :details => :url
41
+ end
31
42
  field :ipam, _("IPAM")
32
- field :gateway, _("Gateway")
33
- field :from, _("From")
34
- field :to, _("To")
43
+ field :from, _("Start of IP Range")
44
+ field :to, _("End of IP Range")
45
+ field :vlanid, _("VLAN ID")
46
+ field :mtu, _("MTU")
47
+ field :boot_mode, _("Boot Mode")
35
48
  HammerCLIForeman::References.domains(self)
36
49
  HammerCLIForeman::References.taxonomies(self)
37
50
  HammerCLIForeman::References.parameters(self)
@@ -55,6 +55,10 @@ module HammerCLIForeman
55
55
  field :locked, _("Locked"), Fields::Boolean
56
56
  HammerCLIForeman::References.operating_systems(self)
57
57
  HammerCLIForeman::References.taxonomies(self)
58
+ collection :template_combinations, 'Template Combinations' do
59
+ field :hostgroup_name, _('Hostgroup name')
60
+ field :environment_name, _('Environment name')
61
+ end
58
62
  end
59
63
 
60
64
  def extend_data(tpl)
@@ -194,6 +198,10 @@ module HammerCLIForeman
194
198
  build_options
195
199
  end
196
200
 
201
+ lazy_subcommand('combination', _("Manage template combinations"),
202
+ 'HammerCLIForeman::Combination', 'hammer_cli_foreman/combination'
203
+ )
204
+
197
205
  HammerCLIForeman::AssociatingCommands::OperatingSystem.extend_command(self)
198
206
 
199
207
  autoload_subcommands
@@ -63,6 +63,9 @@ module HammerCLIForeman
63
63
  if @api_call_matcher && !@api_call_matcher.expected_params.empty?
64
64
  signature += "\n expected params to include: " + params_signature(@api_call_matcher.expected_params)
65
65
  end
66
+ if @api_call_matcher && !@api_call_matcher.block.nil?
67
+ signature += "\n expected params to match block at: " + block_signature(@api_call_matcher.block)
68
+ end
66
69
  signature
67
70
  end
68
71
 
@@ -70,6 +73,10 @@ module HammerCLIForeman
70
73
  JSON.pretty_generate(hash).split("\n").join("\n ")
71
74
  end
72
75
 
76
+ def block_signature(block)
77
+ block.source_location.join(':')
78
+ end
79
+
73
80
  def set_note(note)
74
81
  @note = note
75
82
  end
@@ -128,6 +135,10 @@ module HammerCLIForeman
128
135
  def user(ask=nil)
129
136
  @user
130
137
  end
138
+
139
+ def password(ask=nil)
140
+ @password
141
+ end
131
142
  end
132
143
 
133
144
  class FakeApiConnection < HammerCLI::Apipie::ApiConnection
@@ -1,5 +1,5 @@
1
1
  module HammerCLIForeman
2
2
  def self.version
3
- @version ||= Gem::Version.new '0.13.2'
3
+ @version ||= Gem::Version.new '0.14.0'
4
4
  end
5
5
  end
@@ -169,7 +169,7 @@ describe "host create" do
169
169
  end
170
170
  end
171
171
 
172
- describe 'host reports' do
172
+ describe 'host config reports' do
173
173
  let(:report15) do
174
174
  {
175
175
  "id" => 15,
@@ -180,42 +180,71 @@ describe 'host reports' do
180
180
  end
181
181
 
182
182
  it 'filters reports by --id' do
183
- api_expects(:reports, :index, 'Filter the reports') do |params|
183
+ api_expects(:config_reports, :index, 'Filter the reports') do |params|
184
184
  params['search'] == 'host_id=1'
185
185
  end.returns(index_response([report15]))
186
186
 
187
- result = run_cmd(['host', 'reports', '--id=1'])
187
+ result = run_cmd(['host', 'config-reports', '--id=1'])
188
188
  result.exit_code.must_equal HammerCLI::EX_OK
189
189
  end
190
190
 
191
191
  it 'filters reports by --name' do
192
- api_expects(:reports, :index, 'Filter the reports') do |params|
192
+ api_expects(:config_reports, :index, 'Filter the reports') do |params|
193
193
  params['search'] == 'host="host.example.com"'
194
194
  end.returns(index_response([report15]))
195
195
 
196
- result = run_cmd(['host', 'reports', '--name=host.example.com'])
196
+ result = run_cmd(['host', 'config-reports', '--name=host.example.com'])
197
197
  result.exit_code.must_equal HammerCLI::EX_OK
198
198
  end
199
199
 
200
200
  it 'prints error or missing --id and --name' do
201
- expected_result = CommandExpectation.new
202
- expected_result.expected_err =
203
- ['Error: At least one of options --name, --id is required.', '',
204
- "See: 'hammer host reports --help'.", ''].join("\n")
205
- expected_result.expected_exit_code = HammerCLI::EX_USAGE
201
+ expected_result = CommandExpectation.new
202
+ expected_result.expected_err = [
203
+ 'Error: At least one of options --name, --id is required.',
204
+ '',
205
+ "See: 'hammer host config-reports --help'.",
206
+ ''
207
+ ].join("\n")
208
+ expected_result.expected_exit_code = HammerCLI::EX_USAGE
206
209
 
207
- api_expects_no_call
210
+ api_expects_no_call
208
211
 
209
- result = run_cmd(['host', 'reports'])
210
- assert_cmd(expected_result, result)
212
+ result = run_cmd(['host', 'config-reports'])
213
+ assert_cmd(expected_result, result)
211
214
  end
212
215
 
213
216
  it 'filters reports by --name together with search' do
214
- api_expects(:reports, :index, 'Filter the reports') do |params|
217
+ api_expects(:config_reports, :index, 'Filter the reports') do |params|
215
218
  params['search'] == 'reported > "2 hour ago" and host="host.example.com"'
216
219
  end.returns(index_response([report15]))
217
220
 
218
- result = run_cmd(['host', 'reports', '--name=host.example.com', %Q(--search=reported > "2 hour ago")])
221
+ result = run_cmd(['host', 'config-reports', '--name=host.example.com', '--search=reported > "2 hour ago"'])
219
222
  result.exit_code.must_equal HammerCLI::EX_OK
220
223
  end
221
224
  end
225
+ describe 'disassociate host from vm' do
226
+ let(:cmd) { ["host", "disassociate"] }
227
+
228
+ it 'successful disassociate host' do
229
+ params = ['--id=1']
230
+ expected_result = success_result("The host has been disassociated from VM\n")
231
+ api_expects(:hosts, :disassociate, 'disassociate hosts') do |params|
232
+ params['id'] == "1"
233
+ end.returns({})
234
+
235
+ result = run_cmd(cmd + params)
236
+ assert_cmd(expected_result, result)
237
+ end
238
+
239
+ it 'prints error on missing host id' do
240
+ expected_result = CommandExpectation.new
241
+ expected_result.expected_err = [
242
+ "Failed to disassociated host from VM:",
243
+ " Missing arguments for 'id'",
244
+ ''].join("\n")
245
+ expected_result.expected_exit_code = HammerCLI::EX_USAGE
246
+
247
+ result = run_cmd(cmd)
248
+ assert_cmd(expected_result, result)
249
+ end
250
+ end
@@ -0,0 +1,37 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'test_helper')
2
+
3
+ describe 'Settings' do
4
+ let(:setting) do
5
+ {
6
+ :name => 'content_action_accept_timeout',
7
+ :full_name => 'Accept action timeout',
8
+ :value => 20,
9
+ :description => 'Time in seconds to wait for a Host to pickup a remote action'
10
+ }
11
+ end
12
+
13
+ describe 'list command' do
14
+ before do
15
+ @cmd = %w(settings list)
16
+ end
17
+
18
+ it 'lists all settings' do
19
+ api_expects(:settings, :index, 'List').with_params(
20
+ 'page' => 1, 'per_page' => 1000
21
+ ).returns(index_response([setting]))
22
+
23
+
24
+ output = IndexMatcher.new([
25
+ ['NAME', 'FULL NAME', 'VALUE', 'DESCRIPTION'],
26
+ ['content_action_accept_timeout', 'Accept action timeout', '20', 'Time in seconds to wait for a Host to pickup a remote action']
27
+ ])
28
+ expected_result = success_result(output)
29
+
30
+ result = run_cmd(@cmd)
31
+ assert_cmd(expected_result, result)
32
+ end
33
+
34
+ end
35
+
36
+ end
37
+
@@ -123,4 +123,39 @@ describe 'template' do
123
123
  assert_cmd(expected_result, result)
124
124
  end
125
125
  end
126
+
127
+ describe 'combinations' do
128
+ before do
129
+ @cmd = %w(template combination)
130
+ end
131
+
132
+ it 'should create new combination' do
133
+ params = ['create','--provisioning-template-id=10', '--hostgroup-id=1', '--environment-id=1']
134
+ expected_result = success_result("Template combination created.\n")
135
+ api_expects(:template_combinations, :create, 'Create template combination') do |params|
136
+ params["provisioning_template_id"] == 10 &&
137
+ params["hostgroup_id"] == 1 &&
138
+ params["environment_id"] == 1 &&
139
+ params["template_combination"] == {"environment_id" => 1, "hostgroup_id" => 1}
140
+ end
141
+
142
+ result = run_cmd(@cmd + params)
143
+ assert_cmd(expected_result, result)
144
+ end
145
+
146
+ it 'should update combination' do
147
+ params = ['update','--id=3','--provisioning-template-id=10', '--hostgroup-id=1', '--environment-id=1']
148
+ expected_result = success_result("Template combination updated.\n")
149
+ api_expects(:template_combinations, :update, 'Update template combination') do |params|
150
+ params["provisioning_template_id"] == 10 &&
151
+ params["hostgroup_id"] == 1 &&
152
+ params["environment_id"] == 1 &&
153
+ params["template_combination"] == {"environment_id" => 1, "hostgroup_id" => 1}
154
+ end
155
+
156
+ result = run_cmd(@cmd + params)
157
+ assert_cmd(expected_result, result)
158
+ end
159
+
160
+ end
126
161
  end
@@ -7,12 +7,12 @@ describe "user" do
7
7
 
8
8
  def expect_with_minimal_params(action, message, &block)
9
9
  api_expects(:users, action, message).with_params({
10
- 'user' => {'login' => 'jane', 'mail' => 'jane@test.org', 'password' => 'secret', 'auth_source_id' => 1}})
10
+ 'user' => {'login' => 'jane', 'mail' => 'jane@test.org', 'password' => 'secret', 'auth_source_id' => 1}}, &block)
11
11
  end
12
12
 
13
13
  def expect_with_update_params(action, message, &block)
14
14
  api_expects(:users, action, message).with_params({
15
- 'user' => {'login' => 'jane'}})
15
+ 'user' => {'login' => 'jane'}}, &block)
16
16
  end
17
17
 
18
18
  describe "create" do
@@ -81,5 +81,85 @@ describe "user" do
81
81
  result = run_cmd(cmd + update_params + params)
82
82
  assert_cmd(expected_result, result)
83
83
  end
84
+
85
+ describe "update password" do
86
+ def replace_foreman_connection(connection)
87
+ HammerCLI.context[:api_connection].drop('foreman')
88
+ HammerCLI.context[:api_connection].create('foreman') { connection }
89
+ end
90
+
91
+ def connection(user, password)
92
+ authenticator = TestAuthenticator.new(user, password)
93
+ api_connection({:authenticator => authenticator}, FOREMAN_VERSION)
94
+ end
95
+
96
+ before do
97
+ @original_api_connection = HammerCLI.context[:api_connection].get('foreman')
98
+ end
99
+
100
+ after do
101
+ replace_foreman_connection(@original_api_connection)
102
+ end
103
+
104
+ it 'asks for missing current user password when updating own password' do
105
+ replace_foreman_connection(connection('jane', nil))
106
+
107
+ params = ['--password', 'changeme']
108
+
109
+ api_expects_search(:users, { :login => 'jane' }).returns(index_response([user]))
110
+ api_expects(:users, :show, { :id => 'jane' }).returns(user)
111
+ HammerCLIForeman::OptionSources::UserParams.any_instance
112
+ .expects(:ask_password).with(:current).returns('currentpwd')
113
+ expect_with_update_params(:update, 'Update user password') do |par|
114
+ par['id'] == '32' &&
115
+ par['user']['password'] == 'changeme' &&
116
+ par['user']['current_password'] == 'currentpwd'
117
+ end.returns(user)
118
+
119
+ expected_result = success_result("User [jane] updated.\n")
120
+ result = run_cmd(cmd + update_params + params)
121
+ assert_cmd(expected_result, result)
122
+ end
123
+
124
+ it 'does not ask for missing current password when updating own password and password was already given' do
125
+ replace_foreman_connection(connection('jane', 'currentpwd'))
126
+
127
+ params = ['--password', 'changeme']
128
+
129
+ api_expects_search(:users, { :login => 'jane' }).returns(index_response([user]))
130
+ api_expects(:users, :show, { :id => 'jane' }).returns(user)
131
+ HammerCLIForeman::OptionSources::UserParams.any_instance
132
+ .expects(:ask_password).with(:current).never
133
+ expect_with_update_params(:update, 'Update user password') do |par|
134
+ par['id'] == '32' &&
135
+ par['user']['password'] == 'changeme' &&
136
+ par['user']['current_password'] == 'currentpwd'
137
+ end.returns(user)
138
+
139
+ expected_result = success_result("User [jane] updated.\n")
140
+ result = run_cmd(cmd + update_params + params)
141
+ assert_cmd(expected_result, result)
142
+ end
143
+
144
+ it 'does not ask for current user password when updating password of another user' do
145
+ user_john = { 'id' => '1', 'login' => 'john' }
146
+ replace_foreman_connection(connection('john', nil))
147
+
148
+ params = ['--password', 'changeme']
149
+
150
+ api_expects_search(:users, { :login => 'jane' }).returns(index_response([user]))
151
+ api_expects(:users, :show, { :id => 'john' }).returns(user_john)
152
+ HammerCLIForeman::OptionSources::UserParams.any_instance
153
+ .expects(:ask_password).with(:current).never
154
+ expect_with_update_params(:update, 'Update user password') do |par|
155
+ par['id'] == '32' &&
156
+ par['user']['password'] == 'changeme'
157
+ end.returns(user)
158
+
159
+ expected_result = success_result("User [jane] updated.\n")
160
+ result = run_cmd(cmd + update_params + params)
161
+ assert_cmd(expected_result, result)
162
+ end
163
+ end
84
164
  end
85
165
  end
@@ -96,6 +96,16 @@ describe HammerCLIForeman::Api::InteractiveBasicAuth do
96
96
 
97
97
  assert_nil new_ex
98
98
  end
99
+
100
+ it 'respect server error' do
101
+ ex = RestClient::Unauthorized.new
102
+ response = mock()
103
+ response.stubs(:body).returns('{"error": {"message": "Unable to authenticate user admin"}}')
104
+ ex.response = response
105
+ new_ex = auth.error(ex)
106
+
107
+ assert_equal 'Unable to authenticate user admin', new_ex.message
108
+ end
99
109
  end
100
110
 
101
111
  describe '#set_credentials' do
@@ -1,18 +1,18 @@
1
1
  require File.join(File.dirname(__FILE__), 'test_helper')
2
2
  require File.join(File.dirname(__FILE__), 'apipie_resource_mock')
3
3
 
4
- require 'hammer_cli_foreman/report'
4
+ require 'hammer_cli_foreman/config_report'
5
5
 
6
- describe HammerCLIForeman::Report do
6
+ describe HammerCLIForeman::ConfigReport do
7
7
 
8
8
  include CommandTestHelper
9
9
 
10
10
  context "ListCommand" do
11
11
  before do
12
- ResourceMocks.mock_action_call(:reports, :index, [])
12
+ ResourceMocks.mock_action_call(:config_reports, :index, [])
13
13
  end
14
14
 
15
- let(:cmd) { HammerCLIForeman::Report::ListCommand.new("", ctx) }
15
+ let(:cmd) { HammerCLIForeman::ConfigReport::ListCommand.new("", ctx) }
16
16
 
17
17
  context "parameters" do
18
18
  it_should_accept "no arguments"
@@ -39,7 +39,7 @@ describe HammerCLIForeman::Report do
39
39
 
40
40
  context "InfoCommand" do
41
41
 
42
- let(:cmd) { HammerCLIForeman::Report::InfoCommand.new("", ctx) }
42
+ let(:cmd) { HammerCLIForeman::ConfigReport::InfoCommand.new("", ctx) }
43
43
 
44
44
  context "parameters" do
45
45
  it_should_accept "id", ["--id=1"]
@@ -51,7 +51,7 @@ describe HammerCLIForeman::Report do
51
51
 
52
52
  context "DeleteCommand" do
53
53
 
54
- let(:cmd) { HammerCLIForeman::Report::DeleteCommand.new("", ctx) }
54
+ let(:cmd) { HammerCLIForeman::ConfigReport::DeleteCommand.new("", ctx) }
55
55
 
56
56
  context "parameters" do
57
57
  it_should_accept "id", ["--id=1"]
@@ -155,12 +155,12 @@ describe HammerCLIForeman::Host do
155
155
  end
156
156
 
157
157
 
158
- context "ReportsCommand" do
158
+ context "ConfigReportsCommand" do
159
159
  before do
160
- ResourceMocks.mock_action_call(:reports, :index, [])
160
+ ResourceMocks.mock_action_call(:config_reports, :index, [])
161
161
  end
162
162
 
163
- let(:cmd) { HammerCLIForeman::Host::ReportsCommand.new("", ctx) }
163
+ let(:cmd) { HammerCLIForeman::Host::ConfigReportsCommand.new("", ctx) }
164
164
 
165
165
  context "parameters" do
166
166
  it_should_accept "id", ["--id=1"]
@@ -416,4 +416,13 @@ describe HammerCLIForeman::Host do
416
416
 
417
417
  end
418
418
  end
419
+
420
+
421
+ context "DisassociateCommand" do
422
+ let(:cmd) { HammerCLIForeman::Host::DisassociateCommand.new("", ctx) }
423
+ context "parameters" do
424
+ it_should_accept "name", ["--name=host"]
425
+ it_should_accept "id", ["--id=1"]
426
+ end
427
+ end
419
428
  end
@@ -0,0 +1,45 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+ require File.join(File.dirname(__FILE__), 'apipie_resource_mock')
3
+
4
+ require 'hammer_cli_foreman/settings'
5
+
6
+ describe HammerCLIForeman::Settings do
7
+
8
+ include CommandTestHelper
9
+
10
+ context "ListCommand" do
11
+
12
+ before do
13
+ ResourceMocks.mock_action_call(:settings, :index, [])
14
+ end
15
+
16
+ let(:cmd) { HammerCLIForeman::Settings::ListCommand.new("", ctx) }
17
+
18
+ context "parameters" do
19
+ it_should_accept "no arguments"
20
+ it_should_accept_search_params
21
+ end
22
+
23
+ context "output" do
24
+ let(:expected_record_count) { count_records(cmd.resource.call(:index)) }
25
+
26
+ it_should_print_n_records
27
+ it_should_print_column "Name"
28
+ it_should_print_column "Full name"
29
+ it_should_print_column "Value"
30
+ it_should_print_column "Description"
31
+ end
32
+
33
+ end
34
+
35
+ context "UpdateCommand" do
36
+ let(:cmd) { HammerCLIForeman::Settings::UpdateCommand.new("", ctx) }
37
+
38
+ context "parameters" do
39
+ it_should_accept "name", ["--name=setting1", "--value=setting2"]
40
+ it_should_accept "id", ["--id=1", "--value=setting2"]
41
+ end
42
+
43
+ end
44
+ end
45
+
@@ -23,7 +23,8 @@ describe HammerCLIForeman::Subnet do
23
23
  let(:expected_record_count) { count_records(cmd.resource.call(:index)) }
24
24
 
25
25
  it_should_print_n_records
26
- it_should_print_columns ["Id", "Name", "Network", "Mask"]
26
+ it_should_print_columns ["Id", "Name", "Network Addr", "Network Prefix", "Network Mask"]
27
+ it_should_print_columns ["VLAN ID", "Boot Mode"]
27
28
  end
28
29
 
29
30
  end
@@ -43,12 +44,14 @@ describe HammerCLIForeman::Subnet do
43
44
 
44
45
  with_params ["--name=subnet"] do
45
46
  it_should_print_n_records 1
46
- it_should_print_columns ["Id", "Name", "Network", "Mask"]
47
+ it_should_print_columns ["Id", "Name", "Network Addr", "Network Prefix", "Network Mask"]
47
48
  it_should_print_columns ["Description"]
48
49
  it_should_print_columns ["Priority"]
49
- it_should_print_columns ["DNS", "Primary DNS", "Secondary DNS"]
50
- it_should_print_columns ["Domains", "TFTP", "DHCP"]
51
- it_should_print_columns ["VLAN ID", "Gateway", "From", "To"]
50
+ it_should_print_columns ["Protocol"]
51
+ it_should_print_columns ["Primary DNS", "Secondary DNS", "Smart Proxies", "IPAM"]
52
+ it_should_print_columns ["Domains"]
53
+ it_should_print_columns ["VLAN ID", "MTU", "Boot Mode", "Gateway Addr", "Start of IP Range", "End of IP Range"]
54
+ it_should_print_columns ["Locations", "Organizations", "Parameters"]
52
55
  end
53
56
  end
54
57
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hammer_cli_foreman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.2
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomáš Strachota
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-08-15 00:00:00.000000000 Z
12
+ date: 2018-08-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hammer_cli
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: 0.13.0
20
+ version: 0.14.0
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: 0.13.0
27
+ version: 0.14.0
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: apipie-bindings
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -99,6 +99,7 @@ files:
99
99
  - lib/hammer_cli_foreman/auth.rb
100
100
  - lib/hammer_cli_foreman/auth_source.rb
101
101
  - lib/hammer_cli_foreman/auth_source_ldap.rb
102
+ - lib/hammer_cli_foreman/combination.rb
102
103
  - lib/hammer_cli_foreman/commands.rb
103
104
  - lib/hammer_cli_foreman/common_parameter.rb
104
105
  - lib/hammer_cli_foreman/compute_resource.rb
@@ -118,6 +119,7 @@ files:
118
119
  - lib/hammer_cli_foreman/compute_resources/vmware.rb
119
120
  - lib/hammer_cli_foreman/compute_resources/vmware/host_help_extenstion.rb
120
121
  - lib/hammer_cli_foreman/config_group.rb
122
+ - lib/hammer_cli_foreman/config_report.rb
121
123
  - lib/hammer_cli_foreman/defaults.rb
122
124
  - lib/hammer_cli_foreman/dependency_resolver.rb
123
125
  - lib/hammer_cli_foreman/domain.rb
@@ -157,7 +159,6 @@ files:
157
159
  - lib/hammer_cli_foreman/puppet_class.rb
158
160
  - lib/hammer_cli_foreman/realm.rb
159
161
  - lib/hammer_cli_foreman/references.rb
160
- - lib/hammer_cli_foreman/report.rb
161
162
  - lib/hammer_cli_foreman/resource_supported_test.rb
162
163
  - lib/hammer_cli_foreman/role.rb
163
164
  - lib/hammer_cli_foreman/settings.rb
@@ -206,6 +207,7 @@ files:
206
207
  - test/functional/personal_access_token_test.rb
207
208
  - test/functional/proxy_test.rb
208
209
  - test/functional/role_test.rb
210
+ - test/functional/settings_test.rb
209
211
  - test/functional/smart_class_parameter_test.rb
210
212
  - test/functional/smart_variable_test.rb
211
213
  - test/functional/ssh_keys_test.rb
@@ -466,6 +468,7 @@ files:
466
468
  - test/unit/common_parameter_test.rb
467
469
  - test/unit/compute_resource_test.rb
468
470
  - test/unit/config_group_test.rb
471
+ - test/unit/config_report_test.rb
469
472
  - test/unit/data/test_api.json
470
473
  - test/unit/defaults_test.rb
471
474
  - test/unit/dependency_resolver_test.rb
@@ -495,8 +498,8 @@ files:
495
498
  - test/unit/partition_table_test.rb
496
499
  - test/unit/puppet_class_test.rb
497
500
  - test/unit/realm_test.rb
498
- - test/unit/report_test.rb
499
501
  - test/unit/role_test.rb
502
+ - test/unit/settings_test.rb
500
503
  - test/unit/smart_class_parameter_test.rb
501
504
  - test/unit/smart_proxy_test.rb
502
505
  - test/unit/smart_variable_test.rb
@@ -776,6 +779,7 @@ test_files:
776
779
  - test/unit/location_test.rb
777
780
  - test/unit/environment_test.rb
778
781
  - test/unit/common_parameter_test.rb
782
+ - test/unit/settings_test.rb
779
783
  - test/unit/image_test.rb
780
784
  - test/unit/api/void_auth_test.rb
781
785
  - test/unit/api/interactive_basic_auth_test.rb
@@ -798,7 +802,7 @@ test_files:
798
802
  - test/unit/compute_resource_test.rb
799
803
  - test/unit/data/test_api.json
800
804
  - test/unit/apipie_resource_mock.rb
801
- - test/unit/report_test.rb
805
+ - test/unit/config_report_test.rb
802
806
  - test/unit/user_test.rb
803
807
  - test/unit/filter_test.rb
804
808
  - test/unit/output/formatters_test.rb
@@ -826,6 +830,7 @@ test_files:
826
830
  - test/unit/media_test.rb
827
831
  - test/functional/location_test.rb
828
832
  - test/functional/ssh_keys_test.rb
833
+ - test/functional/settings_test.rb
829
834
  - test/functional/smart_variable_test.rb
830
835
  - test/functional/smart_class_parameter_test.rb
831
836
  - test/functional/commands/list_test.rb