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,127 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'ionoscloud_applicationloadbalancer_rule_remove'
|
3
|
+
|
4
|
+
Chef::Knife::IonoscloudApplicationloadbalancerRuleRemove.load_deps
|
5
|
+
|
6
|
+
describe Chef::Knife::IonoscloudApplicationloadbalancerRuleRemove do
|
7
|
+
before :each do
|
8
|
+
subject { Chef::Knife::IonoscloudApplicationloadbalancerRuleRemove.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 ApplicationLoadBalancersApi.datacenters_applicationloadbalancers_delete when the ID is valid' do
|
16
|
+
application_loadbalancer = application_loadbalancer_mock
|
17
|
+
application_loadbalancer_rule = application_loadbalancer_rule_mock
|
18
|
+
subject_config = {
|
19
|
+
ionoscloud_username: 'email',
|
20
|
+
ionoscloud_password: 'password',
|
21
|
+
datacenter_id: 'datacenter_id',
|
22
|
+
application_loadbalancer_id: application_loadbalancer.id,
|
23
|
+
yes: true,
|
24
|
+
}
|
25
|
+
|
26
|
+
subject_config.each { |key, value| subject.config[key] = value }
|
27
|
+
subject.name_args = [application_loadbalancer_rule.id]
|
28
|
+
|
29
|
+
expect(subject).to receive(:puts).with("ID: #{application_loadbalancer.id}")
|
30
|
+
expect(subject).to receive(:puts).with("Name: #{application_loadbalancer.properties.name}")
|
31
|
+
expect(subject).to receive(:puts).with("Listener LAN: #{application_loadbalancer.properties.listener_lan}")
|
32
|
+
expect(subject).to receive(:puts).with("IPS: #{application_loadbalancer.properties.ips}")
|
33
|
+
expect(subject).to receive(:puts).with("Target LAN: #{application_loadbalancer.properties.target_lan}")
|
34
|
+
expect(subject).to receive(:puts).with("Lb Private IPS: #{application_loadbalancer.properties.lb_private_ips}")
|
35
|
+
expect(subject).to receive(:puts).with("Rules: #{subject.get_application_loadbalancer_extended_properties(application_loadbalancer)}")
|
36
|
+
expect(subject).to receive(:print).with("Removing rules #{subject.name_args} from the Application Loadbalancer...")
|
37
|
+
|
38
|
+
mock_wait_for(subject)
|
39
|
+
mock_call_api(
|
40
|
+
subject,
|
41
|
+
[
|
42
|
+
{
|
43
|
+
method: 'DELETE',
|
44
|
+
path: "/datacenters/#{subject_config[:datacenter_id]}/applicationloadbalancers/#{application_loadbalancer.id}/forwardingrules/#{application_loadbalancer_rule.id}",
|
45
|
+
operation: :'ApplicationLoadBalancersApi.datacenters_applicationloadbalancers_forwardingrules_delete',
|
46
|
+
},
|
47
|
+
{
|
48
|
+
method: 'GET',
|
49
|
+
path: "/datacenters/#{subject_config[:datacenter_id]}/applicationloadbalancers/#{application_loadbalancer.id}",
|
50
|
+
operation: :'ApplicationLoadBalancersApi.datacenters_applicationloadbalancers_find_by_application_load_balancer_id',
|
51
|
+
return_type: 'ApplicationLoadBalancer',
|
52
|
+
result: application_loadbalancer,
|
53
|
+
},
|
54
|
+
],
|
55
|
+
)
|
56
|
+
|
57
|
+
expect { subject.run }.not_to raise_error(Exception)
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should not call ApplicationLoadBalancersApi.datacenters_applicationloadbalancers_delete when the ID is not valid' do
|
61
|
+
application_loadbalancer = application_loadbalancer_mock
|
62
|
+
rule_id = 'invalid_id'
|
63
|
+
subject_config = {
|
64
|
+
ionoscloud_username: 'email',
|
65
|
+
ionoscloud_password: 'password',
|
66
|
+
datacenter_id: 'datacenter_id',
|
67
|
+
application_loadbalancer_id: application_loadbalancer.id,
|
68
|
+
}
|
69
|
+
|
70
|
+
subject_config.each { |key, value| subject.config[key] = value }
|
71
|
+
subject.name_args = [rule_id]
|
72
|
+
|
73
|
+
expect(subject).to receive(:puts).with("ID: #{application_loadbalancer.id}")
|
74
|
+
expect(subject).to receive(:puts).with("Name: #{application_loadbalancer.properties.name}")
|
75
|
+
expect(subject).to receive(:puts).with("Listener LAN: #{application_loadbalancer.properties.listener_lan}")
|
76
|
+
expect(subject).to receive(:puts).with("IPS: #{application_loadbalancer.properties.ips}")
|
77
|
+
expect(subject).to receive(:puts).with("Target LAN: #{application_loadbalancer.properties.target_lan}")
|
78
|
+
expect(subject).to receive(:puts).with("Lb Private IPS: #{application_loadbalancer.properties.lb_private_ips}")
|
79
|
+
expect(subject).to receive(:puts).with("Rules: #{subject.get_application_loadbalancer_extended_properties(application_loadbalancer)}")
|
80
|
+
|
81
|
+
expect(subject.ui).to receive(:warn).with("Error removing Forwarding Rule #{rule_id}. Skipping.")
|
82
|
+
expect(subject.ui).to receive(:warn).with('No valid rules to remove.')
|
83
|
+
|
84
|
+
expect(subject.api_client).not_to receive(:wait_for)
|
85
|
+
mock_call_api(
|
86
|
+
subject,
|
87
|
+
[
|
88
|
+
{
|
89
|
+
method: 'DELETE',
|
90
|
+
path: "/datacenters/#{subject_config[:datacenter_id]}/applicationloadbalancers/#{subject_config[:application_loadbalancer_id]}/forwardingrules/#{rule_id}",
|
91
|
+
operation: :'ApplicationLoadBalancersApi.datacenters_applicationloadbalancers_forwardingrules_delete',
|
92
|
+
exception: Ionoscloud::ApiError.new(code: 404),
|
93
|
+
},
|
94
|
+
{
|
95
|
+
method: 'GET',
|
96
|
+
path: "/datacenters/#{subject_config[:datacenter_id]}/applicationloadbalancers/#{application_loadbalancer.id}",
|
97
|
+
operation: :'ApplicationLoadBalancersApi.datacenters_applicationloadbalancers_find_by_application_load_balancer_id',
|
98
|
+
return_type: 'ApplicationLoadBalancer',
|
99
|
+
result: application_loadbalancer,
|
100
|
+
},
|
101
|
+
],
|
102
|
+
)
|
103
|
+
|
104
|
+
expect { subject.run }.not_to raise_error(Exception)
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'should not make any call if any required option is missing' do
|
108
|
+
required_options = subject.instance_variable_get(:@required_options)
|
109
|
+
|
110
|
+
if required_options.length > 0
|
111
|
+
arrays_without_one_element(required_options).each do |test_case|
|
112
|
+
subject.config[:ionoscloud_token] = 'token'
|
113
|
+
test_case[:array].each { |value| subject.config[value] = 'test' }
|
114
|
+
|
115
|
+
expect(subject).to receive(:puts).with("Missing required parameters #{test_case[:removed]}")
|
116
|
+
expect(subject.api_client).not_to receive(:call_api)
|
117
|
+
|
118
|
+
expect { subject.run }.to raise_error(SystemExit) do |error|
|
119
|
+
expect(error.status).to eq(1)
|
120
|
+
end
|
121
|
+
|
122
|
+
required_options.each { |value| subject.config[value] = nil }
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1,219 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'ionoscloud_applicationloadbalancer_rule_update'
|
3
|
+
|
4
|
+
Chef::Knife::IonoscloudApplicationloadbalancerRuleUpdate.load_deps
|
5
|
+
|
6
|
+
describe Chef::Knife::IonoscloudApplicationloadbalancerRuleUpdate do
|
7
|
+
before :each do
|
8
|
+
subject { Chef::Knife::IonoscloudApplicationloadbalancerRuleUpdate.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 ApplicationLoadBalancersApi.datacenters_applicationloadbalancers_patch' do
|
16
|
+
application_loadbalancer_rule = application_loadbalancer_rule_mock
|
17
|
+
application_loadbalancer = application_loadbalancer_mock(
|
18
|
+
rules: Ionoscloud::ApplicationLoadBalancerForwardingRules.new(
|
19
|
+
id: 'application_loadbalancers_forwardingrules',
|
20
|
+
type: 'collection',
|
21
|
+
items: [application_loadbalancer_rule],
|
22
|
+
),
|
23
|
+
)
|
24
|
+
application_loadbalancer_rule_httprule = application_loadbalancer_rule_httprule_mock(
|
25
|
+
name: 'test_name',
|
26
|
+
type: 'STATIC',
|
27
|
+
content_type: 'new_content_type',
|
28
|
+
conditions: [],
|
29
|
+
)
|
30
|
+
|
31
|
+
existing_httprule_new_name = application_loadbalancer_rule.properties.http_rules.first.name + '_edited'
|
32
|
+
existing_httprule_new_location = application_loadbalancer_rule.properties.http_rules.first.location + '_edited'
|
33
|
+
existing_httprule_new_status_code = 503
|
34
|
+
existing_httprule_new_response_message = application_loadbalancer_rule.properties.http_rules.first.response_message + '_edited'
|
35
|
+
existing_httprule_new_content_type = application_loadbalancer_rule.properties.http_rules.first.content_type + '_edited'
|
36
|
+
|
37
|
+
subject_config = {
|
38
|
+
ionoscloud_username: 'email',
|
39
|
+
ionoscloud_password: 'password',
|
40
|
+
datacenter_id: 'datacenter_id',
|
41
|
+
application_loadbalancer_id: application_loadbalancer.id,
|
42
|
+
forwarding_rule_id: application_loadbalancer_rule.id,
|
43
|
+
name: application_loadbalancer_rule.properties.name + '_edit',
|
44
|
+
listener_ip: '127.1.1.1',
|
45
|
+
listener_port: 30,
|
46
|
+
client_timeout: 3000,
|
47
|
+
http_rules: application_loadbalancer_rule.properties.http_rules.map do |el|
|
48
|
+
hash = el.to_hash
|
49
|
+
hash[:conditions].map! do |condition|
|
50
|
+
condition.collect { |k, v| [k.to_s, v] }.to_h
|
51
|
+
end
|
52
|
+
{
|
53
|
+
'name' => existing_httprule_new_name,
|
54
|
+
'type' => hash[:type],
|
55
|
+
'target_group' => hash[:targetGroup],
|
56
|
+
'drop_query' => hash[:dropQuery],
|
57
|
+
'location' => existing_httprule_new_location,
|
58
|
+
'status_code' => existing_httprule_new_status_code,
|
59
|
+
'response_message' => existing_httprule_new_response_message,
|
60
|
+
'content_type' => existing_httprule_new_content_type,
|
61
|
+
'conditions' => hash[:conditions],
|
62
|
+
}
|
63
|
+
end + [application_loadbalancer_rule_httprule].map do |el|
|
64
|
+
hash = el.to_hash
|
65
|
+
hash[:conditions].map! do |condition|
|
66
|
+
condition.collect { |k, v| [k.to_s, v] }.to_h
|
67
|
+
end
|
68
|
+
{
|
69
|
+
'name' => hash[:name],
|
70
|
+
'type' => hash[:type],
|
71
|
+
'target_group' => hash[:targetGroup],
|
72
|
+
'drop_query' => hash[:dropQuery],
|
73
|
+
'location' => hash[:location],
|
74
|
+
'status_code' => hash[:statusCode],
|
75
|
+
'response_message' => hash[:responseMessage],
|
76
|
+
'content_type' => hash[:contentType],
|
77
|
+
'conditions' => hash[:conditions],
|
78
|
+
}
|
79
|
+
end,
|
80
|
+
yes: true,
|
81
|
+
}
|
82
|
+
|
83
|
+
subject_config.each { |key, value| subject.config[key] = value }
|
84
|
+
|
85
|
+
|
86
|
+
expect(subject).to receive(:puts).with("ID: #{application_loadbalancer.id}")
|
87
|
+
expect(subject).to receive(:puts).with("Name: #{application_loadbalancer.properties.name}")
|
88
|
+
expect(subject).to receive(:puts).with("Listener LAN: #{application_loadbalancer.properties.listener_lan}")
|
89
|
+
expect(subject).to receive(:puts).with("IPS: #{application_loadbalancer.properties.ips}")
|
90
|
+
expect(subject).to receive(:puts).with("Target LAN: #{application_loadbalancer.properties.target_lan}")
|
91
|
+
expect(subject).to receive(:puts).with("Lb Private IPS: #{application_loadbalancer.properties.lb_private_ips}")
|
92
|
+
|
93
|
+
application_loadbalancer.entities.forwardingrules.items.first.properties.name = subject_config[:name]
|
94
|
+
application_loadbalancer.entities.forwardingrules.items.first.properties.listener_ip = subject_config[:listener_ip]
|
95
|
+
application_loadbalancer.entities.forwardingrules.items.first.properties.listener_port = subject_config[:listener_port]
|
96
|
+
application_loadbalancer.entities.forwardingrules.items.first.properties.client_timeout = subject_config[:client_timeout]
|
97
|
+
|
98
|
+
application_loadbalancer.entities.forwardingrules.items.first.properties.http_rules.first.name = existing_httprule_new_name
|
99
|
+
application_loadbalancer.entities.forwardingrules.items.first.properties.http_rules.first.location = existing_httprule_new_location
|
100
|
+
application_loadbalancer.entities.forwardingrules.items.first.properties.http_rules.first.status_code = existing_httprule_new_status_code
|
101
|
+
application_loadbalancer.entities.forwardingrules.items.first.properties.http_rules.first.response_message = existing_httprule_new_response_message
|
102
|
+
application_loadbalancer.entities.forwardingrules.items.first.properties.http_rules.first.content_type = existing_httprule_new_content_type
|
103
|
+
|
104
|
+
application_loadbalancer.entities.forwardingrules.items.first.properties.http_rules << application_loadbalancer_rule_httprule
|
105
|
+
|
106
|
+
expect(subject).to receive(:puts).with("Rules: #{
|
107
|
+
application_loadbalancer.entities.forwardingrules.items.map do |rule|
|
108
|
+
{
|
109
|
+
id: rule.id,
|
110
|
+
name: subject_config[:name],
|
111
|
+
protocol: application_loadbalancer_rule.properties.protocol,
|
112
|
+
listener_ip: subject_config[:listener_ip],
|
113
|
+
listener_port: subject_config[:listener_port],
|
114
|
+
client_timeout: subject_config[:client_timeout],
|
115
|
+
server_certificates: application_loadbalancer_rule.properties.server_certificates,
|
116
|
+
http_rules: rule.properties.http_rules.map do |http_rule|
|
117
|
+
{
|
118
|
+
name: http_rule.name,
|
119
|
+
type: http_rule.type,
|
120
|
+
target_group: http_rule.target_group,
|
121
|
+
drop_query: http_rule.drop_query,
|
122
|
+
location: http_rule.location,
|
123
|
+
status_code: http_rule.status_code,
|
124
|
+
response_message: http_rule.response_message,
|
125
|
+
content_type: http_rule.content_type,
|
126
|
+
conditions: http_rule.conditions.nil? ? [] : http_rule.conditions.map do |condition|
|
127
|
+
{
|
128
|
+
type: condition.type,
|
129
|
+
condition: condition.condition,
|
130
|
+
negate: condition.negate,
|
131
|
+
key: condition.key,
|
132
|
+
value: condition.value,
|
133
|
+
}
|
134
|
+
end,
|
135
|
+
}
|
136
|
+
end,
|
137
|
+
}
|
138
|
+
end}")
|
139
|
+
|
140
|
+
http_rules_body = application_loadbalancer.entities.forwardingrules.items.first.properties.http_rules.map do |el|
|
141
|
+
hash = el.to_hash
|
142
|
+
hash[:conditions].map! do |condition|
|
143
|
+
condition.collect { |k, v| [k.to_s, v] }.to_h
|
144
|
+
end
|
145
|
+
{
|
146
|
+
name: hash[:name],
|
147
|
+
type: hash[:type],
|
148
|
+
targetGroup: hash[:targetGroup],
|
149
|
+
dropQuery: hash[:dropQuery],
|
150
|
+
location: hash[:location],
|
151
|
+
statusCode: hash[:statusCode],
|
152
|
+
responseMessage: hash[:responseMessage],
|
153
|
+
contentType: hash[:contentType],
|
154
|
+
conditions: hash[:conditions].map do |condition|
|
155
|
+
condition
|
156
|
+
{
|
157
|
+
type: condition['type'],
|
158
|
+
condition: condition['condition'],
|
159
|
+
negate: condition['negate'],
|
160
|
+
key: condition['key'],
|
161
|
+
value: condition['value'],
|
162
|
+
}
|
163
|
+
end,
|
164
|
+
}
|
165
|
+
end
|
166
|
+
|
167
|
+
mock_wait_for(subject)
|
168
|
+
mock_call_api(
|
169
|
+
subject,
|
170
|
+
[
|
171
|
+
{
|
172
|
+
method: 'PATCH',
|
173
|
+
path: "/datacenters/#{subject_config[:datacenter_id]}/applicationloadbalancers/"\
|
174
|
+
"#{subject_config[:application_loadbalancer_id]}/forwardingrules/#{subject_config[:forwarding_rule_id]}",
|
175
|
+
operation: :'ApplicationLoadBalancersApi.datacenters_applicationloadbalancers_forwardingrules_patch',
|
176
|
+
return_type: 'ApplicationLoadBalancerForwardingRule',
|
177
|
+
body: {
|
178
|
+
name: subject_config[:name],
|
179
|
+
listenerIp: subject_config[:listener_ip],
|
180
|
+
listenerPort: subject_config[:listener_port],
|
181
|
+
clientTimeout: subject_config[:client_timeout],
|
182
|
+
httpRules: http_rules_body,
|
183
|
+
},
|
184
|
+
result: application_loadbalancer.entities.forwardingrules.items.first,
|
185
|
+
},
|
186
|
+
{
|
187
|
+
method: 'GET',
|
188
|
+
path: "/datacenters/#{subject_config[:datacenter_id]}/applicationloadbalancers/#{subject_config[:application_loadbalancer_id]}",
|
189
|
+
operation: :'ApplicationLoadBalancersApi.datacenters_applicationloadbalancers_find_by_application_load_balancer_id',
|
190
|
+
return_type: 'ApplicationLoadBalancer',
|
191
|
+
result: application_loadbalancer,
|
192
|
+
},
|
193
|
+
],
|
194
|
+
)
|
195
|
+
|
196
|
+
expect { subject.run }.not_to raise_error(Exception)
|
197
|
+
end
|
198
|
+
|
199
|
+
it 'should not make any call if any required option is missing' do
|
200
|
+
required_options = subject.instance_variable_get(:@required_options)
|
201
|
+
|
202
|
+
if required_options.length > 0
|
203
|
+
arrays_without_one_element(required_options).each do |test_case|
|
204
|
+
subject.config[:ionoscloud_token] = 'token'
|
205
|
+
test_case[:array].each { |value| subject.config[value] = 'test' }
|
206
|
+
|
207
|
+
expect(subject).to receive(:puts).with("Missing required parameters #{test_case[:removed]}")
|
208
|
+
expect(subject.api_client).not_to receive(:call_api)
|
209
|
+
|
210
|
+
expect { subject.run }.to raise_error(SystemExit) do |error|
|
211
|
+
expect(error.status).to eq(1)
|
212
|
+
end
|
213
|
+
|
214
|
+
required_options.each { |value| subject.config[value] = nil }
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'ionoscloud_applicationloadbalancer_update'
|
3
|
+
|
4
|
+
Chef::Knife::IonoscloudApplicationloadbalancerUpdate.load_deps
|
5
|
+
|
6
|
+
describe Chef::Knife::IonoscloudApplicationloadbalancerUpdate do
|
7
|
+
before :each do
|
8
|
+
subject { Chef::Knife::IonoscloudApplicationloadbalancerUpdate.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 ApplicationLoadBalancersApi.datacenters_applicationloadbalancers_patch' do
|
16
|
+
application_loadbalancer = application_loadbalancer_mock
|
17
|
+
subject_config = {
|
18
|
+
ionoscloud_username: 'email',
|
19
|
+
ionoscloud_password: 'password',
|
20
|
+
datacenter_id: 'datacenter_id',
|
21
|
+
application_loadbalancer_id: application_loadbalancer.id,
|
22
|
+
name: application_loadbalancer.properties.name + '_edited',
|
23
|
+
ips: (application_loadbalancer.properties.ips + ['127.3.3.3']).join(','),
|
24
|
+
lb_private_ips: (application_loadbalancer.properties.lb_private_ips + ['127.3.3.3']).join(','),
|
25
|
+
listener_lan: application_loadbalancer.properties.listener_lan + 1,
|
26
|
+
target_lan: application_loadbalancer.properties.target_lan + 1,
|
27
|
+
yes: true,
|
28
|
+
}
|
29
|
+
|
30
|
+
subject_config.each { |key, value| subject.config[key] = value }
|
31
|
+
|
32
|
+
|
33
|
+
expect(subject).to receive(:puts).with("ID: #{application_loadbalancer.id}")
|
34
|
+
expect(subject).to receive(:puts).with("Name: #{subject_config[:name]}")
|
35
|
+
expect(subject).to receive(:puts).with("Listener LAN: #{subject_config[:listener_lan]}")
|
36
|
+
expect(subject).to receive(:puts).with("IPS: #{subject_config[:ips].split(',')}")
|
37
|
+
expect(subject).to receive(:puts).with("Target LAN: #{subject_config[:target_lan]}")
|
38
|
+
expect(subject).to receive(:puts).with("Lb Private IPS: #{subject_config[:lb_private_ips].split(',')}")
|
39
|
+
|
40
|
+
application_loadbalancer.properties.name = subject_config[:name]
|
41
|
+
application_loadbalancer.properties.listener_lan = subject_config[:listener_lan]
|
42
|
+
application_loadbalancer.properties.target_lan = subject_config[:target_lan]
|
43
|
+
application_loadbalancer.properties.ips = subject_config[:ips].split(',')
|
44
|
+
application_loadbalancer.properties.lb_private_ips = subject_config[:lb_private_ips].split(',')
|
45
|
+
|
46
|
+
mock_wait_for(subject)
|
47
|
+
mock_call_api(
|
48
|
+
subject,
|
49
|
+
[
|
50
|
+
{
|
51
|
+
method: 'PATCH',
|
52
|
+
path: "/datacenters/#{subject_config[:datacenter_id]}/applicationloadbalancers/#{subject_config[:application_loadbalancer_id]}",
|
53
|
+
operation: :'ApplicationLoadBalancersApi.datacenters_applicationloadbalancers_patch',
|
54
|
+
return_type: 'ApplicationLoadBalancer',
|
55
|
+
body: {
|
56
|
+
name: subject_config[:name],
|
57
|
+
listenerLan: subject_config[:listener_lan],
|
58
|
+
targetLan: subject_config[:target_lan],
|
59
|
+
ips: subject_config[:ips].split(','),
|
60
|
+
lbPrivateIps: subject_config[:lb_private_ips].split(','),
|
61
|
+
},
|
62
|
+
result: application_loadbalancer,
|
63
|
+
},
|
64
|
+
{
|
65
|
+
method: 'GET',
|
66
|
+
path: "/datacenters/#{subject_config[:datacenter_id]}/applicationloadbalancers/#{subject_config[:application_loadbalancer_id]}",
|
67
|
+
operation: :'ApplicationLoadBalancersApi.datacenters_applicationloadbalancers_find_by_application_load_balancer_id',
|
68
|
+
return_type: 'ApplicationLoadBalancer',
|
69
|
+
result: application_loadbalancer,
|
70
|
+
},
|
71
|
+
],
|
72
|
+
)
|
73
|
+
|
74
|
+
expect { subject.run }.not_to raise_error(Exception)
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'should not make any call if any required option is missing' do
|
78
|
+
required_options = subject.instance_variable_get(:@required_options)
|
79
|
+
|
80
|
+
if required_options.length > 0
|
81
|
+
arrays_without_one_element(required_options).each do |test_case|
|
82
|
+
subject.config[:ionoscloud_token] = 'token'
|
83
|
+
test_case[:array].each { |value| subject.config[value] = 'test' }
|
84
|
+
|
85
|
+
expect(subject).to receive(:puts).with("Missing required parameters #{test_case[:removed]}")
|
86
|
+
expect(subject.api_client).not_to receive(:call_api)
|
87
|
+
|
88
|
+
expect { subject.run }.to raise_error(SystemExit) do |error|
|
89
|
+
expect(error.status).to eq(1)
|
90
|
+
end
|
91
|
+
|
92
|
+
required_options.each { |value| subject.config[value] = nil }
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'ionoscloud_targetgroup_create'
|
3
|
+
|
4
|
+
Chef::Knife::IonoscloudTargetgroupCreate.load_deps
|
5
|
+
|
6
|
+
describe Chef::Knife::IonoscloudTargetgroupCreate do
|
7
|
+
before :each do
|
8
|
+
subject { Chef::Knife::IonoscloudTargetgroupCreate.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_post_with_http_info with the expected arguments and output based on what it receives' 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(targets: [new_target])
|
25
|
+
|
26
|
+
subject_config = {
|
27
|
+
ionoscloud_username: 'email',
|
28
|
+
ionoscloud_password: 'password',
|
29
|
+
name: target_group.properties.name,
|
30
|
+
algorithm: target_group.properties.algorithm,
|
31
|
+
protocol: target_group.properties.protocol,
|
32
|
+
check_timeout: target_group.properties.health_check.check_timeout,
|
33
|
+
check_interval: target_group.properties.health_check.check_interval,
|
34
|
+
retries: target_group.properties.health_check.retries,
|
35
|
+
path: target_group.properties.http_health_check.path,
|
36
|
+
method: target_group.properties.http_health_check.method,
|
37
|
+
match_type: target_group.properties.http_health_check.match_type,
|
38
|
+
response: target_group.properties.http_health_check.response,
|
39
|
+
regex: target_group.properties.http_health_check.regex,
|
40
|
+
negate: target_group.properties.http_health_check.negate,
|
41
|
+
targets: [{
|
42
|
+
'ip' => new_target.ip,
|
43
|
+
'port' => new_target.port,
|
44
|
+
'weight' => new_target.weight,
|
45
|
+
'health_check_enabled' => new_target.health_check_enabled,
|
46
|
+
'maintenance_enabled' => new_target.maintenance_enabled,
|
47
|
+
}],
|
48
|
+
}
|
49
|
+
|
50
|
+
subject_config.each { |key, value| subject.config[key] = value }
|
51
|
+
|
52
|
+
health_check, http_health_check, targets = subject.get_target_group_extended_properties(target_group)
|
53
|
+
|
54
|
+
expect(subject).to receive(:puts).with("ID: #{target_group.id}")
|
55
|
+
expect(subject).to receive(:puts).with("Name: #{target_group.properties.name}")
|
56
|
+
expect(subject).to receive(:puts).with("Algorithm: #{target_group.properties.algorithm}")
|
57
|
+
expect(subject).to receive(:puts).with("Protocol: #{target_group.properties.protocol}")
|
58
|
+
expect(subject).to receive(:puts).with("Health Check: #{health_check}")
|
59
|
+
expect(subject).to receive(:puts).with("HTTP Health Check: #{http_health_check}")
|
60
|
+
expect(subject).to receive(:puts).with("Targets: #{targets}")
|
61
|
+
|
62
|
+
expected_body = target_group.properties.to_hash
|
63
|
+
|
64
|
+
mock_wait_for(subject)
|
65
|
+
mock_call_api(
|
66
|
+
subject,
|
67
|
+
[
|
68
|
+
{
|
69
|
+
method: 'POST',
|
70
|
+
path: '/targetgroups',
|
71
|
+
operation: :'TargetGroupsApi.targetgroups_post',
|
72
|
+
return_type: 'TargetGroup',
|
73
|
+
body: { properties: expected_body },
|
74
|
+
result: target_group,
|
75
|
+
},
|
76
|
+
{
|
77
|
+
method: 'GET',
|
78
|
+
path: "/targetgroups/#{target_group.id}",
|
79
|
+
operation: :'TargetGroupsApi.targetgroups_find_by_target_group_id',
|
80
|
+
return_type: 'TargetGroup',
|
81
|
+
result: target_group,
|
82
|
+
},
|
83
|
+
],
|
84
|
+
)
|
85
|
+
|
86
|
+
expect { subject.run }.not_to raise_error(Exception)
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'should not make any call if any required option is missing' do
|
90
|
+
required_options = subject.instance_variable_get(:@required_options)
|
91
|
+
|
92
|
+
if required_options.length > 0
|
93
|
+
arrays_without_one_element(required_options).each do |test_case|
|
94
|
+
subject.config[:ionoscloud_token] = 'token'
|
95
|
+
test_case[:array].each { |value| subject.config[value] = 'test' }
|
96
|
+
|
97
|
+
expect(subject).to receive(:puts).with("Missing required parameters #{test_case[:removed]}")
|
98
|
+
expect(subject.api_client).not_to receive(:call_api)
|
99
|
+
|
100
|
+
expect { subject.run }.to raise_error(SystemExit) do |error|
|
101
|
+
expect(error.status).to eq(1)
|
102
|
+
end
|
103
|
+
|
104
|
+
required_options.each { |value| subject.config[value] = nil }
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'ionoscloud_targetgroup_delete'
|
3
|
+
|
4
|
+
Chef::Knife::IonoscloudTargetgroupDelete.load_deps
|
5
|
+
|
6
|
+
describe Chef::Knife::IonoscloudTargetgroupDelete do
|
7
|
+
before :each do
|
8
|
+
subject { Chef::Knife::IonoscloudTargetgroupDelete.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.target_groups_delete when the ID is valid' do
|
16
|
+
target_group = target_group_mock
|
17
|
+
subject_config = {
|
18
|
+
ionoscloud_username: 'email',
|
19
|
+
ionoscloud_password: 'password',
|
20
|
+
yes: true,
|
21
|
+
}
|
22
|
+
|
23
|
+
subject_config.each { |key, value| subject.config[key] = value }
|
24
|
+
subject.name_args = [target_group.id]
|
25
|
+
|
26
|
+
|
27
|
+
health_check, http_health_check, targets = subject.get_target_group_extended_properties(target_group)
|
28
|
+
|
29
|
+
expect(subject).to receive(:puts).with("ID: #{target_group.id}")
|
30
|
+
expect(subject).to receive(:puts).with("Name: #{target_group.properties.name}")
|
31
|
+
expect(subject).to receive(:puts).with("Algorithm: #{target_group.properties.algorithm}")
|
32
|
+
expect(subject).to receive(:puts).with("Protocol: #{target_group.properties.protocol}")
|
33
|
+
expect(subject).to receive(:puts).with("Health Check: #{health_check}")
|
34
|
+
expect(subject).to receive(:puts).with("HTTP Health Check: #{http_health_check}")
|
35
|
+
expect(subject).to receive(:puts).with("Targets: #{targets}")
|
36
|
+
|
37
|
+
expect(subject.ui).to receive(:warn).with("Deleted Target Group #{target_group.id}. Request ID: ")
|
38
|
+
|
39
|
+
expect(subject.api_client).not_to receive(:wait_for)
|
40
|
+
expect(subject).to receive(:get_request_id).once
|
41
|
+
mock_call_api(
|
42
|
+
subject,
|
43
|
+
[
|
44
|
+
{
|
45
|
+
method: 'GET',
|
46
|
+
path: "/targetgroups/#{target_group.id}",
|
47
|
+
operation: :'TargetGroupsApi.targetgroups_find_by_target_group_id',
|
48
|
+
return_type: 'TargetGroup',
|
49
|
+
result: target_group,
|
50
|
+
},
|
51
|
+
{
|
52
|
+
method: 'DELETE',
|
53
|
+
path: "/targetgroups/#{target_group.id}",
|
54
|
+
operation: :'TargetGroupsApi.target_groups_delete',
|
55
|
+
},
|
56
|
+
],
|
57
|
+
)
|
58
|
+
|
59
|
+
expect { subject.run }.not_to raise_error(Exception)
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should not call TargetGroupsApi.target_groups_delete when the user ID is not valid' do
|
63
|
+
target_group_id = 'invalid_id'
|
64
|
+
subject_config = {
|
65
|
+
ionoscloud_username: 'email',
|
66
|
+
ionoscloud_password: 'password',
|
67
|
+
}
|
68
|
+
|
69
|
+
subject_config.each { |key, value| subject.config[key] = value }
|
70
|
+
subject.name_args = [target_group_id]
|
71
|
+
|
72
|
+
expect(subject.ui).to receive(:error).with("Target Group ID #{target_group_id} not found. Skipping.")
|
73
|
+
|
74
|
+
expect(subject.api_client).not_to receive(:wait_for)
|
75
|
+
mock_call_api(
|
76
|
+
subject,
|
77
|
+
[
|
78
|
+
{
|
79
|
+
method: 'GET',
|
80
|
+
path: "/targetgroups/#{target_group_id}",
|
81
|
+
operation: :'TargetGroupsApi.targetgroups_find_by_target_group_id',
|
82
|
+
return_type: 'TargetGroup',
|
83
|
+
exception: Ionoscloud::ApiError.new(code: 404),
|
84
|
+
},
|
85
|
+
],
|
86
|
+
)
|
87
|
+
|
88
|
+
expect { subject.run }.not_to raise_error(Exception)
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'should not make any call if any required option is missing' do
|
92
|
+
required_options = subject.instance_variable_get(:@required_options)
|
93
|
+
|
94
|
+
if required_options.length > 0
|
95
|
+
arrays_without_one_element(required_options).each do |test_case|
|
96
|
+
subject.config[:ionoscloud_token] = 'token'
|
97
|
+
test_case[:array].each { |value| subject.config[value] = 'test' }
|
98
|
+
|
99
|
+
expect(subject).to receive(:puts).with("Missing required parameters #{test_case[:removed]}")
|
100
|
+
expect(subject.api_client).not_to receive(:call_api)
|
101
|
+
|
102
|
+
expect { subject.run }.to raise_error(SystemExit) do |error|
|
103
|
+
expect(error.status).to eq(1)
|
104
|
+
end
|
105
|
+
|
106
|
+
required_options.each { |value| subject.config[value] = nil }
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|