hammer_cli_foreman 0.12.0 → 0.12.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d87fa149fc1614b767ea22dbb7035c5ce7885b8d
4
- data.tar.gz: 95e857975d4178e6e75da2b50643f52b05ab3723
3
+ metadata.gz: 8c0241ac81129df8860ec4157f08d6aae24d0bd3
4
+ data.tar.gz: ae9dcd30957ce18bbbdfe7b94129f1b53db08ea7
5
5
  SHA512:
6
- metadata.gz: ebb86bc0b6cf8dfde731271567c1c6592fa4d37b59338e26e367bbb62b8ee60f091b2ba6fb1880721c4a5b0d3ce7382af210fe82ba57b94dc24ee2da4f13c6ff
7
- data.tar.gz: 3249b9157df0f2f25417f62fb3268618edfbfdf4be50178675e70a16945f89dc255ffb8a4e4df144666a445eb74c8b1806379c8f3e2b1ffa67767f23a61bd3e3
6
+ metadata.gz: 446b99ddc24f96b787a5fa578f5333daee11c7697b20d3cb1df6f167fb65200620fffbb9f9e2e2fc14c64fcc63ca120492ce8f3bdc8fa41808809e3f0b35d937
7
+ data.tar.gz: ebd443959657a426311487215bbf125407a94e26bd2a28239656bc676ccc6ba8e350b1cfb5563f8eb52708025bfe57670c82b928cb3ef3808f22bdbc8653e3dc
data/doc/release_notes.md CHANGED
@@ -1,5 +1,9 @@
1
1
  Release notes
2
2
  =============
3
+ ### 0.12.1 (2018-03-05)
4
+ * temporary fix for override values ([#22751](http://projects.theforeman.org/issues/22751))
5
+ * raise error when wrong number of ids is resolved ([#22718](http://projects.theforeman.org/issues/22718))
6
+ * Puppetrun command is moved from hosts to puppet hosts ([#22658](http://projects.theforeman.org/issues/22658))
3
7
 
4
8
  ### 0.12.0 (2018-02-19)
5
9
  * Do not resolve already resolved id params ([#22517](http://projects.theforeman.org/issues/22517))
@@ -168,6 +168,7 @@ module HammerCLIForeman
168
168
 
169
169
  class PuppetRunCommand < HammerCLIForeman::SingleResourceCommand
170
170
  command_name "puppetrun"
171
+ resource :puppet_hosts
171
172
  action :puppetrun
172
173
 
173
174
  def print_data(records)
@@ -172,7 +172,7 @@ module HammerCLIForeman
172
172
  def find_resources(resource_name, options)
173
173
  resource = @api.resource(resource_name)
174
174
  results = resolved_call(resource_name, :index, options, :multi)
175
- raise ResolverError.new(_("one of %s not found.") % resource.name, resource) if results.count < expected_record_count(options, resource)
175
+ raise ResolverError.new(_("one of %s not found.") % resource.name, resource) if results.count < expected_record_count(options, resource, :multi)
176
176
  results
177
177
  end
178
178
 
@@ -184,7 +184,7 @@ module HammerCLIForeman
184
184
  ids
185
185
  elsif !options_empty?(resource, options)
186
186
  results = resolved_call(resource_name, :index, options, :multi).first.values.flatten
187
- raise ResolverError.new(_("one of %s not found.") % resource.name, resource) if results.count < expected_record_count(options, resource)
187
+ raise ResolverError.new(_("one of %s not found.") % resource.name, resource) if results.count < expected_record_count(options, resource, :multi)
188
188
  results
189
189
  else
190
190
  []
@@ -266,10 +266,11 @@ module HammerCLIForeman
266
266
  search_options
267
267
  end
268
268
 
269
- def expected_record_count(options, resource)
269
+ # @param mode [Symbol] mode in which ids are searched :single, :multi, nil for old beahvior
270
+ def expected_record_count(options, resource, mode = nil)
270
271
  searchables(resource).each do |s|
271
- value = options[HammerCLI.option_accessor_name(s.name.to_s)]
272
- values = options[HammerCLI.option_accessor_name(s.plural_name.to_s)]
272
+ value = options[HammerCLI.option_accessor_name(s.name.to_s)] unless mode == :multi
273
+ values = options[HammerCLI.option_accessor_name(s.plural_name.to_s)] unless mode == :single
273
274
  if value
274
275
  return 1
275
276
  elsif values
@@ -105,6 +105,8 @@ module HammerCLIForeman
105
105
  success_message _("Parameter updated.")
106
106
  failure_message _("Could not update the parameter")
107
107
 
108
+ option '--default-value', 'VALUE', _('Value to use when there is no match')
109
+
108
110
  build_options do |options|
109
111
  options.expand.including(:puppetclasses)
110
112
  options.without(:parameter_type, :validator_type, :override, :required, :override_value_order)
@@ -140,6 +142,8 @@ module HammerCLIForeman
140
142
  resource :override_values
141
143
  command_name 'add-matcher'
142
144
 
145
+ option '--value', 'VALUE', _('Override value, required if omit is false')
146
+
143
147
  success_message _("Override value created.")
144
148
  failure_message _("Could not create the override value")
145
149
 
@@ -10,6 +10,7 @@ module HammerCLIForeman
10
10
  :format => HammerCLI::Options::Normalizers::Enum.new(['regexp', 'list', ''])
11
11
  base.option "--override-value-order", "OVERRIDE_VALUE_ORDER", _("The order in which values are resolved"),
12
12
  :format => HammerCLI::Options::Normalizers::List.new
13
+ base.option '--default-value', 'VALUE', _('Value to use when there is no match')
13
14
 
14
15
  base.build_options :without => [:variable_type, :validator_type, :override_value_order]
15
16
  end
@@ -129,6 +130,8 @@ module HammerCLIForeman
129
130
  resource :override_values
130
131
  command_name 'add-matcher'
131
132
 
133
+ option '--value', 'VALUE', _('Override value, required if omit is false')
134
+
132
135
  success_message _("Override value created.")
133
136
  failure_message _("Could not create the override value")
134
137
 
@@ -33,7 +33,7 @@ module HammerCLIForeman
33
33
 
34
34
  protected
35
35
  def assert_params(params)
36
- params == deep_merge_hash(params, @expected_params)
36
+ stringify_keys(params) == deep_merge_hash(stringify_keys(params), stringify_keys(@expected_params))
37
37
  end
38
38
 
39
39
  def deep_merge_hash(h, other_h)
@@ -46,6 +46,15 @@ module HammerCLIForeman
46
46
  end
47
47
  end
48
48
  end
49
+
50
+ def stringify_keys(hash)
51
+ hash.inject({}) do |stringified, (key, value)|
52
+ if value.is_a?(Hash)
53
+ value = stringify_keys(value)
54
+ end
55
+ stringified.update(key.to_s => value)
56
+ end
57
+ end
49
58
  end
50
59
 
51
60
  module ExpectationExtensions
@@ -1,5 +1,5 @@
1
1
  module HammerCLIForeman
2
2
  def self.version
3
- @version ||= Gem::Version.new '0.12.0'
3
+ @version ||= Gem::Version.new '0.12.1'
4
4
  end
5
5
  end
@@ -32,38 +32,52 @@ describe 'sc-params add-matcher' do
32
32
  '--match', match
33
33
  ] }
34
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
+
35
46
  it 'allows to set value' do
36
47
  params = ['--value', override_value]
37
48
  expected_result = success_result("Override value created.\n")
38
49
 
39
- prepare_api_expectations = proc do
40
- expectations = []
41
- expectations << api_expects(:puppetclasses, :index, 'Find puppet class') do |par|
42
- par[:search] == %Q(name = "#{puppet_class['name']}")
43
- end.returns(index_response('motd' => [puppet_class]))
44
-
45
- expectations << api_expects(:smart_class_parameters, :index, 'Find smart parameter') do |par|
46
- par[:search] == %Q(key = "#{parameter['name']}") &&
47
- par[:puppetclass_id] == puppet_class['id']
48
- end.returns(index_response([parameter]))
49
-
50
- expectations << api_expects(:override_values, :create, 'Create override value') do |par|
51
- val = par['override_value']
52
- par['smart_class_parameter_id'] == parameter['id'] &&
53
- val['match'] == match &&
54
- val['value'] == override_value
55
- end
56
- end
57
-
58
- expectations = prepare_api_expectations.call()
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
+
59
60
  result = run_cmd(cmd + base + params)
60
61
  assert_cmd(expected_result, result)
61
- assert expectations.all?(&:verified?)
62
+ end
62
63
 
63
- expectations = prepare_api_expectations.call()
64
- result = run_cmd(cmd + base + params + ['--use-puppet-default', false])
64
+ it 'allows to set value with disabled puppet default' do
65
+ params = ['--value', override_value, '--use-puppet-default', 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
+ :use_puppet_default => false
76
+ }
77
+ )
78
+
79
+ result = run_cmd(cmd + base + params)
65
80
  assert_cmd(expected_result, result)
66
- assert expectations.all?(&:verified?)
67
81
  end
68
82
 
69
83
  it 'does not allow to use puppet default and value at the same time' do
@@ -253,6 +253,14 @@ describe HammerCLIForeman::IdResolver do
253
253
  assert_equal [john_id, jane_id], resolver.user_ids({"option_names" => ["John Doe", "Jane Doe"]})
254
254
  end
255
255
 
256
+ it "raises exception when wrong number of resources is found even with conflicting options" do
257
+ ResourceMocks.mock_action_call(:users, :index, [john])
258
+
259
+ assert_raises HammerCLIForeman::ResolverError do
260
+ resolver.user_ids({"option_names" => ["John Doe", "Jane Doe"], "option_name" => "group1"})
261
+ end
262
+ end
263
+
256
264
  it "raises exception when wrong number of resources is found" do
257
265
  ResourceMocks.mock_action_call(:users, :index, [john])
258
266
 
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.12.0
4
+ version: 0.12.1
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-02-19 00:00:00.000000000 Z
12
+ date: 2018-03-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hammer_cli