hammer_cli_foreman_virt_who_configure 0.0.9 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hammer_cli_foreman_virt_who_configure/config.rb +29 -28
- data/lib/hammer_cli_foreman_virt_who_configure/i18n.rb +2 -0
- data/lib/hammer_cli_foreman_virt_who_configure/system_caller.rb +3 -1
- data/lib/hammer_cli_foreman_virt_who_configure/version.rb +3 -1
- data/lib/hammer_cli_foreman_virt_who_configure.rb +5 -3
- data/locale/bn/LC_MESSAGES/hammer-cli-foreman-virt-who-configure.mo +0 -0
- data/locale/bn_IN/LC_MESSAGES/hammer-cli-foreman-virt-who-configure.mo +0 -0
- data/locale/bqi/LC_MESSAGES/hammer-cli-foreman-virt-who-configure.mo +0 -0
- data/locale/ca/LC_MESSAGES/hammer-cli-foreman-virt-who-configure.mo +0 -0
- data/locale/cs_CZ/LC_MESSAGES/hammer-cli-foreman-virt-who-configure.mo +0 -0
- data/locale/de/LC_MESSAGES/hammer-cli-foreman-virt-who-configure.mo +0 -0
- data/locale/de_AT/LC_MESSAGES/hammer-cli-foreman-virt-who-configure.mo +0 -0
- data/locale/de_DE/LC_MESSAGES/hammer-cli-foreman-virt-who-configure.mo +0 -0
- data/locale/el/LC_MESSAGES/hammer-cli-foreman-virt-who-configure.mo +0 -0
- data/locale/en/LC_MESSAGES/hammer-cli-foreman-virt-who-configure.mo +0 -0
- data/locale/en_GB/LC_MESSAGES/hammer-cli-foreman-virt-who-configure.mo +0 -0
- data/locale/en_US/LC_MESSAGES/hammer-cli-foreman-virt-who-configure.mo +0 -0
- data/locale/es/LC_MESSAGES/hammer-cli-foreman-virt-who-configure.mo +0 -0
- data/locale/et_EE/LC_MESSAGES/hammer-cli-foreman-virt-who-configure.mo +0 -0
- data/locale/fr/LC_MESSAGES/hammer-cli-foreman-virt-who-configure.mo +0 -0
- data/locale/gl/LC_MESSAGES/hammer-cli-foreman-virt-who-configure.mo +0 -0
- data/locale/gu/LC_MESSAGES/hammer-cli-foreman-virt-who-configure.mo +0 -0
- data/locale/he_IL/LC_MESSAGES/hammer-cli-foreman-virt-who-configure.mo +0 -0
- data/locale/hi/LC_MESSAGES/hammer-cli-foreman-virt-who-configure.mo +0 -0
- data/locale/id/LC_MESSAGES/hammer-cli-foreman-virt-who-configure.mo +0 -0
- data/locale/it/LC_MESSAGES/hammer-cli-foreman-virt-who-configure.mo +0 -0
- data/locale/ja/LC_MESSAGES/hammer-cli-foreman-virt-who-configure.mo +0 -0
- data/locale/ka/LC_MESSAGES/hammer-cli-foreman-virt-who-configure.mo +0 -0
- data/locale/kn/LC_MESSAGES/hammer-cli-foreman-virt-who-configure.mo +0 -0
- data/locale/ko/LC_MESSAGES/hammer-cli-foreman-virt-who-configure.mo +0 -0
- data/locale/ml_IN/LC_MESSAGES/hammer-cli-foreman-virt-who-configure.mo +0 -0
- data/locale/mr/LC_MESSAGES/hammer-cli-foreman-virt-who-configure.mo +0 -0
- data/locale/nl_NL/LC_MESSAGES/hammer-cli-foreman-virt-who-configure.mo +0 -0
- data/locale/or/LC_MESSAGES/hammer-cli-foreman-virt-who-configure.mo +0 -0
- data/locale/pa/LC_MESSAGES/hammer-cli-foreman-virt-who-configure.mo +0 -0
- data/locale/pl/LC_MESSAGES/hammer-cli-foreman-virt-who-configure.mo +0 -0
- data/locale/pl_PL/LC_MESSAGES/hammer-cli-foreman-virt-who-configure.mo +0 -0
- data/locale/pt/LC_MESSAGES/hammer-cli-foreman-virt-who-configure.mo +0 -0
- data/locale/pt_BR/LC_MESSAGES/hammer-cli-foreman-virt-who-configure.mo +0 -0
- data/locale/ro/LC_MESSAGES/hammer-cli-foreman-virt-who-configure.mo +0 -0
- data/locale/ro_RO/LC_MESSAGES/hammer-cli-foreman-virt-who-configure.mo +0 -0
- data/locale/ru/LC_MESSAGES/hammer-cli-foreman-virt-who-configure.mo +0 -0
- data/locale/sl/LC_MESSAGES/hammer-cli-foreman-virt-who-configure.mo +0 -0
- data/locale/sv_SE/LC_MESSAGES/hammer-cli-foreman-virt-who-configure.mo +0 -0
- data/locale/ta/LC_MESSAGES/hammer-cli-foreman-virt-who-configure.mo +0 -0
- data/locale/ta_IN/LC_MESSAGES/hammer-cli-foreman-virt-who-configure.mo +0 -0
- data/locale/te/LC_MESSAGES/hammer-cli-foreman-virt-who-configure.mo +0 -0
- data/locale/tr/LC_MESSAGES/hammer-cli-foreman-virt-who-configure.mo +0 -0
- data/locale/vi/LC_MESSAGES/hammer-cli-foreman-virt-who-configure.mo +0 -0
- data/locale/vi_VN/LC_MESSAGES/hammer-cli-foreman-virt-who-configure.mo +0 -0
- data/locale/zh/LC_MESSAGES/hammer-cli-foreman-virt-who-configure.mo +0 -0
- data/locale/zh_CN/LC_MESSAGES/hammer-cli-foreman-virt-who-configure.mo +0 -0
- data/locale/zh_TW/LC_MESSAGES/hammer-cli-foreman-virt-who-configure.mo +0 -0
- data/test/data/3.11/foreman_api.json +1 -0
- data/test/functional/config/config_create_test.rb +21 -29
- data/test/functional/config/config_deploy_test.rb +16 -14
- data/test/functional/config/config_fetch_test.rb +12 -10
- data/test/functional/config/config_info_test.rb +45 -43
- data/test/functional/config/config_list_test.rb +11 -9
- data/test/functional/config/config_update_test.rb +7 -5
- data/test/functional/test_helper.rb +23 -21
- data/test/test_helper.rb +4 -2
- data/test/unit/system_caller_test.rb +5 -2
- metadata +193 -17
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative '../test_helper'
|
2
4
|
|
3
|
-
describe
|
4
|
-
describe
|
5
|
+
describe 'virt-who-config' do
|
6
|
+
describe 'create' do
|
5
7
|
before do
|
6
|
-
@cmd = [
|
8
|
+
@cmd = ['virt-who-config', 'create']
|
7
9
|
@required_args = {
|
8
10
|
:name => 'test',
|
9
11
|
:interval => 60,
|
@@ -17,57 +19,47 @@ describe "virt-who-config" do
|
|
17
19
|
}
|
18
20
|
end
|
19
21
|
|
20
|
-
it
|
22
|
+
it 'requires --name' do
|
21
23
|
params = hash_to_opts(@required_args, :reject => :name)
|
22
24
|
assert_requires_argument(@cmd, params, 'name')
|
23
25
|
end
|
24
26
|
|
25
|
-
it
|
27
|
+
it 'requires --interval' do
|
26
28
|
params = hash_to_opts(@required_args, :reject => :interval)
|
27
29
|
assert_requires_argument(@cmd, params, 'interval')
|
28
30
|
end
|
29
31
|
|
30
|
-
it
|
32
|
+
it 'requires --filtering-mode' do
|
31
33
|
params = hash_to_opts(@required_args, :reject => :filtering_mode)
|
32
|
-
assert_requires_argument(@cmd, params, '
|
34
|
+
assert_requires_argument(@cmd, params, 'filtering-mode')
|
33
35
|
end
|
34
36
|
|
35
|
-
it
|
37
|
+
it 'requires --hypervisor-id' do
|
36
38
|
params = hash_to_opts(@required_args, :reject => :hypervisor_id)
|
37
|
-
assert_requires_argument(@cmd, params, '
|
39
|
+
assert_requires_argument(@cmd, params, 'hypervisor-id')
|
38
40
|
end
|
39
41
|
|
40
|
-
it
|
42
|
+
it 'validates --hypervisor-id values' do
|
41
43
|
params = hash_to_opts(@required_args.merge(:hypervisor_id => 'other'))
|
42
|
-
assert_usage_error(@cmd, params, "
|
44
|
+
assert_usage_error(@cmd, params, "Option '--hypervisor-id': Value must be one of 'hostname', 'uuid', 'hwuuid'..")
|
43
45
|
end
|
44
46
|
|
45
|
-
it
|
47
|
+
it 'requires --hypervisor-type' do
|
46
48
|
params = hash_to_opts(@required_args, :reject => :hypervisor_type)
|
47
|
-
assert_requires_argument(@cmd, params, '
|
49
|
+
assert_requires_argument(@cmd, params, 'hypervisor-type')
|
48
50
|
end
|
49
51
|
|
50
|
-
it
|
52
|
+
it 'validates --hypervisor-type values' do
|
51
53
|
params = hash_to_opts(@required_args.merge(:hypervisor_type => 'other'))
|
52
|
-
assert_usage_error(@cmd, params, "
|
53
|
-
end
|
54
|
-
|
55
|
-
it "requires --hypervisor-server" do
|
56
|
-
params = hash_to_opts(@required_args, :reject => :hypervisor_server)
|
57
|
-
assert_requires_argument(@cmd, params, 'hypervisor_server')
|
58
|
-
end
|
59
|
-
|
60
|
-
it "requires --hypervisor-username" do
|
61
|
-
params = hash_to_opts(@required_args, :reject => :hypervisor_username)
|
62
|
-
assert_requires_argument(@cmd, params, 'hypervisor_username')
|
54
|
+
assert_usage_error(@cmd, params, "Option '--hypervisor-type': Value must be one of 'esx', 'hyperv', 'libvirt', 'kubevirt', 'ahv'..")
|
63
55
|
end
|
64
56
|
|
65
|
-
it
|
57
|
+
it 'requires --satellite-url' do
|
66
58
|
params = hash_to_opts(@required_args, :reject => :satellite_url)
|
67
|
-
assert_requires_argument(@cmd, params, '
|
59
|
+
assert_requires_argument(@cmd, params, 'satellite-url')
|
68
60
|
end
|
69
61
|
|
70
|
-
it
|
62
|
+
it 'sends values to api' do
|
71
63
|
params = hash_to_opts(@required_args)
|
72
64
|
|
73
65
|
expected_result = success_result("Virt Who configuration [test] created\n")
|
@@ -84,7 +76,7 @@ describe "virt-who-config" do
|
|
84
76
|
'satellite_url' => '1',
|
85
77
|
'organization_id' => 1
|
86
78
|
}
|
87
|
-
).returns(
|
79
|
+
).returns(:config => { :name => 'test'})
|
88
80
|
|
89
81
|
result = run_cmd(@cmd + params)
|
90
82
|
assert_cmd(expected_result, result)
|
@@ -1,55 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative '../test_helper'
|
2
4
|
|
3
|
-
describe
|
4
|
-
describe
|
5
|
+
describe 'virt-who-config' do
|
6
|
+
describe 'deploy' do
|
5
7
|
class FakeSystemCaller
|
6
|
-
def initialize(output, result=true)
|
8
|
+
def initialize(output, result = true)
|
7
9
|
@output = output
|
8
10
|
@result = result
|
9
11
|
end
|
10
12
|
|
11
|
-
def system(
|
13
|
+
def system(_script)
|
12
14
|
puts @output
|
13
15
|
@result
|
14
16
|
end
|
15
17
|
end
|
16
18
|
|
17
19
|
before do
|
18
|
-
@cmd = [
|
20
|
+
@cmd = ['virt-who-config', 'deploy']
|
19
21
|
@params = ['--name=test']
|
20
22
|
@script = 'echo BASH SCRIPT'
|
21
23
|
end
|
22
24
|
|
23
|
-
it
|
25
|
+
it 'sends the script to #system' do
|
24
26
|
api_expects_search(:configs, :name => 'test').returns(index_response([config]))
|
25
|
-
api_expects(:configs, :deploy_script, 'Get config script').returns(
|
27
|
+
api_expects(:configs, :deploy_script, 'Get config script').returns('virt_who_config_script' => @script)
|
26
28
|
|
27
29
|
system_caller = mock
|
28
30
|
system_caller.expects(:system).with(@script).returns(true)
|
29
31
|
|
30
|
-
result = run_cmd(@cmd + @params,
|
32
|
+
result = run_cmd(@cmd + @params, :system_caller => system_caller)
|
31
33
|
assert_cmd(CommandExpectation.new, result)
|
32
34
|
end
|
33
35
|
|
34
|
-
it
|
36
|
+
it 'prints output of the script to stdout' do
|
35
37
|
api_expects_search(:configs, :name => 'test').returns(index_response([config]))
|
36
|
-
api_expects(:configs, :deploy_script, 'Get config script').returns(
|
38
|
+
api_expects(:configs, :deploy_script, 'Get config script').returns('virt_who_config_script' => @script)
|
37
39
|
|
38
40
|
system_caller = FakeSystemCaller.new('Script output...')
|
39
41
|
expected_result = CommandExpectation.new('Script output...' + "\n")
|
40
42
|
|
41
|
-
result = run_cmd(@cmd + @params,
|
43
|
+
result = run_cmd(@cmd + @params, :system_caller => system_caller)
|
42
44
|
assert_cmd(expected_result, result)
|
43
45
|
end
|
44
46
|
|
45
|
-
it
|
47
|
+
it 'returns HammerCLI::EX_SOFTWARE on config failure' do
|
46
48
|
api_expects_search(:configs, :name => 'test').returns(index_response([config]))
|
47
|
-
api_expects(:configs, :deploy_script, 'Get config script').returns(
|
49
|
+
api_expects(:configs, :deploy_script, 'Get config script').returns('virt_who_config_script' => @script)
|
48
50
|
|
49
51
|
system_caller = FakeSystemCaller.new('Script output...', false)
|
50
52
|
expected_result = CommandExpectation.new('Script output...' + "\n", '', HammerCLI::EX_SOFTWARE)
|
51
53
|
|
52
|
-
result = run_cmd(@cmd + @params,
|
54
|
+
result = run_cmd(@cmd + @params, :system_caller => system_caller)
|
53
55
|
assert_cmd(expected_result, result)
|
54
56
|
end
|
55
57
|
end
|
@@ -1,17 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative '../test_helper'
|
2
4
|
|
3
|
-
describe
|
4
|
-
describe
|
5
|
+
describe 'virt-who-config' do
|
6
|
+
describe 'fetch' do
|
5
7
|
before do
|
6
|
-
@cmd = [
|
8
|
+
@cmd = ['virt-who-config', 'fetch']
|
7
9
|
@script = 'echo BASH SCRIPT'
|
8
10
|
end
|
9
11
|
|
10
|
-
it
|
12
|
+
it 'prints script to stdout by default' do
|
11
13
|
params = ['--name=test']
|
12
14
|
|
13
15
|
api_expects_search(:configs, :name => 'test').returns(index_response([config]))
|
14
|
-
api_expects(:configs, :deploy_script, 'Get config script').returns(
|
16
|
+
api_expects(:configs, :deploy_script, 'Get config script').returns('virt_who_config_script' => @script)
|
15
17
|
|
16
18
|
expected_result = CommandExpectation.new(@script + "\n")
|
17
19
|
|
@@ -19,7 +21,7 @@ describe "virt-who-config" do
|
|
19
21
|
assert_cmd(expected_result, result)
|
20
22
|
end
|
21
23
|
|
22
|
-
it
|
24
|
+
it 'stores script into a file' do
|
23
25
|
file = Tempfile.new
|
24
26
|
file_path = file.path
|
25
27
|
file.unlink
|
@@ -27,7 +29,7 @@ describe "virt-who-config" do
|
|
27
29
|
params = ['--name=test', '--output', file_path]
|
28
30
|
|
29
31
|
api_expects_search(:configs, :name => 'test').returns(index_response([config]))
|
30
|
-
api_expects(:configs, :deploy_script, 'Get config script').returns(
|
32
|
+
api_expects(:configs, :deploy_script, 'Get config script').returns('virt_who_config_script' => @script)
|
31
33
|
|
32
34
|
result = run_cmd(@cmd + params)
|
33
35
|
|
@@ -38,13 +40,13 @@ describe "virt-who-config" do
|
|
38
40
|
end
|
39
41
|
end
|
40
42
|
|
41
|
-
it
|
43
|
+
it 'refuses to store the script into an existing file' do
|
42
44
|
file = Tempfile.new
|
43
45
|
begin
|
44
46
|
params = ['--name=test', '--output', file.path]
|
45
47
|
|
46
48
|
api_expects_search(:configs, :name => 'test').returns(index_response([config]))
|
47
|
-
api_expects(:configs, :deploy_script, 'Get config script').returns(
|
49
|
+
api_expects(:configs, :deploy_script, 'Get config script').returns('virt_who_config_script' => @script)
|
48
50
|
|
49
51
|
result = run_cmd(@cmd + params)
|
50
52
|
|
@@ -53,7 +55,7 @@ describe "virt-who-config" do
|
|
53
55
|
assert_cmd(expected_result, result)
|
54
56
|
assert_equal('', file.read)
|
55
57
|
ensure
|
56
|
-
|
58
|
+
file.unlink
|
57
59
|
end
|
58
60
|
end
|
59
61
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative '../test_helper'
|
2
4
|
|
3
5
|
def expect_config_search(config)
|
@@ -15,77 +17,77 @@ def test_output_field(cmd, config_modification, output_label, output_value)
|
|
15
17
|
end
|
16
18
|
|
17
19
|
def test_status_field(cmd, api_value, output_value)
|
18
|
-
test_output_field(cmd, {
|
20
|
+
test_output_field(cmd, { 'status' => api_value }, 'Status', output_value)
|
19
21
|
end
|
20
22
|
|
21
23
|
def test_interval_field(cmd, api_value, output_value)
|
22
|
-
test_output_field(cmd, {
|
24
|
+
test_output_field(cmd, { 'interval' => api_value }, 'Interval', output_value)
|
23
25
|
end
|
24
26
|
|
25
27
|
def test_filter_field(cmd, api_value, output_value)
|
26
|
-
test_output_field(cmd, {
|
28
|
+
test_output_field(cmd, { 'filtering_mode' => api_value }, 'Filtering', output_value)
|
27
29
|
end
|
28
30
|
|
29
|
-
describe
|
30
|
-
describe
|
31
|
+
describe 'virt-who-config' do
|
32
|
+
describe 'info' do
|
31
33
|
before do
|
32
|
-
@cmd = [
|
34
|
+
@cmd = ['virt-who-config', 'info', '--name=test']
|
33
35
|
end
|
34
36
|
|
35
|
-
describe
|
36
|
-
it
|
37
|
+
describe 'interval formatting' do
|
38
|
+
it 'formats 1 hour' do
|
37
39
|
test_interval_field(@cmd, 60, 'every hour')
|
38
40
|
end
|
39
41
|
|
40
|
-
it
|
42
|
+
it 'formats 2 hours' do
|
41
43
|
test_interval_field(@cmd, 120, 'every 2 hours')
|
42
44
|
end
|
43
45
|
end
|
44
46
|
|
45
|
-
describe
|
46
|
-
it
|
47
|
+
describe 'status formatting' do
|
48
|
+
it 'formats status unknown' do
|
47
49
|
test_status_field(@cmd, 'unknown', 'No Report Yet')
|
48
50
|
end
|
49
51
|
|
50
|
-
it
|
52
|
+
it 'formats status ok' do
|
51
53
|
test_status_field(@cmd, 'ok', 'OK')
|
52
54
|
end
|
53
55
|
|
54
|
-
it
|
56
|
+
it 'formats status out_of_date' do
|
55
57
|
test_status_field(@cmd, 'out_of_date', 'OK')
|
56
58
|
end
|
57
59
|
|
58
|
-
it
|
60
|
+
it 'formats status error' do
|
59
61
|
test_status_field(@cmd, 'error', 'Error')
|
60
62
|
end
|
61
63
|
|
62
|
-
it
|
64
|
+
it 'formats unknown status' do
|
63
65
|
test_status_field(@cmd, nil, 'Unknown configuration status')
|
64
66
|
end
|
65
67
|
end
|
66
68
|
|
67
|
-
describe
|
68
|
-
it
|
69
|
+
describe 'when filter is none' do
|
70
|
+
it 'formats filter' do
|
69
71
|
test_filter_field(@cmd, 0, 'Unlimited')
|
70
72
|
end
|
71
|
-
it
|
72
|
-
expect_config_search(config(
|
73
|
+
it 'hides whitelist field' do
|
74
|
+
expect_config_search(config('filtering_mode' => 0))
|
73
75
|
refute_match('Filtered hosts:', run_cmd(@cmd).out)
|
74
76
|
end
|
75
77
|
|
76
|
-
it
|
77
|
-
expect_config_search(config(
|
78
|
+
it 'hides blacklist field' do
|
79
|
+
expect_config_search(config('filtering_mode' => 0))
|
78
80
|
refute_match('Excluded hosts:', run_cmd(@cmd).out)
|
79
81
|
end
|
80
82
|
end
|
81
83
|
|
82
|
-
describe
|
83
|
-
it
|
84
|
+
describe 'when filter is whitelist' do
|
85
|
+
it 'formats filter' do
|
84
86
|
test_filter_field(@cmd, 1, 'Whitelist')
|
85
87
|
end
|
86
88
|
|
87
|
-
it
|
88
|
-
expect_config_search(config(
|
89
|
+
it 'shows whitelist field' do
|
90
|
+
expect_config_search(config('filtering_mode' => 1, 'whitelist' => 'host1,hostb'))
|
89
91
|
|
90
92
|
output = FieldMatcher.new('Filtered hosts', 'host1,hostb')
|
91
93
|
|
@@ -93,24 +95,24 @@ describe "virt-who-config" do
|
|
93
95
|
assert_cmd(success_result(output), result)
|
94
96
|
end
|
95
97
|
|
96
|
-
it
|
97
|
-
expect_config_search(config(
|
98
|
+
it 'shows empty whitelist field' do
|
99
|
+
expect_config_search(config('filtering_mode' => 1, 'whitelist' => nil))
|
98
100
|
assert_match('Filtered hosts:', run_cmd(@cmd).out)
|
99
101
|
end
|
100
102
|
|
101
|
-
it
|
102
|
-
expect_config_search(config(
|
103
|
+
it 'hides blacklist field' do
|
104
|
+
expect_config_search(config('filtering_mode' => 1))
|
103
105
|
refute_match('Excluded hosts:', run_cmd(@cmd).out)
|
104
106
|
end
|
105
107
|
end
|
106
108
|
|
107
|
-
describe
|
108
|
-
it
|
109
|
+
describe 'when filter is blacklist' do
|
110
|
+
it 'formats filter' do
|
109
111
|
test_filter_field(@cmd, 2, 'Blacklist')
|
110
112
|
end
|
111
113
|
|
112
|
-
it
|
113
|
-
expect_config_search(config(
|
114
|
+
it 'shows blacklist field' do
|
115
|
+
expect_config_search(config('filtering_mode' => 2, 'blacklist' => 'host1,hostb'))
|
114
116
|
|
115
117
|
output = FieldMatcher.new('Excluded hosts', 'host1,hostb')
|
116
118
|
|
@@ -118,28 +120,28 @@ describe "virt-who-config" do
|
|
118
120
|
assert_cmd(success_result(output), result)
|
119
121
|
end
|
120
122
|
|
121
|
-
it
|
122
|
-
expect_config_search(config(
|
123
|
+
it 'shows empty blacklist field' do
|
124
|
+
expect_config_search(config('filtering_mode' => 2, 'whitelist' => nil))
|
123
125
|
assert_match('Excluded hosts:', run_cmd(@cmd).out)
|
124
126
|
end
|
125
127
|
|
126
|
-
it
|
127
|
-
expect_config_search(config(
|
128
|
+
it 'hides whitelist field' do
|
129
|
+
expect_config_search(config('filtering_mode' => 2))
|
128
130
|
refute_match('Filtered hosts:', run_cmd(@cmd).out)
|
129
131
|
end
|
130
132
|
end
|
131
133
|
|
132
|
-
describe
|
133
|
-
it
|
134
|
+
describe 'when filter is unknown value' do
|
135
|
+
it 'formats filter' do
|
134
136
|
test_filter_field(@cmd, nil, 'Unknown listing mode')
|
135
137
|
end
|
136
|
-
it
|
137
|
-
expect_config_search(config(
|
138
|
+
it 'hides whitelist field' do
|
139
|
+
expect_config_search(config('filtering_mode' => 0))
|
138
140
|
refute_match('Filtered hosts:', run_cmd(@cmd).out)
|
139
141
|
end
|
140
142
|
|
141
|
-
it
|
142
|
-
expect_config_search(config(
|
143
|
+
it 'hides blacklist field' do
|
144
|
+
expect_config_search(config('filtering_mode' => 0))
|
143
145
|
refute_match('Excluded hosts:', run_cmd(@cmd).out)
|
144
146
|
end
|
145
147
|
end
|
@@ -1,17 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative '../test_helper'
|
2
4
|
|
3
|
-
describe
|
4
|
-
describe
|
5
|
+
describe 'virt-who-config' do
|
6
|
+
describe 'list' do
|
5
7
|
before do
|
6
|
-
@cmd = [
|
8
|
+
@cmd = ['virt-who-config', 'list']
|
7
9
|
end
|
8
10
|
|
9
|
-
it
|
11
|
+
it 'formats interval and status' do
|
10
12
|
configs = [
|
11
13
|
config,
|
12
14
|
config('status' => 'ok', 'interval' => 120),
|
13
15
|
config('status' => 'out_of_date', 'interval' => 240),
|
14
|
-
config('status' => 'error', 'interval' => 480)
|
16
|
+
config('status' => 'error', 'interval' => 480)
|
15
17
|
]
|
16
18
|
|
17
19
|
api_expects(:configs, :index).returns(index_response(configs))
|
@@ -28,20 +30,20 @@ describe "virt-who-config" do
|
|
28
30
|
assert_cmd(success_result(output), result)
|
29
31
|
end
|
30
32
|
|
31
|
-
it
|
33
|
+
it 'supports pagination' do
|
32
34
|
params = ['--page=2', '--per-page=10', '--order', 'name ASC']
|
33
35
|
|
34
36
|
api_expects(:configs, :index).with_params(
|
35
|
-
'page' =>
|
37
|
+
'page' => 2,
|
36
38
|
'per_page' => '10',
|
37
|
-
'order' => 'name ASC'
|
39
|
+
'order' => 'name ASC'
|
38
40
|
).returns(index_response([]))
|
39
41
|
|
40
42
|
result = run_cmd(@cmd + params)
|
41
43
|
assert_cmd(success_result(/.*/), result)
|
42
44
|
end
|
43
45
|
|
44
|
-
it
|
46
|
+
it 'supports search' do
|
45
47
|
params = ['--search', 'name ~ test']
|
46
48
|
|
47
49
|
api_expects(:configs, :index).with_params('search' => 'name ~ test').returns(index_response([]))
|
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative '../test_helper'
|
2
4
|
|
3
|
-
describe
|
4
|
-
describe
|
5
|
+
describe 'virt-who-config' do
|
6
|
+
describe 'update' do
|
5
7
|
before do
|
6
|
-
@cmd = [
|
8
|
+
@cmd = ['virt-who-config', 'update']
|
7
9
|
@update_args = {
|
8
10
|
:name => 'test',
|
9
11
|
:new_name => 'test2',
|
@@ -18,7 +20,7 @@ describe "virt-who-config" do
|
|
18
20
|
}
|
19
21
|
end
|
20
22
|
|
21
|
-
it
|
23
|
+
it 'sends values to api' do
|
22
24
|
params = hash_to_opts(@update_args)
|
23
25
|
|
24
26
|
expected_result = success_result("Virt Who configuration [test] updated\n")
|
@@ -37,7 +39,7 @@ describe "virt-who-config" do
|
|
37
39
|
'satellite_url' => '1',
|
38
40
|
'organization_id' => 1
|
39
41
|
}
|
40
|
-
).returns(
|
42
|
+
).returns(:config => config)
|
41
43
|
|
42
44
|
result = run_cmd(@cmd + params)
|
43
45
|
assert_cmd(expected_result, result)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative '../test_helper'
|
2
4
|
|
3
5
|
require 'hammer_cli/testing/command_assertions'
|
@@ -7,7 +9,7 @@ include HammerCLI::Testing::CommandAssertions
|
|
7
9
|
include HammerCLI::Testing::OutputMatchers
|
8
10
|
|
9
11
|
def missing_arguments_result(argument_name)
|
10
|
-
HammerCLI::Testing::CommandAssertions::CommandExpectation.new('', /Missing arguments for
|
12
|
+
HammerCLI::Testing::CommandAssertions::CommandExpectation.new('', /Missing arguments for.*#{argument_name}/, HammerCLI::EX_USAGE)
|
11
13
|
end
|
12
14
|
|
13
15
|
def assert_requires_argument(cmd, params, required_argument_name)
|
@@ -21,14 +23,14 @@ end
|
|
21
23
|
def assert_usage_error(cmd, params, error_msg)
|
22
24
|
expected_result = usage_error_result(cmd,
|
23
25
|
error_msg,
|
24
|
-
|
26
|
+
'Could not create the Virt Who configuration')
|
25
27
|
|
26
28
|
api_expects_no_call
|
27
29
|
result = run_cmd(cmd + params)
|
28
30
|
assert_cmd(expected_result, result)
|
29
31
|
end
|
30
32
|
|
31
|
-
def hash_to_opts(hash, options={})
|
33
|
+
def hash_to_opts(hash, options = {})
|
32
34
|
hash.reject do |k|
|
33
35
|
k == options[:reject]
|
34
36
|
end.map do |key, value|
|
@@ -38,23 +40,23 @@ end
|
|
38
40
|
|
39
41
|
def config(attrs = {})
|
40
42
|
{
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
43
|
+
'name' => 'test',
|
44
|
+
'interval' => 60,
|
45
|
+
'organization_id' => 1,
|
46
|
+
'whitelist' => '',
|
47
|
+
'blacklist' => '',
|
48
|
+
'hypervisor_id' => 'hostname',
|
49
|
+
'hypervisor_type' => 'libvirt',
|
50
|
+
'hypervisor_server' => 'libvirt.test.org',
|
51
|
+
'hypervisor_username' => 'user',
|
52
|
+
'debug' => false,
|
53
|
+
'satellite_url' => '10.34.131.166',
|
54
|
+
'proxy' => '',
|
55
|
+
'no_proxy' => '',
|
56
|
+
'status' => 'unknown',
|
57
|
+
'last_report_at' => nil,
|
58
|
+
'out_of_date_at' => nil,
|
59
|
+
'filtering_mode' => 0,
|
60
|
+
'id' => 11
|
59
61
|
}.merge(attrs)
|
60
62
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'minitest/autorun'
|
2
4
|
require 'minitest/spec'
|
3
|
-
require
|
5
|
+
require 'mocha/minitest'
|
4
6
|
|
5
7
|
require 'hammer_cli'
|
6
8
|
require 'hammer_cli_foreman/testing/api_expectations'
|
7
9
|
|
8
|
-
FOREMAN_VERSION = Gem::Version.new(ENV['TEST_API_VERSION'] || '
|
10
|
+
FOREMAN_VERSION = Gem::Version.new(ENV['TEST_API_VERSION'] || '3.11')
|
9
11
|
|
10
12
|
include HammerCLIForeman::Testing::APIExpectations
|
11
13
|
HammerCLI.context[:api_connection].create('foreman') do
|
@@ -1,7 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'hammer_cli_foreman_virt_who_configure/system_caller'
|
2
4
|
require_relative '../test_helper'
|
3
5
|
|
4
|
-
describe
|
6
|
+
describe 'SystemCaller' do
|
5
7
|
class CaptureContentTempfile < Tempfile
|
6
8
|
attr_accessor :contents
|
7
9
|
|
@@ -16,7 +18,8 @@ describe "SystemCaller" do
|
|
16
18
|
|
17
19
|
it 'uses tempfile for executing the script' do
|
18
20
|
tmp_file = CaptureContentTempfile.new
|
19
|
-
|
21
|
+
vars = HammerCLIForemanVirtWhoConfigure::SystemCaller.new.clean_env_vars
|
22
|
+
Kernel.expects(:system).with(vars, "/usr/bin/bash #{tmp_file.path}", unsetenv_others: true)
|
20
23
|
|
21
24
|
sys_caller = HammerCLIForemanVirtWhoConfigure::SystemCaller.new(tmp_file)
|
22
25
|
sys_caller.system(script)
|