Debian Codegraph @

edgegateway_test.go

raw symbols SCIP
1 /*
2 * Copyright 2014 VMware, Inc. All rights reserved. Licensed under the Apache v2 License.
3 */
4
5 package govcd
6
7 import (
8 "github.com/hmrc/vmware-govcd/testutil"
9
10 . "gopkg.in/check.v1"
11 )
12
13 func (s *S) Test_Refresh(c *C) {
14
15 // Get the Org populated
16 testServer.ResponseMap(2, testutil.ResponseMap{
17 "/api/vdc/00000000-0000-0000-0000-000000000000/edgeGateways": testutil.Response{200, nil, edgegatewayqueryresultsExample},
18 "/api/admin/edgeGateway/00000000-0000-0000-0000-000000000000": testutil.Response{200, nil, edgegatewayExample},
19 })
20
21 edge, err := s.vdc.FindEdgeGateway("M916272752-5793")
22 _ = testServer.WaitRequests(2)
23 testServer.Flush()
24
25 c.Assert(err, IsNil)
26 c.Assert(edge.EdgeGateway.Name, Equals, "M916272752-5793")
27
28 testServer.Response(200, nil, edgegatewayExample)
29 err = edge.Refresh()
30 _ = testServer.WaitRequest()
31 testServer.Flush()
32
33 c.Assert(err, IsNil)
34 c.Assert(edge.EdgeGateway.Name, Equals, "M916272752-5793")
35
36 }
37
38 func (s *S) Test_NATMapping(c *C) {
39 testServer.ResponseMap(2, testutil.ResponseMap{
40 "/api/vdc/00000000-0000-0000-0000-000000000000/edgeGateways": testutil.Response{200, nil, edgegatewayqueryresultsExample},
41 "/api/admin/edgeGateway/00000000-0000-0000-0000-000000000000": testutil.Response{200, nil, edgegatewayExample},
42 })
43
44 edge, err := s.vdc.FindEdgeGateway("M916272752-5793")
45 _ = testServer.WaitRequests(2)
46 testServer.Flush()
47
48 c.Assert(err, IsNil)
49 c.Assert(edge.EdgeGateway.Name, Equals, "M916272752-5793")
50
51 testServer.ResponseMap(2, testutil.ResponseMap{
52 "/api/admin/edgeGateway/00000000-0000-0000-0000-000000000000": testutil.Response{200, nil, edgegatewayExample},
53 "/api/admin/edgeGateway/00000000-0000-0000-0000-000000000000/action/configureServices": testutil.Response{200, nil, taskExample},
54 })
55
56 _, err = edge.AddNATMapping("DNAT", "10.0.0.1", "20.0.0.2", "77")
57 _ = testServer.WaitRequest()
58
59 c.Assert(err, IsNil)
60
61 testServer.ResponseMap(2, testutil.ResponseMap{
62 "/api/admin/edgeGateway/00000000-0000-0000-0000-000000000000": testutil.Response{200, nil, edgegatewayExample},
63 "/api/admin/edgeGateway/00000000-0000-0000-0000-000000000000/action/configureServices": testutil.Response{200, nil, taskExample},
64 })
65
66 _, err = edge.RemoveNATMapping("DNAT", "10.0.0.1", "20.0.0.2", "77")
67 _ = testServer.WaitRequest()
68
69 c.Assert(err, IsNil)
70
71 }
72
73 func (s *S) Test_1to1Mappings(c *C) {
74
75 testServer.ResponseMap(2, testutil.ResponseMap{
76 "/api/vdc/00000000-0000-0000-0000-000000000000/edgeGateways": testutil.Response{200, nil, edgegatewayqueryresultsExample},
77 "/api/admin/edgeGateway/00000000-0000-0000-0000-000000000000": testutil.Response{200, nil, edgegatewayExample},
78 })
79
80 edge, err := s.vdc.FindEdgeGateway("M916272752-5793")
81 _ = testServer.WaitRequests(2)
82 testServer.Flush()
83
84 c.Assert(err, IsNil)
85 c.Assert(edge.EdgeGateway.Name, Equals, "M916272752-5793")
86
87 testServer.ResponseMap(2, testutil.ResponseMap{
88 "/api/admin/edgeGateway/00000000-0000-0000-0000-000000000000": testutil.Response{200, nil, edgegatewayExample},
89 "/api/admin/edgeGateway/00000000-0000-0000-0000-000000000000/action/configureServices": testutil.Response{200, nil, taskExample},
90 })
91
92 _, err = edge.Create1to1Mapping("10.0.0.1", "20.0.0.2", "description")
93 _ = testServer.WaitRequests(2)
94
95 c.Assert(err, IsNil)
96
97 testServer.ResponseMap(2, testutil.ResponseMap{
98 "/api/admin/edgeGateway/00000000-0000-0000-0000-000000000000": testutil.Response{200, nil, edgegatewayExample},
99 "/api/admin/edgeGateway/00000000-0000-0000-0000-000000000000/action/configureServices": testutil.Response{200, nil, taskExample},
100 })
101
102 _, err = edge.Remove1to1Mapping("10.0.0.1", "20.0.0.2")
103 _ = testServer.WaitRequests(2)
104
105 c.Assert(err, IsNil)
106
107 }
108
109 var edgegatewayqueryresultsExample = `
110 <QueryResultRecords xmlns="http://www.vmware.com/vcloud/v1.5" name="edgeGateway" page="1" pageSize="25" total="1" href="http://localhost:4444/api/admin/vdc/00000000-0000-0000-0000-000000000000/edgeGateways?page=1&amp;pageSize=25&amp;format=records" type="application/vnd.vmware.vcloud.query.records+xml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://10.6.32.3/api/v1.5/schema/master.xsd">
111 <Link rel="alternate" href="http://localhost:4444/api/admin/vdc/00000000-0000-0000-0000-000000000000/edgeGateways?page=1&amp;pageSize=25&amp;format=references" type="application/vnd.vmware.vcloud.query.references+xml"/>
112 <Link rel="alternate" href="http://localhost:4444/api/admin/vdc/00000000-0000-0000-0000-000000000000/edgeGateways?page=1&amp;pageSize=25&amp;format=idrecords" type="application/vnd.vmware.vcloud.query.idrecords+xml"/>
113 <EdgeGatewayRecord gatewayStatus="READY" haStatus="UP" isBusy="false" name="M916272752-5793" numberOfExtNetworks="1" numberOfOrgNetworks="2" vdc="http://localhost:4444/api/vdc/00000000-0000-0000-0000-000000000000" href="http://localhost:4444/api/admin/edgeGateway/00000000-0000-0000-0000-000000000000" isSyslogServerSettingInSync="true" taskStatus="success" taskOperation="networkConfigureEdgeGatewayServices" task="http://localhost:4444/api/task/eca0d70f-36e0-428a-93c2-311b792f3326" taskDetails=" "/>
114 </QueryResultRecords>
115 `
116
117 var edgegatewayExample = `
118 <EdgeGateway xmlns="http://www.vmware.com/vcloud/v1.5" status="1" name="M916272752-5793" id="urn:vcloud:gateway:00000000-0000-0000-0000-000000000000" href="http://localhost:4444/api/admin/edgeGateway/00000000-0000-0000-0000-000000000000" type="application/vnd.vmware.admin.edgeGateway+xml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.vmware.com/vcloud/v1.5 http://10.6.32.3/api/v1.5/schema/master.xsd">
119 <Link rel="up" href="http://localhost:4444/api/vdc/214cd6b2-3f7a-4ee5-9b0a-52b4001a4a84" type="application/vnd.vmware.vcloud.vdc+xml"/>
120 <Link rel="edgeGateway:redeploy" href="http://localhost:4444/api/admin/edgeGateway/00000000-0000-0000-0000-000000000000/action/redeploy"/>
121 <Link rel="edgeGateway:configureServices" href="http://localhost:4444/api/admin/edgeGateway/00000000-0000-0000-0000-000000000000/action/configureServices" type="application/vnd.vmware.admin.edgeGatewayServiceConfiguration+xml"/>
122 <Link rel="edgeGateway:reapplyServices" href="http://localhost:4444/api/admin/edgeGateway/00000000-0000-0000-0000-000000000000/action/reapplyServices"/>
123 <Link rel="edgeGateway:syncSyslogSettings" href="http://localhost:4444/api/admin/edgeGateway/00000000-0000-0000-0000-000000000000/action/syncSyslogServerSettings"/>
124 <Configuration>
125 <GatewayBackingConfig>compact</GatewayBackingConfig>
126 <GatewayInterfaces>
127 <GatewayInterface>
128 <Name>JGray Network</Name>
129 <DisplayName>JGray Network</DisplayName>
130 <Network href="http://localhost:4444/api/admin/network/32e903a4-c726-497f-9ec7-e4a43b58bdbc" name="JGray Network" type="application/vnd.vmware.admin.network+xml"/>
131 <InterfaceType>internal</InterfaceType>
132 <SubnetParticipation>
133 <Gateway>192.168.108.1</Gateway>
134 <Netmask>255.255.255.0</Netmask>
135 <IpAddress>192.168.108.1</IpAddress>
136 </SubnetParticipation>
137 <ApplyRateLimit>false</ApplyRateLimit>
138 <UseForDefaultRoute>false</UseForDefaultRoute>
139 </GatewayInterface>
140 <GatewayInterface>
141 <Name>M916272752-5793-default-routed</Name>
142 <DisplayName>M916272752-5793-default-routed</DisplayName>
143 <Network href="http://localhost:4444/api/admin/network/cb0f4c9e-1a46-49d4-9fcb-d228000a6bc1" name="M916272752-5793-default-routed" type="application/vnd.vmware.admin.network+xml"/>
144 <InterfaceType>internal</InterfaceType>
145 <SubnetParticipation>
146 <Gateway>192.168.109.1</Gateway>
147 <Netmask>255.255.255.0</Netmask>
148 <IpAddress>192.168.109.1</IpAddress>
149 </SubnetParticipation>
150 <ApplyRateLimit>false</ApplyRateLimit>
151 <UseForDefaultRoute>false</UseForDefaultRoute>
152 </GatewayInterface>
153 <GatewayInterface>
154 <Name>d2p3-ext</Name>
155 <DisplayName>d2p3-ext</DisplayName>
156 <Network href="http://localhost:4444/api/admin/network/6254f107-9876-4d03-986f-8bec7a4bcb3f" name="d2p3-ext" type="application/vnd.vmware.admin.network+xml"/>
157 <InterfaceType>uplink</InterfaceType>
158 <SubnetParticipation>
159 <Gateway>23.92.224.1</Gateway>
160 <Netmask>255.255.254.0</Netmask>
161 <IpAddress>23.92.225.51</IpAddress>
162 <IpRanges>
163 <IpRange>
164 <StartAddress>23.92.225.73</StartAddress>
165 <EndAddress>23.92.225.75</EndAddress>
166 </IpRange>
167 <IpRange>
168 <StartAddress>23.92.225.27</StartAddress>
169 <EndAddress>23.92.225.27</EndAddress>
170 </IpRange>
171 <IpRange>
172 <StartAddress>23.92.225.11</StartAddress>
173 <EndAddress>23.92.225.11</EndAddress>
174 </IpRange>
175 <IpRange>
176 <StartAddress>23.92.225.54</StartAddress>
177 <EndAddress>23.92.225.54</EndAddress>
178 </IpRange>
179 <IpRange>
180 <StartAddress>23.92.224.34</StartAddress>
181 <EndAddress>23.92.224.34</EndAddress>
182 </IpRange>
183 <IpRange>
184 <StartAddress>23.92.225.5</StartAddress>
185 <EndAddress>23.92.225.5</EndAddress>
186 </IpRange>
187 <IpRange>
188 <StartAddress>23.92.225.34</StartAddress>
189 <EndAddress>23.92.225.34</EndAddress>
190 </IpRange>
191 <IpRange>
192 <StartAddress>23.92.224.255</StartAddress>
193 <EndAddress>23.92.224.255</EndAddress>
194 </IpRange>
195 <IpRange>
196 <StartAddress>23.92.225.49</StartAddress>
197 <EndAddress>23.92.225.51</EndAddress>
198 </IpRange>
199 <IpRange>
200 <StartAddress>23.92.225.62</StartAddress>
201 <EndAddress>23.92.225.62</EndAddress>
202 </IpRange>
203 <IpRange>
204 <StartAddress>23.92.225.43</StartAddress>
205 <EndAddress>23.92.225.43</EndAddress>
206 </IpRange>
207 <IpRange>
208 <StartAddress>23.92.225.30</StartAddress>
209 <EndAddress>23.92.225.30</EndAddress>
210 </IpRange>
211 </IpRanges>
212 </SubnetParticipation>
213 <ApplyRateLimit>true</ApplyRateLimit>
214 <InRateLimit>1024.0</InRateLimit>
215 <OutRateLimit>1024.0</OutRateLimit>
216 <UseForDefaultRoute>true</UseForDefaultRoute>
217 </GatewayInterface>
218 </GatewayInterfaces>
219 <EdgeGatewayServiceConfiguration>
220 <FirewallService>
221 <IsEnabled>true</IsEnabled>
222 <DefaultAction>drop</DefaultAction>
223 <LogDefaultAction>false</LogDefaultAction>
224 <FirewallRule>
225 <Id>1</Id>
226 <IsEnabled>true</IsEnabled>
227 <MatchOnTranslate>false</MatchOnTranslate>
228 <Description>ssh prd-001</Description>
229 <Policy>allow</Policy>
230 <Protocols>
231 <Tcp>true</Tcp>
232 </Protocols>
233 <Port>999</Port>
234 <DestinationPortRange>999</DestinationPortRange>
235 <DestinationIp>23.92.225.51</DestinationIp>
236 <SourcePort>-1</SourcePort>
237 <SourcePortRange>Any</SourcePortRange>
238 <SourceIp>60.241.110.111</SourceIp>
239 <EnableLogging>false</EnableLogging>
240 </FirewallRule>
241 <FirewallRule>
242 <Id>2</Id>
243 <IsEnabled>true</IsEnabled>
244 <MatchOnTranslate>false</MatchOnTranslate>
245 <Description>inet prd-001</Description>
246 <Policy>allow</Policy>
247 <Protocols>
248 <Any>true</Any>
249 </Protocols>
250 <Port>-1</Port>
251 <DestinationPortRange>Any</DestinationPortRange>
252 <DestinationIp>Any</DestinationIp>
253 <SourcePort>-1</SourcePort>
254 <SourcePortRange>Any</SourcePortRange>
255 <SourceIp>192.168.109.8</SourceIp>
256 <EnableLogging>false</EnableLogging>
257 </FirewallRule>
258 <FirewallRule>
259 <Id>3</Id>
260 <IsEnabled>true</IsEnabled>
261 <MatchOnTranslate>false</MatchOnTranslate>
262 <Description>suppah megah rulez creati0nz</Description>
263 <Policy>allow</Policy>
264 <Protocols>
265 <Any>true</Any>
266 </Protocols>
267 <Port>-1</Port>
268 <DestinationPortRange>Any</DestinationPortRange>
269 <DestinationIp>23.92.224.255</DestinationIp>
270 <SourcePort>-1</SourcePort>
271 <SourcePortRange>Any</SourcePortRange>
272 <SourceIp>Any</SourceIp>
273 <EnableLogging>false</EnableLogging>
274 </FirewallRule>
275 <FirewallRule>
276 <Id>4</Id>
277 <IsEnabled>true</IsEnabled>
278 <MatchOnTranslate>false</MatchOnTranslate>
279 <Description>suppah megah rulez creati0nz</Description>
280 <Policy>allow</Policy>
281 <Protocols>
282 <Any>true</Any>
283 </Protocols>
284 <Port>-1</Port>
285 <DestinationPortRange>Any</DestinationPortRange>
286 <DestinationIp>Any</DestinationIp>
287 <SourcePort>-1</SourcePort>
288 <SourcePortRange>Any</SourcePortRange>
289 <SourceIp>192.168.109.3</SourceIp>
290 <EnableLogging>false</EnableLogging>
291 </FirewallRule>
292 </FirewallService>
293 <NatService>
294 <IsEnabled>false</IsEnabled>
295 <NatRule>
296 <RuleType>DNAT</RuleType>
297 <IsEnabled>true</IsEnabled>
298 <Id>65537</Id>
299 <GatewayNatRule>
300 <Interface href="http://localhost:4444/api/admin/network/6254f107-9876-4d03-986f-8bec7a4bcb3f" name="d2p3-ext" type="application/vnd.vmware.admin.network+xml"/>
301 <OriginalIp>23.92.225.51</OriginalIp>
302 <OriginalPort>999</OriginalPort>
303 <TranslatedIp>192.168.109.8</TranslatedIp>
304 <TranslatedPort>22</TranslatedPort>
305 <Protocol>Tcp</Protocol>
306 </GatewayNatRule>
307 </NatRule>
308 <NatRule>
309 <RuleType>SNAT</RuleType>
310 <IsEnabled>true</IsEnabled>
311 <Id>65538</Id>
312 <GatewayNatRule>
313 <Interface href="http://localhost:4444/api/admin/network/6254f107-9876-4d03-986f-8bec7a4bcb3f" name="d2p3-ext" type="application/vnd.vmware.admin.network+xml"/>
314 <OriginalIp>192.168.109.8</OriginalIp>
315 <TranslatedIp>23.92.225.51</TranslatedIp>
316 </GatewayNatRule>
317 </NatRule>
318 <NatRule>
319 <RuleType>SNAT</RuleType>
320 <IsEnabled>true</IsEnabled>
321 <Id>65539</Id>
322 <GatewayNatRule>
323 <Interface href="http://localhost:4444/api/admin/network/6254f107-9876-4d03-986f-8bec7a4bcb3f" name="d2p3-ext" type="application/vnd.vmware.admin.network+xml"/>
324 <OriginalIp>192.168.109.3</OriginalIp>
325 <TranslatedIp>23.92.224.255</TranslatedIp>
326 </GatewayNatRule>
327 </NatRule>
328 <NatRule>
329 <RuleType>DNAT</RuleType>
330 <IsEnabled>true</IsEnabled>
331 <Id>65540</Id>
332 <GatewayNatRule>
333 <Interface href="http://localhost:4444/api/admin/network/6254f107-9876-4d03-986f-8bec7a4bcb3f" name="d2p3-ext" type="application/vnd.vmware.admin.network+xml"/>
334 <OriginalIp>23.92.224.255</OriginalIp>
335 <OriginalPort>any</OriginalPort>
336 <TranslatedIp>192.168.109.3</TranslatedIp>
337 <TranslatedPort>any</TranslatedPort>
338 <Protocol>any</Protocol>
339 </GatewayNatRule>
340 </NatRule>
341 </NatService>
342 <GatewayIpsecVpnService>
343 <IsEnabled>true</IsEnabled>
344 <Tunnel>
345 <Name>Test VPN Alpha</Name>
346 <Description>For OC Pod Testing</Description>
347 <IpsecVpnThirdPartyPeer>
348 <PeerId>192.168.110.99</PeerId>
349 </IpsecVpnThirdPartyPeer>
350 <PeerIpAddress>64.184.133.62</PeerIpAddress>
351 <PeerId>192.168.110.99</PeerId>
352 <LocalIpAddress>23.92.225.51</LocalIpAddress>
353 <LocalId>23.92.225.51</LocalId>
354 <LocalSubnet>
355 <Name>M916272752-5793-default-routed</Name>
356 <Gateway>192.168.109.1</Gateway>
357 <Netmask>255.255.255.0</Netmask>
358 </LocalSubnet>
359 <PeerSubnet>
360 <Name>192.168.120.0/24</Name>
361 <Gateway>192.168.120.0</Gateway>
362 <Netmask>255.255.255.0</Netmask>
363 </PeerSubnet>
364 <SharedSecret>Blah1Blah2Blah3Blah1Blah2Blah3Blah1Blah2Blah3</SharedSecret>
365 <SharedSecretEncrypted>false</SharedSecretEncrypted>
366 <EncryptionProtocol>AES256</EncryptionProtocol>
367 <Mtu>1500</Mtu>
368 <IsEnabled>true</IsEnabled>
369 <IsOperational>false</IsOperational>
370 </Tunnel>
371 <Tunnel>
372 <Name>JGray VPN</Name>
373 <IpsecVpnThirdPartyPeer>
374 <PeerId>67.172.148.74</PeerId>
375 </IpsecVpnThirdPartyPeer>
376 <PeerIpAddress>67.172.148.74</PeerIpAddress>
377 <PeerId>67.172.148.74</PeerId>
378 <LocalIpAddress>23.92.225.51</LocalIpAddress>
379 <LocalId>23.92.225.51</LocalId>
380 <LocalSubnet>
381 <Name>JGray Network</Name>
382 <Gateway>192.168.108.1</Gateway>
383 <Netmask>255.255.255.0</Netmask>
384 </LocalSubnet>
385 <PeerSubnet>
386 <Name>192.168.1.0/24</Name>
387 <Gateway>192.168.1.0</Gateway>
388 <Netmask>255.255.255.0</Netmask>
389 </PeerSubnet>
390 <SharedSecret>fM7puHkGbg6tqpd4jKNhBo45mbs8fw3yapgt3H7f97a2jrkLyYjP9eSH4oGwps7u</SharedSecret>
391 <SharedSecretEncrypted>false</SharedSecretEncrypted>
392 <EncryptionProtocol>AES256</EncryptionProtocol>
393 <Mtu>1500</Mtu>
394 <IsEnabled>false</IsEnabled>
395 <IsOperational>false</IsOperational>
396 </Tunnel>
397 </GatewayIpsecVpnService>
398 <StaticRoutingService>
399 <IsEnabled>false</IsEnabled>
400 </StaticRoutingService>
401 <LoadBalancerService>
402 <IsEnabled>false</IsEnabled>
403 </LoadBalancerService>
404 </EdgeGatewayServiceConfiguration>
405 <HaEnabled>true</HaEnabled>
406 <UseDefaultRouteForDnsRelay>true</UseDefaultRouteForDnsRelay>
407 </Configuration>
408 </EdgeGateway>
409 `