Skip to content

Commit 860b020

Browse files
Ashutosh KGirish Shilamkar
authored andcommitted
CLOUDSTACK-4840: Adding first set of test cases for Multiple IPs per NIC feature
1 parent a369647 commit 860b020

3 files changed

Lines changed: 87 additions & 2 deletions

File tree

tools/marvin/marvin/codes.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,7 @@
4747
FAILED = "FAILED"
4848
UNKNOWN_ERROR = "Unknown Error"
4949
EXCEPTION = "EXCEPTION"
50+
BASIC_ZONE = "basic"
51+
ISOLATED_NETWORK = "ISOLATED"
52+
SHARED_NETWORK = "SHARED"
53+
VPC_NETWORK = "VPC"

tools/marvin/marvin/integration/lib/base.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3623,3 +3623,32 @@ def updateCount(cls, apiclient, **kwargs):
36233623
cmd = updateResourceCount.updateResourceCountCmd()
36243624
[setattr(cmd, k, v) for k, v in kwargs.items()]
36253625
return(apiclient.updateResourceCount(cmd))
3626+
3627+
class NIC:
3628+
"""NIC related API"""
3629+
def __init__(self, items):
3630+
self.__dict__.update(items)
3631+
3632+
@classmethod
3633+
def addIp(cls, apiclient, id, ipaddress=None):
3634+
"""Add Ip (secondary) to NIC"""
3635+
cmd = addIpToNic.addIpToNicCmd()
3636+
cmd.nicid = id
3637+
if ipaddress:
3638+
cmd.ipaddress = ipaddress
3639+
return(apiclient.addIpToNic(cmd))
3640+
3641+
@classmethod
3642+
def removeIp(cls,apiclient,ipaddressid):
3643+
"""Remove secondary Ip from NIC"""
3644+
cmd = removeIpFromNic.removeIpFromNicCmd()
3645+
cmd.id = ipaddressid
3646+
return(apiclient.addIpToNic(cmd))
3647+
3648+
@classmethod
3649+
def list(cls, apiclient, **kwargs):
3650+
"""List NICs belonging to a virtual machine"""
3651+
3652+
cmd = listNics.listNicsCmd()
3653+
[setattr(cmd, k, v) for k, v in kwargs.items()]
3654+
return(apiclient.listNics(cmd))

tools/marvin/marvin/integration/lib/common.py

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,14 @@
6363
Resources,
6464
PhysicalNetwork,
6565
Host,
66-
PublicIPAddress)
66+
PublicIPAddress,
67+
NetworkOffering)
6768
from marvin.integration.lib.utils import (get_process_status,
6869
xsplit,
6970
validateList)
7071

7172
from marvin.sshClient import SshClient
72-
from marvin.codes import PASS
73+
from marvin.codes import PASS, ISOLATED_NETWORK, VPC_NETWORK, BASIC_ZONE, FAIL
7374
import random
7475

7576
#Import System modules
@@ -917,3 +918,54 @@ def is_public_ip_in_correct_state(apiclient, ipaddressid, state):
917918
time.sleep(60)
918919
continue
919920
return True
921+
922+
def setSharedNetworkParams(networkServices, range=20):
923+
"""Fill up the services dictionary for shared network using random subnet"""
924+
925+
# @range: range decides the endip. Pass the range as "x" if you want the difference between the startip
926+
# and endip as "x"
927+
# Set the subnet number of shared networks randomly prior to execution
928+
# of each test case to avoid overlapping of ip addresses
929+
shared_network_subnet_number = random.randrange(1,254)
930+
931+
networkServices["gateway"] = "172.16."+str(shared_network_subnet_number)+".1"
932+
networkServices["startip"] = "172.16."+str(shared_network_subnet_number)+".2"
933+
networkServices["endip"] = "172.16."+str(shared_network_subnet_number)+"."+str(range+1)
934+
networkServices["netmask"] = "255.255.255.0"
935+
return networkServices
936+
937+
def createEnabledNetworkOffering(apiclient, networkServices):
938+
"""Create and enable network offering according to the type
939+
940+
@output: List, containing [ Result,Network Offering,Reason ]
941+
Ist Argument('Result') : FAIL : If exception or assertion error occurs
942+
PASS : If network offering
943+
is created and enabled successfully
944+
IInd Argument(Net Off) : Enabled network offering
945+
In case of exception or
946+
assertion error, it will be None
947+
IIIrd Argument(Reason) : Reason for failure,
948+
default to None
949+
"""
950+
try:
951+
resultSet = [FAIL, None, None]
952+
# Create network offering
953+
network_offering = NetworkOffering.create(apiclient, networkServices, conservemode=False)
954+
955+
# Update network offering state from disabled to enabled.
956+
NetworkOffering.update(network_offering, apiclient, id=network_offering.id,
957+
state="enabled")
958+
except Exception as e:
959+
resultSet[2] = e
960+
return resultSet
961+
return [PASS, network_offering, None]
962+
963+
def shouldTestBeSkipped(networkType, zoneType):
964+
"""Decide which test to skip, according to type of network and zone type"""
965+
966+
# If network type is isolated or vpc and zone type is basic, then test should be skipped
967+
skipIt = False
968+
if ((networkType.lower() == str(ISOLATED_NETWORK).lower() or networkType.lower() == str(VPC_NETWORK).lower())
969+
and (zoneType.lower() == BASIC_ZONE)):
970+
skipIt = True
971+
return skipIt

0 commit comments

Comments
 (0)