hammer_cli_foreman 2.0.1 → 2.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/doc/developer_docs.md +1 -0
- data/doc/plugin.md +22 -0
- data/doc/release_notes.md +35 -2
- data/lib/hammer_cli_foreman.rb +9 -1
- data/lib/hammer_cli_foreman/api/connection.rb +1 -18
- data/lib/hammer_cli_foreman/api/oauth/authentication_code_grant.rb +7 -4
- data/lib/hammer_cli_foreman/api/session_authenticator_wrapper.rb +0 -1
- data/lib/hammer_cli_foreman/associating_commands.rb +33 -5
- data/lib/hammer_cli_foreman/audit.rb +7 -0
- data/lib/hammer_cli_foreman/auth.rb +10 -10
- data/lib/hammer_cli_foreman/bookmark.rb +50 -0
- data/lib/hammer_cli_foreman/command_extensions.rb +2 -0
- data/lib/hammer_cli_foreman/command_extensions/puppet_environment.rb +13 -7
- data/lib/hammer_cli_foreman/command_extensions/puppet_environments.rb +13 -7
- data/lib/hammer_cli_foreman/command_extensions/subnet.rb +25 -0
- data/lib/hammer_cli_foreman/command_extensions/user.rb +17 -0
- data/lib/hammer_cli_foreman/commands.rb +14 -9
- data/lib/hammer_cli_foreman/compute_resource.rb +15 -0
- data/lib/hammer_cli_foreman/compute_resource/ec2.rb +11 -0
- data/lib/hammer_cli_foreman/compute_resource/gce.rb +9 -0
- data/lib/hammer_cli_foreman/compute_resource/libvirt.rb +11 -0
- data/lib/hammer_cli_foreman/compute_resource/openstack.rb +7 -0
- data/lib/hammer_cli_foreman/compute_resource/ovirt.rb +21 -9
- data/lib/hammer_cli_foreman/compute_resource/vmware.rb +15 -2
- data/lib/hammer_cli_foreman/hostgroup.rb +11 -19
- data/lib/hammer_cli_foreman/hosts/common_update_options.rb +32 -10
- data/lib/hammer_cli_foreman/id_resolver.rb +12 -11
- data/lib/hammer_cli_foreman/mail_notification.rb +31 -0
- data/lib/hammer_cli_foreman/operating_system.rb +1 -1
- data/lib/hammer_cli_foreman/option_builders.rb +70 -48
- data/lib/hammer_cli_foreman/option_sources.rb +1 -0
- data/lib/hammer_cli_foreman/option_sources/referenced_resource_id_params.rb +47 -0
- data/lib/hammer_cli_foreman/sessions.rb +1 -3
- data/lib/hammer_cli_foreman/subnet.rb +26 -15
- data/lib/hammer_cli_foreman/task_helper.rb +180 -0
- data/lib/hammer_cli_foreman/user.rb +7 -17
- data/lib/hammer_cli_foreman/user_mail_notification.rb +51 -0
- data/lib/hammer_cli_foreman/version.rb +1 -1
- data/lib/hammer_cli_foreman/virtual_machine.rb +55 -0
- data/locale/ca/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/de/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/en/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/en_GB/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/es/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/fr/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/it/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/ja/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/ko/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/pt_BR/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/ru/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/zh_CN/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/locale/zh_TW/LC_MESSAGES/hammer-cli-foreman.mo +0 -0
- data/test/data/2.1/foreman_api.json +1 -0
- data/test/functional/associating_commands_test.rb +134 -30
- data/test/functional/bookmark_test.rb +193 -0
- data/test/functional/host_test.rb +27 -1
- data/test/functional/http_proxy_test.rb +1 -4
- data/test/functional/mail_notification_test.rb +57 -0
- data/test/functional/subnet/create_test.rb +28 -5
- data/test/functional/template_test.rb +2 -2
- data/test/functional/user_mail_notification_test.rb +89 -0
- data/test/functional/virtual_machine_test.rb +129 -0
- data/test/test_helper.rb +1 -1
- data/test/unit/audit_test.rb +1 -0
- data/test/unit/sessions_test.rb +2 -13
- metadata +59 -40
@@ -308,7 +308,10 @@ describe 'host update' do
|
|
308
308
|
'organization_id' => '5',
|
309
309
|
'location_id' => '5',
|
310
310
|
'compute_attributes' => {},
|
311
|
-
'puppetclass_ids' => []
|
311
|
+
'puppetclass_ids' => [],
|
312
|
+
'owner_id' => '1',
|
313
|
+
'owner_name' => 'adminGroup',
|
314
|
+
'owner_type' => 'Usergroup'
|
312
315
|
}
|
313
316
|
end
|
314
317
|
|
@@ -384,6 +387,29 @@ describe 'host update' do
|
|
384
387
|
|
385
388
|
assert_cmd(expected_result, result)
|
386
389
|
end
|
390
|
+
|
391
|
+
it 'should update the host owner' do
|
392
|
+
params = ['--owner-type=Usergroup', '--owner=adminGroup']
|
393
|
+
|
394
|
+
api_expects_search(:usergroups, name: 'adminGroup').returns(
|
395
|
+
index_response([{ 'id' => '1' }])
|
396
|
+
)
|
397
|
+
api_expects(:hosts, :update, 'Update host with new owner').with_params(
|
398
|
+
'id' => '1', 'location_id' => 1, 'organization_id' => 1, 'host' => {
|
399
|
+
'owner_id' => '1', 'compute_attributes' => {}
|
400
|
+
}
|
401
|
+
) do |par|
|
402
|
+
par['id'] == '1' &&
|
403
|
+
par['host']['owner_id'] == '1' &&
|
404
|
+
par['host']['compute_attributes'] == {}
|
405
|
+
end.returns(updated_host)
|
406
|
+
|
407
|
+
expected_result = success_result("Host updated.\n")
|
408
|
+
|
409
|
+
result = run_cmd(cmd + minimal_params + params)
|
410
|
+
|
411
|
+
assert_cmd(expected_result, result)
|
412
|
+
end
|
387
413
|
end
|
388
414
|
|
389
415
|
describe 'host config reports' do
|
@@ -64,9 +64,6 @@ describe 'httpproxy' do
|
|
64
64
|
expected_result = success_result("Http proxy deleted.\n")
|
65
65
|
|
66
66
|
result = run_cmd(%w(http-proxy delete --id 1))
|
67
|
-
|
68
|
-
if RUBY_VERSION < '2.7'
|
69
|
-
assert_cmd(expected_result, result)
|
70
|
-
end
|
67
|
+
assert_cmd(expected_result, result)
|
71
68
|
end
|
72
69
|
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
describe 'mail_notification' do
|
4
|
+
describe 'list' do
|
5
|
+
before do
|
6
|
+
@cmd = %w[mail-notification list]
|
7
|
+
@mail_notifications = [{
|
8
|
+
id: 1,
|
9
|
+
name: 'config_summary',
|
10
|
+
description: 'A summary of eventful configuration management reports',
|
11
|
+
subscription_type: 'report'
|
12
|
+
}]
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should return a list of mail notifications' do
|
16
|
+
api_expects(:mail_notifications, :index, 'List mail notifications').returns(@mail_notifications)
|
17
|
+
|
18
|
+
output = IndexMatcher.new([
|
19
|
+
%w[ID NAME],
|
20
|
+
%w[1 config_summary]
|
21
|
+
])
|
22
|
+
expected_result = success_result(output)
|
23
|
+
|
24
|
+
result = run_cmd(@cmd)
|
25
|
+
assert_cmd(expected_result, result)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'info' do
|
30
|
+
before do
|
31
|
+
@cmd = %w[mail-notification info]
|
32
|
+
@mail_notification = {
|
33
|
+
id: 1,
|
34
|
+
name: 'config_summary',
|
35
|
+
description: 'A summary of eventful configuration management reports',
|
36
|
+
subscription_type: 'report'
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should return the info of a mail notification' do
|
41
|
+
params = ['--id=1']
|
42
|
+
api_expects(:mail_notifications, :show, 'Info mail notification').returns(@mail_notification)
|
43
|
+
|
44
|
+
output = OutputMatcher.new([
|
45
|
+
'Id: 1',
|
46
|
+
'Name: config_summary',
|
47
|
+
'Description: A summary of eventful configuration management reports',
|
48
|
+
'Subscription type: report'
|
49
|
+
])
|
50
|
+
|
51
|
+
expected_result = success_result(output)
|
52
|
+
|
53
|
+
result = run_cmd(@cmd + params)
|
54
|
+
assert_cmd(expected_result, result)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -14,13 +14,36 @@ module HammerCLIForeman
|
|
14
14
|
params
|
15
15
|
end
|
16
16
|
|
17
|
-
it '
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
it 'should print error on missing --mask or --prefix' do
|
18
|
+
params = ['--name=net1']
|
19
|
+
cmd = %w[subnet create]
|
20
|
+
|
21
|
+
expected_result = usage_error_result(
|
22
|
+
cmd,
|
23
|
+
'At least one of options --mask, --prefix is required.',
|
24
|
+
'Could not create the subnet'
|
25
|
+
)
|
26
|
+
|
27
|
+
api_expects_no_call
|
28
|
+
result = run_cmd(cmd + params)
|
29
|
+
assert_cmd(expected_result, result)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'allows minimal options with mask for IPv4' do
|
33
|
+
api_expects(:subnets, :create).with_params(subnet_params(mask: '255.255.255.0'))
|
21
34
|
run_cmd(%w(subnet create --name net1 --network=192.168.122.0 --mask=255.255.255.0))
|
22
35
|
end
|
23
36
|
|
37
|
+
it 'allows minimal options with prefix for IPv4' do
|
38
|
+
api_expects(:subnets, :create).with_params(subnet_params(mask: '255.255.255.0'))
|
39
|
+
run_cmd(%w(subnet create --name net1 --network=192.168.122.0 --prefix=24))
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'allows minimal options with prefix for IPv6' do
|
43
|
+
api_expects(:subnets, :create).with_params(subnet_params(cidr: '96'))
|
44
|
+
run_cmd(%w(subnet create --name net1 --network-type=IPv6 --network='::ffff:c0a8:7a00' --prefix=96))
|
45
|
+
end
|
46
|
+
|
24
47
|
it 'allows dhcp id' do
|
25
48
|
api_expects(:subnets, :create).with_params(subnet_params(:dhcp_id => 1))
|
26
49
|
run_cmd(%w(subnet create --name net1 --network=192.168.122.0 --mask=255.255.255.0 --dhcp-id 1))
|
@@ -91,7 +114,7 @@ module HammerCLIForeman
|
|
91
114
|
it 'allows organization names' do
|
92
115
|
api_expects(:organizations, :index) do |p|
|
93
116
|
p[:search] == "name = \"org1\" or name = \"org2\""
|
94
|
-
end.returns(index_response([{'id' => 1}, {'id' => 2}]))
|
117
|
+
end.returns(index_response([{'id' => 1}, {'id' => 2}]))
|
95
118
|
api_expects(:subnets, :create).with_params(subnet_params(:organization_ids => [1, 2]))
|
96
119
|
run_cmd(%w(subnet create --name net1 --network=192.168.122.0 --mask=255.255.255.0 --organizations org1,org2))
|
97
120
|
end
|
@@ -131,7 +131,7 @@ describe 'template' do
|
|
131
131
|
it 'should create new combination with warning' do
|
132
132
|
params = ['create','--provisioning-template-id=10', '--hostgroup-id=1', '--environment-id=1']
|
133
133
|
expected_result = success_result("Template combination created.\n")
|
134
|
-
expected_result.expected_err = "Warning: Option --environment-id is deprecated. Use --puppet-environment-id instead\n"
|
134
|
+
expected_result.expected_err = "Warning: Option --environment-id is deprecated. Use --puppet-environment[-id] instead\n"
|
135
135
|
api_expects(:template_combinations, :create, 'Create template combination') do |params|
|
136
136
|
params['provisioning_template_id'] == 10 &&
|
137
137
|
params['hostgroup_id'] == 1 &&
|
@@ -160,7 +160,7 @@ describe 'template' do
|
|
160
160
|
it 'should update combination with warning' do
|
161
161
|
params = ['update', '--id=3', '--provisioning-template-id=10', '--hostgroup-id=1', '--environment-id=1']
|
162
162
|
expected_result = success_result("Template combination updated.\n")
|
163
|
-
expected_result.expected_err = "Warning: Option --environment-id is deprecated. Use --puppet-environment-id instead\n"
|
163
|
+
expected_result.expected_err = "Warning: Option --environment-id is deprecated. Use --puppet-environment[-id] instead\n"
|
164
164
|
api_expects(:template_combinations, :update, 'Update template combination') do |params|
|
165
165
|
params['id'] == '3' &&
|
166
166
|
params['provisioning_template_id'] == 10 &&
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
describe 'user_mail_notification' do
|
4
|
+
before do
|
5
|
+
@user_mail_notifications = [{
|
6
|
+
id: 1,
|
7
|
+
user_id: 2,
|
8
|
+
mail_notification_id: 3,
|
9
|
+
interval: "Daily",
|
10
|
+
mail_query: "",
|
11
|
+
name: 'config_summary',
|
12
|
+
description: 'A summary of eventful configuration management reports'
|
13
|
+
}]
|
14
|
+
end
|
15
|
+
describe 'list' do
|
16
|
+
before do
|
17
|
+
@cmd = %w[user mail-notification list]
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should return a list of the user mail notifications' do
|
21
|
+
params = ['--user-id=2']
|
22
|
+
api_expects(:mail_notifications, :user_mail_notifications, 'List user mail notifications').returns(@user_mail_notifications)
|
23
|
+
|
24
|
+
output = IndexMatcher.new([
|
25
|
+
['ID', 'NAME', 'DESCRIPTION', 'INTERVAL', 'MAIL QUERY'],
|
26
|
+
['3', 'config_summary', 'A summary of eventful configuration management reports', 'Daily', '']
|
27
|
+
])
|
28
|
+
expected_result = success_result(output)
|
29
|
+
|
30
|
+
result = run_cmd(@cmd + params)
|
31
|
+
assert_cmd(expected_result, result)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe 'update' do
|
36
|
+
before do
|
37
|
+
@cmd = %w[user mail-notification update]
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should update a user mail notification' do
|
41
|
+
params = ['--user-id=2', '--mail-notification-id=3', '--interval=weekly']
|
42
|
+
api_expects(:mail_notifications, :update, 'Update user mail notification')
|
43
|
+
|
44
|
+
result = run_cmd(@cmd + params)
|
45
|
+
assert_cmd(success_result("User mail notifications was updated.\n"), result)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe 'create' do
|
50
|
+
before do
|
51
|
+
@cmd = %w[user mail-notification add]
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should return an error that there is no mail-notification' do
|
55
|
+
params = ['--user-id=2']
|
56
|
+
|
57
|
+
expected_result = common_error_result(
|
58
|
+
@cmd,
|
59
|
+
"Could not find mail_notification, please set one of options --mail-notification, --mail-notification-id.",
|
60
|
+
"Could not add user mail notification"
|
61
|
+
)
|
62
|
+
|
63
|
+
result = run_cmd(@cmd + params)
|
64
|
+
assert_cmd(expected_result, result)
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should add a user mail notification' do
|
68
|
+
params = ['--user-id=2', '--mail-notification-id=3', '--interval=daily']
|
69
|
+
api_expects(:mail_notifications, :create, 'Create user mail notification')
|
70
|
+
|
71
|
+
result = run_cmd(@cmd + params)
|
72
|
+
assert_cmd(success_result("User mail notifications was added.\n"), result)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe 'remove' do
|
77
|
+
before do
|
78
|
+
@cmd = %w[user mail-notification remove]
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'should remove a user mail notification' do
|
82
|
+
params = ['--user-id=2', '--mail-notification-id=3']
|
83
|
+
api_expects(:mail_notifications, :destroy, 'Remove user mail notification')
|
84
|
+
|
85
|
+
result = run_cmd(@cmd + params)
|
86
|
+
assert_cmd(success_result("User mail notification was removed.\n"), result)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
|
2
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
3
|
+
|
4
|
+
require 'hammer_cli_foreman/compute_resource'
|
5
|
+
|
6
|
+
describe HammerCLIForeman::VirtualMachine do
|
7
|
+
|
8
|
+
context "InfoCommand" do
|
9
|
+
before do
|
10
|
+
@cmd = ["compute-resource", "virtual-machine", "info"]
|
11
|
+
@vm = {
|
12
|
+
'id' => 1,
|
13
|
+
'name' => 'vm1',
|
14
|
+
'provider' => 'Ovirt',
|
15
|
+
'cpu' => 1,
|
16
|
+
'memory' => 1,
|
17
|
+
'status' => 'down'
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should print error on missing --id and --vm-id" do
|
22
|
+
api_expects_no_call
|
23
|
+
result = run_cmd(@cmd)
|
24
|
+
assert_match("Missing arguments for '--id', '--vm-id'.\n", result.err)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should print error on missing --vm-id" do
|
28
|
+
params = ['--id=1']
|
29
|
+
|
30
|
+
api_expects_no_call
|
31
|
+
result = run_cmd(@cmd + params)
|
32
|
+
assert_match("Missing arguments for '--vm-id'.\n", result.err)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should return vm info" do
|
36
|
+
params = ['--id=1', '--vm-id=1']
|
37
|
+
api_expects(:compute_resources, :show_vm) do |par|
|
38
|
+
par['id'] == '1' && par['vm_id'] == '1'
|
39
|
+
end.returns(@vm)
|
40
|
+
result = run_cmd(@cmd + params)
|
41
|
+
assert_match("Id: 1\nName: vm1\nCPUs: 1\nMemory: 1\nStatus: down\n\n", result.out)
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
context "ListCommand" do
|
47
|
+
before do
|
48
|
+
@cmd = ["compute-resource", "virtual-machines"]
|
49
|
+
@available_virtual_machines = [
|
50
|
+
{ id: 1, name: 'vm1' },
|
51
|
+
{ id: 2, name: 'vm2' }
|
52
|
+
]
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should print error on missing --id" do
|
56
|
+
api_expects_no_call
|
57
|
+
result = run_cmd(@cmd)
|
58
|
+
assert_match("Missing arguments for '--id'.\n", result.err)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should return vms list" do
|
62
|
+
params = ['--id=1']
|
63
|
+
api_expects(:compute_resources, :available_virtual_machines) do |par|
|
64
|
+
par['id'] == '1'
|
65
|
+
end.returns(@available_virtual_machines)
|
66
|
+
result = run_cmd(@cmd + params)
|
67
|
+
assert_match(/-----|---\nNAME | ID\n-----|---\nvm1 | 1 \nvm2 | 2 \n-----|---\n/, result.out)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context "PowerCommand" do
|
72
|
+
before do
|
73
|
+
@cmd = ["compute-resource", "virtual-machine", "power"]
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should print error on missing --id and --vm-id" do
|
77
|
+
api_expects_no_call
|
78
|
+
result = run_cmd(@cmd)
|
79
|
+
assert_match("Could not power the virtual machine:\n Missing arguments for '--id', '--vm-id'.\n", result.err)
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should print error on missing --vm-id" do
|
83
|
+
params = ['--id=1']
|
84
|
+
|
85
|
+
api_expects_no_call
|
86
|
+
result = run_cmd(@cmd + params)
|
87
|
+
assert_match("Could not power the virtual machine:\n Missing arguments for '--vm-id'.\n", result.err)
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'should power a virtual machine' do
|
91
|
+
params = ['--id=1', '--vm-id=1']
|
92
|
+
api_expects(:compute_resources, :power_vm) do |par|
|
93
|
+
par['id'] == '1' && par['vm_id'] == '1'
|
94
|
+
end.returns({})
|
95
|
+
result = run_cmd(@cmd + params)
|
96
|
+
assert_cmd(success_result("Virtual machine is powering.\n"), result)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context "DeleteCommand" do
|
101
|
+
before do
|
102
|
+
@cmd = ["compute-resource", "virtual-machine", "delete"]
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should print error on missing --id and --vm-id" do
|
106
|
+
api_expects_no_call
|
107
|
+
result = run_cmd(@cmd)
|
108
|
+
assert_match("Could not delete the virtual machine:\n Missing arguments for '--id', '--vm-id'.\n", result.err)
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should print error on missing --vm-id" do
|
112
|
+
params = ['--id=1']
|
113
|
+
|
114
|
+
api_expects_no_call
|
115
|
+
result = run_cmd(@cmd + params)
|
116
|
+
assert_match("Could not delete the virtual machine:\n Missing arguments for '--vm-id'.\n", result.err)
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'delete virtual machine' do
|
120
|
+
params = ['--id=1', '--vm-id=1']
|
121
|
+
api_expects(:compute_resources, :destroy_vm) do |par|
|
122
|
+
par['id'] == '1' && par['vm_id'] == '1'
|
123
|
+
end.returns({})
|
124
|
+
result = run_cmd(@cmd + params)
|
125
|
+
assert_cmd(success_result("Virtual machine deleted.\n"), result)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
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 = Gem::Version.new(ENV['TEST_API_VERSION'] || '2.
|
20
|
+
FOREMAN_VERSION = Gem::Version.new(ENV['TEST_API_VERSION'] || '2.1')
|
21
21
|
|
22
22
|
include HammerCLIForeman::Testing::APIExpectations
|
23
23
|
HammerCLI.context[:api_connection].create('foreman') do
|
data/test/unit/audit_test.rb
CHANGED
data/test/unit/sessions_test.rb
CHANGED
@@ -13,7 +13,6 @@ describe HammerCLIForeman do
|
|
13
13
|
HammerCLIForeman::Sessions.stubs(:storage).returns(dir)
|
14
14
|
session = HammerCLIForeman::Sessions.get('http://example.com')
|
15
15
|
session.id.must_be_nil
|
16
|
-
session.auth_type.must_be_nil
|
17
16
|
session.user_name.must_be_nil
|
18
17
|
end
|
19
18
|
end
|
@@ -24,8 +23,7 @@ describe HammerCLIForeman do
|
|
24
23
|
HammerCLIForeman::Sessions.stubs(:storage).returns(dir)
|
25
24
|
session_content = {
|
26
25
|
:id => '3040b0f04c3a35a499e6837278904d48',
|
27
|
-
:user_name => 'admin'
|
28
|
-
:auth_type => 'basic_auth'
|
26
|
+
:user_name => 'admin'
|
29
27
|
}
|
30
28
|
session_path = "#{dir}/http_example.com"
|
31
29
|
File.open(session_path,"w") do |f|
|
@@ -35,7 +33,6 @@ describe HammerCLIForeman do
|
|
35
33
|
|
36
34
|
session = HammerCLIForeman::Sessions.get('http://example.com')
|
37
35
|
session.id.must_equal '3040b0f04c3a35a499e6837278904d48'
|
38
|
-
session.auth_type.must_equal 'basic_auth'
|
39
36
|
session.user_name.must_equal 'admin'
|
40
37
|
end
|
41
38
|
end
|
@@ -67,8 +64,7 @@ describe HammerCLIForeman do
|
|
67
64
|
HammerCLIForeman::Sessions.stubs(:storage).returns(dir)
|
68
65
|
session_content = {
|
69
66
|
:id => '3040b0f04c3a35a499e6837278904d48',
|
70
|
-
:user_name => 'admin'
|
71
|
-
:auth_type => 'basic_auth'
|
67
|
+
:user_name => 'admin'
|
72
68
|
}
|
73
69
|
session_path = "#{dir}/http_example.com"
|
74
70
|
File.open(session_path,"w") do |f|
|
@@ -124,13 +120,11 @@ describe HammerCLIForeman do
|
|
124
120
|
Tempfile.create('session') do |f|
|
125
121
|
session = HammerCLIForeman::Session.new(f.path)
|
126
122
|
session.id = '3040b0f04c3a35a499e6837278904d48'
|
127
|
-
session.auth_type = 'basic_auth'
|
128
123
|
session.user_name = 'admin'
|
129
124
|
session.store
|
130
125
|
|
131
126
|
session = HammerCLIForeman::Session.new(f.path)
|
132
127
|
session.id.must_equal '3040b0f04c3a35a499e6837278904d48'
|
133
|
-
session.auth_type.must_equal 'basic_auth'
|
134
128
|
session.user_name.must_equal 'admin'
|
135
129
|
end
|
136
130
|
end
|
@@ -150,7 +144,6 @@ describe HammerCLIForeman do
|
|
150
144
|
_, err = capture_io do
|
151
145
|
session = HammerCLIForeman::Session.new(f.path)
|
152
146
|
session.id = nil
|
153
|
-
session.auth_type = nil
|
154
147
|
session.user_name = nil
|
155
148
|
end
|
156
149
|
err.must_equal("Invalid session data. Resetting the session.\n")
|
@@ -162,13 +155,11 @@ describe HammerCLIForeman do
|
|
162
155
|
Tempfile.create('session') do |f|
|
163
156
|
session = HammerCLIForeman::Session.new(f.path)
|
164
157
|
session.id = '3040b0f04c3a35a499e6837278904d48'
|
165
|
-
session.auth_type = 'basic_auth'
|
166
158
|
session.user_name = 'admin'
|
167
159
|
session.destroy
|
168
160
|
|
169
161
|
session = HammerCLIForeman::Session.new(f.path)
|
170
162
|
session.id.must_be_nil
|
171
|
-
session.auth_type.must_equal 'basic_auth'
|
172
163
|
session.user_name.must_equal 'admin'
|
173
164
|
end
|
174
165
|
end
|
@@ -179,7 +170,6 @@ describe HammerCLIForeman do
|
|
179
170
|
Tempfile.create('session') do |f|
|
180
171
|
session = HammerCLIForeman::Session.new(f.path)
|
181
172
|
session.id = nil
|
182
|
-
session.auth_type = 'basic_auth'
|
183
173
|
session.user_name = 'admin'
|
184
174
|
session.valid?.must_equal false
|
185
175
|
end
|
@@ -189,7 +179,6 @@ describe HammerCLIForeman do
|
|
189
179
|
Tempfile.create('session') do |f|
|
190
180
|
session = HammerCLIForeman::Session.new(f.path)
|
191
181
|
session.id = '34252624635723572357234'
|
192
|
-
session.auth_type = 'basic_auth'
|
193
182
|
session.user_name = 'admin'
|
194
183
|
session.valid?.must_equal true
|
195
184
|
end
|