hammer_cli_foreman 3.1.0 → 3.4.0

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 (49) hide show
  1. checksums.yaml +4 -4
  2. data/config/foreman.yml +4 -0
  3. data/doc/configuration.md +30 -0
  4. data/doc/release_notes.md +24 -0
  5. data/lib/hammer_cli_foreman/api/authenticator.rb +9 -0
  6. data/lib/hammer_cli_foreman/api/connection.rb +2 -0
  7. data/lib/hammer_cli_foreman/api/negotiate_auth.rb +36 -0
  8. data/lib/hammer_cli_foreman/api/session_authenticator_wrapper.rb +6 -2
  9. data/lib/hammer_cli_foreman/api.rb +2 -1
  10. data/lib/hammer_cli_foreman/auth.rb +13 -0
  11. data/lib/hammer_cli_foreman/command_extensions/domain.rb +20 -0
  12. data/lib/hammer_cli_foreman/command_extensions.rb +1 -0
  13. data/lib/hammer_cli_foreman/commands.rb +5 -1
  14. data/lib/hammer_cli_foreman/compute_resource/libvirt.rb +4 -2
  15. data/lib/hammer_cli_foreman/compute_resource/vmware.rb +4 -2
  16. data/lib/hammer_cli_foreman/domain.rb +5 -28
  17. data/lib/hammer_cli_foreman/exception_handler.rb +26 -0
  18. data/lib/hammer_cli_foreman/filter.rb +3 -3
  19. data/lib/hammer_cli_foreman/host.rb +1 -0
  20. data/lib/hammer_cli_foreman/id_resolver.rb +2 -1
  21. data/lib/hammer_cli_foreman/partition_table.rb +30 -0
  22. data/lib/hammer_cli_foreman/report_template.rb +15 -0
  23. data/lib/hammer_cli_foreman/smart_proxy.rb +11 -0
  24. data/lib/hammer_cli_foreman/table_preference.rb +48 -0
  25. data/lib/hammer_cli_foreman/template.rb +30 -0
  26. data/lib/hammer_cli_foreman/user.rb +4 -0
  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/3.4/foreman_api.json +1 -0
  42. data/test/functional/domain/create_test.rb +91 -0
  43. data/test/functional/domain/update_test.rb +90 -0
  44. data/test/functional/partition_table_test.rb +63 -0
  45. data/test/functional/report_template_test.rb +24 -0
  46. data/test/functional/table_preference_test.rb +100 -0
  47. data/test/functional/template_test.rb +60 -0
  48. data/test/test_helper.rb +1 -1
  49. metadata +58 -45
@@ -0,0 +1,91 @@
1
+ require_relative '../test_helper'
2
+
3
+ describe 'Domain' do
4
+ describe 'CreateCommand' do
5
+ let(:cmd) { %w[domain create] }
6
+ let(:minimal_params) { %w[--name=dom1.com] }
7
+
8
+ def domain_params(additional_params = {})
9
+ params = {
10
+ domain: {
11
+ name: 'dom1.com'
12
+ }
13
+ }
14
+ params[:domain].merge!(additional_params)
15
+ params
16
+ end
17
+
18
+ it 'should print error on missing --name' do
19
+ expected_result = missing_args_error_result(cmd, '--name')
20
+
21
+ api_expects_no_call
22
+
23
+ result = run_cmd(cmd)
24
+ assert_cmd(expected_result, result)
25
+ end
26
+
27
+ it 'allows minimal options' do
28
+ api_expects(:domains, :create).with_params(domain_params)
29
+
30
+ run_cmd(cmd + minimal_params)
31
+ end
32
+
33
+ it 'allows description' do
34
+ params = %w[--description=shortdesc]
35
+ api_expects(:domains, :create).with_params(domain_params(fullname: 'shortdesc'))
36
+
37
+ run_cmd(cmd + minimal_params + params)
38
+ end
39
+
40
+ it 'allows dns id' do
41
+ params = %w[--dns-id=1]
42
+ api_expects(:domains, :create).with_params(domain_params(dns_id: 1))
43
+
44
+ run_cmd(cmd + minimal_params + params)
45
+ end
46
+
47
+ it 'allows dns name' do
48
+ params = %w[--dns=sp1]
49
+ api_expects_search(:smart_proxies, { name: 'sp1' }).returns(
50
+ index_response([{ 'id' => 1 }])
51
+ )
52
+ api_expects(:domains, :create).with_params(domain_params(dns_id: 1))
53
+
54
+ run_cmd(cmd + minimal_params + params)
55
+ end
56
+
57
+ it 'allows location ids' do
58
+ params = %w[--location-ids=1,4]
59
+ api_expects(:domains, :create).with_params(domain_params(location_ids: %w[1 4]))
60
+
61
+ run_cmd(cmd + minimal_params + params)
62
+ end
63
+
64
+ it 'allows location names' do
65
+ params = %w[--locations=loc1,loc2]
66
+ api_expects(:locations, :index) do |p|
67
+ p[:search] == 'name = "loc1" or name = "loc2"'
68
+ end.returns(index_response([{ 'id' => 1 }, { 'id' => 2 }]))
69
+ api_expects(:domains, :create).with_params(domain_params(location_ids: [1, 2]))
70
+
71
+ run_cmd(cmd + minimal_params + params)
72
+ end
73
+
74
+ it 'allows organization ids' do
75
+ params = %w[--organization-ids=1,4]
76
+ api_expects(:domains, :create).with_params(domain_params(organization_ids: %w[1 4]))
77
+
78
+ run_cmd(cmd + minimal_params + params)
79
+ end
80
+
81
+ it 'allows organization names' do
82
+ params = %w[--organizations=org1,org2]
83
+ api_expects(:organizations, :index) do |p|
84
+ p[:search] == 'name = "org1" or name = "org2"'
85
+ end.returns(index_response([{ 'id' => 1 }, { 'id' => 2 }]))
86
+ api_expects(:domains, :create).with_params(domain_params(organization_ids: [1, 2]))
87
+
88
+ run_cmd(cmd + minimal_params + params)
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,90 @@
1
+ require_relative '../test_helper'
2
+
3
+ describe 'Domain' do
4
+ describe 'UpdateCommand' do
5
+ let(:cmd) { %w[domain update] }
6
+ let(:minimal_params) { %w[--id=1] }
7
+
8
+ def domain_params(additional_params = {})
9
+ params = {
10
+ id: '1',
11
+ domain: {}
12
+ }
13
+ params[:domain].merge!(additional_params)
14
+ params
15
+ end
16
+
17
+ it 'should print error on missing --id' do
18
+ expected_result = missing_args_error_result(cmd, '--id')
19
+
20
+ api_expects_no_call
21
+
22
+ result = run_cmd(cmd)
23
+ assert_cmd(expected_result, result)
24
+ end
25
+
26
+ it 'allows minimal options' do
27
+ api_expects(:domains, :update).with_params(domain_params)
28
+
29
+ run_cmd(cmd + minimal_params)
30
+ end
31
+
32
+ it 'allows description' do
33
+ params = %w[--description=shortdesc]
34
+ api_expects(:domains, :update).with_params(domain_params(fullname: 'shortdesc'))
35
+
36
+ run_cmd(cmd + minimal_params + params)
37
+ end
38
+
39
+ it 'allows dns id' do
40
+ params = %w[--dns-id=1]
41
+ api_expects(:domains, :update).with_params(domain_params(dns_id: 1))
42
+
43
+ run_cmd(cmd + minimal_params + params)
44
+ end
45
+
46
+ it 'allows dns name' do
47
+ params = %w[--dns=sp1]
48
+ api_expects_search(:smart_proxies, { name: 'sp1' }).returns(
49
+ index_response([{ 'id' => 1 }])
50
+ )
51
+ api_expects(:domains, :update).with_params(domain_params(dns_id: 1))
52
+
53
+ run_cmd(cmd + minimal_params + params)
54
+ end
55
+
56
+ it 'allows location ids' do
57
+ params = %w[--location-ids=1,4]
58
+ api_expects(:domains, :update).with_params(domain_params(location_ids: %w[1 4]))
59
+
60
+ run_cmd(cmd + minimal_params + params)
61
+ end
62
+
63
+ it 'allows location names' do
64
+ params = %w[--locations=loc1,loc2]
65
+ api_expects(:locations, :index) do |p|
66
+ p[:search] == 'name = "loc1" or name = "loc2"'
67
+ end.returns(index_response([{ 'id' => 1 }, { 'id' => 2 }]))
68
+ api_expects(:domains, :update).with_params(domain_params(location_ids: [1, 2]))
69
+
70
+ run_cmd(cmd + minimal_params + params)
71
+ end
72
+
73
+ it 'allows organization ids' do
74
+ params = %w[--organization-ids=1,4]
75
+ api_expects(:domains, :update).with_params(domain_params(organization_ids: %w[1 4]))
76
+
77
+ run_cmd(cmd + minimal_params + params)
78
+ end
79
+
80
+ it 'allows organization names' do
81
+ params = %w[--organizations=org1,org2]
82
+ api_expects(:organizations, :index) do |p|
83
+ p[:search] == 'name = "org1" or name = "org2"'
84
+ end.returns(index_response([{ 'id' => 1 }, { 'id' => 2 }]))
85
+ api_expects(:domains, :update).with_params(domain_params(organization_ids: [1, 2]))
86
+
87
+ run_cmd(cmd + minimal_params + params)
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,63 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ describe 'partition-table' do
4
+ describe 'import' do
5
+ let(:template) do
6
+ {
7
+ 'id' => 1,
8
+ 'template' => 'Template content'
9
+ }
10
+ end
11
+ let(:cmd) { %w(partition-table import) }
12
+ let(:tempfile) { Tempfile.new('template') }
13
+
14
+ it 'requires --name and --file' do
15
+ params = ['--name=test']
16
+ api_expects_no_call
17
+ expected_result = usage_error_result(
18
+ cmd,
19
+ 'Options --name, --file are required.',
20
+ 'Could not import partition table template')
21
+ result = run_cmd(cmd + params)
22
+ assert_cmd(expected_result, result)
23
+ end
24
+
25
+ it 'import template' do
26
+ params = ['--name=test', "--file=#{tempfile.path}"]
27
+ tempfile.write('Template content')
28
+ tempfile.rewind
29
+ api_expects(:ptables, :import, 'Import partition table template').with_params(
30
+ 'ptable' => {
31
+ 'name' => 'test',
32
+ 'template' => 'Template content'
33
+ }).returns(template)
34
+
35
+ result = run_cmd(cmd + params)
36
+ assert_cmd(success_result("Import partition table template succeeded.\n"), result)
37
+ end
38
+ end
39
+
40
+ describe 'export' do
41
+ let(:cmd) { %w(partition-table export) }
42
+ let(:tempfile) { Tempfile.new('template', '/tmp') }
43
+ let(:params) { ['--id=1', '--path=/tmp'] }
44
+ let(:template_response) do
45
+ response = mock('TemplateResponse')
46
+ response.stubs(:code).returns(200)
47
+ response.stubs(:body).returns('Template content')
48
+ response.stubs(:headers).returns({:content_disposition => "filename=\"#{File.basename(tempfile.path)}\""})
49
+ response
50
+ end
51
+
52
+ it 'download template' do
53
+ api_expects(:ptables, :export, 'Export partition table template').with_params(
54
+ 'id' => '1').returns(template_response)
55
+
56
+ output = OutputMatcher.new("The partition table template has been saved to #{tempfile.path}")
57
+ expected_result = success_result(output)
58
+ result = run_cmd(cmd + params)
59
+ assert_cmd(expected_result, result)
60
+ assert_equal('Template content', tempfile.read)
61
+ end
62
+ end
63
+ end
@@ -384,6 +384,30 @@ describe 'report-template' do
384
384
  end
385
385
  end
386
386
 
387
+ describe 'export' do
388
+ let(:cmd) { %w(report-template export) }
389
+ let(:tempfile) { Tempfile.new('template', '/tmp') }
390
+ let(:params) { ['--id=1', '--path=/tmp'] }
391
+ let(:template_response) do
392
+ response = mock('TemplateResponse')
393
+ response.stubs(:code).returns(200)
394
+ response.stubs(:body).returns('Template content')
395
+ response.stubs(:headers).returns({:content_disposition => "filename=\"#{File.basename(tempfile.path)}\""})
396
+ response
397
+ end
398
+
399
+ it 'download template' do
400
+ api_expects(:report_templates, :export, 'Export report template').with_params(
401
+ 'id' => '1').returns(template_response)
402
+
403
+ output = OutputMatcher.new("The report template has been saved to #{tempfile.path}")
404
+ expected_result = success_result(output)
405
+ result = run_cmd(cmd + params)
406
+ assert_cmd(expected_result, result)
407
+ assert_equal('Template content', tempfile.read)
408
+ end
409
+ end
410
+
387
411
  describe 'report-data' do
388
412
  let(:cmd) { %w(report-template report-data) }
389
413
  let(:tempfile) { Tempfile.new('template', '/tmp') }
@@ -0,0 +1,100 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ describe 'table_preference' do
4
+ let(:base_cmd) { ['user', 'table-preference'] }
5
+ let(:user) do
6
+ {
7
+ :id => 1,
8
+ :name => 'admin'
9
+ }
10
+ end
11
+ let(:table_preference) do
12
+ {
13
+ :id => 1,
14
+ :user_id => user[:id],
15
+ :name => 'Table Preference',
16
+ :columns => ['A', 'B', 'C']
17
+ }
18
+ end
19
+
20
+ describe 'list' do
21
+ let(:cmd) { base_cmd << 'list' }
22
+
23
+ it 'lists table preferences for a given user' do
24
+ params = ['--user-id', user[:id]]
25
+ api_expects(:table_preferences, :index, params)
26
+ .returns(index_response([table_preference]))
27
+
28
+ expected_result = success_result(/#{table_preference[:name]}/)
29
+
30
+ result = run_cmd(cmd + params)
31
+ assert_cmd(expected_result, result)
32
+ end
33
+ end
34
+
35
+ describe 'create' do
36
+ let(:cmd) { base_cmd << 'create' }
37
+
38
+ it 'creates a table preference for a given table' do
39
+ params = ['--user-id', user[:id],
40
+ '--name', table_preference[:name],
41
+ '--columns', table_preference[:columns]]
42
+ api_expects(:table_preferences, :create, params)
43
+ .returns(table_preference)
44
+
45
+ expected_result = success_result("Table preference created.\n")
46
+
47
+ result = run_cmd(cmd + params)
48
+ assert_cmd(expected_result, result)
49
+ end
50
+ end
51
+
52
+ describe 'update' do
53
+ let(:cmd) { base_cmd << 'update' }
54
+
55
+ it 'updates a table preference for a given table' do
56
+ params = ['--user-id', user[:id],
57
+ '--name', table_preference[:name],
58
+ '--columns', ['A','B','C','D','E']]
59
+ api_expects(:table_preferences, :update, params)
60
+ .returns(table_preference)
61
+
62
+ expected_result = success_result("Table preference updated.\n")
63
+
64
+ result = run_cmd(cmd + params)
65
+ assert_cmd(expected_result, result)
66
+ end
67
+ end
68
+
69
+ describe 'info' do
70
+ let(:cmd) { base_cmd << 'info' }
71
+
72
+ it 'shows table preference details of a given table' do
73
+ params = ['--user-id', user[:id],
74
+ '--name', table_preference[:name]]
75
+ api_expects(:table_preferences, :show, params)
76
+ .returns(table_preference)
77
+
78
+ expected_result = success_result(/#{table_preference[:name]} | #{table_preference[:columns]}/)
79
+
80
+ result = run_cmd(cmd + params)
81
+ assert_cmd(expected_result, result)
82
+ end
83
+ end
84
+
85
+ describe 'delete' do
86
+ let(:cmd) { base_cmd << 'delete' }
87
+
88
+ it 'deletes a table preference for a given table' do
89
+ params = ['--user-id', user[:id],
90
+ '--name', table_preference[:name]]
91
+ api_expects(:table_preferences, :destroy, params)
92
+ .returns({})
93
+
94
+ expected_result = success_result("Table preference deleted.\n")
95
+
96
+ result = run_cmd(cmd + params)
97
+ assert_cmd(expected_result, result)
98
+ end
99
+ end
100
+ end
@@ -77,6 +77,66 @@ describe 'template' do
77
77
  end
78
78
  end
79
79
 
80
+ describe 'import' do
81
+ let(:template) do
82
+ {
83
+ 'id' => 1,
84
+ 'template' => 'Template content'
85
+ }
86
+ end
87
+ let(:cmd) { %w(template import) }
88
+ let(:tempfile) { Tempfile.new('template') }
89
+
90
+ it 'requires --name and --file' do
91
+ params = ['--name=test']
92
+ api_expects_no_call
93
+ expected_result = usage_error_result(
94
+ cmd,
95
+ 'Options --name, --file are required.',
96
+ 'Could not import provisioning template')
97
+ result = run_cmd(cmd + params)
98
+ assert_cmd(expected_result, result)
99
+ end
100
+
101
+ it 'import template' do
102
+ params = ['--name=test', "--file=#{tempfile.path}"]
103
+ tempfile.write('Template content')
104
+ tempfile.rewind
105
+ api_expects(:provisioning_templates, :import, 'Import template').with_params(
106
+ 'provisioning_template' => {
107
+ 'name' => 'test',
108
+ 'template' => 'Template content'
109
+ }).returns(template)
110
+
111
+ result = run_cmd(cmd + params)
112
+ assert_cmd(success_result("Import provisioning template succeeded.\n"), result)
113
+ end
114
+ end
115
+
116
+ describe 'export' do
117
+ let(:cmd) { %w(template export) }
118
+ let(:tempfile) { Tempfile.new('template', '/tmp') }
119
+ let(:params) { ['--id=1', '--path=/tmp'] }
120
+ let(:template_response) do
121
+ response = mock('TemplateResponse')
122
+ response.stubs(:code).returns(200)
123
+ response.stubs(:body).returns('Template content')
124
+ response.stubs(:headers).returns({:content_disposition => "filename=\"#{File.basename(tempfile.path)}\""})
125
+ response
126
+ end
127
+
128
+ it 'download template' do
129
+ api_expects(:provisioning_templates, :export, 'Export template').with_params(
130
+ 'id' => '1').returns(template_response)
131
+
132
+ output = OutputMatcher.new("The provisioning template has been saved to #{tempfile.path}")
133
+ expected_result = success_result(output)
134
+ result = run_cmd(cmd + params)
135
+ assert_cmd(expected_result, result)
136
+ assert_equal('Template content', tempfile.read)
137
+ end
138
+ end
139
+
80
140
  describe 'update' do
81
141
  before do
82
142
  @cmd = %w(template update)
data/test/test_helper.rb CHANGED
@@ -17,7 +17,7 @@ require "mocha/minitest"
17
17
  require 'hammer_cli'
18
18
  require 'hammer_cli_foreman/testing/api_expectations'
19
19
 
20
- FOREMAN_VERSION = ENV['TEST_API_VERSION'] || '3.1'
20
+ FOREMAN_VERSION = ENV['TEST_API_VERSION'] || '3.4'
21
21
  unless Dir.entries('test/data').include? FOREMAN_VERSION
22
22
  raise StandardError.new "Version is not correct"
23
23
  end