CLOUDSTACK-6536: Code cleanup - removing unnecessary waits after VM stop operation, modifying imports, removing white-spaces, adding try catch blocks whenever necessary

This commit is contained in:
Girish Shilamkar 2014-04-30 03:40:40 -04:00 committed by Gaurav Aradhye
parent d4f167032b
commit 247c796693
28 changed files with 1342 additions and 1621 deletions

View File

@ -347,14 +347,10 @@ class TestAddNetworkToVirtualMachine(cloudstackTestCase):
# Validate the following: # Validate the following:
# 1. New nic is generated for the added network # 1. New nic is generated for the added network
self.debug("Stopping Virtual Machine: %s" % self.virtual_machine.id) try:
self.virtual_machine.stop(self.apiclient) self.virtual_machine.stop(self.apiclient)
except Exception as e:
vm_list = list_virtual_machines(self.apiclient,id=self.virtual_machine.id) self.fail("Failed to stop VM: %s" % e)
vm_list_validation_result = validateList(vm_list)
self.assertEqual(vm_list_validation_result[0], PASS, "vm list validation failed due to %s" %
vm_list_validation_result[2])
self.assertTrue(vm_list[0].state == 'Stopped', "Failed to stop VM, the state is %s" % vm_list[0].state)
network = None #The network which we are adding to the vm network = None #The network which we are adding to the vm
if value == "isolated": if value == "isolated":
@ -451,16 +447,10 @@ class TestAddNetworkToVirtualMachine(cloudstackTestCase):
# Validate the following: # Validate the following:
# 1. Adding VPC to vm should fail # 1. Adding VPC to vm should fail
self.debug("Stopping Virtual Machine: %s" % self.virtual_machine.id) try:
self.virtual_machine.stop(self.apiclient) self.virtual_machine.stop(self.apiclient)
except Exception as e:
vm_list = list_virtual_machines(self.apiclient,id=self.virtual_machine.id) self.fail("Failed to stop virtual machine: %s" % e)
#validation vm list
vm_list_validation_result = validateList(vm_list)
self.assertEqual(vm_list_validation_result[0], PASS, "vm list validation failed due to %s" %
vm_list_validation_result[2])
self.assertTrue(vm_list[0].state == 'Stopped', "Failed to stop VM, the state is %s" % vm_list[0].state)
self.addNetworkToVm(self.isolated_network, self.virtual_machine) self.addNetworkToVm(self.isolated_network, self.virtual_machine)

View File

@ -28,7 +28,7 @@ from marvin.lib.base import (Snapshot,
StaticNATRule, StaticNATRule,
FireWallRule, FireWallRule,
Volume) Volume)
from marvin.lib.utils import cleanup_resources from marvin.lib.utils import cleanup_resources, validateList
from marvin.lib.common import (get_zone, from marvin.lib.common import (get_zone,
get_domain, get_domain,
get_template, get_template,
@ -36,8 +36,9 @@ from marvin.lib.common import (get_zone,
get_builtin_template_info) get_builtin_template_info)
#Import Local Modules #Import Local Modules
from marvin.cloudstackTestCase import cloudstackTestCase from marvin.cloudstackTestCase import cloudstackTestCase, unittest
from marvin.cloudstackAPI import restartNetwork from marvin.cloudstackAPI import restartNetwork
from marvin.codes import PASS
import time import time
@ -744,17 +745,21 @@ class TestTemplates(cloudstackTestCase):
cls.services["ostype"] cls.services["ostype"]
) )
cls.services["virtual_machine"]["zoneid"] = cls.zone.id cls.services["virtual_machine"]["zoneid"] = cls.zone.id
cls._cleanup = []
try:
cls.account = Account.create( cls.account = Account.create(
cls.api_client, cls.api_client,
cls.services["account"], cls.services["account"],
domainid=cls.domain.id domainid=cls.domain.id
) )
cls._cleanup.append(cls.account)
cls.services["account"] = cls.account.name cls.services["account"] = cls.account.name
cls.service_offering = ServiceOffering.create( cls.service_offering = ServiceOffering.create(
cls.api_client, cls.api_client,
cls.services["service_offering"], cls.services["service_offering"],
) )
cls._cleanup.append(cls.service_offering)
# create virtual machine # create virtual machine
cls.virtual_machine = VirtualMachine.create( cls.virtual_machine = VirtualMachine.create(
@ -768,24 +773,17 @@ class TestTemplates(cloudstackTestCase):
#Stop virtual machine #Stop virtual machine
cls.virtual_machine.stop(cls.api_client) cls.virtual_machine.stop(cls.api_client)
#Wait before server has be successfully stopped listvolumes = Volume.list(
time.sleep(30)
list_volume = Volume.list(
cls.api_client, cls.api_client,
virtualmachineid=cls.virtual_machine.id, virtualmachineid=cls.virtual_machine.id,
type='ROOT', type='ROOT',
listall=True listall=True
) )
try: assert validateList(listvolumes)[0] == PASS, "volumes list is empty"
if isinstance(list_volume, list): cls.volume = listvolumes[0]
cls.volume = list_volume[0]
except Exception as e: except Exception as e:
raise Exception("Warning: Exception during setup : %s" % e) cls.tearDownClass()
raise unittest.SkipTest("Exception in setUpClass: %s" % e)
cls._cleanup = [
cls.service_offering,
cls.account,
]
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):

View File

@ -17,12 +17,19 @@
""" P1 tests for user provide hostname cases """ P1 tests for user provide hostname cases
""" """
#Import Local Modules #Import Local Modules
import marvin
from nose.plugins.attrib import attr from nose.plugins.attrib import attr
from marvin.cloudstackTestCase import * from marvin.cloudstackTestCase import cloudstackTestCase
from marvin.lib.utils import * from marvin.lib.utils import (cleanup_resources,
from marvin.lib.base import * random_gen)
from marvin.lib.common import * from marvin.lib.base import (ServiceOffering,
Configurations,
VirtualMachine,
Account)
from marvin.lib.common import (get_domain,
get_zone,
get_template,
is_config_suitable)
class Services: class Services:

View File

@ -24,12 +24,22 @@
Feature Specifications: https://cwiki.apache.org/confluence/display/CLOUDSTACK/Dynamic+Compute+Offering+FS Feature Specifications: https://cwiki.apache.org/confluence/display/CLOUDSTACK/Dynamic+Compute+Offering+FS
""" """
from marvin.cloudstackTestCase import cloudstackTestCase from marvin.cloudstackTestCase import cloudstackTestCase
from marvin.lib.utils import * from marvin.lib.utils import (cleanup_resources,
from marvin.lib.base import * validateList,
from marvin.lib.common import * random_gen)
from marvin.lib.base import (Account,
VirtualMachine,
ServiceOffering,
Resources,
AffinityGroup,
Host)
from marvin.lib.common import (get_zone,
get_domain,
get_template,
verifyComputeOfferingCreation)
from nose.plugins.attrib import attr from nose.plugins.attrib import attr
from marvin.codes import PASS, ADMIN_ACCOUNT, USER_ACCOUNT from marvin.codes import PASS, ADMIN_ACCOUNT, USER_ACCOUNT, FAILED
from ddt import ddt, data from ddt import ddt, data
@ddt @ddt
@ -460,27 +470,6 @@ class TestScaleVmDynamicServiceOffering(cloudstackTestCase):
raise Exception("Warning: Exception during cleanup : %s" % e) raise Exception("Warning: Exception during cleanup : %s" % e)
return return
def stopVM(self, vm):
"""Stop VM and verify that it is indeed in stopped state"""
try:
vm.stop(self.apiclient)
except Exception as e:
self.fail("Failed to stop VM: %s" % e)
retriesCount = 10
while True:
vmlist = VirtualMachine.list(self.apiclient, id=vm.id)
if str(vmlist[0].state).lower() == "stopped":
break
elif retriesCount == 0:
self.fail("Failed to stop VM even after 10 minutes")
else:
retriesCount -= 1
time.sleep(60)
continue
# End while
return
@data(ADMIN_ACCOUNT, USER_ACCOUNT) @data(ADMIN_ACCOUNT, USER_ACCOUNT)
@attr(tags=["basic","advanced"]) @attr(tags=["basic","advanced"])
def test_change_so_stopped_vm_static_to_static(self, value): def test_change_so_stopped_vm_static_to_static(self, value):
@ -500,12 +489,13 @@ class TestScaleVmDynamicServiceOffering(cloudstackTestCase):
if value == USER_ACCOUNT: if value == USER_ACCOUNT:
isadmin=False isadmin=False
try:
# Create Account # Create Account
self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id, admin=isadmin) self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id, admin=isadmin)
self.cleanup.append(self.account)
apiclient = self.testClient.getUserApiClient( apiclient = self.testClient.getUserApiClient(
UserName=self.account.name, UserName=self.account.name,
DomainName=self.account.domain) DomainName=self.account.domain)
self.cleanup.append(self.account)
# Create static service offerings (Second offering should have # Create static service offerings (Second offering should have
# one of the custom values greater than 1st one, scaling down is not allowed # one of the custom values greater than 1st one, scaling down is not allowed
@ -525,21 +515,17 @@ class TestScaleVmDynamicServiceOffering(cloudstackTestCase):
self.cleanup_co.append(serviceOffering_static_2) self.cleanup_co.append(serviceOffering_static_2)
# Deploy VM # Deploy VM
try:
virtualMachine = VirtualMachine.create(apiclient,self.services["virtual_machine"], virtualMachine = VirtualMachine.create(apiclient,self.services["virtual_machine"],
serviceofferingid=serviceOffering_static_1.id, serviceofferingid=serviceOffering_static_1.id,
accountid=self.account.name,domainid=self.account.domainid) accountid=self.account.name,domainid=self.account.domainid)
except Exception as e:
self.fail("vm creation failed: %s" % e)
# Stop VM and verify it is in stopped state # Stop VM
self.stopVM(virtualMachine) virtualMachine.stop(apiclient)
# Scale VM to new static service offering # Scale VM to new static service offering
try:
virtualMachine.scale(apiclient, serviceOfferingId=serviceOffering_static_2.id) virtualMachine.scale(apiclient, serviceOfferingId=serviceOffering_static_2.id)
except Exception as e: except Exception as e:
self.fail("Failure while changing service offering: %s" % e) self.fail("Exception occured: %s" % e)
return return
@data(ADMIN_ACCOUNT, USER_ACCOUNT) @data(ADMIN_ACCOUNT, USER_ACCOUNT)
@ -565,6 +551,7 @@ class TestScaleVmDynamicServiceOffering(cloudstackTestCase):
if value == USER_ACCOUNT: if value == USER_ACCOUNT:
isadmin=False isadmin=False
try:
# Create Account and api client # Create Account and api client
self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id, admin=isadmin) self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id, admin=isadmin)
apiclient = self.testClient.getUserApiClient( apiclient = self.testClient.getUserApiClient(
@ -592,42 +579,31 @@ class TestScaleVmDynamicServiceOffering(cloudstackTestCase):
self.cleanup_co.append(serviceOffering_dynamic) self.cleanup_co.append(serviceOffering_dynamic)
# Deploy VM with static service offering # Deploy VM with static service offering
try:
virtualMachine_1 = VirtualMachine.create(apiclient,self.services["virtual_machine"], virtualMachine_1 = VirtualMachine.create(apiclient,self.services["virtual_machine"],
serviceofferingid=serviceOffering_static.id, serviceofferingid=serviceOffering_static.id,
accountid=self.account.name,domainid=self.account.domainid) accountid=self.account.name,domainid=self.account.domainid)
except Exception as e:
self.fail("vm creation failed: %s" % e)
# Stop VM and verify it is in stopped state # Stop VM
self.stopVM(virtualMachine_1) virtualMachine_1.stop(apiclient)
# Scale VM to dynamic service offering proving all custom values # Scale VM to dynamic service offering proving all custom values
try:
virtualMachine_1.scale(apiclient, serviceOfferingId=serviceOffering_dynamic.id, virtualMachine_1.scale(apiclient, serviceOfferingId=serviceOffering_dynamic.id,
customcpunumber=4, customcpuspeed=256, custommemory=128) customcpunumber=4, customcpuspeed=256, custommemory=128)
except Exception as e:
self.fail("Failure while changing service offering: %s" % e)
# Deploy VM with static service offering # Deploy VM with static service offering
try:
virtualMachine_2 = VirtualMachine.create(apiclient,self.services["virtual_machine"], virtualMachine_2 = VirtualMachine.create(apiclient,self.services["virtual_machine"],
serviceofferingid=serviceOffering_static.id, serviceofferingid=serviceOffering_static.id,
accountid=self.account.name,domainid=self.account.domainid) accountid=self.account.name,domainid=self.account.domainid)
except Exception as e:
self.fail("vm creation failed: %s" % e)
# Stop VM and verify it is in stopped state # Stop VM
self.stopVM(virtualMachine_2) virtualMachine_2.stop(apiclient)
except Exception as e:
self.fail("Exception occuered: %s" % e)
# Scale VM to dynamic service offering proving only custom cpu number # Scale VM to dynamic service offering proving only custom cpu number
try: with self.assertRaises(Exception):
virtualMachine_2.scale(apiclient, serviceOfferingId=serviceOffering_dynamic.id, virtualMachine_2.scale(apiclient, serviceOfferingId=serviceOffering_dynamic.id,
customcpunumber=4) customcpunumber=4)
self.fail("Changing service offering with incomplete data should have failed, it succeded")
except Exception as e:
self.debug("Failure while changing service offering as expected: %s" % e)
return return
@data(ADMIN_ACCOUNT, USER_ACCOUNT) @data(ADMIN_ACCOUNT, USER_ACCOUNT)
@ -649,6 +625,7 @@ class TestScaleVmDynamicServiceOffering(cloudstackTestCase):
if value == USER_ACCOUNT: if value == USER_ACCOUNT:
isadmin=False isadmin=False
try:
# Create account and api client # Create account and api client
self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id, admin=isadmin) self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id, admin=isadmin)
apiclient = self.testClient.getUserApiClient( apiclient = self.testClient.getUserApiClient(
@ -675,22 +652,18 @@ class TestScaleVmDynamicServiceOffering(cloudstackTestCase):
self.cleanup_co.append(serviceOffering_dynamic) self.cleanup_co.append(serviceOffering_dynamic)
# Deploy VM with dynamic service offering # Deploy VM with dynamic service offering
try:
virtualMachine = VirtualMachine.create(apiclient,self.services["virtual_machine"], virtualMachine = VirtualMachine.create(apiclient,self.services["virtual_machine"],
serviceofferingid=serviceOffering_dynamic.id, serviceofferingid=serviceOffering_dynamic.id,
accountid=self.account.name,domainid=self.account.domainid, accountid=self.account.name,domainid=self.account.domainid,
customcpunumber=2, customcpuspeed=256, custommemory=128) customcpunumber=2, customcpuspeed=256, custommemory=128)
except Exception as e:
self.fail("vm creation failed: %s" % e)
# Stop VM and verify that it is in stopped state # Stop VM and verify that it is in stopped state
self.stopVM(virtualMachine) virtualMachine.stop(apiclient)
# Scale VM to static service offering # Scale VM to static service offering
try:
virtualMachine.scale(apiclient, serviceOfferingId=serviceOffering_static.id) virtualMachine.scale(apiclient, serviceOfferingId=serviceOffering_static.id)
except Exception as e: except Exception as e:
self.fail("Failure while changing service offering: %s" % e) self.fail("Exception occured: %s" % e)
return return
@data(ADMIN_ACCOUNT, USER_ACCOUNT) @data(ADMIN_ACCOUNT, USER_ACCOUNT)
@ -717,6 +690,7 @@ class TestScaleVmDynamicServiceOffering(cloudstackTestCase):
if value == USER_ACCOUNT: if value == USER_ACCOUNT:
isadmin=False isadmin=False
try:
# Create Account # Create Account
self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id, admin=isadmin) self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id, admin=isadmin)
apiclient = self.testClient.getUserApiClient( apiclient = self.testClient.getUserApiClient(
@ -739,40 +713,29 @@ class TestScaleVmDynamicServiceOffering(cloudstackTestCase):
self.cleanup_co.append(serviceOffering_dynamic_2) self.cleanup_co.append(serviceOffering_dynamic_2)
# Deploy VM with dynamic service offering # Deploy VM with dynamic service offering
try:
virtualMachine = VirtualMachine.create(apiclient,self.services["virtual_machine"], virtualMachine = VirtualMachine.create(apiclient,self.services["virtual_machine"],
serviceofferingid=serviceOffering_dynamic_1.id, serviceofferingid=serviceOffering_dynamic_1.id,
accountid=self.account.name,domainid=self.account.domainid, accountid=self.account.name,domainid=self.account.domainid,
customcpunumber=2, customcpuspeed=256, custommemory=128) customcpunumber=2, customcpuspeed=256, custommemory=128)
except Exception as e:
self.fail("vm creation failed: %s" % e)
# Stop VM and verify that it is in stopped state # Stop VM
self.stopVM(virtualMachine) virtualMachine.stop(apiclient)
# Scale VM with same dynamic service offering # Scale VM with same dynamic service offering
try:
virtualMachine.scale(apiclient, serviceOfferingId=serviceOffering_dynamic_1.id, virtualMachine.scale(apiclient, serviceOfferingId=serviceOffering_dynamic_1.id,
customcpunumber=4, customcpuspeed=512, custommemory=256) customcpunumber=4, customcpuspeed=512, custommemory=256)
except Exception as e:
self.fail("Failure while changing service offering: %s" % e)
# Scale VM with other dynamic service offering # Scale VM with other dynamic service offering
try:
virtualMachine.scale(apiclient, serviceOfferingId=serviceOffering_dynamic_2.id, virtualMachine.scale(apiclient, serviceOfferingId=serviceOffering_dynamic_2.id,
customcpunumber=4, customcpuspeed=512, custommemory=256) customcpunumber=4, customcpuspeed=512, custommemory=256)
except Exception as e: except Exception as e:
self.fail("Failure while changing service offering: %s" % e) self.fail("Exception occured: %s" % e)
# Scale VM with dynamic service offering proving custom value # Scale VM with dynamic service offering proving custom value
# only for cpu number # only for cpu number
try: with self.assertRaises(Exception):
virtualMachine.scale(apiclient, serviceOfferingId=serviceOffering_dynamic_1.id, virtualMachine.scale(apiclient, serviceOfferingId=serviceOffering_dynamic_1.id,
customcpunumber=4) customcpunumber=4)
self.fail("Changing service offering should have failed, it succeded")
except Exception as e:
self.debug("Failure while changing service offering: %s" % e)
return return
@data(ADMIN_ACCOUNT, USER_ACCOUNT) @data(ADMIN_ACCOUNT, USER_ACCOUNT)

View File

@ -1901,27 +1901,11 @@ class TestStartStopVMWithEgressRule(cloudstackTestCase):
"Check egress rule created properly" "Check egress rule created properly"
) )
try:
# Stop virtual machine # Stop virtual machine
self.debug("Stopping virtual machine: %s" % self.virtual_machine.id)
self.virtual_machine.stop(self.apiclient) self.virtual_machine.stop(self.apiclient)
except Exception as e:
vms = VirtualMachine.list( self.fail("Failed to stop instance: %s" % e)
self.apiclient,
id=self.virtual_machine.id,
listall=True
)
self.assertEqual(
isinstance(vms, list),
True,
"List VM should return a valid list"
)
vm = vms[0]
self.assertEqual(
vm.state,
"Stopped",
"VM state should be stopped"
)
self.debug("VM: %s state: %s" % (vm.id, vm.state))
# Start virtual machine # Start virtual machine
self.debug("Starting virtual machine: %s" % self.virtual_machine.id) self.debug("Starting virtual machine: %s" % self.virtual_machine.id)

View File

@ -16,17 +16,41 @@
# under the License. # under the License.
#Import Local Modules #Import Local Modules
from marvin.cloudstackTestCase import * from marvin.cloudstackTestCase import cloudstackTestCase
from marvin.cloudstackException import * from marvin.cloudstackAPI import (createVolume,
from marvin.cloudstackAPI import * createTemplate)
from marvin.sshClient import SshClient from marvin.lib.base import (Volume,
from marvin.lib.utils import * Iso,
from marvin.lib.base import * VirtualMachine,
from marvin.lib.common import * Template,
from marvin.lib.utils import checkVolumeSize Snapshot,
from marvin.codes import SUCCESS SecurityGroup,
Account,
Zone,
Network,
NetworkOffering,
DiskOffering,
ServiceOffering,
VmSnapshot,
SnapshotPolicy,
SSHKeyPair,
Resources,
Configurations,
VpnCustomerGateway,
Hypervisor,
VpcOffering,
VPC,
NetworkACL)
from marvin.lib.common import (get_zone,
get_domain,
get_template,
list_os_types)
from marvin.lib.utils import (validateList,
cleanup_resources,
random_gen)
from marvin.codes import (PASS, FAIL, EMPTY_LIST)
from nose.plugins.attrib import attr from nose.plugins.attrib import attr
from time import sleep import time
class TestVolumes(cloudstackTestCase): class TestVolumes(cloudstackTestCase):
@ -3198,22 +3222,6 @@ class TestListInstances(cloudstackTestCase):
self.userapiclient, self.userapiclient,
forced=True forced=True
) )
# Listing VM details
list_vm = VirtualMachine.list(
self.userapiclient,
id=vm_created.id
)
status = validateList(list_vm)
self.assertEquals(
PASS,
status[0],
"Listing of VM failed"
)
self.assertEquals(
"Stopped",
list_vm[0].state,
"Stopped VM is not in stopped state"
)
# Listing all the SSH Key pairs # Listing all the SSH Key pairs
list_keypairs_before = SSHKeyPair.list( list_keypairs_before = SSHKeyPair.list(
self.userapiclient self.userapiclient
@ -3465,7 +3473,6 @@ class TestListInstances(cloudstackTestCase):
default_nic = vm_nics_after[i] default_nic = vm_nics_after[i]
else: else:
non_default_nic = vm_nics_after[i] non_default_nic = vm_nics_after[i]
self.assertEquals( self.assertEquals(
1, 1,
default_count, default_count,
@ -4504,22 +4511,6 @@ class TestInstances(cloudstackTestCase):
self.userapiclient, self.userapiclient,
forced=True forced=True
) )
# Listing VM details
list_vm = VirtualMachine.list(
self.userapiclient,
id=vm_created.id
)
status = validateList(list_vms_after)
self.assertEquals(
PASS,
status[0],
"Listing of VM failed"
)
self.assertEquals(
"Stopped",
list_vm[0].state,
"Stopped VM is not in stopped state"
)
# Listing all the service offerings # Listing all the service offerings
service_offerings_list = ServiceOffering.list( service_offerings_list = ServiceOffering.list(
self.userapiclient, self.userapiclient,
@ -4629,22 +4620,6 @@ class TestInstances(cloudstackTestCase):
self.userapiclient, self.userapiclient,
forced=True forced=True
) )
# Listing VM details
list_vm = VirtualMachine.list(
self.userapiclient,
id=vm_created.id
)
status = validateList(list_vm)
self.assertEquals(
PASS,
status[0],
"Listing of VM failed"
)
self.assertEquals(
"Stopped",
list_vm[0].state,
"Stopped VM is not in stopped state"
)
# Listing all the SSH Key pairs # Listing all the SSH Key pairs
list_keypairs_before = SSHKeyPair.list( list_keypairs_before = SSHKeyPair.list(
self.userapiclient self.userapiclient

View File

@ -18,15 +18,28 @@
""" P1 tests for netscaler configurations """ P1 tests for netscaler configurations
""" """
#Import Local Modules #Import Local Modules
import marvin
from nose.plugins.attrib import attr from nose.plugins.attrib import attr
from marvin.cloudstackTestCase import * from marvin.cloudstackTestCase import cloudstackTestCase
from marvin.cloudstackAPI import * #from marvin.cloudstackAPI import *
from marvin.lib.utils import * from marvin.lib.utils import (cleanup_resources,
from marvin.lib.base import * random_gen)
from marvin.lib.common import * from marvin.lib.base import (VirtualMachine,
NetworkServiceProvider,
PublicIPAddress,
Account,
Network,
NetScaler,
LoadBalancerRule,
NetworkOffering,
ServiceOffering,
PhysicalNetwork,
Configurations)
from marvin.lib.common import (get_domain,
get_zone,
get_template,
add_netscaler)
from marvin.sshClient import SshClient from marvin.sshClient import SshClient
import datetime import time
class Services: class Services:
@ -559,7 +572,7 @@ class TestNetScalerDedicated(cloudstackTestCase):
netscaler_provider = nw_service_providers[0] netscaler_provider = nw_service_providers[0]
if netscaler_provider.state != 'Enabled': if netscaler_provider.state != 'Enabled':
response = NetworkServiceProvider.update( NetworkServiceProvider.update(
cls.api_client, cls.api_client,
id=netscaler_provider.id, id=netscaler_provider.id,
state='Enabled' state='Enabled'
@ -621,11 +634,11 @@ class TestNetScalerDedicated(cloudstackTestCase):
self.debug("Cleaning up the resources") self.debug("Cleaning up the resources")
#Clean up, terminate the created network offerings #Clean up, terminate the created network offerings
cleanup_resources(self.apiclient, self.cleanup) cleanup_resources(self.apiclient, self.cleanup)
interval = list_configurations( interval = Configurations.list(
self.apiclient, self.apiclient,
name='network.gc.interval' name='network.gc.interval'
) )
wait = list_configurations( wait = Configurations.list(
self.apiclient, self.apiclient,
name='network.gc.wait' name='network.gc.wait'
) )
@ -781,7 +794,7 @@ class TestNetScalerShared(cloudstackTestCase):
netscaler_provider = nw_service_providers[0] netscaler_provider = nw_service_providers[0]
if netscaler_provider.state != 'Enabled': if netscaler_provider.state != 'Enabled':
response = NetworkServiceProvider.update( NetworkServiceProvider.update(
cls.api_client, cls.api_client,
id=netscaler_provider.id, id=netscaler_provider.id,
state='Enabled' state='Enabled'
@ -839,11 +852,11 @@ class TestNetScalerShared(cloudstackTestCase):
self.debug("Cleaning up the resources") self.debug("Cleaning up the resources")
#Clean up, terminate the created network offerings #Clean up, terminate the created network offerings
cleanup_resources(self.apiclient, self.cleanup) cleanup_resources(self.apiclient, self.cleanup)
interval = list_configurations( interval = Configurations.list(
self.apiclient, self.apiclient,
name='network.gc.interval' name='network.gc.interval'
) )
wait = list_configurations( wait = Configurations.list(
self.apiclient, self.apiclient,
name='network.gc.wait' name='network.gc.wait'
) )
@ -1023,7 +1036,7 @@ class TestNetScalerCustomCapacity(cloudstackTestCase):
netscaler_provider = nw_service_providers[0] netscaler_provider = nw_service_providers[0]
if netscaler_provider.state != 'Enabled': if netscaler_provider.state != 'Enabled':
response = NetworkServiceProvider.update( NetworkServiceProvider.update(
cls.api_client, cls.api_client,
id=netscaler_provider.id, id=netscaler_provider.id,
state='Enabled' state='Enabled'
@ -1087,11 +1100,11 @@ class TestNetScalerCustomCapacity(cloudstackTestCase):
self.debug("Cleaning up the resources") self.debug("Cleaning up the resources")
#Clean up, terminate the created network offerings #Clean up, terminate the created network offerings
cleanup_resources(self.apiclient, self.cleanup) cleanup_resources(self.apiclient, self.cleanup)
interval = list_configurations( interval = Configurations.list(
self.apiclient, self.apiclient,
name='network.gc.interval' name='network.gc.interval'
) )
wait = list_configurations( wait = Configurations.list(
self.apiclient, self.apiclient,
name='network.gc.wait' name='network.gc.wait'
) )
@ -1244,7 +1257,7 @@ class TestNetScalerCustomCapacity(cloudstackTestCase):
self.debug("Deploying VM in account: %s" % self.account_3.name) self.debug("Deploying VM in account: %s" % self.account_3.name)
with self.assertRaises(Exception): with self.assertRaises(Exception):
# Spawn an instance in that network # Spawn an instance in that network
virtual_machine_3 = VirtualMachine.create( VirtualMachine.create(
self.apiclient, self.apiclient,
self.services["virtual_machine"], self.services["virtual_machine"],
accountid=self.account_3.name, accountid=self.account_3.name,
@ -1295,7 +1308,7 @@ class TestNetScalerNoCapacity(cloudstackTestCase):
netscaler_provider = nw_service_providers[0] netscaler_provider = nw_service_providers[0]
if netscaler_provider.state != 'Enabled': if netscaler_provider.state != 'Enabled':
response = NetworkServiceProvider.update( NetworkServiceProvider.update(
cls.api_client, cls.api_client,
id=netscaler_provider.id, id=netscaler_provider.id,
state='Enabled' state='Enabled'
@ -1359,11 +1372,11 @@ class TestNetScalerNoCapacity(cloudstackTestCase):
self.debug("Cleaning up the resources") self.debug("Cleaning up the resources")
#Clean up, terminate the created network offerings #Clean up, terminate the created network offerings
cleanup_resources(self.apiclient, self.cleanup) cleanup_resources(self.apiclient, self.cleanup)
interval = list_configurations( interval = Configurations.list(
self.apiclient, self.apiclient,
name='network.gc.interval' name='network.gc.interval'
) )
wait = list_configurations( wait = Configurations.list(
self.apiclient, self.apiclient,
name='network.gc.wait' name='network.gc.wait'
) )
@ -1517,7 +1530,7 @@ class TestNetScalerNoCapacity(cloudstackTestCase):
self.debug("Deploying VM in account: %s" % self.account_3.name) self.debug("Deploying VM in account: %s" % self.account_3.name)
with self.assertRaises(Exception): with self.assertRaises(Exception):
# Spawn an instance in that network # Spawn an instance in that network
virtual_machine_3 = VirtualMachine.create( VirtualMachine.create(
self.apiclient, self.apiclient,
self.services["virtual_machine"], self.services["virtual_machine"],
accountid=self.account_3.name, accountid=self.account_3.name,
@ -1568,7 +1581,7 @@ class TestGuestNetworkWithNetScaler(cloudstackTestCase):
netscaler_provider = nw_service_providers[0] netscaler_provider = nw_service_providers[0]
if netscaler_provider.state != 'Enabled': if netscaler_provider.state != 'Enabled':
response = NetworkServiceProvider.update( NetworkServiceProvider.update(
cls.api_client, cls.api_client,
id=netscaler_provider.id, id=netscaler_provider.id,
state='Enabled' state='Enabled'
@ -1626,11 +1639,11 @@ class TestGuestNetworkWithNetScaler(cloudstackTestCase):
self.debug("Cleaning up the resources") self.debug("Cleaning up the resources")
#Clean up, terminate the created network offerings #Clean up, terminate the created network offerings
cleanup_resources(self.apiclient, self.cleanup) cleanup_resources(self.apiclient, self.cleanup)
interval = list_configurations( interval = Configurations.list(
self.apiclient, self.apiclient,
name='network.gc.interval' name='network.gc.interval'
) )
wait = list_configurations( wait = Configurations.list(
self.apiclient, self.apiclient,
name='network.gc.wait' name='network.gc.wait'
) )
@ -2030,11 +2043,11 @@ class TestGuestNetworkWithNetScaler(cloudstackTestCase):
self.debug("Account: %s is deleted!" % self.account_1.name) self.debug("Account: %s is deleted!" % self.account_1.name)
self.debug("Waiting for network.gc.interval & network.gc.wait..") self.debug("Waiting for network.gc.interval & network.gc.wait..")
interval = list_configurations( interval = Configurations.list(
self.apiclient, self.apiclient,
name='network.gc.interval' name='network.gc.interval'
) )
wait = list_configurations( wait = Configurations.list(
self.apiclient, self.apiclient,
name='network.gc.wait' name='network.gc.wait'
) )
@ -2223,15 +2236,18 @@ class TestGuestNetworkShutDown(cloudstackTestCase):
"Stopping all the VM instances for the account: %s" % "Stopping all the VM instances for the account: %s" %
self.account.name) self.account.name)
try:
self.vm_1.stop(self.apiclient) self.vm_1.stop(self.apiclient)
self.vm_2.stop(self.apiclient) self.vm_2.stop(self.apiclient)
except Exception as e:
self.fail("Failed to stop instance: %s" % e)
self.debug("Sleep for network.gc.interval + network.gc.wait") self.debug("Sleep for network.gc.interval + network.gc.wait")
interval = list_configurations( interval = Configurations.list(
self.apiclient, self.apiclient,
name='network.gc.interval' name='network.gc.interval'
) )
wait = list_configurations( wait = Configurations.list(
self.apiclient, self.apiclient,
name='network.gc.wait' name='network.gc.wait'
) )
@ -2529,7 +2545,7 @@ class TestServiceProvider(cloudstackTestCase):
cls.netscaler_provider = nw_service_providers[0] cls.netscaler_provider = nw_service_providers[0]
if cls.netscaler_provider.state != 'Enabled': if cls.netscaler_provider.state != 'Enabled':
response = NetworkServiceProvider.update( NetworkServiceProvider.update(
cls.api_client, cls.api_client,
id=cls.netscaler_provider.id, id=cls.netscaler_provider.id,
state='Enabled' state='Enabled'
@ -2586,11 +2602,11 @@ class TestServiceProvider(cloudstackTestCase):
self.debug("Cleaning up the resources") self.debug("Cleaning up the resources")
#Clean up, terminate the created network offerings #Clean up, terminate the created network offerings
cleanup_resources(self.apiclient, self.cleanup) cleanup_resources(self.apiclient, self.cleanup)
interval = list_configurations( interval = Configurations.list(
self.apiclient, self.apiclient,
name='network.gc.interval' name='network.gc.interval'
) )
wait = list_configurations( wait = Configurations.list(
self.apiclient, self.apiclient,
name='network.gc.wait' name='network.gc.wait'
) )
@ -2843,7 +2859,7 @@ class TestDeleteNetscaler(cloudstackTestCase):
netscaler_provider = nw_service_providers[0] netscaler_provider = nw_service_providers[0]
if netscaler_provider.state != 'Enabled': if netscaler_provider.state != 'Enabled':
response = NetworkServiceProvider.update( NetworkServiceProvider.update(
cls.api_client, cls.api_client,
id=netscaler_provider.id, id=netscaler_provider.id,
state='Enabled' state='Enabled'
@ -2901,11 +2917,11 @@ class TestDeleteNetscaler(cloudstackTestCase):
self.debug("Cleaning up the resources") self.debug("Cleaning up the resources")
#Clean up, terminate the created network offerings #Clean up, terminate the created network offerings
cleanup_resources(self.apiclient, self.cleanup) cleanup_resources(self.apiclient, self.cleanup)
interval = list_configurations( interval = Configurations.list(
self.apiclient, self.apiclient,
name='network.gc.interval' name='network.gc.interval'
) )
wait = list_configurations( wait = Configurations.list(
self.apiclient, self.apiclient,
name='network.gc.wait' name='network.gc.wait'
) )

View File

@ -18,15 +18,27 @@
""" P1 tests for netscaler load balancing """ P1 tests for netscaler load balancing
""" """
#Import Local Modules #Import Local Modules
import marvin
from nose.plugins.attrib import attr from nose.plugins.attrib import attr
from marvin.cloudstackTestCase import * from marvin.cloudstackTestCase import cloudstackTestCase
from marvin.cloudstackAPI import * from marvin.cloudstackAPI import migrateVirtualMachine
from marvin.lib.utils import * from marvin.lib.utils import (cleanup_resources,
from marvin.lib.base import * random_gen)
from marvin.lib.common import * from marvin.lib.base import (Account,
VirtualMachine,
PublicIPAddress,
LoadBalancerRule,
ServiceOffering,
NetworkOffering,
Host,
Network,
NATRule,
Configurations)
from marvin.lib.common import (get_domain,
get_zone,
get_template,
add_netscaler)
from marvin.sshClient import SshClient from marvin.sshClient import SshClient
import datetime import time
class Services: class Services:
@ -209,11 +221,11 @@ class TestLbSourceNat(cloudstackTestCase):
self.debug("Cleaning up the resources") self.debug("Cleaning up the resources")
#Clean up, terminate the created network offerings #Clean up, terminate the created network offerings
cleanup_resources(self.apiclient, self.cleanup) cleanup_resources(self.apiclient, self.cleanup)
interval = list_configurations( interval = Configurations.list(
self.apiclient, self.apiclient,
name='network.gc.interval' name='network.gc.interval'
) )
wait = list_configurations( wait = Configurations.list(
self.apiclient, self.apiclient,
name='network.gc.wait' name='network.gc.wait'
) )
@ -418,11 +430,11 @@ class TestLbOnIpWithPf(cloudstackTestCase):
self.debug("Cleaning up the resources") self.debug("Cleaning up the resources")
#Clean up, terminate the created network offerings #Clean up, terminate the created network offerings
cleanup_resources(self.apiclient, self.cleanup) cleanup_resources(self.apiclient, self.cleanup)
interval = list_configurations( interval = Configurations.list(
self.apiclient, self.apiclient,
name='network.gc.interval' name='network.gc.interval'
) )
wait = list_configurations( wait = Configurations.list(
self.apiclient, self.apiclient,
name='network.gc.wait' name='network.gc.wait'
) )
@ -630,11 +642,11 @@ class TestPfOnIpWithLb(cloudstackTestCase):
self.debug("Cleaning up the resources") self.debug("Cleaning up the resources")
#Clean up, terminate the created network offerings #Clean up, terminate the created network offerings
cleanup_resources(self.apiclient, self.cleanup) cleanup_resources(self.apiclient, self.cleanup)
interval = list_configurations( interval = Configurations.list(
self.apiclient, self.apiclient,
name='network.gc.interval' name='network.gc.interval'
) )
wait = list_configurations( wait = Configurations.list(
self.apiclient, self.apiclient,
name='network.gc.wait' name='network.gc.wait'
) )
@ -771,7 +783,7 @@ class TestPfOnIpWithLb(cloudstackTestCase):
with self.assertRaises(Exception): with self.assertRaises(Exception):
NATRule.create( NATRule.create(
self.apiclient, self.apiclient,
virtual_machine, virtual_machine_1,
self.services["natrule"], self.services["natrule"],
ipaddressid=ip_with_lb_rule.ipaddress.id ipaddressid=ip_with_lb_rule.ipaddress.id
) )
@ -843,11 +855,11 @@ class TestLbOnNonSourceNat(cloudstackTestCase):
self.debug("Cleaning up the resources") self.debug("Cleaning up the resources")
#Clean up, terminate the created network offerings #Clean up, terminate the created network offerings
cleanup_resources(self.apiclient, self.cleanup) cleanup_resources(self.apiclient, self.cleanup)
interval = list_configurations( interval = Configurations.list(
self.apiclient, self.apiclient,
name='network.gc.interval' name='network.gc.interval'
) )
wait = list_configurations( wait = Configurations.list(
self.apiclient, self.apiclient,
name='network.gc.wait' name='network.gc.wait'
) )
@ -1059,11 +1071,11 @@ class TestAddMultipleVmsLb(cloudstackTestCase):
self.debug("Cleaning up the resources") self.debug("Cleaning up the resources")
#Clean up, terminate the created network offerings #Clean up, terminate the created network offerings
cleanup_resources(self.apiclient, self.cleanup) cleanup_resources(self.apiclient, self.cleanup)
interval = list_configurations( interval = Configurations.list(
self.apiclient, self.apiclient,
name='network.gc.interval' name='network.gc.interval'
) )
wait = list_configurations( wait = Configurations.list(
self.apiclient, self.apiclient,
name='network.gc.wait' name='network.gc.wait'
) )
@ -1338,11 +1350,11 @@ class TestMultipleLbRules(cloudstackTestCase):
self.debug("Cleaning up the resources") self.debug("Cleaning up the resources")
#Clean up, terminate the created network offerings #Clean up, terminate the created network offerings
cleanup_resources(self.apiclient, self.cleanup) cleanup_resources(self.apiclient, self.cleanup)
interval = list_configurations( interval = Configurations.list(
self.apiclient, self.apiclient,
name='network.gc.interval' name='network.gc.interval'
) )
wait = list_configurations( wait = Configurations.list(
self.apiclient, self.apiclient,
name='network.gc.wait' name='network.gc.wait'
) )
@ -1656,11 +1668,11 @@ class TestMultipleLbRulesSameIp(cloudstackTestCase):
self.debug("Cleaning up the resources") self.debug("Cleaning up the resources")
#Clean up, terminate the created network offerings #Clean up, terminate the created network offerings
cleanup_resources(self.apiclient, self.cleanup) cleanup_resources(self.apiclient, self.cleanup)
interval = list_configurations( interval = Configurations.list(
self.apiclient, self.apiclient,
name='network.gc.interval' name='network.gc.interval'
) )
wait = list_configurations( wait = Configurations.list(
self.apiclient, self.apiclient,
name='network.gc.wait' name='network.gc.wait'
) )
@ -2246,7 +2258,7 @@ class TestDeleteCreateLBRule(cloudstackTestCase):
self.debug("Create a new LB rule with different public port") self.debug("Create a new LB rule with different public port")
self.services["lbrule"]["publicport"] = 23 self.services["lbrule"]["publicport"] = 23
lb_rule = LoadBalancerRule.create( LoadBalancerRule.create(
self.apiclient, self.apiclient,
self.services["lbrule"], self.services["lbrule"],
ipaddressid=self.public_ip.ipaddress.id, ipaddressid=self.public_ip.ipaddress.id,
@ -2462,18 +2474,11 @@ class TestVmWithLb(cloudstackTestCase):
# 4. In netscaler, LB rules for this VM still remain configured.But # 4. In netscaler, LB rules for this VM still remain configured.But
# it will be marked as being down # it will be marked as being down
self.debug("Adding instances: %s, %s to LB rule: %s" % ( try:
self.vm_1.name,
self.vm_2.name,
self.lb_rule_1.name))
self.lb_rule_1.assign(self.apiclient, [self.vm_1, self.vm_2]) self.lb_rule_1.assign(self.apiclient, [self.vm_1, self.vm_2])
self.debug("Assigned instances: %s, %s to LB rule: %s" % (
self.vm_1.name,
self.vm_2.name,
self.lb_rule_1.name))
self.debug("Stopping VM instance: %s" % self.vm_2.name)
self.vm_2.stop(self.apiclient) self.vm_2.stop(self.apiclient)
self.debug("Stopped VM: %s" % self.vm_2.name) except Exception as e:
self.fail("Exception occured: %s" % e)
try: try:
self.debug( self.debug(
@ -2642,7 +2647,7 @@ class TestVmWithLb(cloudstackTestCase):
cmd.virtualmachineid = self.vm_2.id cmd.virtualmachineid = self.vm_2.id
self.apiclient.migrateVirtualMachine(cmd) self.apiclient.migrateVirtualMachine(cmd)
list_vm_response = list_virtual_machines( list_vm_response = VirtualMachine.list(
self.apiclient, self.apiclient,
id=self.vm_2.id id=self.vm_2.id
) )
@ -2852,11 +2857,11 @@ class TestVmWithLb(cloudstackTestCase):
self.fail("Exception occured during SSH: %s - %s" % ( self.fail("Exception occured during SSH: %s - %s" % (
self.public_ip_1.ipaddress.ipaddress, self.public_ip_1.ipaddress.ipaddress,
e)) e))
delay = list_configurations( delay = Configurations.list(
self.apiclient, self.apiclient,
name='expunge.delay' name='expunge.delay'
) )
wait = list_configurations( wait = Configurations.list(
self.apiclient, self.apiclient,
name='expunge.interval' name='expunge.interval'
) )

View File

@ -18,15 +18,32 @@
""" P1 tests for multiple netscaler instances """ P1 tests for multiple netscaler instances
""" """
#Import Local Modules #Import Local Modules
import marvin
from nose.plugins.attrib import attr from nose.plugins.attrib import attr
from marvin.cloudstackTestCase import * from marvin.cloudstackTestCase import cloudstackTestCase
from marvin.cloudstackAPI import * #from marvin.cloudstackAPI import *
from marvin.lib.utils import * from marvin.lib.utils import (cleanup_resources)
from marvin.lib.base import * from marvin.lib.base import (NATRule,
from marvin.lib.common import * LoadBalancerRule,
from marvin.sshClient import SshClient FireWallRule,
import datetime PublicIPAddress,
VirtualMachine,
Network,
Account,
NetScaler,
PhysicalNetwork,
NetworkServiceProvider,
NetworkOffering,
Vpn,
Zone,
ServiceOffering,
Configurations
)
from marvin.lib.common import (get_domain,
get_zone,
get_template,
add_netscaler,
)
import time
class Services: class Services:
@ -540,7 +557,7 @@ class TestNetScalerSharedMode(cloudstackTestCase):
netscaler_provider = nw_service_providers[0] netscaler_provider = nw_service_providers[0]
if netscaler_provider.state != 'Enabled': if netscaler_provider.state != 'Enabled':
response = NetworkServiceProvider.update( NetworkServiceProvider.update(
cls.api_client, cls.api_client,
id=netscaler_provider.id, id=netscaler_provider.id,
state='Enabled' state='Enabled'
@ -767,7 +784,7 @@ class TestNetScalerSharedMode(cloudstackTestCase):
with self.assertRaises(Exception): with self.assertRaises(Exception):
# Spawn an instance in that network # Spawn an instance in that network
virtual_machine_3 = VirtualMachine.create( VirtualMachine.create(
self.apiclient, self.apiclient,
self.services["virtual_machine"], self.services["virtual_machine"],
accountid=self.account_3.name, accountid=self.account_3.name,
@ -955,7 +972,7 @@ class TestNetScalerSharedMode(cloudstackTestCase):
with self.assertRaises(Exception): with self.assertRaises(Exception):
# Spawn an instance in that network # Spawn an instance in that network
virtual_machine_5 = VirtualMachine.create( VirtualMachine.create(
self.apiclient, self.apiclient,
self.services["virtual_machine"], self.services["virtual_machine"],
accountid=self.account_5.name, accountid=self.account_5.name,
@ -983,14 +1000,10 @@ class TestNetScalerSharedMode(cloudstackTestCase):
self.account_4.delete(self.apiclient) self.account_4.delete(self.apiclient)
self.debug("Account: %s is deleted" % self.account_4.name) self.debug("Account: %s is deleted" % self.account_4.name)
interval = list_configurations( interval = Configurations.list(self.apiclient,
self.apiclient, name='network.gc.interval')
name='network.gc.interval' wait = Configurations.list(self.apiclient,
) name='network.gc.wait')
wait = list_configurations(
self.apiclient,
name='network.gc.wait'
)
self.debug("Sleeping for: network.gc.interval + network.gc.wait") self.debug("Sleeping for: network.gc.interval + network.gc.wait")
# Sleep to ensure that all resources are deleted # Sleep to ensure that all resources are deleted
time.sleep(int(interval[0].value) + int(wait[0].value)) time.sleep(int(interval[0].value) + int(wait[0].value))
@ -1084,7 +1097,7 @@ class TestNwOffDedicatedNetscaler(cloudstackTestCase):
netscaler_provider = nw_service_providers[0] netscaler_provider = nw_service_providers[0]
if netscaler_provider.state != 'Enabled': if netscaler_provider.state != 'Enabled':
response = NetworkServiceProvider.update( NetworkServiceProvider.update(
cls.api_client, cls.api_client,
id=netscaler_provider.id, id=netscaler_provider.id,
state='Enabled' state='Enabled'
@ -1135,11 +1148,11 @@ class TestNwOffDedicatedNetscaler(cloudstackTestCase):
self.debug("Cleaning up the resources") self.debug("Cleaning up the resources")
#Clean up, terminate the created network offerings #Clean up, terminate the created network offerings
cleanup_resources(self.apiclient, self.cleanup) cleanup_resources(self.apiclient, self.cleanup)
interval = list_configurations( interval = Configurations.list(
self.apiclient, self.apiclient,
name='network.gc.interval' name='network.gc.interval'
) )
wait = list_configurations( wait = Configurations.list(
self.apiclient, self.apiclient,
name='network.gc.wait' name='network.gc.wait'
) )
@ -1256,7 +1269,7 @@ class TestNwOffNetscaler(cloudstackTestCase):
netscaler_provider = nw_service_providers[0] netscaler_provider = nw_service_providers[0]
if netscaler_provider.state != 'Enabled': if netscaler_provider.state != 'Enabled':
response = NetworkServiceProvider.update( NetworkServiceProvider.update(
cls.api_client, cls.api_client,
id=netscaler_provider.id, id=netscaler_provider.id,
state='Enabled' state='Enabled'
@ -1326,11 +1339,11 @@ class TestNwOffNetscaler(cloudstackTestCase):
self.debug("Cleaning up the resources") self.debug("Cleaning up the resources")
#Clean up, terminate the created network offerings #Clean up, terminate the created network offerings
cleanup_resources(self.apiclient, self.cleanup) cleanup_resources(self.apiclient, self.cleanup)
interval = list_configurations( interval = Configurations.list(
self.apiclient, self.apiclient,
name='network.gc.interval' name='network.gc.interval'
) )
wait = list_configurations( wait = Configurations.list(
self.apiclient, self.apiclient,
name='network.gc.wait' name='network.gc.wait'
) )
@ -1386,14 +1399,13 @@ class TestNwOffNetscaler(cloudstackTestCase):
zoneid=self.zone.id zoneid=self.zone.id
) )
self.debug("Deploying VM in account: %s" % self.account_1.name) self.debug("Deploying VM in account: %s" % self.account_1.name)
virtual_machine = VirtualMachine.create( VirtualMachine.create(
self.apiclient, self.apiclient,
self.services["virtual_machine"], self.services["virtual_machine"],
accountid=self.account_1.name, accountid=self.account_1.name,
domainid=self.account_1.domainid, domainid=self.account_1.domainid,
serviceofferingid=self.service_offering.id, serviceofferingid=self.service_offering.id,
networkids=[str(self.network.id)] networkids=[str(self.network.id)])
)
# Creating network using the network offering created # Creating network using the network offering created
self.debug("Creating different network with network offering: %s" % self.debug("Creating different network with network offering: %s" %
self.network_offering.id) self.network_offering.id)
@ -1421,14 +1433,12 @@ class TestNwOffNetscaler(cloudstackTestCase):
self.debug("Deleting account: %s" % self.account_1.name) self.debug("Deleting account: %s" % self.account_1.name)
self.account_1.delete(self.apiclient) self.account_1.delete(self.apiclient)
self.debug("Account: %s deleted!" % self.account_1.name) self.debug("Account: %s deleted!" % self.account_1.name)
interval = list_configurations( interval = Configurations.list(
self.apiclient, self.apiclient,
name='network.gc.interval' name='network.gc.interval'
) )
wait = list_configurations( wait = Configurations.list(self.apiclient,
self.apiclient, name='network.gc.wait')
name='network.gc.wait'
)
self.debug("Sleeping for: network.gc.interval + network.gc.wait") self.debug("Sleeping for: network.gc.interval + network.gc.wait")
# Sleep to ensure that all resources are deleted # Sleep to ensure that all resources are deleted
time.sleep(int(interval[0].value) + int(wait[0].value)) time.sleep(int(interval[0].value) + int(wait[0].value))
@ -1564,7 +1574,7 @@ class TestNwOffSToDUpgrade(cloudstackTestCase):
netscaler_provider = nw_service_providers[0] netscaler_provider = nw_service_providers[0]
if netscaler_provider.state != 'Enabled': if netscaler_provider.state != 'Enabled':
response = NetworkServiceProvider.update( NetworkServiceProvider.update(
cls.api_client, cls.api_client,
id=netscaler_provider.id, id=netscaler_provider.id,
state='Enabled' state='Enabled'
@ -1634,11 +1644,11 @@ class TestNwOffSToDUpgrade(cloudstackTestCase):
self.debug("Cleaning up the resources") self.debug("Cleaning up the resources")
#Clean up, terminate the created network offerings #Clean up, terminate the created network offerings
cleanup_resources(self.apiclient, self.cleanup) cleanup_resources(self.apiclient, self.cleanup)
interval = list_configurations( interval = Configurations.list(
self.apiclient, self.apiclient,
name='network.gc.interval' name='network.gc.interval'
) )
wait = list_configurations( wait = Configurations.list(
self.apiclient, self.apiclient,
name='network.gc.wait' name='network.gc.wait'
) )
@ -1823,29 +1833,6 @@ class TestNwOffSToDUpgrade(cloudstackTestCase):
self.account_1.name) self.account_1.name)
virtual_machine_1.stop(self.apiclient) virtual_machine_1.stop(self.apiclient)
list_vm_response = VirtualMachine.list(
self.apiclient,
id=virtual_machine_1.id
)
self.debug(
"Verify listVirtualMachines response for virtual machine: %s" \
% virtual_machine_1.id
)
self.assertEqual(
isinstance(list_vm_response, list),
True,
"Check list response returns a valid list"
)
vm_response = list_vm_response[0]
self.assertEqual(
vm_response.state,
"Stopped",
"VM state should be running after deployment"
)
self.debug("All Vms are in stopped state")
self.debug("Upgrading the network: %s" % self.network_1.id) self.debug("Upgrading the network: %s" % self.network_1.id)
self.network_1.update( self.network_1.update(
self.apiclient, self.apiclient,
@ -1917,7 +1904,7 @@ class TestNwOffSToDUpgrade(cloudstackTestCase):
"Creating LB rule for IP address: %s with round robin algo" % "Creating LB rule for IP address: %s with round robin algo" %
public_ip.ipaddress.ipaddress) public_ip.ipaddress.ipaddress)
lb_rule = LoadBalancerRule.create( LoadBalancerRule.create(
self.apiclient, self.apiclient,
self.services["lbrule"], self.services["lbrule"],
ipaddressid=public_ip.ipaddress.id, ipaddressid=public_ip.ipaddress.id,
@ -1978,7 +1965,7 @@ class TestNwOffDToSUpgrade(cloudstackTestCase):
netscaler_provider = nw_service_providers[0] netscaler_provider = nw_service_providers[0]
if netscaler_provider.state != 'Enabled': if netscaler_provider.state != 'Enabled':
response = NetworkServiceProvider.update( NetworkServiceProvider.update(
cls.api_client, cls.api_client,
id=netscaler_provider.id, id=netscaler_provider.id,
state='Enabled' state='Enabled'
@ -2048,11 +2035,11 @@ class TestNwOffDToSUpgrade(cloudstackTestCase):
self.debug("Cleaning up the resources") self.debug("Cleaning up the resources")
#Clean up, terminate the created network offerings #Clean up, terminate the created network offerings
cleanup_resources(self.apiclient, self.cleanup) cleanup_resources(self.apiclient, self.cleanup)
interval = list_configurations( interval = Configurations.list(
self.apiclient, self.apiclient,
name='network.gc.interval' name='network.gc.interval'
) )
wait = list_configurations( wait = Configurations.list(
self.apiclient, self.apiclient,
name='network.gc.wait' name='network.gc.wait'
) )
@ -2227,29 +2214,6 @@ class TestNwOffDToSUpgrade(cloudstackTestCase):
self.debug("Stopping all VMs in account: %s" % self.account_3.name) self.debug("Stopping all VMs in account: %s" % self.account_3.name)
virtual_machine_3.stop(self.apiclient) virtual_machine_3.stop(self.apiclient)
list_vm_response = VirtualMachine.list(
self.apiclient,
id=virtual_machine_3.id
)
self.debug(
"Verify listVirtualMachines response for virtual machine: %s" \
% virtual_machine_3.id
)
self.assertEqual(
isinstance(list_vm_response, list),
True,
"Check list response returns a valid list"
)
vm_response = list_vm_response[0]
self.assertEqual(
vm_response.state,
"Stopped",
"VM state should be stopped"
)
self.debug("All user VMs stopped")
self.debug("Upgrading the network: %s" % self.network_3.id) self.debug("Upgrading the network: %s" % self.network_3.id)
self.network_3.update( self.network_3.update(
self.apiclient, self.apiclient,
@ -2318,7 +2282,7 @@ class TestNwOffDToSUpgrade(cloudstackTestCase):
"Creating LB rule for IP address: %s with round robin algo" % "Creating LB rule for IP address: %s with round robin algo" %
public_ip.ipaddress.ipaddress) public_ip.ipaddress.ipaddress)
lb_rule = LoadBalancerRule.create( LoadBalancerRule.create(
self.apiclient, self.apiclient,
self.services["lbrule"], self.services["lbrule"],
ipaddressid=public_ip.ipaddress.id, ipaddressid=public_ip.ipaddress.id,
@ -2936,7 +2900,7 @@ class TestNOWithNetscaler(cloudstackTestCase):
# User should be able to enable VPN on source NAT # User should be able to enable VPN on source NAT
self.debug("Created VPN with source NAT IP: %s" % src_nat.ipaddress) self.debug("Created VPN with source NAT IP: %s" % src_nat.ipaddress)
# Assign VPN to source NAT # Assign VPN to source NAT
vpn = Vpn.create( Vpn.create(
self.apiclient, self.apiclient,
src_nat.id, src_nat.id,
account=self.account.name, account=self.account.name,

View File

@ -18,14 +18,23 @@
""" P1 tests for network offering """ P1 tests for network offering
""" """
#Import Local Modules #Import Local Modules
import marvin
from nose.plugins.attrib import attr from nose.plugins.attrib import attr
from marvin.cloudstackTestCase import * from marvin.cloudstackTestCase import cloudstackTestCase
from marvin.cloudstackAPI import * #from marvin.cloudstackAPI import *
from marvin.lib.utils import * from marvin.lib.utils import (cleanup_resources)
from marvin.lib.base import * from marvin.lib.base import (VirtualMachine,
from marvin.lib.common import * Account,
import datetime Network,
LoadBalancerRule,
PublicIPAddress,
FireWallRule,
NATRule,
Vpn,
ServiceOffering,
NetworkOffering)
from marvin.lib.common import (get_domain,
get_zone,
get_template)
class Services: class Services:
@ -700,7 +709,7 @@ class TestNOVirtualRouter(cloudstackTestCase):
# User should be able to enable VPN on source NAT # User should be able to enable VPN on source NAT
self.debug("Created VPN with source NAT IP: %s" % src_nat.ipaddress) self.debug("Created VPN with source NAT IP: %s" % src_nat.ipaddress)
# Assign VPN to source NAT # Assign VPN to source NAT
vpn = Vpn.create( Vpn.create(
self.apiclient, self.apiclient,
src_nat.id, src_nat.id,
account=self.account.name, account=self.account.name,
@ -942,7 +951,7 @@ class TestNetworkUpgrade(cloudstackTestCase):
# Assign VPN to source NAT # Assign VPN to source NAT
self.debug("Enabling VPN on source NAT") self.debug("Enabling VPN on source NAT")
vpn = Vpn.create( Vpn.create(
self.apiclient, self.apiclient,
src_nat.id, src_nat.id,
account=self.account.name, account=self.account.name,
@ -1142,7 +1151,7 @@ class TestNetworkUpgrade(cloudstackTestCase):
# Assign VPN to source NAT # Assign VPN to source NAT
self.debug("Enabling VPN on source NAT") self.debug("Enabling VPN on source NAT")
vpn = Vpn.create( Vpn.create(
self.apiclient, self.apiclient,
src_nat.id, src_nat.id,
account=self.account.name, account=self.account.name,
@ -1262,7 +1271,7 @@ class TestNOWithOnlySourceNAT(cloudstackTestCase):
self.debug("Deploying VM in account: %s on the network %s" % (self.account.name, self.network.id)) self.debug("Deploying VM in account: %s on the network %s" % (self.account.name, self.network.id))
# Spawn an instance in that network # Spawn an instance in that network
virtual_machine = VirtualMachine.create( VirtualMachine.create(
self.apiclient, self.apiclient,
self.services["virtual_machine"], self.services["virtual_machine"],
accountid=self.account.name, accountid=self.account.name,

View File

@ -15,11 +15,32 @@
# specific language governing permissions and limitations # specific language governing permissions and limitations
# under the License. # under the License.
""" Tests for Persistent Networks without running VMs feature""" """ Tests for Persistent Networks without running VMs feature"""
from marvin.cloudstackException import CloudstackAPIException from marvin.lib.utils import (cleanup_resources,
from marvin.lib.utils import * validateList,
from marvin.lib.base import * get_hypervisor_type)
from marvin.lib.common import * from marvin.lib.base import (Account,
import netaddr VPC,
VirtualMachine,
LoadBalancerRule,
Network,
Domain,
Router,
NetworkACL,
PublicIPAddress,
VpcOffering,
ServiceOffering,
Project,
NetworkOffering,
NATRule,
FireWallRule,
Host,
StaticNATRule)
from marvin.lib.common import (get_domain,
get_zone,
get_template,
verifyNetworkState,
add_netscaler,
wait_for_cleanup)
from nose.plugins.attrib import attr from nose.plugins.attrib import attr
from marvin.codes import PASS, FAIL, FAILED from marvin.codes import PASS, FAIL, FAILED
from marvin.sshClient import SshClient from marvin.sshClient import SshClient
@ -1051,15 +1072,9 @@ class TestAssignVirtualMachine(cloudstackTestCase):
networkids=[network.id], networkids=[network.id],
serviceofferingid=self.service_offering.id, serviceofferingid=self.service_offering.id,
accountid=account_1.name,domainid=self.domain.id) accountid=account_1.name,domainid=self.domain.id)
except Exception as e:
self.fail("vm creation failed: %s" % e)
virtual_machine.stop(self.apiclient) virtual_machine.stop(self.apiclient)
vms = VirtualMachine.list(self.apiclient, id=virtual_machine.id)
self.assertEqual(validateList(vms)[0], PASS, "vm list validation failed, vm list is %s" % vms)
self.assertEqual(str(vms[0].state).lower(), "stopped", "vm state should be stopped, it is %s" % vms[0].state)
# Assign virtual machine to different account # Assign virtual machine to different account
virtual_machine.assign_virtual_machine(self.apiclient, account=account_2.name, domainid=self.domain.id) virtual_machine.assign_virtual_machine(self.apiclient, account=account_2.name, domainid=self.domain.id)
@ -1069,6 +1084,8 @@ class TestAssignVirtualMachine(cloudstackTestCase):
# Verify that new network is created in other account # Verify that new network is created in other account
networks = Network.list(self.apiclient, account=account_2.name, domainid = account_2.domainid) networks = Network.list(self.apiclient, account=account_2.name, domainid = account_2.domainid)
self.assertEqual(validateList(networks)[0], PASS, "networks list validation failed, list is %s" % networks) self.assertEqual(validateList(networks)[0], PASS, "networks list validation failed, list is %s" % networks)
except Exception as e:
self.fail("Exception occured: %s" % e)
return return
@ddt @ddt

View File

@ -18,7 +18,7 @@
""" """
#Import Local Modules #Import Local Modules
from nose.plugins.attrib import attr from nose.plugins.attrib import attr
from marvin.cloudstackTestCase import cloudstackTestCase, unittest from marvin.cloudstackTestCase import cloudstackTestCase
from marvin.lib.base import (VirtualMachine, from marvin.lib.base import (VirtualMachine,
Account, Account,
Project, Project,
@ -458,7 +458,6 @@ class TestNetwork(cloudstackTestCase):
True, True,
"Check for the valid network list response" "Check for the valid network list response"
) )
network_response = networks[0]
self.debug("Deploying VM with network: %s" % network.id) self.debug("Deploying VM with network: %s" % network.id)
@ -631,6 +630,7 @@ class TestTemplates(cloudstackTestCase):
# 3. Verify that template created in project can be used in project # 3. Verify that template created in project can be used in project
# without any restrictions # without any restrictions
try:
self.debug("Deploying VM for with public template: %s" % self.debug("Deploying VM for with public template: %s" %
self.template.id) self.template.id)
virtual_machine_1 = VirtualMachine.create( virtual_machine_1 = VirtualMachine.create(
@ -678,6 +678,8 @@ class TestTemplates(cloudstackTestCase):
True, True,
"Check Template is in ready state or not" "Check Template is in ready state or not"
) )
except Exception as e:
self.fail("Exception occured: %s" % e)
return return
@attr(tags=["advanced", "basic", "sg", "eip", "advancedns", "selfservice"]) @attr(tags=["advanced", "basic", "sg", "eip", "advancedns", "selfservice"])
@ -690,6 +692,7 @@ class TestTemplates(cloudstackTestCase):
# be granted to the Project (use API 'updateTemplatePermissions' # be granted to the Project (use API 'updateTemplatePermissions'
# with project id to achieve that). # with project id to achieve that).
try:
self.debug("Deploying VM for with public template: %s" % self.debug("Deploying VM for with public template: %s" %
self.template.id) self.template.id)
virtual_machine_1 = VirtualMachine.create( virtual_machine_1 = VirtualMachine.create(
@ -701,12 +704,9 @@ class TestTemplates(cloudstackTestCase):
) )
self.cleanup.append(virtual_machine_1) self.cleanup.append(virtual_machine_1)
# Verify VM state # Verify VM state
self.assertEqual( self.assertEqual(virtual_machine_1.state,
virtual_machine_1.state,
'Running', 'Running',
"Check VM state is Running or not" "Check VM state is Running or not")
)
self.debug("Stopping the VM: %s" % virtual_machine_1.id)
virtual_machine_1.stop(self.apiclient) virtual_machine_1.stop(self.apiclient)
# Get the Root disk of VM # Get the Root disk of VM
volumes = list_volumes( volumes = list_volumes(
@ -767,6 +767,8 @@ class TestTemplates(cloudstackTestCase):
'Running', 'Running',
"Check VM state is Running or not" "Check VM state is Running or not"
) )
except Exception as e:
self.fail("Exception occured: %s" % e)
return return
@ -882,7 +884,6 @@ class TestSnapshots(cloudstackTestCase):
True, True,
"Check for list volume response return valid data" "Check for list volume response return valid data"
) )
volume = volumes[0]
self.debug("Creating snapshot from volume: %s" % volumes[0].id) self.debug("Creating snapshot from volume: %s" % volumes[0].id)
# Create a snapshot from the ROOTDISK # Create a snapshot from the ROOTDISK

View File

@ -17,16 +17,29 @@
""" P1 tests for Snapshots """ P1 tests for Snapshots
""" """
#Import Local Modules #Import Local Modules
import marvin
from nose.plugins.attrib import attr from nose.plugins.attrib import attr
from marvin.cloudstackTestCase import * from marvin.cloudstackTestCase import cloudstackTestCase, unittest
from marvin.cloudstackAPI import * from marvin.cloudstackAPI import deleteVolume
from marvin.lib.utils import * from marvin.lib.utils import (cleanup_resources)
from marvin.lib.base import * from marvin.lib.base import (Project,
from marvin.lib.common import * VirtualMachine,
from marvin.sshClient import SshClient Account,
import datetime Network,
PublicIPAddress,
NATRule,
ServiceOffering,
Vpn,
VpnUser,
Snapshot,
ImageStore,
DiskOffering,
LoadBalancerRule,
Template,
Iso)
from marvin.lib.common import (get_domain,
get_zone,
get_template,
list_volumes)
class Services: class Services:
"""Test Snapshots Services """Test Snapshots Services
@ -204,14 +217,19 @@ class TestVmUsage(cloudstackTestCase):
# VM.Destroy and volume .delete Event for the created account # VM.Destroy and volume .delete Event for the created account
# 4. Delete the account # 4. Delete the account
try:
self.debug("Stopping the VM: %s" % self.virtual_machine.id) self.debug("Stopping the VM: %s" % self.virtual_machine.id)
# Stop the VM # Stop the VM
self.virtual_machine.stop(self.apiclient) self.virtual_machine.stop(self.apiclient)
except Exception as e:
self.fail("Failed to stop VM: %s" % e)
time.sleep(self.services["sleep"]) try:
# Destroy the VM # Destroy the VM
self.debug("Destroying the VM: %s" % self.virtual_machine.id) self.debug("Destroying the VM: %s" % self.virtual_machine.id)
self.virtual_machine.delete(self.apiclient) self.virtual_machine.delete(self.apiclient)
except Exception as e:
self.fail("Failed to delete VM: %s" % e)
# Fetch project account ID from project UUID # Fetch project account ID from project UUID
self.debug( self.debug(
@ -574,7 +592,10 @@ class TestVolumeUsage(cloudstackTestCase):
# Stop VM # Stop VM
self.debug("Stopping VM with ID: %s" % self.virtual_machine.id) self.debug("Stopping VM with ID: %s" % self.virtual_machine.id)
try:
self.virtual_machine.stop(self.apiclient) self.virtual_machine.stop(self.apiclient)
except Exception as e:
self.fail("Failed to stop VM: %s" % e)
volume_response = list_volumes( volume_response = list_volumes(
self.apiclient, self.apiclient,
@ -594,7 +615,10 @@ class TestVolumeUsage(cloudstackTestCase):
data_volume.id, data_volume.id,
self.virtual_machine.id self.virtual_machine.id
)) ))
try:
self.virtual_machine.detach_volume(self.apiclient, data_volume) self.virtual_machine.detach_volume(self.apiclient, data_volume)
except Exception as e:
self.fail("Failed to detach volume: %s" % e)
# Delete Data disk # Delete Data disk
self.debug("Delete volume ID: %s" % data_volume.id) self.debug("Delete volume ID: %s" % data_volume.id)
@ -680,11 +704,14 @@ class TestTemplateUsage(cloudstackTestCase):
cls.services["ostype"] cls.services["ostype"]
) )
cls.services["server"]["zoneid"] = cls.zone.id cls.services["server"]["zoneid"] = cls.zone.id
cls._cleanup = []
try:
cls.account = Account.create( cls.account = Account.create(
cls.api_client, cls.api_client,
cls.services["account"], cls.services["account"],
domainid=cls.domain.id domainid=cls.domain.id
) )
cls._cleanup.append(cls.account)
cls.services["account"] = cls.account.name cls.services["account"] = cls.account.name
cls.project = Project.create( cls.project = Project.create(
@ -693,11 +720,10 @@ class TestTemplateUsage(cloudstackTestCase):
account=cls.account.name, account=cls.account.name,
domainid=cls.account.domainid domainid=cls.account.domainid
) )
cls._cleanup.append(cls.account)
cls.service_offering = ServiceOffering.create( cls.service_offering = ServiceOffering.create(
cls.api_client, cls.api_client,
cls.services["service_offering"] cls.services["service_offering"])
)
#create virtual machine #create virtual machine
cls.virtual_machine = VirtualMachine.create( cls.virtual_machine = VirtualMachine.create(
cls.api_client, cls.api_client,
@ -710,8 +736,6 @@ class TestTemplateUsage(cloudstackTestCase):
#Stop virtual machine #Stop virtual machine
cls.virtual_machine.stop(cls.api_client) cls.virtual_machine.stop(cls.api_client)
#Wait before server has be successfully stopped
time.sleep(30)
list_volume = list_volumes( list_volume = list_volumes(
cls.api_client, cls.api_client,
projectid=cls.project.id, projectid=cls.project.id,
@ -722,10 +746,9 @@ class TestTemplateUsage(cloudstackTestCase):
cls.volume = list_volume[0] cls.volume = list_volume[0]
else: else:
raise Exception("List Volumes failed!") raise Exception("List Volumes failed!")
cls._cleanup = [ except Exception as e:
cls.project, cls.tearDownClass()
cls.account, raise unittest.SkipTest("Failed during setUpClass: %s" % e)
]
return return
@classmethod @classmethod
@ -1271,8 +1294,6 @@ class TestSnapshotUsage(cloudstackTestCase):
"Check if list volumes return a valid data" "Check if list volumes return a valid data"
) )
volume = volumes[0]
# Create a snapshot from the ROOTDISK # Create a snapshot from the ROOTDISK
self.debug("Creating snapshot from volume: %s" % volumes[0].id) self.debug("Creating snapshot from volume: %s" % volumes[0].id)
snapshot = Snapshot.create(self.apiclient, volumes[0].id) snapshot = Snapshot.create(self.apiclient, volumes[0].id)

View File

@ -16,13 +16,22 @@
# under the License. # under the License.
from nose.plugins.attrib import attr from nose.plugins.attrib import attr
from marvin.lib.base import * from marvin.lib.base import (Account,
from marvin.lib.utils import * Network,
from marvin.lib.common import * ServiceOffering,
NetworkOffering,
VirtualMachine,
Router,
Configurations)
from marvin.lib.utils import cleanup_resources
from marvin.lib.common import (get_domain,
get_zone,
get_template)
#Import Local Modules #Import Local Modules
from marvin.cloudstackTestCase import cloudstackTestCase from marvin.cloudstackTestCase import cloudstackTestCase
from marvin.cloudstackAPI import * from marvin.cloudstackAPI import startRouter
import time
class Services: class Services:
"""Test Services for customer defects """Test Services for customer defects
@ -304,13 +313,6 @@ class TestRedundantRouterNetworkCleanups(cloudstackTestCase):
"Length of the list router should be 2 (Backup & master)" "Length of the list router should be 2 (Backup & master)"
) )
if routers[0].redundantstate == 'MASTER':
master_router = routers[0]
backup_router = routers[1]
else:
master_router = routers[1]
backup_router = routers[0]
self.debug("restarting network with cleanup=False") self.debug("restarting network with cleanup=False")
try: try:
network.restart(self.apiclient, cleanup=False) network.restart(self.apiclient, cleanup=False)
@ -445,13 +447,6 @@ class TestRedundantRouterNetworkCleanups(cloudstackTestCase):
"Length of the list router should be 2 (Backup & master)" "Length of the list router should be 2 (Backup & master)"
) )
if routers[0].redundantstate == 'MASTER':
master_router = routers[0]
backup_router = routers[1]
else:
master_router = routers[1]
backup_router = routers[0]
self.debug("restarting network with cleanup=True") self.debug("restarting network with cleanup=True")
try: try:
network.restart(self.apiclient, cleanup=True) network.restart(self.apiclient, cleanup=True)
@ -597,12 +592,12 @@ class TestRedundantRouterNetworkCleanups(cloudstackTestCase):
self.fail("Failed to stop guest Vm: %s - %s" % self.fail("Failed to stop guest Vm: %s - %s" %
(virtual_machine.name, e)) (virtual_machine.name, e))
interval = list_configurations( interval = Configurations(
self.apiclient, self.apiclient,
name='network.gc.interval' name='network.gc.interval'
) )
delay = int(interval[0].value) delay = int(interval[0].value)
interval = list_configurations( interval = Configurations.list(
self.apiclient, self.apiclient,
name='network.gc.wait' name='network.gc.wait'
) )

View File

@ -24,12 +24,11 @@ from marvin.lib.base import (VirtualMachine,
Account, Account,
Template, Template,
ServiceOffering, ServiceOffering,
EgressFireWallRule) EgressFireWallRule,
Volume)
from marvin.lib.common import (get_domain, from marvin.lib.common import (get_domain,
get_zone, get_zone,
get_template, get_template)
list_virtual_machines,
list_volumes)
from marvin.lib.utils import (cleanup_resources, from marvin.lib.utils import (cleanup_resources,
random_gen, random_gen,
validateList) validateList)
@ -136,17 +135,19 @@ class TestResetSSHKeypair(cloudstackTestCase):
cls.services["virtual_machine"]["zoneid"] = cls.zone.id cls.services["virtual_machine"]["zoneid"] = cls.zone.id
cls.services["virtual_machine"]["template"] = template.id cls.services["virtual_machine"]["template"] = template.id
cls._cleanup = []
try:
# Create VMs, NAT Rules etc # Create VMs, NAT Rules etc
cls.account = Account.create( cls.account = Account.create(
cls.api_client, cls.api_client,
cls.services["account"], cls.services["account"],
domainid=domain.id domainid=domain.id)
) cls._cleanup.append(cls.account)
cls.service_offering = ServiceOffering.create( cls.service_offering = ServiceOffering.create(
cls.api_client, cls.api_client,
cls.services["service_offering"] cls.services["service_offering"])
) cls._cleanup.append(cls.service_offering)
cls.virtual_machine = VirtualMachine.create( cls.virtual_machine = VirtualMachine.create(
cls.api_client, cls.api_client,
@ -154,8 +155,7 @@ class TestResetSSHKeypair(cloudstackTestCase):
accountid=cls.account.name, accountid=cls.account.name,
domainid=cls.account.domainid, domainid=cls.account.domainid,
serviceofferingid=cls.service_offering.id, serviceofferingid=cls.service_offering.id,
mode=cls.services["mode"] mode=cls.services["mode"])
)
networkid = cls.virtual_machine.nic[0].networkid networkid = cls.virtual_machine.nic[0].networkid
@ -189,41 +189,17 @@ class TestResetSSHKeypair(cloudstackTestCase):
"chkconfig --add cloud-set-guest-sshkey.in" "chkconfig --add cloud-set-guest-sshkey.in"
] ]
for c in cmds: for c in cmds:
result = ssh.execute(c) ssh.execute(c)
#Stop virtual machine #Stop virtual machine
cls.virtual_machine.stop(cls.api_client) cls.virtual_machine.stop(cls.api_client)
# Poll listVM to ensure VM is stopped properly list_volume = Volume.list(
timeout = cls.services["timeout"]
while True:
time.sleep(cls.services["sleep"])
# Ensure that VM is in stopped state
list_vm_response = list_virtual_machines(
cls.api_client,
id=cls.virtual_machine.id
)
if isinstance(list_vm_response, list):
vm = list_vm_response[0]
if vm.state == 'Stopped':
break
if timeout == 0:
raise Exception(
"Failed to stop VM (ID: %s) " %
vm.id)
timeout = timeout - 1
list_volume = list_volumes(
cls.api_client, cls.api_client,
virtualmachineid=cls.virtual_machine.id, virtualmachineid=cls.virtual_machine.id,
type='ROOT', type='ROOT',
listall=True listall=True)
)
if isinstance(list_volume, list): if isinstance(list_volume, list):
cls.volume = list_volume[0] cls.volume = list_volume[0]
else: else:
@ -240,14 +216,12 @@ class TestResetSSHKeypair(cloudstackTestCase):
account=cls.account.name, account=cls.account.name,
domainid=cls.account.domainid domainid=cls.account.domainid
) )
cls._cleanup.append(cls.pw_ssh_enabled_template)
# Delete the VM - No longer needed # Delete the VM - No longer needed
cls.virtual_machine.delete(cls.api_client) cls.virtual_machine.delete(cls.api_client)
except Exception as e:
cls._cleanup = [ cls.tearDownClass()
cls.service_offering, raise unittest.SkipTest("Exception in setUpClass: %s" % e)
cls.pw_ssh_enabled_template,
cls.account
]
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
@ -1026,36 +1000,16 @@ class TestResetSSHKeyUserRights(cloudstackTestCase):
"chkconfig --add cloud-set-guest-sshkey.in" "chkconfig --add cloud-set-guest-sshkey.in"
] ]
for c in cmds: for c in cmds:
result = ssh.execute(c) ssh.execute(c)
try:
#Stop virtual machine #Stop virtual machine
cls.virtual_machine.stop(cls.api_client) cls.virtual_machine.stop(cls.api_client)
except Exception as e:
cls.tearDownClass()
raise unittest.SkipTest("Exception in setUpClass: %s" % e)
# Poll listVM to ensure VM is stopped properly list_volume = Volume.list(
timeout = cls.services["timeout"]
while True:
time.sleep(cls.services["sleep"])
# Ensure that VM is in stopped state
list_vm_response = list_virtual_machines(
cls.api_client,
id=cls.virtual_machine.id
)
if isinstance(list_vm_response, list):
vm = list_vm_response[0]
if vm.state == 'Stopped':
break
if timeout == 0:
raise Exception(
"Failed to stop VM (ID: %s) " %
vm.id)
timeout = timeout - 1
list_volume = list_volumes(
cls.api_client, cls.api_client,
virtualmachineid=cls.virtual_machine.id, virtualmachineid=cls.virtual_machine.id,
type='ROOT', type='ROOT',

View File

@ -747,6 +747,7 @@ class TestResourceLimitsAccount(cloudstackTestCase):
# 3. Try to create 2 templates in account 2. Verify account 2 should be # 3. Try to create 2 templates in account 2. Verify account 2 should be
# able to create template without any error # able to create template without any error
try:
self.debug( self.debug(
"Updating template resource limit for account: %s" % "Updating template resource limit for account: %s" %
self.account_1.name) self.account_1.name)
@ -831,7 +832,8 @@ class TestResourceLimitsAccount(cloudstackTestCase):
True, True,
"Check Template is in ready state or not" "Check Template is in ready state or not"
) )
except Exception as e:
self.fail("Exception occured: %s" % e)
# Exception should be raised for second snapshot (account_1) # Exception should be raised for second snapshot (account_1)
with self.assertRaises(Exception): with self.assertRaises(Exception):
Template.create( Template.create(
@ -841,6 +843,8 @@ class TestResourceLimitsAccount(cloudstackTestCase):
account=self.account_1.name, account=self.account_1.name,
domainid=self.account_1.domainid, domainid=self.account_1.domainid,
) )
try:
virtual_machine_2.stop(self.apiclient) virtual_machine_2.stop(self.apiclient)
# Get the Root disk of VM # Get the Root disk of VM
volumes = list_volumes( volumes = list_volumes(
@ -892,6 +896,8 @@ class TestResourceLimitsAccount(cloudstackTestCase):
True, True,
"Check Template is in ready state or not" "Check Template is in ready state or not"
) )
except Exception as e:
self.fail("Exception occured: %s" % e)
return return
@ -1256,6 +1262,7 @@ class TestResourceLimitsDomain(cloudstackTestCase):
# 4. Try create 3rd template in the domain. It should give the user an # 4. Try create 3rd template in the domain. It should give the user an
# appropriate error and an alert should be generated. # appropriate error and an alert should be generated.
try:
# Set usage_vm=1 for Account 1 # Set usage_vm=1 for Account 1
update_resource_limit( update_resource_limit(
self.apiclient, self.apiclient,
@ -1264,9 +1271,6 @@ class TestResourceLimitsDomain(cloudstackTestCase):
max=5 max=5
) )
self.debug(
"Updating template resource limits for domain: %s" %
self.account.domainid)
# Set usage_vm=1 for Account 1 # Set usage_vm=1 for Account 1
update_resource_limit( update_resource_limit(
self.apiclient, self.apiclient,
@ -1274,8 +1278,6 @@ class TestResourceLimitsDomain(cloudstackTestCase):
domainid=self.account.domainid, domainid=self.account.domainid,
max=2 max=2
) )
self.debug("Deploying VM for account: %s" % self.account.name)
virtual_machine_1 = VirtualMachine.create( virtual_machine_1 = VirtualMachine.create(
self.apiclient, self.apiclient,
self.services["server"], self.services["server"],
@ -1340,6 +1342,8 @@ class TestResourceLimitsDomain(cloudstackTestCase):
True, True,
"Check Template is in ready state or not" "Check Template is in ready state or not"
) )
except Exception as e:
self.fail("Exception occured: %s" % e)
# Exception should be raised for second template # Exception should be raised for second template
with self.assertRaises(Exception): with self.assertRaises(Exception):

View File

@ -18,13 +18,21 @@
""" P1 for Security groups """ P1 for Security groups
""" """
#Import Local Modules #Import Local Modules
import marvin
from nose.plugins.attrib import attr from nose.plugins.attrib import attr
from marvin.cloudstackTestCase import * from marvin.cloudstackTestCase import cloudstackTestCase
from marvin.cloudstackAPI import * #from marvin.cloudstackAPI import *
from marvin.lib.utils import * from marvin.lib.utils import cleanup_resources
from marvin.lib.base import * from marvin.lib.base import (Account,
from marvin.lib.common import * ServiceOffering,
VirtualMachine,
SecurityGroup,
Router,
Host,
Configurations)
from marvin.lib.common import (get_domain,
get_zone,
get_template,
get_process_status)
from marvin.sshClient import SshClient from marvin.sshClient import SshClient
#Import System modules #Import System modules
@ -186,7 +194,7 @@ class TestDefaultSecurityGroup(cloudstackTestCase):
self.debug("Deployed VM with ID: %s" % self.virtual_machine.id) self.debug("Deployed VM with ID: %s" % self.virtual_machine.id)
self.cleanup.append(self.virtual_machine) self.cleanup.append(self.virtual_machine)
list_vm_response = list_virtual_machines( list_vm_response = VirtualMachine.list(
self.apiclient, self.apiclient,
id=self.virtual_machine.id id=self.virtual_machine.id
) )
@ -225,7 +233,7 @@ class TestDefaultSecurityGroup(cloudstackTestCase):
"Verify list routers response for account: %s" \ "Verify list routers response for account: %s" \
% self.account.name % self.account.name
) )
routers = list_routers( routers = Router.list(
self.apiclient, self.apiclient,
zoneid=self.zone.id, zoneid=self.zone.id,
listall=True listall=True
@ -300,7 +308,7 @@ class TestDefaultSecurityGroup(cloudstackTestCase):
self.debug("Deployed VM with ID: %s" % self.virtual_machine.id) self.debug("Deployed VM with ID: %s" % self.virtual_machine.id)
self.cleanup.append(self.virtual_machine) self.cleanup.append(self.virtual_machine)
list_vm_response = list_virtual_machines( list_vm_response = VirtualMachine.list(
self.apiclient, self.apiclient,
id=self.virtual_machine.id id=self.virtual_machine.id
) )
@ -362,7 +370,7 @@ class TestDefaultSecurityGroup(cloudstackTestCase):
# SSH Attempt to VM should fail # SSH Attempt to VM should fail
with self.assertRaises(Exception): with self.assertRaises(Exception):
self.debug("SSH into VM: %s" % self.virtual_machine.ssh_ip) self.debug("SSH into VM: %s" % self.virtual_machine.ssh_ip)
ssh = SshClient( SshClient(
self.virtual_machine.ssh_ip, self.virtual_machine.ssh_ip,
self.virtual_machine.ssh_port, self.virtual_machine.ssh_port,
self.virtual_machine.username, self.virtual_machine.username,
@ -651,7 +659,7 @@ class TestRevokeIngressRule(cloudstackTestCase):
self.debug("Revoking ingress rule for sec group ID: %s for ssh access" self.debug("Revoking ingress rule for sec group ID: %s for ssh access"
% security_group.id) % security_group.id)
# Revoke Security group to SSH to VM # Revoke Security group to SSH to VM
result = security_group.revoke( security_group.revoke(
self.apiclient, self.apiclient,
id=ssh_rule["ruleid"] id=ssh_rule["ruleid"]
) )
@ -752,7 +760,7 @@ class TestDhcpOnlyRouter(cloudstackTestCase):
#2. The only service supported by this router should be dhcp #2. The only service supported by this router should be dhcp
# Find router associated with user account # Find router associated with user account
list_router_response = list_routers( list_router_response = Router.list(
self.apiclient, self.apiclient,
zoneid=self.zone.id, zoneid=self.zone.id,
listall=True listall=True
@ -764,7 +772,7 @@ class TestDhcpOnlyRouter(cloudstackTestCase):
) )
router = list_router_response[0] router = list_router_response[0]
hosts = list_hosts( hosts = Host.list(
self.apiclient, self.apiclient,
zoneid=router.zoneid, zoneid=router.zoneid,
type='Routing', type='Routing',
@ -886,7 +894,7 @@ class TestdeployVMWithUserData(cloudstackTestCase):
# router for this VM # router for this VM
# Find router associated with user account # Find router associated with user account
list_router_response = list_routers( list_router_response = Router.list(
self.apiclient, self.apiclient,
zoneid=self.zone.id, zoneid=self.zone.id,
listall=True listall=True
@ -1201,7 +1209,7 @@ class TestDeleteSecurityGroup(cloudstackTestCase):
# Destroy the VM # Destroy the VM
self.virtual_machine.delete(self.apiclient) self.virtual_machine.delete(self.apiclient)
config = list_configurations( config = Configurations.list(
self.apiclient, self.apiclient,
name='expunge.delay' name='expunge.delay'
) )
@ -1220,8 +1228,8 @@ class TestDeleteSecurityGroup(cloudstackTestCase):
self.debug("Deleting Security Group: %s" % security_group.id) self.debug("Deleting Security Group: %s" % security_group.id)
security_group.delete(self.apiclient) security_group.delete(self.apiclient)
except Exception as e: except Exception as e:
self.fail("Failed to delete security group - ID: %s" \ self.fail("Failed to delete security group - ID: %s: %s" \
% security_group.id % (security_group.id, e)
) )
return return
@ -1639,15 +1647,13 @@ class TestIngressRule(cloudstackTestCase):
% ingress_rule["id"] % ingress_rule["id"]
) )
try:
self.virtual_machine.stop(self.apiclient) self.virtual_machine.stop(self.apiclient)
# Sleep to ensure that VM is in stopped state
time.sleep(self.services["sleep"])
self.virtual_machine.start(self.apiclient) self.virtual_machine.start(self.apiclient)
# Sleep to ensure that VM is in running state # Sleep to ensure that VM is in running state
time.sleep(self.services["sleep"]) time.sleep(self.services["sleep"])
except Exception as e:
self.fail("Exception occured: %s" % e)
# SSH should be allowed on 22 port after restart # SSH should be allowed on 22 port after restart
try: try:

View File

@ -18,13 +18,27 @@
""" P1 for stopped Virtual Maschine life cycle """ P1 for stopped Virtual Maschine life cycle
""" """
#Import Local Modules #Import Local Modules
import marvin
from nose.plugins.attrib import attr from nose.plugins.attrib import attr
from marvin.cloudstackTestCase import * from marvin.cloudstackTestCase import cloudstackTestCase
from marvin.cloudstackAPI import * #from marvin.cloudstackAPI import *
from marvin.lib.utils import * from marvin.lib.utils import cleanup_resources
from marvin.lib.base import * from marvin.lib.base import (Account,
from marvin.lib.common import * VirtualMachine,
ServiceOffering,
Volume,
Router,
DiskOffering,
Host,
Iso,
Cluster,
StoragePool,
Configurations,
Template)
from marvin.lib.common import (get_zone,
get_domain,
get_template,
get_builtin_template_info,
update_resource_limit)
#Import System modules #Import System modules
import time import time
@ -194,7 +208,7 @@ class TestDeployVM(cloudstackTestCase):
self.debug("Deployed instance in account: %s" % self.debug("Deployed instance in account: %s" %
self.account.name) self.account.name)
list_vm_response = list_virtual_machines( list_vm_response = VirtualMachine.list(
self.apiclient, self.apiclient,
id=self.virtual_machine.id id=self.virtual_machine.id
) )
@ -245,7 +259,7 @@ class TestDeployVM(cloudstackTestCase):
self.debug("Deployed instance in account: %s" % self.debug("Deployed instance in account: %s" %
self.account.name) self.account.name)
list_vm_response = list_virtual_machines( list_vm_response = VirtualMachine.list(
self.apiclient, self.apiclient,
id=self.virtual_machine.id id=self.virtual_machine.id
) )
@ -297,7 +311,7 @@ class TestDeployVM(cloudstackTestCase):
self.debug("Deployed instance in account: %s" % self.debug("Deployed instance in account: %s" %
self.account.name) self.account.name)
list_vm_response = list_virtual_machines( list_vm_response = VirtualMachine.list(
self.apiclient, self.apiclient,
id=self.virtual_machine.id id=self.virtual_machine.id
) )
@ -340,17 +354,17 @@ class TestDeployVM(cloudstackTestCase):
) )
self.debug("Instance destroyed..waiting till expunge interval") self.debug("Instance destroyed..waiting till expunge interval")
interval = list_configurations( interval = Configurations.list(
self.apiclient, self.apiclient,
name='expunge.interval' name='expunge.interval'
) )
delay = list_configurations( delay = Configurations.list(
self.apiclient, self.apiclient,
name='expunge.delay' name='expunge.delay'
) )
# Sleep to ensure that all resources are deleted # Sleep to ensure that all resources are deleted
time.sleep((int(interval[0].value) + int(delay[0].value))) time.sleep((int(interval[0].value) + int(delay[0].value)))
list_vm_response = list_virtual_machines( list_vm_response = VirtualMachine.list(
self.apiclient, self.apiclient,
id=self.virtual_machine.id id=self.virtual_machine.id
) )
@ -387,7 +401,7 @@ class TestDeployVM(cloudstackTestCase):
self.debug("Deployed instance in account: %s" % self.debug("Deployed instance in account: %s" %
self.account.name) self.account.name)
list_vm_response = list_virtual_machines( list_vm_response = VirtualMachine.list(
self.apiclient, self.apiclient,
id=self.virtual_machine.id id=self.virtual_machine.id
) )
@ -425,7 +439,7 @@ class TestDeployVM(cloudstackTestCase):
try: try:
self.virtual_machine.attach_volume(self.apiclient, volume) self.virtual_machine.attach_volume(self.apiclient, volume)
except Exception as e: except Exception as e:
self.fail("Attach volume failed!") self.fail("Attach volume failed with Exception: %s" % e)
return return
@attr(tags=["advanced", "eip", "advancedns", "basic", "sg", "selfservice"]) @attr(tags=["advanced", "eip", "advancedns", "basic", "sg", "selfservice"])
@ -452,7 +466,7 @@ class TestDeployVM(cloudstackTestCase):
self.debug("Deployed instance in account: %s" % self.debug("Deployed instance in account: %s" %
self.account.name) self.account.name)
list_vm_response = list_virtual_machines( list_vm_response = VirtualMachine.list(
self.apiclient, self.apiclient,
id=self.virtual_machine.id id=self.virtual_machine.id
) )
@ -528,7 +542,7 @@ class TestDeployVM(cloudstackTestCase):
self.debug("Deployed instance in account: %s" % self.debug("Deployed instance in account: %s" %
self.account.name) self.account.name)
list_vm_response = list_virtual_machines( list_vm_response = VirtualMachine.list(
self.apiclient, self.apiclient,
id=self.virtual_machine.id id=self.virtual_machine.id
) )
@ -566,7 +580,7 @@ class TestDeployVM(cloudstackTestCase):
try: try:
self.virtual_machine.attach_volume(self.apiclient, volume) self.virtual_machine.attach_volume(self.apiclient, volume)
except Exception as e: except Exception as e:
self.fail("Attach volume failed!") self.fail("Attach volume failed with Exception: %s" % e)
self.debug("Detaching the disk: %s" % volume.name) self.debug("Detaching the disk: %s" % volume.name)
self.virtual_machine.detach_volume(self.apiclient, volume) self.virtual_machine.detach_volume(self.apiclient, volume)
@ -611,7 +625,7 @@ class TestDeployVM(cloudstackTestCase):
self.debug("Deployed instance in account: %s" % self.debug("Deployed instance in account: %s" %
self.account.name) self.account.name)
list_vm_response = list_virtual_machines( list_vm_response = VirtualMachine.list(
self.apiclient, self.apiclient,
id=self.virtual_machine.id id=self.virtual_machine.id
) )
@ -702,7 +716,7 @@ class TestDeployVM(cloudstackTestCase):
self.debug("Deployed instance in account: %s" % self.debug("Deployed instance in account: %s" %
self.account.name) self.account.name)
list_vm_response = list_virtual_machines( list_vm_response = VirtualMachine.list(
self.apiclient, self.apiclient,
id=self.virtual_machine_1.id id=self.virtual_machine_1.id
) )
@ -738,7 +752,7 @@ class TestDeployVM(cloudstackTestCase):
self.debug("Deployed instance in account: %s" % self.debug("Deployed instance in account: %s" %
self.account.name) self.account.name)
list_vm_response = list_virtual_machines( list_vm_response = VirtualMachine.list(
self.apiclient, self.apiclient,
id=self.virtual_machine_2.id id=self.virtual_machine_2.id
) )
@ -868,7 +882,7 @@ class TestDeployVM(cloudstackTestCase):
self.debug("Deployed instance in account: %s" % self.debug("Deployed instance in account: %s" %
self.account.name) self.account.name)
list_vm_response = list_virtual_machines( list_vm_response = VirtualMachine.list(
self.apiclient, self.apiclient,
id=self.virtual_machine.id id=self.virtual_machine.id
) )
@ -889,28 +903,10 @@ class TestDeployVM(cloudstackTestCase):
"Running", "Running",
"VM should be in Running state after deployment" "VM should be in Running state after deployment"
) )
self.debug("Stopping instance: %s" % self.virtual_machine.name) try:
self.virtual_machine.stop(self.apiclient) self.virtual_machine.stop(self.apiclient)
self.debug("Instance is stopped!") except Exception as e:
self.debug( self.fail("failed to stop instance: %s" % e)
"Verify listVirtualMachines response for virtual machine: %s" \
% self.virtual_machine.id
)
list_vm_response = list_virtual_machines(
self.apiclient,
id=self.virtual_machine.id
)
self.assertEqual(
isinstance(list_vm_response, list),
True,
"Check list response returns a valid list"
)
vm_response = list_vm_response[0]
self.assertEqual(
vm_response.state,
"Stopped",
"VM should be in Stopped state after stoping vm"
)
volumes = Volume.list( volumes = Volume.list(
self.apiclient, self.apiclient,
virtualmachineid=self.virtual_machine.id, virtualmachineid=self.virtual_machine.id,
@ -1047,7 +1043,7 @@ class TestDeployHaEnabledVM(cloudstackTestCase):
self.debug("Deployed instance in account: %s" % self.debug("Deployed instance in account: %s" %
self.account.name) self.account.name)
list_vm_response = list_virtual_machines( list_vm_response = VirtualMachine.list(
self.apiclient, self.apiclient,
id=self.virtual_machine.id id=self.virtual_machine.id
) )
@ -1112,7 +1108,7 @@ class TestDeployHaEnabledVM(cloudstackTestCase):
self.debug("Deployed instance in account: %s" % self.debug("Deployed instance in account: %s" %
self.account.name) self.account.name)
list_vm_response = list_virtual_machines( list_vm_response = VirtualMachine.list(
self.apiclient, self.apiclient,
id=self.virtual_machine.id id=self.virtual_machine.id
) )
@ -1161,7 +1157,7 @@ class TestDeployHaEnabledVM(cloudstackTestCase):
self.debug("Deployed instance in account: %s" % self.debug("Deployed instance in account: %s" %
self.account.name) self.account.name)
list_vm_response = list_virtual_machines( list_vm_response = VirtualMachine.list(
self.apiclient, self.apiclient,
id=self.virtual_machine.id id=self.virtual_machine.id
) )
@ -1278,7 +1274,7 @@ class TestRouterStateAfterDeploy(cloudstackTestCase):
self.debug("Deployed instance in account: %s" % self.debug("Deployed instance in account: %s" %
self.account.name) self.account.name)
list_vm_response = list_virtual_machines( list_vm_response = VirtualMachine.list(
self.apiclient, self.apiclient,
id=self.virtual_machine_1.id id=self.virtual_machine_1.id
) )
@ -1328,7 +1324,7 @@ class TestRouterStateAfterDeploy(cloudstackTestCase):
self.debug("Deployed instance in account: %s" % self.debug("Deployed instance in account: %s" %
self.account.name) self.account.name)
list_vm_response = list_virtual_machines( list_vm_response = VirtualMachine.list(
self.apiclient, self.apiclient,
id=self.virtual_machine_2.id id=self.virtual_machine_2.id
) )
@ -1375,11 +1371,11 @@ class TestRouterStateAfterDeploy(cloudstackTestCase):
self.virtual_machine_2.delete(self.apiclient) self.virtual_machine_2.delete(self.apiclient)
self.debug("Instance destroyed..waiting till expunge interval") self.debug("Instance destroyed..waiting till expunge interval")
interval = list_configurations( interval = Configurations.list(
self.apiclient, self.apiclient,
name='expunge.interval' name='expunge.interval'
) )
delay = list_configurations( delay = Configurations.list(
self.apiclient, self.apiclient,
name='expunge.delay' name='expunge.delay'
) )
@ -1578,7 +1574,7 @@ class TestDeployVMFromTemplate(cloudstackTestCase):
self.debug("Deployed instance in account: %s" % self.debug("Deployed instance in account: %s" %
self.account.name) self.account.name)
list_vm_response = list_virtual_machines( list_vm_response = VirtualMachine.list(
self.apiclient, self.apiclient,
id=self.virtual_machine.id id=self.virtual_machine.id
) )
@ -1605,7 +1601,7 @@ class TestDeployVMFromTemplate(cloudstackTestCase):
self.virtual_machine.start(self.apiclient) self.virtual_machine.start(self.apiclient)
self.debug("Started the instance: %s" % self.virtual_machine.name) self.debug("Started the instance: %s" % self.virtual_machine.name)
list_vm_response = list_virtual_machines( list_vm_response = VirtualMachine.list(
self.apiclient, self.apiclient,
id=self.virtual_machine.id id=self.virtual_machine.id
) )

View File

@ -17,15 +17,31 @@
""" P1 tests for tags """ P1 tests for tags
""" """
#Import Local Modules #Import Local Modules
import marvin
from nose.plugins.attrib import attr from nose.plugins.attrib import attr
from marvin.cloudstackTestCase import * from marvin.cloudstackTestCase import cloudstackTestCase
from marvin.cloudstackAPI import * from marvin.lib.utils import cleanup_resources
from marvin.lib.utils import * from marvin.lib.base import (Tag,
from marvin.lib.base import * Account,
from marvin.lib.common import * VirtualMachine,
import datetime Iso,
Volume,
Network,
Host,
DiskOffering,
NATRule,
PublicIPAddress,
FireWallRule,
LoadBalancerRule,
Vpn,
Template,
Snapshot,
ServiceOffering,
Project)
from marvin.lib.common import (get_zone,
get_domain,
get_template)
from marvin.codes import FAILED
import time
class Services: class Services:
"""Test tags Services """Test tags Services
@ -924,14 +940,14 @@ class TestResourceTags(cloudstackTestCase):
# 1. Create a tag on template/ISO using createTags API # 1. Create a tag on template/ISO using createTags API
# 2. Delete above created tag using deleteTags API # 2. Delete above created tag using deleteTags API
try:
self.debug("Stopping the virtual machine: %s" % self.vm_1.name) self.debug("Stopping the virtual machine: %s" % self.vm_1.name)
#Stop virtual machine #Stop virtual machine
self.vm_1.stop(self.apiclient) self.vm_1.stop(self.apiclient)
except Exception as e:
self.fail("Failed to stop VM: %s" % e)
timeout = self.services["timeout"] timeout = self.services["timeout"]
#Wait before server has be successfully stopped
time.sleep(self.services["sleep"])
while True: while True:
list_volume = Volume.list( list_volume = Volume.list(
self.apiclient, self.apiclient,
@ -991,7 +1007,7 @@ class TestResourceTags(cloudstackTestCase):
'The tag should have original value' 'The tag should have original value'
) )
templates = Template.list( Template.list(
self.apiclient, self.apiclient,
templatefilter=\ templatefilter=\
self.services["template"]["templatefilter"], self.services["template"]["templatefilter"],
@ -1044,10 +1060,8 @@ class TestResourceTags(cloudstackTestCase):
) )
self.debug("ISO created with ID: %s" % iso.id) self.debug("ISO created with ID: %s" % iso.id)
list_iso_response = list_isos( list_iso_response = Iso.list(self.apiclient,
self.apiclient, id=iso.id)
id=iso.id
)
self.assertEqual( self.assertEqual(
isinstance(list_iso_response, list), isinstance(list_iso_response, list),
True, True,
@ -1225,12 +1239,10 @@ class TestResourceTags(cloudstackTestCase):
self.debug("Creating snapshot on ROOT volume for VM: %s " % self.debug("Creating snapshot on ROOT volume for VM: %s " %
self.vm_1.name) self.vm_1.name)
# Get the Root disk of VM # Get the Root disk of VM
volumes = list_volumes( volumes = Volume.list(self.apiclient,
self.apiclient,
virtualmachineid=self.vm_1.id, virtualmachineid=self.vm_1.id,
type='ROOT', type='ROOT',
listall=True listall=True)
)
volume = volumes[0] volume = volumes[0]
# Create a snapshot from the ROOTDISK # Create a snapshot from the ROOTDISK
@ -1238,10 +1250,8 @@ class TestResourceTags(cloudstackTestCase):
self.debug("Snapshot created: ID - %s" % snapshot.id) self.debug("Snapshot created: ID - %s" % snapshot.id)
self.cleanup.append(snapshot) self.cleanup.append(snapshot)
snapshots = list_snapshots( snapshots = Snapshot.list(self.apiclient,
self.apiclient, id=snapshot.id)
id=snapshot.id
)
self.assertEqual( self.assertEqual(
isinstance(snapshots, list), isinstance(snapshots, list),
True, True,
@ -1275,13 +1285,10 @@ class TestResourceTags(cloudstackTestCase):
'manual', 'manual',
'The tag should have original value' 'The tag should have original value'
) )
snapshots = Snapshot.list(self.apiclient,
snapshots = list_snapshots(
self.apiclient,
listall=True, listall=True,
key='type', key='type',
value='manual' value='manual')
)
self.assertEqual( self.assertEqual(
isinstance(snapshots, list), isinstance(snapshots, list),
True, True,
@ -1563,21 +1570,16 @@ class TestResourceTags(cloudstackTestCase):
'India', 'India',
'The tag should have original value' 'The tag should have original value'
) )
self.debug("Creating the same tag with caps for user VM")
try: try:
tag_2 = Tag.create( Tag.create(self.apiclient,
self.apiclient,
resourceIds=self.vm_1.id, resourceIds=self.vm_1.id,
resourceType='userVM', resourceType='userVM',
tags={'REGION': 'INDIA'} tags={'REGION': 'INDIA'})
)
except Exception as e: except Exception as e:
pass pass
else: else:
assert("Creating same tag in upper case succeeded") assert("Creating same tag in upper case succeeded")
self.debug("Deleting the created tag..")
try: try:
tag_1.delete( tag_1.delete(
self.apiclient, self.apiclient,
@ -1801,10 +1803,8 @@ class TestResourceTags(cloudstackTestCase):
) )
self.debug("ISO created with ID: %s" % iso.id) self.debug("ISO created with ID: %s" % iso.id)
list_iso_response = list_isos( list_iso_response = Iso.list(self.apiclient,
self.apiclient, id=iso.id)
id=iso.id
)
self.assertEqual( self.assertEqual(
isinstance(list_iso_response, list), isinstance(list_iso_response, list),
True, True,
@ -1828,8 +1828,6 @@ class TestResourceTags(cloudstackTestCase):
domainid=user_account.domainid, domainid=user_account.domainid,
key='region', key='region',
) )
self.debug("Verify listTag API using user account")
self.assertEqual( self.assertEqual(
isinstance(tags, list), isinstance(tags, list),
True, True,
@ -1884,26 +1882,18 @@ class TestResourceTags(cloudstackTestCase):
account=user_account.name, account=user_account.name,
domainid=user_account.domainid domainid=user_account.domainid
) )
self.debug("ISO created with ID: %s" % iso.id)
list_iso_response = list_isos( list_iso_response = Iso.list(self.apiclient,
self.apiclient, id=iso.id)
id=iso.id
)
self.assertEqual( self.assertEqual(
isinstance(list_iso_response, list), isinstance(list_iso_response, list),
True, True,
"Check list response returns a valid list" "Check list response returns a valid list"
) )
Tag.create(self.apiclient,
self.debug("Creating a tag for the ISO")
tag = Tag.create(
self.apiclient,
resourceIds=iso.id, resourceIds=iso.id,
resourceType='ISO', resourceType='ISO',
tags={'region': 'India'} tags={'region': 'India'})
)
self.debug("Tag created: %s" % tag.__dict__)
tags = Tag.list( tags = Tag.list(
self.apiclient, self.apiclient,
@ -1913,8 +1903,6 @@ class TestResourceTags(cloudstackTestCase):
domainid=user_account.domainid, domainid=user_account.domainid,
key='region', key='region',
) )
self.debug("Verify listTag API using user account")
self.assertEqual( self.assertEqual(
isinstance(tags, list), isinstance(tags, list),
True, True,
@ -2200,37 +2188,11 @@ class TestResourceTags(cloudstackTestCase):
def test_21_create_tag_stopped_vm(self): def test_21_create_tag_stopped_vm(self):
"Test creation of tag on stopped vm." "Test creation of tag on stopped vm."
try:
self.debug("Stopping the virtual machine: %s" % self.vm_1.name) self.debug("Stopping the virtual machine: %s" % self.vm_1.name)
#Stop virtual machine #Stop virtual machine
self.vm_1.stop(self.apiclient) self.vm_1.stop(self.apiclient)
timeout = self.services["timeout"]
#Wait before server has be successfully stopped
time.sleep(self.services["sleep"])
list_vm_response = list_virtual_machines(
self.apiclient,
id=self.vm_1.id
)
self.debug(
"Verify listVirtualMachines response for virtual machine: %s" \
% self.vm_1.id
)
self.assertEqual(
isinstance(list_vm_response, list),
True,
"Check list response returns a valid list"
)
vm_response = list_vm_response[0]
self.assertEqual(
vm_response.state,
"Stopped",
"VM should be in stopped state after deployment"
)
self.debug("Creating a tag for user VM") self.debug("Creating a tag for user VM")
tag = Tag.create( tag = Tag.create(
self.apiclient, self.apiclient,
@ -2262,7 +2224,6 @@ class TestResourceTags(cloudstackTestCase):
) )
self.debug("Deleting the created tag..") self.debug("Deleting the created tag..")
try:
tag.delete( tag.delete(
self.apiclient, self.apiclient,
resourceIds=self.vm_1.id, resourceIds=self.vm_1.id,
@ -2270,7 +2231,7 @@ class TestResourceTags(cloudstackTestCase):
tags={'region': 'India'} tags={'region': 'India'}
) )
except Exception as e: except Exception as e:
self.fail("Failed to delete the tag - %s" % e) self.fail("Exception occured - %s" % e)
return return
@attr(tags=["advanced", "basic", "selfservice"]) @attr(tags=["advanced", "basic", "selfservice"])

View File

@ -17,15 +17,20 @@
""" P1 tests for Templates """ P1 tests for Templates
""" """
#Import Local Modules #Import Local Modules
import marvin
from nose.plugins.attrib import attr from nose.plugins.attrib import attr
from marvin.cloudstackTestCase import * from marvin.cloudstackTestCase import cloudstackTestCase, unittest
from marvin.cloudstackAPI import * from marvin.cloudstackAPI import listZones
from marvin.lib.utils import * from marvin.lib.utils import (cleanup_resources)
from marvin.lib.base import * from marvin.lib.base import (Account,
from marvin.lib.common import * Template,
import urllib ServiceOffering,
from random import random VirtualMachine,
Snapshot,
Volume)
from marvin.lib.common import (get_domain,
get_zone,
get_template,
get_builtin_template_info)
#Import System modules #Import System modules
import time import time
@ -201,14 +206,13 @@ class TestCreateTemplate(cloudstackTestCase):
time.sleep(self.services["sleep"]) time.sleep(self.services["sleep"])
timeout = self.services["timeout"] timeout = self.services["timeout"]
while True: while True:
list_template_response = list_templates( list_template_response = Template.list(
self.apiclient, self.apiclient,
templatefilter='all', templatefilter='all',
id=template.id, id=template.id,
zoneid=self.zone.id, zoneid=self.zone.id,
account=self.account.name, account=self.account.name,
domainid=self.account.domainid domainid=self.account.domainid)
)
if isinstance(list_template_response, list): if isinstance(list_template_response, list):
break break
elif timeout == 0: elif timeout == 0:
@ -247,12 +251,10 @@ class TestCreateTemplate(cloudstackTestCase):
mode=self.services["mode"] mode=self.services["mode"]
) )
self.debug("creating an instance with template ID: %s" % template.id) self.debug("creating an instance with template ID: %s" % template.id)
vm_response = list_virtual_machines( vm_response = VirtualMachine.list(self.apiclient,
self.apiclient,
id=virtual_machine.id, id=virtual_machine.id,
account=self.account.name, account=self.account.name,
domainid=self.account.domainid domainid=self.account.domainid)
)
self.assertEqual( self.assertEqual(
isinstance(vm_response, list), isinstance(vm_response, list),
True, True,
@ -300,17 +302,21 @@ class TestTemplates(cloudstackTestCase):
cls.services["ostype"] cls.services["ostype"]
) )
cls.services["virtual_machine"]["zoneid"] = cls.zone.id cls.services["virtual_machine"]["zoneid"] = cls.zone.id
cls._cleanup = []
try:
cls.account = Account.create( cls.account = Account.create(
cls.api_client, cls.api_client,
cls.services["account"], cls.services["account"],
domainid=cls.domain.id domainid=cls.domain.id
) )
cls._cleanup.append(cls.account)
cls.services["account"] = cls.account.name cls.services["account"] = cls.account.name
cls.service_offering = ServiceOffering.create( cls.service_offering = ServiceOffering.create(
cls.api_client, cls.api_client,
cls.services["service_offering"] cls.services["service_offering"]
) )
cls._cleanup.append(cls.service_offering)
# create virtual machine # create virtual machine
cls.virtual_machine = VirtualMachine.create( cls.virtual_machine = VirtualMachine.create(
@ -325,16 +331,13 @@ class TestTemplates(cloudstackTestCase):
cls.virtual_machine.stop(cls.api_client) cls.virtual_machine.stop(cls.api_client)
timeout = cls.services["timeout"] timeout = cls.services["timeout"]
#Wait before server has be successfully stopped
time.sleep(cls.services["sleep"])
while True: while True:
list_volume = list_volumes( list_volume = Volume.list(
cls.api_client, cls.api_client,
virtualmachineid=cls.virtual_machine.id, virtualmachineid=cls.virtual_machine.id,
type='ROOT', type='ROOT',
listall=True listall=True)
)
if isinstance(list_volume, list): if isinstance(list_volume, list):
break break
elif timeout == 0: elif timeout == 0:
@ -351,10 +354,9 @@ class TestTemplates(cloudstackTestCase):
cls.services["template"], cls.services["template"],
cls.volume.id cls.volume.id
) )
cls._cleanup = [ except Exception as e:
cls.service_offering, cls.tearDownClass()
cls.account, raise unittest.SkipTest("Failure in setUpClass: %s" % e)
]
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
@ -405,12 +407,11 @@ class TestTemplates(cloudstackTestCase):
self.debug("creating an instance with template ID: %s" % self.template.id) self.debug("creating an instance with template ID: %s" % self.template.id)
self.cleanup.append(virtual_machine) self.cleanup.append(virtual_machine)
vm_response = list_virtual_machines( vm_response = VirtualMachine.list(
self.apiclient, self.apiclient,
id=virtual_machine.id, id=virtual_machine.id,
account=self.account.name, account=self.account.name,
domainid=self.account.domainid domainid=self.account.domainid)
)
#Verify VM response to check whether VM deployment was successful #Verify VM response to check whether VM deployment was successful
self.assertNotEqual( self.assertNotEqual(
len(vm_response), len(vm_response),
@ -435,13 +436,12 @@ class TestTemplates(cloudstackTestCase):
# 2. Delete the created template and again verify list template response # 2. Delete the created template and again verify list template response
# Verify template response for updated attributes # Verify template response for updated attributes
list_template_response = list_templates( list_template_response = Template.list(
self.apiclient, self.apiclient,
templatefilter=\ templatefilter=\
self.services["template"]["templatefilter"], self.services["template"]["templatefilter"],
id=self.template.id, id=self.template.id,
zoneid=self.zone.id zoneid=self.zone.id)
)
self.assertEqual( self.assertEqual(
isinstance(list_template_response, list), isinstance(list_template_response, list),
True, True,
@ -467,7 +467,7 @@ class TestTemplates(cloudstackTestCase):
self.template.delete(self.apiclient) self.template.delete(self.apiclient)
self.debug("Delete template: %s successful" % self.template) self.debug("Delete template: %s successful" % self.template)
list_template_response = list_templates( list_template_response = Template.list(
self.apiclient, self.apiclient,
templatefilter=\ templatefilter=\
self.services["template"]["templatefilter"], self.services["template"]["templatefilter"],
@ -493,7 +493,7 @@ class TestTemplates(cloudstackTestCase):
# 4. Deploy Virtual machine using this template # 4. Deploy Virtual machine using this template
# 5. VM should be in running state # 5. VM should be in running state
volumes = list_volumes( volumes = Volume.list(
self.apiclient, self.apiclient,
virtualmachineid=self.virtual_machine.id, virtualmachineid=self.virtual_machine.id,
type='ROOT', type='ROOT',
@ -518,7 +518,7 @@ class TestTemplates(cloudstackTestCase):
) )
self.cleanup.append(template) self.cleanup.append(template)
# Verify created template # Verify created template
templates = list_templates( templates = Template.list(
self.apiclient, self.apiclient,
templatefilter=\ templatefilter=\
self.services["template"]["templatefilter"], self.services["template"]["templatefilter"],
@ -547,7 +547,7 @@ class TestTemplates(cloudstackTestCase):
) )
self.cleanup.append(virtual_machine) self.cleanup.append(virtual_machine)
vm_response = list_virtual_machines( vm_response = VirtualMachine.list(
self.apiclient, self.apiclient,
id=virtual_machine.id, id=virtual_machine.id,
account=self.account.name, account=self.account.name,

View File

@ -17,16 +17,27 @@
""" P1 tests for Snapshots """ P1 tests for Snapshots
""" """
#Import Local Modules #Import Local Modules
import marvin
from nose.plugins.attrib import attr from nose.plugins.attrib import attr
from marvin.cloudstackTestCase import * from marvin.cloudstackTestCase import cloudstackTestCase, unittest
from marvin.cloudstackAPI import * from marvin.cloudstackAPI import deleteVolume
from marvin.lib.utils import * from marvin.lib.utils import (cleanup_resources)
from marvin.lib.base import * from marvin.lib.base import (Account,
from marvin.lib.common import * ServiceOffering,
from marvin.sshClient import SshClient NATRule,
import datetime VirtualMachine,
Snapshot,
Iso,
ImageStore,
LoadBalancerRule,
PublicIPAddress,
DiskOffering,
Template,
VpnUser,
Vpn,
Volume)
from marvin.lib.common import (get_zone,
get_domain,
get_template)
class Services: class Services:
"""Test Snapshots Services """Test Snapshots Services
@ -193,14 +204,19 @@ class TestVmUsage(cloudstackTestCase):
# VM.Destroy and volume .delete Event for the created account # VM.Destroy and volume .delete Event for the created account
# 4. Delete the account # 4. Delete the account
try:
self.debug("Stopping the VM: %s" % self.virtual_machine.id) self.debug("Stopping the VM: %s" % self.virtual_machine.id)
# Stop the VM # Stop the VM
self.virtual_machine.stop(self.apiclient) self.virtual_machine.stop(self.apiclient)
except Exception as e:
self.fail("Failed to stop instance: %s" % e)
time.sleep(self.services["sleep"]) try:
# Destroy the VM # Destroy the VM
self.debug("Destroying the VM: %s" % self.virtual_machine.id) self.debug("Destroying the VM: %s" % self.virtual_machine.id)
self.virtual_machine.delete(self.apiclient) self.virtual_machine.delete(self.apiclient)
except Exception as e:
self.fail("Failed to destroy VM: %s" % e)
# Fetch account ID from account_uuid # Fetch account ID from account_uuid
self.debug("select id from account where uuid = '%s';" \ self.debug("select id from account where uuid = '%s';" \
@ -536,16 +552,18 @@ class TestVolumeUsage(cloudstackTestCase):
# 4. Destroy the Data disk. Volume.delete event is generated for data # 4. Destroy the Data disk. Volume.delete event is generated for data
# disk of the destroyed VM # disk of the destroyed VM
try:
# Stop VM # Stop VM
self.debug("Stopping VM with ID: %s" % self.virtual_machine.id) self.debug("Stopping VM with ID: %s" % self.virtual_machine.id)
self.virtual_machine.stop(self.apiclient) self.virtual_machine.stop(self.apiclient)
except Exception as e:
self.fail("Failed to stop instance: %s" % e)
volume_response = list_volumes( volume_response = Volume.list(
self.apiclient, self.apiclient,
virtualmachineid=self.virtual_machine.id, virtualmachineid=self.virtual_machine.id,
type='DATADISK', type='DATADISK',
listall=True listall=True)
)
self.assertEqual( self.assertEqual(
isinstance(volume_response, list), isinstance(volume_response, list),
True, True,
@ -643,17 +661,20 @@ class TestTemplateUsage(cloudstackTestCase):
cls.services["ostype"] cls.services["ostype"]
) )
cls.services["server"]["zoneid"] = cls.zone.id cls.services["server"]["zoneid"] = cls.zone.id
try:
cls.account = Account.create( cls.account = Account.create(
cls.api_client, cls.api_client,
cls.services["account"], cls.services["account"],
domainid=cls.domain.id domainid=cls.domain.id
) )
cls._cleanup.append(cls.account)
cls.services["account"] = cls.account.name cls.services["account"] = cls.account.name
cls.service_offering = ServiceOffering.create( cls.service_offering = ServiceOffering.create(
cls.api_client, cls.api_client,
cls.services["service_offering"] cls.services["service_offering"]
) )
cls._cleanup.append(cls.service_offering)
#create virtual machine #create virtual machine
cls.virtual_machine = VirtualMachine.create( cls.virtual_machine = VirtualMachine.create(
cls.api_client, cls.api_client,
@ -668,21 +689,18 @@ class TestTemplateUsage(cloudstackTestCase):
#Stop virtual machine #Stop virtual machine
cls.virtual_machine.stop(cls.api_client) cls.virtual_machine.stop(cls.api_client)
#Wait before server has be successfully stopped list_volume = Volume.list(
time.sleep(30)
list_volume = list_volumes(
cls.api_client, cls.api_client,
virtualmachineid=cls.virtual_machine.id, virtualmachineid=cls.virtual_machine.id,
type='ROOT', type='ROOT',
listall=True listall=True)
)
if isinstance(list_volume, list): if isinstance(list_volume, list):
cls.volume = list_volume[0] cls.volume = list_volume[0]
else: else:
raise Exception("List Volumes failed!") raise Exception("List Volumes failed!")
cls._cleanup = [ except Exception as e:
cls.account, cls.tearDownClass()
] raise unittest.SkipTest("Exception in setUpClass: %s" % e)
return return
@classmethod @classmethod
@ -1180,20 +1198,17 @@ class TestSnapshotUsage(cloudstackTestCase):
# 3. Delete the account # 3. Delete the account
# Get the Root disk of VM # Get the Root disk of VM
volumes = list_volumes( volumes = Volume.list(
self.apiclient, self.apiclient,
virtualmachineid=self.virtual_machine.id, virtualmachineid=self.virtual_machine.id,
type='ROOT', type='ROOT',
listall=True listall=True)
)
self.assertEqual( self.assertEqual(
isinstance(volumes, list), isinstance(volumes, list),
True, True,
"Check if list volumes return a valid data" "Check if list volumes return a valid data"
) )
volume = volumes[0]
# Create a snapshot from the ROOTDISK # Create a snapshot from the ROOTDISK
self.debug("Creating snapshot from volume: %s" % volumes[0].id) self.debug("Creating snapshot from volume: %s" % volumes[0].id)
snapshot = Snapshot.create(self.apiclient, volumes[0].id) snapshot = Snapshot.create(self.apiclient, volumes[0].id)

View File

@ -18,11 +18,24 @@
""" """
#Import Local Modules #Import Local Modules
from nose.plugins.attrib import attr from nose.plugins.attrib import attr
from marvin.cloudstackTestCase import * from marvin.cloudstackTestCase import cloudstackTestCase
from marvin.cloudstackAPI import * from marvin.cloudstackAPI import (listHypervisorCapabilities,
from marvin.lib.utils import * attachIso,
from marvin.lib.base import * deleteVolume)
from marvin.lib.common import * from marvin.lib.utils import cleanup_resources
from marvin.lib.base import (Account,
ServiceOffering,
VirtualMachine,
Volume,
Host,
Iso,
Configurations,
DiskOffering,
Domain)
from marvin.lib.common import (get_domain,
get_zone,
get_template,
get_pod)
#Import System modules #Import System modules
import time import time
@ -186,8 +199,8 @@ class TestAttachVolume(cloudstackTestCase):
# 5. Start The VM. Start VM should be successful # 5. Start The VM. Start VM should be successful
# Create 5 volumes and attach to VM # Create 5 volumes and attach to VM
try:
for i in range(self.max_data_volumes): for i in range(self.max_data_volumes):
self.debug(i)
volume = Volume.create( volume = Volume.create(
self.apiclient, self.apiclient,
self.services["volume"], self.services["volume"],
@ -196,12 +209,8 @@ class TestAttachVolume(cloudstackTestCase):
domainid=self.account.domainid, domainid=self.account.domainid,
diskofferingid=self.disk_offering.id diskofferingid=self.disk_offering.id
) )
self.debug("Created volume: %s for account: %s" % (
volume.id,
self.account.name
))
# Check List Volume response for newly created volume # Check List Volume response for newly created volume
list_volume_response = list_volumes( list_volume_response = Volume.list(
self.apiclient, self.apiclient,
id=volume.id id=volume.id
) )
@ -215,12 +224,8 @@ class TestAttachVolume(cloudstackTestCase):
self.apiclient, self.apiclient,
volume volume
) )
self.debug("Attach volume: %s to VM: %s" % (
volume.id,
self.virtual_machine.id
))
# Check all volumes attached to same VM # Check all volumes attached to same VM
list_volume_response = list_volumes( list_volume_response = Volume.list(
self.apiclient, self.apiclient,
virtualmachineid=self.virtual_machine.id, virtualmachineid=self.virtual_machine.id,
type='DATADISK', type='DATADISK',
@ -229,23 +234,20 @@ class TestAttachVolume(cloudstackTestCase):
self.assertNotEqual( self.assertNotEqual(
list_volume_response, list_volume_response,
None, None,
"Check if volume exists in ListVolumes" "Check if volume exists in ListVolumes")
)
self.assertEqual( self.assertEqual(
isinstance(list_volume_response, list), isinstance(list_volume_response, list),
True, True,
"Check list volumes response for valid list" "Check list volumes response for valid list")
)
self.assertEqual( self.assertEqual(
len(list_volume_response), len(list_volume_response),
self.max_data_volumes, self.max_data_volumes,
"Volumes attached to the VM %s. Expected %s" % (len(list_volume_response), self.max_data_volumes) "Volumes attached to the VM %s. Expected %s" % (len(list_volume_response), self.max_data_volumes))
)
self.debug("Rebooting the VM: %s" % self.virtual_machine.id) self.debug("Rebooting the VM: %s" % self.virtual_machine.id)
# Reboot VM # Reboot VM
self.virtual_machine.reboot(self.apiclient) self.virtual_machine.reboot(self.apiclient)
vm_response = list_virtual_machines( vm_response = VirtualMachine.list(
self.apiclient, self.apiclient,
id=self.virtual_machine.id, id=self.virtual_machine.id,
) )
@ -267,41 +269,15 @@ class TestAttachVolume(cloudstackTestCase):
"Check the state of VM" "Check the state of VM"
) )
self.debug("Stopping the VM: %s" % self.virtual_machine.id)
# Stop VM # Stop VM
self.virtual_machine.stop(self.apiclient) self.virtual_machine.stop(self.apiclient)
vm_response = list_virtual_machines(
self.apiclient,
id=self.virtual_machine.id,
)
self.assertEqual(
isinstance(vm_response, list),
True,
"Check list VM response for valid list"
)
#Verify VM response to check whether VM deployment was successful
self.assertNotEqual(
len(vm_response),
0,
"Check VMs available in List VMs response"
)
vm = vm_response[0]
self.assertEqual(
vm.state,
'Stopped',
"Check the state of VM"
)
self.debug("Starting the VM: %s" % self.virtual_machine.id)
# Start VM # Start VM
self.virtual_machine.start(self.apiclient) self.virtual_machine.start(self.apiclient)
# Sleep to ensure that VM is in ready state # Sleep to ensure that VM is in ready state
time.sleep(self.services["sleep"]) time.sleep(self.services["sleep"])
vm_response = list_virtual_machines( vm_response = VirtualMachine.list(
self.apiclient, self.apiclient,
id=self.virtual_machine.id, id=self.virtual_machine.id,
) )
@ -324,6 +300,8 @@ class TestAttachVolume(cloudstackTestCase):
'Running', 'Running',
"Check the state of VM" "Check the state of VM"
) )
except Exception as e:
self.fail("Exception occured: %s" % e)
return return
@attr(tags = ["advanced", "advancedns"]) @attr(tags = ["advanced", "advancedns"])
@ -349,7 +327,7 @@ class TestAttachVolume(cloudstackTestCase):
self.account.name self.account.name
)) ))
# Check List Volume response for newly created volume # Check List Volume response for newly created volume
list_volume_response = list_volumes( list_volume_response = Volume.list(
self.apiclient, self.apiclient,
id=volume.id id=volume.id
) )
@ -476,6 +454,7 @@ class TestAttachDetachVolume(cloudstackTestCase):
# 5. Stop the VM. Stop VM should be successful # 5. Stop the VM. Stop VM should be successful
# 6. Start The VM. Start VM should be successful # 6. Start The VM. Start VM should be successful
try:
volumes = [] volumes = []
# Create 5 volumes and attach to VM # Create 5 volumes and attach to VM
for i in range(self.max_data_volumes): for i in range(self.max_data_volumes):
@ -487,32 +466,22 @@ class TestAttachDetachVolume(cloudstackTestCase):
domainid=self.account.domainid, domainid=self.account.domainid,
diskofferingid=self.disk_offering.id diskofferingid=self.disk_offering.id
) )
self.debug("Created volume: %s for account: %s" % (
volume.id,
self.account.name
))
self.cleanup.append(volume) self.cleanup.append(volume)
volumes.append(volume) volumes.append(volume)
# Check List Volume response for newly created volume # Check List Volume response for newly created volume
list_volume_response = list_volumes( list_volume_response = Volume.list(
self.apiclient, self.apiclient,
id=volume.id id=volume.id
) )
self.assertNotEqual( self.assertNotEqual(
list_volume_response, list_volume_response,
None, None,
"Check if volume exists in ListVolumes" "Check if volume exists in ListVolumes")
)
self.assertEqual( self.assertEqual(
isinstance(list_volume_response, list), isinstance(list_volume_response, list),
True, True,
"Check list volumes response for valid list" "Check list volumes response for valid list")
)
self.debug("Attach volume: %s to VM: %s" % (
volume.id,
self.virtual_machine.id
))
# Attach volume to VM # Attach volume to VM
self.virtual_machine.attach_volume( self.virtual_machine.attach_volume(
self.apiclient, self.apiclient,
@ -520,7 +489,7 @@ class TestAttachDetachVolume(cloudstackTestCase):
) )
# Check all volumes attached to same VM # Check all volumes attached to same VM
list_volume_response = list_volumes( list_volume_response = Volume.list(
self.apiclient, self.apiclient,
virtualmachineid=self.virtual_machine.id, virtualmachineid=self.virtual_machine.id,
type='DATADISK', type='DATADISK',
@ -544,10 +513,6 @@ class TestAttachDetachVolume(cloudstackTestCase):
# Detach all volumes from VM # Detach all volumes from VM
for volume in volumes: for volume in volumes:
self.debug("Detach volume: %s to VM: %s" % (
volume.id,
self.virtual_machine.id
))
self.virtual_machine.detach_volume( self.virtual_machine.detach_volume(
self.apiclient, self.apiclient,
volume volume
@ -558,7 +523,7 @@ class TestAttachDetachVolume(cloudstackTestCase):
# Sleep to ensure that VM is in ready state # Sleep to ensure that VM is in ready state
time.sleep(self.services["sleep"]) time.sleep(self.services["sleep"])
vm_response = list_virtual_machines( vm_response = VirtualMachine.list(
self.apiclient, self.apiclient,
id=self.virtual_machine.id, id=self.virtual_machine.id,
) )
@ -582,40 +547,14 @@ class TestAttachDetachVolume(cloudstackTestCase):
) )
# Stop VM # Stop VM
self.debug("Stopping the VM: %s" % self.virtual_machine.id)
self.virtual_machine.stop(self.apiclient) self.virtual_machine.stop(self.apiclient)
# Sleep to ensure that VM is in ready state
time.sleep(self.services["sleep"])
vm_response = list_virtual_machines(
self.apiclient,
id=self.virtual_machine.id,
)
#Verify VM response to check whether VM deployment was successful
self.assertEqual(
isinstance(vm_response, list),
True,
"Check list VM response for valid list"
)
self.assertNotEqual(
len(vm_response),
0,
"Check VMs available in List VMs response"
)
vm = vm_response[0]
self.assertEqual(
vm.state,
'Stopped',
"Check the state of VM"
)
# Start VM # Start VM
self.debug("Starting the VM: %s" % self.virtual_machine.id)
self.virtual_machine.start(self.apiclient) self.virtual_machine.start(self.apiclient)
# Sleep to ensure that VM is in ready state # Sleep to ensure that VM is in ready state
time.sleep(self.services["sleep"]) time.sleep(self.services["sleep"])
vm_response = list_virtual_machines( vm_response = VirtualMachine.list(
self.apiclient, self.apiclient,
id=self.virtual_machine.id, id=self.virtual_machine.id,
) )
@ -636,6 +575,8 @@ class TestAttachDetachVolume(cloudstackTestCase):
'Running', 'Running',
"Check the state of VM" "Check the state of VM"
) )
except Exception as e:
self.fail("Exception occuered: %s" % e)
return return
@ -754,7 +695,7 @@ class TestAttachVolumeISO(cloudstackTestCase):
self.account.name self.account.name
)) ))
# Check List Volume response for newly created volume # Check List Volume response for newly created volume
list_volume_response = list_volumes( list_volume_response = Volume.list(
self.apiclient, self.apiclient,
id=volume.id id=volume.id
) )
@ -775,7 +716,7 @@ class TestAttachVolumeISO(cloudstackTestCase):
) )
# Check all volumes attached to same VM # Check all volumes attached to same VM
list_volume_response = list_volumes( list_volume_response = Volume.list(
self.apiclient, self.apiclient,
virtualmachineid=self.virtual_machine.id, virtualmachineid=self.virtual_machine.id,
type='DATADISK', type='DATADISK',
@ -826,7 +767,7 @@ class TestAttachVolumeISO(cloudstackTestCase):
self.apiclient.attachIso(cmd) self.apiclient.attachIso(cmd)
# Verify ISO is attached to VM # Verify ISO is attached to VM
vm_response = list_virtual_machines( vm_response = VirtualMachine.list(
self.apiclient, self.apiclient,
id=self.virtual_machine.id, id=self.virtual_machine.id,
) )
@ -941,7 +882,7 @@ class TestVolumes(cloudstackTestCase):
# response before volume attach (to VM) # response before volume attach (to VM)
# Check the list volumes response for vmname and virtualmachineid # Check the list volumes response for vmname and virtualmachineid
list_volume_response = list_volumes( list_volume_response = Volume.list(
self.apiclient, self.apiclient,
id=self.volume.id id=self.volume.id
) )
@ -982,7 +923,7 @@ class TestVolumes(cloudstackTestCase):
self.virtual_machine.attach_volume(self.apiclient, self.volume) self.virtual_machine.attach_volume(self.apiclient, self.volume)
# Check all volumes attached to same VM # Check all volumes attached to same VM
list_volume_response = list_volumes( list_volume_response = Volume.list(
self.apiclient, self.apiclient,
virtualmachineid=self.virtual_machine.id, virtualmachineid=self.virtual_machine.id,
type='DATADISK', type='DATADISK',
@ -1030,7 +971,7 @@ class TestVolumes(cloudstackTestCase):
#Sleep to ensure the current state will reflected in other calls #Sleep to ensure the current state will reflected in other calls
time.sleep(self.services["sleep"]) time.sleep(self.services["sleep"])
list_volume_response = list_volumes( list_volume_response = Volume.list(
self.apiclient, self.apiclient,
id=self.volume.id id=self.volume.id
) )
@ -1074,7 +1015,7 @@ class TestVolumes(cloudstackTestCase):
#Sleep to ensure the current state will reflected in other calls #Sleep to ensure the current state will reflected in other calls
time.sleep(self.services["sleep"]) time.sleep(self.services["sleep"])
list_volume_response = list_volumes( list_volume_response = Volume.list(
self.apiclient, self.apiclient,
id=self.volume.id, id=self.volume.id,
) )

View File

@ -1933,8 +1933,6 @@ class TestVPCNetworkUpgrade(cloudstackTestCase):
except Exception as e: except Exception as e:
self.fail("Failed to stop VMs, %s" % e) self.fail("Failed to stop VMs, %s" % e)
wait_for_cleanup(self.apiclient, ["expunge.interval", "expunge.delay"])
# When all Vms ain network are stopped, network state changes from Implemented --> Shutdown --> Allocated # When all Vms ain network are stopped, network state changes from Implemented --> Shutdown --> Allocated
# We can't update the network when it is in Shutodown state, hence we should wait for the state to change to # We can't update the network when it is in Shutodown state, hence we should wait for the state to change to
# Allocated and then update the network # Allocated and then update the network
@ -2108,8 +2106,6 @@ class TestVPCNetworkUpgrade(cloudstackTestCase):
except Exception as e: except Exception as e:
self.fail("Failed to stop VMs, %s" % e) self.fail("Failed to stop VMs, %s" % e)
wait_for_cleanup(self.apiclient, ["expunge.interval", "expunge.delay"])
self.debug("Upgrading network offering to support PF services") self.debug("Upgrading network offering to support PF services")
with self.assertRaises(Exception): with self.assertRaises(Exception):
network_1.update( network_1.update(

View File

@ -19,7 +19,7 @@
""" """
#Import Local Modules #Import Local Modules
from nose.plugins.attrib import attr from nose.plugins.attrib import attr
from marvin.cloudstackTestCase import cloudstackTestCase, unittest from marvin.cloudstackTestCase import cloudstackTestCase
from marvin.lib.utils import cleanup_resources, validateList from marvin.lib.utils import cleanup_resources, validateList
from marvin.lib.base import (VirtualMachine, from marvin.lib.base import (VirtualMachine,
NATRule, NATRule,
@ -1256,24 +1256,6 @@ class TestVMLifeCycleSharedNwVPC(cloudstackTestCase):
except Exception as e: except Exception as e:
self.fail("Failed to stop the virtual instances, %s" % e) self.fail("Failed to stop the virtual instances, %s" % e)
self.debug("Check if the instance is in stopped state?")
vms = VirtualMachine.list(
self.apiclient,
id=self.vm_2.id,
listall=True
)
self.assertEqual(
isinstance(vms, list),
True,
"List virtual machines should return a valid list"
)
vm = vms[0]
self.assertEqual(
vm.state,
"Stopped",
"Virtual machine should be in stopped state"
)
self.debug("Validating if network rules are coonfigured properly?") self.debug("Validating if network rules are coonfigured properly?")
self.validate_network_rules() self.validate_network_rules()
return return
@ -3099,35 +3081,7 @@ class TestVMLifeCycleDiffHosts(cloudstackTestCase):
self.account.name) self.account.name)
try: try:
self.vm_1.stop(self.apiclient) self.vm_1.stop(self.apiclient)
list_vm_response = list_virtual_machines(
self.apiclient,
id=self.vm_1.id
)
vm_response = list_vm_response[0]
self.assertEqual(
vm_response.state,
'Stopped',
"VM state should be stopped"
)
self.vm_2.stop(self.apiclient) self.vm_2.stop(self.apiclient)
list_vm_response = list_virtual_machines(
self.apiclient,
id=self.vm_2.id
)
vm_response = list_vm_response[0]
self.assertEqual(
vm_response.state,
'Stopped',
"VM state should be stopped"
)
except Exception as e: except Exception as e:
self.fail("Failed to stop the virtual instances, %s" % e) self.fail("Failed to stop the virtual instances, %s" % e)

View File

@ -85,7 +85,6 @@ class TestCreateServiceOffering(cloudstackTestCase):
0, 0,
"Check Service offering is created" "Check Service offering is created"
) )
service_response = list_service_response[0]
self.assertEqual( self.assertEqual(
list_service_response[0].cpunumber, list_service_response[0].cpunumber,
@ -293,23 +292,10 @@ class TestServiceOfferings(cloudstackTestCase):
# 2. Using listVM command verify that this Vm # 2. Using listVM command verify that this Vm
# has Small service offering Id. # has Small service offering Id.
self.debug("Stopping VM - ID: %s" % self.medium_virtual_machine.id) try:
self.medium_virtual_machine.stop(self.apiclient) self.medium_virtual_machine.stop(self.apiclient)
# Ensure that VM is in stopped state except Exception as e:
list_vm_response = list_virtual_machines( self.fail("Failed to stop VM: %s" % e)
self.apiclient,
id=self.medium_virtual_machine.id
)
if isinstance(list_vm_response, list):
vm = list_vm_response[0]
if vm.state == 'Stopped':
self.debug("VM state: %s" % vm.state)
else:
raise Exception(
"Failed to stop VM (ID: %s) in change service offering" % vm.id)
self.debug("Change Service offering VM - ID: %s" %
self.medium_virtual_machine.id)
cmd = changeServiceForVirtualMachine.changeServiceForVirtualMachineCmd() cmd = changeServiceForVirtualMachine.changeServiceForVirtualMachineCmd()
cmd.id = self.medium_virtual_machine.id cmd.id = self.medium_virtual_machine.id

View File

@ -17,19 +17,28 @@
""" BVT tests for Templates ISO """ BVT tests for Templates ISO
""" """
#Import Local Modules #Import Local Modules
import marvin
from marvin.codes import FAILED from marvin.codes import FAILED
from marvin.cloudstackTestCase import * from marvin.cloudstackTestCase import cloudstackTestCase, unittest
from marvin.cloudstackAPI import * from marvin.cloudstackAPI import (updateTemplate,
from marvin.sshClient import SshClient extractTemplate,
from marvin.lib.utils import * listZones,
from marvin.lib.base import * updateTemplatePermissions,
from marvin.lib.common import * deleteTemplate,
copyTemplate)
from marvin.lib.utils import random_gen, cleanup_resources
from marvin.lib.base import (Account,
ServiceOffering,
VirtualMachine,
DiskOffering,
Template,
Volume)
from marvin.lib.common import (get_domain,
get_zone,
get_template)
from nose.plugins.attrib import attr from nose.plugins.attrib import attr
import urllib import urllib
from random import random
#Import System modules #Import System modules
import datetime import time
_multiprocess_shared_ = True _multiprocess_shared_ = True
@ -62,10 +71,14 @@ class TestCreateTemplate(cloudstackTestCase):
cls.domain = get_domain(cls.apiclient) cls.domain = get_domain(cls.apiclient)
cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests()) cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())
cls.services['mode'] = cls.zone.networktype cls.services['mode'] = cls.zone.networktype
cls._cleanup = []
try:
cls.disk_offering = DiskOffering.create( cls.disk_offering = DiskOffering.create(
cls.apiclient, cls.apiclient,
cls.services["disk_offering"] cls.services["disk_offering"]
) )
cls._cleanup.append(cls.disk_offering)
template = get_template( template = get_template(
cls.apiclient, cls.apiclient,
cls.zone.id, cls.zone.id,
@ -82,16 +95,17 @@ class TestCreateTemplate(cloudstackTestCase):
cls.services["volume"]["diskoffering"] = cls.disk_offering.id cls.services["volume"]["diskoffering"] = cls.disk_offering.id
cls.services["volume"]["zoneid"] = cls.zone.id cls.services["volume"]["zoneid"] = cls.zone.id
cls.services["sourcezoneid"] = cls.zone.id cls.services["sourcezoneid"] = cls.zone.id
cls.account = Account.create( cls.account = Account.create(
cls.apiclient, cls.apiclient,
cls.services["account"], cls.services["account"],
domainid=cls.domain.id domainid=cls.domain.id
) )
cls._cleanup.append(cls.account)
cls.service_offering = ServiceOffering.create( cls.service_offering = ServiceOffering.create(
cls.apiclient, cls.apiclient,
cls.services["service_offerings"] cls.services["service_offerings"]
) )
cls._cleanup.append(cls.service_offering)
#create virtual machine #create virtual machine
cls.virtual_machine = VirtualMachine.create( cls.virtual_machine = VirtualMachine.create(
cls.apiclient, cls.apiclient,
@ -102,35 +116,10 @@ class TestCreateTemplate(cloudstackTestCase):
serviceofferingid=cls.service_offering.id, serviceofferingid=cls.service_offering.id,
mode=cls.services["mode"] mode=cls.services["mode"]
) )
#Stop virtual machine #Stop virtual machine
cls.virtual_machine.stop(cls.apiclient) cls.virtual_machine.stop(cls.apiclient)
# Poll listVM to ensure VM is stopped properly list_volume = Volume.list(
timeout = cls.services["timeout"]
while True:
time.sleep(cls.services["sleep"])
# Ensure that VM is in stopped state
list_vm_response = list_virtual_machines(
cls.apiclient,
id=cls.virtual_machine.id
)
if isinstance(list_vm_response, list):
vm = list_vm_response[0]
if vm.state == 'Stopped':
break
if timeout == 0:
raise Exception(
"Failed to stop VM (ID: %s) in change service offering" %
vm.id)
timeout = timeout - 1
list_volume = list_volumes(
cls.apiclient, cls.apiclient,
virtualmachineid=cls.virtual_machine.id, virtualmachineid=cls.virtual_machine.id,
type='ROOT', type='ROOT',
@ -138,11 +127,9 @@ class TestCreateTemplate(cloudstackTestCase):
) )
cls.volume = list_volume[0] cls.volume = list_volume[0]
cls._cleanup = [ except Exception as e:
cls.account, cls.tearDownClass()
cls.service_offering, raise unittest.SkipTest("Exception in setUpClass: %s" % e)
cls.disk_offering,
]
return return
@classmethod @classmethod
@ -180,7 +167,7 @@ class TestCreateTemplate(cloudstackTestCase):
self.debug("Created template with ID: %s" % template.id) self.debug("Created template with ID: %s" % template.id)
list_template_response = list_templates( list_template_response = Template.list(
self.apiclient, self.apiclient,
templatefilter=\ templatefilter=\
self.services["templatefilter"], self.services["templatefilter"],
@ -289,31 +276,7 @@ class TestTemplates(cloudstackTestCase):
#Stop virtual machine #Stop virtual machine
cls.virtual_machine.stop(cls.apiclient) cls.virtual_machine.stop(cls.apiclient)
# Poll listVM to ensure VM is stopped properly list_volume = Volume.list(
timeout = cls.services["timeout"]
while True:
time.sleep(cls.services["sleep"])
# Ensure that VM is in stopped state
list_vm_response = list_virtual_machines(
cls.apiclient,
id=cls.virtual_machine.id
)
if isinstance(list_vm_response, list):
vm = list_vm_response[0]
if vm.state == 'Stopped':
break
if timeout == 0:
raise Exception(
"Failed to stop VM (ID: %s) in change service offering" %
vm.id)
timeout = timeout - 1
list_volume = list_volumes(
cls.apiclient, cls.apiclient,
virtualmachineid=cls.virtual_machine.id, virtualmachineid=cls.virtual_machine.id,
type='ROOT', type='ROOT',
@ -323,8 +286,8 @@ class TestTemplates(cloudstackTestCase):
cls.volume = list_volume[0] cls.volume = list_volume[0]
except Exception as e: except Exception as e:
raise Exception( raise Exception(
"Exception: Unable to find root volume foe VM: %s" % "Exception: Unable to find root volume foe VM: %s - %s" %
cls.virtual_machine.id) (cls.virtual_machine.id, e))
#Create templates for Edit, Delete & update permissions testcases #Create templates for Edit, Delete & update permissions testcases
cls.template_1 = Template.create( cls.template_1 = Template.create(
@ -407,7 +370,7 @@ class TestTemplates(cloudstackTestCase):
timeout = self.services["timeout"] timeout = self.services["timeout"]
while True: while True:
# Verify template response for updated attributes # Verify template response for updated attributes
list_template_response = list_templates( list_template_response = Template.list(
self.apiclient, self.apiclient,
templatefilter=\ templatefilter=\
self.services["templatefilter"], self.services["templatefilter"],
@ -473,7 +436,7 @@ class TestTemplates(cloudstackTestCase):
self.template_1.delete(self.apiclient) self.template_1.delete(self.apiclient)
list_template_response = list_templates( list_template_response = Template.list(
self.apiclient, self.apiclient,
templatefilter=\ templatefilter=\
self.services["templatefilter"], self.services["templatefilter"],
@ -560,7 +523,7 @@ class TestTemplates(cloudstackTestCase):
cmd.isextractable = self.services["isextractable"] cmd.isextractable = self.services["isextractable"]
self.apiclient.updateTemplatePermissions(cmd) self.apiclient.updateTemplatePermissions(cmd)
list_template_response = list_templates( list_template_response = Template.list(
self.apiclient, self.apiclient,
templatefilter='featured', templatefilter='featured',
id=self.template_2.id, id=self.template_2.id,
@ -617,7 +580,7 @@ class TestTemplates(cloudstackTestCase):
self.apiclient.copyTemplate(cmd) self.apiclient.copyTemplate(cmd)
# Verify template is copied to another zone using ListTemplates # Verify template is copied to another zone using ListTemplates
list_template_response = list_templates( list_template_response = Template.list(
self.apiclient, self.apiclient,
templatefilter=\ templatefilter=\
self.services["templatefilter"], self.services["templatefilter"],
@ -651,7 +614,7 @@ class TestTemplates(cloudstackTestCase):
timeout = self.services["timeout"] timeout = self.services["timeout"]
while True: while True:
time.sleep(self.services["sleep"]) time.sleep(self.services["sleep"])
list_template_response = list_templates( list_template_response = Template.list(
self.apiclient, self.apiclient,
templatefilter=\ templatefilter=\
self.services["templatefilter"], self.services["templatefilter"],
@ -691,7 +654,7 @@ class TestTemplates(cloudstackTestCase):
# Validate the following # Validate the following
# 1. ListTemplates should show only 'public' templates for normal user # 1. ListTemplates should show only 'public' templates for normal user
list_template_response = list_templates( list_template_response = Template.list(
self.apiclient, self.apiclient,
templatefilter='featured', templatefilter='featured',
account=self.user.name, account=self.user.name,
@ -723,7 +686,7 @@ class TestTemplates(cloudstackTestCase):
# Validate the following # Validate the following
# 1. ListTemplates should not show 'SYSTEM' templates for normal user # 1. ListTemplates should not show 'SYSTEM' templates for normal user
list_template_response = list_templates( list_template_response = Template.list(
self.apiclient, self.apiclient,
templatefilter='featured', templatefilter='featured',
account=self.user.name, account=self.user.name,

View File

@ -18,12 +18,24 @@
""" """
#Import Local Modules #Import Local Modules
from marvin.cloudstackTestCase import cloudstackTestCase from marvin.cloudstackTestCase import cloudstackTestCase
from marvin.codes import FAILED from marvin.cloudstackAPI import (recoverVirtualMachine,
from marvin.cloudstackTestCase import * destroyVirtualMachine,
from marvin.cloudstackAPI import * attachIso,
from marvin.lib.utils import * detachIso)
from marvin.lib.base import * from marvin.lib.utils import (cleanup_resources,
from marvin.lib.common import * validateList,
get_hypervisor_type)
from marvin.lib.base import (Account,
ServiceOffering,
VirtualMachine,
Host,
Iso,
Router,
Configurations)
from marvin.lib.common import (get_domain,
get_zone,
get_template)
from marvin.codes import FAILED, PASS
from nose.plugins.attrib import attr from nose.plugins.attrib import attr
#Import System modules #Import System modules
import time import time
@ -110,7 +122,7 @@ class TestDeployVM(cloudstackTestCase):
# Validate the following: # Validate the following:
# 1. Virtual Machine is accessible via SSH # 1. Virtual Machine is accessible via SSH
# 2. listVirtualMachines returns accurate information # 2. listVirtualMachines returns accurate information
list_vm_response = list_virtual_machines( list_vm_response = VirtualMachine.list(
self.apiclient, self.apiclient,
id=self.virtual_machine.id id=self.virtual_machine.id
) )
@ -159,7 +171,7 @@ class TestDeployVM(cloudstackTestCase):
3. Has a linklocalip, publicip and a guestip 3. Has a linklocalip, publicip and a guestip
@return: @return:
""" """
routers = list_routers(self.apiclient, account=self.account.name) routers = Router.list(self.apiclient, account=self.account.name)
self.assertTrue(len(routers) > 0, msg = "No virtual router found") self.assertTrue(len(routers) > 0, msg = "No virtual router found")
router = routers[0] router = routers[0]
@ -181,7 +193,7 @@ class TestDeployVM(cloudstackTestCase):
2. is in the account the VM was deployed in 2. is in the account the VM was deployed in
@return: @return:
""" """
routers = list_routers(self.apiclient, account=self.account.name) routers = Router.list(self.apiclient, account=self.account.name)
self.assertTrue(len(routers) > 0, msg = "No virtual router found") self.assertTrue(len(routers) > 0, msg = "No virtual router found")
router = routers[0] router = routers[0]
@ -301,31 +313,10 @@ class TestVMLifeCycle(cloudstackTestCase):
# 1. Should Not be able to login to the VM. # 1. Should Not be able to login to the VM.
# 2. listVM command should return # 2. listVM command should return
# this VM.State of this VM should be ""Stopped"". # this VM.State of this VM should be ""Stopped"".
try:
self.debug("Stopping VM - ID: %s" % self.virtual_machine.id)
self.small_virtual_machine.stop(self.apiclient) self.small_virtual_machine.stop(self.apiclient)
except Exception as e:
list_vm_response = list_virtual_machines( self.fail("Failed to stop VM: %s" % e)
self.apiclient,
id=self.small_virtual_machine.id
)
self.assertEqual(
isinstance(list_vm_response, list),
True,
"Check list response returns a valid list"
)
self.assertNotEqual(
len(list_vm_response),
0,
"Check VM available in List Virtual Machines"
)
self.assertEqual(
list_vm_response[0].state,
"Stopped",
"Check virtual machine is in stopped state"
)
return return
@attr(tags = ["devcloud", "advanced", "advancedns", "smoke", "basic", "sg", "selfservice"]) @attr(tags = ["devcloud", "advanced", "advancedns", "smoke", "basic", "sg", "selfservice"])
@ -339,7 +330,7 @@ class TestVMLifeCycle(cloudstackTestCase):
self.debug("Starting VM - ID: %s" % self.virtual_machine.id) self.debug("Starting VM - ID: %s" % self.virtual_machine.id)
self.small_virtual_machine.start(self.apiclient) self.small_virtual_machine.start(self.apiclient)
list_vm_response = list_virtual_machines( list_vm_response = VirtualMachine.list(
self.apiclient, self.apiclient,
id=self.small_virtual_machine.id id=self.small_virtual_machine.id
) )
@ -379,7 +370,7 @@ class TestVMLifeCycle(cloudstackTestCase):
self.debug("Rebooting VM - ID: %s" % self.virtual_machine.id) self.debug("Rebooting VM - ID: %s" % self.virtual_machine.id)
self.small_virtual_machine.reboot(self.apiclient) self.small_virtual_machine.reboot(self.apiclient)
list_vm_response = list_virtual_machines( list_vm_response = VirtualMachine.list(
self.apiclient, self.apiclient,
id=self.small_virtual_machine.id id=self.small_virtual_machine.id
) )
@ -416,7 +407,7 @@ class TestVMLifeCycle(cloudstackTestCase):
self.debug("Destroy VM - ID: %s" % self.small_virtual_machine.id) self.debug("Destroy VM - ID: %s" % self.small_virtual_machine.id)
self.small_virtual_machine.delete(self.apiclient) self.small_virtual_machine.delete(self.apiclient)
list_vm_response = list_virtual_machines( list_vm_response = VirtualMachine.list(
self.apiclient, self.apiclient,
id=self.small_virtual_machine.id id=self.small_virtual_machine.id
) )
@ -456,7 +447,7 @@ class TestVMLifeCycle(cloudstackTestCase):
cmd.id = self.small_virtual_machine.id cmd.id = self.small_virtual_machine.id
self.apiclient.recoverVirtualMachine(cmd) self.apiclient.recoverVirtualMachine(cmd)
list_vm_response = list_virtual_machines( list_vm_response = VirtualMachine.list(
self.apiclient, self.apiclient,
id=self.small_virtual_machine.id id=self.small_virtual_machine.id
) )
@ -540,7 +531,7 @@ class TestVMLifeCycle(cloudstackTestCase):
self.vm_to_migrate.migrate(self.apiclient, migrate_host.id) self.vm_to_migrate.migrate(self.apiclient, migrate_host.id)
list_vm_response = list_virtual_machines( list_vm_response = VirtualMachine.list(
self.apiclient, self.apiclient,
id=self.vm_to_migrate.id id=self.vm_to_migrate.id
) )
@ -580,7 +571,7 @@ class TestVMLifeCycle(cloudstackTestCase):
cmd.id = self.small_virtual_machine.id cmd.id = self.small_virtual_machine.id
self.apiclient.destroyVirtualMachine(cmd) self.apiclient.destroyVirtualMachine(cmd)
config = list_configurations( config = Configurations.list(
self.apiclient, self.apiclient,
name='expunge.delay' name='expunge.delay'
) )
@ -590,14 +581,14 @@ class TestVMLifeCycle(cloudstackTestCase):
#VM should be destroyed unless expunge thread hasn't run #VM should be destroyed unless expunge thread hasn't run
#Wait for two cycles of the expunge thread #Wait for two cycles of the expunge thread
config = list_configurations( config = Configurations.list(
self.apiclient, self.apiclient,
name='expunge.interval' name='expunge.interval'
) )
expunge_cycle = int(config[0].value) expunge_cycle = int(config[0].value)
wait_time = expunge_cycle * 2 wait_time = expunge_cycle * 2
while wait_time >= 0: while wait_time >= 0:
list_vm_response = list_virtual_machines( list_vm_response = VirtualMachine.list(
self.apiclient, self.apiclient,
id=self.small_virtual_machine.id id=self.small_virtual_machine.id
) )
@ -676,7 +667,7 @@ class TestVMLifeCycle(cloudstackTestCase):
self.debug("Found a mount point at %s with size %s" % (res, size)) self.debug("Found a mount point at %s with size %s" % (res, size))
# Get ISO size # Get ISO size
iso_response = list_isos( iso_response = Iso.list(
self.apiclient, self.apiclient,
id=iso.id id=iso.id
) )

View File

@ -17,15 +17,25 @@
""" BVT tests for Volumes """ BVT tests for Volumes
""" """
#Import Local Modules #Import Local Modules
from marvin.cloudstackTestCase import * from marvin.cloudstackTestCase import cloudstackTestCase
from marvin.cloudstackException import * #from marvin.cloudstackException import *
from marvin.cloudstackAPI import * from marvin.cloudstackAPI import (deleteVolume,
from marvin.sshClient import SshClient extractVolume,
from marvin.lib.utils import * resizeVolume)
from marvin.lib.base import * #from marvin.sshClient import SshClient
from marvin.lib.common import * from marvin.lib.utils import (cleanup_resources,
format_volume_to_ext3)
from marvin.lib.base import (ServiceOffering,
VirtualMachine,
Account,
Volume,
Host,
DiskOffering)
from marvin.lib.common import (get_domain,
get_zone,
get_template)
from marvin.lib.utils import checkVolumeSize from marvin.lib.utils import checkVolumeSize
from marvin.codes import SUCCESS from marvin.codes import SUCCESS, FAILED
from nose.plugins.attrib import attr from nose.plugins.attrib import attr
#Import System modules #Import System modules
import os import os
@ -149,10 +159,9 @@ class TestCreateVolume(cloudstackTestCase):
#Attach a volume with different disk offerings #Attach a volume with different disk offerings
#and check the memory allocated to each of them #and check the memory allocated to each of them
for volume in self.volumes: for volume in self.volumes:
list_volume_response = list_volumes( list_volume_response = Volume.list(
self.apiClient, self.apiClient,
id=volume.id id=volume.id)
)
self.assertEqual( self.assertEqual(
isinstance(list_volume_response, list), isinstance(list_volume_response, list),
True, True,
@ -186,7 +195,7 @@ class TestCreateVolume(cloudstackTestCase):
time.sleep(self.services["sleep"]) time.sleep(self.services["sleep"])
# Ensure that VM is in running state # Ensure that VM is in running state
list_vm_response = list_virtual_machines( list_vm_response = VirtualMachine.list(
self.apiClient, self.apiClient,
id=self.virtual_machine.id id=self.virtual_machine.id
) )
@ -337,7 +346,7 @@ class TestVolumes(cloudstackTestCase):
)) ))
self.virtual_machine.attach_volume(self.apiClient, self.volume) self.virtual_machine.attach_volume(self.apiClient, self.volume)
self.attached = True self.attached = True
list_volume_response = list_volumes( list_volume_response = Volume.list(
self.apiClient, self.apiClient,
id=self.volume.id id=self.volume.id
) )
@ -429,7 +438,7 @@ class TestVolumes(cloudstackTestCase):
self.attached = False self.attached = False
#Sleep to ensure the current state will reflected in other calls #Sleep to ensure the current state will reflected in other calls
time.sleep(self.services["sleep"]) time.sleep(self.services["sleep"])
list_volume_response = list_volumes( list_volume_response = Volume.list(
self.apiClient, self.apiClient,
id=self.volume.id id=self.volume.id
) )
@ -501,7 +510,7 @@ class TestVolumes(cloudstackTestCase):
cmd.diskofferingid = self.services['resizeddiskofferingid'] cmd.diskofferingid = self.services['resizeddiskofferingid']
success = False success = False
try: try:
response = self.apiClient.resizeVolume(cmd) self.apiClient.resizeVolume(cmd)
except Exception as ex: except Exception as ex:
#print str(ex) #print str(ex)
if "invalid" in str(ex): if "invalid" in str(ex):
@ -516,7 +525,7 @@ class TestVolumes(cloudstackTestCase):
cmd.diskofferingid = "invalid id" cmd.diskofferingid = "invalid id"
success = False success = False
try: try:
response = self.apiClient.resizeVolume(cmd) self.apiClient.resizeVolume(cmd)
except Exception as ex: except Exception as ex:
if "invalid" in str(ex): if "invalid" in str(ex):
success = True success = True
@ -527,7 +536,7 @@ class TestVolumes(cloudstackTestCase):
# try to resize a root disk with a disk offering, root can only be resized by size= # try to resize a root disk with a disk offering, root can only be resized by size=
# get root vol from created vm # get root vol from created vm
list_volume_response = list_volumes( list_volume_response = Volume.list(
self.apiClient, self.apiClient,
virtualmachineid=self.virtual_machine.id, virtualmachineid=self.virtual_machine.id,
type='ROOT', type='ROOT',
@ -540,7 +549,7 @@ class TestVolumes(cloudstackTestCase):
cmd.diskofferingid = self.services['diskofferingid'] cmd.diskofferingid = self.services['diskofferingid']
success = False success = False
try: try:
response = self.apiClient.resizeVolume(cmd) self.apiClient.resizeVolume(cmd)
except Exception as ex: except Exception as ex:
if "Can only resize Data volumes" in str(ex): if "Can only resize Data volumes" in str(ex):
success = True success = True
@ -578,7 +587,7 @@ class TestVolumes(cloudstackTestCase):
count = 0 count = 0
success = True success = True
while count < 10: while count < 10:
list_volume_response = list_volumes( list_volume_response = Volume.list(
self.apiClient, self.apiClient,
id=self.volume.id, id=self.volume.id,
type='DATADISK' type='DATADISK'
@ -637,7 +646,7 @@ class TestVolumes(cloudstackTestCase):
count = 0 count = 0
success = False success = False
while count < 3: while count < 3:
list_volume_response = list_volumes( list_volume_response = Volume.list(
self.apiClient, self.apiClient,
id=self.volume.id, id=self.volume.id,
type='DATADISK' type='DATADISK'
@ -661,7 +670,7 @@ class TestVolumes(cloudstackTestCase):
self.debug("Resize Root for : %s" % self.virtual_machine.id) self.debug("Resize Root for : %s" % self.virtual_machine.id)
# get root vol from created vm # get root vol from created vm
list_volume_response = list_volumes( list_volume_response = Volume.list(
self.apiClient, self.apiClient,
virtualmachineid=self.virtual_machine.id, virtualmachineid=self.virtual_machine.id,
type='ROOT', type='ROOT',
@ -679,7 +688,7 @@ class TestVolumes(cloudstackTestCase):
count = 0 count = 0
success = False success = False
while count < 3: while count < 3:
list_volume_response = list_volumes( list_volume_response = Volume.list(
self.apiClient, self.apiClient,
id=rootvolume.id id=rootvolume.id
) )
@ -732,7 +741,7 @@ class TestVolumes(cloudstackTestCase):
cmd.id = self.volume_1.id cmd.id = self.volume_1.id
self.apiClient.deleteVolume(cmd) self.apiClient.deleteVolume(cmd)
list_volume_response = list_volumes( list_volume_response = Volume.list(
self.apiClient, self.apiClient,
id=self.volume_1.id, id=self.volume_1.id,
type='DATADISK' type='DATADISK'