hammer_cli_foreman 0.0.17 → 0.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of hammer_cli_foreman might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/lib/hammer_cli_foreman/commands.rb +16 -8
- data/lib/hammer_cli_foreman/exception_handler.rb +3 -2
- data/lib/hammer_cli_foreman/operating_system.rb +3 -3
- data/lib/hammer_cli_foreman/user.rb +15 -3
- data/lib/hammer_cli_foreman/version.rb +1 -1
- data/test/unit/apipie_resource_mock.rb +5 -1
- data/test/unit/architecture_test.rb +1 -0
- data/test/unit/commands_test.rb +20 -1
- data/test/unit/common_parameter_test.rb +1 -0
- data/test/unit/compute_resource_test.rb +1 -0
- data/test/unit/domain_test.rb +1 -0
- data/test/unit/environment_test.rb +1 -0
- data/test/unit/exception_handler_test.rb +3 -3
- data/test/unit/fact_test.rb +1 -0
- data/test/unit/host_test.rb +1 -0
- data/test/unit/hostgroup_test.rb +1 -0
- data/test/unit/image_test.rb +1 -0
- data/test/unit/location_test.rb +1 -0
- data/test/unit/media_test.rb +1 -0
- data/test/unit/model_test.rb +1 -0
- data/test/unit/operating_system_test.rb +1 -3
- data/test/unit/organization_test.rb +1 -0
- data/test/unit/partition_table_test.rb +6 -5
- data/test/unit/puppet_class_test.rb +1 -0
- data/test/unit/report_test.rb +1 -0
- data/test/unit/smart_class_parameter_test.rb +5 -4
- data/test/unit/smart_proxy_test.rb +1 -0
- data/test/unit/subnet_test.rb +1 -0
- data/test/unit/template_test.rb +1 -0
- data/test/unit/user_test.rb +4 -0
- metadata +10 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6fd5cd72dd8217359f1f71719934fe9377086b17
|
4
|
+
data.tar.gz: bd87b55ddf01d0ff6f043b459c95899f0b5b58da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: babdcab332392d62a38d006d84fca84069dc66087b0915703f5325c6a1123612b1833f0a8b51402f3824ffe7f29a4fb48c026a798e3f0035c8babd807a3b446c
|
7
|
+
data.tar.gz: ce713dc6633bf093ebbec501e97f8d33901079dfe9927c6d605f2d6fd95abc493d02210824fdd78c190b32dcb9a5697f0346aea0311e29e10d66c1833992c65a
|
@@ -28,10 +28,6 @@ module HammerCLIForeman
|
|
28
28
|
|
29
29
|
class WriteCommand < HammerCLI::Apipie::WriteCommand
|
30
30
|
|
31
|
-
def request_headers
|
32
|
-
{}
|
33
|
-
end
|
34
|
-
|
35
31
|
def send_request
|
36
32
|
HammerCLIForeman.record_to_common_format(resource.call(action, request_params, request_headers)[0])
|
37
33
|
end
|
@@ -205,7 +201,10 @@ module HammerCLIForeman
|
|
205
201
|
def self.setup_associated_identifier_options
|
206
202
|
name = associated_resource.name.to_s
|
207
203
|
option_switch = "--"+name.gsub('_', '-')
|
208
|
-
|
204
|
+
|
205
|
+
option option_switch, name.upcase, " ", :attribute_name => :associated_name do |value|
|
206
|
+
name_to_id(value, "name", associated_resource)
|
207
|
+
end if declared_associated_identifiers.include? :name
|
209
208
|
option option_switch+"-id", name.upcase+"_ID", " ", :attribute_name => :associated_id if declared_associated_identifiers.include? :id
|
210
209
|
end
|
211
210
|
|
@@ -243,7 +242,11 @@ module HammerCLIForeman
|
|
243
242
|
|
244
243
|
def get_current_ids
|
245
244
|
item = HammerCLIForeman.record_to_common_format(resource.call('show', {'id' => get_identifier[0]})[0])
|
246
|
-
item
|
245
|
+
if item.has_key?(associated_resource.plural_name)
|
246
|
+
item[associated_resource.plural_name].map { |assoc| assoc['id'] }
|
247
|
+
else
|
248
|
+
item[associated_resource.name+'_ids'] || []
|
249
|
+
end
|
247
250
|
end
|
248
251
|
|
249
252
|
def get_required_id
|
@@ -252,8 +255,13 @@ module HammerCLIForeman
|
|
252
255
|
end
|
253
256
|
|
254
257
|
def request_params
|
255
|
-
params =
|
256
|
-
params
|
258
|
+
params = {}
|
259
|
+
if params.key?(resource.name)
|
260
|
+
params[resource.name] = {"#{associated_resource.name}_ids" => get_new_ids }
|
261
|
+
else
|
262
|
+
params["#{associated_resource.name}_ids"] = get_new_ids
|
263
|
+
end
|
264
|
+
|
257
265
|
params['id'] = get_identifier[0]
|
258
266
|
params
|
259
267
|
end
|
@@ -18,7 +18,7 @@ module HammerCLIForeman
|
|
18
18
|
def handle_unprocessable_entity(e)
|
19
19
|
response = JSON.parse(e.response)
|
20
20
|
response = HammerCLIForeman.record_to_common_format(response)
|
21
|
-
print_error response[
|
21
|
+
print_error response['full_messages']
|
22
22
|
HammerCLI::EX_DATAERR
|
23
23
|
end
|
24
24
|
|
@@ -46,7 +46,8 @@ module HammerCLIForeman
|
|
46
46
|
|
47
47
|
def handle_not_found(e)
|
48
48
|
response = JSON.parse(e.response)
|
49
|
-
|
49
|
+
response = HammerCLIForeman.record_to_common_format(response)
|
50
|
+
message = response['message'] || e.message
|
50
51
|
|
51
52
|
print_error message
|
52
53
|
log_full_error e
|
@@ -24,7 +24,7 @@ module HammerCLIForeman
|
|
24
24
|
|
25
25
|
class InfoCommand < HammerCLIForeman::InfoCommand
|
26
26
|
|
27
|
-
identifiers :id
|
27
|
+
identifiers :id
|
28
28
|
|
29
29
|
output ListCommand.output_definition do
|
30
30
|
field :media_names, "Installation media", Fields::List
|
@@ -91,7 +91,7 @@ module HammerCLIForeman
|
|
91
91
|
option "--ptable-ids", "PTABLE_IDS", "set associated partition tables",
|
92
92
|
:format => HammerCLI::Options::Normalizers::List.new
|
93
93
|
|
94
|
-
identifiers :id
|
94
|
+
identifiers :id
|
95
95
|
|
96
96
|
success_message "Operating system updated"
|
97
97
|
failure_message "Could not update the operating system"
|
@@ -111,7 +111,7 @@ module HammerCLIForeman
|
|
111
111
|
|
112
112
|
class DeleteCommand < HammerCLIForeman::DeleteCommand
|
113
113
|
|
114
|
-
identifiers :id
|
114
|
+
identifiers :id
|
115
115
|
|
116
116
|
success_message "Operating system deleted"
|
117
117
|
failure_message "Could not delete the operating system"
|
@@ -23,7 +23,11 @@ module HammerCLIForeman
|
|
23
23
|
|
24
24
|
class InfoCommand < HammerCLIForeman::InfoCommand
|
25
25
|
|
26
|
-
identifiers :id
|
26
|
+
identifiers :id, :login
|
27
|
+
|
28
|
+
option '--login', 'LOGIN', "User login" do |value|
|
29
|
+
name_to_id(value, "login", resource)
|
30
|
+
end
|
27
31
|
|
28
32
|
output ListCommand.output_definition do
|
29
33
|
field :last_login_on, "Last login", Fields::Date
|
@@ -52,7 +56,11 @@ module HammerCLIForeman
|
|
52
56
|
|
53
57
|
class UpdateCommand < HammerCLIForeman::UpdateCommand
|
54
58
|
|
55
|
-
identifiers :id
|
59
|
+
identifiers :id, :login
|
60
|
+
|
61
|
+
option '--login', 'LOGIN', "User login" do |value|
|
62
|
+
name_to_id(value, "login", resource)
|
63
|
+
end
|
56
64
|
|
57
65
|
success_message "User updated"
|
58
66
|
failure_message "Could not update the user"
|
@@ -64,7 +72,11 @@ module HammerCLIForeman
|
|
64
72
|
|
65
73
|
class DeleteCommand < HammerCLIForeman::DeleteCommand
|
66
74
|
|
67
|
-
identifiers :id
|
75
|
+
identifiers :id, :login
|
76
|
+
|
77
|
+
option '--login', 'LOGIN', "User login" do |value|
|
78
|
+
name_to_id(value, "login", resource)
|
79
|
+
end
|
68
80
|
|
69
81
|
success_message "User deleted"
|
70
82
|
failure_message "Could not delete the user"
|
@@ -12,11 +12,15 @@ class ApipieResourceMock
|
|
12
12
|
@resource.doc
|
13
13
|
end
|
14
14
|
|
15
|
+
def name
|
16
|
+
@resource.name
|
17
|
+
end
|
18
|
+
|
15
19
|
def new(attrs)
|
16
20
|
return self
|
17
21
|
end
|
18
22
|
|
19
|
-
def expects_with(method_name, params, headers=
|
23
|
+
def expects_with(method_name, params, headers={}, return_value=nil)
|
20
24
|
return_value ||= return_value_for(method_name)
|
21
25
|
self.expects(method_name).with(params, headers).returns(return_value)
|
22
26
|
end
|
data/test/unit/commands_test.rb
CHANGED
@@ -110,7 +110,26 @@ describe HammerCLIForeman do
|
|
110
110
|
end
|
111
111
|
res = Assoc.new("", { :adapter => :csv, :interactive => false })
|
112
112
|
res.get_new_ids.sort.must_equal [1, 2]
|
113
|
-
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should associate resource with new format" do
|
116
|
+
ForemanApi::Resources::Organization.any_instance.stubs(:show).returns([{
|
117
|
+
"id" => 1,
|
118
|
+
"domains" => [
|
119
|
+
{ "id" => 2, "name" => "global.lan" }]
|
120
|
+
}])
|
121
|
+
ForemanApi::Resources::Domain.any_instance.stubs(:show).returns([{
|
122
|
+
"id" => 1,
|
123
|
+
"name" => "local.lan"}])
|
124
|
+
|
125
|
+
class Assoc < HammerCLIForeman::AddAssociatedCommand
|
126
|
+
resource ForemanApi::Resources::Organization
|
127
|
+
associated_resource ForemanApi::Resources::Domain
|
128
|
+
apipie_options
|
129
|
+
end
|
130
|
+
res = Assoc.new("", { :adapter => :csv, :interactive => false })
|
131
|
+
res.get_new_ids.sort.must_equal [1, 2]
|
132
|
+
end
|
114
133
|
end
|
115
134
|
|
116
135
|
end
|
data/test/unit/domain_test.rb
CHANGED
@@ -20,7 +20,7 @@ describe HammerCLIForeman::ExceptionHandler do
|
|
20
20
|
|
21
21
|
it "should print resource errors on unprocessable entity exception" do
|
22
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"]}
|
23
|
+
{"error":{"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
24
|
RESPONSE
|
25
25
|
|
26
26
|
ex = RestClient::UnprocessableEntity.new(response)
|
@@ -58,7 +58,7 @@ describe HammerCLIForeman::ExceptionHandler do
|
|
58
58
|
|
59
59
|
it "should print resource errors on resource not found exception" do
|
60
60
|
response = <<-RESPONSE
|
61
|
-
{"message":"Resource architecture not found by id '1'"}
|
61
|
+
{"error":{"message":"Resource architecture not found by id '1'"}}
|
62
62
|
RESPONSE
|
63
63
|
ex = RestClient::ResourceNotFound.new(response)
|
64
64
|
ex.stubs(:message).returns("")
|
@@ -69,7 +69,7 @@ describe HammerCLIForeman::ExceptionHandler do
|
|
69
69
|
end
|
70
70
|
|
71
71
|
it "should print exception message on resource not found exception without explicit message" do
|
72
|
-
response = "
|
72
|
+
response = '{"error": ""}'
|
73
73
|
ex = RestClient::ResourceNotFound.new(response)
|
74
74
|
ex.stubs(:message).returns("ResourceNotFound message")
|
75
75
|
|
data/test/unit/fact_test.rb
CHANGED
data/test/unit/host_test.rb
CHANGED
data/test/unit/hostgroup_test.rb
CHANGED
data/test/unit/image_test.rb
CHANGED
data/test/unit/location_test.rb
CHANGED
data/test/unit/media_test.rb
CHANGED
data/test/unit/model_test.rb
CHANGED
@@ -11,6 +11,7 @@ describe HammerCLIForeman::OperatingSystem do
|
|
11
11
|
resource_mock.stub_method(:index, [])
|
12
12
|
resource_mock.stub_method(:show, {"operatingsystem" => {}})
|
13
13
|
cmd.class.resource resource_mock
|
14
|
+
cmd.stubs(:name_to_id).returns(1)
|
14
15
|
end
|
15
16
|
|
16
17
|
context "ListCommand" do
|
@@ -45,7 +46,6 @@ describe HammerCLIForeman::OperatingSystem do
|
|
45
46
|
|
46
47
|
context "parameters" do
|
47
48
|
it_should_accept "id", ["--id=1"]
|
48
|
-
it_should_accept "label", ["--label=os"]
|
49
49
|
it_should_fail_with "no arguments"
|
50
50
|
end
|
51
51
|
|
@@ -87,7 +87,6 @@ describe HammerCLIForeman::OperatingSystem do
|
|
87
87
|
let(:cmd) { HammerCLIForeman::OperatingSystem::DeleteCommand.new("", ctx) }
|
88
88
|
|
89
89
|
context "parameters" do
|
90
|
-
it_should_accept "label", ["--label=os"]
|
91
90
|
it_should_accept "id", ["--id=1"]
|
92
91
|
it_should_fail_with "name or id missing", []
|
93
92
|
end
|
@@ -100,7 +99,6 @@ describe HammerCLIForeman::OperatingSystem do
|
|
100
99
|
let(:cmd) { HammerCLIForeman::OperatingSystem::UpdateCommand.new("", ctx) }
|
101
100
|
|
102
101
|
context "parameters" do
|
103
|
-
it_should_accept "label", ["--label=os"]
|
104
102
|
it_should_accept "id", ["--id=1"]
|
105
103
|
it_should_accept "name, major, minor, family, release name", ["--id=83", "--name=os", "--major=1", "--minor=2", "--family=Red Hat", "--release-name=awesome"]
|
106
104
|
it_should_fail_with "no params", []
|
@@ -9,6 +9,7 @@ describe HammerCLIForeman::PartitionTable do
|
|
9
9
|
|
10
10
|
before :each do
|
11
11
|
cmd.class.resource ApipieResourceMock.new(cmd.class.resource.resource_class)
|
12
|
+
cmd.stubs(:name_to_id).returns(1)
|
12
13
|
|
13
14
|
::File.stubs(:read).returns("FILE_CONTENT")
|
14
15
|
end
|
@@ -50,11 +51,11 @@ describe HammerCLIForeman::PartitionTable do
|
|
50
51
|
end
|
51
52
|
|
52
53
|
with_params ["--id=83"] do
|
53
|
-
it_should_call_action :show, {'id' => '83'}
|
54
|
+
it_should_call_action :show, {'id' => '83'}
|
54
55
|
end
|
55
56
|
|
56
57
|
with_params ["--name=ptable"] do
|
57
|
-
it_should_call_action :show, {'id' =>
|
58
|
+
it_should_call_action :show, {'id' => 1}
|
58
59
|
end
|
59
60
|
|
60
61
|
end
|
@@ -71,11 +72,11 @@ describe HammerCLIForeman::PartitionTable do
|
|
71
72
|
end
|
72
73
|
|
73
74
|
with_params ["--id=83"] do
|
74
|
-
it_should_call_action :show, {'id' => '83'}
|
75
|
+
it_should_call_action :show, {'id' => '83'}
|
75
76
|
end
|
76
77
|
|
77
78
|
with_params ["--name=ptable"] do
|
78
|
-
it_should_call_action :show, {'id' =>
|
79
|
+
it_should_call_action :show, {'id' => 1}
|
79
80
|
end
|
80
81
|
|
81
82
|
end
|
@@ -134,7 +135,7 @@ describe HammerCLIForeman::PartitionTable do
|
|
134
135
|
end
|
135
136
|
|
136
137
|
with_params ["--name=ptable"] do
|
137
|
-
it_should_call_action :destroy, {'id' =>
|
138
|
+
it_should_call_action :destroy, {'id' => 1}
|
138
139
|
end
|
139
140
|
|
140
141
|
end
|
data/test/unit/report_test.rb
CHANGED
@@ -8,6 +8,7 @@ describe HammerCLIForeman::SmartClassParameter do
|
|
8
8
|
|
9
9
|
before :each do
|
10
10
|
cmd.class.resource ResourceMocks.smart_class_parameter
|
11
|
+
cmd.stubs(:name_to_id).returns(1)
|
11
12
|
end
|
12
13
|
|
13
14
|
context "ListCommand" do
|
@@ -41,7 +42,7 @@ describe HammerCLIForeman::SmartClassParameter do
|
|
41
42
|
context "InfoCommand" do
|
42
43
|
|
43
44
|
let(:cmd) { HammerCLIForeman::SmartClassParameter::InfoCommand.new("", ctx) }
|
44
|
-
|
45
|
+
|
45
46
|
|
46
47
|
context "parameters" do
|
47
48
|
it_should_accept "id", ["--id=1"]
|
@@ -59,13 +60,13 @@ describe HammerCLIForeman::SmartClassParameter do
|
|
59
60
|
context "parameters" do
|
60
61
|
it_should_accept "id", ["--id=1"]
|
61
62
|
it_should_accept "override", ["--id=1","--override=true"]
|
62
|
-
it_should_accept "description", ["--id=1","--description=descr"]
|
63
|
+
it_should_accept "description", ["--id=1","--description=descr"]
|
63
64
|
it_should_accept "default-value", ["--id=1","--default-value=1"]
|
64
|
-
it_should_accept "path ", ["--id=1","--path=path"]
|
65
|
+
it_should_accept "path ", ["--id=1","--path=path"]
|
65
66
|
it_should_accept "validator-type", ["--id=1","--validator-type=list"]
|
66
67
|
it_should_accept "validator-rule ", ["--id=1","--validator-rule=''"]
|
67
68
|
it_should_accept "override-value-order", ["--id=1","--override-value-order=fqdn"]
|
68
|
-
it_should_accept "parameter-type ", ["--id=1","--parameter-type=string"]
|
69
|
+
it_should_accept "parameter-type ", ["--id=1","--parameter-type=string"]
|
69
70
|
it_should_accept "required", ["--id=1","--required=true"]
|
70
71
|
|
71
72
|
it_should_fail_with "id missing", []
|
data/test/unit/subnet_test.rb
CHANGED
data/test/unit/template_test.rb
CHANGED
data/test/unit/user_test.rb
CHANGED
@@ -8,6 +8,7 @@ describe HammerCLIForeman::User do
|
|
8
8
|
|
9
9
|
before :each do
|
10
10
|
cmd.class.resource ApipieResourceMock.new(cmd.class.resource.resource_class)
|
11
|
+
cmd.stubs(:name_to_id).returns(1)
|
11
12
|
end
|
12
13
|
|
13
14
|
let(:cmd_module) { HammerCLIForeman::User }
|
@@ -37,6 +38,7 @@ describe HammerCLIForeman::User do
|
|
37
38
|
|
38
39
|
context "parameters" do
|
39
40
|
it_should_accept "id", ["--id=1"]
|
41
|
+
it_should_accept "login", ["--login=admin"]
|
40
42
|
it_should_fail_with "no arguments"
|
41
43
|
end
|
42
44
|
|
@@ -73,6 +75,7 @@ describe HammerCLIForeman::User do
|
|
73
75
|
|
74
76
|
context "parameters" do
|
75
77
|
it_should_accept "id", ["--id=1"]
|
78
|
+
it_should_accept "login", ["--login=admin"]
|
76
79
|
it_should_fail_with "id missing", []
|
77
80
|
end
|
78
81
|
|
@@ -85,6 +88,7 @@ describe HammerCLIForeman::User do
|
|
85
88
|
|
86
89
|
context "parameters" do
|
87
90
|
it_should_accept "id", ["--id=1"]
|
91
|
+
it_should_accept "login", ["--login=admin"]
|
88
92
|
it_should_fail_with "no params", []
|
89
93
|
end
|
90
94
|
|
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.
|
4
|
+
version: 0.0.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomáš Strachota
|
@@ -9,36 +9,36 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-01-
|
12
|
+
date: 2014-01-29 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.
|
20
|
+
version: 0.0.18
|
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.
|
27
|
+
version: 0.0.18
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: foreman_api
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- - '
|
32
|
+
- - '>='
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: 0.1.
|
34
|
+
version: 0.1.11
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
|
-
- - '
|
39
|
+
- - '>='
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: 0.1.
|
41
|
+
version: 0.1.11
|
42
42
|
description: |
|
43
43
|
Foreman commands for Hammer CLI
|
44
44
|
email: tstracho@redhat.com
|