forked from apache/cloudstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_vpc_network.py
More file actions
2758 lines (2486 loc) · 97.9 KB
/
test_vpc_network.py
File metadata and controls
2758 lines (2486 loc) · 97.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
""" Component tests for VPC network functionality - with and without Netscaler (Netscaler tests will be skipped if Netscaler configuration fails)
"""
# Import Local Modules
from nose.plugins.attrib import attr
from marvin.cloudstackTestCase import cloudstackTestCase
import unittest
from marvin.cloudstackAPI import startVirtualMachine, stopVirtualMachine
from marvin.lib.utils import cleanup_resources, validateList
from marvin.lib.base import (VirtualMachine,
ServiceOffering,
Account,
NATRule,
NetworkOffering,
Network,
VPC,
VpcOffering,
LoadBalancerRule,
Router,
StaticNATRule,
NetworkACL,
PublicIPAddress)
from marvin.lib.common import (get_zone,
get_domain,
get_template,
wait_for_cleanup,
add_netscaler,
list_networks,
verifyRouterState)
# For more info on ddt refer to
# http://ddt.readthedocs.org/en/latest/api.html#module-ddt
from ddt import ddt, data
import time
from marvin.codes import PASS
class Services:
"""Test VPC network services
"""
def __init__(self):
self.services = {
"account": {
"email": "test@test.com",
"firstname": "Test",
"lastname": "User",
"username": "test",
# Random characters are appended for unique
# username
"password": "password",
},
"service_offering": {
"name": "Tiny Instance",
"displaytext": "Tiny Instance",
"cpunumber": 1,
"cpuspeed": 100,
"memory": 128,
},
"network_offering": {
"name": 'VPC Network offering',
"displaytext": 'VPC Network off',
"guestiptype": 'Isolated',
"supportedservices": 'Vpn,Dhcp,Dns,SourceNat,PortForwarding,Lb,UserData,StaticNat,NetworkACL',
"traffictype": 'GUEST',
"availability": 'Optional',
"useVpc": 'on',
"serviceProviderList": {
"Vpn": 'VpcVirtualRouter',
"Dhcp": 'VpcVirtualRouter',
"Dns": 'VpcVirtualRouter',
"SourceNat": 'VpcVirtualRouter',
"PortForwarding": 'VpcVirtualRouter',
"Lb": 'VpcVirtualRouter',
"UserData": 'VpcVirtualRouter',
"StaticNat": 'VpcVirtualRouter',
"NetworkACL": 'VpcVirtualRouter'
},
"serviceCapabilityList": {
"SourceNat": {"SupportedSourceNatTypes": "peraccount"},
},
},
# Offering that uses Netscaler as provider for LB inside VPC,
# dedicated = false
"network_off_netscaler": {
"name": 'Network offering-netscaler',
"displaytext": 'Network offering-netscaler',
"guestiptype": 'Isolated',
"supportedservices": 'Dhcp,Dns,SourceNat,PortForwarding,Vpn,Lb,UserData,StaticNat',
"traffictype": 'GUEST',
"availability": 'Optional',
"useVpc": 'on',
"serviceProviderList": {
"Dhcp": 'VpcVirtualRouter',
"Dns": 'VpcVirtualRouter',
"SourceNat": 'VpcVirtualRouter',
"PortForwarding": 'VpcVirtualRouter',
"Vpn": 'VpcVirtualRouter',
"Lb": 'Netscaler',
"UserData": 'VpcVirtualRouter',
"StaticNat": 'VpcVirtualRouter',
},
"serviceCapabilityList": {
"SourceNat": {"SupportedSourceNatTypes": "peraccount"},
},
},
# Offering that uses Netscaler as provider for LB in VPC, dedicated = True
# This offering is required for the tests that use Netscaler as external LB provider in VPC
"network_offering_vpcns": {
"name": 'VPC Network offering',
"displaytext": 'VPC Network off',
"guestiptype": 'Isolated',
"supportedservices": 'Vpn,Dhcp,Dns,SourceNat,PortForwarding,Lb,UserData,StaticNat,NetworkACL',
"traffictype": 'GUEST',
"availability": 'Optional',
"useVpc": 'on',
"serviceProviderList": {
"Vpn": 'VpcVirtualRouter',
"Dhcp": 'VpcVirtualRouter',
"Dns": 'VpcVirtualRouter',
"SourceNat": 'VpcVirtualRouter',
"PortForwarding": 'VpcVirtualRouter',
"Lb": 'Netscaler',
"UserData": 'VpcVirtualRouter',
"StaticNat": 'VpcVirtualRouter',
"NetworkACL": 'VpcVirtualRouter'
},
"serviceCapabilityList": {
"SourceNat": {
"SupportedSourceNatTypes": "peraccount"
},
"lb": {
"SupportedLbIsolation": "dedicated"
},
},
},
"network_off_shared": {
"name": 'Shared Network offering',
"displaytext": 'Shared Network offering',
"guestiptype": 'Shared',
"traffictype": 'GUEST',
"availability": 'Optional',
"useVpc": 'on',
"specifyIpRanges": True,
"specifyVlan": True
},
"vpc_offering": {
"name": 'VPC off',
"displaytext": 'VPC off',
"supportedservices": 'Dhcp,Dns,SourceNat,PortForwarding,Vpn,Lb,UserData,StaticNat',
},
"vpc": {
"name": "TestVPC",
"displaytext": "TestVPC",
"cidr": '10.0.0.1/24'
},
# Netscaler should be added as a dedicated device for it to work as external LB provider in VPC
"netscaler": {
"ipaddress": '10.102.192.50',
"username": 'nsroot',
"password": 'nsroot',
"networkdevicetype": 'NetscalerVPXLoadBalancer',
"publicinterface": '1/3',
"privateinterface": '1/4',
"numretries": 2,
"lbdevicededicated": True,
"lbdevicecapacity": 50,
"port": 22,
},
"network": {
"name": "Test Network",
"displaytext": "Test Network",
"netmask": '255.255.255.0'
},
"lbrule": {
"name": "SSH",
"alg": "leastconn",
# Algorithm used for load balancing
"privateport": 22,
"publicport": 2222,
"openfirewall": False,
"startport": 22,
"endport": 2222,
"protocol": "TCP",
"cidrlist": '0.0.0.0/0',
},
"natrule": {
"privateport": 22,
"publicport": 22,
"startport": 22,
"endport": 22,
"protocol": "TCP",
"cidrlist": '0.0.0.0/0',
},
"fw_rule": {
"startport": 1,
"endport": 6000,
"cidr": '0.0.0.0/0',
# Any network (For creating FW rule)
"protocol": "TCP"
},
"icmp_rule": {
"icmptype": -1,
"icmpcode": -1,
"cidrlist": '0.0.0.0/0',
"protocol": "ICMP"
},
"virtual_machine": {
"displayname": "Test VM",
"username": "root",
"password": "password",
"ssh_port": 22,
"hypervisor": 'XenServer',
# Hypervisor type should be same as
# hypervisor type of cluster
"privateport": 22,
"publicport": 22,
"protocol": 'TCP',
},
"ostype": 'CentOS 5.3 (64-bit)',
# Cent OS 5.3 (64 bit)
"sleep": 60,
"timeout": 10,
}
@ddt
class TestVPCNetwork(cloudstackTestCase):
@classmethod
def setUpClass(cls):
cls.testClient = super(TestVPCNetwork, cls).getClsTestClient()
cls.api_client = cls.testClient.getApiClient()
cls.services = Services().services
# Added an attribute to track if Netscaler addition was successful.
# Value is checked in tests and if not configured, Netscaler tests will
# be skipped
cls.ns_configured = False
# Get Zone, Domain and templates
cls.domain = get_domain(cls.api_client)
cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests())
cls.template = get_template(
cls.api_client,
cls.zone.id,
cls.services["ostype"]
)
cls.services["virtual_machine"]["zoneid"] = cls.zone.id
cls.services["virtual_machine"]["template"] = cls.template.id
cls._cleanup = []
cls.service_offering = ServiceOffering.create(
cls.api_client,
cls.services["service_offering"]
)
cls._cleanup.append(cls.service_offering)
# Configure Netscaler device
# If configuration succeeds, set ns_configured to True so that
# Netscaler tests are executed
try:
cls.netscaler = add_netscaler(
cls.api_client,
cls.zone.id,
cls.services["netscaler"])
cls._cleanup.append(cls.netscaler)
cls.debug("Netscaler configured")
cls.ns_configured = True
except Exception as e:
cls.debug("Warning: Couldn't configure Netscaler: %s" % e)
return
@classmethod
def tearDownClass(cls):
super(TestVPCNetwork, cls).tearDownClass()
def setUp(self):
self.services = Services().services
self.apiclient = self.testClient.getApiClient()
self.dbclient = self.testClient.getDbConnection()
self.cleanup = []
self.account = Account.create(
self.apiclient,
self.services["account"],
admin=True,
domainid=self.domain.id
)
self.cleanup.append(self.account)
return
def tearDown(self):
super(TestVPCNetwork, self).tearDown()
def validate_vpc_offering(self, vpc_offering):
"""Validates the VPC offering"""
self.debug("Check if the VPC offering is created successfully?")
vpc_offs = VpcOffering.list(
self.apiclient,
id=vpc_offering.id
)
self.assertEqual(
isinstance(vpc_offs, list),
True,
"List VPC offerings should return a valid list"
)
self.assertEqual(
vpc_offering.name,
vpc_offs[0].name,
"Name of the VPC offering should match with listVPCOff data"
)
self.debug(
"VPC offering is created successfully - %s" %
vpc_offering.name)
return
def validate_vpc_network(self, network, state=None):
"""Validates the VPC network"""
self.debug("Check if the VPC network is created successfully?")
vpc_networks = VPC.list(
self.apiclient,
id=network.id
)
self.assertEqual(
isinstance(vpc_networks, list),
True,
"List VPC network should return a valid list"
)
self.assertEqual(
network.name,
vpc_networks[0].name,
"Name of the VPC network should match with listVPC data"
)
if state:
self.assertEqual(
vpc_networks[0].state,
state,
"VPC state should be '%s'" % state
)
self.debug("VPC network validated - %s" % network.name)
return
@data("network_offering", "network_offering_vpcns")
@attr(tags=["advanced", "intervlan"])
def test_01_create_network(self, value):
""" Test create network in VPC
# Validate the following
# 1. Create a VPC using Default Offering
# 2. Create a network offering with guest type=Isolated" that has
# all of supported Services(Vpn,dhcpdns,UserData, SourceNat,Static
# NAT,LB and PF,LB,NetworkAcl ) provided by VPCVR and conserve
# mode is ON
# 3. Create a network tier using the network offering created in
# step 2 as part of this VPC.
# 4. Validate Network is created
# 5. Repeat test for offering which has Netscaler as external LB
# provider
"""
if (value == "network_offering_vpcns" and not self.ns_configured):
self.skipTest('Netscaler not configured: skipping test')
if (value == "network_offering"):
vpc_off_list = VpcOffering.list(
self.apiclient,
name='Default VPC offering',
listall=True
)
else:
vpc_off_list = VpcOffering.list(
self.apiclient,
name='Default VPC offering with Netscaler',
listall=True
)
vpc_off = vpc_off_list[0]
self.debug("Creating a VPC with offering: %s" % vpc_off.id)
self.services["vpc"]["cidr"] = '10.1.1.1/16'
vpc = VPC.create(
self.apiclient,
self.services["vpc"],
vpcofferingid=vpc_off.id,
zoneid=self.zone.id,
account=self.account.name,
domainid=self.account.domainid
)
self.cleanup.append(vpc)
self.validate_vpc_network(vpc)
self.network_offering = NetworkOffering.create(
self.apiclient,
self.services[value],
conservemode=False
)
self.cleanup.append(self.network_offering)
self.network_offering.update(self.apiclient, state='Enabled')
# Creating network using the network offering created
self.debug("Creating network with network offering: %s" %
self.network_offering.id)
network = Network.create(
self.apiclient,
self.services["network"],
accountid=self.account.name,
domainid=self.account.domainid,
networkofferingid=self.network_offering.id,
zoneid=self.zone.id,
gateway='10.1.1.1',
vpcid=vpc.id
)
self.cleanup.append(network)
self.debug("Created network with ID: %s" % network.id)
self.debug(
"Verifying list network response to check if network created?")
networks = Network.list(
self.apiclient,
id=network.id,
listall=True
)
self.assertEqual(
isinstance(networks, list),
True,
"List networks should return a valid response"
)
nw = networks[0]
self.assertEqual(
nw.networkofferingid,
self.network_offering.id,
"Network should be created from network offering - %s" %
self.network_offering.id
)
self.assertEqual(
nw.vpcid,
vpc.id,
"Network should be created in VPC: %s" % vpc.name
)
return
@data("network_offering", "network_offering_vpcns")
@attr(tags=["advanced", "intervlan"])
def test_02_create_network_fail(self, value):
""" Test create network in VPC mismatched services (Should fail)
# Validate the following
# 1. Create a VPC using Default VPC Offering
# 2. Create a network offering with guest type=Isolated" that has
# one of supported Services(Vpn,dhcpdns,UserData, Static
# NAT,LB and PF,LB,NetworkAcl ) provided by VPCVR, SourceNat by VR
# and conserve mode is ON
# 3. Create a network using the network offering created in step2 as
# part of this VPC.
# 4. Network creation should fail since SourceNat offered by VR
# instead of VPCVR
# 5. Repeat test for offering which has Netscaler as external LB
# provider
"""
if (value == "network_offering_vpcns" and not self.ns_configured):
self.skipTest('Netscaler not configured: skipping test')
if (value == "network_offering"):
vpc_off_list = VpcOffering.list(
self.apiclient,
name='Default VPC offering',
listall=True
)
else:
vpc_off_list = VpcOffering.list(
self.apiclient,
name='Default VPC offering with Netscaler',
listall=True
)
vpc_off = vpc_off_list[0]
self.debug("Creating a VPC with offering: %s" % vpc_off.id)
self.services["vpc"]["cidr"] = '10.1.1.1/16'
vpc = VPC.create(
self.apiclient,
self.services["vpc"],
vpcofferingid=vpc_off.id,
zoneid=self.zone.id,
account=self.account.name,
domainid=self.account.domainid
)
self.cleanup.append(vpc)
self.validate_vpc_network(vpc)
self.services[value]["serviceProviderList"] = {
"SourceNat": 'VirtualRouter', }
self.network_offering = NetworkOffering.create(
self.apiclient,
self.services[value],
conservemode=False
)
self.cleanup.append(self.network_offering)
self.network_offering.update(self.apiclient, state='Enabled')
# Creating network using the network offering created
self.debug("Creating network with network offering: %s" %
self.network_offering.id)
with self.assertRaises(Exception):
nw = Network.create(
self.apiclient,
self.services["network"],
accountid=self.account.name,
domainid=self.account.domainid,
networkofferingid=self.network_offering.id,
zoneid=self.zone.id,
gateway='10.1.1.1',
vpcid=vpc.id
)
self.cleanup.append(nw)
return
@data("network_offering", "network_offering_vpcns")
@attr(tags=["advanced", "intervlan"])
def test_04_create_multiple_networks_with_lb(self, value):
""" Test create multiple networks with LB service (Should fail)
# Validate the following
# 1. Create a VPC using Default Offering
# 2. Create a network offering with guest type=Isolated that has LB
# services Enabled and conserve mode is "ON".
# 3. Create a network using the network offering created in step2 as
# part of this VPC.
# 4. Create another network using the network offering created in
# step3 as part of this VPC
# 5. Create Network should fail
# 6. Repeat test for offering which has Netscaler as external LB
# provider
"""
self.skipTest('Skipping test due to CLOUDSTACK-8437')
if (value == "network_offering_vpcns" and not self.ns_configured):
self.skipTest('Netscaler not configured: skipping test')
if (value == "network_offering"):
vpc_off_list = VpcOffering.list(
self.apiclient,
name='Default VPC offering',
listall=True
)
else:
vpc_off_list = VpcOffering.list(
self.apiclient,
name='Default VPC offering with Netscaler',
listall=True
)
vpc_off = vpc_off_list[0]
self.debug("Creating a VPC with offering: %s" % vpc_off.id)
self.services["vpc"]["cidr"] = '10.1.1.1/16'
vpc = VPC.create(
self.apiclient,
self.services["vpc"],
vpcofferingid=vpc_off.id,
zoneid=self.zone.id,
account=self.account.name,
domainid=self.account.domainid
)
self.cleanup.append(vpc)
self.validate_vpc_network(vpc)
self.network_offering = NetworkOffering.create(
self.apiclient,
self.services[value],
conservemode=False
)
self.cleanup.append(self.network_offering)
self.network_offering.update(self.apiclient, state='Enabled')
# Creating network using the network offering created
self.debug("Creating network with network offering: %s" %
self.network_offering.id)
network = Network.create(
self.apiclient,
self.services["network"],
accountid=self.account.name,
domainid=self.account.domainid,
networkofferingid=self.network_offering.id,
zoneid=self.zone.id,
gateway='10.1.1.1',
vpcid=vpc.id
)
self.cleanup.append(network)
self.debug("Created network with ID: %s" % network.id)
self.debug(
"Verifying list network response to check if network created?")
networks = Network.list(
self.apiclient,
id=network.id,
listall=True
)
self.assertEqual(
isinstance(networks, list),
True,
"List networks should return a valid response"
)
nw = networks[0]
self.assertEqual(
nw.networkofferingid,
self.network_offering.id,
"Network should be created from network offering - %s" %
self.network_offering.id
)
self.assertEqual(
nw.vpcid,
vpc.id,
"Network should be created in VPC: %s" % vpc.name
)
self.debug("Creating another network in VPC: %s" % vpc.name)
with self.assertRaises(Exception):
nw = Network.create(
self.apiclient,
self.services["network"],
accountid=self.account.name,
domainid=self.account.domainid,
networkofferingid=self.network_offering.id,
zoneid=self.zone.id,
gateway='10.1.2.1',
vpcid=vpc.id
)
self.cleanup.append(nw)
self.debug(
"Network creation failed as network with LB service\
already exists")
return
@attr(tags=["intervlan"])
def test_05_create_network_ext_LB(self):
""" Test create network with external LB devices
# Validate the following
# 1.Create a VPC using Default Offering (Without Netscaler)
# 2. Create a network offering with guest type=Isolated that has LB
# service provided by netscaler and conserve mode is "ON".
# 3. Create a network using this network offering as part of this VPC.
# 4. Create Network should fail since it doesn't match the VPC offering
"""
vpc_off_list = VpcOffering.list(
self.apiclient,
name='Default VPC offering',
listall=True
)
vpc_off = vpc_off_list[0]
self.debug("Creating a VPC with offering: %s" % vpc_off.id)
self.services["vpc"]["cidr"] = '10.1.1.1/16'
vpc = VPC.create(
self.apiclient,
self.services["vpc"],
vpcofferingid=vpc_off.id,
zoneid=self.zone.id,
account=self.account.name,
domainid=self.account.domainid
)
self.cleanup.append(vpc)
self.validate_vpc_network(vpc)
self.network_offering = NetworkOffering.create(
self.apiclient,
self.services["network_offering_vpcns"],
conservemode=False
)
self.cleanup.append(self.network_offering)
self.network_offering.update(self.apiclient, state='Enabled')
# Creating network using the network offering created
self.debug("Creating network with network offering: %s" %
self.network_offering.id)
with self.assertRaises(Exception):
nw = Network.create(
self.apiclient,
self.services["network"],
accountid=self.account.name,
domainid=self.account.domainid,
networkofferingid=self.network_offering.id,
zoneid=self.zone.id,
gateway='10.1.1.1',
vpcid=vpc.id
)
self.cleanup.append(nw)
self.debug("Network creation failed")
return
@unittest.skip("skipped - RvR didn't support VPC currently ")
@attr(tags=["advanced", "intervlan", "NA"])
def test_06_create_network_with_rvr(self):
""" Test create network with redundant router capability
# Validate the following
# 1. Create VPC Offering by specifying all supported Services
# (Vpn,dhcpdns,UserData, SourceNat,Static NAT and PF,LB,NetworkAcl)
# 2. Create a VPC using the above VPC offering
# 3. Create a network offering with guest type=Isolated that has all
# services provided by VPC VR,conserver mode ""OFF"" and Redundant
# Router capability enabled.
# 4. Create a VPC using the above VPC offering.
# 5. Create a network using the network offering created in step2 as
# part of this VPC
"""
self.debug("Creating a VPC offering..")
vpc_off = VpcOffering.create(
self.apiclient,
self.services["vpc_offering"]
)
self.cleanup.append(vpc_off)
self.validate_vpc_offering(vpc_off)
self.debug("Enabling the VPC offering created")
vpc_off.update(self.apiclient, state='Enabled')
self.debug("creating a VPC network in the account: %s" %
self.account.name)
self.services["vpc"]["cidr"] = '10.1.1.1/16'
vpc = VPC.create(
self.apiclient,
self.services["vpc"],
vpcofferingid=vpc_off.id,
zoneid=self.zone.id,
account=self.account.name,
domainid=self.account.domainid
)
self.cleanup.append(vpc)
self.validate_vpc_network(vpc)
# Enable redundant router capability for the network offering
self.services["network"]["serviceCapabilityList"] = {
"SourceNat": {
"RedundantRouter": "true",
},
}
self.network_offering = NetworkOffering.create(
self.apiclient,
self.services["network_offering"],
conservemode=False
)
self.cleanup.append(self.network_offering)
self.network_offering.update(self.apiclient, state='Enabled')
# Creating network using the network offering created
self.debug("Creating network with network offering: %s" %
self.network_offering.id)
with self.assertRaises(Exception):
nw = Network.create(
self.apiclient,
self.services["network"],
accountid=self.account.name,
domainid=self.account.domainid,
networkofferingid=self.network_offering.id,
zoneid=self.zone.id,
gateway='10.1.2.1',
vpcid=vpc.id
)
self.cleanup.append(nw)
self.debug("Network creation failed")
return
@attr(tags=["advanced", "intervlan"], required_hardware="false")
def test_07_create_network_unsupported_services(self):
""" Test create network services not supported by VPC (Should fail)
# Validate the following
# 1. Create VPC Offering without LB service
# 2. Create a VPC using the above VPC offering
# 3. Create a network offering with guest type=Isolated that has all
# supported Services(Vpn,dhcpdns,UserData, SourceNat,Static NAT,LB
# and PF,LB,NetworkAcl ) provided by VPCVR and conserve mode is OFF
# 4. Create Network with the above offering
# 5. Create network fails since VPC offering doesn't support LB
"""
self.debug("Creating a VPC offering without LB service")
self.services["vpc_offering"][
"supportedservices"] = 'Dhcp,Dns,SourceNat,PortForwarding,Vpn,UserData,StaticNat'
vpc_off = VpcOffering.create(
self.apiclient,
self.services["vpc_offering"]
)
self.cleanup.append(vpc_off)
self.validate_vpc_offering(vpc_off)
self.debug("Enabling the VPC offering created")
vpc_off.update(self.apiclient, state='Enabled')
self.debug("creating a VPC network in the account: %s" %
self.account.name)
self.services["vpc"]["cidr"] = '10.1.1.1/16'
vpc = VPC.create(
self.apiclient,
self.services["vpc"],
vpcofferingid=vpc_off.id,
zoneid=self.zone.id,
account=self.account.name,
domainid=self.account.domainid
)
self.cleanup.append(vpc)
self.validate_vpc_network(vpc)
self.network_offering = NetworkOffering.create(
self.apiclient,
self.services["network_offering"],
conservemode=False
)
self.cleanup.append(self.network_offering)
self.network_offering.update(self.apiclient, state='Enabled')
# Creating network using the network offering created
self.debug("Creating network with network offering: %s" %
self.network_offering.id)
with self.assertRaises(Exception):
nw = Network.create(
self.apiclient,
self.services["network"],
accountid=self.account.name,
domainid=self.account.domainid,
networkofferingid=self.network_offering.id,
zoneid=self.zone.id,
gateway='10.1.2.1',
vpcid=vpc.id
)
self.cleanup.append(nw)
self.debug("Network creation failed as VPC doesn't have LB service")
return
@attr(tags=["advanced", "intervlan"], required_hardware="false")
def test_08_create_network_without_sourceNAT(self):
""" Test create network without sourceNAT service in VPC (should fail)
# Validate the following
# 1. Create VPC Offering by specifying supported Services-
# Vpn,dhcpdns,UserData, SourceNat,Static NAT and PF,LB,NetworkAcl)
# with out including LB services.
# 2. Create a VPC using the above VPC offering
# 3. Create a network offering with guest type=Isolated that does not
# have SourceNAT services enabled
# 4. Create a VPC using the above VPC offering
# 5. Create a network using the network offering created in step2 as
# part of this VPC
"""
self.debug("Creating a VPC offering without LB service")
self.services["vpc_offering"][
"supportedservices"] = 'Dhcp,Dns,SourceNat,PortForwarding,UserData,StaticNat'
vpc_off = VpcOffering.create(
self.apiclient,
self.services["vpc_offering"]
)
self.cleanup.append(vpc_off)
self.validate_vpc_offering(vpc_off)
self.debug("Enabling the VPC offering created")
vpc_off.update(self.apiclient, state='Enabled')
self.debug("creating a VPC network in the account: %s" %
self.account.name)
self.services["vpc"]["cidr"] = '10.1.1.1/16'
vpc = VPC.create(
self.apiclient,
self.services["vpc"],
vpcofferingid=vpc_off.id,
zoneid=self.zone.id,
account=self.account.name,
domainid=self.account.domainid
)
self.cleanup.append(vpc)
self.validate_vpc_network(vpc)
self.debug("Creating network offering without SourceNAT service")
self.services["network_offering"][
"supportedservices"] = 'Dhcp,Dns,PortForwarding,Lb,UserData,StaticNat,NetworkACL'
self.services["network_offering"]["serviceProviderList"] = {
"Dhcp": 'VpcVirtualRouter',
"Dns": 'VpcVirtualRouter',
"PortForwarding": 'VpcVirtualRouter',
"Lb": 'VpcVirtualRouter',
"UserData": 'VpcVirtualRouter',
"StaticNat": 'VpcVirtualRouter',
"NetworkACL": 'VpcVirtualRouter'
}
self.debug("Creating network offering without SourceNAT")
with self.assertRaises(Exception):
nw = NetworkOffering.create(
self.apiclient,
self.services["network_offering"],
conservemode=False
)
self.cleanup.append(nw)
self.debug("Network creation failed as VPC doesn't have LB service")
return
@data("network_off_shared", "network_offering_vpcns")
@attr(tags=["advanced", "intervlan"])
def test_09_create_network_shared_nwoff(self, value):
""" Test create network with shared network offering
# Validate the following
# 1. Create VPC Offering using Default Offering
# 2. Create a VPC using the above VPC offering
# 3. Create a network offering with guest type=shared
# 4. Create a network using the network offering created
# in step3 as part of this VPC
# 5. Create network fails since it using shared offering
# 6. Repeat test for offering which has Netscaler as external LB
# provider
"""
if (value == "network_offering_vpcns" and not self.ns_configured):
self.skipTest('Netscaler not configured: skipping test')
if (value == "network_off_shared"):
vpc_off_list = VpcOffering.list(
self.apiclient,
name='Default VPC offering',
listall=True
)
else:
vpc_off_list = VpcOffering.list(
self.apiclient,
name='Default VPC offering with Netscaler',
listall=True
)
vpc_off = vpc_off_list[0]
self.debug("Creating a VPC with offering: %s" % vpc_off.id)
self.services["vpc"]["cidr"] = '10.1.1.1/16'
vpc = VPC.create(
self.apiclient,
self.services["vpc"],
vpcofferingid=vpc_off.id,
zoneid=self.zone.id,
account=self.account.name,
domainid=self.account.domainid
)
self.cleanup.append(vpc)
self.validate_vpc_network(vpc)
self.debug("Creating network offering with guesttype=shared")
self.network_offering = NetworkOffering.create(
self.apiclient,
self.services["network_off_shared"],
conservemode=False
)
self.cleanup.append(self.network_offering)
self.network_offering.update(self.apiclient, state='Enabled')
# Creating network using the network offering created
self.debug(
"Creating network with network offering without SourceNAT: %s" %
self.network_offering.id)
with self.assertRaises(Exception):
nw = Network.create(
self.apiclient,
self.services["network"],
accountid=self.account.name,
domainid=self.account.domainid,
networkofferingid=self.network_offering.id,
zoneid=self.zone.id,
gateway='10.1.1.1',
vpcid=vpc.id
)
self.cleanup.append(nw)
self.debug("Network creation failed")
return
@data("network_offering", "network_offering_vpcns")
@attr(tags=["advanced", "intervlan"])
def test_10_create_network_with_conserve_mode(self, value):
""" Test create network with conserve mode ON
# Validate the following