diff --git a/test/integration/component/test_accounts.py b/test/integration/component/test_accounts.py index 9b9ae753729..f71dea523da 100644 --- a/test/integration/component/test_accounts.py +++ b/test/integration/component/test_accounts.py @@ -18,6 +18,7 @@ """ #Import Local Modules from marvin.cloudstackTestCase import cloudstackTestCase +#from marvin.cloudstackAPI import * from marvin.lib.utils import (random_gen, cleanup_resources) from marvin.lib.base import (Domain, @@ -40,7 +41,7 @@ from marvin.lib.common import (get_domain, get_builtin_template_info, wait_for_cleanup) from nose.plugins.attrib import attr -from marvin.codes import ERROR_CODE_530 +from marvin.cloudstackException import CloudstackAPIException import time class Services: @@ -1672,18 +1673,16 @@ class TestDomainForceRemove(cloudstackTestCase): " to cleanup any remaining resouces") # Sleep 3*account.gc to ensure that all resources are deleted wait_for_cleanup(self.apiclient, ["account.cleanup.interval"]*3) - response = Domain.list( + with self.assertRaises(CloudstackAPIException): + Domain.list( self.apiclient, id=domain.id, listall=True ) - self.assertEqual(response.errorcode, ERROR_CODE_530, "Job should \ - have failed with error code %s, instead got response \ - %s" % (ERROR_CODE_530, str(response))) self.debug("Checking if the resources in domain are deleted") - with self.assertRaises(Exception): - response = Account.list( + with self.assertRaises(CloudstackAPIException): + Account.list( self.apiclient, name=self.account_1.name, domainid=self.account_1.domainid, @@ -1833,8 +1832,6 @@ class TestDomainForceRemove(cloudstackTestCase): ) self.debug("Deleting domain without force option") - response = domain.delete(self.apiclient, cleanup=False) - self.assertEqual(response.errorcode, ERROR_CODE_530, "Job should \ - have failed with error code %s, instead got response \ - %s" % (ERROR_CODE_530, str(response))) + with self.assertRaises(Exception): + domain.delete(self.apiclient, cleanup=False) return diff --git a/test/integration/component/test_add_remove_network.py b/test/integration/component/test_add_remove_network.py index 969d94ca109..c17293d17af 100644 --- a/test/integration/component/test_add_remove_network.py +++ b/test/integration/component/test_add_remove_network.py @@ -58,7 +58,7 @@ from marvin.cloudstackAPI import (addNicToVirtualMachine, removeNicFromVirtualMachine, updateDefaultNicForVirtualMachine) -from marvin.codes import PASS, ERROR_CODE_530 +from marvin.codes import PASS import random import time @@ -466,10 +466,8 @@ class TestAddNetworkToVirtualMachine(cloudstackTestCase): self.cleanup.append(vpc) self.cleanup.append(vpc_off) self.debug("Trying to add VPC to vm belonging to isolated network, this should fail") - response = self.virtual_machine.add_nic(self.apiclient, vpc.id) - self.assertEqual(response.errorcode, ERROR_CODE_530, "Job should \ - have failed with error code %s, instead got response \ - %s" % (ERROR_CODE_530, str(response))) + with self.assertRaises(Exception): + self.virtual_machine.add_nic(self.apiclient, vpc.id) self.debug("Starting virtual machine") self.virtual_machine.start(self.apiclient) self.debug("Disabling vpc offering: %s" % vpc_off.id) @@ -827,10 +825,9 @@ class TestRemoveNetworkFromVirtualMachine(cloudstackTestCase): self.assertEqual(len(vm_list[0].nic), 1, "There should only be default nic present in the vm") self.debug("Trying to remove the default nic of vm : %s, this should fail" % self.virtual_machine.id) - response = self.virtual_machine.remove_nic(self.apiclient, vm_list[0].nic[0].id) - self.assertEqual(response.errorcode, ERROR_CODE_530, "Job should \ - have failed with error code %s, instead got response \ - %s" % (ERROR_CODE_530, str(response))) + with self.assertRaises(Exception): + self.virtual_machine.remove_nic(self.apiclient, vm_list[0].nic[0].id) + self.debug("Removing default nic of vm failed") return @attr(tags = ["advanced"]) diff --git a/test/integration/component/test_affinity_groups.py b/test/integration/component/test_affinity_groups.py index d31746afe5e..d0fa2f7a3d9 100644 --- a/test/integration/component/test_affinity_groups.py +++ b/test/integration/component/test_affinity_groups.py @@ -29,7 +29,6 @@ from marvin.lib.common import (get_zone, get_template, list_virtual_machines, wait_for_cleanup) -from marvin.codes import ERROR_CODE_530 from nose.plugins.attrib import attr class Services: @@ -1087,10 +1086,9 @@ class TestUpdateVMAffinityGroups(cloudstackTestCase): vm1, hostid1 = self.create_vm_in_aff_grps([self.aff_grp[0].name], account_name=self.account.name, domain_id=self.domain.id) aff_grps = [self.aff_grp[0], self.aff_grp[1]] - response = vm1.update_affinity_group(self.api_client, affinitygroupnames=[]) - self.assertEqual(response.errorcode, ERROR_CODE_530, "Job should \ - have failed with error code %s, instead got response \ - %s" % (ERROR_CODE_530, str(response))) + with self.assertRaises(Exception): + vm1.update_affinity_group(self.api_client, affinitygroupnames=[]) + vm1.delete(self.api_client) #Wait for expunge interval to cleanup VM wait_for_cleanup(self.apiclient, ["expunge.delay", "expunge.interval"]) diff --git a/test/integration/component/test_assign_vm.py b/test/integration/component/test_assign_vm.py index 0b07e9f8777..24b63a62f14 100644 --- a/test/integration/component/test_assign_vm.py +++ b/test/integration/component/test_assign_vm.py @@ -38,7 +38,6 @@ from marvin.lib.common import (get_domain, list_snapshots, list_virtual_machines) from marvin.lib.utils import cleanup_resources -from marvin.codes import ERROR_CODE_530 def log_test_exceptions(func): def test_wrap_exception_log(self, *args, **kwargs): @@ -370,14 +369,7 @@ class TestVMOwnership(cloudstackTestCase): # 1. deploy VM in sub subdomain1 # 3. assignVirtualMachine to subdomain2 self.create_vm(self.sdomain_account_user1['account'], self.sdomain_account_user1['domain'],isRunning=True) - response = self.virtual_machine.assign_virtual_machine( - self.apiclient, - self.sdomain_account_user2['account'].name, - self.sdomain_account_user2['domain'].id) - self.assertEqual(response.errorcode, ERROR_CODE_530, "Job should \ - have failed with error code %s, instead got response \ - %s" % (ERROR_CODE_530, str(response))) - return + self.assertRaises(Exception, self.virtual_machine.assign_virtual_machine, self.apiclient, self.sdomain_account_user2['account'].name ,self.sdomain_account_user2['domain'].id) @attr(tags = ["advanced"]) @log_test_exceptions @@ -388,14 +380,7 @@ class TestVMOwnership(cloudstackTestCase): # 1. deploy VM in sub subdomain1 with PF rule set. # 3. assignVirtualMachine to subdomain2 self.create_vm(self.sdomain_account_user1['account'], self.sdomain_account_user1['domain'],pfrule=True) - response = self.virtual_machine.assign_virtual_machine( - self.apiclient, - self.sdomain_account_user2['account'].name, - self.sdomain_account_user2['domain'].id) - self.assertEqual(response.errorcode, ERROR_CODE_530, "Job should \ - have failed with error code %s, instead got response \ - %s" % (ERROR_CODE_530, str(response))) - return + self.assertRaises(Exception, self.virtual_machine.assign_virtual_machine, self.apiclient, self.sdomain_account_user2['account'].name ,self.sdomain_account_user2['domain'].id) @attr(tags = ["advanced"]) @log_test_exceptions diff --git a/test/integration/component/test_ip_reservation.py b/test/integration/component/test_ip_reservation.py index 69d0b89613b..ce76c1ab550 100644 --- a/test/integration/component/test_ip_reservation.py +++ b/test/integration/component/test_ip_reservation.py @@ -38,7 +38,7 @@ from marvin.lib.common import (get_zone, createNetworkRulesForVM, verifyNetworkState) from marvin.codes import (PASS, FAIL, FAILED, UNKNOWN, FAULT, MASTER, - NAT_RULE, STATIC_NAT_RULE, ERROR_CODE_530) + NAT_RULE, STATIC_NAT_RULE) import netaddr import random @@ -270,10 +270,8 @@ class TestIpReservation(cloudstackTestCase): except Exception as e: self.fail("VM creation failed: %s" % e) - response = isolated_network.update(self.apiclient, guestvmcidr=guest_vm_cidr) - self.assertEqual(response.errorcode, ERROR_CODE_530, "Job should \ - have failed with error code %s, instead got response \ - %s" % (ERROR_CODE_530, str(response))) + with self.assertRaises(Exception): + isolated_network.update(self.apiclient, guestvmcidr=guest_vm_cidr) return @attr(tags=["advanced"]) @@ -302,10 +300,8 @@ class TestIpReservation(cloudstackTestCase): except Exception as e: self.fail("VM creation failed: %s" % e) - response = isolated_network.update(self.apiclient, guestvmcidr=guest_vm_cidr) - self.assertEqual(response.errorcode, ERROR_CODE_530, "Job should \ - have failed with error code %s, instead got response \ - %s" % (ERROR_CODE_530, str(response))) + with self.assertRaises(Exception): + isolated_network.update(self.apiclient, guestvmcidr=guest_vm_cidr) return @data(NAT_RULE, STATIC_NAT_RULE) @@ -1083,10 +1079,8 @@ class TestFailureScnarios(cloudstackTestCase): else: isolated_network = resultSet[1] - response = isolated_network.update(self.apiclient, guestvmcidr="10.1.1.0/26") - self.assertEqual(response.errorcode, ERROR_CODE_530, "Job should \ - have failed with error code %s, instead got response \ - %s" % (ERROR_CODE_530, str(response))) + with self.assertRaises(Exception): + response = isolated_network.update(self.apiclient, guestvmcidr="10.1.1.0/26") return @attr(tags=["advanced", "selfservice"]) diff --git a/test/integration/component/test_non_contiguous_vlan.py b/test/integration/component/test_non_contiguous_vlan.py index 1f74252a028..4609af95f13 100644 --- a/test/integration/component/test_non_contiguous_vlan.py +++ b/test/integration/component/test_non_contiguous_vlan.py @@ -27,7 +27,7 @@ #Import local modules -from marvin.cloudstackTestCase import (cloudstackTestCase) +from marvin.cloudstackTestCase import (cloudstackTestCase,unittest) from marvin.lib.base import (Account, ServiceOffering, PhysicalNetwork, @@ -40,7 +40,6 @@ from marvin.lib.common import (get_zone, setNonContiguousVlanIds) from marvin.lib.utils import (cleanup_resources, xsplit) -from marvin.codes import ERROR_CODE_530 from nose.plugins.attrib import attr @@ -318,11 +317,12 @@ class TestNonContiguousVLANRanges(cloudstackTestCase): self.debug("Deployed instance in account: %s" % account.name) self.debug("Trying to remove vlan range : %s , This should fail" % self.vlan["partial_range"][0]) - response = self.physicalnetwork.update(self.apiClient, id = self.physicalnetworkid, vlan = self.vlan["partial_range"][0]) - self.assertEqual(response.errorcode, ERROR_CODE_530, "Job should \ - have failed with error code %s, instead got response \ - %s" % (ERROR_CODE_530, str(response))) + with self.assertRaises(Exception) as e: + self.physicalnetwork.update(self.apiClient, id = self.physicalnetworkid, vlan = self.vlan["partial_range"][0]) + + self.debug("operation failed with exception: %s" % e.exception) account.delete(self.apiclient) + except Exception as e: self.fail("Exception in test case: %s" % e) diff --git a/test/integration/component/test_projects.py b/test/integration/component/test_projects.py index cf6cec8c421..c593fb6d9ef 100644 --- a/test/integration/component/test_projects.py +++ b/test/integration/component/test_projects.py @@ -17,13 +17,15 @@ """ P1 tests for Project """ #Import Local Modules +import marvin from nose.plugins.attrib import attr from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * from marvin.lib.utils import * from marvin.lib.base import * from marvin.lib.common import * -from marvin.codes import ERROR_CODE_530 +from marvin.sshClient import SshClient +import datetime class Services: @@ -428,14 +430,13 @@ class TestCrossDomainAccountAdd(cloudstackTestCase): self.user.domainid, project.id )) - # Add user to the project from different domain - response = project.addAccount( + with self.assertRaises(Exception): + # Add user to the project from different domain + project.addAccount( self.apiclient, self.user.name ) - self.assertEqual(response.errorcode, ERROR_CODE_530, "Job should \ - have failed with error code %s, instead got response \ - %s" % (ERROR_CODE_530, str(response))) + self.debug("User add to project failed!") return @@ -541,10 +542,10 @@ class TestDeleteAccountWithProject(cloudstackTestCase): "Check project name from list response" ) # Deleting account who is owner of the project - response = self.account.delete(self.apiclient) - self.assertEqual(response.errorcode, ERROR_CODE_530, "Job should \ - have failed with error code %s, instead got response \ - %s" % (ERROR_CODE_530, str(response))) + with self.assertRaises(Exception): + self.account.delete(self.apiclient) + self.debug("Deleting account %s failed!" % + self.account.name) return diff --git a/test/integration/component/test_volumes.py b/test/integration/component/test_volumes.py index 4a91e5dff1c..b5b08e2d5c0 100644 --- a/test/integration/component/test_volumes.py +++ b/test/integration/component/test_volumes.py @@ -36,7 +36,6 @@ from marvin.lib.common import (get_domain, get_zone, get_template, get_pod) -from marvin.codes import ERROR_CODE_530 #Import System modules import time @@ -342,17 +341,16 @@ class TestAttachVolume(cloudstackTestCase): True, "Check list volumes response for valid list" ) - self.debug("Trying to Attach volume: %s to VM: %s" % ( + # Attach volume to VM + with self.assertRaises(Exception): + self.debug("Trying to Attach volume: %s to VM: %s" % ( volume.id, self.virtual_machine.id )) - response = self.virtual_machine.attach_volume( + self.virtual_machine.attach_volume( self.apiclient, volume ) - self.assertEqual(response.errorcode, ERROR_CODE_530, "Job should \ - have failed with error code %s, instead got response \ - %s" % (ERROR_CODE_530, str(response))) return class TestAttachDetachVolume(cloudstackTestCase): diff --git a/test/integration/component/test_vpc.py b/test/integration/component/test_vpc.py index 31b421c0fd8..e9d396e8b89 100644 --- a/test/integration/component/test_vpc.py +++ b/test/integration/component/test_vpc.py @@ -25,7 +25,6 @@ from marvin.cloudstackAPI import * from marvin.lib.utils import * from marvin.lib.base import * from marvin.lib.common import * -from marvin.codes import ERROR_CODE_530 class Services: @@ -700,10 +699,8 @@ class TestVPC(cloudstackTestCase): self.debug("Created network with ID: %s" % network_2.id) self.debug("Deleting the VPC with no network") - response = vpc.delete(self.apiclient) - self.assertEqual(response.errorcode, ERROR_CODE_530, "Job should \ - have failed with error code %s, instead got response \ - %s" % (ERROR_CODE_530, str(response))) + with self.assertRaises(Exception): + vpc.delete(self.apiclient) self.debug("Delete VPC failed as there are still networks in VPC") self.debug("Deleting the networks in the VPC") diff --git a/test/integration/component/test_vpc_network.py b/test/integration/component/test_vpc_network.py index 8d12ec64981..a449948c91f 100644 --- a/test/integration/component/test_vpc_network.py +++ b/test/integration/component/test_vpc_network.py @@ -44,7 +44,7 @@ from marvin.lib.common import (get_zone, # For more info on ddt refer to http://ddt.readthedocs.org/en/latest/api.html#module-ddt from ddt import ddt, data import time -from marvin.codes import PASS, ERROR_CODE_530 +from marvin.codes import PASS class Services: """Test VPC network services @@ -2107,14 +2107,12 @@ class TestVPCNetworkUpgrade(cloudstackTestCase): self.fail("Failed to stop VMs, %s" % e) self.debug("Upgrading network offering to support PF services") - response = network_1.update( + with self.assertRaises(Exception): + network_1.update( self.apiclient, networkofferingid=nw_off_vr.id, changecidr=True ) - self.assertEqual(response.errorcode, ERROR_CODE_530, "Job should \ - have failed with error code %s, instead got response \ - %s" % (ERROR_CODE_530, str(response))) return class TestVPCNetworkGc(cloudstackTestCase): diff --git a/test/integration/component/test_vpc_network_lbrules.py b/test/integration/component/test_vpc_network_lbrules.py index 47bdce53a9e..a5625e72166 100644 --- a/test/integration/component/test_vpc_network_lbrules.py +++ b/test/integration/component/test_vpc_network_lbrules.py @@ -39,7 +39,6 @@ from marvin.lib.common import (get_domain, get_template, list_routers) from marvin.lib.utils import cleanup_resources -from marvin.codes import ERROR_CODE_530 import socket import time @@ -641,10 +640,8 @@ class TestVPCNetworkLBRules(cloudstackTestCase): lb_rule = self.create_LB_Rule(public_ip_1, network_1, [vm_1, vm_2], self.services["lbrule_http"]) # In a VPC, the load balancing service is supported only on a single tier. # http://cloudstack.apache.org/docs/en-US/Apache_CloudStack/4.0.2/html/Installation_Guide/configure-vpc.html - response = lb_rule.assign(self.apiclient, [vm_3]) - self.assertEqual(response.errorcode, ERROR_CODE_530, "Job should \ - have failed with error code %s, instead got response \ - %s" % (ERROR_CODE_530, str(response))) + with self.assertRaises(Exception): + lb_rule.assign(self.apiclient, [vm_3]) self.check_wget_from_vm(vm_1, public_ip_1, testnegative=False) return diff --git a/test/integration/component/test_vpc_vms_deployment.py b/test/integration/component/test_vpc_vms_deployment.py index 19aa448792a..1c1f93d37e2 100644 --- a/test/integration/component/test_vpc_vms_deployment.py +++ b/test/integration/component/test_vpc_vms_deployment.py @@ -19,7 +19,7 @@ """ #Import Local Modules from nose.plugins.attrib import attr -from marvin.cloudstackTestCase import cloudstackTestCase +from marvin.cloudstackTestCase import cloudstackTestCase, unittest from marvin.lib.base import (VirtualMachine, NetworkOffering, VpcOffering, @@ -43,7 +43,6 @@ from marvin.lib.common import (get_domain, get_free_vlan) from marvin.lib.utils import cleanup_resources -from marvin.codes import ERROR_CODE_530 from marvin.cloudstackAPI import rebootRouter @@ -1623,10 +1622,8 @@ class TestVMDeployVPC(cloudstackTestCase): "Vm state should be running for each VM deployed" ) self.debug("Trying to delete network: %s" % network_1.name) - response = network_1.delete(self.apiclient) - self.assertEqual(response.errorcode, ERROR_CODE_530, "Job should \ - have failed with error code %s, instead got response \ - %s" % (ERROR_CODE_530, str(response))) + with self.assertRaises(Exception): + network_1.delete(self.apiclient) self.debug("Delete netwpork failed as there are running instances") self.debug("Destroying all the instances in network1: %s" % @@ -2164,10 +2161,8 @@ class TestVMDeployVPC(cloudstackTestCase): ) self.debug("Trying to delete network: %s" % network_1.name) - response = network_1.delete(self.apiclient) - self.assertEqual(response.errorcode, ERROR_CODE_530, "Job should \ - have failed with error code %s, instead got response \ - %s" % (ERROR_CODE_530, str(response))) + with self.assertRaises(Exception): + network_1.delete(self.apiclient) self.debug("Delete network failed as there are running instances") self.debug("Destroying all the instances in network1: %s" % diff --git a/test/integration/smoke/test_network.py b/test/integration/smoke/test_network.py index 85b417ccc84..a9e0c25a36d 100644 --- a/test/integration/smoke/test_network.py +++ b/test/integration/smoke/test_network.py @@ -27,7 +27,6 @@ from marvin.lib.utils import * from marvin.lib.base import * from marvin.lib.common import * from nose.plugins.attrib import attr -from marvin.codes import ERROR_CODE_530 #Import System modules import time @@ -390,14 +389,12 @@ class TestPortForwarding(cloudstackTestCase): try: nat_rule.delete(self.apiclient) + list_nat_rule_response = list_nat_rules( + self.apiclient, + id=nat_rule.id + ) except CloudstackAPIException: - self.fail("Nat Rule deletion failed: %s" % e) - - response = list_nat_rules(self.apiclient, - id=nat_rule.id) - self.assertEqual(response.errorcode, ERROR_CODE_530, "Job should \ - have failed with error code %s, instead got response \ - %s" % (ERROR_CODE_530, str(response))) + self.fail("Nat Rule Deletion or Listing Failed") # Check if the Public SSH port is inaccessible with self.assertRaises(Exception): diff --git a/test/integration/smoke/test_nic.py b/test/integration/smoke/test_nic.py index a76e858226e..592a8391a01 100644 --- a/test/integration/smoke/test_nic.py +++ b/test/integration/smoke/test_nic.py @@ -15,17 +15,14 @@ # specific language governing permissions and limitations # under the License. """ NIC tests for VM """ -from marvin.codes import ERROR_CODE_530 -from marvin.cloudstackTestCase import cloudstackTestCase -from marvin.lib.base import(Account, - ServiceOffering, - Network, - VirtualMachine, - NetworkOffering) -from marvin.lib.common import (get_zone, - get_domain, - get_template, - list_virtual_machines) +import marvin +from marvin.codes import FAILED +from marvin.cloudstackTestCase import * +from marvin.cloudstackAPI import * +from marvin.sshClient import SshClient +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * from nose.plugins.attrib import attr import signal @@ -189,7 +186,7 @@ class TestNic(cloudstackTestCase): existing_nic_id = vm_response.nic[0].id # 1. add a nic - self.virtual_machine.add_nic(self.apiclient, self.test_network2.id) + add_response = self.virtual_machine.add_nic(self.apiclient, self.test_network2.id) time.sleep(5) # now go get the vm list? @@ -234,11 +231,13 @@ class TestNic(cloudstackTestCase): "Verify second adapter is set to default" ) - response = self.virtual_machine.remove_nic(self.apiclient, new_nic_id) - self.assertEqual(response.errorcode, ERROR_CODE_530, "Job should \ - have failed with error code %s, instead got response \ - %s" % (ERROR_CODE_530, str(response))) + sawException = False + try: + self.virtual_machine.remove_nic(self.apiclient, new_nic_id) + except Exception as ex: + sawException = True + self.assertEqual(sawException, True, "Make sure we cannot delete the default NIC") self.virtual_machine.update_default_nic(self.apiclient, existing_nic_id) time.sleep(5) self.virtual_machine.remove_nic(self.apiclient, new_nic_id) diff --git a/test/integration/smoke/test_primary_storage.py b/test/integration/smoke/test_primary_storage.py index 5b24b6490f0..3147d86645f 100644 --- a/test/integration/smoke/test_primary_storage.py +++ b/test/integration/smoke/test_primary_storage.py @@ -17,18 +17,16 @@ """ BVT tests for Primary Storage """ #Import Local Modules -from marvin.cloudstackTestCase import cloudstackTestCase -#from marvin.cloudstackAPI import * -from marvin.lib.utils import cleanup_resources -from marvin.lib.base import StoragePool -from marvin.lib.common import (get_zone, - get_pod, - list_clusters, - list_hosts, - list_storage_pools) +import marvin +from marvin.cloudstackTestCase import * +from marvin.cloudstackAPI import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * from nose.plugins.attrib import attr #Import System modules +import time _multiprocess_shared_ = True class TestPrimaryStorageServices(cloudstackTestCase): diff --git a/test/integration/smoke/test_volumes.py b/test/integration/smoke/test_volumes.py index 352298006a8..c621bc7f3a2 100644 --- a/test/integration/smoke/test_volumes.py +++ b/test/integration/smoke/test_volumes.py @@ -18,9 +18,11 @@ """ #Import Local Modules from marvin.cloudstackTestCase import cloudstackTestCase +#from marvin.cloudstackException import * from marvin.cloudstackAPI import (deleteVolume, extractVolume, resizeVolume) +#from marvin.sshClient import SshClient from marvin.lib.utils import (cleanup_resources, format_volume_to_ext3) from marvin.lib.base import (ServiceOffering, @@ -33,7 +35,7 @@ from marvin.lib.common import (get_domain, get_zone, get_template) from marvin.lib.utils import checkVolumeSize -from marvin.codes import SUCCESS, FAILED, ERROR_CODE_530, XEN_SERVER +from marvin.codes import SUCCESS, FAILED, XEN_SERVER from nose.plugins.attrib import attr #Import System modules import os @@ -402,11 +404,8 @@ class TestVolumes(cloudstackTestCase): cmd.zoneid = self.services["zoneid"] # A proper exception should be raised; # downloading attach VM is not allowed - response = self.apiClient.extractVolume(cmd) - self.assertEqual(response.errorcode, ERROR_CODE_530, "Job should \ - have failed with error code %s, instead got response \ - %s" % (ERROR_CODE_530, str(response))) - return + with self.assertRaises(Exception): + self.apiClient.extractVolume(cmd) @attr(tags = ["advanced", "advancedns", "smoke", "basic", "selfservice"]) def test_04_delete_attached_volume(self): @@ -558,11 +557,15 @@ class TestVolumes(cloudstackTestCase): cmd.id = rootvolume.id cmd.diskofferingid = self.services['diskofferingid'] success = False - - response = self.apiClient.resizeVolume(cmd) - self.assertEqual(response.errorcode, ERROR_CODE_530, "Job should \ - have failed with error code %s, instead got response \ - %s" % (ERROR_CODE_530, str(response))) + try: + self.apiClient.resizeVolume(cmd) + except Exception as ex: + if "Can only resize Data volumes" in str(ex): + success = True + self.assertEqual( + success, + True, + "ResizeVolume - verify root disks cannot be resized by disk offering id") # Ok, now let's try and resize a volume that is not custom. cmd.id = self.volume.id diff --git a/tools/marvin/marvin/cloudstackConnection.py b/tools/marvin/marvin/cloudstackConnection.py index 8044da7ec66..c49edf3a408 100644 --- a/tools/marvin/marvin/cloudstackConnection.py +++ b/tools/marvin/marvin/cloudstackConnection.py @@ -21,23 +21,14 @@ import base64 import hmac import hashlib import time -from cloudstackAPI import * +from cloudstackAPI import queryAsyncJobResult import jsonHelper from marvin.codes import ( FAILED, - INVALID_RESPONSE, - INVALID_INPUT, JOB_FAILED, - JOB_INPROGRESS, JOB_CANCELLED, JOB_SUCCEEDED ) -from requests import ( - ConnectionError, - HTTPError, - Timeout, - RequestException -) from marvin.cloudstackException import ( InvalidParameterException, GetDetailExceptionInfo) @@ -106,10 +97,12 @@ class CSConnection(object): marvinRequest(cmd, response_type=response_cmd) if async_response != FAILED: job_status = async_response.jobstatus - if job_status in [JOB_FAILED, - JOB_CANCELLED, + if job_status in [JOB_CANCELLED, JOB_SUCCEEDED]: break + elif job_status == JOB_FAILED: + raise Exception("Job failed: %s"\ + % async_response) time.sleep(5) timeout -= 5 self.logger.debug("=== JobId:%s is Still Processing, " diff --git a/tools/marvin/marvin/codes.py b/tools/marvin/marvin/codes.py index c72a6bde8f9..ef49c0c3c8f 100644 --- a/tools/marvin/marvin/codes.py +++ b/tools/marvin/marvin/codes.py @@ -60,7 +60,6 @@ JOB_INPROGRESS = 0 JOB_SUCCEEDED = 1 JOB_FAILED = 2 JOB_CANCELLED = 3 -ERROR_CODE_530 = 530 ''' User Related Codes '''