hammer_cli_foreman 0.0.15 → 0.0.16

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of hammer_cli_foreman might be problematic. Click here for more details.

Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/lib/hammer_cli_foreman/architecture.rb +4 -6
  3. data/lib/hammer_cli_foreman/associating_commands.rb +26 -4
  4. data/lib/hammer_cli_foreman/commands.rb +17 -27
  5. data/lib/hammer_cli_foreman/common_parameter.rb +4 -3
  6. data/lib/hammer_cli_foreman/compute_resource.rb +3 -5
  7. data/lib/hammer_cli_foreman/domain.rb +8 -12
  8. data/lib/hammer_cli_foreman/environment.rb +2 -1
  9. data/lib/hammer_cli_foreman/exception_handler.rb +11 -2
  10. data/lib/hammer_cli_foreman/exceptions.rb +0 -2
  11. data/lib/hammer_cli_foreman/fact.rb +1 -5
  12. data/lib/hammer_cli_foreman/host.rb +47 -38
  13. data/lib/hammer_cli_foreman/hostgroup.rb +5 -8
  14. data/lib/hammer_cli_foreman/image.rb +11 -13
  15. data/lib/hammer_cli_foreman/location.rb +2 -5
  16. data/lib/hammer_cli_foreman/media.rb +2 -6
  17. data/lib/hammer_cli_foreman/model.rb +4 -5
  18. data/lib/hammer_cli_foreman/operating_system.rb +14 -18
  19. data/lib/hammer_cli_foreman/organization.rb +2 -5
  20. data/lib/hammer_cli_foreman/output.rb +2 -2
  21. data/lib/hammer_cli_foreman/parameter.rb +6 -8
  22. data/lib/hammer_cli_foreman/partition_table.rb +8 -11
  23. data/lib/hammer_cli_foreman/puppet_class.rb +2 -4
  24. data/lib/hammer_cli_foreman/report.rb +3 -4
  25. data/lib/hammer_cli_foreman/smart_class_parameter.rb +2 -6
  26. data/lib/hammer_cli_foreman/smart_proxy.rb +4 -7
  27. data/lib/hammer_cli_foreman/subnet.rb +2 -5
  28. data/lib/hammer_cli_foreman/template.rb +5 -6
  29. data/lib/hammer_cli_foreman/user.rb +2 -5
  30. data/lib/hammer_cli_foreman/version.rb +1 -1
  31. data/lib/hammer_cli_foreman.rb +7 -3
  32. data/test/unit/apipie_resource_mock.rb +9 -3
  33. data/test/unit/commands_test.rb +20 -0
  34. data/test/unit/exception_handler_test.rb +35 -1
  35. data/test/unit/helpers/command.rb +10 -2
  36. data/test/unit/host_test.rb +22 -0
  37. data/test/unit/partition_table_test.rb +4 -4
  38. metadata +6 -6
@@ -1,7 +1,3 @@
1
- require 'hammer_cli'
2
- require 'foreman_api'
3
- require 'hammer_cli_foreman/commands'
4
-
5
1
  module HammerCLIForeman
6
2
 
7
3
  class Report < HammerCLI::Apipie::Command
@@ -74,6 +70,7 @@ module HammerCLIForeman
74
70
  end
75
71
  end
76
72
 
73
+ apipie_options
77
74
  end
78
75
 
79
76
 
@@ -81,6 +78,8 @@ module HammerCLIForeman
81
78
  identifiers :id
82
79
  success_message "Report has been deleted"
83
80
  failure_message "Could not delete the report"
81
+
82
+ apipie_options
84
83
  end
85
84
 
86
85
 
@@ -1,7 +1,3 @@
1
- require 'hammer_cli'
2
- require 'foreman_api'
3
- require 'hammer_cli_foreman/commands'
4
-
5
1
  module HammerCLIForeman
6
2
 
7
3
  class SmartClassParametersBriefList < HammerCLIForeman::ListCommand
@@ -78,10 +74,10 @@ module HammerCLIForeman
78
74
  res
79
75
  end
80
76
 
77
+ apipie_options
81
78
  end
82
79
 
83
80
  class UpdateCommand < HammerCLIForeman::UpdateCommand
84
- # identifiers :id, :name
85
81
 
86
82
  success_message "Parameter updated"
87
83
  failure_message "Could not update the parameter"
@@ -104,6 +100,6 @@ module HammerCLIForeman
104
100
 
105
101
  end
106
102
 
107
- HammerCLI::MainCommand.subcommand 'sc_param', "Manipulate Foreman's smart class parameters.", HammerCLIForeman::SmartClassParameter
103
+ HammerCLI::MainCommand.subcommand 'sc_param', "Manipulate smart class parameters.", HammerCLIForeman::SmartClassParameter
108
104
 
109
105
  end
@@ -1,7 +1,3 @@
1
- require 'hammer_cli'
2
- require 'foreman_api'
3
- require 'hammer_cli_foreman/commands'
4
-
5
1
  module HammerCLIForeman
6
2
 
7
3
  class SmartProxy < HammerCLI::Apipie::Command
@@ -33,10 +29,11 @@ module HammerCLIForeman
33
29
  end
34
30
 
35
31
  def extend_data(proxy)
36
- proxy['_features'] = proxy['features'].map { |f| f['feature']['name'] }
32
+ proxy['_features'] = proxy['features'].map { |f| f['name'] }
37
33
  proxy
38
34
  end
39
35
 
36
+ apipie_options
40
37
  end
41
38
 
42
39
 
@@ -87,7 +84,7 @@ module HammerCLIForeman
87
84
 
88
85
  def request_params
89
86
  opts = super
90
- opts['dryrun'] = dryrun?
87
+ opts['dryrun'] = option_dryrun?
91
88
  opts
92
89
  end
93
90
  end
@@ -97,4 +94,4 @@ module HammerCLIForeman
97
94
 
98
95
  end
99
96
 
100
- HammerCLI::MainCommand.subcommand 'proxy', "Manipulate Foreman's smart proxies.", HammerCLIForeman::SmartProxy
97
+ HammerCLI::MainCommand.subcommand 'proxy', "Manipulate smart proxies.", HammerCLIForeman::SmartProxy
@@ -1,7 +1,3 @@
1
- require 'hammer_cli'
2
- require 'foreman_api'
3
- require 'hammer_cli_foreman/commands'
4
-
5
1
  module HammerCLIForeman
6
2
 
7
3
  class Subnet < HammerCLI::AbstractCommand
@@ -39,6 +35,7 @@ module HammerCLIForeman
39
35
  field :to, "To"
40
36
  end
41
37
 
38
+ apipie_options
42
39
  end
43
40
 
44
41
 
@@ -76,5 +73,5 @@ module HammerCLIForeman
76
73
 
77
74
  end
78
75
 
79
- HammerCLI::MainCommand.subcommand 'subnet', "Manipulate Foreman's subnets.", HammerCLIForeman::Subnet
76
+ HammerCLI::MainCommand.subcommand 'subnet', "Manipulate subnets.", HammerCLIForeman::Subnet
80
77
 
@@ -1,8 +1,3 @@
1
- require 'hammer_cli'
2
- require 'foreman_api'
3
- require 'hammer_cli_foreman/commands'
4
- require 'hammer_cli_foreman/associating_commands'
5
-
6
1
  module HammerCLIForeman
7
2
 
8
3
  class Template < HammerCLI::Apipie::Command
@@ -49,6 +44,7 @@ module HammerCLIForeman
49
44
  tpl
50
45
  end
51
46
 
47
+ apipie_options
52
48
  end
53
49
 
54
50
 
@@ -82,6 +78,7 @@ module HammerCLIForeman
82
78
  puts template["template"]
83
79
  end
84
80
 
81
+ apipie_options
85
82
  end
86
83
 
87
84
 
@@ -141,6 +138,8 @@ module HammerCLIForeman
141
138
 
142
139
  success_message "Config template deleted"
143
140
  failure_message "Could not delete the config template"
141
+
142
+ apipie_options
144
143
  end
145
144
 
146
145
 
@@ -153,5 +152,5 @@ module HammerCLIForeman
153
152
 
154
153
  end
155
154
 
156
- HammerCLI::MainCommand.subcommand 'template', "Manipulate Foreman's config templates.", HammerCLIForeman::Template
155
+ HammerCLI::MainCommand.subcommand 'template', "Manipulate config templates.", HammerCLIForeman::Template
157
156
 
@@ -1,7 +1,3 @@
1
- require 'hammer_cli'
2
- require 'foreman_api'
3
- require 'hammer_cli_foreman/commands'
4
-
5
1
  module HammerCLIForeman
6
2
 
7
3
  class User < HammerCLI::Apipie::Command
@@ -40,6 +36,7 @@ module HammerCLIForeman
40
36
  user
41
37
  end
42
38
 
39
+ apipie_options
43
40
  end
44
41
 
45
42
 
@@ -81,5 +78,5 @@ module HammerCLIForeman
81
78
 
82
79
  end
83
80
 
84
- HammerCLI::MainCommand.subcommand 'user', "Manipulate Foreman's users.", HammerCLIForeman::User
81
+ HammerCLI::MainCommand.subcommand 'user', "Manipulate users.", HammerCLIForeman::User
85
82
 
@@ -1,5 +1,5 @@
1
1
  module HammerCLIForeman
2
2
  def self.version
3
- @version ||= Gem::Version.new '0.0.15'
3
+ @version ||= Gem::Version.new '0.0.16'
4
4
  end
5
5
  end
@@ -1,8 +1,7 @@
1
1
  require 'hammer_cli'
2
2
  require 'hammer_cli/exit_codes'
3
3
 
4
- require 'hammer_cli_foreman/version'
5
- require 'hammer_cli_foreman/output/fields'
4
+ require 'foreman_api'
6
5
 
7
6
  module HammerCLIForeman
8
7
 
@@ -10,10 +9,15 @@ module HammerCLIForeman
10
9
  HammerCLIForeman::ExceptionHandler
11
10
  end
12
11
 
12
+ require 'hammer_cli_foreman/version'
13
13
  require 'hammer_cli_foreman/output'
14
+ require 'hammer_cli_foreman/commands'
15
+ require 'hammer_cli_foreman/associating_commands'
16
+ require 'hammer_cli_foreman/parameter'
14
17
  require 'hammer_cli_foreman/exception_handler'
15
- require 'hammer_cli_foreman/architecture'
16
18
  require 'hammer_cli_foreman/common_parameter'
19
+
20
+ require 'hammer_cli_foreman/architecture'
17
21
  require 'hammer_cli_foreman/compute_resource'
18
22
  require 'hammer_cli_foreman/domain'
19
23
  require 'hammer_cli_foreman/environment'
@@ -16,11 +16,17 @@ class ApipieResourceMock
16
16
  return self
17
17
  end
18
18
 
19
- def expects_with(method_name, params, return_value=nil)
19
+ def expects_with(method_name, params, headers=nil, return_value=nil)
20
20
  return_value ||= return_value_for(method_name)
21
- self.expects(method_name).with(params).returns(return_value)
21
+ self.expects(method_name).with(params, headers).returns(return_value)
22
22
  end
23
23
 
24
+ def expects_with_block(method_name, &block)
25
+ return_value ||= return_value_for(method_name)
26
+ self.expects(method_name).with() { |param, headers| yield param }
27
+ end
28
+
29
+
24
30
  def stub_method(method_name, return_value)
25
31
  self.stubs(method_name.to_s).returns([return_value, return_value.to_s])
26
32
  @return_values[method_name.to_s] = return_value
@@ -85,4 +91,4 @@ module ResourceMocks
85
91
  sc_params
86
92
  end
87
93
 
88
- end
94
+ end
@@ -93,4 +93,24 @@ describe HammerCLIForeman do
93
93
  out.must_match("Message,Id,Name\nArchitecture created,3,i386\n")
94
94
  end
95
95
  end
96
+
97
+ context "AddAssociatedCommand" do
98
+ it "should associate resource" do
99
+ ForemanApi::Resources::Organization.any_instance.stubs(:show).returns([{
100
+ "id" => 1,
101
+ "domain_ids" => [2]}])
102
+ ForemanApi::Resources::Domain.any_instance.stubs(:show).returns([{
103
+ "id" => 1,
104
+ "name" => "local.lan"}])
105
+
106
+ class Assoc < HammerCLIForeman::AddAssociatedCommand
107
+ resource ForemanApi::Resources::Organization
108
+ associated_resource ForemanApi::Resources::Domain
109
+ apipie_options
110
+ end
111
+ res = Assoc.new("", { :adapter => :csv, :interactive => false })
112
+ res.get_new_ids.sort.must_equal [1, 2]
113
+ end
114
+ end
115
+
96
116
  end
@@ -7,7 +7,7 @@ describe HammerCLIForeman::ExceptionHandler do
7
7
  let(:handler) { HammerCLIForeman::ExceptionHandler.new(:output => output) }
8
8
  let(:heading) { "Something went wrong" }
9
9
 
10
- it "should print resource errors on unprocessable entity exception" do
10
+ it "should print nested resource errors on unprocessable entity exception" do
11
11
  response = <<-RESPONSE
12
12
  {"subnet":{"id":null,"errors":{"network":["can't be blank","is invalid"],"name":["can't be blank"]},"full_messages":["Network address can't be blank","Network address is invalid","Name can't be blank"]}}
13
13
  RESPONSE
@@ -18,6 +18,17 @@ describe HammerCLIForeman::ExceptionHandler do
18
18
  err_code.must_equal HammerCLI::EX_DATAERR
19
19
  end
20
20
 
21
+ it "should print resource errors on unprocessable entity exception" do
22
+ response = <<-RESPONSE
23
+ {"id":null,"errors":{"network":["can't be blank","is invalid"],"name":["can't be blank"]},"full_messages":["Network address can't be blank","Network address is invalid","Name can't be blank"]}
24
+ RESPONSE
25
+
26
+ ex = RestClient::UnprocessableEntity.new(response)
27
+ output.expects(:print_error).with(heading, "Network address can't be blank\nNetwork address is invalid\nName can't be blank")
28
+ err_code = handler.handle_exception(ex, :heading => heading)
29
+ err_code.must_equal HammerCLI::EX_DATAERR
30
+ end
31
+
21
32
  it "should handle argument error" do
22
33
  ex = ArgumentError.new
23
34
  output.expects(:print_error).with(heading, ex.message)
@@ -44,5 +55,28 @@ describe HammerCLIForeman::ExceptionHandler do
44
55
  err_code = handler.handle_exception(HammerCLIForeman::OperationNotSupportedError.new('message'), :heading => heading)
45
56
  err_code.must_equal HammerCLI::EX_UNAVAILABLE
46
57
  end
58
+
59
+ it "should print resource errors on resource not found exception" do
60
+ response = <<-RESPONSE
61
+ {"message":"Resource architecture not found by id '1'"}
62
+ RESPONSE
63
+ ex = RestClient::ResourceNotFound.new(response)
64
+ ex.stubs(:message).returns("")
65
+
66
+ output.expects(:print_error).with(heading, "Resource architecture not found by id '1'")
67
+ err_code = handler.handle_exception(ex, :heading => heading)
68
+ err_code.must_equal HammerCLI::EX_NOT_FOUND
69
+ end
70
+
71
+ it "should print exception message on resource not found exception without explicit message" do
72
+ response = "{}"
73
+ ex = RestClient::ResourceNotFound.new(response)
74
+ ex.stubs(:message).returns("ResourceNotFound message")
75
+
76
+ output.expects(:print_error).with(heading, "ResourceNotFound message")
77
+ err_code = handler.handle_exception(ex, :heading => heading)
78
+ err_code.must_equal HammerCLI::EX_NOT_FOUND
79
+ end
80
+
47
81
  end
48
82
 
@@ -10,10 +10,18 @@ module CommandTestHelper
10
10
  end
11
11
  end
12
12
 
13
- def it_should_call_action(action, params)
13
+ def it_should_call_action(action, params, headers={})
14
14
  it "should call action "+action.to_s do
15
15
  arguments ||= respond_to?(:with_params) ? with_params : []
16
- cmd.resource.resource_class.expects_with(action, params)
16
+ cmd.resource.resource_class.expects_with(action, params, headers)
17
+ cmd.run(arguments)
18
+ end
19
+ end
20
+
21
+ def it_should_call_action_and_test_params(action, &block)
22
+ it "should call action "+action.to_s do
23
+ arguments ||= respond_to?(:with_params) ? with_params : []
24
+ cmd.resource.resource_class.expects_with_block(action, &block)
17
25
  cmd.run(arguments)
18
26
  end
19
27
  end
@@ -212,6 +212,14 @@ describe HammerCLIForeman::Host do
212
212
  ["--name=host", "--environment-id=1", "--architecture-id=1", "--domain-id=1", "--operatingsystem-id=1"]
213
213
  it_should_fail_with "operatingsystem_id missing",
214
214
  ["--name=host", "--environment-id=1", "--architecture-id=1", "--domain-id=1", "--puppet-proxy-id=1"]
215
+
216
+ with_params ["--name=host", "--environment-id=1", "--architecture-id=1", "--domain-id=1", "--puppet-proxy-id=1", "--operatingsystem-id=1",
217
+ "--ip=1.2.3.4", "--mac=11:22:33:44:55:66", "--medium-id=1", "--partition-table-id=1", "--subnet-id=1",
218
+ "--sp-subnet-id=1", "--model-id=1", "--hostgroup-id=1", "--owner-id=1", '--puppet-ca-proxy-id=1', '--puppetclass-ids'] do
219
+ it_should_call_action_and_test_params(:create) { |par| par["host"]["managed"] == true }
220
+ it_should_call_action_and_test_params(:create) { |par| par["host"]["build"] == true }
221
+ it_should_call_action_and_test_params(:create) { |par| par["host"]["enabled"] == true }
222
+ end
215
223
  end
216
224
  end
217
225
 
@@ -227,6 +235,20 @@ describe HammerCLIForeman::Host do
227
235
  "--sp-subnet-id=1", "--model-id=1", "--hostgroup-id=1", "--owner-id=1", '--puppet-ca-proxy-id=1']
228
236
  it_should_fail_with "no params", []
229
237
  it_should_fail_with "name or id missing", ["--new-name=host2"]
238
+
239
+ with_params ["--id=1", "--puppet-proxy-id=1"] do
240
+ it_should_call_action_and_test_params(:update) { |par| par["host"].key?("managed") != true }
241
+ it_should_call_action_and_test_params(:update) { |par| par["host"].key?("build") != true }
242
+ it_should_call_action_and_test_params(:update) { |par| par["host"].key?("enabled") != true }
243
+ end
244
+
245
+ with_params ["--id=1", "--enabled=true"] do
246
+ it_should_call_action_and_test_params(:update) { |par| par["host"]["enabled"] == true }
247
+ end
248
+
249
+ with_params ["--id=1", "--enabled=false"] do
250
+ it_should_call_action_and_test_params(:update) { |par| par["host"]["enabled"] == false }
251
+ end
230
252
  end
231
253
 
232
254
  end
@@ -50,11 +50,11 @@ describe HammerCLIForeman::PartitionTable do
50
50
  end
51
51
 
52
52
  with_params ["--id=83"] do
53
- it_should_call_action :show, {'id' => '83'}
53
+ it_should_call_action :show, {'id' => '83'}, nil
54
54
  end
55
55
 
56
56
  with_params ["--name=ptable"] do
57
- it_should_call_action :show, {'id' => 'ptable'}
57
+ it_should_call_action :show, {'id' => 'ptable'}, nil
58
58
  end
59
59
 
60
60
  end
@@ -71,11 +71,11 @@ describe HammerCLIForeman::PartitionTable do
71
71
  end
72
72
 
73
73
  with_params ["--id=83"] do
74
- it_should_call_action :show, {'id' => '83'}
74
+ it_should_call_action :show, {'id' => '83'}, nil
75
75
  end
76
76
 
77
77
  with_params ["--name=ptable"] do
78
- it_should_call_action :show, {'id' => 'ptable'}
78
+ it_should_call_action :show, {'id' => 'ptable'}, nil
79
79
  end
80
80
 
81
81
  end
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.0.15
4
+ version: 0.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomáš Strachota
@@ -9,22 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-12-19 00:00:00.000000000 Z
12
+ date: 2014-01-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hammer_cli
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - '>='
18
+ - - '='
19
19
  - !ruby/object:Gem::Version
20
- version: 0.0.14
20
+ version: 0.0.15
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.0.14
27
+ version: 0.0.15
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: foreman_api
30
30
  requirement: !ruby/object:Gem::Requirement