hammer_cli_foreman 2.3.0 → 2.5.1

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.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/doc/release_notes.md +27 -0
  3. data/lib/hammer_cli_foreman.rb +3 -0
  4. data/lib/hammer_cli_foreman/architecture.rb +5 -5
  5. data/lib/hammer_cli_foreman/bookmark.rb +6 -6
  6. data/lib/hammer_cli_foreman/command_extensions.rb +1 -0
  7. data/lib/hammer_cli_foreman/command_extensions/ping.rb +21 -2
  8. data/lib/hammer_cli_foreman/command_extensions/status.rb +1 -1
  9. data/lib/hammer_cli_foreman/command_extensions/update_common.rb +14 -0
  10. data/lib/hammer_cli_foreman/commands.rb +14 -0
  11. data/lib/hammer_cli_foreman/compute_profile.rb +5 -5
  12. data/lib/hammer_cli_foreman/compute_resource.rb +22 -0
  13. data/lib/hammer_cli_foreman/compute_resource/ovirt.rb +2 -1
  14. data/lib/hammer_cli_foreman/config_group.rb +5 -5
  15. data/lib/hammer_cli_foreman/config_report.rb +2 -0
  16. data/lib/hammer_cli_foreman/filter.rb +2 -2
  17. data/lib/hammer_cli_foreman/host.rb +1 -11
  18. data/lib/hammer_cli_foreman/hosts/common_update_options.rb +6 -5
  19. data/lib/hammer_cli_foreman/mail_notification.rb +2 -2
  20. data/lib/hammer_cli_foreman/model.rb +5 -5
  21. data/lib/hammer_cli_foreman/operating_system.rb +10 -9
  22. data/lib/hammer_cli_foreman/option_builders.rb +27 -7
  23. data/lib/hammer_cli_foreman/ping.rb +6 -1
  24. data/lib/hammer_cli_foreman/registration.rb +18 -0
  25. data/lib/hammer_cli_foreman/settings.rb +3 -3
  26. data/lib/hammer_cli_foreman/usergroup.rb +5 -5
  27. data/lib/hammer_cli_foreman/version.rb +1 -1
  28. data/locale/ca/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  29. data/locale/de/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  30. data/locale/en/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  31. data/locale/en_GB/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  32. data/locale/es/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  33. data/locale/fr/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  34. data/locale/it/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  35. data/locale/ja/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  36. data/locale/ko/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  37. data/locale/pt_BR/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  38. data/locale/ru/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  39. data/locale/zh_CN/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  40. data/locale/zh_TW/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
  41. data/test/data/2.4/foreman_api.json +1 -0
  42. data/test/data/2.5/foreman_api.json +1 -0
  43. data/test/functional/architecture_test.rb +79 -0
  44. data/test/functional/bookmark_test.rb +22 -1
  45. data/test/functional/compute_profile_test.rb +54 -0
  46. data/test/functional/compute_resource_test.rb +37 -0
  47. data/test/functional/config_group_test.rb +50 -0
  48. data/test/functional/filter_test.rb +115 -47
  49. data/test/functional/host_test.rb +99 -3
  50. data/test/functional/http_proxy_test.rb +12 -0
  51. data/test/functional/location_test.rb +13 -0
  52. data/test/functional/mail_notification_test.rb +20 -0
  53. data/test/functional/media_test.rb +11 -0
  54. data/test/functional/model_test.rb +50 -0
  55. data/test/functional/operating_system_test.rb +51 -0
  56. data/test/functional/ping_test.rb +33 -0
  57. data/test/functional/realm_test.rb +11 -0
  58. data/test/functional/registration_test.rb +8 -0
  59. data/test/functional/report_template_test.rb +11 -0
  60. data/test/functional/settings_test.rb +21 -0
  61. data/test/functional/status_test.rb +79 -13
  62. data/test/functional/template_test.rb +12 -0
  63. data/test/functional/user_test.rb +11 -0
  64. data/test/functional/usergroup_test.rb +51 -0
  65. data/test/test_helper.rb +1 -1
  66. data/test/unit/apipie_resource_mock.rb +21 -0
  67. data/test/unit/architecture_test.rb +10 -1
  68. data/test/unit/bookmark_test.rb +99 -0
  69. data/test/unit/compute_profile_test.rb +87 -0
  70. data/test/unit/config_group_test.rb +10 -0
  71. data/test/unit/config_report_test.rb +1 -0
  72. data/test/unit/host_test.rb +0 -23
  73. data/test/unit/mail_notification_test.rb +53 -0
  74. data/test/unit/model_test.rb +10 -0
  75. data/test/unit/operating_system_test.rb +14 -1
  76. data/test/unit/settings_test.rb +4 -0
  77. data/test/unit/usergroup_test.rb +10 -0
  78. metadata +129 -107
  79. data/test/reports/TEST-Minitest-Result.xml +0 -4344
@@ -61,9 +61,21 @@ describe 'httpproxy' do
61
61
  end
62
62
 
63
63
  it 'deletes an http proxy' do
64
+ api_expects(:http_proxies, :destroy, 'Delete proxy').returns(http_proxy)
65
+
64
66
  expected_result = success_result("Http proxy deleted.\n")
65
67
 
66
68
  result = run_cmd(%w(http-proxy delete --id 1))
67
69
  assert_cmd(expected_result, result)
68
70
  end
71
+
72
+ it 'updates nothing without related parameters' do
73
+ api_expects(:http_proxies, :update, 'Update proxy with no params').returns({})
74
+
75
+ expected_result = success_result("Nothing to update.\n")
76
+
77
+ result = run_cmd(%w(http-proxy update --id 1))
78
+ assert_cmd(expected_result, result)
79
+ end
80
+
69
81
  end
@@ -272,4 +272,17 @@ describe 'update' do
272
272
  result = run_cmd(@cmd + params)
273
273
  assert_cmd(success_result("Location updated.\n"), result)
274
274
  end
275
+
276
+ it 'updates nothing without related parameters' do
277
+ params = %w[--id=1]
278
+
279
+ api_expects(:locations, :index)
280
+ api_expects(:locations, :update, 'Update location with no params').returns({})
281
+
282
+ expected_result = success_result("Nothing to update.\n")
283
+
284
+ result = run_cmd(@cmd + params)
285
+ assert_cmd(expected_result, result)
286
+ end
287
+
275
288
  end
@@ -24,6 +24,26 @@ describe 'mail_notification' do
24
24
  result = run_cmd(@cmd)
25
25
  assert_cmd(expected_result, result)
26
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(:mail_notifications, :index, 'List mail notifications').returns(@mail_notifications)
43
+
44
+ result = run_cmd(@cmd, { use_defaults: true, defaults: defaults })
45
+ _(result.exit_code).must_equal HammerCLI::EX_OK
46
+ end
27
47
  end
28
48
 
29
49
  describe 'info' do
@@ -126,5 +126,16 @@ describe 'medium' do
126
126
  result = run_cmd(@cmd + params)
127
127
  assert_cmd(success_result("Installation medium updated.\n"), result)
128
128
  end
129
+
130
+ it 'updates nothing without medium related parameters' do
131
+ params = %w[--id=1]
132
+
133
+ api_expects(:media, :update, 'Update medium with no params').returns({})
134
+
135
+ expected_result = success_result("Nothing to update.\n")
136
+
137
+ result = run_cmd(@cmd + params)
138
+ assert_cmd(expected_result, result)
139
+ end
129
140
  end
130
141
  end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.join(File.dirname(__FILE__), 'test_helper')
4
+
5
+ describe 'model' do
6
+ describe 'list' do
7
+ before do
8
+ @cmd = %w[model list]
9
+ @models = [{
10
+ id: 1,
11
+ name: 'model',
12
+ }]
13
+ end
14
+
15
+ it 'should return a list of models' do
16
+ api_expects(:models, :index, 'List models').returns(@models)
17
+
18
+ output = IndexMatcher.new([
19
+ %w[ID NAME],
20
+ %w[1 model]
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(:models, :index, 'List models').returns(@models)
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
+
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.join(File.dirname(__FILE__), 'test_helper')
4
+
5
+ describe 'operating_system' do
6
+ describe 'list' do
7
+ before do
8
+ @cmd = %w[os list]
9
+ @operating_system = [{
10
+ id: 1,
11
+ release_name: 'Redhat 7',
12
+ family: 'Redhat',
13
+ }]
14
+ end
15
+
16
+ it 'should return a list of operating system' do
17
+ api_expects(:operatingsystems, :index, 'List operating systems').returns(@operating_system)
18
+
19
+ output = IndexMatcher.new([
20
+ ['ID', 'RELEASE NAME', 'FAMILY'],
21
+ ['1', 'Redhat 7', 'Redhat']
22
+ ])
23
+ expected_result = success_result(output)
24
+
25
+ result = run_cmd(@cmd)
26
+ assert_cmd(expected_result, result)
27
+ end
28
+
29
+ it 'should run list command with defaults' do
30
+ providers = { 'foreman' => HammerCLIForeman::Defaults.new(api_connection({}, '2.1')) }
31
+ defaults = HammerCLI::Defaults.new(
32
+ {
33
+ organization_id: {
34
+ provider: 'foreman'
35
+ },
36
+ location_id: {
37
+ provider: 'foreman'
38
+ }
39
+ }
40
+ )
41
+ defaults.stubs(:write_to_file).returns(true)
42
+ defaults.stubs(:providers).returns(providers)
43
+ api_expects(:operatingsystems, :index, 'List operating systems').returns(@operating_system)
44
+
45
+ result = run_cmd(@cmd, { use_defaults: true, defaults: defaults })
46
+ _(result.exit_code).must_equal HammerCLI::EX_OK
47
+ end
48
+ end
49
+ end
50
+
51
+
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require File.join(File.dirname(__FILE__), 'test_helper')
2
4
 
3
5
  describe 'ping' do
@@ -30,5 +32,36 @@ describe 'ping' do
30
32
  result = run_cmd(cmd)
31
33
  assert_cmd(expected_result, result)
32
34
  end
35
+
36
+ it 'returns 1 if one of the services failed and shows unrecognized services' do
37
+ ping_results['results']['new_plugin'] = {
38
+ 'services' => {
39
+ 'first' => {
40
+ 'status' => 'FAIL'
41
+ },
42
+ 'second' => {
43
+ 'status' => 'ok'
44
+ }
45
+ },
46
+ 'status' => 'FAIL'
47
+ }
48
+ api_expects(:ping, :ping, 'Ping').returns(ping_results)
49
+
50
+ expected_result = CommandExpectation.new
51
+ expected_result.expected_out = OutputMatcher.new(
52
+ [
53
+ 'database:',
54
+ ' Status: ok',
55
+ ' Server Response: Duration: 0ms'
56
+ ]
57
+ )
58
+ expected_result.expected_err =
59
+ ['1 more service(s) failed, but not shown:',
60
+ 'first',
61
+ ''].join("\n")
62
+ expected_result.expected_exit_code = 1
63
+ result = run_cmd(cmd)
64
+ assert_cmd(expected_result, result)
65
+ end
33
66
  end
34
67
  end
@@ -99,5 +99,16 @@ describe 'realm' do
99
99
  result = run_cmd(@cmd + params)
100
100
  assert_cmd(success_result("Realm [%{name}] updated.\n"), result)
101
101
  end
102
+
103
+ it 'updates nothing without realm related parameters' do
104
+ params = %w[--id=1]
105
+
106
+ api_expects(:realms, :update, 'Update realm with no params').returns({})
107
+
108
+ expected_result = success_result("Nothing to update.\n")
109
+
110
+ result = run_cmd(@cmd + params)
111
+ assert_cmd(expected_result, result)
112
+ end
102
113
  end
103
114
  end
@@ -0,0 +1,8 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ describe 'registration_commands' do
4
+ it 'create' do
5
+ api_expects(:registration_commands, :create)
6
+ run_cmd(%w(host-registration generate-command))
7
+ end
8
+ end
@@ -195,6 +195,17 @@ describe 'report-template' do
195
195
  result = run_cmd(cmd + params)
196
196
  assert_cmd(success_result("Report template updated.\n"), result)
197
197
  end
198
+
199
+ it 'updates nothing without template related parameters' do
200
+ params = %w[--id=1]
201
+
202
+ api_expects(:report_templates, :update, 'Update template with no params').returns({})
203
+
204
+ expected_result = success_result("Nothing to update.\n")
205
+
206
+ result = run_cmd(cmd + params)
207
+ assert_cmd(expected_result, result)
208
+ end
198
209
  end
199
210
 
200
211
  describe 'dump' do
@@ -31,6 +31,27 @@ describe 'Settings' do
31
31
  assert_cmd(expected_result, result)
32
32
  end
33
33
 
34
+ it 'should run list command with defaults' do
35
+ providers = { 'foreman' => HammerCLIForeman::Defaults.new(api_connection({}, '2.1')) }
36
+ defaults = HammerCLI::Defaults.new(
37
+ {
38
+ organization_id: {
39
+ provider: 'foreman'
40
+ },
41
+ location_id: {
42
+ provider: 'foreman'
43
+ }
44
+ }
45
+ )
46
+ defaults.stubs(:write_to_file).returns(true)
47
+ defaults.stubs(:providers).returns(providers)
48
+ api_expects(:settings, :index, 'List').with_params(
49
+ 'page' => 1, 'per_page' => 1000
50
+ ).returns(index_response([setting]))
51
+
52
+ result = run_cmd(@cmd, { use_defaults: true, defaults: defaults })
53
+ _(result.exit_code).must_equal HammerCLI::EX_OK
54
+ end
34
55
  end
35
56
 
36
57
  describe 'info' do
@@ -1,24 +1,60 @@
1
1
  require File.join(File.dirname(__FILE__), 'test_helper')
2
2
 
3
+ BASIC_STATUS = {
4
+ 'database' => { 'active' => true, 'duration_ms' => 0 },
5
+ 'version' => '1.24.0-develop',
6
+ 'api' => { 'version' => 'v2' },
7
+ 'plugins' => [],
8
+ 'smart_proxies' => [],
9
+ 'compute_resources' => []
10
+ }
11
+
12
+ STRING_STATUS = Marshal.load(Marshal.dump(BASIC_STATUS)).merge({
13
+ 'plugins' => [
14
+ 'Foreman plugin: foreman_ansible, 6.0.1, Daniel Lobato Garcia, Ansible integration with Foreman'
15
+ ]
16
+ })
17
+
18
+ STRUCTURED_STATUS = Marshal.load(Marshal.dump(BASIC_STATUS)).merge({
19
+ 'plugins' => [
20
+ {'name': 'foreman_ansible', 'version': '6.0.1'}
21
+ ]
22
+ })
23
+
3
24
  describe 'status' do
4
25
  let(:base_cmd) { %w[status] }
5
26
 
6
27
  describe 'foreman' do
7
28
  let(:cmd) { base_cmd << 'foreman' }
8
- let(:status_results) do
9
- {
10
- 'results' => {
11
- 'foreman' => {
12
- 'database' => { 'active' => true, 'duration_ms' => 0 },
13
- 'version' => '1.24.0-develop',
14
- 'api' => { 'version' => 'v2' },
15
- 'plugins' => [],
16
- 'smart_proxies' => [],
17
- 'compute_resources' => []
18
- }
19
- }
20
- }
29
+ let(:status_results) { {'results' => {'foreman' => BASIC_STATUS }} }
30
+
31
+ it 'checks status of the foreman system' do
32
+ api_expects(:ping, :statuses, 'Status').returns(status_results)
33
+
34
+ output = OutputMatcher.new(
35
+ [
36
+ 'Version: 1.24.0-develop',
37
+ 'API Version: v2',
38
+ 'Database:',
39
+ ' Status: ok',
40
+ ' Server Response: Duration: 0ms',
41
+ 'Plugins:',
42
+ '',
43
+ 'Smart Proxies:',
44
+ '',
45
+ 'Compute Resources:'
46
+ ]
47
+ )
48
+
49
+ expected_result = success_result(output)
50
+ result = run_cmd(cmd)
51
+ assert_cmd(expected_result, result)
21
52
  end
53
+ end
54
+
55
+ describe 'foreman with string plugins' do
56
+ let(:cmd) { base_cmd << 'foreman' }
57
+ let(:status_results) { {'results' => {'foreman' => STRING_STATUS }} }
22
58
 
23
59
  it 'checks status of the foreman system' do
24
60
  api_expects(:ping, :statuses, 'Status').returns(status_results)
@@ -31,7 +67,37 @@ describe 'status' do
31
67
  ' Status: ok',
32
68
  ' Server Response: Duration: 0ms',
33
69
  'Plugins:',
70
+ ' 1) Name: foreman_ansible',
71
+ ' Version: 6.0.1',
72
+ 'Smart Proxies:',
34
73
  '',
74
+ 'Compute Resources:'
75
+ ]
76
+ )
77
+
78
+ expected_result = success_result(output)
79
+ result = run_cmd(cmd)
80
+ assert_cmd(expected_result, result)
81
+ end
82
+ end
83
+
84
+ describe 'foreman with structured plugins' do
85
+ let(:cmd) { base_cmd << 'foreman' }
86
+ let(:status_results) { {'results' => {'foreman' => STRUCTURED_STATUS }} }
87
+
88
+ it 'checks status of the foreman system' do
89
+ api_expects(:ping, :statuses, 'Status').returns(status_results)
90
+
91
+ output = OutputMatcher.new(
92
+ [
93
+ 'Version: 1.24.0-develop',
94
+ 'API Version: v2',
95
+ 'Database:',
96
+ ' Status: ok',
97
+ ' Server Response: Duration: 0ms',
98
+ 'Plugins:',
99
+ ' 1) Name: foreman_ansible',
100
+ ' Version: 6.0.1',
35
101
  'Smart Proxies:',
36
102
  '',
37
103
  'Compute Resources:'
@@ -95,6 +95,18 @@ describe 'template' do
95
95
 
96
96
  assert_cmd(success_result("Provisioning template updated.\n"), result)
97
97
  end
98
+
99
+ it 'updates nothing without template related parameters' do
100
+ params = %w[--id=1 --organization-id=1 --location-id=1]
101
+
102
+ api_expects(:template_kinds, :index, 'Get list of template kinds').returns(index_response([]))
103
+ api_expects(:provisioning_templates, :update, 'Update template with no params').returns({})
104
+
105
+ expected_result = success_result("Nothing to update.\n")
106
+
107
+ result = run_cmd(@cmd + params)
108
+ assert_cmd(expected_result, result)
109
+ end
98
110
  end
99
111
 
100
112
  describe 'create' do
@@ -82,6 +82,17 @@ describe "user" do
82
82
  assert_cmd(expected_result, result)
83
83
  end
84
84
 
85
+ it 'updates nothing without user related parameters' do
86
+ params = %w[--id=1]
87
+
88
+ api_expects(:users, :update, 'Update user with no params').returns({})
89
+
90
+ expected_result = success_result("Nothing to update.\n")
91
+
92
+ result = run_cmd(cmd + params)
93
+ assert_cmd(expected_result, result)
94
+ end
95
+
85
96
  describe "update password" do
86
97
  def replace_foreman_connection(connection)
87
98
  HammerCLI.context[:api_connection].drop('foreman')