vcloud-edge_gateway 0.0.2 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. data/CHANGELOG.md +11 -0
  2. data/jenkins_integration_tests.sh +8 -0
  3. data/lib/vcloud/edge_gateway/configuration_generator/load_balancer_service.rb +1 -7
  4. data/lib/vcloud/edge_gateway/configuration_generator/nat_service.rb +16 -6
  5. data/lib/vcloud/edge_gateway/edge_gateway_configuration.rb +34 -9
  6. data/lib/vcloud/edge_gateway/load_balancer_configuration_differ.rb +28 -0
  7. data/lib/vcloud/edge_gateway/version.rb +1 -1
  8. data/lib/vcloud/edge_gateway.rb +1 -0
  9. data/lib/vcloud/edge_gateway_services.rb +9 -4
  10. data/lib/vcloud/schema/edge_gateway.rb +2 -1
  11. data/lib/vcloud/schema/load_balancer_service.rb +3 -2
  12. data/spec/erb_helper.rb +1 -1
  13. data/spec/integration/edge_gateway/data/load_balancer_config.yaml.erb +24 -0
  14. data/spec/integration/edge_gateway/data/load_balancer_empty.yaml.erb +4 -0
  15. data/spec/integration/edge_gateway/data/load_balancer_single_pool.yaml.erb +15 -0
  16. data/spec/integration/edge_gateway/data/load_balancer_single_virtual_server_invalid_pool.yaml.erb +13 -0
  17. data/spec/integration/edge_gateway/data/load_balancer_single_virtual_server_missing_pool.yaml.erb +12 -0
  18. data/spec/integration/edge_gateway/data/nat_and_firewall_plus_load_balancer_config.yaml.erb +54 -0
  19. data/spec/integration/edge_gateway/edge_gateway_services_spec.rb +52 -23
  20. data/spec/integration/edge_gateway/load_balancer_service_spec.rb +204 -0
  21. data/spec/integration/edge_gateway/nat_service_spec.rb +7 -2
  22. data/spec/vcloud/edge_gateway/configuration_generator/data/load_balancer_http-output.yaml +2 -2
  23. data/spec/vcloud/edge_gateway/configuration_generator/data/load_balancer_https-output.yaml +2 -0
  24. data/spec/vcloud/edge_gateway/configuration_generator/data/load_balancer_mixed_complex-output.yaml +1 -0
  25. data/spec/vcloud/edge_gateway/configuration_generator/load_balancer_service_spec.rb +2 -0
  26. data/spec/vcloud/edge_gateway/configuration_generator/nat_service_spec.rb +198 -94
  27. data/spec/vcloud/edge_gateway/edge_gateway_configuration_spec.rb +1043 -88
  28. data/spec/vcloud/edge_gateway/load_balancer_configuration_differ_spec.rb +160 -0
  29. data/spec/vcloud/edge_gateway/load_balancer_schema_validation_spec.rb +4 -6
  30. data/vcloud-edge_gateway.gemspec +1 -1
  31. metadata +24 -5
@@ -0,0 +1,204 @@
1
+ require 'spec_helper'
2
+
3
+ module Vcloud
4
+ describe EdgeGatewayServices do
5
+
6
+ required_env = {
7
+ 'VCLOUD_EDGE_GATEWAY' => 'to name of VSE',
8
+ 'VCLOUD_PROVIDER_NETWORK_ID' => 'to ID of VSE external network',
9
+ 'VCLOUD_PROVIDER_NETWORK_IP' => 'to an available IP on VSE external network',
10
+ 'VCLOUD_NETWORK1_ID' => 'to the ID of a VSE internal network',
11
+ 'VCLOUD_NETWORK1_NAME' => 'to the name of the VSE internal network',
12
+ 'VCLOUD_NETWORK1_IP' => 'to an ID on the VSE internal network',
13
+ }
14
+
15
+ error = false
16
+ required_env.each do |var,message|
17
+ unless ENV[var]
18
+ puts "Must set #{var} #{message}" unless ENV[var]
19
+ error = true
20
+ end
21
+ end
22
+ Kernel.exit(2) if error
23
+
24
+ before(:all) do
25
+ @edge_name = ENV['VCLOUD_EDGE_GATEWAY']
26
+ @ext_net_id = ENV['VCLOUD_PROVIDER_NETWORK_ID']
27
+ @ext_net_ip = ENV['VCLOUD_PROVIDER_NETWORK_IP']
28
+ @ext_net_name = ENV['VCLOUD_PROVIDER_NETWORK_NAME']
29
+ @int_net_id = ENV['VCLOUD_NETWORK1_ID']
30
+ @int_net_ip = ENV['VCLOUD_NETWORK1_IP']
31
+ @int_net_name = ENV['VCLOUD_NETWORK1_NAME']
32
+ @files_to_delete = []
33
+ end
34
+
35
+ context "Test LoadBalancerService specifics of EdgeGatewayServices" do
36
+
37
+ before(:all) do
38
+ reset_edge_gateway
39
+ @initial_load_balancer_config_file =
40
+ generate_input_config_file('load_balancer_config.yaml.erb', edge_gateway_erb_input)
41
+ @edge_gateway = Vcloud::Core::EdgeGateway.get_by_name(@edge_name)
42
+ end
43
+
44
+ context "Check update is functional" do
45
+
46
+ before(:all) do
47
+ local_config = ConfigLoader.new.load_config(
48
+ @initial_load_balancer_config_file,
49
+ Vcloud::Schema::EDGE_GATEWAY_SERVICES
50
+ )
51
+ @local_vcloud_config = EdgeGateway::ConfigurationGenerator::LoadBalancerService.new(
52
+ @edge_name
53
+ ).generate_fog_config(local_config[:load_balancer_service])
54
+ end
55
+
56
+ it "should be starting our tests from an empty LoadBalancerService" do
57
+ edge_service_config = @edge_gateway.vcloud_attributes[:Configuration][:EdgeGatewayServiceConfiguration]
58
+ remote_vcloud_config = edge_service_config[:LoadBalancerService]
59
+ expect(remote_vcloud_config[:Pool].empty?).to be_true
60
+ expect(remote_vcloud_config[:VirtualServer].empty?).to be_true
61
+ end
62
+
63
+ it "should only make one EdgeGateway update task, to minimise EdgeGateway reload events" do
64
+ start_time = DateTime.now()
65
+ task_list_before_update = get_all_edge_gateway_update_tasks_ordered_by_start_date_since_time(start_time)
66
+ EdgeGatewayServices.new.update(@initial_load_balancer_config_file)
67
+ task_list_after_update = get_all_edge_gateway_update_tasks_ordered_by_start_date_since_time(start_time)
68
+ expect(task_list_after_update.size - task_list_before_update.size).to be(1)
69
+ end
70
+
71
+ it "should have configured at least one LoadBancer Pool entry" do
72
+ edge_service_config = @edge_gateway.vcloud_attributes[:Configuration][:EdgeGatewayServiceConfiguration]
73
+ remote_vcloud_config = edge_service_config[:LoadBalancerService]
74
+ expect(remote_vcloud_config[:Pool].empty?).to be_false
75
+ end
76
+
77
+ it "should have configured at least one LoadBancer VirtualServer entry" do
78
+ edge_service_config = @edge_gateway.vcloud_attributes[:Configuration][:EdgeGatewayServiceConfiguration]
79
+ remote_vcloud_config = edge_service_config[:LoadBalancerService]
80
+ expect(remote_vcloud_config[:VirtualServer].empty?).to be_false
81
+ end
82
+
83
+ it "should have configured the same number of Pools as in our configuration" do
84
+ edge_service_config = @edge_gateway.vcloud_attributes[:Configuration][:EdgeGatewayServiceConfiguration]
85
+ remote_vcloud_config = edge_service_config[:LoadBalancerService]
86
+ expect(remote_vcloud_config[:Pool].size).
87
+ to eq(@local_vcloud_config[:Pool].size)
88
+ end
89
+
90
+ it "should have configured the same number of VirtualServers as in our configuration" do
91
+ edge_service_config = @edge_gateway.vcloud_attributes[:Configuration][:EdgeGatewayServiceConfiguration]
92
+ remote_vcloud_config = edge_service_config[:LoadBalancerService]
93
+ expect(remote_vcloud_config[:VirtualServer].size).
94
+ to eq(@local_vcloud_config[:VirtualServer].size)
95
+ end
96
+
97
+ it "ConfigurationDiffer should return empty if local and remote LoadBalancer configs match" do
98
+ edge_service_config = @edge_gateway.vcloud_attributes[:Configuration][:EdgeGatewayServiceConfiguration]
99
+ remote_vcloud_config = edge_service_config[:LoadBalancerService]
100
+ differ = EdgeGateway::LoadBalancerConfigurationDiffer.new(@local_vcloud_config, remote_vcloud_config)
101
+ diff_output = differ.diff
102
+ expect(diff_output).to eq([])
103
+ end
104
+
105
+ it "should not then configure the LoadBalancerService if updated again with the same configuration" do
106
+ expect(Vcloud::EdgeGateway.logger).
107
+ to receive(:info).with('EdgeGatewayServices.update: Configuration is already up to date. Skipping.')
108
+ EdgeGatewayServices.new.update(@initial_load_balancer_config_file)
109
+ end
110
+
111
+ end
112
+
113
+ context "Check specific LoadBalancerService update cases" do
114
+
115
+ it "should be able to configure with no pools and virtual_servers" do
116
+ config_file = generate_input_config_file(
117
+ 'load_balancer_empty.yaml.erb',
118
+ edge_gateway_erb_input
119
+ )
120
+ EdgeGatewayServices.new.update(config_file)
121
+ edge_config = @edge_gateway.vcloud_attributes[:Configuration]
122
+ remote_vcloud_config = edge_config[:EdgeGatewayServiceConfiguration][:LoadBalancerService]
123
+ expect(remote_vcloud_config[:Pool].size).to be == 0
124
+ expect(remote_vcloud_config[:VirtualServer].size).to be == 0
125
+ end
126
+
127
+ it "should be able to configure with a single Pool and no VirtualServers" do
128
+ config_file = generate_input_config_file(
129
+ 'load_balancer_single_pool.yaml.erb',
130
+ edge_gateway_erb_input
131
+ )
132
+ EdgeGatewayServices.new.update(config_file)
133
+ edge_config = @edge_gateway.vcloud_attributes[:Configuration]
134
+ remote_vcloud_config = edge_config[:EdgeGatewayServiceConfiguration][:LoadBalancerService]
135
+ expect(remote_vcloud_config[:Pool].size).to be == 1
136
+ end
137
+
138
+ it "should raise an error when trying configure with a single VirtualServer, and no pool mentioned" do
139
+ config_file = generate_input_config_file(
140
+ 'load_balancer_single_virtual_server_missing_pool.yaml.erb',
141
+ edge_gateway_erb_input
142
+ )
143
+ expect { EdgeGatewayServices.new.update(config_file) }.
144
+ to raise_error('Supplied configuration does not match supplied schema')
145
+ end
146
+
147
+ it "should raise an error when trying configure with a single VirtualServer, with an unconfigured pool" do
148
+ config_file = generate_input_config_file(
149
+ 'load_balancer_single_virtual_server_invalid_pool.yaml.erb',
150
+ edge_gateway_erb_input
151
+ )
152
+ expect { EdgeGatewayServices.new.update(config_file) }.
153
+ to raise_error(
154
+ 'Load balancer virtual server integration-test-vs-1 does not have a valid backing pool.'
155
+ )
156
+ end
157
+
158
+ end
159
+
160
+ after(:all) do
161
+ reset_edge_gateway unless ENV['VCLOUD_NO_RESET_VSE_AFTER']
162
+ FileUtils.rm(@files_to_delete)
163
+ end
164
+
165
+ def reset_edge_gateway
166
+ edge_gateway = Core::EdgeGateway.get_by_name @edge_name
167
+ edge_gateway.update_configuration({
168
+ LoadBalancerService: {
169
+ IsEnabled: "false",
170
+ Pool: [],
171
+ VirtualServer: []
172
+ }
173
+ })
174
+ end
175
+
176
+ def generate_input_config_file(data_file, erb_input)
177
+ config_erb = File.expand_path("data/#{data_file}", File.dirname(__FILE__))
178
+ output_file = ErbHelper.convert_erb_template_to_yaml(erb_input, config_erb)
179
+ @files_to_delete << output_file
180
+ output_file
181
+ end
182
+
183
+ def edge_gateway_erb_input
184
+ {
185
+ :edge_gateway_name => @edge_name,
186
+ :edge_gateway_ext_network_id => @ext_net_id,
187
+ :edge_gateway_ext_network_ip => @ext_net_ip,
188
+ }
189
+ end
190
+
191
+ def get_all_edge_gateway_update_tasks_ordered_by_start_date_since_time(timestamp)
192
+ vcloud_time = timestamp.strftime('%FT%T.000Z')
193
+ q = Query.new('task',
194
+ :filter =>
195
+ "name==networkConfigureEdgeGatewayServices;objectName==#{@edge_name};startDate=ge=#{vcloud_time}",
196
+ :sortDesc => 'startDate',
197
+ )
198
+ q.get_all_results
199
+ end
200
+
201
+ end
202
+
203
+ end
204
+ end
@@ -49,8 +49,13 @@ module Vcloud
49
49
  context "Check update is functional" do
50
50
 
51
51
  before(:all) do
52
- local_config = ConfigLoader.new.load_config(@initial_nat_config_file, Vcloud::Schema::EDGE_GATEWAY_SERVICES)
53
- @local_vcloud_config = EdgeGateway::ConfigurationGenerator::NatService.new(@edge_name, local_config[:nat_service]).generate_fog_config
52
+ local_config = ConfigLoader.new.load_config(
53
+ @initial_nat_config_file, Vcloud::Schema::EDGE_GATEWAY_SERVICES
54
+ )
55
+ @local_vcloud_config = EdgeGateway::ConfigurationGenerator::NatService.new(
56
+ local_config[:nat_service],
57
+ @edge_gateway.interfaces
58
+ ).generate_fog_config
54
59
  end
55
60
 
56
61
  it "should be starting our tests from an empty NatService" do
@@ -24,7 +24,7 @@
24
24
  HealthCheckPort: '',
25
25
  HealthCheck:
26
26
  {
27
- Mode: "SSL", HealthThreshold: '2', UnhealthThreshold: '3', Interval: '5', Timeout: '15'
27
+ Mode: "SSL", Uri: '', HealthThreshold: '2', UnhealthThreshold: '3', Interval: '5', Timeout: '15'
28
28
  }
29
29
  },
30
30
  {
@@ -35,7 +35,7 @@
35
35
  HealthCheckPort: '',
36
36
  HealthCheck:
37
37
  {
38
- Mode: "TCP", HealthThreshold: '2', UnhealthThreshold: '3', Interval: '5', Timeout: '15'
38
+ Mode: "TCP", Uri: '', HealthThreshold: '2', UnhealthThreshold: '3', Interval: '5', Timeout: '15'
39
39
  }
40
40
  }
41
41
  ],
@@ -23,6 +23,7 @@
23
23
  :HealthCheckPort: ''
24
24
  :HealthCheck:
25
25
  :Mode: SSL
26
+ :Uri: ''
26
27
  :HealthThreshold: '2'
27
28
  :UnhealthThreshold: '3'
28
29
  :Interval: '5'
@@ -34,6 +35,7 @@
34
35
  :HealthCheckPort: ''
35
36
  :HealthCheck:
36
37
  :Mode: TCP
38
+ :Uri: ''
37
39
  :HealthThreshold: '2'
38
40
  :UnhealthThreshold: '3'
39
41
  :Interval: '5'
@@ -34,6 +34,7 @@
34
34
  :HealthCheckPort: ''
35
35
  :HealthCheck:
36
36
  :Mode: TCP
37
+ :Uri: ''
37
38
  :HealthThreshold: '2'
38
39
  :UnhealthThreshold: '3'
39
40
  :Interval: '5'
@@ -142,6 +142,7 @@ module Vcloud
142
142
  :HealthCheckPort=>"",
143
143
  :HealthCheck=>{
144
144
  :Mode=>"SSL",
145
+ :Uri=>"",
145
146
  :HealthThreshold=>"2",
146
147
  :UnhealthThreshold=>"3",
147
148
  :Interval=>"5",
@@ -156,6 +157,7 @@ module Vcloud
156
157
  :HealthCheckPort=>"",
157
158
  :HealthCheck=>{
158
159
  :Mode=>"TCP",
160
+ :Uri=>"",
159
161
  :HealthThreshold=>"2",
160
162
  :UnhealthThreshold=>"3",
161
163
  :Interval=>"5",
@@ -6,18 +6,20 @@ module Vcloud
6
6
  describe NatService do
7
7
 
8
8
  before(:each) do
9
- @edge_id = '1111111-7b54-43dd-9eb1-631dd337e5a7'
10
- @mock_edge_gateway = double(
11
- :edge_gateway,
12
- :vcloud_gateway_interface_by_id => {
13
- Network: {
14
- name: 'ane012345',
15
- href: 'https://vmware.api.net/api/admin/network/2ad93597-7b54-43dd-9eb1-631dd337e5a7'
16
- }
17
- }
9
+ @base_nat_id = ID_RANGES::NAT_SERVICE[:min]
10
+ mock_uplink_interface = double(
11
+ :mock_uplink,
12
+ :network_name => "ane012345",
13
+ :network_id => "2ad93597-7b54-43dd-9eb1-631dd337e5a7",
14
+ :network_href => "https://vmware.api.net/api/admin/network/2ad93597-7b54-43dd-9eb1-631dd337e5a7",
15
+ )
16
+ mock_internal_interface = double(
17
+ :mock_uplink,
18
+ :network_name => "internal_interface",
19
+ :network_id => "12346788-1234-1234-1234-123456789000",
20
+ :network_href => "https://vmware.api.net/api/admin/network/12346788-1234-1234-1234-123456789000",
18
21
  )
19
- expect(Vcloud::Core::EdgeGateway).to receive(:get_by_name).with(@edge_id)
20
- .and_return(@mock_edge_gateway)
22
+ @edge_gw_interface_list = [ mock_internal_interface, mock_uplink_interface ]
21
23
  end
22
24
 
23
25
  context "SNAT rule defaults" do
@@ -29,7 +31,7 @@ module Vcloud
29
31
  original_ip: "192.0.2.2",
30
32
  translated_ip: "10.10.20.20",
31
33
  }]} # minimum NAT configuration with a rule
32
- output = NatService.new(@edge_id, input).generate_fog_config
34
+ output = NatService.new(input, @edge_gw_interface_list).generate_fog_config
33
35
  @rule = output[:NatRule].first
34
36
  end
35
37
 
@@ -47,13 +49,14 @@ module Vcloud
47
49
 
48
50
  it 'should completely match our expected default rule' do
49
51
  expect(@rule).to eq({
50
- :Id=>"65537",
52
+ :Id=>"#{@base_nat_id}",
51
53
  :IsEnabled=>"true",
52
54
  :RuleType=>"SNAT",
53
55
  :GatewayNatRule=>{
54
56
  :Interface=>{
55
- :name=>"ane012345",
56
- :href=>"https://vmware.api.net/api/admin/network/2ad93597-7b54-43dd-9eb1-631dd337e5a7"
57
+ :type => 'application/vnd.vmware.admin.network+xml',
58
+ :name => "ane012345",
59
+ :href => "https://vmware.api.net/api/admin/network/2ad93597-7b54-43dd-9eb1-631dd337e5a7"
57
60
  },
58
61
  :OriginalIp=>"192.0.2.2",
59
62
  :TranslatedIp=>"10.10.20.20"}
@@ -74,7 +77,7 @@ module Vcloud
74
77
  translated_ip: "10.10.20.20",
75
78
  protocol: 'tcp',
76
79
  }]} # minimum NAT configuration with a rule
77
- output = NatService.new(@edge_id, input).generate_fog_config
80
+ output = NatService.new(input, @edge_gw_interface_list).generate_fog_config
78
81
  @rule = output[:NatRule].first
79
82
  end
80
83
 
@@ -92,13 +95,14 @@ module Vcloud
92
95
 
93
96
  it 'should completely match our expected default rule' do
94
97
  expect(@rule).to eq({
95
- :Id=>"65537",
98
+ :Id=>"#{@base_nat_id}",
96
99
  :IsEnabled=>"true",
97
100
  :RuleType=>"DNAT",
98
101
  :GatewayNatRule=>{
99
102
  :Interface=>{
100
- :name=>"ane012345",
101
- :href=>"https://vmware.api.net/api/admin/network/2ad93597-7b54-43dd-9eb1-631dd337e5a7"
103
+ :type => 'application/vnd.vmware.admin.network+xml',
104
+ :name => "ane012345",
105
+ :href => "https://vmware.api.net/api/admin/network/2ad93597-7b54-43dd-9eb1-631dd337e5a7"
102
106
  },
103
107
  :OriginalIp=>"192.0.2.2",
104
108
  :TranslatedIp=>"10.10.20.20",
@@ -113,10 +117,8 @@ module Vcloud
113
117
 
114
118
  context "nat service config generation" do
115
119
 
116
- test_cases = [
117
- {
118
- title: 'should generate config for enabled nat service with single disabled DNAT rule',
119
- input: {
120
+ it 'should generate config for enabled nat service with single disabled DNAT rule' do
121
+ input = {
120
122
  enabled: 'true',
121
123
  nat_rules: [
122
124
  {
@@ -131,8 +133,8 @@ module Vcloud
131
133
  protocol: 'tcp',
132
134
  }
133
135
  ]
134
- },
135
- output: {
136
+ }
137
+ output = {
136
138
  :IsEnabled => 'true',
137
139
  :NatRule => [
138
140
  {
@@ -142,6 +144,7 @@ module Vcloud
142
144
  :GatewayNatRule => {
143
145
  :Interface =>
144
146
  {
147
+ :type => 'application/vnd.vmware.admin.network+xml',
145
148
  :name => 'ane012345',
146
149
  :href => 'https://vmware.api.net/api/admin/network/2ad93597-7b54-43dd-9eb1-631dd337e5a7'
147
150
  },
@@ -154,11 +157,12 @@ module Vcloud
154
157
  }
155
158
  ]
156
159
  }
157
- },
160
+ generated_config = NatService.new(input, @edge_gw_interface_list).generate_fog_config
161
+ expect(generated_config).to eq(output)
162
+ end
158
163
 
159
- {
160
- title: 'should handle specification of UDP based DNAT rules',
161
- input: {
164
+ it 'should handle specification of UDP based DNAT rules' do
165
+ input = {
162
166
  enabled: 'true',
163
167
  nat_rules: [
164
168
  {
@@ -171,17 +175,18 @@ module Vcloud
171
175
  protocol: 'udp',
172
176
  }
173
177
  ]
174
- },
175
- output: {
178
+ }
179
+ output = {
176
180
  :IsEnabled => 'true',
177
181
  :NatRule => [
178
182
  {
179
183
  :RuleType => 'DNAT',
180
184
  :IsEnabled => 'true',
181
- :Id => '65537',
185
+ :Id => "#{@base_nat_id}",
182
186
  :GatewayNatRule => {
183
187
  :Interface =>
184
188
  {
189
+ :type => 'application/vnd.vmware.admin.network+xml',
185
190
  :name => 'ane012345',
186
191
  :href => 'https://vmware.api.net/api/admin/network/2ad93597-7b54-43dd-9eb1-631dd337e5a7'
187
192
  },
@@ -194,11 +199,12 @@ module Vcloud
194
199
  }
195
200
  ]
196
201
  }
197
- },
202
+ generated_config = NatService.new(input, @edge_gw_interface_list).generate_fog_config
203
+ expect(generated_config).to eq(output)
204
+ end
198
205
 
199
- {
200
- title: 'should generate config for enabled nat service with single disabled SNAT rule',
201
- input: {
206
+ it 'should generate config for enabled nat service with single disabled SNAT rule' do
207
+ input = {
202
208
  enabled: 'true',
203
209
  nat_rules: [
204
210
  {
@@ -209,17 +215,18 @@ module Vcloud
209
215
  translated_ip: "10.10.20.20",
210
216
  }
211
217
  ]
212
- },
213
- output: {
218
+ }
219
+ output = {
214
220
  :IsEnabled => 'true',
215
221
  :NatRule => [
216
222
  {
217
223
  :RuleType => 'SNAT',
218
224
  :IsEnabled => 'false',
219
- :Id => '65537',
225
+ :Id => "#{@base_nat_id}",
220
226
  :GatewayNatRule => {
221
227
  :Interface =>
222
228
  {
229
+ :type => 'application/vnd.vmware.admin.network+xml',
223
230
  :name => 'ane012345',
224
231
  :href => 'https://vmware.api.net/api/admin/network/2ad93597-7b54-43dd-9eb1-631dd337e5a7'
225
232
  },
@@ -229,11 +236,12 @@ module Vcloud
229
236
  }
230
237
  ]
231
238
  }
232
- },
239
+ generated_config = NatService.new(input, @edge_gw_interface_list).generate_fog_config
240
+ expect(generated_config).to eq(output)
241
+ end
233
242
 
234
- {
235
- title: 'should auto generate rule id if not provided',
236
- input: {
243
+ it 'should auto generate rule id if not provided' do
244
+ input = {
237
245
  enabled: 'true',
238
246
  nat_rules: [
239
247
  {
@@ -247,17 +255,18 @@ module Vcloud
247
255
  protocol: 'tcp',
248
256
  }
249
257
  ]
250
- },
251
- output: {
258
+ }
259
+ output = {
252
260
  :IsEnabled => 'true',
253
261
  :NatRule => [
254
262
  {
255
263
  :RuleType => 'DNAT',
256
264
  :IsEnabled => 'false',
257
- :Id => '65537',
265
+ :Id => "#{@base_nat_id}",
258
266
  :GatewayNatRule => {
259
267
  :Interface =>
260
268
  {
269
+ :type => 'application/vnd.vmware.admin.network+xml',
261
270
  :name => 'ane012345',
262
271
  :href => 'https://vmware.api.net/api/admin/network/2ad93597-7b54-43dd-9eb1-631dd337e5a7'
263
272
  },
@@ -270,11 +279,12 @@ module Vcloud
270
279
  }
271
280
  ]
272
281
  }
273
- },
282
+ generated_config = NatService.new(input, @edge_gw_interface_list).generate_fog_config
283
+ expect(generated_config).to eq(output)
284
+ end
274
285
 
275
- {
276
- title: 'should use default values for optional fields if they are missing',
277
- input: {
286
+ it 'should use default values for optional fields if they are missing' do
287
+ input = {
278
288
  nat_rules: [
279
289
  {
280
290
  rule_type: 'DNAT',
@@ -285,17 +295,18 @@ module Vcloud
285
295
  translated_ip: "10.10.20.20",
286
296
  }
287
297
  ]
288
- },
289
- output: {
298
+ }
299
+ output = {
290
300
  :IsEnabled => 'true',
291
301
  :NatRule => [
292
302
  {
293
303
  :RuleType => 'DNAT',
294
304
  :IsEnabled => 'true',
295
- :Id => '65537',
305
+ :Id => "#{@base_nat_id}",
296
306
  :GatewayNatRule => {
297
307
  :Interface =>
298
308
  {
309
+ :type => 'application/vnd.vmware.admin.network+xml',
299
310
  :name => 'ane012345',
300
311
  :href => 'https://vmware.api.net/api/admin/network/2ad93597-7b54-43dd-9eb1-631dd337e5a7'
301
312
  },
@@ -308,49 +319,142 @@ module Vcloud
308
319
  }
309
320
  ]
310
321
  }
311
-
312
- }
313
- ]
314
-
315
- test_cases.each do |test_case|
316
- it "#{test_case[:title]}" do
317
- generated_config = NatService.new(@edge_id, test_case[:input]).generate_fog_config
318
- expect(generated_config).to eq(test_case[:output])
319
- end
322
+ generated_config = NatService.new(input, @edge_gw_interface_list).generate_fog_config
323
+ expect(generated_config).to eq(output)
320
324
  end
321
325
 
322
- it "should only make a single API call per network specified" do
323
- input = {
324
- nat_rules: [
325
- {
326
- rule_type: 'DNAT',
327
- network_id: '2ad93597-7b54-43dd-9eb1-631dd337e5a7',
328
- original_ip: "192.0.2.2",
329
- original_port: '8081',
330
- translated_port: '8081',
331
- translated_ip: "10.10.20.21",
332
- },
333
- {
334
- rule_type: 'DNAT',
335
- network_id: '2ad93597-7b54-43dd-9eb1-631dd337e5a7',
336
- original_ip: "192.0.2.2",
337
- original_port: '8082',
338
- translated_port: '8082',
339
- translated_ip: "10.10.20.22",
340
- },
341
- {
342
- rule_type: 'DNAT',
343
- network_id: '2ad93597-7b54-43dd-9eb1-631dd337e5a7',
344
- original_ip: "192.0.2.2",
345
- original_port: '8083',
346
- translated_port: '8083',
347
- translated_ip: "10.10.20.23",
348
- },
349
- ]
350
- }
351
- expect(@mock_edge_gateway).
352
- to receive(:vcloud_gateway_interface_by_id).exactly(1).times
353
- NatService.new(@edge_id, input).generate_fog_config
326
+ it 'output rule order should be same as the input rule order' do
327
+ input = {
328
+ nat_rules: [
329
+ {
330
+ rule_type: 'DNAT',
331
+ network_id: '2ad93597-7b54-43dd-9eb1-631dd337e5a7',
332
+ original_ip: "192.0.2.2",
333
+ original_port: '8081',
334
+ translated_port: '8080',
335
+ translated_ip: "10.10.20.21",
336
+ },
337
+ {
338
+ rule_type: 'SNAT',
339
+ network_id: '2ad93597-7b54-43dd-9eb1-631dd337e5a7',
340
+ original_ip: "192.0.2.2",
341
+ translated_ip: "10.10.20.20",
342
+ },
343
+ {
344
+ rule_type: 'DNAT',
345
+ network_id: '2ad93597-7b54-43dd-9eb1-631dd337e5a7',
346
+ original_ip: "192.0.2.2",
347
+ original_port: '8082',
348
+ translated_port: '8080',
349
+ translated_ip: "10.10.20.22",
350
+ },
351
+ {
352
+ rule_type: 'SNAT',
353
+ network_id: '2ad93597-7b54-43dd-9eb1-631dd337e5a7',
354
+ original_ip: "192.0.2.3",
355
+ translated_ip: "10.10.20.21",
356
+ },
357
+ {
358
+ rule_type: 'DNAT',
359
+ network_id: '2ad93597-7b54-43dd-9eb1-631dd337e5a7',
360
+ original_ip: "192.0.2.2",
361
+ original_port: '8083',
362
+ translated_port: '8080',
363
+ translated_ip: "10.10.20.23",
364
+ },
365
+ ],
366
+ }
367
+ output = {
368
+ IsEnabled: 'true',
369
+ NatRule: [
370
+ {
371
+ :Id => "#{@base_nat_id}",
372
+ :IsEnabled => 'true',
373
+ :RuleType => 'DNAT',
374
+ :GatewayNatRule => {
375
+ :Interface =>
376
+ {
377
+ :type => 'application/vnd.vmware.admin.network+xml',
378
+ :name => 'ane012345',
379
+ :href => 'https://vmware.api.net/api/admin/network/2ad93597-7b54-43dd-9eb1-631dd337e5a7'
380
+ },
381
+ :OriginalIp => "192.0.2.2",
382
+ :TranslatedIp => "10.10.20.21",
383
+ :OriginalPort => '8081',
384
+ :TranslatedPort => '8080',
385
+ :Protocol => 'tcp',
386
+ },
387
+ },
388
+ {
389
+ :Id => "#{@base_nat_id + 1}",
390
+ :IsEnabled => 'true',
391
+ :RuleType => 'SNAT',
392
+ :GatewayNatRule => {
393
+ :Interface =>
394
+ {
395
+ :type => 'application/vnd.vmware.admin.network+xml',
396
+ :name => 'ane012345',
397
+ :href => 'https://vmware.api.net/api/admin/network/2ad93597-7b54-43dd-9eb1-631dd337e5a7'
398
+ },
399
+ :OriginalIp => "192.0.2.2",
400
+ :TranslatedIp => "10.10.20.20",
401
+ },
402
+ },
403
+ {
404
+ :Id => "#{@base_nat_id + 2}",
405
+ :IsEnabled => 'true',
406
+ :RuleType => 'DNAT',
407
+ :GatewayNatRule => {
408
+ :Interface =>
409
+ {
410
+ :type => 'application/vnd.vmware.admin.network+xml',
411
+ :name => 'ane012345',
412
+ :href => 'https://vmware.api.net/api/admin/network/2ad93597-7b54-43dd-9eb1-631dd337e5a7'
413
+ },
414
+ :OriginalIp => "192.0.2.2",
415
+ :TranslatedIp => "10.10.20.22",
416
+ :OriginalPort => '8082',
417
+ :TranslatedPort => '8080',
418
+ :Protocol => 'tcp',
419
+ },
420
+ },
421
+ {
422
+ :Id => "#{@base_nat_id + 3}",
423
+ :IsEnabled => 'true',
424
+ :RuleType => 'SNAT',
425
+ :GatewayNatRule => {
426
+ :Interface =>
427
+ {
428
+ :type => 'application/vnd.vmware.admin.network+xml',
429
+ :name => 'ane012345',
430
+ :href => 'https://vmware.api.net/api/admin/network/2ad93597-7b54-43dd-9eb1-631dd337e5a7'
431
+ },
432
+ :OriginalIp => "192.0.2.3",
433
+ :TranslatedIp => "10.10.20.21",
434
+ },
435
+ },
436
+ {
437
+ :Id => "#{@base_nat_id + 4}",
438
+ :IsEnabled => 'true',
439
+ :RuleType => 'DNAT',
440
+ :GatewayNatRule => {
441
+ :Interface =>
442
+ {
443
+ :type => 'application/vnd.vmware.admin.network+xml',
444
+ :name => 'ane012345',
445
+ :href => 'https://vmware.api.net/api/admin/network/2ad93597-7b54-43dd-9eb1-631dd337e5a7'
446
+ },
447
+ :OriginalIp => "192.0.2.2",
448
+ :TranslatedIp => "10.10.20.23",
449
+ :OriginalPort => '8083',
450
+ :TranslatedPort => '8080',
451
+ :Protocol => 'tcp',
452
+ },
453
+ }
454
+ ]
455
+ }
456
+ generated_config = NatService.new(input, @edge_gw_interface_list).generate_fog_config
457
+ expect(generated_config).to eq(output)
354
458
  end
355
459
 
356
460
  end