knife-ionoscloud 6.1.2 → 6.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/docs/changelog.md +8 -0
- data/docs/docs_generator.rb +2 -1
- data/docs/subcommands/application-loadbalancer/applicationloadbalancer_create.md +60 -0
- data/docs/subcommands/application-loadbalancer/applicationloadbalancer_delete.md +41 -0
- data/docs/subcommands/application-loadbalancer/applicationloadbalancer_get.md +45 -0
- data/docs/subcommands/application-loadbalancer/applicationloadbalancer_list.md +41 -0
- data/docs/subcommands/application-loadbalancer/applicationloadbalancer_rule_add.md +69 -0
- data/docs/subcommands/application-loadbalancer/applicationloadbalancer_rule_httprule_add.md +78 -0
- data/docs/subcommands/application-loadbalancer/applicationloadbalancer_rule_httprule_remove.md +49 -0
- data/docs/subcommands/application-loadbalancer/applicationloadbalancer_rule_remove.md +45 -0
- data/docs/subcommands/application-loadbalancer/applicationloadbalancer_rule_update.md +70 -0
- data/docs/subcommands/application-loadbalancer/applicationloadbalancer_update.md +60 -0
- data/docs/subcommands/application-loadbalancer/targetgroup_create.md +79 -0
- data/docs/subcommands/application-loadbalancer/targetgroup_delete.md +37 -0
- data/docs/subcommands/application-loadbalancer/targetgroup_get.md +41 -0
- data/docs/subcommands/application-loadbalancer/targetgroup_list.md +37 -0
- data/docs/subcommands/application-loadbalancer/targetgroup_target_add.md +59 -0
- data/docs/subcommands/application-loadbalancer/targetgroup_target_remove.md +49 -0
- data/docs/subcommands/application-loadbalancer/targetgroup_update.md +80 -0
- data/docs/summary.md +61 -43
- data/knife-ionoscloud.gemspec +3 -2
- data/lib/chef/knife/ionoscloud_applicationloadbalancer_create.rb +85 -0
- data/lib/chef/knife/ionoscloud_applicationloadbalancer_delete.rb +64 -0
- data/lib/chef/knife/ionoscloud_applicationloadbalancer_get.rb +45 -0
- data/lib/chef/knife/ionoscloud_applicationloadbalancer_list.rb +56 -0
- data/lib/chef/knife/ionoscloud_applicationloadbalancer_rule_add.rb +129 -0
- data/lib/chef/knife/ionoscloud_applicationloadbalancer_rule_httprule_add.rb +159 -0
- data/lib/chef/knife/ionoscloud_applicationloadbalancer_rule_httprule_remove.rb +89 -0
- data/lib/chef/knife/ionoscloud_applicationloadbalancer_rule_remove.rb +70 -0
- data/lib/chef/knife/ionoscloud_applicationloadbalancer_rule_update.rb +137 -0
- data/lib/chef/knife/ionoscloud_applicationloadbalancer_update.rb +96 -0
- data/lib/chef/knife/ionoscloud_base.rb +139 -7
- data/lib/chef/knife/ionoscloud_targetgroup_create.rb +140 -0
- data/lib/chef/knife/ionoscloud_targetgroup_delete.rb +50 -0
- data/lib/chef/knife/ionoscloud_targetgroup_get.rb +34 -0
- data/lib/chef/knife/ionoscloud_targetgroup_list.rb +45 -0
- data/lib/chef/knife/ionoscloud_targetgroup_target_add.rb +93 -0
- data/lib/chef/knife/ionoscloud_targetgroup_target_remove.rb +66 -0
- data/lib/chef/knife/ionoscloud_targetgroup_update.rb +151 -0
- data/lib/knife-ionoscloud/version.rb +1 -1
- data/spec/chef/knife/ionoscloud_applicationloadbalancer_create_spec.rb +82 -0
- data/spec/chef/knife/ionoscloud_applicationloadbalancer_delete_spec.rb +110 -0
- data/spec/chef/knife/ionoscloud_applicationloadbalancer_get_spec.rb +70 -0
- data/spec/chef/knife/ionoscloud_applicationloadbalancer_list_spec.rb +87 -0
- data/spec/chef/knife/ionoscloud_applicationloadbalancer_rule_add_spec.rb +140 -0
- data/spec/chef/knife/ionoscloud_applicationloadbalancer_rule_httprule_add_spec.rb +238 -0
- data/spec/chef/knife/ionoscloud_applicationloadbalancer_rule_httprule_remove_spec.rb +204 -0
- data/spec/chef/knife/ionoscloud_applicationloadbalancer_rule_remove_spec.rb +127 -0
- data/spec/chef/knife/ionoscloud_applicationloadbalancer_rule_update_spec.rb +219 -0
- data/spec/chef/knife/ionoscloud_applicationloadbalancer_update_spec.rb +97 -0
- data/spec/chef/knife/ionoscloud_targetgroup_create_spec.rb +109 -0
- data/spec/chef/knife/ionoscloud_targetgroup_delete_spec.rb +111 -0
- data/spec/chef/knife/ionoscloud_targetgroup_get_spec.rb +71 -0
- data/spec/chef/knife/ionoscloud_targetgroup_list_spec.rb +78 -0
- data/spec/chef/knife/ionoscloud_targetgroup_target_add_spec.rb +164 -0
- data/spec/chef/knife/ionoscloud_targetgroup_target_remove_spec.rb +139 -0
- data/spec/chef/knife/ionoscloud_targetgroup_update_spec.rb +144 -0
- data/spec/spec_helper.rb +135 -27
- metadata +77 -9
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'ionoscloud_targetgroup_get'
|
3
|
+
|
4
|
+
Chef::Knife::IonoscloudTargetgroupGet.load_deps
|
5
|
+
|
6
|
+
describe Chef::Knife::IonoscloudTargetgroupGet do
|
7
|
+
before :each do
|
8
|
+
subject { Chef::Knife::IonoscloudTargetgroupGet.new }
|
9
|
+
|
10
|
+
allow(subject).to receive(:puts)
|
11
|
+
allow(subject).to receive(:print)
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#run' do
|
15
|
+
it 'should call TargetGroupsApi.targetgroups_find_by_target_group_id' do
|
16
|
+
target_group = target_group_mock
|
17
|
+
subject_config = {
|
18
|
+
ionoscloud_username: 'email',
|
19
|
+
ionoscloud_password: 'password',
|
20
|
+
target_group_id: target_group.id,
|
21
|
+
}
|
22
|
+
|
23
|
+
subject_config.each { |key, value| subject.config[key] = value }
|
24
|
+
|
25
|
+
health_check, http_health_check, targets = subject.get_target_group_extended_properties(target_group)
|
26
|
+
|
27
|
+
expect(subject).to receive(:puts).with("ID: #{target_group.id}")
|
28
|
+
expect(subject).to receive(:puts).with("Name: #{target_group.properties.name}")
|
29
|
+
expect(subject).to receive(:puts).with("Algorithm: #{target_group.properties.algorithm}")
|
30
|
+
expect(subject).to receive(:puts).with("Protocol: #{target_group.properties.protocol}")
|
31
|
+
expect(subject).to receive(:puts).with("Health Check: #{health_check}")
|
32
|
+
expect(subject).to receive(:puts).with("HTTP Health Check: #{http_health_check}")
|
33
|
+
expect(subject).to receive(:puts).with("Targets: #{targets}")
|
34
|
+
|
35
|
+
mock_call_api(
|
36
|
+
subject,
|
37
|
+
[
|
38
|
+
{
|
39
|
+
method: 'GET',
|
40
|
+
path: "/targetgroups/#{subject_config[:target_group_id]}",
|
41
|
+
operation: :'TargetGroupsApi.targetgroups_find_by_target_group_id',
|
42
|
+
return_type: 'TargetGroup',
|
43
|
+
result: target_group,
|
44
|
+
},
|
45
|
+
],
|
46
|
+
)
|
47
|
+
|
48
|
+
expect { subject.run }.not_to raise_error(Exception)
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should not make any call if any required option is missing' do
|
52
|
+
required_options = subject.instance_variable_get(:@required_options)
|
53
|
+
|
54
|
+
if required_options.length > 0
|
55
|
+
arrays_without_one_element(required_options).each do |test_case|
|
56
|
+
subject.config[:ionoscloud_token] = 'token'
|
57
|
+
test_case[:array].each { |value| subject.config[value] = 'test' }
|
58
|
+
|
59
|
+
expect(subject).to receive(:puts).with("Missing required parameters #{test_case[:removed]}")
|
60
|
+
expect(subject.api_client).not_to receive(:call_api)
|
61
|
+
|
62
|
+
expect { subject.run }.to raise_error(SystemExit) do |error|
|
63
|
+
expect(error.status).to eq(1)
|
64
|
+
end
|
65
|
+
|
66
|
+
required_options.each { |value| subject.config[value] = nil }
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'ionoscloud_targetgroup_list'
|
3
|
+
|
4
|
+
Chef::Knife::IonoscloudTargetgroupList.load_deps
|
5
|
+
|
6
|
+
describe Chef::Knife::IonoscloudTargetgroupList do
|
7
|
+
before :each do
|
8
|
+
subject { Chef::Knife::IonoscloudTargetgroupList.new }
|
9
|
+
|
10
|
+
allow(subject).to receive(:puts)
|
11
|
+
allow(subject).to receive(:print)
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#run' do
|
15
|
+
it 'should call DataCentersApi.datacenters_get' do
|
16
|
+
target_groups = target_groups_mock
|
17
|
+
subject_config = {
|
18
|
+
ionoscloud_username: 'email',
|
19
|
+
ionoscloud_password: 'password',
|
20
|
+
}
|
21
|
+
|
22
|
+
subject_config.each { |key, value| subject.config[key] = value }
|
23
|
+
|
24
|
+
target_group_list = [
|
25
|
+
subject.ui.color('ID', :bold),
|
26
|
+
subject.ui.color('Name', :bold),
|
27
|
+
subject.ui.color('Algorithm', :bold),
|
28
|
+
subject.ui.color('Protocol', :bold),
|
29
|
+
subject.ui.color('Targets', :bold),
|
30
|
+
]
|
31
|
+
|
32
|
+
target_groups.items.each do |target_group|
|
33
|
+
target_group_list << target_group.id
|
34
|
+
target_group_list << target_group.properties.name
|
35
|
+
target_group_list << target_group.properties.algorithm
|
36
|
+
target_group_list << target_group.properties.protocol
|
37
|
+
target_group_list << target_group.properties.targets.nil? ? 0 : target_group.properties.targets.length
|
38
|
+
end
|
39
|
+
|
40
|
+
expect(subject.ui).to receive(:list).with(target_group_list, :uneven_columns_across, 5)
|
41
|
+
|
42
|
+
mock_call_api(
|
43
|
+
subject,
|
44
|
+
[
|
45
|
+
{
|
46
|
+
method: 'GET',
|
47
|
+
path: '/targetgroups',
|
48
|
+
operation: :'TargetGroupsApi.targetgroups_get',
|
49
|
+
return_type: 'TargetGroups',
|
50
|
+
result: target_groups,
|
51
|
+
},
|
52
|
+
],
|
53
|
+
)
|
54
|
+
|
55
|
+
expect { subject.run }.not_to raise_error(Exception)
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should not make any call if any required option is missing' do
|
59
|
+
required_options = subject.instance_variable_get(:@required_options)
|
60
|
+
|
61
|
+
if required_options.length > 0
|
62
|
+
arrays_without_one_element(required_options).each do |test_case|
|
63
|
+
subject.config[:ionoscloud_token] = 'token'
|
64
|
+
test_case[:array].each { |value| subject.config[value] = 'test' }
|
65
|
+
|
66
|
+
expect(subject).to receive(:puts).with("Missing required parameters #{test_case[:removed]}")
|
67
|
+
expect(subject.api_client).not_to receive(:call_api)
|
68
|
+
|
69
|
+
expect { subject.run }.to raise_error(SystemExit) do |error|
|
70
|
+
expect(error.status).to eq(1)
|
71
|
+
end
|
72
|
+
|
73
|
+
required_options.each { |value| subject.config[value] = nil }
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,164 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'ionoscloud_targetgroup_target_add'
|
3
|
+
|
4
|
+
Chef::Knife::IonoscloudTargetgroupTargetAdd.load_deps
|
5
|
+
|
6
|
+
describe Chef::Knife::IonoscloudTargetgroupTargetAdd do
|
7
|
+
before :each do
|
8
|
+
subject { Chef::Knife::IonoscloudTargetgroupTargetAdd.new }
|
9
|
+
|
10
|
+
allow(subject).to receive(:puts)
|
11
|
+
allow(subject).to receive(:print)
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#run' do
|
15
|
+
it 'should call TargetGroupsApi.targetgroups_patch and add a new target when needed' do
|
16
|
+
target_group = target_group_mock
|
17
|
+
target = target_group_target_mock(ip: '127.0.0.2', port: 22)
|
18
|
+
|
19
|
+
subject_config = {
|
20
|
+
ionoscloud_username: 'email',
|
21
|
+
ionoscloud_password: 'password',
|
22
|
+
target_group_id: target_group.id,
|
23
|
+
ip: target.ip,
|
24
|
+
port: target.port,
|
25
|
+
weight: target.weight,
|
26
|
+
health_check_disabled: !target.health_check_enabled,
|
27
|
+
maintenance_enabled: target.maintenance_enabled,
|
28
|
+
yes: true,
|
29
|
+
}
|
30
|
+
|
31
|
+
subject_config.each { |key, value| subject.config[key] = value }
|
32
|
+
|
33
|
+
health_check, http_health_check, targets = subject.get_target_group_extended_properties(target_group)
|
34
|
+
|
35
|
+
expect(subject).to receive(:puts).with("ID: #{target_group.id}")
|
36
|
+
expect(subject).to receive(:puts).with("Name: #{target_group.properties.name}")
|
37
|
+
expect(subject).to receive(:puts).with("Algorithm: #{target_group.properties.algorithm}")
|
38
|
+
expect(subject).to receive(:puts).with("Protocol: #{target_group.properties.protocol}")
|
39
|
+
expect(subject).to receive(:puts).with("Health Check: #{health_check}")
|
40
|
+
expect(subject).to receive(:puts).with("HTTP Health Check: #{http_health_check}")
|
41
|
+
expect(subject).to receive(:puts).with("Targets: #{targets + [{
|
42
|
+
ip: target.ip,
|
43
|
+
port: target.port,
|
44
|
+
weight: target.weight,
|
45
|
+
health_check_enabled: target.health_check_enabled,
|
46
|
+
maintenance_enabled: target.maintenance_enabled,
|
47
|
+
}]}")
|
48
|
+
|
49
|
+
expected_properties = target_group.properties.to_hash
|
50
|
+
expected_properties[:targets] << target.to_hash
|
51
|
+
|
52
|
+
mock_wait_for(subject)
|
53
|
+
mock_call_api(
|
54
|
+
subject,
|
55
|
+
[
|
56
|
+
{
|
57
|
+
method: 'GET',
|
58
|
+
path: "/targetgroups/#{target_group.id}",
|
59
|
+
operation: :'TargetGroupsApi.targetgroups_find_by_target_group_id',
|
60
|
+
return_type: 'TargetGroup',
|
61
|
+
result: target_group,
|
62
|
+
},
|
63
|
+
{
|
64
|
+
method: 'PATCH',
|
65
|
+
path: "/targetgroups/#{target_group.id}",
|
66
|
+
operation: :'TargetGroupsApi.targetgroups_patch',
|
67
|
+
body: expected_properties,
|
68
|
+
return_type: 'TargetGroup',
|
69
|
+
result: target_group,
|
70
|
+
},
|
71
|
+
{
|
72
|
+
method: 'GET',
|
73
|
+
path: "/targetgroups/#{target_group.id}",
|
74
|
+
operation: :'TargetGroupsApi.targetgroups_find_by_target_group_id',
|
75
|
+
return_type: 'TargetGroup',
|
76
|
+
result: target_group,
|
77
|
+
},
|
78
|
+
],
|
79
|
+
)
|
80
|
+
|
81
|
+
expect { subject.run }.not_to raise_error(Exception)
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'should not call TargetGroupsApi.targetgroups_patch and notify the user when the target already exists' do
|
85
|
+
target_group = target_group_mock
|
86
|
+
target = target_group_target_mock(weight: 100, check: false, maintenance: true, check_interval: 3000)
|
87
|
+
|
88
|
+
subject_config = {
|
89
|
+
ionoscloud_username: 'email',
|
90
|
+
ionoscloud_password: 'password',
|
91
|
+
target_group_id: target_group.id,
|
92
|
+
ip: target.ip,
|
93
|
+
port: target.port,
|
94
|
+
weight: target.weight,
|
95
|
+
health_check_disabled: !target.health_check_enabled,
|
96
|
+
maintenance_enabled: target.maintenance_enabled,
|
97
|
+
yes: true,
|
98
|
+
}
|
99
|
+
|
100
|
+
subject_config.each { |key, value| subject.config[key] = value }
|
101
|
+
|
102
|
+
health_check, http_health_check, _ = subject.get_target_group_extended_properties(target_group)
|
103
|
+
|
104
|
+
expect(subject.ui).to receive(:warn).with("Specified target already exists (#{target_group.properties.targets.first}).")
|
105
|
+
|
106
|
+
expect(subject).to receive(:puts).with("ID: #{target_group.id}")
|
107
|
+
expect(subject).to receive(:puts).with("Name: #{target_group.properties.name}")
|
108
|
+
expect(subject).to receive(:puts).with("Algorithm: #{target_group.properties.algorithm}")
|
109
|
+
expect(subject).to receive(:puts).with("Protocol: #{target_group.properties.protocol}")
|
110
|
+
expect(subject).to receive(:puts).with("Health Check: #{health_check}")
|
111
|
+
expect(subject).to receive(:puts).with("HTTP Health Check: #{http_health_check}")
|
112
|
+
expect(subject).to receive(:puts).with("Targets: #{[{
|
113
|
+
ip: target_group.properties.targets.first.ip,
|
114
|
+
port: target_group.properties.targets.first.port,
|
115
|
+
weight: target_group.properties.targets.first.weight,
|
116
|
+
health_check_enabled: target_group.properties.targets.first.health_check_enabled,
|
117
|
+
maintenance_enabled: target_group.properties.targets.first.maintenance_enabled,
|
118
|
+
}]}")
|
119
|
+
|
120
|
+
expect(subject).not_to receive(:wait_for)
|
121
|
+
mock_call_api(
|
122
|
+
subject,
|
123
|
+
[
|
124
|
+
{
|
125
|
+
method: 'GET',
|
126
|
+
path: "/targetgroups/#{target_group.id}",
|
127
|
+
operation: :'TargetGroupsApi.targetgroups_find_by_target_group_id',
|
128
|
+
return_type: 'TargetGroup',
|
129
|
+
result: target_group,
|
130
|
+
},
|
131
|
+
{
|
132
|
+
method: 'GET',
|
133
|
+
path: "/targetgroups/#{target_group.id}",
|
134
|
+
operation: :'TargetGroupsApi.targetgroups_find_by_target_group_id',
|
135
|
+
return_type: 'TargetGroup',
|
136
|
+
result: target_group,
|
137
|
+
},
|
138
|
+
],
|
139
|
+
)
|
140
|
+
|
141
|
+
expect { subject.run }.not_to raise_error(Exception)
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'should not make any call if any required option is missing' do
|
145
|
+
required_options = subject.instance_variable_get(:@required_options)
|
146
|
+
|
147
|
+
if required_options.length > 0
|
148
|
+
arrays_without_one_element(required_options).each do |test_case|
|
149
|
+
subject.config[:ionoscloud_token] = 'token'
|
150
|
+
test_case[:array].each { |value| subject.config[value] = 'test' }
|
151
|
+
|
152
|
+
expect(subject).to receive(:puts).with("Missing required parameters #{test_case[:removed]}")
|
153
|
+
expect(subject.api_client).not_to receive(:call_api)
|
154
|
+
|
155
|
+
expect { subject.run }.to raise_error(SystemExit) do |error|
|
156
|
+
expect(error.status).to eq(1)
|
157
|
+
end
|
158
|
+
|
159
|
+
required_options.each { |value| subject.config[value] = nil }
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'ionoscloud_targetgroup_target_remove'
|
3
|
+
|
4
|
+
Chef::Knife::IonoscloudTargetgroupTargetRemove.load_deps
|
5
|
+
|
6
|
+
describe Chef::Knife::IonoscloudTargetgroupTargetRemove do
|
7
|
+
before :each do
|
8
|
+
subject { Chef::Knife::IonoscloudTargetgroupTargetRemove.new }
|
9
|
+
|
10
|
+
allow(subject).to receive(:puts)
|
11
|
+
allow(subject).to receive(:print)
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#run' do
|
15
|
+
it 'should not call TargetGroupsApi.targetgroups_patch when the specified target does not exist in the Target Group' do
|
16
|
+
target_group = target_group_mock
|
17
|
+
target = target_group_target_mock(ip: '127.0.0.2', port: 22)
|
18
|
+
|
19
|
+
subject_config = {
|
20
|
+
ionoscloud_username: 'email',
|
21
|
+
ionoscloud_password: 'password',
|
22
|
+
target_group_id: target_group.id,
|
23
|
+
ip: target.ip,
|
24
|
+
port: target.port,
|
25
|
+
yes: true,
|
26
|
+
}
|
27
|
+
|
28
|
+
subject_config.each { |key, value| subject.config[key] = value }
|
29
|
+
|
30
|
+
health_check, http_health_check, targets = subject.get_target_group_extended_properties(target_group)
|
31
|
+
|
32
|
+
expect(subject).to receive(:puts).with("ID: #{target_group.id}")
|
33
|
+
expect(subject).to receive(:puts).with("Name: #{target_group.properties.name}")
|
34
|
+
expect(subject).to receive(:puts).with("Algorithm: #{target_group.properties.algorithm}")
|
35
|
+
expect(subject).to receive(:puts).with("Protocol: #{target_group.properties.protocol}")
|
36
|
+
expect(subject).to receive(:puts).with("Health Check: #{health_check}")
|
37
|
+
expect(subject).to receive(:puts).with("HTTP Health Check: #{http_health_check}")
|
38
|
+
expect(subject).to receive(:puts).with("Targets: #{targets}")
|
39
|
+
|
40
|
+
expect(subject.ui).to receive(:warn).with("Specified target does not exist (#{subject_config[:ip]}:#{subject_config[:port]}).")
|
41
|
+
|
42
|
+
expect(subject).not_to receive(:wait_for)
|
43
|
+
mock_call_api(
|
44
|
+
subject,
|
45
|
+
[
|
46
|
+
{
|
47
|
+
method: 'GET',
|
48
|
+
path: "/targetgroups/#{target_group.id}",
|
49
|
+
operation: :'TargetGroupsApi.targetgroups_find_by_target_group_id',
|
50
|
+
return_type: 'TargetGroup',
|
51
|
+
result: target_group,
|
52
|
+
},
|
53
|
+
],
|
54
|
+
)
|
55
|
+
|
56
|
+
expect { subject.run }.not_to raise_error(Exception)
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should call TargetGroupsApi.targetgroups_patch and remove the target when it exists' do
|
60
|
+
target_group = target_group_mock
|
61
|
+
target = target_group_target_mock
|
62
|
+
|
63
|
+
subject_config = {
|
64
|
+
ionoscloud_username: 'email',
|
65
|
+
ionoscloud_password: 'password',
|
66
|
+
target_group_id: target_group.id,
|
67
|
+
ip: target.ip,
|
68
|
+
port: target.port,
|
69
|
+
yes: true,
|
70
|
+
}
|
71
|
+
|
72
|
+
subject_config.each { |key, value| subject.config[key] = value }
|
73
|
+
|
74
|
+
health_check, http_health_check, _ = subject.get_target_group_extended_properties(target_group)
|
75
|
+
|
76
|
+
expect(subject).to receive(:puts).with("ID: #{target_group.id}")
|
77
|
+
expect(subject).to receive(:puts).with("Name: #{target_group.properties.name}")
|
78
|
+
expect(subject).to receive(:puts).with("Algorithm: #{target_group.properties.algorithm}")
|
79
|
+
expect(subject).to receive(:puts).with("Protocol: #{target_group.properties.protocol}")
|
80
|
+
expect(subject).to receive(:puts).with("Health Check: #{health_check}")
|
81
|
+
expect(subject).to receive(:puts).with("HTTP Health Check: #{http_health_check}")
|
82
|
+
expect(subject).to receive(:puts).with("Targets: #{[]}")
|
83
|
+
|
84
|
+
expected_properties = target_group.properties.to_hash
|
85
|
+
expected_properties[:targets] = []
|
86
|
+
|
87
|
+
mock_wait_for(subject)
|
88
|
+
mock_call_api(
|
89
|
+
subject,
|
90
|
+
[
|
91
|
+
{
|
92
|
+
method: 'GET',
|
93
|
+
path: "/targetgroups/#{target_group.id}",
|
94
|
+
operation: :'TargetGroupsApi.targetgroups_find_by_target_group_id',
|
95
|
+
return_type: 'TargetGroup',
|
96
|
+
result: target_group,
|
97
|
+
},
|
98
|
+
{
|
99
|
+
method: 'PATCH',
|
100
|
+
path: "/targetgroups/#{target_group.id}",
|
101
|
+
operation: :'TargetGroupsApi.targetgroups_patch',
|
102
|
+
body: expected_properties,
|
103
|
+
return_type: 'TargetGroup',
|
104
|
+
result: target_group,
|
105
|
+
},
|
106
|
+
{
|
107
|
+
method: 'GET',
|
108
|
+
path: "/targetgroups/#{target_group.id}",
|
109
|
+
operation: :'TargetGroupsApi.targetgroups_find_by_target_group_id',
|
110
|
+
return_type: 'TargetGroup',
|
111
|
+
result: target_group,
|
112
|
+
},
|
113
|
+
],
|
114
|
+
)
|
115
|
+
|
116
|
+
expect { subject.run }.not_to raise_error(Exception)
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'should not make any call if any required option is missing' do
|
120
|
+
required_options = subject.instance_variable_get(:@required_options)
|
121
|
+
|
122
|
+
if required_options.length > 0
|
123
|
+
arrays_without_one_element(required_options).each do |test_case|
|
124
|
+
subject.config[:ionoscloud_token] = 'token'
|
125
|
+
test_case[:array].each { |value| subject.config[value] = 'test' }
|
126
|
+
|
127
|
+
expect(subject).to receive(:puts).with("Missing required parameters #{test_case[:removed]}")
|
128
|
+
expect(subject.api_client).not_to receive(:call_api)
|
129
|
+
|
130
|
+
expect { subject.run }.to raise_error(SystemExit) do |error|
|
131
|
+
expect(error.status).to eq(1)
|
132
|
+
end
|
133
|
+
|
134
|
+
required_options.each { |value| subject.config[value] = nil }
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
@@ -0,0 +1,144 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'ionoscloud_targetgroup_update'
|
3
|
+
|
4
|
+
Chef::Knife::IonoscloudTargetgroupUpdate.load_deps
|
5
|
+
|
6
|
+
describe Chef::Knife::IonoscloudTargetgroupUpdate do
|
7
|
+
before :each do
|
8
|
+
subject { Chef::Knife::IonoscloudTargetgroupUpdate.new }
|
9
|
+
|
10
|
+
allow(subject).to receive(:puts)
|
11
|
+
allow(subject).to receive(:print)
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#run' do
|
15
|
+
it 'should call TargetGroupsApi.targetgroups_patch' do
|
16
|
+
new_target = target_group_target_mock(
|
17
|
+
ip: '127.9.9.9',
|
18
|
+
port: 90,
|
19
|
+
weight: 50,
|
20
|
+
check: false,
|
21
|
+
check_interval: 1234,
|
22
|
+
maintenance: true,
|
23
|
+
)
|
24
|
+
target_group = target_group_mock
|
25
|
+
|
26
|
+
subject_config = {
|
27
|
+
ionoscloud_username: 'email',
|
28
|
+
ionoscloud_password: 'password',
|
29
|
+
target_group_id: 'target_group_id',
|
30
|
+
name: target_group.properties.name + '_edited',
|
31
|
+
algorithm: 'RANDOM',
|
32
|
+
check_timeout: target_group.properties.health_check.check_timeout + 100,
|
33
|
+
check_interval: target_group.properties.health_check.check_interval + 100,
|
34
|
+
retries: target_group.properties.health_check.retries + 10,
|
35
|
+
path: target_group.properties.http_health_check.path + '_edited',
|
36
|
+
method: 'POST',
|
37
|
+
response: target_group.properties.http_health_check.response + ' edited',
|
38
|
+
regex: !target_group.properties.http_health_check.regex,
|
39
|
+
negate: !target_group.properties.http_health_check.negate,
|
40
|
+
targets: [{
|
41
|
+
'ip' => new_target.ip,
|
42
|
+
'port' => new_target.port,
|
43
|
+
'weight' => new_target.weight,
|
44
|
+
'health_check_enabled' => new_target.health_check_enabled,
|
45
|
+
'maintenance_enabled' => new_target.maintenance_enabled,
|
46
|
+
}],
|
47
|
+
yes: true,
|
48
|
+
}
|
49
|
+
|
50
|
+
subject_config.each { |key, value| subject.config[key] = value }
|
51
|
+
|
52
|
+
|
53
|
+
target_group.properties.name = subject_config[:name]
|
54
|
+
target_group.properties.algorithm = subject_config[:algorithm]
|
55
|
+
target_group.properties.health_check.check_timeout = subject_config[:check_timeout]
|
56
|
+
target_group.properties.health_check.check_interval = subject_config[:check_interval]
|
57
|
+
target_group.properties.health_check.retries = subject_config[:retries]
|
58
|
+
target_group.properties.health_check.check_timeout = subject_config[:check_timeout]
|
59
|
+
target_group.properties.http_health_check.method = subject_config[:method]
|
60
|
+
target_group.properties.http_health_check.path = subject_config[:path]
|
61
|
+
target_group.properties.http_health_check.response = subject_config[:response]
|
62
|
+
target_group.properties.http_health_check.regex = subject_config[:regex]
|
63
|
+
target_group.properties.http_health_check.negate = subject_config[:negate]
|
64
|
+
|
65
|
+
target_group.properties.targets = [new_target]
|
66
|
+
|
67
|
+
health_check, http_health_check, targets = subject.get_target_group_extended_properties(target_group)
|
68
|
+
|
69
|
+
expect(subject).to receive(:puts).with("ID: #{target_group.id}")
|
70
|
+
expect(subject).to receive(:puts).with("Name: #{target_group.properties.name}")
|
71
|
+
expect(subject).to receive(:puts).with("Algorithm: #{target_group.properties.algorithm}")
|
72
|
+
expect(subject).to receive(:puts).with("Protocol: #{target_group.properties.protocol}")
|
73
|
+
expect(subject).to receive(:puts).with("Health Check: #{health_check}")
|
74
|
+
expect(subject).to receive(:puts).with("HTTP Health Check: #{http_health_check}")
|
75
|
+
expect(subject).to receive(:puts).with("Targets: #{targets}")
|
76
|
+
|
77
|
+
mock_wait_for(subject)
|
78
|
+
mock_call_api(
|
79
|
+
subject,
|
80
|
+
[
|
81
|
+
{
|
82
|
+
method: 'PATCH',
|
83
|
+
path: "/targetgroups/#{subject_config[:target_group_id]}",
|
84
|
+
operation: :'TargetGroupsApi.targetgroups_patch',
|
85
|
+
return_type: 'TargetGroup',
|
86
|
+
body: {
|
87
|
+
name: subject_config[:name],
|
88
|
+
algorithm: subject_config[:algorithm],
|
89
|
+
healthCheck: {
|
90
|
+
checkTimeout: subject_config[:check_timeout],
|
91
|
+
checkInterval: subject_config[:check_interval],
|
92
|
+
retries: subject_config[:retries],
|
93
|
+
},
|
94
|
+
httpHealthCheck: {
|
95
|
+
method: subject_config[:method],
|
96
|
+
path: subject_config[:path],
|
97
|
+
response: subject_config[:response],
|
98
|
+
regex: subject_config[:regex],
|
99
|
+
negate: subject_config[:negate],
|
100
|
+
},
|
101
|
+
targets: [{
|
102
|
+
ip: new_target.ip,
|
103
|
+
port: new_target.port,
|
104
|
+
weight: new_target.weight,
|
105
|
+
healthCheckEnabled: new_target.health_check_enabled,
|
106
|
+
maintenanceEnabled: new_target.maintenance_enabled,
|
107
|
+
}],
|
108
|
+
},
|
109
|
+
result: target_group,
|
110
|
+
},
|
111
|
+
{
|
112
|
+
method: 'GET',
|
113
|
+
path: "/targetgroups/#{subject_config[:target_group_id]}",
|
114
|
+
operation: :'TargetGroupsApi.targetgroups_find_by_target_group_id',
|
115
|
+
return_type: 'TargetGroup',
|
116
|
+
result: target_group,
|
117
|
+
},
|
118
|
+
],
|
119
|
+
)
|
120
|
+
|
121
|
+
expect { subject.run }.not_to raise_error(Exception)
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'should not make any call if any required option is missing' do
|
125
|
+
required_options = subject.instance_variable_get(:@required_options)
|
126
|
+
|
127
|
+
if required_options.length > 0
|
128
|
+
arrays_without_one_element(required_options).each do |test_case|
|
129
|
+
subject.config[:ionoscloud_token] = 'token'
|
130
|
+
test_case[:array].each { |value| subject.config[value] = 'test' }
|
131
|
+
|
132
|
+
expect(subject).to receive(:puts).with("Missing required parameters #{test_case[:removed]}")
|
133
|
+
expect(subject.api_client).not_to receive(:call_api)
|
134
|
+
|
135
|
+
expect { subject.run }.to raise_error(SystemExit) do |error|
|
136
|
+
expect(error.status).to eq(1)
|
137
|
+
end
|
138
|
+
|
139
|
+
required_options.each { |value| subject.config[value] = nil }
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|