Skip to content

Commit 8f15fc1

Browse files
Gaurav AradhyeGirish Shilamkar
authored andcommitted
CLOUDSTACK-5636: Fixed issue 'Failed to upgrade network offering' in test_vpc_network test suite
1 parent 88ce5b8 commit 8f15fc1

1 file changed

Lines changed: 96 additions & 67 deletions

File tree

‎test/integration/component/test_vpc_network.py‎

Lines changed: 96 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,33 @@
1818
""" Component tests for VPC network functionality - with and without Netscaler (Netscaler tests will be skipped if Netscaler configuration fails)
1919
"""
2020
#Import Local Modules
21-
import marvin
2221
from nose.plugins.attrib import attr
23-
from marvin.cloudstackTestCase import *
24-
from marvin.cloudstackAPI import *
25-
from marvin.integration.lib.utils import *
26-
from marvin.integration.lib.base import *
27-
from marvin.integration.lib.common import *
28-
from marvin.sshClient import SshClient
29-
import datetime
22+
from marvin.cloudstackTestCase import cloudstackTestCase, unittest
23+
from marvin.cloudstackAPI import startVirtualMachine, stopVirtualMachine
24+
from marvin.integration.lib.utils import cleanup_resources, validateList
25+
from marvin.integration.lib.base import (VirtualMachine,
26+
ServiceOffering,
27+
Account,
28+
NATRule,
29+
NetworkOffering,
30+
Network,
31+
VPC,
32+
VpcOffering,
33+
LoadBalancerRule,
34+
Router,
35+
StaticNATRule,
36+
NetworkACL,
37+
PublicIPAddress)
38+
from marvin.integration.lib.common import (get_zone,
39+
get_domain,
40+
get_template,
41+
wait_for_cleanup,
42+
add_netscaler,
43+
list_networks)
3044
# For more info on ddt refer to http://ddt.readthedocs.org/en/latest/api.html#module-ddt
3145
from ddt import ddt, data
46+
import time
47+
from marvin.codes import PASS
3248

3349
class Services:
3450
"""Test VPC network services
@@ -75,7 +91,7 @@ def __init__(self):
7591
"SourceNat": {"SupportedSourceNatTypes": "peraccount"},
7692
},
7793
},
78-
# Offering that uses Netscaler as provider for LB inside VPC, dedicated = false
94+
# Offering that uses Netscaler as provider for LB inside VPC, dedicated = false
7995
"network_off_netscaler": {
8096
"name": 'Network offering-netscaler',
8197
"displaytext": 'Network offering-netscaler',
@@ -98,7 +114,7 @@ def __init__(self):
98114
"SourceNat": {"SupportedSourceNatTypes": "peraccount"},
99115
},
100116
},
101-
# Offering that uses Netscaler as provider for LB in VPC, dedicated = True
117+
# Offering that uses Netscaler as provider for LB in VPC, dedicated = True
102118
# This offering is required for the tests that use Netscaler as external LB provider in VPC
103119
"network_offering_vpcns": {
104120
"name": 'VPC Network offering',
@@ -228,8 +244,8 @@ def setUpClass(cls):
228244
cls
229245
).getClsTestClient().getApiClient()
230246
cls.services = Services().services
231-
# Added an attribute to track if Netscaler addition was successful.
232-
# Value is checked in tests and if not configured, Netscaler tests will be skipped
247+
# Added an attribute to track if Netscaler addition was successful.
248+
# Value is checked in tests and if not configured, Netscaler tests will be skipped
233249
cls.ns_configured = False
234250
# Get Zone, Domain and templates
235251
cls.domain = get_domain(cls.api_client, cls.services)
@@ -249,7 +265,7 @@ def setUpClass(cls):
249265
)
250266
cls._cleanup.append(cls.service_offering)
251267
# Configure Netscaler device
252-
# If configuration succeeds, set ns_configured to True so that Netscaler tests are executed
268+
# If configuration succeeds, set ns_configured to True so that Netscaler tests are executed
253269
try:
254270
cls.netscaler = add_netscaler(cls.api_client, cls.zone.id, cls.services["netscaler"])
255271
cls._cleanup.append(cls.netscaler)
@@ -339,7 +355,7 @@ def validate_vpc_network(self, network, state=None):
339355
)
340356
self.debug("VPC network validated - %s" % network.name)
341357
return
342-
358+
343359
@data("network_offering", "network_offering_vpcns")
344360
@attr(tags=["advanced", "intervlan"])
345361
def test_01_create_network(self, value):
@@ -441,17 +457,17 @@ def test_01_create_network(self, value):
441457
def test_02_create_network_fail(self, value):
442458
""" Test create network in VPC mismatched services (Should fail)
443459
"""
444-
460+
445461
# Validate the following
446-
# 1. Create a VPC using Default VPC Offering
462+
# 1. Create a VPC using Default VPC Offering
447463
# 2. Create a network offering with guest type=Isolated" that has
448464
# one of supported Services(Vpn,dhcpdns,UserData, Static
449-
# NAT,LB and PF,LB,NetworkAcl ) provided by VPCVR, SourceNat by VR
465+
# NAT,LB and PF,LB,NetworkAcl ) provided by VPCVR, SourceNat by VR
450466
# and conserve mode is ON
451467
# 3. Create a network using the network offering created in step2 as
452468
# part of this VPC.
453469
# 4. Network creation should fail since SourceNat offered by VR instead of VPCVR
454-
# 5. Repeat test for offering which has Netscaler as external LB provider
470+
# 5. Repeat test for offering which has Netscaler as external LB provider
455471

456472
if (value == "network_offering_vpcns" and self.ns_configured == False):
457473
self.skipTest('Netscaler not configured: skipping test')
@@ -471,7 +487,7 @@ def test_02_create_network_fail(self, value):
471487
)
472488
vpc_off=vpc_off_list[0]
473489
self.debug("Creating a VPC with offering: %s" % vpc_off.id)
474-
490+
475491
self.services["vpc"]["cidr"] = '10.1.1.1/16'
476492
vpc = VPC.create(
477493
self.apiclient,
@@ -511,7 +527,7 @@ def test_02_create_network_fail(self, value):
511527
)
512528
return
513529

514-
@data("network_offering", "network_offering_vpcns")
530+
@data("network_offering", "network_offering_vpcns")
515531
@attr(tags=["advanced", "intervlan"])
516532
def test_04_create_multiple_networks_with_lb(self, value):
517533
""" Test create multiple networks with LB service (Should fail)
@@ -525,7 +541,7 @@ def test_04_create_multiple_networks_with_lb(self, value):
525541
# part of this VPC.
526542
# 4. Create another network using the network offering created in
527543
# step3 as part of this VPC
528-
# 5. Create Network should fail
544+
# 5. Create Network should fail
529545
# 6. Repeat test for offering which has Netscaler as external LB provider
530546
if (value == "network_offering_vpcns" and self.ns_configured == False):
531547
self.skipTest('Netscaler not configured: skipping test')
@@ -884,7 +900,7 @@ def test_08_create_network_without_sourceNAT(self):
884900
)
885901
self.debug("Network creation failed as VPC doesn't have LB service")
886902
return
887-
903+
888904
@data("network_off_shared", "network_offering_vpcns")
889905
@attr(tags=["advanced", "intervlan"])
890906
def test_09_create_network_shared_nwoff(self, value):
@@ -992,8 +1008,8 @@ def setUpClass(cls):
9921008
cls
9931009
).getClsTestClient().getApiClient()
9941010
cls.services = Services().services
995-
# Added an attribute to track if Netscaler addition was successful.
996-
# Value is checked in tests and if not configured, Netscaler tests will be skipped
1011+
# Added an attribute to track if Netscaler addition was successful.
1012+
# Value is checked in tests and if not configured, Netscaler tests will be skipped
9971013
cls.ns_configured = False
9981014
# Get Zone, Domain and templates
9991015
cls.domain = get_domain(cls.api_client, cls.services)
@@ -1013,7 +1029,7 @@ def setUpClass(cls):
10131029
)
10141030
cls._cleanup.append(cls.service_offering)
10151031
# Configure Netscaler device
1016-
# If configuration succeeds, set ns_configured to True so that Netscaler tests are executed
1032+
# If configuration succeeds, set ns_configured to True so that Netscaler tests are executed
10171033
try:
10181034
cls.netscaler = add_netscaler(cls.api_client, cls.zone.id, cls.services["netscaler"])
10191035
cls._cleanup.append(cls.netscaler)
@@ -1628,7 +1644,7 @@ def validate_vpc_network(self, network, state=None):
16281644
)
16291645
self.debug("VPC network validated - %s" % network.name)
16301646
return
1631-
1647+
16321648
@attr(tags=["advanced", "intervlan"])
16331649
def test_01_network_services_upgrade(self):
16341650
""" Test update Network that is part of a VPC to a network offering that has more services
@@ -1761,9 +1777,8 @@ def test_01_network_services_upgrade(self):
17611777
domainid=self.account.domainid
17621778
)
17631779

1764-
self.debug("Adding virtual machines %s and %s to LB rule" % (
1765-
vm_1.name, vm_2.name))
1766-
lb_rule.assign(self.apiclient, [vm_1, vm_2])
1780+
self.debug("Adding virtual machines %s to LB rule" % vm_1.name)
1781+
lb_rule.assign(self.apiclient, [vm_1])
17671782

17681783
self.debug("Associating public IP for network: %s" % network_1.name)
17691784
public_ip_2 = PublicIPAddress.create(
@@ -1813,22 +1828,22 @@ def test_01_network_services_upgrade(self):
18131828
)
18141829

18151830
self.debug("Adding NetwrokACl rules to make PF and LB accessible")
1816-
nwacl_lb = NetworkACL.create(
1817-
self.apiclient,
1818-
networkid=network_1.id,
1819-
services=self.services["lbrule"],
1820-
traffictype='Ingress'
1821-
)
1831+
NetworkACL.create(
1832+
self.apiclient,
1833+
networkid=network_1.id,
1834+
services=self.services["lbrule"],
1835+
traffictype='Ingress'
1836+
)
18221837

18231838
self.debug(
18241839
"Adding Egress rules to network %s to access internet" %
18251840
(network_1.name))
1826-
nwacl_internet_1 = NetworkACL.create(
1827-
self.apiclient,
1828-
networkid=network_1.id,
1829-
services=self.services["icmp_rule"],
1830-
traffictype='Egress'
1831-
)
1841+
NetworkACL.create(
1842+
self.apiclient,
1843+
networkid=network_1.id,
1844+
services=self.services["icmp_rule"],
1845+
traffictype='Egress'
1846+
)
18321847

18331848
self.debug("Checking if we can SSH into VM_1? - IP: %s" %
18341849
public_ip_1.ipaddress.ipaddress)
@@ -1899,15 +1914,15 @@ def test_01_network_services_upgrade(self):
18991914

19001915
self.debug("Creatinng NAT rule in network shall through exception?")
19011916
with self.assertRaises(Exception):
1902-
nat_rule = NATRule.create(
1903-
self.apiclient,
1904-
vm_1,
1905-
self.services["natrule"],
1906-
ipaddressid=public_ip_3.ipaddress.id,
1907-
openfirewall=False,
1908-
networkid=network_1.id,
1909-
vpcid=vpc.id
1910-
)
1917+
NATRule.create(
1918+
self.apiclient,
1919+
vm_1,
1920+
self.services["natrule"],
1921+
ipaddressid=public_ip_3.ipaddress.id,
1922+
openfirewall=False,
1923+
networkid=network_1.id,
1924+
vpcid=vpc.id
1925+
)
19111926
self.debug("Create NAT rule failed!")
19121927

19131928
self.debug(
@@ -1920,12 +1935,26 @@ def test_01_network_services_upgrade(self):
19201935

19211936
wait_for_cleanup(self.apiclient, ["expunge.interval", "expunge.delay"])
19221937

1938+
# When all Vms ain network are stopped, network state changes from Implemented --> Shutdown --> Allocated
1939+
# We can't update the network when it is in Shutodown state, hence we should wait for the state to change to
1940+
# Allocated and then update the network
1941+
retriesCount = 10
1942+
while True:
1943+
networks = list_networks(self.apiclient, id=network_1.id)
1944+
self.assertEqual(validateList(networks)[0], PASS, "networks list validation failed, list id %s" % networks)
1945+
self.debug("network state is %s" % networks[0].state)
1946+
if networks[0].state == "Allocated":
1947+
break
1948+
if retriesCount == 0:
1949+
self.fail("Network state should change to Allocated, it is %s" % networks[0].state)
1950+
retriesCount -= 1
1951+
time.sleep(6)
1952+
19231953
self.debug("Upgrading network offering to support PF services")
19241954
try:
19251955
network_1.update(
19261956
self.apiclient,
1927-
networkofferingid=nw_off.id,
1928-
changecidr=True
1957+
networkofferingid=nw_off.id
19291958
)
19301959
except Exception as e:
19311960
self.fail("failed to upgrade the network offering- %s" % e)
@@ -1938,23 +1967,23 @@ def test_01_network_services_upgrade(self):
19381967
except Exception as e:
19391968
self.fail("Failed to start VMs, %s" % e)
19401969

1941-
nat_rule = NATRule.create(
1942-
self.apiclient,
1943-
vm_1,
1944-
self.services["natrule"],
1945-
ipaddressid=public_ip_3.ipaddress.id,
1946-
openfirewall=False,
1947-
networkid=network_1.id,
1948-
vpcid=vpc.id
1949-
)
1970+
NATRule.create(
1971+
self.apiclient,
1972+
vm_1,
1973+
self.services["natrule"],
1974+
ipaddressid=public_ip_3.ipaddress.id,
1975+
openfirewall=False,
1976+
networkid=network_1.id,
1977+
vpcid=vpc.id
1978+
)
19501979

19511980
self.debug("Adding NetwrokACl rules to make NAT rule accessible")
1952-
nwacl_nat = NetworkACL.create(
1953-
self.apiclient,
1954-
networkid=network_1.id,
1955-
services=self.services["natrule"],
1956-
traffictype='Ingress'
1957-
)
1981+
NetworkACL.create(
1982+
self.apiclient,
1983+
networkid=network_1.id,
1984+
services=self.services["natrule"],
1985+
traffictype='Ingress'
1986+
)
19581987
self.debug("Checking if we can SSH into VM using NAT rule?")
19591988
try:
19601989
ssh_3 = vm_1.get_ssh_client(

0 commit comments

Comments
 (0)