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,20 +745,24 @@ 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.account = Account.create( cls._cleanup = []
try:
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,
cls.services["virtual_machine"], cls.services["virtual_machine"],
templateid=template.id, templateid=template.id,
@ -765,27 +770,20 @@ class TestTemplates(cloudstackTestCase):
domainid=cls.account.domainid, domainid=cls.account.domainid,
serviceofferingid=cls.service_offering.id, serviceofferingid=cls.service_offering.id,
) )
#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,46 +489,43 @@ class TestScaleVmDynamicServiceOffering(cloudstackTestCase):
if value == USER_ACCOUNT: if value == USER_ACCOUNT:
isadmin=False isadmin=False
# Create Account try:
self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id, admin=isadmin) # Create Account
apiclient = self.testClient.getUserApiClient( self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id, admin=isadmin)
self.cleanup.append(self.account)
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
self.services["service_offering"]["cpunumber"] = "2" self.services["service_offering"]["cpunumber"] = "2"
self.services["service_offering"]["cpuspeed"] = "256" self.services["service_offering"]["cpuspeed"] = "256"
self.services["service_offering"]["memory"] = "128" self.services["service_offering"]["memory"] = "128"
serviceOffering_static_1 = ServiceOffering.create(self.apiclient, serviceOffering_static_1 = ServiceOffering.create(self.apiclient,
self.services["service_offering"]) self.services["service_offering"])
self.services["service_offering"]["cpunumber"] = "4" self.services["service_offering"]["cpunumber"] = "4"
serviceOffering_static_2 = ServiceOffering.create(self.apiclient, serviceOffering_static_2 = ServiceOffering.create(self.apiclient,
self.services["service_offering"]) self.services["service_offering"])
self.cleanup_co.append(serviceOffering_static_1) self.cleanup_co.append(serviceOffering_static_1)
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,69 +551,59 @@ class TestScaleVmDynamicServiceOffering(cloudstackTestCase):
if value == USER_ACCOUNT: if value == USER_ACCOUNT:
isadmin=False isadmin=False
# Create Account and api client try:
self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id, admin=isadmin) # Create Account and api client
apiclient = self.testClient.getUserApiClient( self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id, admin=isadmin)
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) self.cleanup.append(self.account)
# Create static and dynamic service offerings # Create static and dynamic service offerings
self.services["service_offering"]["cpunumber"] = "2" self.services["service_offering"]["cpunumber"] = "2"
self.services["service_offering"]["cpuspeed"] = "256" self.services["service_offering"]["cpuspeed"] = "256"
self.services["service_offering"]["memory"] = "128" self.services["service_offering"]["memory"] = "128"
serviceOffering_static = ServiceOffering.create(self.apiclient, serviceOffering_static = ServiceOffering.create(self.apiclient,
self.services["service_offering"]) self.services["service_offering"])
self.services["service_offering"]["cpunumber"] = "" self.services["service_offering"]["cpunumber"] = ""
self.services["service_offering"]["cpuspeed"] = "" self.services["service_offering"]["cpuspeed"] = ""
self.services["service_offering"]["memory"] = "" self.services["service_offering"]["memory"] = ""
serviceOffering_dynamic = ServiceOffering.create(self.apiclient, serviceOffering_dynamic = ServiceOffering.create(self.apiclient,
self.services["service_offering"]) self.services["service_offering"])
self.cleanup_co.append(serviceOffering_static) self.cleanup_co.append(serviceOffering_static)
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)
# Stop VM
virtualMachine_2.stop(apiclient)
except Exception as e: except Exception as e:
self.fail("vm creation failed: %s" % e) self.fail("Exception occuered: %s" % e)
# Stop VM and verify it is in stopped state # Scale VM to dynamic service offering proving only custom cpu number
self.stopVM(virtualMachine_2) with self.assertRaises(Exception):
# Scale VM to dynamic service offering proving only custom cpu number
try:
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,48 +625,45 @@ class TestScaleVmDynamicServiceOffering(cloudstackTestCase):
if value == USER_ACCOUNT: if value == USER_ACCOUNT:
isadmin=False isadmin=False
# Create account and api client try:
self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id, admin=isadmin) # Create account and api client
apiclient = self.testClient.getUserApiClient( self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id, admin=isadmin)
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) self.cleanup.append(self.account)
# Create dynamic and static service offering # Create dynamic and static service offering
self.services["service_offering"]["cpunumber"] = "" self.services["service_offering"]["cpunumber"] = ""
self.services["service_offering"]["cpuspeed"] = "" self.services["service_offering"]["cpuspeed"] = ""
self.services["service_offering"]["memory"] = "" self.services["service_offering"]["memory"] = ""
serviceOffering_dynamic = ServiceOffering.create(self.apiclient, serviceOffering_dynamic = ServiceOffering.create(self.apiclient,
self.services["service_offering"]) self.services["service_offering"])
self.services["service_offering"]["cpunumber"] = "4" self.services["service_offering"]["cpunumber"] = "4"
self.services["service_offering"]["cpuspeed"] = "256" self.services["service_offering"]["cpuspeed"] = "256"
self.services["service_offering"]["memory"] = "128" self.services["service_offering"]["memory"] = "128"
serviceOffering_static = ServiceOffering.create(self.apiclient, serviceOffering_static = ServiceOffering.create(self.apiclient,
self.services["service_offering"]) self.services["service_offering"])
self.cleanup_co.append(serviceOffering_static) self.cleanup_co.append(serviceOffering_static)
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,62 +690,52 @@ class TestScaleVmDynamicServiceOffering(cloudstackTestCase):
if value == USER_ACCOUNT: if value == USER_ACCOUNT:
isadmin=False isadmin=False
# Create Account try:
self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id, admin=isadmin) # Create Account
apiclient = self.testClient.getUserApiClient( self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id, admin=isadmin)
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) self.cleanup.append(self.account)
# Create dynamic service offerings # Create dynamic service offerings
self.services["service_offering"]["cpunumber"] = "" self.services["service_offering"]["cpunumber"] = ""
self.services["service_offering"]["cpuspeed"] = "" self.services["service_offering"]["cpuspeed"] = ""
self.services["service_offering"]["memory"] = "" self.services["service_offering"]["memory"] = ""
serviceOffering_dynamic_1 = ServiceOffering.create(self.apiclient, serviceOffering_dynamic_1 = ServiceOffering.create(self.apiclient,
self.services["service_offering"]) self.services["service_offering"])
serviceOffering_dynamic_2 = ServiceOffering.create(self.apiclient, serviceOffering_dynamic_2 = ServiceOffering.create(self.apiclient,
self.services["service_offering"]) self.services["service_offering"])
self.cleanup_co.append(serviceOffering_dynamic_1) self.cleanup_co.append(serviceOffering_dynamic_1)
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

@ -5,9 +5,9 @@
# to you under the Apache License, Version 2.0 (the # to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance # "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at # with the License. You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, # Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an # software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@ -1901,27 +1901,11 @@ class TestStartStopVMWithEgressRule(cloudstackTestCase):
"Check egress rule created properly" "Check egress rule created properly"
) )
# Stop virtual machine try:
self.debug("Stopping virtual machine: %s" % self.virtual_machine.id) # Stop virtual machine
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,23 +16,47 @@
# 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):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
cls.testClient = super(TestVolumes, cls).getClsTestClient() cls.testClient = super(TestVolumes, cls).getClsTestClient()
cls.api_client = cls.testClient.getApiClient() cls.api_client = cls.testClient.getApiClient()
cls.services = cls.testClient.getParsedTestDataConfig() cls.services = cls.testClient.getParsedTestDataConfig()
@ -112,9 +136,9 @@ class TestVolumes(cloudstackTestCase):
except Exception as e: except Exception as e:
raise Exception("Warning: Exception during cleanup : %s" % e) raise Exception("Warning: Exception during cleanup : %s" % e)
def __verify_values(self, expected_vals, actual_vals): def __verify_values(self, expected_vals, actual_vals):
""" """
@summary: Function to verify expected and actual values @summary: Function to verify expected and actual values
Step1: Initializing return flag to True Step1: Initializing return flag to True
Step1: Verifying length of expected and actual dictionaries is matching. Step1: Verifying length of expected and actual dictionaries is matching.
@ -2142,7 +2166,7 @@ class TestListInstances(cloudstackTestCase):
@attr(tags=["advanced", "basic", "selfservice"]) @attr(tags=["advanced", "basic", "selfservice"])
def test_04_list_Destroyed_vm(self): def test_04_list_Destroyed_vm(self):
""" """
@Desc: Test List Destroyed VM's @Desc: Test List Destroyed VM's
@Steps: @Steps:
Step1: Listing all the Destroyed VMs for a user Step1: Listing all the Destroyed VMs for a user
@ -2250,7 +2274,7 @@ class TestListInstances(cloudstackTestCase):
@attr(tags=["advanced", "basic", "selfservice"]) @attr(tags=["advanced", "basic", "selfservice"])
def test_05_list_vm_by_id(self): def test_05_list_vm_by_id(self):
""" """
@Desc: Test List VM by Id @Desc: Test List VM by Id
@Steps: @Steps:
Step1: Listing all the VMs for a user Step1: Listing all the VMs for a user
@ -2352,7 +2376,7 @@ class TestListInstances(cloudstackTestCase):
@attr(tags=["advanced", "basic", "selfservice"]) @attr(tags=["advanced", "basic", "selfservice"])
def test_06_list_vm_by_name(self): def test_06_list_vm_by_name(self):
""" """
@Desc: Test List VM's by Name @Desc: Test List VM's by Name
@Steps: @Steps:
Step1: Listing all the VMs for a user Step1: Listing all the VMs for a user
@ -2394,7 +2418,7 @@ class TestListInstances(cloudstackTestCase):
) )
self.cleanup.append(vm_created) self.cleanup.append(vm_created)
vms.update({i: vm_created}) vms.update({i: vm_created})
# Listing all the VM's for a User # Listing all the VM's for a User
list_vms_after = VirtualMachine.list( list_vms_after = VirtualMachine.list(
self.userapiclient, self.userapiclient,
@ -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
@ -3284,7 +3292,7 @@ class TestListInstances(cloudstackTestCase):
@attr(tags=["advanced", "provisioning"]) @attr(tags=["advanced", "provisioning"])
def test_12_vm_nics(self): def test_12_vm_nics(self):
""" """
@Desc: Test to verify Nics for a VM @Desc: Test to verify Nics for a VM
@Steps: @Steps:
Step1: Deploying a VM Step1: Deploying a VM
@ -3293,7 +3301,7 @@ class TestListInstances(cloudstackTestCase):
Step4: Creating 1 network Step4: Creating 1 network
Step5: Listing all the networks again Step5: Listing all the networks again
Step6: Verifying that the list size is 2 Step6: Verifying that the list size is 2
Step7: Verifying that VM deployed in step1 has only 1 nic Step7: Verifying that VM deployed in step1 has only 1 nic
and it is same as network listed in step3 and it is same as network listed in step3
Step8: Adding the networks created in step4 to VM deployed in step1 Step8: Adding the networks created in step4 to VM deployed in step1
Step9: Verifying that VM deployed in step1 has 2 nics Step9: Verifying that VM deployed in step1 has 2 nics
@ -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,
@ -3513,7 +3520,7 @@ 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,
@ -3566,7 +3573,7 @@ class TestInstances(cloudstackTestCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
try: try:
cls._cleanup = [] cls._cleanup = []
cls.testClient = super(TestInstances, cls).getClsTestClient() cls.testClient = super(TestInstances, cls).getClsTestClient()
cls.api_client = cls.testClient.getApiClient() cls.api_client = cls.testClient.getApiClient()
cls.services = cls.testClient.getParsedTestDataConfig() cls.services = cls.testClient.getParsedTestDataConfig()
@ -3587,13 +3594,13 @@ class TestInstances(cloudstackTestCase):
cls.storagetype = 'shared' cls.storagetype = 'shared'
cls.services["service_offerings"]["tiny"]["storagetype"] = 'shared' cls.services["service_offerings"]["tiny"]["storagetype"] = 'shared'
cls.services["disk_offering"]["storagetype"] = 'shared' cls.services["disk_offering"]["storagetype"] = 'shared'
cls.services['mode'] = cls.zone.networktype cls.services['mode'] = cls.zone.networktype
cls.services["virtual_machine"]["hypervisor"] = cls.testClient.getHypervisorInfo() cls.services["virtual_machine"]["hypervisor"] = cls.testClient.getHypervisorInfo()
cls.services["virtual_machine"]["zoneid"] = cls.zone.id cls.services["virtual_machine"]["zoneid"] = cls.zone.id
cls.services["virtual_machine"]["template"] = cls.template.id cls.services["virtual_machine"]["template"] = cls.template.id
cls.services["custom_volume"]["zoneid"] = cls.zone.id cls.services["custom_volume"]["zoneid"] = cls.zone.id
# Creating Disk offering, Service Offering and Account # Creating Disk offering, Service Offering and Account
cls.disk_offering = DiskOffering.create( cls.disk_offering = DiskOffering.create(
cls.api_client, cls.api_client,
@ -3648,7 +3655,7 @@ class TestInstances(cloudstackTestCase):
return return
def __verify_values(self, expected_vals, actual_vals): def __verify_values(self, expected_vals, actual_vals):
""" """
@Desc: Function to verify expected and actual values @Desc: Function to verify expected and actual values
@Steps: @Steps:
Step1: Initializing return flag to True Step1: Initializing return flag to True
@ -3660,10 +3667,10 @@ class TestInstances(cloudstackTestCase):
Step4: returning the return flag after all the values are verified Step4: returning the return flag after all the values are verified
""" """
return_flag = True return_flag = True
if len(expected_vals) != len(actual_vals): if len(expected_vals) != len(actual_vals):
return False return False
keys = expected_vals.keys() keys = expected_vals.keys()
for i in range(0, len(expected_vals)): for i in range(0, len(expected_vals)):
exp_val = expected_vals[keys[i]] exp_val = expected_vals[keys[i]]
@ -3680,8 +3687,8 @@ class TestInstances(cloudstackTestCase):
@attr(tags=["advanced", "basic", "provisioning"]) @attr(tags=["advanced", "basic", "provisioning"])
def test_13_attach_detach_iso(self): def test_13_attach_detach_iso(self):
""" """
@Desc: Test Attach ISO to VM and Detach ISO from VM. @Desc: Test Attach ISO to VM and Detach ISO from VM.
@Steps: @Steps:
Step1: Listing all the VMs for a user Step1: Listing all the VMs for a user
Step2: Verifying that the size of the list is 0 Step2: Verifying that the size of the list is 0
@ -3808,15 +3815,15 @@ class TestInstances(cloudstackTestCase):
@attr(tags=["advanced", "basic", "provisioning"]) @attr(tags=["advanced", "basic", "provisioning"])
def test_14_vm_snapshot_pagination(self): def test_14_vm_snapshot_pagination(self):
""" """
@Desc: Test VM Snapshots pagination. @Desc: Test VM Snapshots pagination.
@Steps: @Steps:
Step1: Deploying a VM Step1: Deploying a VM
Step2: Listing all the Snapshots of the VM deployed in Step 1 Step2: Listing all the Snapshots of the VM deployed in Step 1
Step3: Verifying that the list size is 0 Step3: Verifying that the list size is 0
Step4: Creating (pagesize + 1) number of Snapshots for the VM Step4: Creating (pagesize + 1) number of Snapshots for the VM
Step5: Listing all the Snapshots of the VM deployed in Step 1 Step5: Listing all the Snapshots of the VM deployed in Step 1
Step6: Verifying that the list size is (pagesize + 1) Step6: Verifying that the list size is (pagesize + 1)
Step7: Listing all the VM snapshots in Page 1 with page size Step7: Listing all the VM snapshots in Page 1 with page size
Step8: Verifying that size of the list is same as page size Step8: Verifying that size of the list is same as page size
Step9: Listing all the VM snapshots in Page 2 with page size Step9: Listing all the VM snapshots in Page 2 with page size
@ -3965,8 +3972,8 @@ class TestInstances(cloudstackTestCase):
@attr(tags=["advanced", "basic", "provisioning"]) @attr(tags=["advanced", "basic", "provisioning"])
def test_15_revert_vm_to_snapshot(self): def test_15_revert_vm_to_snapshot(self):
""" """
@Desc: Test Revert VM to Snapshot functionality. @Desc: Test Revert VM to Snapshot functionality.
@Steps: @Steps:
Step1: Deploying a VM Step1: Deploying a VM
Step2: Listing all the Snapshots of the VM deployed in Step 1 Step2: Listing all the Snapshots of the VM deployed in Step 1
@ -4064,14 +4071,14 @@ class TestInstances(cloudstackTestCase):
len(list_snapshots_after), len(list_snapshots_after),
"Count of VM Snapshots is not matching" "Count of VM Snapshots is not matching"
) )
# Verifying that only 1 snapshot is having current flag set to true # Verifying that only 1 snapshot is having current flag set to true
# and that snapshot is the latest snapshot created (snapshot2) # and that snapshot is the latest snapshot created (snapshot2)
current_count = 0 current_count = 0
for i in range(0, len(list_snapshots_after)): for i in range(0, len(list_snapshots_after)):
if(list_snapshots_after[i].current is True): if(list_snapshots_after[i].current is True):
current_count = current_count + 1 current_count = current_count + 1
current_snapshot = list_snapshots_after[i] current_snapshot = list_snapshots_after[i]
self.assertEquals( self.assertEquals(
1, 1,
current_count, current_count,
@ -4104,7 +4111,7 @@ class TestInstances(cloudstackTestCase):
len(list_snapshots_after), len(list_snapshots_after),
"Count of VM Snapshots is not matching" "Count of VM Snapshots is not matching"
) )
# Verifying that only 1 snapshot is having current flag set to true # Verifying that only 1 snapshot is having current flag set to true
# and that snapshot is snapshot1 # and that snapshot is snapshot1
current_count = 0 current_count = 0
for i in range(0, len(list_snapshots_after)): for i in range(0, len(list_snapshots_after)):
@ -4125,7 +4132,7 @@ class TestInstances(cloudstackTestCase):
@attr(tags=["advanced", "basic", "selfservice"]) @attr(tags=["advanced", "basic", "selfservice"])
def test_16_list_vm_volumes_pagination(self): def test_16_list_vm_volumes_pagination(self):
""" """
@Desc: Test to verify pagination of Volumes for a VM @Desc: Test to verify pagination of Volumes for a VM
@Steps: @Steps:
Step1: Deploying a VM Step1: Deploying a VM
@ -4218,7 +4225,7 @@ class TestInstances(cloudstackTestCase):
self.userapiclient, self.userapiclient,
volume_created volume_created
) )
# List all the volumes for the VM again # List all the volumes for the VM again
list_volumes_after = Volume.list( list_volumes_after = Volume.list(
self.userapiclient, self.userapiclient,
@ -4299,7 +4306,7 @@ class TestInstances(cloudstackTestCase):
@attr(tags=["advanced", "basic", "provisioning"]) @attr(tags=["advanced", "basic", "provisioning"])
def test_17_running_vm_scaleup(self): def test_17_running_vm_scaleup(self):
""" """
@Desc: Test to verify change service for Running VM @Desc: Test to verify change service for Running VM
@Steps: @Steps:
Step1: Checking if dynamic scaling of virtual machines is enabled in zone and template. Step1: Checking if dynamic scaling of virtual machines is enabled in zone and template.
@ -4437,7 +4444,7 @@ class TestInstances(cloudstackTestCase):
@attr(tags=["advanced", "basic", "provisioning"]) @attr(tags=["advanced", "basic", "provisioning"])
def test_18_stopped_vm_change_service(self): def test_18_stopped_vm_change_service(self):
""" """
@Desc: Test to verify change service for Stopped VM @Desc: Test to verify change service for Stopped VM
@Steps: @Steps:
Step1: Deploying a VM Step1: Deploying a VM
@ -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,
@ -4573,7 +4564,7 @@ class TestInstances(cloudstackTestCase):
@attr(tags=["advanced", "basic", "provisioning"]) @attr(tags=["advanced", "basic", "provisioning"])
def test_19_create_reset_vm_sshkey(self): def test_19_create_reset_vm_sshkey(self):
""" """
@Desc: Test to verify creation and reset of SSH Key for VM @Desc: Test to verify creation and reset of SSH Key for VM
@Steps: @Steps:
Step1: Deploying a VM Step1: Deploying a VM
@ -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
@ -4652,7 +4627,7 @@ class TestInstances(cloudstackTestCase):
list_keypairs_before_size = 0 list_keypairs_before_size = 0
if list_keypairs_before is not None: if list_keypairs_before is not None:
list_keypairs_before_size = len(list_keypairs_before) list_keypairs_before_size = len(list_keypairs_before)
# Creating a new Key pair # Creating a new Key pair
new_keypair = SSHKeyPair.create( new_keypair = SSHKeyPair.create(
self.userapiclient, self.userapiclient,
@ -4716,7 +4691,7 @@ class TestInstances(cloudstackTestCase):
@attr(tags=["advanced", "basic", "selfservice"]) @attr(tags=["advanced", "basic", "selfservice"])
def test_20_update_vm_displayname_group(self): def test_20_update_vm_displayname_group(self):
""" """
@Desc: Test to verify Update VM details @Desc: Test to verify Update VM details
@Steps: @Steps:
Step1: List all the VM's for a user Step1: List all the VM's for a user
@ -4817,7 +4792,7 @@ class TestInstances(cloudstackTestCase):
@attr(tags=["advanced", "basic", "provisioning"]) @attr(tags=["advanced", "basic", "provisioning"])
def test_21_restore_vm(self): def test_21_restore_vm(self):
""" """
@Desc: Test to verify Restore VM @Desc: Test to verify Restore VM
@Steps: @Steps:
Step1: List all the VM's for a user Step1: List all the VM's for a user
@ -4904,7 +4879,7 @@ class TestInstances(cloudstackTestCase):
@attr(tags=["advanced", "selfservice"]) @attr(tags=["advanced", "selfservice"])
def test_22_deploy_vm_multiple_networks(self): def test_22_deploy_vm_multiple_networks(self):
""" """
@Desc: Test to verify deploy VM with multiple networks @Desc: Test to verify deploy VM with multiple networks
@Steps: @Steps:
Step1: List all the networks for user Step1: List all the networks for user
@ -4924,7 +4899,7 @@ class TestInstances(cloudstackTestCase):
networks_list_size = 0 networks_list_size = 0
if networks_list_before is not None: if networks_list_before is not None:
networks_list_size = len(networks_list_before) networks_list_size = len(networks_list_before)
# Listing Network Offerings # Listing Network Offerings
network_offerings_list = NetworkOffering.list( network_offerings_list = NetworkOffering.list(
self.apiClient, self.apiClient,
@ -4956,7 +4931,7 @@ class TestInstances(cloudstackTestCase):
) )
self.cleanup.append(network) self.cleanup.append(network)
networks_list_size = networks_list_size + 1 networks_list_size = networks_list_size + 1
# Listing the networks again # Listing the networks again
networks_list_after = Network.list( networks_list_after = Network.list(
self.userapiclient, self.userapiclient,
@ -5036,7 +5011,7 @@ class TestInstances(cloudstackTestCase):
@attr(tags=["basic", "provisioning"]) @attr(tags=["basic", "provisioning"])
def test_23_deploy_vm_multiple_securitygroups(self): def test_23_deploy_vm_multiple_securitygroups(self):
""" """
@Desc: Test to verify deploy VM with multiple Security Groups @Desc: Test to verify deploy VM with multiple Security Groups
@Steps: @Steps:
Step1: List all the security groups for user Step1: List all the security groups for user
@ -5057,7 +5032,7 @@ class TestInstances(cloudstackTestCase):
security_groups_list_size = 0 security_groups_list_size = 0
if security_groups_list is not None: if security_groups_list is not None:
security_groups_list_size = len(security_groups_list) security_groups_list_size = len(security_groups_list)
while security_groups_list_size < 2: while security_groups_list_size < 2:
# Creating a security group # Creating a security group
security_group = SecurityGroup.create( security_group = SecurityGroup.create(
@ -5072,7 +5047,7 @@ class TestInstances(cloudstackTestCase):
) )
self.cleanup.append(security_group) self.cleanup.append(security_group)
security_groups_list_size = security_groups_list_size + 1 security_groups_list_size = security_groups_list_size + 1
# Listing the networks again # Listing the networks again
security_groups_list = SecurityGroup.list( security_groups_list = SecurityGroup.list(
self.userapiclient, self.userapiclient,
@ -5142,7 +5117,7 @@ class TestInstances(cloudstackTestCase):
(vm_securitygroups[i].id != security_groups_list[1].id)): (vm_securitygroups[i].id != security_groups_list[1].id)):
vm_securitygroups_flag = False vm_securitygroups_flag = False
break break
self.assertEquals( self.assertEquals(
True, True,
vm_securitygroups_flag, vm_securitygroups_flag,
@ -5155,7 +5130,7 @@ class TestSnapshots(cloudstackTestCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
try: try:
cls._cleanup = [] cls._cleanup = []
cls.testClient = super(TestSnapshots, cls).getClsTestClient() cls.testClient = super(TestSnapshots, cls).getClsTestClient()
cls.api_client = cls.testClient.getApiClient() cls.api_client = cls.testClient.getApiClient()
cls.services = cls.testClient.getParsedTestDataConfig() cls.services = cls.testClient.getParsedTestDataConfig()
@ -5175,7 +5150,7 @@ class TestSnapshots(cloudstackTestCase):
cls.storagetype = 'shared' cls.storagetype = 'shared'
cls.services["service_offerings"]["tiny"]["storagetype"] = 'shared' cls.services["service_offerings"]["tiny"]["storagetype"] = 'shared'
cls.services["disk_offering"]["storagetype"] = 'shared' cls.services["disk_offering"]["storagetype"] = 'shared'
cls.services['mode'] = cls.zone.networktype cls.services['mode'] = cls.zone.networktype
cls.services["virtual_machine"]["hypervisor"] = cls.testClient.getHypervisorInfo() cls.services["virtual_machine"]["hypervisor"] = cls.testClient.getHypervisorInfo()
cls.services["virtual_machine"]["zoneid"] = cls.zone.id cls.services["virtual_machine"]["zoneid"] = cls.zone.id
@ -5235,7 +5210,7 @@ class TestSnapshots(cloudstackTestCase):
return return
def __verify_values(self, expected_vals, actual_vals): def __verify_values(self, expected_vals, actual_vals):
""" """
@Desc: Function to verify expected and actual values @Desc: Function to verify expected and actual values
@Steps: @Steps:
Step1: Initializing return flag to True Step1: Initializing return flag to True
@ -5267,7 +5242,7 @@ class TestSnapshots(cloudstackTestCase):
@attr(tags=["advanced", "basic", "provisioning"]) @attr(tags=["advanced", "basic", "provisioning"])
def test_01_list_volume_snapshots_pagination(self): def test_01_list_volume_snapshots_pagination(self):
""" """
@Desc: Test to List Volume Snapshots pagination @Desc: Test to List Volume Snapshots pagination
@steps: @steps:
Step1: Listing all the volume snapshots for a user Step1: Listing all the volume snapshots for a user
@ -5399,7 +5374,7 @@ class TestSnapshots(cloudstackTestCase):
@attr(tags=["advanced", "basic", "provisioning"]) @attr(tags=["advanced", "basic", "provisioning"])
def test_02_list_volume_snapshots_byid(self): def test_02_list_volume_snapshots_byid(self):
""" """
@Desc: Test to List Volume Snapshots by Id @Desc: Test to List Volume Snapshots by Id
@Steps: @Steps:
Step1: Listing all the volume snapshots for a user Step1: Listing all the volume snapshots for a user
@ -5517,7 +5492,7 @@ class TestSnapshots(cloudstackTestCase):
@attr(tags=["advanced", "basic", "provisioning"]) @attr(tags=["advanced", "basic", "provisioning"])
def test_03_list_vm_snapshots_pagination(self): def test_03_list_vm_snapshots_pagination(self):
""" """
@Desc: Test to List VM Snapshots pagination @Desc: Test to List VM Snapshots pagination
@Steps: @Steps:
Step1: Listing all the VM snapshots for a user Step1: Listing all the VM snapshots for a user
@ -5653,7 +5628,7 @@ class TestSnapshots(cloudstackTestCase):
@attr(tags=["advanced", "basic", "provisioning"]) @attr(tags=["advanced", "basic", "provisioning"])
def test_04_list_vm_snapshots_byid(self): def test_04_list_vm_snapshots_byid(self):
""" """
@summary: Test to List VM Snapshots by Id @summary: Test to List VM Snapshots by Id
Step1: Listing all the VM snapshots for a user Step1: Listing all the VM snapshots for a user
@ -5749,7 +5724,7 @@ class TestSecurityGroups(cloudstackTestCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
try: try:
cls._cleanup = [] cls._cleanup = []
cls.testClient = super(TestSecurityGroups, cls).getClsTestClient() cls.testClient = super(TestSecurityGroups, cls).getClsTestClient()
cls.api_client = cls.testClient.getApiClient() cls.api_client = cls.testClient.getApiClient()
cls.services = cls.testClient.getParsedTestDataConfig() cls.services = cls.testClient.getParsedTestDataConfig()
@ -5796,7 +5771,7 @@ class TestSecurityGroups(cloudstackTestCase):
return return
def __verify_values(self, expected_vals, actual_vals): def __verify_values(self, expected_vals, actual_vals):
""" """
@Desc: Function to verify expected and actual values @Desc: Function to verify expected and actual values
@Steps: @Steps:
Step1: Initializing return flag to True Step1: Initializing return flag to True
@ -5828,11 +5803,11 @@ class TestSecurityGroups(cloudstackTestCase):
@attr(tags=["basic", "provisioning"]) @attr(tags=["basic", "provisioning"])
def test_01_list_securitygroups_pagination(self): def test_01_list_securitygroups_pagination(self):
""" """
@Desc: Test to List Security Groups pagination @Desc: Test to List Security Groups pagination
@steps: @steps:
Step1: Listing all the Security Groups for a user Step1: Listing all the Security Groups for a user
Step2: Verifying that list size is 1 Step2: Verifying that list size is 1
Step3: Creating (page size) number of Security Groups Step3: Creating (page size) number of Security Groups
Step4: Listing all the Security Groups again for a user Step4: Listing all the Security Groups again for a user
Step5: Verifying that list size is (page size + 1) Step5: Verifying that list size is (page size + 1)
@ -5953,11 +5928,11 @@ class TestSecurityGroups(cloudstackTestCase):
@attr(tags=["basic", "provisioning"]) @attr(tags=["basic", "provisioning"])
def test_02_securitygroups_authorize_revoke_ingress(self): def test_02_securitygroups_authorize_revoke_ingress(self):
""" """
@Desc: Test to Authorize and Revoke Ingress for Security Group @Desc: Test to Authorize and Revoke Ingress for Security Group
@steps: @steps:
Step1: Listing all the Security Groups for a user Step1: Listing all the Security Groups for a user
Step2: Verifying that list size is 1 Step2: Verifying that list size is 1
Step3: Creating a Security Groups Step3: Creating a Security Groups
Step4: Listing all the Security Groups again for a user Step4: Listing all the Security Groups again for a user
Step5: Verifying that list size is 2 Step5: Verifying that list size is 2
@ -6117,11 +6092,11 @@ class TestSecurityGroups(cloudstackTestCase):
@attr(tags=["basic", "provisioning"]) @attr(tags=["basic", "provisioning"])
def test_03_securitygroups_authorize_revoke_egress(self): def test_03_securitygroups_authorize_revoke_egress(self):
""" """
@Desc: Test to Authorize and Revoke Egress for Security Group @Desc: Test to Authorize and Revoke Egress for Security Group
@steps: @steps:
Step1: Listing all the Security Groups for a user Step1: Listing all the Security Groups for a user
Step2: Verifying that list size is 1 Step2: Verifying that list size is 1
Step3: Creating a Security Groups Step3: Creating a Security Groups
Step4: Listing all the Security Groups again for a user Step4: Listing all the Security Groups again for a user
Step5: Verifying that list size is 2 Step5: Verifying that list size is 2
@ -6284,7 +6259,7 @@ class TestVpnCustomerGateways(cloudstackTestCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
try: try:
cls._cleanup = [] cls._cleanup = []
cls.testClient = super(TestVpnCustomerGateways, cls).getClsTestClient() cls.testClient = super(TestVpnCustomerGateways, cls).getClsTestClient()
cls.api_client = cls.testClient.getApiClient() cls.api_client = cls.testClient.getApiClient()
cls.services = cls.testClient.getParsedTestDataConfig() cls.services = cls.testClient.getParsedTestDataConfig()
@ -6331,7 +6306,7 @@ class TestVpnCustomerGateways(cloudstackTestCase):
return return
def __verify_values(self, expected_vals, actual_vals): def __verify_values(self, expected_vals, actual_vals):
""" """
@Desc: Function to verify expected and actual values @Desc: Function to verify expected and actual values
@Steps: @Steps:
Step1: Initializing return flag to True Step1: Initializing return flag to True
@ -6363,7 +6338,7 @@ class TestVpnCustomerGateways(cloudstackTestCase):
@attr(tags=["advanced", "basic", "provisioning"]) @attr(tags=["advanced", "basic", "provisioning"])
def test_01_list_vpncustomergateways_pagination(self): def test_01_list_vpncustomergateways_pagination(self):
""" """
@Desc: Test to List VPN Customer Gateways pagination @Desc: Test to List VPN Customer Gateways pagination
@steps: @steps:
Step1: Listing all the VPN Customer Gateways for a user Step1: Listing all the VPN Customer Gateways for a user
@ -6483,7 +6458,7 @@ class TestVpnCustomerGateways(cloudstackTestCase):
@attr(tags=["advanced", "basic", "provisioning"]) @attr(tags=["advanced", "basic", "provisioning"])
def test_02_update_vpncustomergateways(self): def test_02_update_vpncustomergateways(self):
""" """
@Desc: Test to update VPN Customer Gateways pagination @Desc: Test to update VPN Customer Gateways pagination
@steps: @steps:
Step1: Listing all the VPN Customer Gateways for a user Step1: Listing all the VPN Customer Gateways for a user
@ -6613,7 +6588,7 @@ class TestTemplates(cloudstackTestCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
try: try:
cls._cleanup = [] cls._cleanup = []
cls.testClient = super(TestTemplates, cls).getClsTestClient() cls.testClient = super(TestTemplates, cls).getClsTestClient()
cls.api_client = cls.testClient.getApiClient() cls.api_client = cls.testClient.getApiClient()
cls.services = cls.testClient.getParsedTestDataConfig() cls.services = cls.testClient.getParsedTestDataConfig()
@ -6661,7 +6636,7 @@ class TestTemplates(cloudstackTestCase):
return return
def __verify_values(self, expected_vals, actual_vals): def __verify_values(self, expected_vals, actual_vals):
""" """
@Desc: Function to verify expected and actual values @Desc: Function to verify expected and actual values
@Steps: @Steps:
Step1: Initializing return flag to True Step1: Initializing return flag to True
@ -6693,7 +6668,7 @@ class TestTemplates(cloudstackTestCase):
@attr(tags=["advanced", "basic", "provisioning"]) @attr(tags=["advanced", "basic", "provisioning"])
def test_01_list_templates_pagination(self): def test_01_list_templates_pagination(self):
""" """
@Desc: Test to List Templates pagination @Desc: Test to List Templates pagination
@steps: @steps:
Step1: Listing all the Templates for a user Step1: Listing all the Templates for a user
@ -6706,8 +6681,8 @@ class TestTemplates(cloudstackTestCase):
Step8: Listing all the Templates in page2 Step8: Listing all the Templates in page2
Step9: Verifying that list size is 1 Step9: Verifying that list size is 1
Step10: Listing the template by Id Step10: Listing the template by Id
Step11: Verifying if the template is downloaded and ready. Step11: Verifying if the template is downloaded and ready.
If yes the continuing If yes the continuing
If not waiting and checking for template to be ready till timeout If not waiting and checking for template to be ready till timeout
Step12: Deleting the Template present in page 2 Step12: Deleting the Template present in page 2
Step13: Listing all the Templates in page2 Step13: Listing all the Templates in page2
@ -6853,7 +6828,7 @@ class TestTemplates(cloudstackTestCase):
@attr(tags=["advanced", "basic", "provisioning"]) @attr(tags=["advanced", "basic", "provisioning"])
def test_02_download_template(self): def test_02_download_template(self):
""" """
@Desc: Test to Download Template @Desc: Test to Download Template
@steps: @steps:
Step1: Listing all the Templates for a user Step1: Listing all the Templates for a user
@ -6861,8 +6836,8 @@ class TestTemplates(cloudstackTestCase):
Step3: Creating a Templates Step3: Creating a Templates
Step4: Listing all the Templates again for a user Step4: Listing all the Templates again for a user
Step5: Verifying that list size is 1 Step5: Verifying that list size is 1
Step6: Verifying if the template is in ready state. Step6: Verifying if the template is in ready state.
If yes the continuing If yes the continuing
If not waiting and checking for template to be ready till timeout If not waiting and checking for template to be ready till timeout
Step7: Downloading the template (Extract) Step7: Downloading the template (Extract)
Step8: Verifying that Template is downloaded Step8: Verifying that Template is downloaded
@ -6974,7 +6949,7 @@ class TestTemplates(cloudstackTestCase):
@attr(tags=["advanced", "basic", "provisioning"]) @attr(tags=["advanced", "basic", "provisioning"])
def test_03_edit_template_details(self): def test_03_edit_template_details(self):
""" """
@Desc: Test to Edit Template name, displaytext, OSType @Desc: Test to Edit Template name, displaytext, OSType
@steps: @steps:
Step1: Listing all the Templates for a user Step1: Listing all the Templates for a user
@ -6982,8 +6957,8 @@ class TestTemplates(cloudstackTestCase):
Step3: Creating a Templates Step3: Creating a Templates
Step4: Listing all the Templates again for a user Step4: Listing all the Templates again for a user
Step5: Verifying that list size is 1 Step5: Verifying that list size is 1
Step6: Verifying if the template is in ready state. Step6: Verifying if the template is in ready state.
If yes the continuing If yes the continuing
If not waiting and checking for template to be ready till timeout If not waiting and checking for template to be ready till timeout
Step7: Editing the template name Step7: Editing the template name
Step8: Verifying that Template name is edited Step8: Verifying that Template name is edited
@ -7160,7 +7135,7 @@ class TestTemplates(cloudstackTestCase):
if ostype_list[i].id != template_created.ostypeid: if ostype_list[i].id != template_created.ostypeid:
newostypeid = ostype_list[i].id newostypeid = ostype_list[i].id
break break
edited_template = Template.update( edited_template = Template.update(
template_created, template_created,
self.userapiclient, self.userapiclient,
@ -7290,7 +7265,7 @@ class TestTemplates(cloudstackTestCase):
@attr(tags=["advanced", "basic", "provisioning"]) @attr(tags=["advanced", "basic", "provisioning"])
def test_04_copy_template(self): def test_04_copy_template(self):
""" """
@Desc: Test to copy Template from one zone to another @Desc: Test to copy Template from one zone to another
@steps: @steps:
Step1: Listing Zones available for a user Step1: Listing Zones available for a user
@ -7504,7 +7479,7 @@ class TestIsos(cloudstackTestCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
try: try:
cls._cleanup = [] cls._cleanup = []
cls.testClient = super(TestIsos, cls).getClsTestClient() cls.testClient = super(TestIsos, cls).getClsTestClient()
cls.api_client = cls.testClient.getApiClient() cls.api_client = cls.testClient.getApiClient()
cls.services = cls.testClient.getParsedTestDataConfig() cls.services = cls.testClient.getParsedTestDataConfig()
@ -7552,7 +7527,7 @@ class TestIsos(cloudstackTestCase):
return return
def __verify_values(self, expected_vals, actual_vals): def __verify_values(self, expected_vals, actual_vals):
""" """
@Desc: Function to verify expected and actual values @Desc: Function to verify expected and actual values
@Steps: @Steps:
Step1: Initializing return flag to True Step1: Initializing return flag to True
@ -7584,7 +7559,7 @@ class TestIsos(cloudstackTestCase):
@attr(tags=["advanced", "basic", "provisioning"]) @attr(tags=["advanced", "basic", "provisioning"])
def test_01_list_isos_pagination(self): def test_01_list_isos_pagination(self):
""" """
@Desc: Test to List ISO's pagination @Desc: Test to List ISO's pagination
@steps: @steps:
Step1: Listing all the ISO's for a user Step1: Listing all the ISO's for a user
@ -7597,8 +7572,8 @@ class TestIsos(cloudstackTestCase):
Step8: Listing all the ISO's in page2 Step8: Listing all the ISO's in page2
Step9: Verifying that list size is 1 Step9: Verifying that list size is 1
Step10: Listing the ISO's by Id Step10: Listing the ISO's by Id
Step11: Verifying if the ISO is downloaded and ready. Step11: Verifying if the ISO is downloaded and ready.
If yes the continuing If yes the continuing
If not waiting and checking for iso to be ready till timeout If not waiting and checking for iso to be ready till timeout
Step12: Deleting the ISO present in page 2 Step12: Deleting the ISO present in page 2
Step13: Listing all the ISO's in page2 Step13: Listing all the ISO's in page2
@ -7738,7 +7713,7 @@ class TestIsos(cloudstackTestCase):
@attr(tags=["advanced", "basic", "provisioning"]) @attr(tags=["advanced", "basic", "provisioning"])
def test_02_download_iso(self): def test_02_download_iso(self):
""" """
@Desc: Test to Download ISO @Desc: Test to Download ISO
@steps: @steps:
Step1: Listing all the ISO's for a user Step1: Listing all the ISO's for a user
@ -7746,8 +7721,8 @@ class TestIsos(cloudstackTestCase):
Step3: Creating an ISO Step3: Creating an ISO
Step4: Listing all the ISO's again for a user Step4: Listing all the ISO's again for a user
Step5: Verifying that list size is 1 Step5: Verifying that list size is 1
Step6: Verifying if the ISO is in ready state. Step6: Verifying if the ISO is in ready state.
If yes the continuing If yes the continuing
If not waiting and checking for template to be ready till timeout If not waiting and checking for template to be ready till timeout
Step7: Downloading the ISO (Extract) Step7: Downloading the ISO (Extract)
Step8: Verifying the details of downloaded ISO Step8: Verifying the details of downloaded ISO
@ -7853,7 +7828,7 @@ class TestIsos(cloudstackTestCase):
@attr(tags=["advanced", "basic", "provisioning"]) @attr(tags=["advanced", "basic", "provisioning"])
def test_03_edit_iso_details(self): def test_03_edit_iso_details(self):
""" """
@Desc: Test to Edit ISO name, displaytext, OSType @Desc: Test to Edit ISO name, displaytext, OSType
@steps: @steps:
Step1: Listing all the ISO's for a user Step1: Listing all the ISO's for a user
@ -7861,8 +7836,8 @@ class TestIsos(cloudstackTestCase):
Step3: Creating an ISO Step3: Creating an ISO
Step4: Listing all the ISO's again for a user Step4: Listing all the ISO's again for a user
Step5: Verifying that list size is 1 Step5: Verifying that list size is 1
Step6: Verifying if the ISO is in ready state. Step6: Verifying if the ISO is in ready state.
If yes the continuing If yes the continuing
If not waiting and checking for template to be ready till timeout If not waiting and checking for template to be ready till timeout
Step7: Editing the ISO's name, displaytext Step7: Editing the ISO's name, displaytext
Step8: Verifying that ISO name and displaytext are edited Step8: Verifying that ISO name and displaytext are edited
@ -7990,7 +7965,7 @@ class TestIsos(cloudstackTestCase):
if ostype_list[i].id != iso_created.ostypeid: if ostype_list[i].id != iso_created.ostypeid:
newostypeid = ostype_list[i].id newostypeid = ostype_list[i].id
break break
edited_iso = Iso.update( edited_iso = Iso.update(
iso_created, iso_created,
self.userapiclient, self.userapiclient,
@ -8037,7 +8012,7 @@ class TestIsos(cloudstackTestCase):
@attr(tags=["advanced", "basic", "provisioning"]) @attr(tags=["advanced", "basic", "provisioning"])
def test_04_copy_iso(self): def test_04_copy_iso(self):
""" """
@Desc: Test to copy ISO from one zone to another @Desc: Test to copy ISO from one zone to another
@steps: @steps:
Step1: Listing Zones available for a user Step1: Listing Zones available for a user
@ -8234,7 +8209,7 @@ class TestNetworks(cloudstackTestCase):
@classmethod @classmethod
def setUpClass(cls): def setUpClass(cls):
try: try:
cls._cleanup = [] cls._cleanup = []
cls.testClient = super(TestNetworks, cls).getClsTestClient() cls.testClient = super(TestNetworks, cls).getClsTestClient()
cls.api_client = cls.testClient.getApiClient() cls.api_client = cls.testClient.getApiClient()
cls.services = cls.testClient.getParsedTestDataConfig() cls.services = cls.testClient.getParsedTestDataConfig()
@ -9646,4 +9621,4 @@ class TestNetworks(cloudstackTestCase):
networkid=network_created.id networkid=network_created.id
) )
self.assertIsNone(list_network_acl, "ACL list is not empty for newly created network") self.assertIsNone(list_network_acl, "ACL list is not empty for newly created network")
return return

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)
self.vm_1.stop(self.apiclient) try:
self.vm_2.stop(self.apiclient) self.vm_1.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.lb_rule_1.assign(self.apiclient, [self.vm_1, self.vm_2])
self.vm_2.name, self.vm_2.stop(self.apiclient)
self.lb_rule_1.name)) except Exception as e:
self.lb_rule_1.assign(self.apiclient, [self.vm_1, self.vm_2]) self.fail("Exception occured: %s" % e)
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.debug("Stopped VM: %s" % self.vm_2.name)
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,24 +1072,20 @@ 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)
virtual_machine.stop(self.apiclient)
# Assign virtual machine to different account
virtual_machine.assign_virtual_machine(self.apiclient, account=account_2.name, domainid=self.domain.id)
# Start VM
virtual_machine.start(self.apiclient)
# Verify that new network is created in other account
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)
except Exception as e: except Exception as e:
self.fail("vm creation failed: %s" % e) self.fail("Exception occured: %s" % e)
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
virtual_machine.assign_virtual_machine(self.apiclient, account=account_2.name, domainid=self.domain.id)
# Start VM
virtual_machine.start(self.apiclient)
# Verify that new network is created in other account
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)
return return
@ddt @ddt

View File

@ -5,9 +5,9 @@
# to you under the Apache License, Version 2.0 (the # to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance # "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at # with the License. You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, # Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an # software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@ -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,53 +630,56 @@ 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
self.debug("Deploying VM for with public template: %s" % try:
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(
self.apiclient, self.apiclient,
self.services["server"], self.services["server"],
templateid=self.template.id, templateid=self.template.id,
serviceofferingid=self.service_offering.id, serviceofferingid=self.service_offering.id,
projectid=self.project.id projectid=self.project.id
) )
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"
) )
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(
self.apiclient, self.apiclient,
projectid=self.project.id, projectid=self.project.id,
type='ROOT', type='ROOT',
listall=True listall=True
) )
self.assertEqual( self.assertEqual(
isinstance(volumes, list), isinstance(volumes, list),
True, True,
"Check for list volume response return valid data" "Check for list volume response return valid data"
) )
volume = volumes[0] volume = volumes[0]
self.debug("Creating template from volume: %s" % volume.id) self.debug("Creating template from volume: %s" % volume.id)
# Create a template from the ROOTDISK # Create a template from the ROOTDISK
template_1 = Template.create( template_1 = Template.create(
self.apiclient, self.apiclient,
self.services["template"], self.services["template"],
volumeid=volume.id, volumeid=volume.id,
projectid=self.project.id projectid=self.project.id
) )
self.cleanup.append(template_1) self.cleanup.append(template_1)
# Verify Template state # Verify Template state
self.assertEqual( self.assertEqual(
template_1.isready, template_1.isready,
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,83 +692,83 @@ 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).
self.debug("Deploying VM for with public template: %s" % try:
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(
self.apiclient, self.apiclient,
self.services["server"], self.services["server"],
templateid=self.template.id, templateid=self.template.id,
serviceofferingid=self.service_offering.id, serviceofferingid=self.service_offering.id,
projectid=self.project.id projectid=self.project.id
) )
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" virtual_machine_1.stop(self.apiclient)
) # Get the Root disk of VM
self.debug("Stopping the VM: %s" % virtual_machine_1.id) volumes = list_volumes(
virtual_machine_1.stop(self.apiclient)
# Get the Root disk of VM
volumes = list_volumes(
self.apiclient, self.apiclient,
projectid=self.project.id, projectid=self.project.id,
type='ROOT', type='ROOT',
listall=True listall=True
) )
self.assertEqual( self.assertEqual(
isinstance(volumes, list), isinstance(volumes, list),
True, True,
"Check for list volume response return valid data" "Check for list volume response return valid data"
) )
volume = volumes[0] volume = volumes[0]
self.debug("Creating template from volume: %s" % volume.id) self.debug("Creating template from volume: %s" % volume.id)
# Create a template from the ROOTDISK # Create a template from the ROOTDISK
template_1 = Template.create( template_1 = Template.create(
self.apiclient, self.apiclient,
self.services["template"], self.services["template"],
volumeid=volume.id, volumeid=volume.id,
projectid=self.project.id projectid=self.project.id
) )
self.cleanup.append(template_1) self.cleanup.append(template_1)
# Verify Template state # Verify Template state
self.assertEqual( self.assertEqual(
template_1.isready, template_1.isready,
True, True,
"Check Template is in ready state or not" "Check Template is in ready state or not"
) )
# Update template permissions to grant permission to project # Update template permissions to grant permission to project
self.debug( self.debug(
"Updating template permissions:%s to grant access to project: %s" % ( "Updating template permissions:%s to grant access to project: %s" % (
template_1.id, template_1.id,
self.project.id self.project.id
)) ))
template_1.updatePermissions( template_1.updatePermissions(
self.apiclient, self.apiclient,
op='add', op='add',
projectids=self.project.id projectids=self.project.id
) )
self.debug("Deploying VM for with privileged template: %s" % self.debug("Deploying VM for with privileged template: %s" %
self.template.id) self.template.id)
virtual_machine_2 = VirtualMachine.create( virtual_machine_2 = VirtualMachine.create(
self.apiclient, self.apiclient,
self.services["server"], self.services["server"],
templateid=template_1.id, templateid=template_1.id,
serviceofferingid=self.service_offering.id, serviceofferingid=self.service_offering.id,
projectid=self.project.id projectid=self.project.id
) )
self.cleanup.append(virtual_machine_2) self.cleanup.append(virtual_machine_2)
# Verify VM state # Verify VM state
self.assertEqual( self.assertEqual(
virtual_machine_2.state, virtual_machine_2.state,
'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

@ -5,9 +5,9 @@
# to you under the Apache License, Version 2.0 (the # to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance # "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at # with the License. You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, # Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an # software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@ -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
self.debug("Stopping the VM: %s" % self.virtual_machine.id) try:
# Stop the VM self.debug("Stopping the VM: %s" % self.virtual_machine.id)
self.virtual_machine.stop(self.apiclient) # Stop the VM
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)
self.virtual_machine.stop(self.apiclient) try:
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
)) ))
self.virtual_machine.detach_volume(self.apiclient, data_volume) try:
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,26 +704,28 @@ class TestTemplateUsage(cloudstackTestCase):
cls.services["ostype"] cls.services["ostype"]
) )
cls.services["server"]["zoneid"] = cls.zone.id cls.services["server"]["zoneid"] = cls.zone.id
cls.account = Account.create( cls._cleanup = []
try:
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.services["account"] = cls.account.name cls._cleanup.append(cls.account)
cls.services["account"] = cls.account.name
cls.project = Project.create( cls.project = Project.create(
cls.api_client, cls.api_client,
cls.services["project"], cls.services["project"],
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,
cls.services["server"], cls.services["server"],
templateid=template.id, templateid=template.id,
@ -707,25 +733,22 @@ class TestTemplateUsage(cloudstackTestCase):
projectid=cls.project.id projectid=cls.project.id
) )
#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 = list_volumes(
time.sleep(30)
list_volume = list_volumes(
cls.api_client, cls.api_client,
projectid=cls.project.id, projectid=cls.project.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.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

@ -5,9 +5,9 @@
# to you under the Apache License, Version 2.0 (the # to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance # "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at # with the License. You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, # Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an # software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@ -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,118 +135,93 @@ 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
# Create VMs, NAT Rules etc cls._cleanup = []
cls.account = Account.create( try:
cls.api_client, # Create VMs, NAT Rules etc
cls.services["account"], cls.account = Account.create(
domainid=domain.id cls.api_client,
) cls.services["account"],
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,
cls.services["virtual_machine"], cls.services["virtual_machine"],
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
# create egress rule to allow wget of my cloud-set-guest-password script # create egress rule to allow wget of my cloud-set-guest-password script
if cls.zone.networktype.lower() == 'advanced': if cls.zone.networktype.lower() == 'advanced':
EgressFireWallRule.create(cls.api_client, EgressFireWallRule.create(cls.api_client,
networkid=networkid, networkid=networkid,
protocol=cls.services["egress"]["protocol"], protocol=cls.services["egress"]["protocol"],
startport=cls.services["egress"]["startport"], startport=cls.services["egress"]["startport"],
endport=cls.services["egress"]["endport"], endport=cls.services["egress"]["endport"],
cidrlist=cls.services["egress"]["cidrlist"]) cidrlist=cls.services["egress"]["cidrlist"])
cls.virtual_machine.password = cls.services["virtual_machine"]["password"] cls.virtual_machine.password = cls.services["virtual_machine"]["password"]
ssh = cls.virtual_machine.get_ssh_client() ssh = cls.virtual_machine.get_ssh_client()
# below steps are required to get the new password from VR(reset password) # below steps are required to get the new password from VR(reset password)
# http://cloudstack.org/dl/cloud-set-guest-password # http://cloudstack.org/dl/cloud-set-guest-password
# Copy this file to /etc/init.d # Copy this file to /etc/init.d
# chmod +x /etc/init.d/cloud-set-guest-password # chmod +x /etc/init.d/cloud-set-guest-password
# chkconfig --add cloud-set-guest-password # chkconfig --add cloud-set-guest-password
# similar steps to get SSH key from web so as to make it ssh enabled # similar steps to get SSH key from web so as to make it ssh enabled
cmds = [ cmds = [
"cd /etc/init.d;wget http://people.apache.org/~tsp/cloud-set-guest-password", "cd /etc/init.d;wget http://people.apache.org/~tsp/cloud-set-guest-password",
"chmod +x /etc/init.d/cloud-set-guest-password", "chmod +x /etc/init.d/cloud-set-guest-password",
"chkconfig --add cloud-set-guest-password", "chkconfig --add cloud-set-guest-password",
"cd /etc/init.d;wget http://downloads.sourceforge.net/project/cloudstack/SSH%20Key%20Gen%20Script/" + \ "cd /etc/init.d;wget http://downloads.sourceforge.net/project/cloudstack/SSH%20Key%20Gen%20Script/" + \
"cloud-set-guest-sshkey.in?r=http%3A%2F%2Fsourceforge" + \ "cloud-set-guest-sshkey.in?r=http%3A%2F%2Fsourceforge" + \
".net%2Fprojects%2Fcloudstack%2Ffiles%2FSSH%2520Key%2520Gen%2520Script%2F&ts=1331225219&use_mirror=iweb", ".net%2Fprojects%2Fcloudstack%2Ffiles%2FSSH%2520Key%2520Gen%2520Script%2F&ts=1331225219&use_mirror=iweb",
"chmod +x /etc/init.d/cloud-set-guest-sshkey.in", "chmod +x /etc/init.d/cloud-set-guest-sshkey.in",
"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"] cls.api_client,
while True: virtualmachineid=cls.virtual_machine.id,
time.sleep(cls.services["sleep"]) type='ROOT',
listall=True)
# Ensure that VM is in stopped state if isinstance(list_volume, list):
list_vm_response = list_virtual_machines( cls.volume = list_volume[0]
cls.api_client, else:
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( raise Exception(
"Failed to stop VM (ID: %s) " %
vm.id)
timeout = timeout - 1
list_volume = list_volumes(
cls.api_client,
virtualmachineid=cls.virtual_machine.id,
type='ROOT',
listall=True
)
if isinstance(list_volume, list):
cls.volume = list_volume[0]
else:
raise Exception(
"Exception: Unable to find root volume for VM: %s" % "Exception: Unable to find root volume for VM: %s" %
cls.virtual_machine.id) cls.virtual_machine.id)
cls.services["template"]["ostype"] = cls.services["ostype"] cls.services["template"]["ostype"] = cls.services["ostype"]
#Create templates for Edit, Delete & update permissions testcases #Create templates for Edit, Delete & update permissions testcases
cls.pw_ssh_enabled_template = Template.create( cls.pw_ssh_enabled_template = Template.create(
cls.api_client, cls.api_client,
cls.services["template"], cls.services["template"],
cls.volume.id, cls.volume.id,
account=cls.account.name, account=cls.account.name,
domainid=cls.account.domainid domainid=cls.account.domainid
) )
# Delete the VM - No longer needed cls._cleanup.append(cls.pw_ssh_enabled_template)
cls.virtual_machine.delete(cls.api_client) # Delete the VM - No longer needed
cls.virtual_machine.delete(cls.api_client)
cls._cleanup = [ except Exception as e:
cls.service_offering, cls.tearDownClass()
cls.pw_ssh_enabled_template, raise unittest.SkipTest("Exception in setUpClass: %s" % e)
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)
#Stop virtual machine try:
cls.virtual_machine.stop(cls.api_client) #Stop virtual machine
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

@ -5,9 +5,9 @@
# to you under the Apache License, Version 2.0 (the # to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance # "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at # with the License. You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, # Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an # software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@ -747,11 +747,12 @@ 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
self.debug( try:
"Updating template resource limit for account: %s" % self.debug(
"Updating template resource limit for account: %s" %
self.account_1.name) self.account_1.name)
# Set usage_vm=1 for Account 1 # Set usage_vm=1 for Account 1
update_resource_limit( update_resource_limit(
self.apiclient, self.apiclient,
4, # Template 4, # Template
account=self.account_1.name, account=self.account_1.name,
@ -759,10 +760,10 @@ class TestResourceLimitsAccount(cloudstackTestCase):
max=1 max=1
) )
self.debug( self.debug(
"Updating volume resource limit for account: %s" % "Updating volume resource limit for account: %s" %
self.account_1.name) self.account_1.name)
virtual_machine_1 = VirtualMachine.create( virtual_machine_1 = VirtualMachine.create(
self.apiclient, self.apiclient,
self.services["server"], self.services["server"],
templateid=self.template.id, templateid=self.template.id,
@ -770,19 +771,19 @@ class TestResourceLimitsAccount(cloudstackTestCase):
domainid=self.account_1.domainid, domainid=self.account_1.domainid,
serviceofferingid=self.service_offering.id serviceofferingid=self.service_offering.id
) )
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( self.debug(
"Deploying virtual machine for account: %s" % "Deploying virtual machine for account: %s" %
self.account_2.name) self.account_2.name)
# Create VM for second account # Create VM for second account
virtual_machine_2 = VirtualMachine.create( virtual_machine_2 = VirtualMachine.create(
self.apiclient, self.apiclient,
self.services["server"], self.services["server"],
templateid=self.template.id, templateid=self.template.id,
@ -790,33 +791,33 @@ class TestResourceLimitsAccount(cloudstackTestCase):
domainid=self.account_2.domainid, domainid=self.account_2.domainid,
serviceofferingid=self.service_offering.id serviceofferingid=self.service_offering.id
) )
self.cleanup.append(virtual_machine_2) self.cleanup.append(virtual_machine_2)
# Verify VM state # Verify VM state
self.assertEqual( self.assertEqual(
virtual_machine_2.state, virtual_machine_2.state,
'Running', 'Running',
"Check VM state is Running or not" "Check VM state is Running or not"
) )
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(
self.apiclient, self.apiclient,
virtualmachineid=virtual_machine_1.id, virtualmachineid=virtual_machine_1.id,
type='ROOT', type='ROOT',
listall=True listall=True
) )
self.assertEqual( self.assertEqual(
isinstance(volumes, list), isinstance(volumes, list),
True, True,
"Check for list volume response return valid data" "Check for list volume response return valid data"
) )
volume = volumes[0] volume = volumes[0]
self.debug( self.debug(
"Creating template from volume: %s" % volume.id) "Creating template from volume: %s" % volume.id)
# Create a template from the ROOTDISK (Account 1) # Create a template from the ROOTDISK (Account 1)
template_1 = Template.create( template_1 = Template.create(
self.apiclient, self.apiclient,
self.services["template"], self.services["template"],
volumeid=volume.id, volumeid=volume.id,
@ -824,14 +825,15 @@ class TestResourceLimitsAccount(cloudstackTestCase):
domainid=self.account_1.domainid, domainid=self.account_1.domainid,
) )
self.cleanup.append(template_1) self.cleanup.append(template_1)
# Verify Template state # Verify Template state
self.assertEqual( self.assertEqual(
template_1.isready, template_1.isready,
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,25 +843,27 @@ class TestResourceLimitsAccount(cloudstackTestCase):
account=self.account_1.name, account=self.account_1.name,
domainid=self.account_1.domainid, domainid=self.account_1.domainid,
) )
virtual_machine_2.stop(self.apiclient)
# Get the Root disk of VM try:
volumes = list_volumes( virtual_machine_2.stop(self.apiclient)
# Get the Root disk of VM
volumes = list_volumes(
self.apiclient, self.apiclient,
virtualmachineid=virtual_machine_2.id, virtualmachineid=virtual_machine_2.id,
type='ROOT', type='ROOT',
listall=True listall=True
) )
self.assertEqual( self.assertEqual(
isinstance(volumes, list), isinstance(volumes, list),
True, True,
"Check for list volume response return valid data" "Check for list volume response return valid data"
) )
volume = volumes[0] volume = volumes[0]
self.debug( self.debug(
"Creating template from volume: %s" % volume.id) "Creating template from volume: %s" % volume.id)
# Create a snapshot from the ROOTDISK (Account 1) # Create a snapshot from the ROOTDISK (Account 1)
template_2 = Template.create( template_2 = Template.create(
self.apiclient, self.apiclient,
self.services["template"], self.services["template"],
volumeid=volume.id, volumeid=volume.id,
@ -867,17 +871,17 @@ class TestResourceLimitsAccount(cloudstackTestCase):
domainid=self.account_2.domainid, domainid=self.account_2.domainid,
) )
self.cleanup.append(template_2) self.cleanup.append(template_2)
# Verify Template state # Verify Template state
self.assertEqual( self.assertEqual(
template_2.isready, template_2.isready,
True, True,
"Check Template is in ready state or not" "Check Template is in ready state or not"
) )
self.debug( self.debug(
"Creating template from volume: %s" % volume.id) "Creating template from volume: %s" % volume.id)
# Create a second volume from the ROOTDISK (Account 2) # Create a second volume from the ROOTDISK (Account 2)
template_3 = Template.create( template_3 = Template.create(
self.apiclient, self.apiclient,
self.services["template"], self.services["template"],
volumeid=volume.id, volumeid=volume.id,
@ -885,13 +889,15 @@ class TestResourceLimitsAccount(cloudstackTestCase):
domainid=self.account_2.domainid, domainid=self.account_2.domainid,
) )
self.cleanup.append(template_3) self.cleanup.append(template_3)
# Verify Template state # Verify Template state
self.assertEqual( self.assertEqual(
template_3.isready, template_3.isready,
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,27 +1262,23 @@ 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.
# Set usage_vm=1 for Account 1 try:
update_resource_limit( # Set usage_vm=1 for Account 1
update_resource_limit(
self.apiclient, self.apiclient,
2, # Volume 2, # Volume
domainid=self.account.domainid, domainid=self.account.domainid,
max=5 max=5
) )
self.debug( # Set usage_vm=1 for Account 1
"Updating template resource limits for domain: %s" % update_resource_limit(
self.account.domainid)
# Set usage_vm=1 for Account 1
update_resource_limit(
self.apiclient, self.apiclient,
4, # Template 4, # Template
domainid=self.account.domainid, domainid=self.account.domainid,
max=2 max=2
) )
virtual_machine_1 = VirtualMachine.create(
self.debug("Deploying VM for account: %s" % self.account.name)
virtual_machine_1 = VirtualMachine.create(
self.apiclient, self.apiclient,
self.services["server"], self.services["server"],
templateid=self.template.id, templateid=self.template.id,
@ -1284,31 +1286,31 @@ class TestResourceLimitsDomain(cloudstackTestCase):
domainid=self.account.domainid, domainid=self.account.domainid,
serviceofferingid=self.service_offering.id serviceofferingid=self.service_offering.id
) )
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"
) )
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(
self.apiclient, self.apiclient,
virtualmachineid=virtual_machine_1.id, virtualmachineid=virtual_machine_1.id,
type='ROOT', type='ROOT',
listall=True listall=True
) )
self.assertEqual( self.assertEqual(
isinstance(volumes, list), isinstance(volumes, list),
True, True,
"Check for list volume response return valid data" "Check for list volume response return valid data"
) )
volume = volumes[0] volume = volumes[0]
self.debug("Creating template from volume: %s" % volume.id) self.debug("Creating template from volume: %s" % volume.id)
# Create a template from the ROOTDISK # Create a template from the ROOTDISK
template_1 = Template.create( template_1 = Template.create(
self.apiclient, self.apiclient,
self.services["template"], self.services["template"],
volumeid=volume.id, volumeid=volume.id,
@ -1316,16 +1318,16 @@ class TestResourceLimitsDomain(cloudstackTestCase):
domainid=self.account.domainid, domainid=self.account.domainid,
) )
self.cleanup.append(template_1) self.cleanup.append(template_1)
# Verify Template state # Verify Template state
self.assertEqual( self.assertEqual(
template_1.isready, template_1.isready,
True, True,
"Check Template is in ready state or not" "Check Template is in ready state or not"
) )
self.debug("Creating template from volume: %s" % volume.id) self.debug("Creating template from volume: %s" % volume.id)
# Create a template from the ROOTDISK # Create a template from the ROOTDISK
template_2 = Template.create( template_2 = Template.create(
self.apiclient, self.apiclient,
self.services["template"], self.services["template"],
volumeid=volume.id, volumeid=volume.id,
@ -1333,13 +1335,15 @@ class TestResourceLimitsDomain(cloudstackTestCase):
domainid=self.account.domainid, domainid=self.account.domainid,
) )
self.cleanup.append(template_2) self.cleanup.append(template_2)
# Verify Template state # Verify Template state
self.assertEqual( self.assertEqual(
template_2.isready, template_2.isready,
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,12 +370,12 @@ 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,
self.virtual_machine.password self.virtual_machine.password
) )
return return
@ -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"]
) )
self.virtual_machine.stop(self.apiclient) try:
self.virtual_machine.stop(self.apiclient)
# Sleep to ensure that VM is in stopped state self.virtual_machine.start(self.apiclient)
time.sleep(self.services["sleep"]) # Sleep to ensure that VM is in running state
time.sleep(self.services["sleep"])
self.virtual_machine.start(self.apiclient) except Exception as e:
self.fail("Exception occured: %s" % e)
# Sleep to ensure that VM is in running state
time.sleep(self.services["sleep"])
# 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'
) )
@ -1518,8 +1514,8 @@ class TestDeployVMFromTemplate(cloudstackTestCase):
) )
builtin_info = get_builtin_template_info(self.apiclient, self.zone.id) builtin_info = get_builtin_template_info(self.apiclient, self.zone.id)
self.services["template"]["url"] = builtin_info[0] self.services["template"]["url"] = builtin_info[0]
self.services["template"]["hypervisor"] = builtin_info[1] self.services["template"]["hypervisor"] = builtin_info[1]
self.services["template"]["format"] = builtin_info[2] self.services["template"]["format"] = builtin_info[2]
# Register new template # Register new template
@ -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
self.debug("Stopping the virtual machine: %s" % self.vm_1.name) try:
#Stop virtual machine self.debug("Stopping the virtual machine: %s" % self.vm_1.name)
self.vm_1.stop(self.apiclient) #Stop virtual machine
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,
@ -990,11 +1006,11 @@ class TestResourceTags(cloudstackTestCase):
'CentOS', 'CentOS',
'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"],
listall=True, listall=True,
key='OS', key='OS',
value='CentOS' value='CentOS'
@ -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( listall=True,
self.apiclient, key='type',
listall=True, value='manual')
key='type',
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,
@ -1785,14 +1787,14 @@ class TestResourceTags(cloudstackTestCase):
domainid=self.domain.id domainid=self.domain.id
) )
self.cleanup.append(user_account) self.cleanup.append(user_account)
other_user_account = Account.create( other_user_account = Account.create(
self.apiclient, self.apiclient,
self.services["other_user"], self.services["other_user"],
domainid=self.domain.id domainid=self.domain.id
) )
self.cleanup.append(other_user_account) self.cleanup.append(other_user_account)
iso = Iso.create( iso = Iso.create(
self.apiclient, self.apiclient,
self.services["iso"], self.services["iso"],
@ -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,
@ -1877,33 +1875,25 @@ class TestResourceTags(cloudstackTestCase):
domainid=self.domain.id domainid=self.domain.id
) )
self.cleanup.append(user_account) self.cleanup.append(user_account)
iso = Iso.create( iso = Iso.create(
self.apiclient, self.apiclient,
self.services["iso"], self.services["iso"],
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") resourceIds=iso.id,
tag = Tag.create( resourceType='ISO',
self.apiclient, tags={'region': 'India'})
resourceIds=iso.id,
resourceType='ISO',
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,47 +2188,21 @@ 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."
self.debug("Stopping the virtual machine: %s" % self.vm_1.name) try:
#Stop virtual machine self.debug("Stopping the virtual machine: %s" % self.vm_1.name)
self.vm_1.stop(self.apiclient) #Stop virtual machine
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.debug("Creating a tag for user VM")
self.apiclient, tag = Tag.create(
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")
tag = 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'}
) )
self.debug("Tag created: %s" % tag.__dict__) self.debug("Tag created: %s" % tag.__dict__)
tags = Tag.list( tags = Tag.list(
self.apiclient, self.apiclient,
listall=True, listall=True,
resourceType='userVM', resourceType='userVM',
@ -2249,20 +2211,19 @@ class TestResourceTags(cloudstackTestCase):
key='region', key='region',
value='India' value='India'
) )
self.assertEqual( self.assertEqual(
isinstance(tags, list), isinstance(tags, list),
True, True,
"List tags should not return empty response" "List tags should not return empty response"
) )
self.assertEqual( self.assertEqual(
tags[0].value, tags[0].value,
"India", "India",
"Tag created with incorrect value" "Tag created with incorrect value"
) )
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

@ -5,9 +5,9 @@
# to you under the Apache License, Version 2.0 (the # to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance # "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at # with the License. You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, # Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an # software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@ -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,20 +302,24 @@ 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.account = Account.create( cls._cleanup = []
try:
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,
cls.services["virtual_machine"], cls.services["virtual_machine"],
templateid=template.id, templateid=template.id,
@ -321,40 +327,36 @@ class TestTemplates(cloudstackTestCase):
domainid=cls.account.domainid, domainid=cls.account.domainid,
serviceofferingid=cls.service_offering.id, serviceofferingid=cls.service_offering.id,
) )
#Stop virtual machine #Stop virtual machine
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: raise Exception("List volumes failed.")
raise Exception("List volumes failed.")
time.sleep(5) time.sleep(5)
timeout = timeout - 1 timeout = timeout - 1
cls.volume = list_volume[0] cls.volume = list_volume[0]
#Create template from volume #Create template from volume
cls.template = Template.create( cls.template = Template.create(
cls.api_client, cls.api_client,
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

@ -5,9 +5,9 @@
# to you under the Apache License, Version 2.0 (the # to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance # "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at # with the License. You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, # Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an # software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@ -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
self.debug("Stopping the VM: %s" % self.virtual_machine.id) try:
# Stop the VM self.debug("Stopping the VM: %s" % self.virtual_machine.id)
self.virtual_machine.stop(self.apiclient) # Stop the VM
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
# Stop VM try:
self.debug("Stopping VM with ID: %s" % self.virtual_machine.id) # Stop VM
self.virtual_machine.stop(self.apiclient) self.debug("Stopping VM with ID: %s" % self.virtual_machine.id)
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,19 +661,22 @@ class TestTemplateUsage(cloudstackTestCase):
cls.services["ostype"] cls.services["ostype"]
) )
cls.services["server"]["zoneid"] = cls.zone.id cls.services["server"]["zoneid"] = cls.zone.id
cls.account = Account.create( try:
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.services["account"] = cls.account.name cls._cleanup.append(cls.account)
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"]
) )
#create virtual machine cls._cleanup.append(cls.service_offering)
cls.virtual_machine = VirtualMachine.create( #create virtual machine
cls.virtual_machine = VirtualMachine.create(
cls.api_client, cls.api_client,
cls.services["server"], cls.services["server"],
templateid=template.id, templateid=template.id,
@ -665,24 +686,21 @@ class TestTemplateUsage(cloudstackTestCase):
mode=cls.services["mode"] mode=cls.services["mode"]
) )
#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) cls.api_client,
list_volume = list_volumes( virtualmachineid=cls.virtual_machine.id,
cls.api_client, type='ROOT',
virtualmachineid=cls.virtual_machine.id, listall=True)
type='ROOT', if isinstance(list_volume, list):
listall=True cls.volume = list_volume[0]
) else:
if isinstance(list_volume, list): raise Exception("List Volumes failed!")
cls.volume = list_volume[0] except Exception as e:
else: cls.tearDownClass()
raise Exception("List Volumes failed!") raise unittest.SkipTest("Exception in setUpClass: %s" % e)
cls._cleanup = [
cls.account,
]
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

@ -5,9 +5,9 @@
# to you under the Apache License, Version 2.0 (the # to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance # "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at # with the License. You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, # Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an # software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@ -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,9 +199,9 @@ 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
for i in range(self.max_data_volumes): try:
self.debug(i) for i in range(self.max_data_volumes):
volume = Volume.create( volume = Volume.create(
self.apiclient, self.apiclient,
self.services["volume"], self.services["volume"],
zoneid=self.zone.id, zoneid=self.zone.id,
@ -196,134 +209,99 @@ 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" % ( # Check List Volume response for newly created volume
volume.id, list_volume_response = Volume.list(
self.account.name
))
# Check List Volume response for newly created volume
list_volume_response = list_volumes(
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"
) )
# Attach volume to VM # Attach volume to VM
self.virtual_machine.attach_volume( self.virtual_machine.attach_volume(
self.apiclient, self.apiclient,
volume volume
) )
self.debug("Attach volume: %s to VM: %s" % ( # Check all volumes attached to same VM
volume.id, list_volume_response = Volume.list(
self.virtual_machine.id
))
# Check all volumes attached to same VM
list_volume_response = list_volumes(
self.apiclient, self.apiclient,
virtualmachineid=self.virtual_machine.id, virtualmachineid=self.virtual_machine.id,
type='DATADISK', type='DATADISK',
listall=True listall=True
) )
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(
) len(list_volume_response),
self.assertEqual( self.max_data_volumes,
len(list_volume_response), "Volumes attached to the VM %s. Expected %s" % (len(list_volume_response), self.max_data_volumes))
self.max_data_volumes, self.debug("Rebooting the VM: %s" % self.virtual_machine.id)
"Volumes attached to the VM %s. Expected %s" % (len(list_volume_response), self.max_data_volumes) # Reboot VM
) self.virtual_machine.reboot(self.apiclient)
self.debug("Rebooting the VM: %s" % self.virtual_machine.id)
# Reboot VM
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,
) )
#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),
0, 0,
"Check VMs available in List VMs response" "Check VMs available in List VMs response"
) )
self.assertEqual( self.assertEqual(
isinstance(vm_response, list), isinstance(vm_response, list),
True, True,
"Check list VM response for valid list" "Check list VM response for valid list"
) )
vm = vm_response[0] vm = vm_response[0]
self.assertEqual( self.assertEqual(
vm.state, vm.state,
'Running', 'Running',
"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( # Start VM
self.virtual_machine.start(self.apiclient)
# Sleep to ensure that VM is in ready state
time.sleep(self.services["sleep"])
vm_response = VirtualMachine.list(
self.apiclient, self.apiclient,
id=self.virtual_machine.id, id=self.virtual_machine.id,
) )
self.assertEqual( self.assertEqual(
isinstance(vm_response, list), isinstance(vm_response, list),
True, True,
"Check list VM response for valid list" "Check list VM response for valid list"
) )
#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),
0, 0,
"Check VMs available in List VMs response" "Check VMs available in List VMs response"
) )
vm = vm_response[0] vm = vm_response[0]
self.assertEqual( self.assertEqual(
vm.state,
'Stopped',
"Check the state of VM"
)
self.debug("Starting the VM: %s" % self.virtual_machine.id)
# Start VM
self.virtual_machine.start(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,
)
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, vm.state,
'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,10 +454,11 @@ 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
volumes = [] try:
# Create 5 volumes and attach to VM volumes = []
for i in range(self.max_data_volumes): # Create 5 volumes and attach to VM
volume = Volume.create( for i in range(self.max_data_volumes):
volume = Volume.create(
self.apiclient, self.apiclient,
self.services["volume"], self.services["volume"],
zoneid=self.zone.id, zoneid=self.zone.id,
@ -487,155 +466,117 @@ 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" % ( self.cleanup.append(volume)
volume.id, volumes.append(volume)
self.account.name
))
self.cleanup.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" # Attach volume to VM
) self.virtual_machine.attach_volume(
self.debug("Attach volume: %s to VM: %s" % (
volume.id,
self.virtual_machine.id
))
# Attach volume to VM
self.virtual_machine.attach_volume(
self.apiclient, self.apiclient,
volume 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',
listall=True listall=True
) )
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)
) )
# 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" % ( self.virtual_machine.detach_volume(
volume.id,
self.virtual_machine.id
))
self.virtual_machine.detach_volume(
self.apiclient, self.apiclient,
volume volume
) )
# Reboot VM # Reboot VM
self.debug("Rebooting the VM: %s" % self.virtual_machine.id) self.debug("Rebooting the VM: %s" % self.virtual_machine.id)
self.virtual_machine.reboot(self.apiclient) self.virtual_machine.reboot(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,
) )
#Verify VM response to check whether VM deployment was successful #Verify VM response to check whether VM deployment was successful
self.assertEqual( self.assertEqual(
isinstance(vm_response, list), isinstance(vm_response, list),
True, True,
"Check list VM response for valid list" "Check list VM response for valid list"
) )
self.assertNotEqual( self.assertNotEqual(
len(vm_response), len(vm_response),
0, 0,
"Check VMs available in List VMs response" "Check VMs available in List VMs response"
) )
vm = vm_response[0] vm = vm_response[0]
self.assertEqual( self.assertEqual(
vm.state, vm.state,
'Running', 'Running',
"Check the state of VM" "Check the state of VM"
) )
# 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( # Start VM
self.virtual_machine.start(self.apiclient)
# Sleep to ensure that VM is in ready state
time.sleep(self.services["sleep"])
vm_response = VirtualMachine.list(
self.apiclient, self.apiclient,
id=self.virtual_machine.id, id=self.virtual_machine.id,
) )
#Verify VM response to check whether VM deployment was successful #Verify VM response to check whether VM deployment was successful
self.assertEqual( self.assertEqual(
isinstance(vm_response, list), isinstance(vm_response, list),
True, True,
"Check list VM response for valid list" "Check list VM response for valid list"
) )
self.assertNotEqual( self.assertNotEqual(
len(vm_response), len(vm_response),
0, 0,
"Check VMs available in List VMs response" "Check VMs available in List VMs response"
) )
vm = vm_response[0] vm = vm_response[0]
self.assertEqual( self.assertEqual(
vm.state,
'Stopped',
"Check the state of VM"
)
# Start VM
self.debug("Starting the VM: %s" % self.virtual_machine.id)
self.virtual_machine.start(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, vm.state,
'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

@ -5,9 +5,9 @@
# to you under the Apache License, Version 2.0 (the # to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance # "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at # with the License. You may obtain a copy of the License at
# #
# http://www.apache.org/licenses/LICENSE-2.0 # http://www.apache.org/licenses/LICENSE-2.0
# #
# Unless required by applicable law or agreed to in writing, # Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an # software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@ -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,38 +71,43 @@ 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.disk_offering = DiskOffering.create(
cls._cleanup = []
try:
cls.disk_offering = DiskOffering.create(
cls.apiclient, cls.apiclient,
cls.services["disk_offering"] cls.services["disk_offering"]
) )
template = get_template( cls._cleanup.append(cls.disk_offering)
template = get_template(
cls.apiclient, cls.apiclient,
cls.zone.id, cls.zone.id,
cls.services["ostype"] cls.services["ostype"]
) )
if template == FAILED: if template == FAILED:
assert False, "get_template() failed to return template with description %s" % cls.services["ostype"] assert False, "get_template() failed to return template with description %s" % cls.services["ostype"]
cls.services["template"]["ostypeid"] = template.ostypeid cls.services["template"]["ostypeid"] = template.ostypeid
cls.services["template_2"]["ostypeid"] = template.ostypeid cls.services["template_2"]["ostypeid"] = template.ostypeid
cls.services["ostypeid"] = template.ostypeid cls.services["ostypeid"] = template.ostypeid
cls.services["virtual_machine"]["zoneid"] = cls.zone.id cls.services["virtual_machine"]["zoneid"] = cls.zone.id
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.service_offering = ServiceOffering.create( cls._cleanup.append(cls.account)
cls.service_offering = ServiceOffering.create(
cls.apiclient, cls.apiclient,
cls.services["service_offerings"] cls.services["service_offerings"]
) )
#create virtual machine cls._cleanup.append(cls.service_offering)
cls.virtual_machine = VirtualMachine.create( #create virtual machine
cls.virtual_machine = VirtualMachine.create(
cls.apiclient, cls.apiclient,
cls.services["virtual_machine"], cls.services["virtual_machine"],
templateid=template.id, templateid=template.id,
@ -102,47 +116,20 @@ class TestCreateTemplate(cloudstackTestCase):
serviceofferingid=cls.service_offering.id, serviceofferingid=cls.service_offering.id,
mode=cls.services["mode"] mode=cls.services["mode"]
) )
#Stop virtual machine
cls.virtual_machine.stop(cls.apiclient)
#Stop virtual machine list_volume = Volume.list(
cls.virtual_machine.stop(cls.apiclient)
# Poll listVM to ensure VM is stopped properly
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',
listall=True listall=True
) )
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:
self.fail("Failed to stop VM: %s" % e)
list_vm_response = list_virtual_machines(
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
) )
@ -657,7 +648,7 @@ class TestVMLifeCycle(cloudstackTestCase):
except Exception as e: except Exception as e:
self.fail("SSH failed for virtual machine: %s - %s" % self.fail("SSH failed for virtual machine: %s - %s" %
(self.virtual_machine.ipaddress, e)) (self.virtual_machine.ipaddress, e))
mount_dir = "/mnt/tmp" mount_dir = "/mnt/tmp"
cmds = "mkdir -p %s" % mount_dir cmds = "mkdir -p %s" % mount_dir
self.assert_(ssh_client.execute(cmds) == [], "mkdir failed within guest") self.assert_(ssh_client.execute(cmds) == [], "mkdir failed within guest")
@ -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
@ -548,7 +557,7 @@ class TestVolumes(cloudstackTestCase):
success, success,
True, True,
"ResizeVolume - verify root disks cannot be resized by disk offering id") "ResizeVolume - verify root disks cannot be resized by disk offering id")
# Ok, now let's try and resize a volume that is not custom. # Ok, now let's try and resize a volume that is not custom.
cmd.id = self.volume.id cmd.id = self.volume.id
cmd.diskofferingid = self.services['diskofferingid'] cmd.diskofferingid = self.services['diskofferingid']
@ -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'