diff --git a/test/integration/component/maint/test_egress_rules_host_maintenance.py b/test/integration/component/maint/test_egress_rules_host_maintenance.py index 2b817879c4b..a27ada3dcae 100644 --- a/test/integration/component/maint/test_egress_rules_host_maintenance.py +++ b/test/integration/component/maint/test_egress_rules_host_maintenance.py @@ -23,9 +23,9 @@ from nose.plugins.attrib import attr from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * from marvin.sshClient import SshClient -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * #Import System modules import time @@ -100,19 +100,17 @@ class TestEgressAfterHostMaintenance(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.services = Services().services - cls.api_client = super( - TestEgressAfterHostMaintenance, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestEgressAfterHostMaintenance, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype cls.pod = get_pod( cls.api_client, - zoneid=cls.zone.id + zone_id=cls.zone.id ) template = get_template( diff --git a/test/integration/component/maint/test_high_availability.py b/test/integration/component/maint/test_high_availability.py index 6ada659cd4f..cc687f83ea7 100644 --- a/test/integration/component/maint/test_high_availability.py +++ b/test/integration/component/maint/test_high_availability.py @@ -23,9 +23,9 @@ import marvin from nose.plugins.attrib import attr from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * from marvin.sshClient import SshClient import datetime @@ -107,24 +107,16 @@ class TestHighAvailability(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestHighAvailability, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestHighAvailability, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain( - cls.api_client, - cls.services - ) - cls.zone = get_zone( - cls.api_client, - cls.services - ) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.pod = get_pod( cls.api_client, - zoneid=cls.zone.id, - services=cls.services + zone_id=cls.zone.id ) cls.template = get_template( cls.api_client, diff --git a/test/integration/component/maint/test_host_high_availability.py b/test/integration/component/maint/test_host_high_availability.py index b4c50c7114d..4cd7fd8fe84 100644 --- a/test/integration/component/maint/test_host_high_availability.py +++ b/test/integration/component/maint/test_host_high_availability.py @@ -21,9 +21,10 @@ from nose.plugins.attrib import attr from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * +import time class Services: @@ -76,20 +77,13 @@ class TestHostHighAvailability(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestHostHighAvailability, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestHostHighAvailability, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain( - cls.api_client, - cls.services - ) - cls.zone = get_zone( - cls.api_client, - cls.services - ) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, @@ -626,11 +620,7 @@ class TestHostHighAvailability(cloudstackTestCase): #verify the VM live migration happened to another running host self.debug("Waiting for VM to come up") - wait_for_vm( - self.apiclient, - virtualmachineid=vm_with_ha_enabled.id, - interval=timeout - ) + time.sleep(timeout) vms = VirtualMachine.list( self.apiclient, @@ -758,11 +748,7 @@ class TestHostHighAvailability(cloudstackTestCase): #verify the VM live migration happened to another running host self.debug("Waiting for VM to come up") - wait_for_vm( - self.apiclient, - virtualmachineid=vm_with_ha_disabled.id, - interval=timeout - ) + time.sleep(timeout) vms = VirtualMachine.list( self.apiclient, diff --git a/test/integration/component/maint/test_multiple_ip_ranges.py b/test/integration/component/maint/test_multiple_ip_ranges.py index dc8021bc91e..982dd7c85bc 100644 --- a/test/integration/component/maint/test_multiple_ip_ranges.py +++ b/test/integration/component/maint/test_multiple_ip_ranges.py @@ -18,10 +18,10 @@ """ from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.cloudstackException import cloudstackAPIException -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.cloudstackException import CloudstackAPIException +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * # from netaddr import * import netaddr from nose.plugins.attrib import attr @@ -87,13 +87,15 @@ class TestMultipleIpRanges(cloudstackTestCase): """ @classmethod def setUpClass(cls): - cls.api_client = super(TestMultipleIpRanges, cls).getClsTestClient().getApiClient() - cls.dbclient = super(TestMultipleIpRanges, cls).getClsTestClient().getDbConnection() + cls.testClient = super(TestEgressAfterHostMaintenance, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.dbclient = cls.testClient.getDbConnection() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) - cls.pod = get_pod(cls.api_client, cls.zone.id, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) + cls.pod = get_pod(cls.api_client, cls.zone.id) cls.services['mode'] = cls.zone.networktype cls.services["domainid"] = cls.domain.id cls.services["zoneid"] = cls.zone.id diff --git a/test/integration/component/maint/test_redundant_router.py b/test/integration/component/maint/test_redundant_router.py index 617a54673bc..66bb477e046 100644 --- a/test/integration/component/maint/test_redundant_router.py +++ b/test/integration/component/maint/test_redundant_router.py @@ -16,9 +16,9 @@ # under the License. from nose.plugins.attrib import attr -from marvin.integration.lib.base import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.common import * +from marvin.lib.base import * +from marvin.lib.utils import * +from marvin.lib.common import * #Import Local Modules from marvin.cloudstackTestCase import cloudstackTestCase @@ -137,14 +137,13 @@ class TestCreateRvRNetworkOffering(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestCreateRvRNetworkOffering, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestCreateRvRNetworkOffering, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls._cleanup = [] return @@ -231,14 +230,13 @@ class TestCreateRvRNetwork(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestCreateRvRNetwork, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestCreateRvRNetwork, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, @@ -433,14 +431,13 @@ class TestCreateRvRNetworkNonDefaultGuestCidr(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestCreateRvRNetworkNonDefaultGuestCidr, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestCreateRvRNetworkNonDefaultGuestCidr, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, @@ -642,14 +639,13 @@ class TestRVRInternals(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestRVRInternals, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestRVRInternals, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, @@ -685,6 +681,7 @@ class TestRVRInternals(cloudstackTestCase): def setUp(self): self.apiclient = self.testClient.getApiClient() + self.hypervisor = self.testClient.getHypervisorInfo() self.dbclient = self.testClient.getDbConnection() self.account = Account.create( self.apiclient, @@ -846,7 +843,7 @@ class TestRVRInternals(cloudstackTestCase): self.debug(master_router.linklocalip) # Check eth2 port for master router - if self.apiclient.hypervisor.lower() == 'vmware': + if self.hypervisor.lower() == 'vmware': result = get_process_status( self.apiclient.connection.mgtSvr, 22, @@ -854,7 +851,7 @@ class TestRVRInternals(cloudstackTestCase): self.apiclient.connection.passwd, master_router.linklocalip, 'ip addr show eth2', - hypervisor=self.apiclient.hypervisor + hypervisor=self.hypervisor ) else: result = get_process_status( @@ -882,7 +879,7 @@ class TestRVRInternals(cloudstackTestCase): ) # Check eth2 port for backup router - if self.apiclient.hypervisor.lower() == 'vmware': + if self.hypervisor.lower() == 'vmware': result = get_process_status( self.apiclient.connection.mgtSvr, 22, @@ -890,7 +887,7 @@ class TestRVRInternals(cloudstackTestCase): self.apiclient.connction.passwd, backup_router.linklocalip, 'ip addr show eth2', - hypervisor=self.apiclient.hypervisor + hypervisor=self.hypervisor ) else: result = get_process_status( @@ -945,14 +942,13 @@ class TestRvRRedundancy(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestRvRRedundancy, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestRvRRedundancy, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, diff --git a/test/integration/component/maint/test_redundant_router_deployment_planning.py b/test/integration/component/maint/test_redundant_router_deployment_planning.py index 879a4da7740..b63cda94e58 100644 --- a/test/integration/component/maint/test_redundant_router_deployment_planning.py +++ b/test/integration/component/maint/test_redundant_router_deployment_planning.py @@ -16,9 +16,9 @@ # under the License. from nose.plugins.attrib import attr -from marvin.integration.lib.base import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.common import * +from marvin.lib.base import * +from marvin.lib.utils import * +from marvin.lib.common import * #Import Local Modules from marvin.cloudstackTestCase import cloudstackTestCase @@ -136,14 +136,13 @@ class TestRvRDeploymentPlanning(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestRvRDeploymentPlanning, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestRvRDeploymentPlanning, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, diff --git a/test/integration/component/maint/test_redundant_router_network_rules.py b/test/integration/component/maint/test_redundant_router_network_rules.py index 010aaaa7b70..12c4d2c1168 100644 --- a/test/integration/component/maint/test_redundant_router_network_rules.py +++ b/test/integration/component/maint/test_redundant_router_network_rules.py @@ -16,9 +16,9 @@ # under the License. from nose.plugins.attrib import attr -from marvin.integration.lib.base import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.common import * +from marvin.lib.base import * +from marvin.lib.utils import * +from marvin.lib.common import * #Import Local Modules from marvin.cloudstackTestCase import cloudstackTestCase @@ -137,14 +137,13 @@ class TestRedundantRouterRulesLifeCycle(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestRedundantRouterRulesLifeCycle, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestRedundantRouterRulesLifeCycle, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, diff --git a/test/integration/component/maint/test_vpc_host_maintenance.py b/test/integration/component/maint/test_vpc_host_maintenance.py index 57dfb4be8d0..83ba2717d99 100644 --- a/test/integration/component/maint/test_vpc_host_maintenance.py +++ b/test/integration/component/maint/test_vpc_host_maintenance.py @@ -22,11 +22,9 @@ import marvin from nose.plugins.attrib import attr from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * -from marvin.sshClient import SshClient -import datetime +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * class Services: @@ -190,14 +188,13 @@ class TestVMLifeCycleHostmaintenance(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestVMLifeCycleHostmaintenance, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestVMLifeCycleHostmaintenance, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, @@ -554,4 +551,4 @@ class TestVMLifeCycleHostmaintenance(cloudstackTestCase): "Router state should be running" ) # TODO: Check for the network connectivity - return \ No newline at end of file + return diff --git a/test/integration/component/maint/test_vpc_on_host_maintenance.py b/test/integration/component/maint/test_vpc_on_host_maintenance.py index 6630ee61e0a..eb3360a458f 100644 --- a/test/integration/component/maint/test_vpc_on_host_maintenance.py +++ b/test/integration/component/maint/test_vpc_on_host_maintenance.py @@ -18,9 +18,9 @@ from nose.plugins.attrib import attr from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * class Services: @@ -77,14 +77,13 @@ class TestVPCHostMaintenance(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestVPCHostMaintenance, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestVPCHostMaintenance, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, diff --git a/test/integration/component/test_VirtualRouter_alerts.py b/test/integration/component/test_VirtualRouter_alerts.py index 4b53e3fd2cd..e6f0a823fd9 100644 --- a/test/integration/component/test_VirtualRouter_alerts.py +++ b/test/integration/component/test_VirtualRouter_alerts.py @@ -20,10 +20,11 @@ import marvin from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +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 FAILED import time @@ -96,12 +97,13 @@ class Services: class TestVRServiceFailureAlerting(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestVRServiceFailureAlerting, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestVRServiceFailureAlerting, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() cls.services = Services().services # Get Zone, Domain and templates - domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) + domain = get_domain(cls.api_client) cls.services['mode'] = cls.zone.networktype template = get_template( @@ -109,6 +111,9 @@ class TestVRServiceFailureAlerting(cloudstackTestCase): cls.zone.id, cls.services["ostype"] ) + + if template == FAILED: + assert False, "get_template() failed to return template with description %s" % cls.services["ostype"] # Set Zones and disk offerings ?? cls.services["small"]["zoneid"] = cls.zone.id cls.services["small"]["template"] = template.id @@ -148,6 +153,7 @@ class TestVRServiceFailureAlerting(cloudstackTestCase): def setUp(self): self.apiclient = self.testClient.getApiClient() self.dbclient = self.testClient.getDbConnection() + self.hypervisor = self.testClient.getHypervisorInfo() self.cleanup = [] def tearDown(self): @@ -202,7 +208,7 @@ class TestVRServiceFailureAlerting(cloudstackTestCase): alertSubject = "Monitoring Service on VR " + router.name - if self.apiclient.hypervisor.lower() == 'vmware': + if self.hypervisor.lower() == 'vmware': result = get_process_status( self.apiclient.connection.mgtSvr, 22, @@ -210,7 +216,7 @@ class TestVRServiceFailureAlerting(cloudstackTestCase): self.apiclient.connection.passwd, router.linklocalip, "service dnsmasq status", - hypervisor=self.apiclient.hypervisor + hypervisor=self.hypervisor ) else: try: diff --git a/test/integration/component/test_accounts.py b/test/integration/component/test_accounts.py index bee17fbc7b4..cf5f2b6e476 100644 --- a/test/integration/component/test_accounts.py +++ b/test/integration/component/test_accounts.py @@ -17,14 +17,32 @@ """ P1 tests for Account """ #Import Local Modules -from marvin.cloudstackTestCase import * -from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * -from marvin.sshClient import SshClient +from marvin.cloudstackTestCase import cloudstackTestCase +#from marvin.cloudstackAPI import * +from marvin.lib.utils import (random_gen, + cleanup_resources) +from marvin.lib.base import (Domain, + Account, + ServiceOffering, + VirtualMachine, + Network, + User, + NATRule, + Template, + PublicIPAddress) +from marvin.lib.common import (get_domain, + get_zone, + get_template, + list_accounts, + list_virtual_machines, + list_service_offering, + list_templates, + list_users, + get_builtin_template_info, + wait_for_cleanup) from nose.plugins.attrib import attr -from marvin.cloudstackException import cloudstackAPIException +from marvin.cloudstackException import CloudstackAPIException +import time class Services: """Test Account Services @@ -102,13 +120,11 @@ class TestAccounts(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestAccounts, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestAccounts, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services - # Get Zone, Domain and templates - cls.zone = get_zone(cls.api_client, cls.services) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype cls.template = get_template( cls.api_client, @@ -232,13 +248,11 @@ class TestRemoveUserFromAccount(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestRemoveUserFromAccount, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestRemoveUserFromAccount, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services - # Get Zone, Domain and templates - cls.zone = get_zone(cls.api_client, cls.services) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype cls.template = get_template( cls.api_client, @@ -392,13 +406,11 @@ class TestNonRootAdminsPrivileges(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestNonRootAdminsPrivileges, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestNonRootAdminsPrivileges, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services - # Get Zone settings - cls.zone = get_zone(cls.api_client, cls.services) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype # Create an account, domain etc cls.domain = Domain.create( @@ -726,12 +738,12 @@ class TestTemplateHierarchy(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestTemplateHierarchy, - cls).getClsTestClient().getApiClient() + cls.testClient = super(TestTemplateHierarchy, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.hypervisor = cls.testClient.getHypervisorInfo() + cls.services = Services().services - # Get Zone settings - cls.zone = get_zone(cls.api_client, cls.services) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype # Create domains, accounts and template @@ -772,7 +784,8 @@ class TestTemplateHierarchy(cloudstackTestCase): cls.services["template"], zoneid=cls.zone.id, account=cls.account_1.name, - domainid=cls.domain_1.id + domainid=cls.domain_1.id, + hypervisor=cls.hypervisor ) # Wait for template to download @@ -879,21 +892,12 @@ class TestAddVmToSubDomain(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestAddVmToSubDomain, - cls - ).getClsTestClient().getApiClient() - cls.services = Services().services + cls.testClient = super(TestAddVmToSubDomain, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() - # Setup working Environment- Create domain, zone, pod cluster etc. - cls.domain = get_domain( - cls.api_client, - cls.services - ) - cls.zone = get_zone( - cls.api_client, - cls.services, - ) + cls.services = Services().services + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype cls.sub_domain = Domain.create( cls.api_client, @@ -1031,14 +1035,12 @@ class TestUserDetails(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestUserDetails, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestUserDetails, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services - # Get Zone, Domain etc - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype cls._cleanup = [] return @@ -1331,14 +1333,12 @@ class TestUserLogin(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestUserLogin, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestUserLogin, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services - # Get Zone, Domain etc - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype cls._cleanup = [] return @@ -1482,21 +1482,12 @@ class TestDomainForceRemove(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestDomainForceRemove, - cls - ).getClsTestClient().getApiClient() - cls.services = Services().services + cls.testClient = super(TestDomainForceRemove, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() - # Setup working Environment- Create domain, zone, pod cluster etc. - cls.domain = get_domain( - cls.api_client, - cls.services - ) - cls.zone = get_zone( - cls.api_client, - cls.services, - ) + cls.services = Services().services + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype cls.template = get_template( @@ -1681,7 +1672,7 @@ 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) - with self.assertRaises(cloudstackAPIException): + with self.assertRaises(CloudstackAPIException): Domain.list( self.apiclient, id=domain.id, @@ -1689,7 +1680,7 @@ class TestDomainForceRemove(cloudstackTestCase): ) self.debug("Checking if the resources in domain are deleted") - with self.assertRaises(cloudstackAPIException): + with self.assertRaises(CloudstackAPIException): Account.list( self.apiclient, name=self.account_1.name, diff --git a/test/integration/component/test_add_remove_network.py b/test/integration/component/test_add_remove_network.py index b2b3594d9c4..2aadb5bfac3 100644 --- a/test/integration/component/test_add_remove_network.py +++ b/test/integration/component/test_add_remove_network.py @@ -29,7 +29,7 @@ from nose.plugins.attrib import attr from marvin.cloudstackTestCase import cloudstackTestCase, unittest from ddt import ddt, data -from marvin.integration.lib.base import ( +from marvin.lib.base import ( Account, Domain, ServiceOffering, @@ -39,7 +39,7 @@ from marvin.integration.lib.base import ( VpcOffering, VPC ) -from marvin.integration.lib.common import (get_domain, +from marvin.lib.common import (get_domain, get_zone, get_template, list_virtual_machines, @@ -49,7 +49,7 @@ from marvin.integration.lib.common import (get_domain, update_resource_limit ) -from marvin.integration.lib.utils import (validateList, +from marvin.lib.utils import (validateList, random_gen, get_hypervisor_type, cleanup_resources) @@ -60,6 +60,7 @@ from marvin.cloudstackAPI import (addNicToVirtualMachine, from marvin.codes import PASS import random +import time class Services: """Test Add Remove Network Services @@ -67,7 +68,7 @@ class Services: def __init__(self): self.services = { - + "sleep": 60, "ostype": "CentOS 5.3 (64-bit)", # Cent OS 5.3 (64 bit) @@ -173,7 +174,10 @@ class TestAddNetworkToVirtualMachine(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestAddNetworkToVirtualMachine, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestAddNetworkToVirtualMachine, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + + cls.services = Services().services hypervisor = get_hypervisor_type(cls.api_client) if hypervisor.lower() not in ["xenserver","kvm"]: @@ -181,8 +185,8 @@ class TestAddNetworkToVirtualMachine(cloudstackTestCase): cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) template = get_template(cls.api_client, cls.zone.id, cls.services["ostype"]) # Set Zones and disk offerings @@ -394,8 +398,7 @@ class TestAddNetworkToVirtualMachine(cloudstackTestCase): # Trying to add same network to vm for the second time with self.assertRaises(Exception) as e: self.addNetworkToVm(network, self.virtual_machine) - - self.debug("Adding same network again failed with exception: %s" % e.exception) + self.debug("Adding same network again failed with exception: %s" % e.exception) return @@ -517,7 +520,7 @@ class TestAddNetworkToVirtualMachine(cloudstackTestCase): with self.assertRaises(Exception) as e: self.addNetworkToVm(self.shared_network, self.virtual_machine, ipaddress = ipaddress) - self.debug("API failed with exception: %s" % e.exception) + self.debug("API failed with exception: %s" % e.exception) return @@ -554,9 +557,7 @@ class TestAddNetworkToVirtualMachine(cloudstackTestCase): with self.assertRaises(Exception) as e: self.virtual_machine.add_nic(self.apiclient, network.id) - network.delete(self.apiclient) - - self.debug("Operation failed with exception %s" % e.exception) + self.debug("Operation failed with exception %s" % e.exception) return @@ -608,15 +609,13 @@ class TestAddNetworkToVirtualMachine(cloudstackTestCase): domainid=self.child_do_admin_2.domainid, serviceofferingid=self.service_offering.id, mode=self.zone.networktype) + time.sleep(self.services["sleep"]) self.debug("Trying to %s network in domain %s to a vm in domain %s, This should fail" % (network.type, self.child_domain_1.name, self.child_domain_2.name)) with self.assertRaises(Exception) as e: virtual_machine.add_nic(self.apiclient, network.id) - self.debug("Operation failed with exception %s" % e.exception) - - network.delete(self.apiclient) - + self.debug("Operation failed with exception %s" % e.exception) return @attr(tags = ["advanced"]) @@ -688,7 +687,7 @@ class TestAddNetworkToVirtualMachine(cloudstackTestCase): with self.assertRaises(Exception) as e: virtual_machine.add_nic(self.apiclient, network_2.id) - self.debug("Operation failed with exception %s" % e.exception) + self.debug("Operation failed with exception %s" % e.exception) return @@ -696,16 +695,18 @@ class TestRemoveNetworkFromVirtualMachine(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestRemoveNetworkFromVirtualMachine, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestRemoveNetworkFromVirtualMachine, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + + cls.services = Services().services hypervisor = get_hypervisor_type(cls.api_client) if hypervisor.lower() not in ["xenserver","kvm"]: raise unittest.SkipTest("This feature is supported only on XenServer and KVM") - cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) template = get_template(cls.api_client,cls.zone.id,cls.services["ostype"]) # Set Zones and disk offerings @@ -838,7 +839,7 @@ class TestRemoveNetworkFromVirtualMachine(cloudstackTestCase): self.virtual_machine.id) 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") + self.debug("Removing default nic of vm failed") return @attr(tags = ["advanced"]) @@ -869,23 +870,25 @@ class TestRemoveNetworkFromVirtualMachine(cloudstackTestCase): operation should fail") with self.assertRaises(Exception) as e: self.virtual_machine.remove_nic(self.apiclient, virtual_machine.nic[0].id) - self.debug("Operation failed with exception: %s" % e.exception) + self.debug("Operation failed with exception: %s" % e.exception) return class TestUpdateVirtualMachineNIC(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestUpdateVirtualMachineNIC, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestUpdateVirtualMachineNIC, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + + cls.services = Services().services hypervisor = get_hypervisor_type(cls.api_client) if hypervisor.lower() not in ["xenserver","kvm"]: raise unittest.SkipTest("This feature is supported only on XenServer and KVM") - cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) template = get_template(cls.api_client,cls.zone.id,cls.services["ostype"]) # Set Zones and disk offerings @@ -1047,7 +1050,7 @@ class TestUpdateVirtualMachineNIC(cloudstackTestCase): self.debug("Trying to set default nic again as default nic, This should fail") with self.assertRaises(Exception) as e: self.virtual_machine.update_default_nic(self.apiclient, nicId = defaultNicId) - self.debug("updateDefaultNic operation failed as expected with exception: %s" % + self.debug("updateDefaultNic operation failed as expected with exception: %s" % e.exception) return @@ -1072,15 +1075,16 @@ class TestUpdateVirtualMachineNIC(cloudstackTestCase): virtual_machine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"], accountid=account.name,domainid=account.domainid, serviceofferingid=self.service_offering.id,mode=self.zone.networktype) + time.sleep(self.services["sleep"]) self.debug("Deployed virtual machine: %s" % virtual_machine.id) - + foreignNicId = virtual_machine.nic[0].id self.debug("Trying to set nic of new virtual machine as default nic of existing virtual machine, This \ operation should fail") with self.assertRaises(Exception) as e: self.virtual_machine.update_default_nic(self.apiclient, nicId = foreignNicId) - self.debug("updateDefaultNic operation failed as expected with exception: %s" % + self.debug("updateDefaultNic operation failed as expected with exception: %s" % e.exception) return @@ -1089,16 +1093,18 @@ class TestFailureScenariosAddNetworkToVM(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestFailureScenariosAddNetworkToVM, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestFailureScenariosAddNetworkToVM, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + + cls.services = Services().services hypervisor = get_hypervisor_type(cls.api_client) if hypervisor.lower() not in ["xenserver","kvm"]: raise unittest.SkipTest("This feature is supported only on XenServer and KVM") - cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) template = get_template(cls.api_client,cls.zone.id,cls.services["ostype"]) # Set Zones and disk offerings cls.services["virtual_machine"]["zoneid"] = cls.zone.id @@ -1226,6 +1232,7 @@ class TestFailureScenariosAddNetworkToVM(cloudstackTestCase): cmd.networkid = isolated_network.id with self.assertRaises(Exception) as e: + time.sleep(5) self.apiclient.addNicToVirtualMachine(cmd) self.debug("addNicToVirtualMachine API failed with exception: %s" % e.exception) @@ -1267,6 +1274,7 @@ class TestFailureScenariosAddNetworkToVM(cloudstackTestCase): virtual_machine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"], serviceofferingid=self.service_offering.id, mode=basicZone.networktype) + time.sleep(self.services["sleep"]) self.debug("Deployed virtual machine %s: " % virtual_machine.id) cmd = addNicToVirtualMachine.addNicToVirtualMachineCmd() @@ -1276,6 +1284,7 @@ class TestFailureScenariosAddNetworkToVM(cloudstackTestCase): self.dedbug("Trying to add isolated network to VM (both in basic zone,\ this operation should fail") with self.assertRaises(Exception) as e: + time.sleep(5) self.apiclient.addNicToVirtualMachine(cmd) self.debug("addNicToVirtualMachine API failed with exception: %s" % e.exception) @@ -1302,12 +1311,13 @@ class TestFailureScenariosAddNetworkToVM(cloudstackTestCase): self.debug("Created account %s" % account.name) self.debug("creating user api client for account: %s" % account.name) - api_client = self.testClient.createUserApiClient(UserName=account.name, DomainName=self.account.domain) + api_client = self.testClient.getUserApiClient(UserName=account.name, DomainName=self.account.domain) self.debug("Trying to add network to vm with this api client, this should fail due to \ insufficient permission") with self.assertRaises(Exception) as e: + time.sleep(5) api_client.addNicToVirtualMachine(cmd) self.debug("addNicToVirtualMachine API failed with exception: %s" % e.exception) @@ -1317,16 +1327,18 @@ class TestFailureScenariosRemoveNicFromVM(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestFailureScenariosRemoveNicFromVM, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestFailureScenariosRemoveNicFromVM, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + + cls.services = Services().services hypervisor = get_hypervisor_type(cls.api_client) if hypervisor.lower() not in ["xenserver","kvm"]: raise unittest.SkipTest("This feature is supported only on XenServer and KVM") - cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) template = get_template(cls.api_client,cls.zone.id,cls.services["ostype"]) # Set Zones and disk offerings @@ -1374,7 +1386,7 @@ class TestFailureScenariosRemoveNicFromVM(cloudstackTestCase): def tearDownClass(cls): try: # Disable Network Offerings - #cls.isolated_network_offering.update(cls.api_client, state='Disabled') + cls.isolated_network_offering.update(cls.api_client, state='Disabled') # Cleanup resources used cleanup_resources(cls.api_client, cls._cleanup) @@ -1480,7 +1492,7 @@ class TestFailureScenariosRemoveNicFromVM(cloudstackTestCase): self.debug("Created account %s" % account.name) self.debug("creating user api client for account: %s" % account.name) - api_client = self.testClient.createUserApiClient(UserName=account.name, DomainName=self.account.domain) + api_client = self.testClient.getUserApiClient(UserName=account.name, DomainName=self.account.domain) self.debug("Trying to add network to vm with this api client, this should fail due to \ insufficient permission") @@ -1495,16 +1507,18 @@ class TestFailureScenariosUpdateVirtualMachineNIC(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestFailureScenariosUpdateVirtualMachineNIC, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestFailureScenariosUpdateVirtualMachineNIC, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + + cls.services = Services().services hypervisor = get_hypervisor_type(cls.api_client) if hypervisor.lower() not in ["xenserver","kvm"]: raise unittest.SkipTest("This feature is supported only on XenServer and KVM") - cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) template = get_template(cls.api_client, cls.zone.id, cls.services["ostype"]) # Set Zones and disk offerings @@ -1603,7 +1617,7 @@ class TestFailureScenariosUpdateVirtualMachineNIC(cloudstackTestCase): with self.assertRaises(Exception) as e: self.apiclient.updateDefaultNicForVirtualMachine(cmd) - self.debug("updateDefaultNicForVirtualMachine API failed with exception: %s" % + self.debug("updateDefaultNicForVirtualMachine API failed with exception: %s" % e.exception) return @@ -1649,7 +1663,7 @@ class TestFailureScenariosUpdateVirtualMachineNIC(cloudstackTestCase): with self.assertRaises(Exception) as e: self.apiclient.updateDefaultNicForVirtualMachine(cmd) - self.debug("updateDefaultNicForVirtualMachine API failed with exception: %s" % + self.debug("updateDefaultNicForVirtualMachine API failed with exception: %s" % e.exception) return @@ -1678,7 +1692,7 @@ class TestFailureScenariosUpdateVirtualMachineNIC(cloudstackTestCase): accountid=account.name,domainid=account.domainid, serviceofferingid=self.service_offering.id, mode=self.zone.networktype) - + time.sleep(self.services["sleep"]) self.debug("Created virtual machine %s" % virtual_machine.id) self.debug("Creating isolated network in account %s" % account.name) @@ -1731,7 +1745,7 @@ class TestFailureScenariosUpdateVirtualMachineNIC(cloudstackTestCase): with self.assertRaises(Exception) as e: self.apiclient.updateDefaultNicForVirtualMachine(cmd) - self.debug("updateDefaultNicForVirtualMachine API failed with exception: %s" % + self.debug("updateDefaultNicForVirtualMachine API failed with exception: %s" % e.exception) return @@ -1751,7 +1765,7 @@ class TestFailureScenariosUpdateVirtualMachineNIC(cloudstackTestCase): self.debug("Created account %s" % account.name) self.debug("creating user api client for account: %s" % account.name) - api_client = self.testClient.createUserApiClient(UserName=account.name, DomainName=self.account.domain) + api_client = self.testClient.getUserApiClient(UserName=account.name, DomainName=self.account.domain) self.debug("Listing virtual machine so that to retrive the list of non-default and default nic") vm_list = list_virtual_machines(self.apiclient, id=self.virtual_machine.id) @@ -1781,7 +1795,7 @@ class TestFailureScenariosUpdateVirtualMachineNIC(cloudstackTestCase): with self.assertRaises(Exception) as e: api_client.updateDefaultNicForVirtualMachine(cmd) - self.debug("updateDefaultNicForVirtualMachine API failed with exception: %s" % + self.debug("updateDefaultNicForVirtualMachine API failed with exception: %s" % e.exception) return diff --git a/test/integration/component/test_advancedsg_networks.py b/test/integration/component/test_advancedsg_networks.py index 207659f1efd..f9155ed13ca 100644 --- a/test/integration/component/test_advancedsg_networks.py +++ b/test/integration/component/test_advancedsg_networks.py @@ -19,7 +19,7 @@ """ from marvin.cloudstackTestCase import cloudstackTestCase, unittest from ddt import ddt, data -from marvin.integration.lib.base import (Zone, +from marvin.lib.base import (Zone, ServiceOffering, Account, NetworkOffering, @@ -31,14 +31,14 @@ from marvin.integration.lib.base import (Zone, SecurityGroup, Host) -from marvin.integration.lib.common import (get_domain, +from marvin.lib.common import (get_domain, get_zone, get_template, get_free_vlan, list_virtual_machines, wait_for_cleanup) -from marvin.integration.lib.utils import (cleanup_resources, +from marvin.lib.utils import (cleanup_resources, random_gen, validateList) from marvin.cloudstackAPI import (authorizeSecurityGroupIngress, @@ -54,14 +54,12 @@ class TestCreateZoneSG(cloudstackTestCase): @classmethod def setUpClass(cls): - cloudstackTestClient = super(TestCreateZoneSG,cls).getClsTestClient() - cls.api_client = cloudstackTestClient.getApiClient() - - # Fill services from the external config file - cls.services = cloudstackTestClient.getConfigParser().parsedDict + cls.testClient = super(TestCreateZoneSG, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = cls.testClient.getParsedTestDataConfig() # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) cls._cleanup = [] return @@ -154,14 +152,13 @@ class TestNetworksInAdvancedSG(cloudstackTestCase): @classmethod def setUpClass(cls): - cloudstackTestClient = super(TestNetworksInAdvancedSG,cls).getClsTestClient() - cls.api_client = cloudstackTestClient.getApiClient() - - cls.services = cloudstackTestClient.getConfigParser().parsedDict + cls.testClient = super(TestNetworksInAdvancedSG, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = cls.testClient.getParsedTestDataConfig() # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template(cls.api_client, cls.zone.id, cls.services["ostype"]) @@ -1102,14 +1099,13 @@ class TestNetworksInAdvancedSG_VmOperations(cloudstackTestCase): @classmethod def setUpClass(cls): - cloudstackTestClient = super(TestNetworksInAdvancedSG_VmOperations,cls).getClsTestClient() - cls.api_client = cloudstackTestClient.getApiClient() - - cls.services = cloudstackTestClient.getConfigParser().parsedDict + cls.testClient = super(TestNetworksInAdvancedSG_VmOperations, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = cls.testClient.getParsedTestDataConfig() # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template(cls.api_client,cls.zone.id,cls.services["ostype"]) cls.services["virtual_machine"]["zoneid"] = cls.zone.id @@ -2086,14 +2082,13 @@ class TestSecurityGroups_BasicSanity(cloudstackTestCase): @classmethod def setUpClass(cls): - cloudstackTestClient = super(TestSecurityGroups_BasicSanity,cls).getClsTestClient() - cls.api_client = cloudstackTestClient.getApiClient() - - cls.services = cloudstackTestClient.getConfigParser().parsedDict + cls.testClient = super(TestSecurityGroups_BasicSanity, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = cls.testClient.getParsedTestDataConfig() # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template(cls.api_client,cls.zone.id,cls.services["ostype"]) cls.services["virtual_machine"]["zoneid"] = cls.zone.id @@ -2548,14 +2543,13 @@ class TestSharedNetworkOperations(cloudstackTestCase): @classmethod def setUpClass(cls): - cloudstackTestClient = super(TestSharedNetworkOperations,cls).getClsTestClient() - cls.api_client = cloudstackTestClient.getApiClient() - - cls.services = cloudstackTestClient.getConfigParser().parsedDict + cls.testClient = super(TestSharedNetworkOperations, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = cls.testClient.getParsedTestDataConfig() # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template(cls.api_client,cls.zone.id,cls.services["ostype"]) cls.services["virtual_machine"]["zoneid"] = cls.zone.id @@ -2815,14 +2809,13 @@ class TestAccountBasedIngressRules(cloudstackTestCase): @classmethod def setUpClass(cls): - cloudstackTestClient = super(TestAccountBasedIngressRules,cls).getClsTestClient() - cls.api_client = cloudstackTestClient.getApiClient() - - cls.services = cloudstackTestClient.getConfigParser().parsedDict + cls.testClient = super(TestAccountBasedIngressRules, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = cls.testClient.getParsedTestDataConfig() # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template(cls.api_client,cls.zone.id,cls.services["ostype"]) cls.services["virtual_machine"]["zoneid"] = cls.zone.id diff --git a/test/integration/component/test_affinity_groups.py b/test/integration/component/test_affinity_groups.py index 68902f5fbf9..eb5877763c4 100644 --- a/test/integration/component/test_affinity_groups.py +++ b/test/integration/component/test_affinity_groups.py @@ -15,12 +15,20 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. -from marvin.cloudstackTestCase import * -from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * -from marvin.sshClient import SshClient +from marvin.cloudstackTestCase import cloudstackTestCase, unittest +from marvin.cloudstackAPI import deleteAffinityGroup +from marvin.lib.utils import (cleanup_resources, + random_gen) +from marvin.lib.base import (Account, + ServiceOffering, + VirtualMachine, + AffinityGroup, + Domain) +from marvin.lib.common import (get_zone, + get_domain, + get_template, + list_virtual_machines, + wait_for_cleanup) from nose.plugins.attrib import attr class Services: @@ -89,12 +97,12 @@ class TestCreateAffinityGroup(cloudstackTestCase): @classmethod def setUpClass(cls): - - cls.api_client = super(TestCreateAffinityGroup, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestCreateAffinityGroup, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, @@ -197,7 +205,7 @@ class TestCreateAffinityGroup(cloudstackTestCase): self.cleanup.append(self.do_admin) self.cleanup.append(self.new_domain) - domainapiclient = self.testClient.createUserApiClient(self.do_admin.name, self.new_domain.name, 2) + domainapiclient = self.testClient.getUserApiClient(self.do_admin.name, self.new_domain.name, 2) aff_grp = self.create_aff_grp(api_client=domainapiclient, aff_grp=self.services["host_anti_affinity"], acc=self.do_admin.name, domainid=self.new_domain.id) @@ -214,7 +222,7 @@ class TestCreateAffinityGroup(cloudstackTestCase): self.user = Account.create(self.api_client, self.services["new_account"], domainid=self.domain.id) - userapiclient = self.testClient.createUserApiClient(self.user.name, self.domain.name) + userapiclient = self.testClient.getUserApiClient(self.user.name, self.domain.name) self.cleanup.append(self.user) aff_grp = self.create_aff_grp(api_client=userapiclient, aff_grp=self.services["host_anti_affinity"], @@ -283,12 +291,14 @@ class TestListAffinityGroups(cloudstackTestCase): @classmethod def setUpClass(cls): + cls.testClient = super(TestListAffinityGroups, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() - cls.api_client = super(TestListAffinityGroups, cls).getClsTestClient().getApiClient() cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) + cls.template = get_template( cls.api_client, cls.zone.id, @@ -530,11 +540,14 @@ class TestDeleteAffinityGroups(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestDeleteAffinityGroups, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestDeleteAffinityGroups, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) + cls.template = get_template( cls.api_client, cls.zone.id, @@ -704,10 +717,10 @@ class TestDeleteAffinityGroups(cloudstackTestCase): self.user2 = Account.create(self.apiclient, self.services["new_account1"]) self.cleanup.append(self.user2) - userapiclient = self.testClient.createUserApiClient( + userapiclient = self.testClient.getUserApiClient( UserName=self.user2.name, DomainName=self.user2.domain, - acctType=0) + type=0) aff_1 = self.create_aff_grp(api_client=userapiclient, aff_grp=self.services["host_anti_affinity"]) @@ -740,10 +753,10 @@ class TestDeleteAffinityGroups(cloudstackTestCase): self.user2 = Account.create(self.apiclient, self.services["new_account1"]) self.cleanup.append(self.user2) - userapiclient = self.testClient.createUserApiClient( + userapiclient = self.testClient.getUserApiClient( UserName=self.user2.name, DomainName=self.user2.domain, - acctType=0) + type=0) aff_1 = self.create_aff_grp(api_client=userapiclient, aff_grp=self.services["host_anti_affinity"]) @@ -781,10 +794,10 @@ class TestDeleteAffinityGroups(cloudstackTestCase): self.services["new_account"]) self.cleanup.append(self.user1) - user1apiclient = self.testClient.createUserApiClient( + user1apiclient = self.testClient.getUserApiClient( UserName=self.user1.name, DomainName=self.user1.domain, - acctType=0) + type=0) aff_grp = self.create_aff_grp(api_client=user1apiclient, aff_grp=self.services["host_anti_affinity"]) @@ -800,11 +813,14 @@ class TestUpdateVMAffinityGroups(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestUpdateVMAffinityGroups, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestUpdateVMAffinityGroups, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) + cls.template = get_template( cls.api_client, cls.zone.id, @@ -1084,11 +1100,14 @@ class TestDeployVMAffinityGroups(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestDeployVMAffinityGroups, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestDeployVMAffinityGroups, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) + cls.template = get_template( cls.api_client, cls.zone.id, @@ -1294,10 +1313,10 @@ class TestDeployVMAffinityGroups(cloudstackTestCase): self.user2 = Account.create(self.apiclient, self.services["new_account1"]) self.cleanup.append(self.user2) - userapiclient = self.testClient.createUserApiClient( + userapiclient = self.testClient.getUserApiClient( UserName=self.user2.name, DomainName=self.user2.domain, - acctType=0) + type=0) self.create_aff_grp(api_client=userapiclient, aff_grp=self.services["host_anti_affinity"]) @@ -1327,10 +1346,10 @@ class TestDeployVMAffinityGroups(cloudstackTestCase): self.user2 = Account.create(self.apiclient, self.services["new_account1"]) self.cleanup.append(self.user2) - userapiclient = self.testClient.createUserApiClient( + userapiclient = self.testClient.getUserApiClient( UserName=self.user2.name, DomainName=self.user2.domain, - acctType=0) + type=0) self.create_aff_grp(api_client=userapiclient, aff_grp=self.services["host_anti_affinity"]) @@ -1432,11 +1451,13 @@ class TestAffinityGroupsAdminUser(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestAffinityGroupsAdminUser, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestAffinityGroupsAdminUser, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, @@ -1549,10 +1570,10 @@ class TestAffinityGroupsAdminUser(cloudstackTestCase): self.services["new_account"]) self.cleanup.append(self.user1) - userapiclient = self.testClient.createUserApiClient( + userapiclient = self.testClient.getUserApiClient( UserName=self.user1.name, DomainName=self.user1.domain, - acctType=0) + type=0) aff_grp = self.create_aff_grp(api_client=userapiclient, aff_grp=self.services["host_anti_affinity"]) @@ -1588,10 +1609,10 @@ class TestAffinityGroupsAdminUser(cloudstackTestCase): self.services["new_account"]) self.cleanup.append(self.user1) - userapiclient = self.testClient.createUserApiClient( + userapiclient = self.testClient.getUserApiClient( UserName=self.user1.name, DomainName=self.user1.domain, - acctType=0) + type=0) aff_grp = self.create_aff_grp(api_client=userapiclient, aff_grp=self.services["host_anti_affinity"]) @@ -1638,10 +1659,10 @@ class TestAffinityGroupsAdminUser(cloudstackTestCase): self.services["new_account"]) self.cleanup.append(self.user1) - userapiclient = self.testClient.createUserApiClient( + userapiclient = self.testClient.getUserApiClient( UserName=self.user1.name, DomainName=self.user1.domain, - acctType=0) + type=0) aff_grp1 = self.create_aff_grp(api_client=userapiclient, aff_grp=self.services["host_anti_affinity"]) @@ -1674,10 +1695,10 @@ class TestAffinityGroupsAdminUser(cloudstackTestCase): self.services["new_account"]) self.cleanup.append(self.user1) - userapiclient = self.testClient.createUserApiClient( + userapiclient = self.testClient.getUserApiClient( UserName=self.user1.name, DomainName=self.user1.domain, - acctType=0) + type=0) aff_grp = self.create_aff_grp(api_client=userapiclient, aff_grp=self.services["host_anti_affinity"]) @@ -1706,10 +1727,10 @@ class TestAffinityGroupsAdminUser(cloudstackTestCase): self.services["new_account"]) self.cleanup.append(self.user1) - userapiclient = self.testClient.createUserApiClient( + userapiclient = self.testClient.getUserApiClient( UserName=self.user1.name, DomainName=self.user1.domain, - acctType=0) + type=0) aff_grp = self.create_aff_grp(api_client=userapiclient, aff_grp=self.services["host_anti_affinity"]) diff --git a/test/integration/component/test_allocation_states.py b/test/integration/component/test_allocation_states.py index 1c0bce5dbd6..9ba246ffd80 100644 --- a/test/integration/component/test_allocation_states.py +++ b/test/integration/component/test_allocation_states.py @@ -15,17 +15,16 @@ # specific language governing permissions and limitations # under the License. -import marvin from nose.plugins.attrib import attr -from marvin.cloudstackTestCase import * -from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * -from nose.plugins.attrib import attr -import datetime - - +from marvin.cloudstackTestCase import cloudstackTestCase +from marvin.lib.utils import cleanup_resources +from marvin.lib.base import (Host, + Pod, + Zone, + Cluster, + StoragePool) +from marvin.lib.common import get_zone, get_template +from marvin.codes import FAILED class Services: """Test Resource Limits Services """ @@ -86,13 +85,23 @@ class TestAllocationState(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestAllocationState, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestAllocationState, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services + # Get Zone, Domain and templates - cls.zone = get_zone(cls.api_client, cls.services) + + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) + cls.template = get_template( + cls.api_client, + cls.zone.id, + cls.services["ostype"] + ) + if cls.template == FAILED: + assert False, "get_template() failed to return template with description %s" % cls.services["ostype"] + + cls.services['mode'] = cls.zone.networktype cls._cleanup = [] return diff --git a/test/integration/component/test_asa1000v_fw.py b/test/integration/component/test_asa1000v_fw.py index c8a11ab1701..43d06d18642 100644 --- a/test/integration/component/test_asa1000v_fw.py +++ b/test/integration/component/test_asa1000v_fw.py @@ -18,15 +18,15 @@ """ Cisco ASA1000v external firewall """ #Import Local Modules -import marvin from nose.plugins.attrib import attr -from marvin.cloudstackTestCase import * -from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * -from marvin.sshClient import SshClient -import datetime +from marvin.cloudstackTestCase import cloudstackTestCase +from marvin.lib.utils import cleanup_resources +from marvin.lib.base import (NetworkOffering, + PhysicalNetwork, + VNMC, + ASA1000V, + Cluster) +from marvin.lib.common import get_zone class Services: @@ -101,7 +101,7 @@ class TestASASetup(cloudstackTestCase): self.apiclient = self.testClient.getApiClient() self.dbclient = self.testClient.getDbConnection() - self.zone = get_zone(self.apiclient, self.services) + self.zone = get_zone(self.apiclient, self.testClient.getZoneForTests()) self.physicalnetworks = PhysicalNetwork.list(self.apiclient, zoneid=self.zone.id) self.assertNotEqual(len(self.physicalnetworks), 0, "Check if the list physical network API returns a non-empty response") self.clusters = Cluster.list(self.apiclient, hypervisor='VMware') diff --git a/test/integration/component/test_assign_vm.py b/test/integration/component/test_assign_vm.py index 400d5f2e724..24b63a62f14 100644 --- a/test/integration/component/test_assign_vm.py +++ b/test/integration/component/test_assign_vm.py @@ -20,7 +20,7 @@ #Import Local Modules from nose.plugins.attrib import attr from marvin.cloudstackTestCase import cloudstackTestCase -from marvin.integration.lib.base import (Account, +from marvin.lib.base import (Account, Domain, User, Project, @@ -29,7 +29,7 @@ from marvin.integration.lib.base import (Account, DiskOffering, ServiceOffering, VirtualMachine) -from marvin.integration.lib.common import (get_domain, +from marvin.lib.common import (get_domain, get_zone, get_template, list_volumes, @@ -37,7 +37,7 @@ from marvin.integration.lib.common import (get_domain, list_networks, list_snapshots, list_virtual_machines) -from marvin.integration.lib.utils import cleanup_resources +from marvin.lib.utils import cleanup_resources def log_test_exceptions(func): def test_wrap_exception_log(self, *args, **kwargs): @@ -98,12 +98,13 @@ class TestVMOwnership(cloudstackTestCase): @classmethod def setUpClass(cls): cls._cleanup = [] - cls.api_client = super(TestVMOwnership, - cls).getClsTestClient().getApiClient() - cls.services = Services().services - # Get Zone Domain and create Domains and sub Domains. - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.testClient = super(TestVMOwnership, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + + cls.services = Services().services + # Get Zone, Domain and templates + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype # Get and set template id for VM creation. cls.template = get_template(cls.api_client, @@ -353,8 +354,8 @@ class TestVMOwnership(cloudstackTestCase): # 1. deploy VM in sub subdomain1 # 2. stop VM in sub subdomain1 # 3. assignVirtualMachine to subdomain2 - userapiclient = self.testClient.getUserApiClient(account=self.sdomain_account_user1['account'].name, - domain=self.sdomain_account_user1['domain'].name, + userapiclient = self.testClient.getUserApiClient(UserName=self.sdomain_account_user1['account'].name, + DomainName=self.sdomain_account_user1['domain'].name, type=2) self.create_vm(self.sdomain_account_user1['account'], self.sdomain_account_user1['domain']) self.assertRaises(Exception, self.virtual_machine.assign_virtual_machine, userapiclient, self.sdomain_account_user2['account'].name ,self.sdomain_account_user2['domain'].id) @@ -389,8 +390,8 @@ class TestVMOwnership(cloudstackTestCase): # Validate the following: # 1. deploy VM in sub subdomain1 with volumes. # 3. assignVirtualMachine to subdomain2 - userapiclient = self.testClient.getUserApiClient(account=self.sdomain_account_user1['account'].name, - domain=self.sdomain_account_user1['domain'].name, + userapiclient = self.testClient.getUserApiClient(UserName=self.sdomain_account_user1['account'].name, + DomainName=self.sdomain_account_user1['domain'].name, type=2) self.create_vm(self.sdomain_account_user1['account'], self.sdomain_account_user1['domain'],volume=self.sdomain_account_user1['volume']) self.assertRaises(Exception, self.virtual_machine.assign_virtual_machine, userapiclient, self.sdomain_account_user2['account'].name ,self.sdomain_account_user2['domain'].id) @@ -431,8 +432,8 @@ class TestVMOwnership(cloudstackTestCase): # Validate the following: # 1. deploy VM in sub subdomain1 with snapshot. # 3. assignVirtualMachine to subdomain2 - userapiclient = self.testClient.getUserApiClient(account=self.sdomain_account_user1['account'].name, - domain=self.sdomain_account_user1['domain'].name, + userapiclient = self.testClient.getUserApiClient(UserName=self.sdomain_account_user1['account'].name, + DomainName=self.sdomain_account_user1['domain'].name, type=2) self.create_vm(self.sdomain_account_user1['account'], self.sdomain_account_user1['domain'], project=self.sdomain_account_user1['project']) self.assertRaises(Exception, self.virtual_machine.assign_virtual_machine, userapiclient, self.sdomain_account_user2['account'].name ,self.sdomain_account_user2['domain'].id) @@ -450,8 +451,8 @@ class TestVMOwnership(cloudstackTestCase): account=self.sdomain_account_user2['account'].name, domainid=self.sdomain_account_user2['domain'].id, max=0) - userapiclient = self.testClient.getUserApiClient(account=self.sdomain_account_user1['account'].name, - domain=self.sdomain_account_user1['domain'].name, + userapiclient = self.testClient.getUserApiClient(UserName=self.sdomain_account_user1['account'].name, + DomainName=self.sdomain_account_user1['domain'].name, type=2) self.create_vm(self.sdomain_account_user1['account'], self.sdomain_account_user1['domain'], snapshot=True) self.assertRaises(Exception, self.virtual_machine.assign_virtual_machine, userapiclient, self.sdomain_account_user2['account'].name ,self.sdomain_account_user2['domain'].id) @@ -470,8 +471,8 @@ class TestVMOwnership(cloudstackTestCase): account=self.sdomain_account_user2['account'].name, domainid=self.sdomain_account_user2['domain'].id, max=0) - userapiclient = self.testClient.getUserApiClient(account=self.sdomain_account_user1['account'].name, - domain=self.sdomain_account_user1['domain'].name, + userapiclient = self.testClient.getUserApiClient(UserName=self.sdomain_account_user1['account'].name, + DomainName=self.sdomain_account_user1['domain'].name, type=2) self.create_vm(self.sdomain_account_user1['account'], self.sdomain_account_user1['domain'], snapshot=True, volume=self.sdomain_account_user1['volume']) self.assertRaises(Exception, self.virtual_machine.assign_virtual_machine, userapiclient, self.sdomain_account_user2['account'].name ,self.sdomain_account_user2['domain'].id) diff --git a/test/integration/component/test_baremetal.py b/test/integration/component/test_baremetal.py index 2439d0d2132..6ab91466bd1 100644 --- a/test/integration/component/test_baremetal.py +++ b/test/integration/component/test_baremetal.py @@ -17,18 +17,18 @@ """ Test for baremetal """ #Import Local Modules -import marvin -from marvin.cloudstackTestCase import * -from marvin.cloudstackAPI import * -from marvin.sshClient import SshClient -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.cloudstackTestCase import cloudstackTestCase +from marvin.cloudstackAPI import createVlanIpRange +from marvin.lib.utils import cleanup_resources +from marvin.lib.base import (NetworkOffering, + NetworkServiceProvider, + PhysicalNetwork, + Network, + Pod) +#from marvin.lib.common import * from nose.plugins.attrib import attr -import telnetlib #Import System modules -import time _multiprocess_shared_ = True class Services: @@ -89,19 +89,19 @@ class TestBaremetal(cloudstackTestCase): physical_network = PhysicalNetwork.list(self.apiclient, zoneid=self.zoneid)[0]; dhcp_provider = NetworkServiceProvider.list(self.apiclient, name="BaremetalDhcpProvider", physical_network_id=physical_network.id)[0] - response = NetworkServiceProvider.update( + NetworkServiceProvider.update( self.apiclient, id=dhcp_provider.id, state='Enabled' ) pxe_provider = NetworkServiceProvider.list(self.apiclient, name="BaremetalPxeProvider", physical_network_id=physical_network.id)[0] - response = NetworkServiceProvider.update( + NetworkServiceProvider.update( self.apiclient, id=pxe_provider.id, state='Enabled' ) userdata_provider = NetworkServiceProvider.list(self.apiclient, name="BaremetalUserdataProvider", physical_network_id=physical_network.id)[0] - response = NetworkServiceProvider.update( + NetworkServiceProvider.update( self.apiclient, id=userdata_provider.id, state='Enabled' @@ -119,5 +119,5 @@ class TestBaremetal(cloudstackTestCase): cmd.startip = "10.1.1.20" cmd.endip = "10.1.1.40" cmd.forVirtualNetwork="false" - response = self.apiclient.createVlanIpRange(cmd) - \ No newline at end of file + self.apiclient.createVlanIpRange(cmd) + diff --git a/test/integration/component/test_base_image_updation.py b/test/integration/component/test_base_image_updation.py index 3c059969067..081d855fcac 100644 --- a/test/integration/component/test_base_image_updation.py +++ b/test/integration/component/test_base_image_updation.py @@ -31,7 +31,7 @@ from marvin.codes import (PASS, from nose.plugins.attrib import attr from marvin.cloudstackTestCase import cloudstackTestCase -from marvin.integration.lib.base import (ServiceOffering, +from marvin.lib.base import (ServiceOffering, Account, VirtualMachine, Volume, @@ -41,13 +41,13 @@ from marvin.integration.lib.base import (ServiceOffering, Template ) -from marvin.integration.lib.common import (get_domain, +from marvin.lib.common import (get_domain, get_zone, get_template, list_templates ) -from marvin.integration.lib.utils import (validateList, +from marvin.lib.utils import (validateList, cleanup_resources) import time @@ -161,14 +161,14 @@ class TestBaseImageUpdate(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestBaseImageUpdate, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestBaseImageUpdate, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) + cls.template = get_template( cls.api_client, cls.zone.id, @@ -238,6 +238,7 @@ class TestBaseImageUpdate(cloudstackTestCase): def setUp(self): self.apiclient = self.testClient.getApiClient() + self.hypervisor = self.testClient.getHypervisorInfo() self.dbclient = self.testClient.getDbConnection() self.cleanup = [] @@ -427,7 +428,8 @@ class TestBaseImageUpdate(cloudstackTestCase): v, zoneid=self.zone.id, account=self.account.name, - domainid=self.account.domainid + domainid=self.account.domainid, + hypervisor=self.hypervisor ) self.debug( "Registered a template of format: %s with ID: %s" % ( diff --git a/test/integration/component/test_blocker_bugs.py b/test/integration/component/test_blocker_bugs.py index 282803275db..5c9a08cc6b6 100644 --- a/test/integration/component/test_blocker_bugs.py +++ b/test/integration/component/test_blocker_bugs.py @@ -16,15 +16,29 @@ # under the License. """ Tests for Blocker bugs """ -import marvin from nose.plugins.attrib import attr -from marvin.integration.lib.base import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.common import * +from marvin.lib.base import (Snapshot, + Template, + Domain, + Account, + ServiceOffering, + Network, + VirtualMachine, + PublicIPAddress, + StaticNATRule, + FireWallRule, + Volume) +from marvin.lib.utils import cleanup_resources +from marvin.lib.common import (get_zone, + get_domain, + get_template, + list_routers, + get_builtin_template_info) #Import Local Modules -from marvin.cloudstackTestCase import * -from marvin.cloudstackAPI import * +from marvin.cloudstackTestCase import cloudstackTestCase +from marvin.cloudstackAPI import restartNetwork +import time class Services: @@ -95,8 +109,8 @@ class Services: class TestTemplate(cloudstackTestCase): def setUp(self): - self.apiclient = self.testClient.getApiClient() + self.hypervisor = self.testClient.getHypervisorInfo() self.dbclient = self.testClient.getDbConnection() self.cleanup = [] return @@ -110,12 +124,13 @@ class TestTemplate(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.services = Services().services - cls.api_client = super(TestTemplate, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestTemplate, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype cls.services["virtual_machine"]["zoneid"] = cls.zone.id cls.services["template"]["zoneid"] = cls.zone.id @@ -173,7 +188,8 @@ class TestTemplate(cloudstackTestCase): self.services["template"], zoneid=self.zone.id, account=self.account.name, - domainid=self.account.domainid + domainid=self.account.domainid, + hypervisor=self.hypervisor ) self.debug( "Registered a template of format: %s with ID: %s" % ( @@ -242,12 +258,14 @@ class TestNATRules(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestNATRules, cls).getClsTestClient().getApiClient() - cls.services = Services().services + cls.testClient = super(TestNATRules, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) + cls.services['mode'] = cls.zone.networktype template = get_template( cls.api_client, @@ -448,10 +466,12 @@ class TestRouters(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestRouters, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestRouters, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.zone = get_zone(cls.api_client, cls.services) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype cls.template = get_template( cls.api_client, @@ -573,11 +593,13 @@ class TestRouterRestart(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestRouterRestart, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestRouterRestart, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) + cls.domain = get_domain(cls.api_client) cls.services['mode'] = cls.zone.networktype template = get_template( cls.api_client, @@ -706,12 +728,14 @@ class TestTemplates(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.services = Services().services - cls.api_client = super(TestTemplates, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestTemplates, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + + cls.services = Services().services + # Get Zone, Domain and templates + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) + cls.domain = get_domain(cls.api_client) - # Get Zone, templates etc - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) cls.services['mode'] = cls.zone.networktype template = get_template( diff --git a/test/integration/component/test_cpu_domain_limits.py b/test/integration/component/test_cpu_domain_limits.py index c0bd9e739ea..6cca7c82c64 100644 --- a/test/integration/component/test_cpu_domain_limits.py +++ b/test/integration/component/test_cpu_domain_limits.py @@ -19,21 +19,21 @@ """ # Import Local Modules from nose.plugins.attrib import attr -from marvin.cloudstackTestCase import cloudstackTestCase, unittest -from marvin.integration.lib.base import ( +from marvin.cloudstackTestCase import cloudstackTestCase +from marvin.lib.base import ( Account, ServiceOffering, VirtualMachine, Resources, Domain ) -from marvin.integration.lib.common import (get_domain, +from marvin.lib.common import (get_domain, get_zone, get_template, findSuitableHostForMigration, get_resource_type ) -from marvin.integration.lib.utils import cleanup_resources +from marvin.lib.utils import cleanup_resources from marvin.codes import ERROR_NO_HOST_FOR_MIGRATION class Services: @@ -91,12 +91,13 @@ class TestDomainCPULimitsUpdateResources(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestDomainCPULimitsUpdateResources, - cls).getClsTestClient().getApiClient() + cls.testClient = super(TestDomainCPULimitsUpdateResources, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services["mode"] = cls.zone.networktype cls.template = get_template( cls.api_client, @@ -237,7 +238,7 @@ class TestDomainCPULimitsUpdateResources(cloudstackTestCase): self.account = admin self.domain = domain - api_client = self.testClient.createUserApiClient( + api_client = self.testClient.getUserApiClient( UserName=self.account.name, DomainName=self.account.domain) @@ -310,7 +311,7 @@ class TestDomainCPULimitsUpdateResources(cloudstackTestCase): self.account = admin self.domain = domain - api_client = self.testClient.createUserApiClient( + api_client = self.testClient.getUserApiClient( UserName=self.account.name, DomainName=self.account.domain) @@ -371,7 +372,7 @@ class TestDomainCPULimitsUpdateResources(cloudstackTestCase): self.account = admin self.domain = domain - api_client = self.testClient.createUserApiClient( + api_client = self.testClient.getUserApiClient( UserName=self.account.name, DomainName=self.account.domain) @@ -435,7 +436,7 @@ class TestDomainCPULimitsUpdateResources(cloudstackTestCase): self.account = admin self.domain = domain - api_client = self.testClient.createUserApiClient( + api_client = self.testClient.getUserApiClient( UserName=self.account.name, DomainName=self.account.domain) @@ -505,12 +506,13 @@ class TestMultipleChildDomains(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestMultipleChildDomains, - cls).getClsTestClient().getApiClient() + cls.testClient = super(TestMultipleChildDomains, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services["mode"] = cls.zone.networktype cls.template = get_template( cls.api_client, @@ -689,11 +691,11 @@ class TestMultipleChildDomains(cloudstackTestCase): self.debug("Setting up account and domain hierarchy") self.setupAccounts() - api_client_cadmin_1 = self.testClient.createUserApiClient( + api_client_cadmin_1 = self.testClient.getUserApiClient( UserName=self.cadmin_1.name, DomainName=self.cadmin_1.domain) - api_client_cadmin_2 = self.testClient.createUserApiClient( + api_client_cadmin_2 = self.testClient.getUserApiClient( UserName=self.cadmin_2.name, DomainName=self.cadmin_2.domain) diff --git a/test/integration/component/test_cpu_limits.py b/test/integration/component/test_cpu_limits.py index 9868bf28098..2cf92f8c2ad 100644 --- a/test/integration/component/test_cpu_limits.py +++ b/test/integration/component/test_cpu_limits.py @@ -19,21 +19,21 @@ """ # Import Local Modules from nose.plugins.attrib import attr -from marvin.cloudstackTestCase import cloudstackTestCase, unittest -from marvin.integration.lib.base import ( +from marvin.cloudstackTestCase import cloudstackTestCase +from marvin.lib.base import ( Account, ServiceOffering, VirtualMachine, Domain, Resources ) -from marvin.integration.lib.common import (get_domain, +from marvin.lib.common import (get_domain, get_zone, get_template, findSuitableHostForMigration, get_resource_type ) -from marvin.integration.lib.utils import cleanup_resources +from marvin.lib.utils import cleanup_resources from marvin.codes import ERROR_NO_HOST_FOR_MIGRATION @@ -92,12 +92,13 @@ class TestCPULimits(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestCPULimits, - cls).getClsTestClient().getApiClient() + cls.testClient = super(TestCPULimits, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services["mode"] = cls.zone.networktype cls.template = get_template( @@ -352,12 +353,14 @@ class TestDomainCPULimitsConfiguration(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestDomainCPULimitsConfiguration, - cls).getClsTestClient().getApiClient() + cls.testClient = super(TestDomainCPULimitsConfiguration, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) + cls.services["mode"] = cls.zone.networktype cls.template = get_template( cls.api_client, @@ -481,7 +484,7 @@ class TestDomainCPULimitsConfiguration(cloudstackTestCase): self.account = admin self.domain = domain - api_client = self.testClient.createUserApiClient( + api_client = self.testClient.getUserApiClient( UserName=self.account.name, DomainName=self.account.domain) @@ -553,7 +556,7 @@ class TestDomainCPULimitsConfiguration(cloudstackTestCase): self.account = admin self.domain = domain - api_client = self.testClient.createUserApiClient( + api_client = self.testClient.getUserApiClient( UserName=self.account.name, DomainName=self.account.domain) @@ -613,7 +616,7 @@ class TestDomainCPULimitsConfiguration(cloudstackTestCase): self.account = admin self.domain = domain - api_client = self.testClient.createUserApiClient( + api_client = self.testClient.getUserApiClient( UserName=self.account.name, DomainName=self.account.domain) @@ -685,7 +688,7 @@ class TestDomainCPULimitsConfiguration(cloudstackTestCase): if cpu_account_gc[0].max != 16: self.skipTest("This test case requires configuration value max.account.cpus to be 16") - api_client = self.testClient.createUserApiClient( + api_client = self.testClient.getUserApiClient( UserName=self.account.name, DomainName=self.account.domain) diff --git a/test/integration/component/test_cpu_max_limits.py b/test/integration/component/test_cpu_max_limits.py index c0d30483e57..a08ff6d4b48 100644 --- a/test/integration/component/test_cpu_max_limits.py +++ b/test/integration/component/test_cpu_max_limits.py @@ -19,8 +19,8 @@ """ # Import Local Modules from nose.plugins.attrib import attr -from marvin.cloudstackTestCase import cloudstackTestCase, unittest -from marvin.integration.lib.base import ( +from marvin.cloudstackTestCase import cloudstackTestCase +from marvin.lib.base import ( Account, ServiceOffering, VirtualMachine, @@ -28,11 +28,11 @@ from marvin.integration.lib.base import ( Domain, Project ) -from marvin.integration.lib.common import (get_domain, +from marvin.lib.common import (get_domain, get_zone, get_template ) -from marvin.integration.lib.utils import cleanup_resources +from marvin.lib.utils import cleanup_resources class Services: """Test resource limit services @@ -89,12 +89,13 @@ class TestMaxCPULimits(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestMaxCPULimits, - cls).getClsTestClient().getApiClient() + cls.testClient = super(TestMaxCPULimits, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services["mode"] = cls.zone.networktype cls.template = get_template( cls.api_client, @@ -251,7 +252,7 @@ class TestMaxCPULimits(cloudstackTestCase): self.debug("Setting up account and domain hierarchy") self.setupAccounts(account_limit=4, domain_limit=2) - api_client_admin = self.testClient.createUserApiClient( + api_client_admin = self.testClient.getUserApiClient( UserName=self.child_do_admin.name, DomainName=self.child_do_admin.domain) @@ -284,7 +285,7 @@ class TestMaxCPULimits(cloudstackTestCase): self.debug("Setting up account and domain hierarchy") self.setupAccounts(account_limit=6, domain_limit=8) - api_client_admin = self.testClient.createUserApiClient( + api_client_admin = self.testClient.getUserApiClient( UserName=self.child_do_admin.name, DomainName=self.child_do_admin.domain) @@ -325,7 +326,7 @@ class TestMaxCPULimits(cloudstackTestCase): self.debug("Setting up account and domain hierarchy") self.setupAccounts(account_limit=4, domain_limit=4, project_limit=2) - api_client_admin = self.testClient.createUserApiClient( + api_client_admin = self.testClient.getUserApiClient( UserName=self.child_do_admin.name, DomainName=self.child_do_admin.domain) @@ -360,7 +361,7 @@ class TestMaxCPULimits(cloudstackTestCase): self.debug("Setting up account and domain hierarchy") self.setupAccounts(account_limit=6, domain_limit=6, project_limit=6) - api_client_admin = self.testClient.createUserApiClient( + api_client_admin = self.testClient.getUserApiClient( UserName=self.child_do_admin.name, DomainName=self.child_do_admin.domain) diff --git a/test/integration/component/test_cpu_project_limits.py b/test/integration/component/test_cpu_project_limits.py index 8a355cf44e7..b33b9f120c0 100644 --- a/test/integration/component/test_cpu_project_limits.py +++ b/test/integration/component/test_cpu_project_limits.py @@ -20,20 +20,20 @@ # Import Local Modules from nose.plugins.attrib import attr from marvin.cloudstackTestCase import cloudstackTestCase, unittest -from marvin.integration.lib.base import ( +from marvin.lib.base import ( Account, ServiceOffering, VirtualMachine, Domain, Project ) -from marvin.integration.lib.common import (get_domain, +from marvin.lib.common import (get_domain, get_zone, get_template, findSuitableHostForMigration, get_resource_type ) -from marvin.integration.lib.utils import cleanup_resources +from marvin.lib.utils import cleanup_resources from marvin.codes import ERROR_NO_HOST_FOR_MIGRATION class Services: @@ -91,12 +91,13 @@ class TestProjectsCPULimits(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestProjectsCPULimits, - cls).getClsTestClient().getApiClient() + cls.testClient = super(TestProjectsCPULimits, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services["mode"] = cls.zone.networktype cls.template = get_template( cls.api_client, @@ -137,7 +138,7 @@ class TestProjectsCPULimits(cloudstackTestCase): self.debug("Setting up account and domain hierarchy") self.setupProjectAccounts() - api_client = self.testClient.createUserApiClient( + api_client = self.testClient.getUserApiClient( UserName=self.admin.name, DomainName=self.admin.domain) diff --git a/test/integration/component/test_custom_hostname.py b/test/integration/component/test_custom_hostname.py index baf4f1b46d0..7eeda492583 100644 --- a/test/integration/component/test_custom_hostname.py +++ b/test/integration/component/test_custom_hostname.py @@ -20,9 +20,9 @@ import marvin from nose.plugins.attrib import attr from marvin.cloudstackTestCase import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * class Services: @@ -94,13 +94,13 @@ class TestInstanceNameFlagTrue(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestInstanceNameFlagTrue, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestInstanceNameFlagTrue, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services - # Get Zone, default template - cls.zone = get_zone(cls.api_client, cls.services) + # Get Zone, Domain and templates + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services["mode"] = cls.zone.networktype cls.template = get_template( cls.api_client, @@ -108,12 +108,7 @@ class TestInstanceNameFlagTrue(cloudstackTestCase): cls.services["ostype"] ) - # Create domains, account etc. - cls.domain = get_domain( - cls.api_client, - cls.services - ) - + # Create account cls.account = Account.create( cls.api_client, cls.services["account"], @@ -561,13 +556,13 @@ class TestInstanceNameFlagFalse(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestInstanceNameFlagFalse, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestInstanceNameFlagFalse, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services - # Get Zone, default template - cls.zone = get_zone(cls.api_client, cls.services) + # Get Zone, Domain and templates + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, @@ -575,12 +570,7 @@ class TestInstanceNameFlagFalse(cloudstackTestCase): cls.services["ostype"] ) - # Create domains, account etc. - cls.domain = get_domain( - cls.api_client, - cls.services - ) - + # Create account cls.account = Account.create( cls.api_client, cls.services["account"], diff --git a/test/integration/component/test_deploy_vm_userdata_reg.py b/test/integration/component/test_deploy_vm_userdata_reg.py index 912c9172ea2..1c9f35c579d 100755 --- a/test/integration/component/test_deploy_vm_userdata_reg.py +++ b/test/integration/component/test_deploy_vm_userdata_reg.py @@ -19,9 +19,9 @@ # this script will cover VMdeployment with Userdata tests from marvin.cloudstackTestCase import cloudstackTestCase -from marvin.integration.lib.base import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.common import * +from marvin.lib.base import * +from marvin.lib.utils import * +from marvin.lib.common import * from nose.plugins.attrib import attr from marvin.sshClient import SshClient import unittest @@ -71,9 +71,10 @@ class TestDeployVmWithUserData(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.apiClient = super(TestDeployVmWithUserData, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestDeployVmWithUserData, cls).getClsTestClient() + cls.apiClient = cls.testClient.getApiClient() cls.services = Services().services - cls.zone = get_zone(cls.apiClient, cls.services) + cls.zone = get_zone(cls.apiClient, cls.testClient.getZoneForTests()) if cls.zone.localstorageenabled: #For devcloud since localstroage is enabled cls.services["service_offering"]["storagetype"] = "local" @@ -99,6 +100,10 @@ class TestDeployVmWithUserData(cloudstackTestCase): cls.user_data_2kl = ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(1900)) + def setUp(self): + self.apiClient = self.testClient.getApiClient() + self.hypervisor = self.testClient.getHypervisorInfo() + @attr(tags=["simulator", "devcloud", "basic", "advanced", "provisioning"]) def test_deployvm_userdata_post(self): @@ -174,7 +179,7 @@ class TestDeployVmWithUserData(cloudstackTestCase): host.passwd="password" cmd="cat /var/www/html/userdata/"+deployVmResponse.ipaddress+"/user-data" - if self.apiClient.hypervisor.lower() == 'vmware': + if self.hypervisor.lower() == 'vmware': try: result = get_process_status( @@ -184,7 +189,7 @@ class TestDeployVmWithUserData(cloudstackTestCase): self.apiClient.connection.passwd, router.linklocalip, cmd, - hypervisor=self.apiClient.hypervisor + hypervisor=self.hypervisor ) res = str(result) self.assertEqual(res.__contains__(self.userdata),True,"Userdata Not applied Check the failures") diff --git a/test/integration/component/test_dynamic_compute_offering.py b/test/integration/component/test_dynamic_compute_offering.py index cb21caf9352..da43fdfeb55 100644 --- a/test/integration/component/test_dynamic_compute_offering.py +++ b/test/integration/component/test_dynamic_compute_offering.py @@ -24,24 +24,13 @@ Feature Specifications: https://cwiki.apache.org/confluence/display/CLOUDSTACK/Dynamic+Compute+Offering+FS """ from marvin.cloudstackTestCase import cloudstackTestCase -from marvin.integration.lib.utils import (cleanup_resources, - validateList, - random_gen) -from marvin.integration.lib.base import (ServiceOffering, - VirtualMachine, - Account, - Resources, - AffinityGroup, - Host) -from marvin.integration.lib.common import (get_domain, - get_zone, - get_template, - verifyComputeOfferingCreation) +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 PASS, ADMIN_ACCOUNT, USER_ACCOUNT from ddt import ddt, data -import time @ddt class TestDynamicServiceOffering(cloudstackTestCase): @@ -50,21 +39,22 @@ class TestDynamicServiceOffering(cloudstackTestCase): @classmethod def setUpClass(cls): - cloudstackTestClient = super(TestDynamicServiceOffering,cls).getClsTestClient() - cls.api_client = cloudstackTestClient.getApiClient() - - # Fill services from the external config file - cls.services = cloudstackTestClient.getConfigParser().parsedDict + testClient = super(TestDynamicServiceOffering, cls).getClsTestClient() + cls.apiclient = testClient.getApiClient() + cls.services = testClient.getParsedTestDataConfig() # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) - cls.mode = str(cls.zone.networktype).lower() - cls.template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) + domain = get_domain(cls.apiclient) + cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests()) + cls.services['mode'] = cls.zone.networktype + + template = get_template( + cls.apiclient, + cls.zone.id, + cls.services["ostype"] + ) + if template == FAILED: + assert False, "get_template() failed to return template with description %s" % cls.services["ostype"] cls.services["virtual_machine"]["zoneid"] = cls.zone.id cls.services["virtual_machine"]["template"] = cls.template.id cls._cleanup = [] diff --git a/test/integration/component/test_egress_fw_rules.py b/test/integration/component/test_egress_fw_rules.py index 6060115e091..4b4b6eee66e 100644 --- a/test/integration/component/test_egress_fw_rules.py +++ b/test/integration/component/test_egress_fw_rules.py @@ -21,7 +21,7 @@ import unittest from nose.plugins.attrib import attr from marvin.cloudstackTestCase import cloudstackTestCase -from marvin.integration.lib.base import (Account, +from marvin.lib.base import (Account, Domain, Router, Network, @@ -31,14 +31,14 @@ from marvin.integration.lib.base import (Account, FireWallRule, NATRule, PublicIPAddress) -from marvin.integration.lib.common import (get_domain, +from marvin.lib.common import (get_domain, get_zone, get_template, list_routers, wait_for_cleanup, list_virtual_machines ) -from marvin.integration.lib.utils import cleanup_resources, validateList +from marvin.lib.utils import cleanup_resources, validateList from marvin.cloudstackAPI import rebootRouter from marvin.cloudstackAPI.createEgressFirewallRule import createEgressFirewallRuleCmd from marvin.cloudstackAPI.deleteEgressFirewallRule import deleteEgressFirewallRuleCmd @@ -132,12 +132,13 @@ class TestEgressFWRules(cloudstackTestCase): @classmethod def setUpClass(cls): cls._cleanup = [] - cls.api_client = super(TestEgressFWRules, - cls).getClsTestClient().getApiClient() - cls.services = Services().services - # Get Zone Domain and create Domains and sub Domains. - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.testClient = super(TestEgressFWRules, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + + cls.services = Services().services + # Get Zone, Domain and templates + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype # Get and set template id for VM creation. cls.template = get_template(cls.api_client, diff --git a/test/integration/component/test_egress_rules.py b/test/integration/component/test_egress_rules.py index a2443d49402..f0b98e4a628 100644 --- a/test/integration/component/test_egress_rules.py +++ b/test/integration/component/test_egress_rules.py @@ -20,13 +20,13 @@ #Import Local Modules from nose.plugins.attrib import attr from marvin.cloudstackTestCase import cloudstackTestCase -from marvin.integration.lib.utils import (random_gen, +from marvin.lib.utils import (random_gen, cleanup_resources) -from marvin.integration.lib.base import (SecurityGroup, +from marvin.lib.base import (SecurityGroup, VirtualMachine, Account, ServiceOffering) -from marvin.integration.lib.common import (get_domain, +from marvin.lib.common import (get_domain, get_zone, get_template, list_virtual_machines) @@ -149,15 +149,13 @@ class TestDefaultSecurityGroupEgress(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.services = Services().services - cls.api_client = super( - TestDefaultSecurityGroupEgress, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestDefaultSecurityGroupEgress, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype template = get_template( @@ -307,15 +305,13 @@ class TestAuthorizeIngressRule(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.services = Services().services - cls.api_client = super( - TestAuthorizeIngressRule, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestAuthorizeIngressRule, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype template = get_template( @@ -465,15 +461,13 @@ class TestDefaultGroupEgress(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.services = Services().services - cls.api_client = super( - TestDefaultGroupEgress, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestDefaultGroupEgress, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype template = get_template( @@ -663,15 +657,13 @@ class TestDefaultGroupEgressAfterDeploy(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.services = Services().services - cls.api_client = super( - TestDefaultGroupEgressAfterDeploy, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestDefaultGroupEgressAfterDeploy, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype template = get_template( @@ -842,15 +834,13 @@ class TestRevokeEgressRule(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.services = Services().services - cls.api_client = super( - TestRevokeEgressRule, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestRevokeEgressRule, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype template = get_template( @@ -1125,15 +1115,13 @@ class TestInvalidAccountAuthroize(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.services = Services().services - cls.api_client = super( - TestInvalidAccountAuthroize, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestInvalidAccountAuthroize, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype template = get_template( @@ -1246,15 +1234,13 @@ class TestMultipleAccountsEgressRuleNeg(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.services = Services().services - cls.api_client = super( - TestMultipleAccountsEgressRuleNeg, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestMultipleAccountsEgressRuleNeg, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype template = get_template( @@ -1495,15 +1481,13 @@ class TestMultipleAccountsEgressRule(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.services = Services().services - cls.api_client = super( - TestMultipleAccountsEgressRule, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestMultipleAccountsEgressRule, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype template = get_template( @@ -1786,15 +1770,13 @@ class TestStartStopVMWithEgressRule(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.services = Services().services - cls.api_client = super( - TestStartStopVMWithEgressRule, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestStartStopVMWithEgressRule, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype template = get_template( @@ -1993,15 +1975,13 @@ class TestInvalidParametersForEgress(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.services = Services().services - cls.api_client = super( - TestInvalidParametersForEgress, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestInvalidParametersForEgress, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype template = get_template( diff --git a/test/integration/component/test_eip_elb.py b/test/integration/component/test_eip_elb.py index d639d82d9f5..0613c4d0535 100644 --- a/test/integration/component/test_eip_elb.py +++ b/test/integration/component/test_eip_elb.py @@ -22,9 +22,9 @@ import marvin from nose.plugins.attrib import attr from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * from marvin.sshClient import SshClient import datetime @@ -91,11 +91,13 @@ class TestEIP(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestEIP, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestEIP, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype cls.template = get_template( cls.api_client, @@ -909,11 +911,13 @@ class TestELB(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestELB, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestELB, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype cls.template = get_template( cls.api_client, diff --git a/test/integration/component/test_escalations.py b/test/integration/component/test_escalations.py new file mode 100644 index 00000000000..e9945790b8b --- /dev/null +++ b/test/integration/component/test_escalations.py @@ -0,0 +1,8230 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +#Import Local Modules +from marvin.cloudstackTestCase import * +from marvin.cloudstackException 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 marvin.lib.utils import checkVolumeSize +from marvin.codes import SUCCESS +from nose.plugins.attrib import attr +from time import sleep + +class TestVolumes(cloudstackTestCase): + + @classmethod + def setUpClass(cls): + + cls.testClient = super(TestVolumes, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = cls.testClient.getParsedTestDataConfig() + # Get Domain, Zone, Template + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client) + cls.template = get_template( + cls.api_client, + cls.zone.id, + cls.services["ostype"] + ) + if cls.zone.localstorageenabled: + cls.storagetype = 'local' + cls.services["service_offerings"]["tiny"]["storagetype"] = 'local' + cls.services["disk_offering"]["storagetype"] = 'local' + else: + cls.storagetype = 'shared' + cls.services["service_offerings"]["tiny"]["storagetype"] = 'shared' + cls.services["disk_offering"]["storagetype"] = 'shared' + + cls.services['mode'] = cls.zone.networktype + cls.services["virtual_machine"]["hypervisor"] = 'XenServer' + cls.services["virtual_machine"]["zoneid"] = cls.zone.id + cls.services["virtual_machine"]["template"] = cls.template.id + cls.services["custom_volume"]["zoneid"] = cls.zone.id + + # Creating Disk offering, Service Offering and Account + cls.disk_offering = DiskOffering.create( + cls.api_client, + cls.services["disk_offering"] + ) + cls.service_offering = ServiceOffering.create( + cls.api_client, + cls.services["service_offerings"]["tiny"] + ) + cls.account = Account.create( + cls.api_client, + cls.services["account"], + domainid=cls.domain.id + ) + + # Getting authentication for user in newly created Account + cls.user = cls.account.user[0] + + cls.userapiclient = cls.testClient.getUserApiClient(cls.user.username, cls.domain.name) + + # Creating Virtual Machine + cls.virtual_machine = VirtualMachine.create( + cls.userapiclient, + cls.services["virtual_machine"], + accountid=cls.account.name, + domainid=cls.account.domainid, + serviceofferingid=cls.service_offering.id, + ) + cls._cleanup = [ + cls.virtual_machine, + cls.disk_offering, + cls.service_offering, + cls.account + ] + + def setUp(self): + + self.apiClient = self.testClient.getApiClient() + self.cleanup = [] + + def tearDown(self): + #Clean up, terminate the created volumes + cleanup_resources(self.apiClient, self.cleanup) + return + + @classmethod + def tearDownClass(cls): + try: + cls.apiclient = super(TestVolumes, cls).getClsTestClient().getApiClient() + cleanup_resources(cls.apiclient, cls._cleanup) + except Exception as e: + raise Exception("Warning: Exception during cleanup : %s" % e) + + + def __verify_values(self, expected_vals, actual_vals): + """ + @summary: Function to verify expected and actual values + Step1: Initializing return flag to True + Step1: Verifying length of expected and actual dictionaries is matching. + If not matching returning false + Step2: Listing all the keys from expected dictionary + Step3: Looping through each key from step2 and verifying expected and actual dictionaries have same value + If not making return flag to False + Step4: returning the return flag after all the values are verified + """ + return_flag = True + + if len(expected_vals) != len(actual_vals): + return False + + keys = expected_vals.keys() + for i in range(0, len(expected_vals)): + exp_val = expected_vals[keys[i]] + act_val = actual_vals[keys[i]] + if exp_val == act_val: + return_flag = return_flag and True + else: + return_flag = return_flag and False + self.debug("expected Value: %s, is not matching with actual value: %s" % ( + exp_val, + act_val + )) + return return_flag + + @attr(tags=["advanced", "basic", "provisioning"]) + def test_01_list_volumes_pagination(self): + """ + @summary: Test List Volumes pagination + + Step1: Listing all the volumes for a user + Step2: Verifying listed volumes for account created at class level + Step3: If number of volumes is less than (page size + 1), then creating them + Step4: Listing all the volumes again after creation of volumes + Step5: Verifying the length of the volumes is (page size + 1) + Step6: Listing all the volumes in page1 + Step7: Verifying that the length of the volumes in page 1 is (page size) + Step8: Listing all the volumes in page2 + Step9: Verifying that the length of the volumes in page 2 is 1 + Step10: Deleting the volume present in page 2 + Step11: Listing for the volumes on page 2 + Step12: Verifying that there are no volumes present in page 2 + """ + # Listing all the volumes for a user + list_volumes_before = Volume.list(self.userapiclient, listall=self.services["listall"]) + + # Verifying listed volumes for account created at class level + self.assertIsNotNone( + list_volumes_before, + "create volume from VM failed at class setup method" + ) + self.assertEqual( + len(list_volumes_before), + 1, + "more than 1 volume created from VM at class level" + ) + + # If number of volumes is less than (pagesize + 1), then creating them + for i in range(0, (self.services["pagesize"])): + volume_created = Volume.create( + self.userapiclient, + self.services["volume"], + zoneid=self.zone.id, + diskofferingid=self.disk_offering.id + ) + self.assertIsNotNone( + volume_created, + "Volume is not created" + ) + if(i < (self.services["pagesize"] - 1)): + self.cleanup.append(volume_created) + + self.assertEqual( + self.services["volume"]["diskname"], + volume_created.name, + "Newly created volume name and the test data volume name are not matching" + ) + + # Listing all the volumes again after creation of volumes + list_volumes_after = Volume.list(self.userapiclient, listall=self.services["listall"]) + + # Verifying the length of the volumes is (page size + 1) + self.assertEqual( + len(list_volumes_after), + (self.services["pagesize"] + 1), + "Number of volumes created is not matching expected" + ) + + # Listing all the volumes in page1 + list_volumes_page1 = Volume.list( + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"] + ) + self.assertIsNotNone( + list_volumes_page1, + "No volumes found in Page 1" + ) + # Verifying that the length of the volumes in page 1 is (page size) + self.assertEqual( + len(list_volumes_page1), + self.services["pagesize"], + "List Volume response is not matching with the page size length for page 1" + ) + + # Listing all the volumes in page2 + list_volumes_page2 = Volume.list( + self.userapiclient, + listall=self.services["listall"], + page=2, + pagesize=self.services["pagesize"] + ) + self.assertIsNotNone( + list_volumes_page2, + "No volumes found in Page 2" + ) + # Verifying that the length of the volumes in page 2 is 1 + self.assertEqual( + len(list_volumes_page2), + 1, + "List Volume response is not matching with the page size length for page 2" + ) + volume_page2 = list_volumes_page2[0] + + # Verifying that the volume on page 2 is not present in page1 + for i in range(0, len(list_volumes_page1)): + volume_page1 = list_volumes_page1[i] + self.assertNotEquals( + volume_page2.id, + volume_page1.id, + "Volume listed in page 2 is also listed in page 1" + ) + + # Deleting a single volume + Volume.delete(volume_created, self.userapiclient) + + # Listing the volumes in page 2 + list_volume_response = Volume.list( + self.userapiclient, + listall=self.services["listall"], + page=2, + pagesize=self.services["pagesize"] + ) + # verifying that volume does not exists on page 2 + self.assertEqual( + list_volume_response, + None, + "Volume was not deleted" + ) + return + + @attr(tags=["advanced", "basic", "provisioning"]) + def test_02_list_volume_byid(self): + """ + @summary: Test List Volumes with Id + + Step1: Listing all the volumes for a user before creating a data volume + Step2: Verifying the length of the list as 1 + Step3: Creating a data volume + Step4: Listing all the volumes for a user after creating a data volume + Step5: Verifying the list volume size is increased by 1 + Step6: List the volumes by specifying root volume Id + Step7: Verifying the details of the root volume + Step8: List the volumes by specifying data volume Id + Step9: Verifying the details of the data volume + """ + # Listing all the volumes for a user before creating a data volume + list_volumes_before = Volume.list( + self.userapiclient, + listall=self.services["listall"] + ) + self.assertIsNotNone( + list_volumes_before, + "create volume from VM failed at class setup method") + # Verifying the length of the list as 1 + self.assertEqual( + len(list_volumes_before), + 1, + "more than 1 volume created at class level" + ) + root_volume = list_volumes_before[0] + + # Creating a data volume + volume_created = Volume.create( + self.userapiclient, + self.services["volume"], + zoneid=self.zone.id, + diskofferingid=self.disk_offering.id + ) + self.assertIsNotNone( + volume_created, + "Volume is not created" + ) + self.cleanup.append(volume_created) + + self.assertEqual( + self.services["volume"]["diskname"], + volume_created.name, + "Newly created volume name and the test data volume name are not matching" + ) + # Listing all the volumes for a user after creating a data volume + list_volumes_after = Volume.list( + self.userapiclient, + listall=self.services["listall"] + ) + self.assertIsNotNone( + list_volumes_after, + "Volume creation failed" + ) + # Verifying the list volume size is increased by 1 + self.assertEqual( + len(list_volumes_before) + 1, + len(list_volumes_after), + "list volume is not matching with Number of volumes created" + ) + + # Listing a Root Volume by Id and verifying the volume details + list_volumes_by_id = Volume.list( + self.userapiclient, + listall=self.services["listall"], + id=root_volume.id + ) + self.assertIsNotNone( + list_volumes_by_id, + "Root volume is not listed" + ) + self.assertEqual( + 1, + len(list_volumes_by_id), + "list volume is not matching with Number of volumes created" + ) + obtained_volume = list_volumes_by_id[0] + + #Creating expected and actual values dictionaries + expected_dict = { + "id":root_volume.id, + "name":root_volume.name, + "vmname":self.virtual_machine.name, + "state":"Ready", + "type":"ROOT", + "zoneid":self.zone.id, + "account":self.account.name, + "storagetype":self.storagetype, + "size":self.template.size + } + actual_dict = { + "id":obtained_volume.id, + "name":obtained_volume.name, + "vmname":obtained_volume.vmname, + "state":obtained_volume.state, + "type":obtained_volume.type, + "zoneid":obtained_volume.zoneid, + "account":obtained_volume.account, + "storagetype":obtained_volume.storagetype, + "size":obtained_volume.size, + } + root_volume_status = self.__verify_values( + expected_dict, + actual_dict + ) + self.assertEqual( + True, + root_volume_status, + "Listed Root Volume details are not as expected" + ) + # Listing a Data Volume by Id and verifying the volume details + list_volumes_by_id = Volume.list( + self.userapiclient, + listall=self.services["listall"], + id=volume_created.id + ) + self.assertIsNotNone( + list_volumes_by_id, + "Data volume is not listed" + ) + self.assertEqual( + len(list_volumes_by_id), + 1, + "list volume is not matching with Number of volumes created" + ) + obtained_volume = list_volumes_by_id[0] + + #Creating expected and actual values dictionaries + expected_dict = { + "id":volume_created.id, + "name":volume_created.name, + "state":"Allocated", + "type":"DATADISK", + "zoneid":self.zone.id, + "account":self.account.name, + "storagetype":self.storagetype, + "size":self.disk_offering.disksize + } + actual_dict = { + "id":obtained_volume.id, + "name":obtained_volume.name, + "state":obtained_volume.state, + "type":obtained_volume.type, + "zoneid":obtained_volume.zoneid, + "account":obtained_volume.account, + "storagetype":obtained_volume.storagetype, + "size":obtained_volume.size/(1024*1024*1024), + } + root_volume_status = self.__verify_values( + expected_dict, + actual_dict + ) + self.assertEqual( + True, + root_volume_status, + "Listed Data Volume details are not as expected" + ) + return + + @attr(tags=["advanced", "basic", "provisioning"]) + def test_03_data_volume_resize(self): + """ + @summary: Test to verify creation and resize of data volume + + Step1: Listing the volumes for a user before creating data volume + Step2: Creating a data volume + Step3: Listing the volumes for a user after creating data volume + Step4: Attaching and Detaching data volume created to Virtual Machine + Step5: Verifying if there exists a disk offering with higher size + If not present creating it + Step6: Resizing data volume + """ + # Listing volumes for a user before creating a volume + list_volumes_before = Volume.list(self.userapiclient, listall=self.services["listall"]) + + # Creating a data volume + volume_created = Volume.create( + self.userapiclient, + self.services["volume"], + zoneid=self.zone.id, + diskofferingid=self.disk_offering.id + ) + self.assertIsNotNone(volume_created, "Data volume creation failed") + + self.cleanup.append(volume_created) + + # Listing volumes for a user after creating data volume + list_volumes_after = Volume.list(self.userapiclient, listall=self.services["listall"]) + self.assertEquals( + len(list_volumes_before) + 1, + len(list_volumes_after), + "Data volume creation failed" + ) + + # Attaching data volume created to Virtual Machine + self.virtual_machine.attach_volume( + self.userapiclient, + volume_created + ) + + list_volumes = Volume.list( + self.userapiclient, + listall=self.services["listall"], + id=volume_created.id + ) + attached_volume = list_volumes[0] + + self.assertIsNotNone( + attached_volume.vmname, + "VM is not attached to Volume" + ) + self.assertEquals( + self.virtual_machine.name, + attached_volume.vmname, + "VM Name is not matching with attached vm" + ) + + # Detaching data volume from Virtual Machine + self.virtual_machine.detach_volume( + self.userapiclient, + volume_created + ) + list_volumes = Volume.list( + self.userapiclient, + listall=self.services["listall"], + id=volume_created.id + ) + detached_volume = list_volumes[0] + self.assertIsNone( + detached_volume.vmname, + "VM is not detached from volume" + ) + + # Verifying if there exists a disk offering with higher size. If not present creating it + list_disk_offerings = DiskOffering.list(self.apiClient) + + large_disk_offering_exists = False + # Converting disk_size in bytes to GB + current_disk_size = volume_created.size/(1024*1024*1024) + + for disk_offering in list_disk_offerings: + if ((disk_offering.disksize > current_disk_size) and (not disk_offering.iscustomized) and disk_offering.storagetype == self.storagetype): + new_disk_offering = disk_offering + large_disk_offering_exists = True + break + + if large_disk_offering_exists == False: + new_size = (volume_created.size/(1024*1024*1024)) + 1 + self.services["disk_offering"]["disksize"] = new_size + new_disk_offering = DiskOffering.create( + self.apiClient, + self.services["disk_offering"] + ) + if new_disk_offering is not None: + self.cleanup.append(new_disk_offering) + else: + new_size = new_disk_offering.disksize + + # Resizing data volume + resized_volume = volume_created.resize( + self.userapiclient, + diskofferingid=new_disk_offering.id, + shrinkok='false', + ) + self.assertIsNotNone(resized_volume, "Resize Volume failed") + # Verifying data volume size is increased + self.assertEquals( + new_size, + (resized_volume.size/(1024*1024*1024)), + "volume not resized to expected value" + ) + return + + @attr(tags=["advanced", "basic", "provisioning"]) + def test_04_custom_volume_resize(self): + """ + @summary: Test to verify creation and resize of custom volume + + Step1: Checking if Custom disk offering already exists. + If not present then creating custom Disk Offering + Step2: Listing the volumes for a user before creating custom volume + Step3: Creating a custom volume + Step4: Listing the volumes for a user after creating custom volume + Step5: Attaching and Detaching custom volume created to Virtual Machine + Step6: Resizing custom volume + """ + # Listing all the disk offerings + list_disk_offerings = DiskOffering.list(self.apiClient) + + custom_disk_offering_exists = False + + # Verifying if a custom disk offering already exists + if list_disk_offerings is not None: + for disk_offering in list_disk_offerings: + if (disk_offering.iscustomized and disk_offering.storagetype == self.storagetype): + custom_disk_offering = disk_offering + custom_disk_offering_exists = True + break + + # If a custom disk offering does not exists, then creating a custom disk offering + if custom_disk_offering_exists == False: + custom_disk_offering = DiskOffering.create( + self.apiClient, + self.services["disk_offering"], + custom=True + ) + if custom_disk_offering is not None: + self.cleanup.append(custom_disk_offering) + + # Listing the volumes for a user before creating custom volume + list_volumes_before = Volume.list(self.userapiclient, listall=self.services["listall"]) + + # Creating a custom volume + volume_created = Volume.create_custom_disk( + self.userapiclient, + self.services["custom_volume"], + account=self.account.name, + domainid=self.account.domainid, + diskofferingid=custom_disk_offering.id + ) + self.assertIsNotNone( + volume_created, + "Custom volume did not get created" + ) + + self.cleanup.append(volume_created) + + # Listing the volumes for a user after creating custom volume + list_volumes_after = Volume.list(self.userapiclient, listall=self.services["listall"]) + + # Verifyign that volume list is increased by 1 after creation of custion volume + self.assertEquals( + len(list_volumes_before) + 1, + len(list_volumes_after), + "Custom volume did not get created" + ) + + # Attaching custom volume created to Virtual Machine + self.virtual_machine.attach_volume( + self.userapiclient, + volume_created + ) + list_volumes = Volume.list( + self.userapiclient, + listall=self.services["listall"], + id=volume_created.id + ) + attached_volume = list_volumes[0] + + self.assertIsNotNone( + attached_volume.vmname, + "VM is not attached to Volume" + ) + self.assertEquals( + self.virtual_machine.name, + attached_volume.vmname, + "VM Name is not matching with attached vm" + ) + + # Detaching custom volume from Virtual Machine + self.virtual_machine.detach_volume( + self.userapiclient, + volume_created + ) + list_volumes = Volume.list( + self.userapiclient, + listall=self.services["listall"], + id=volume_created.id + ) + detached_volume = list_volumes[0] + self.assertIsNone( + detached_volume.vmname, + "VM is not detached from volume" + ) + + # Resizing custom volume + # Increasing custom disk size by 1 + new_size = self.services["custom_volume"]["customdisksize"] + 1 + resized_volume = volume_created.resize( + self.userapiclient, + diskofferingid=custom_disk_offering.id, + shrinkok='false', + size=new_size) + self.assertIsNotNone(resized_volume, "Resize Volume failed") + # Verifying that custom disk size is increased + self.assertEquals( + new_size, + (resized_volume.size/(1024*1024*1024)), + "volume not resized to expected value" + ) + return + + @attr(tags=["advanced", "basic", "provisioning"]) + def test_05_volume_snapshot(self): + """ + @summary: Test to verify creation of snapshot from volume and creation of template, volume from snapshot + + Step1: Creating a volume + Step2: Attaching and Detaching custom volume created to Virtual Machine + Step3: Creating Snapshot from volume + Step4: Creating Volume from snapshot + Step5: Creating Template from Snapshot + """ + list_volumes_before = Volume.list(self.userapiclient, listall=self.services["listall"]) + + volume_created = Volume.create( + self.userapiclient, + self.services["volume"], + zoneid=self.zone.id, + diskofferingid=self.disk_offering.id + ) + + self.assertIsNotNone(volume_created, "Volume not created") + + if volume_created is not None: + self.cleanup.append(volume_created) + + list_volumes_after = Volume.list(self.userapiclient, listall=self.services["listall"]) + + self.assertEquals( + len(list_volumes_before) + 1, + len(list_volumes_after), + "Volume not created" + ) + # Attaching and Detaching custom volume created to Virtual Machine + self.virtual_machine.attach_volume( + self.userapiclient, + volume_created + ) + + list_volumes = Volume.list( + self.userapiclient, + listall=self.services["listall"], + id=volume_created.id + ) + attached_volume = list_volumes[0] + + self.assertIsNotNone( + attached_volume.vmname, + "VM is not attached to Volume" + ) + self.assertEquals( + self.virtual_machine.name, + attached_volume.vmname, + "VM Name is not matching with attached vm" + ) + self.virtual_machine.detach_volume( + self.userapiclient, + volume_created + ) + list_volumes = Volume.list( + self.userapiclient, + listall=self.services["listall"], + id=volume_created.id + ) + detached_volume = list_volumes[0] + self.assertIsNone( + detached_volume.vmname, + "VM is not detached from volume" + ) + # Creating Snapshot from volume + snapshot_created = Snapshot.create( + self.userapiclient, + volume_created.id, + ) + + self.assertIsNotNone(snapshot_created, "Snapshot not created") + + self.cleanup.append(snapshot_created) + + #Creating expected and actual values dictionaries + expected_dict = { + "id":volume_created.id, + "intervaltype":"MANUAL", + "snapshottype":"MANUAL", + "volumetype":volume_created.type, + "domain":self.domain.id + } + actual_dict = { + "id":snapshot_created.volumeid, + "intervaltype":snapshot_created.intervaltype, + "snapshottype":snapshot_created.snapshottype, + "volumetype":snapshot_created.volumetype, + "domain":snapshot_created.domainid, + } + status = self.__verify_values( + expected_dict, + actual_dict + ) + self.assertEqual( + True, + status, + "Snapshot created from Volume details are not as expected" + ) + # Creating Volume from snapshot + cmd = createVolume.createVolumeCmd() + cmd.name = "-".join([self.services["volume"]["diskname"], random_gen()]) + cmd.snapshotid = snapshot_created.id + + volume_from_snapshot = Volume(self.userapiclient.createVolume(cmd).__dict__) + + self.assertIsNotNone( + volume_from_snapshot, + "Volume creation failed from snapshot" + ) + self.cleanup.append(volume_from_snapshot) + + #Creating expected and actual values dictionaries + expected_dict = { + "snapshotid":snapshot_created.id, + "volumetype":snapshot_created.volumetype, + "size":self.disk_offering.disksize, + "accounr":self.account.name, + "domain":self.domain.id, + "storagetype":self.storagetype, + "zone":self.zone.id + } + actual_dict = { + "snapshotid":volume_from_snapshot.snapshotid, + "volumetype":volume_from_snapshot.type, + "size":volume_from_snapshot.size/(1024*1024*1024), + "accounr":volume_from_snapshot.account, + "domain":volume_from_snapshot.domainid, + "storagetype":volume_from_snapshot.storagetype, + "zone":volume_from_snapshot.zoneid, + } + status = self.__verify_values( + expected_dict, + actual_dict + ) + self.assertEqual( + True, + status, + "Volume created from Snapshot details are not as expected" + ) + # Creating Template from Snapshot + list_templates_before = Template.list(self.userapiclient, templatefilter='self') + + if list_templates_before is None: + templates_before_size = 0 + else: + templates_before_size = len(list_templates_before) + + cmd = createTemplate.createTemplateCmd() + cmd.name = self.services["ostype"] + cmd.displaytext = self.services["ostype"] + cmd.ostypeid = self.template.ostypeid + cmd.snapshotid = snapshot_created.id + cmd.ispublic = False + cmd.passwordenabled = False + + template_from_snapshot = Template(self.userapiclient.createTemplate(cmd).__dict__) + + self.assertIsNotNone( + template_from_snapshot, + "Template creation failed from snapshot" + ) + + self.cleanup.append(template_from_snapshot) + + #Creating expected and actual values dictionaries + expected_dict = { + "name":self.services["ostype"], + "ostypeid":self.template.ostypeid, + "type":"USER", + "zone":self.zone.id, + "domain":self.domain.id, + "account":self.account.name, + "passwordenabled":False, + "ispublic":False, + "size":self.disk_offering.disksize + } + actual_dict = { + "name":template_from_snapshot.name, + "ostypeid":template_from_snapshot.ostypeid, + "type":template_from_snapshot.templatetype, + "zone":template_from_snapshot.zoneid, + "domain":template_from_snapshot.domainid, + "account":template_from_snapshot.account, + "passwordenabled":template_from_snapshot.passwordenabled, + "ispublic":template_from_snapshot.ispublic, + "size":template_from_snapshot.size/(1024*1024*1024) + } + status = self.__verify_values( + expected_dict, + actual_dict + ) + self.assertEqual( + True, + status, + "Template created from Snapshot details are not as expected" + ) + + list_templates_after = Template.list(self.userapiclient, templatefilter='self') + + self.assertEquals( + templates_before_size + 1, + len(list_templates_after), + "Template creation failed from snapshot" + ) + return + + @attr(tags=["advanced", "basic", "provisioning"]) + def test_06_volume_snapshot_policy_hourly(self): + """ + @summary: Test to verify creation of Hourly Snapshot policies from volume + + Step1: Creating a Volume. + Step2: Attaching volume created in Step2 to virtual machine + Step3: Detaching the volume created in step2 from virtual machine + Step4: Listing snapshot policies for a volume created in step1 + Step5: Creating Hourly snapshot policy + Step6: Listing snapshot policies for a volume created in step1 again + Step7: Verifyign that the list snapshot policy length is increased by 1 + """ + list_volumes_before = Volume.list(self.userapiclient, listall=self.services["listall"]) + + volume_created = Volume.create( + self.userapiclient, + self.services["volume"], + zoneid=self.zone.id, + diskofferingid=self.disk_offering.id + ) + + self.assertIsNotNone(volume_created, "Volume not created") + self.cleanup.append(volume_created) + + list_volumes_after = Volume.list(self.userapiclient, listall=self.services["listall"]) + + self.assertEquals( + len(list_volumes_before) + 1, + len(list_volumes_after), + "Volume not created" + ) + + # Attaching volume created to Virtual Machine + self.virtual_machine.attach_volume( + self.userapiclient, + volume_created + ) + + list_volumes = Volume.list( + self.userapiclient, + listall=self.services["listall"], + id=volume_created.id + ) + attached_volume = list_volumes[0] + + self.assertIsNotNone( + attached_volume.vmname, + "VM is not attached to Volume" + ) + self.assertEquals( + self.virtual_machine.name, + attached_volume.vmname, + "VM Name is not matching with attached vm" + ) + # Detaching volume created from Virtual Machine + self.virtual_machine.detach_volume( + self.userapiclient, + volume_created + ) + list_volumes = Volume.list( + self.userapiclient, + listall=self.services["listall"], + id=volume_created.id + ) + detached_volume = list_volumes[0] + self.assertIsNone( + detached_volume.vmname, + "VM is not detached from volume" + ) + # Creating Hourly Snapshot Policy from volume + self.services["recurring_snapshot"]["intervaltype"] = 'hourly' + self.services["recurring_snapshot"]["schedule"] = '1' + + list_snapshot_policy_before = SnapshotPolicy.list(self.userapiclient, volumeid=volume_created.id) + + snapshot_policy_before_size = 0 + + if list_snapshot_policy_before is not None: + snapshot_policy_before_size = len(list_snapshot_policy_before) + + snapshot_policy_hourly = SnapshotPolicy.create( + self.userapiclient, + volume_created.id, + self.services["recurring_snapshot"] + ) + self.assertIsNotNone( + snapshot_policy_hourly, + "Hourly Snapshot policy creation failed" + ) + #Creating expected and actual values dictionaries + expected_dict = { + "schedule":self.services["recurring_snapshot"]["schedule"], + "intervaltype":0, + "volumeid":volume_created.id + } + actual_dict = { + "schedule":snapshot_policy_hourly.schedule, + "intervaltype":snapshot_policy_hourly.intervaltype, + "volumeid":snapshot_policy_hourly.volumeid + } + status = self.__verify_values( + expected_dict, + actual_dict + ) + self.assertEqual( + True, + status, + "Hourly Snapshot Policy details are not as expected" + ) + + list_snapshot_policy_after = SnapshotPolicy.list(self.userapiclient, volumeid=volume_created.id) + + self.assertIsNotNone( + list_snapshot_policy_after, + "Hourly Snapshot policy creation failed" + ) + self.assertEquals( + snapshot_policy_before_size + 1, + len(list_snapshot_policy_after), + "Hourly Snapshot policy creation failed" + ) + return + + @attr(tags=["advanced", "basic", "provisioning"]) + def test_07_volume_snapshot_policy_daily(self): + """ + @summary: Test to verify creation of Daily Snapshot policies from volume + + Step1: Creating a Volume. + Step2: Attaching volume created in Step2 to virtual machine + Step3: Detaching the volume created in step2 from virtual machine + Step4: Listing snapshot policies for a volume created in step1 + Step5: Creating Daily snapshot policy + Step6: Listing snapshot policies for a volume created in step1 again + Step7: Verifyign that the list snapshot policy length is increased by 1 + """ + list_volumes_before = Volume.list(self.userapiclient, listall=self.services["listall"]) + + volume_created = Volume.create( + self.userapiclient, + self.services["volume"], + zoneid=self.zone.id, + diskofferingid=self.disk_offering.id + ) + + self.assertIsNotNone(volume_created, "Volume not created") + self.cleanup.append(volume_created) + + list_volumes_after = Volume.list(self.userapiclient, listall=self.services["listall"]) + + self.assertEquals( + len(list_volumes_before) + 1, + len(list_volumes_after), + "Volume not created" + ) + # Attaching volume created to Virtual Machine + self.virtual_machine.attach_volume( + self.userapiclient, + volume_created + ) + + list_volumes = Volume.list( + self.userapiclient, + listall=self.services["listall"], + id=volume_created.id + ) + attached_volume = list_volumes[0] + + self.assertIsNotNone( + attached_volume.vmname, + "VM is not attached to Volume" + ) + self.assertEquals( + self.virtual_machine.name, + attached_volume.vmname, + "VM Name is not matching with attached vm" + ) + # Detaching volume created from Virtual Machine + self.virtual_machine.detach_volume( + self.userapiclient, + volume_created + ) + list_volumes = Volume.list( + self.userapiclient, + listall=self.services["listall"], + id=volume_created.id + ) + detached_volume = list_volumes[0] + self.assertIsNone( + detached_volume.vmname, + "VM is not detached from volume" + ) + # Creating Daily Snapshot Policy from volume + self.services["recurring_snapshot"]["intervaltype"] = 'daily' + self.services["recurring_snapshot"]["schedule"] = '00:00' + + list_snapshot_policy_before = SnapshotPolicy.list(self.userapiclient, volumeid=volume_created.id) + + snapshot_policy_before_size = 0 + + if list_snapshot_policy_before is not None: + snapshot_policy_before_size = len(list_snapshot_policy_before) + + snapshot_policy_daily = SnapshotPolicy.create( + self.userapiclient, + volume_created.id, + self.services["recurring_snapshot"] + ) + self.assertIsNotNone( + snapshot_policy_daily, + "Daily Snapshot policy creation failed" + ) + #Creating expected and actual values dictionaries + expected_dict = { + "schedule":self.services["recurring_snapshot"]["schedule"], + "intervaltype":1, + "volumeid":volume_created.id + } + actual_dict = { + "schedule":snapshot_policy_daily.schedule, + "intervaltype":snapshot_policy_daily.intervaltype, + "volumeid":snapshot_policy_daily.volumeid + } + status = self.__verify_values( + expected_dict, + actual_dict + ) + self.assertEqual( + True, + status, + "Daily Snapshot Policy details are not as expected" + ) + + list_snapshot_policy_after = SnapshotPolicy.list(self.userapiclient, volumeid=volume_created.id) + + self.assertIsNotNone( + list_snapshot_policy_after, + "Daily Snapshot policy creation failed" + ) + self.assertEquals( + snapshot_policy_before_size + 1, + len(list_snapshot_policy_after), + "Daily Snapshot policy creation failed" + ) + return + + @attr(tags=["advanced", "basic", "provisioning"]) + def test_08_volume_snapshot_policy_weekly(self): + """ + @summary: Test to verify creation of Weekly Snapshot policies from volume + + Step1: Creating a Volume. + Step2: Attaching volume created in Step2 to virtual machine + Step3: Detaching the volume created in step2 from virtual machine + Step4: Listing snapshot policies for a volume created in step1 + Step5: Creating Weekly snapshot policy + Step6: Listing snapshot policies for a volume created in step1 again + Step7: Verifyign that the list snapshot policy length is increased by 1 + """ + list_volumes_before = Volume.list(self.userapiclient, listall=self.services["listall"]) + + volume_created = Volume.create( + self.userapiclient, + self.services["volume"], + zoneid=self.zone.id, + diskofferingid=self.disk_offering.id + ) + + self.assertIsNotNone(volume_created, "Volume not created") + self.cleanup.append(volume_created) + + list_volumes_after = Volume.list(self.userapiclient, listall=self.services["listall"]) + + self.assertEquals( + len(list_volumes_before) + 1, + len(list_volumes_after), + "Volume not created" + ) + + # Attaching volume created to Virtual Machine + self.virtual_machine.attach_volume( + self.userapiclient, + volume_created + ) + list_volumes = Volume.list( + self.userapiclient, + listall=self.services["listall"], + id=volume_created.id + ) + attached_volume = list_volumes[0] + + self.assertIsNotNone( + attached_volume.vmname, + "VM is not attached to Volume" + ) + self.assertEquals( + self.virtual_machine.name, + attached_volume.vmname, + "VM Name is not matching with attached vm" + ) + # Detaching volume created to Virtual Machine + self.virtual_machine.detach_volume( + self.userapiclient, + volume_created + ) + list_volumes = Volume.list( + self.userapiclient, + listall=self.services["listall"], + id=volume_created.id + ) + detached_volume = list_volumes[0] + self.assertIsNone( + detached_volume.vmname, + "VM is not detached from volume" + ) + # Creating Weekly Snapshot Policy from volume + self.services["recurring_snapshot"]["intervaltype"] = 'weekly' + self.services["recurring_snapshot"]["schedule"] = '00:00:1' + + list_snapshot_policy_before = SnapshotPolicy.list(self.userapiclient, volumeid=volume_created.id) + + snapshot_policy_before_size = 0 + + if list_snapshot_policy_before is not None: + snapshot_policy_before_size = len(list_snapshot_policy_before) + + snapshot_policy_weekly = SnapshotPolicy.create( + self.userapiclient, + volume_created.id, + self.services["recurring_snapshot"] + ) + self.assertIsNotNone( + snapshot_policy_weekly, + "Weekly Snapshot policy creation failed" + ) + #Creating expected and actual values dictionaries + expected_dict = { + "schedule":self.services["recurring_snapshot"]["schedule"], + "intervaltype":2, + "volumeid":volume_created.id + } + actual_dict = { + "schedule":snapshot_policy_weekly.schedule, + "intervaltype":snapshot_policy_weekly.intervaltype, + "volumeid":snapshot_policy_weekly.volumeid + } + status = self.__verify_values( + expected_dict, + actual_dict + ) + self.assertEqual( + True, + status, + "Weekly Snapshot Policy details are not as expected" + ) + + list_snapshot_policy_after = SnapshotPolicy.list(self.userapiclient, volumeid=volume_created.id) + + self.assertIsNotNone( + list_snapshot_policy_after, + "Weekly Snapshot policy creation failed" + ) + self.assertEquals( + snapshot_policy_before_size + 1, + len(list_snapshot_policy_after), + "Weekly Snapshot policy creation failed" + ) + return + + @attr(tags=["advanced", "basic", "provisioning"]) + def test_09_volume_snapshot_policy_monthly(self): + """ + @summary: Test to verify creation of Monthly Snapshot policies from volume + + Step1: Creating a Volume. + Step2: Attaching volume created in Step2 to virtual machine + Step3: Detaching the volume created in step2 from virtual machine + Step4: Listing snapshot policies for a volume created in step1 + Step5: Creating Monthly snapshot policy + Step6: Listing snapshot policies for a volume created in step1 again + Step7: Verifyign that the list snapshot policy length is increased by 1 + Step8: Deleting monthly snapshot policy created in step5 + Step9: List snapshot policies for a volume again + Step10: Verifying that the list snapshot policy length is decreased by 1 + """ + list_volumes_before = Volume.list(self.userapiclient, listall=self.services["listall"]) + + volume_created = Volume.create( + self.userapiclient, + self.services["volume"], + zoneid=self.zone.id, + diskofferingid=self.disk_offering.id + ) + self.assertIsNotNone(volume_created, "Volume not created") + self.cleanup.append(volume_created) + + list_volumes_after = Volume.list(self.userapiclient, listall=self.services["listall"]) + + self.assertEquals( + len(list_volumes_before) + 1, + len(list_volumes_after), + "Volume not created" + ) + # Attaching and Detaching custom volume created to Virtual Machine + self.virtual_machine.attach_volume( + self.userapiclient, + volume_created + ) + list_volumes = Volume.list( + self.userapiclient, + listall=self.services["listall"], + id=volume_created.id + ) + attached_volume = list_volumes[0] + + self.assertIsNotNone( + attached_volume.vmname, + "VM is not attached to Volume" + ) + self.assertEquals( + self.virtual_machine.name, + attached_volume.vmname, + "VM Name is not matching with attached vm" + ) + self.virtual_machine.detach_volume( + self.userapiclient, + volume_created + ) + list_volumes = Volume.list( + self.userapiclient, + listall=self.services["listall"], + id=volume_created.id + ) + detached_volume = list_volumes[0] + self.assertIsNone( + detached_volume.vmname, + "VM is not detached from volume" + ) + # Creating Monthly Snapshot Policy from volume + self.services["recurring_snapshot"]["intervaltype"] = 'monthly' + self.services["recurring_snapshot"]["schedule"] = '00:00:1' + + list_snapshot_policy_before = SnapshotPolicy.list(self.userapiclient, volumeid=volume_created.id) + + snapshot_policy_before_size = 0 + + if list_snapshot_policy_before is not None: + snapshot_policy_before_size = len(list_snapshot_policy_before) + + snapshot_policy_monthly = SnapshotPolicy.create( + self.userapiclient, + volume_created.id, + self.services["recurring_snapshot"]) + self.assertIsNotNone( + snapshot_policy_monthly, + "Monthly Snapshot policy creation failed" + ) + #Creating expected and actual values dictionaries + expected_dict = { + "schedule":self.services["recurring_snapshot"]["schedule"], + "intervaltype":3, + "volumeid":volume_created.id + } + actual_dict = { + "schedule":snapshot_policy_monthly.schedule, + "intervaltype":snapshot_policy_monthly.intervaltype, + "volumeid":snapshot_policy_monthly.volumeid + } + status = self.__verify_values( + expected_dict, + actual_dict + ) + self.assertEqual( + True, + status, + "Monthly Snapshot Policy details are not as expected" + ) + + list_snapshot_policy_after = SnapshotPolicy.list(self.userapiclient, volumeid=volume_created.id) + + self.assertIsNotNone( + list_snapshot_policy_after, + "Monthly Snapshot policy creation failed" + ) + self.assertEquals( + snapshot_policy_before_size + 1, + len(list_snapshot_policy_after), + "Monthly Snapshot policy creation failed" + ) + # Deleting monthly snapshot policy + SnapshotPolicy.delete(snapshot_policy_monthly, self.userapiclient) + + list_snapshot_policies = SnapshotPolicy.list(self.userapiclient, volumeid=volume_created.id) + + self.assertIsNone( + list_snapshot_policies, + "Deletion of Monthly Snapshot policy failed" + ) + return + + @attr(tags=["advanced", "basic", "provisioning"]) + def test_10_volume_snapshots_pagination(self): + """ + @summary: Test to verify pagination of snapshots for Volume + + Step1: Creating a Volume. + Step2: Attaching volume created in Step2 to virtual machine + Step3: Detaching the volume created in step2 from virtual machine + Step4: Listing all the snapshots for a volume + Step5: Creating Pagesize + 1 number of snapshots for a volume + Step6: Listing all the snapshots for a volume + Step7: Verifying that there are pagesize + 1 number of snapshots listsed + Step8: Listing all the snapshots in page 1 + Step9: Listing all the snapshots in page 2 + Step10: Deleting the snapshot present in page 2 + Step11: Listign the snapshots from page 2 again and verifyign that list returns none + """ + list_volumes_before = Volume.list(self.userapiclient, listall=self.services["listall"]) + + # Creating a Volume + volume_created = Volume.create( + self.userapiclient, + self.services["volume"], + zoneid=self.zone.id, + diskofferingid=self.disk_offering.id + ) + self.assertIsNotNone(volume_created, "Volume not created") + self.cleanup.append(volume_created) + + list_volumes_after = Volume.list(self.userapiclient, listall=self.services["listall"]) + + self.assertEquals( + len(list_volumes_before) + 1, + len(list_volumes_after), + "Volume not created" + ) + #Attaching volume to virtual machine + self.virtual_machine.attach_volume( + self.userapiclient, + volume_created + ) + list_volumes = Volume.list( + self.userapiclient, + listall=self.services["listall"], + id=volume_created.id + ) + attached_volume = list_volumes[0] + + self.assertIsNotNone( + attached_volume.vmname, + "VM is not attached to Volume" + ) + self.assertEquals( + self.virtual_machine.name, + attached_volume.vmname, + "VM Name is not matching with attached vm" + ) + #Detaching volume from virtual machine + self.virtual_machine.detach_volume( + self.userapiclient, + volume_created + ) + list_volumes = Volume.list( + self.userapiclient, + listall=self.services["listall"], + id=volume_created.id + ) + detached_volume = list_volumes[0] + self.assertIsNone( + detached_volume.vmname, + "VM is not detached from volume" + ) + + #Creating 3 Snapshots from volume + list_snapshot_before = Snapshot.list( + self.userapiclient, + volumeid=volume_created.id, + listall=self.services["listall"] + ) + self.assertIsNone( + list_snapshot_before, + "Newly created volume is already having snapshots" + ) + + list_snapshot_before_size = 0 + for i in range(0, 3): + snapshot_created = Snapshot.create( + self.userapiclient, + volume_created.id, + ) + self.assertIsNotNone(snapshot_created, "Snapshot not created") + self.cleanup.append(snapshot_created) + + self.assertEquals( + volume_created.id, + snapshot_created.volumeid, + "Snapshot not created for given volume" + ) + + list_snapshot_after = Snapshot.list( + self.userapiclient, + volumeid=volume_created.id, + listall=self.services["listall"] + ) + self.assertEqual( + list_snapshot_before_size+3, + len(list_snapshot_after), + "Number of snapshots created is not matching expected" + ) + #Listing all the snapshots in page1 + list_snapshots_page1 = Snapshot.list( + self.userapiclient, + volumeid=volume_created.id, + listall=self.services["listall"], + page=1, + pagesize=2 + ) + self.assertEqual( + 2, + len(list_snapshots_page1), + "List snapshots response is not matching with the page size length for page 1" + ) + + #Listing all the snapshots in page2 and ensuring only 1 snapshot is present + list_snapshots_page2 = Snapshot.list( + self.userapiclient, + volumeid=volume_created.id, + listall=self.services["listall"], + page=2, + pagesize=2 + ) + self.assertEqual( + len(list_snapshots_page2), + 1, + "List snapshots response is not matching with the page size length for page 2" + ) + snapshot_page2 = list_snapshots_page2[0] + + # Verifying that the snapshot on page 2 is not present in page1 + for i in range(0, len(list_snapshots_page1)): + snapshot_page1 = list_snapshots_page1[i] + self.assertNotEquals( + snapshot_page2.id, + snapshot_page1.id, + "Snapshot listed in page 2 is also listed in page 1" + ) + # Deleting a single snapshot and verifying that snapshot does not exists on page 2 + Snapshot.delete(snapshot_created, self.userapiclient) + + list_snapshot_page2 = Snapshot.list( + self.userapiclient, + volumeid=volume_created.id, + listall=self.services["listall"], + page=2, + pagesize=2 + ) + self.assertEqual( + None, + list_snapshot_page2, + "Snapshot was not deleted" + ) + list_snapshot_page1 = Snapshot.list( + self.userapiclient, + volumeid=volume_created.id, + listall=self.services["listall"], + page=1, + pagesize=2 + ) + self.assertEqual( + 2, + len(list_snapshot_page1), + "Snapshots on page 1 are not matching" + ) + return + + @attr(tags=["advanced", "basic", "provisioning"]) + def test_11_volume_extract(self): + """ + @summary: Test to verify extract/download a Volume + + Step1: Listing Volumes before creating a Volume + Step2: Creating a Volume. + Step3: Verifying that created volume is not none and adding to clean up + Step4: Listing the volumes after creation + Step5: Verifying that the list volume size is increased by 1 + Step6: Attaching volume created in Step2 to virtual machine + Step7: Detaching the volume created in step2 from virtual machine + Step8: Extracting/Downloadign the volume + Step9: Verifyign that a download URL is created for volume download + """ + list_volumes_before = Volume.list(self.userapiclient, listall=self.services["listall"]) + + self.assertIsNotNone( + list_volumes_before, + "volume not created for the vm launched at class level" + ) + volume_created = Volume.create( + self.userapiclient, + self.services["volume"], + zoneid=self.zone.id, + diskofferingid=self.disk_offering.id + ) + + self.assertIsNotNone(volume_created, "Volume not created") + self.cleanup.append(volume_created) + + list_volumes_after = Volume.list(self.userapiclient, listall=self.services["listall"]) + + self.assertIsNotNone( + list_volumes_after, + "volume creation failed" + ) + self.assertEquals( + len(list_volumes_before) + 1, + len(list_volumes_after), + "Volume not created" + ) + #Attaching and Detaching volume created to Virtual Machine + self.virtual_machine.attach_volume( + self.userapiclient, + volume_created + ) + list_volumes = Volume.list( + self.userapiclient, + listall=self.services["listall"], + id=volume_created.id + ) + attached_volume = list_volumes[0] + + self.assertIsNotNone( + attached_volume.vmname, + "VM is not attached to Volume" + ) + self.assertEquals( + self.virtual_machine.name, + attached_volume.vmname, + "VM Name is not matching with attached vm" + ) + self.virtual_machine.detach_volume( + self.userapiclient, + volume_created + ) + list_volumes = Volume.list( + self.userapiclient, + listall=self.services["listall"], + id=volume_created.id + ) + detached_volume = list_volumes[0] + self.assertIsNone( + detached_volume.vmname, + "VM is not detached from volume" + ) + #Extract/Download the volume + self.services["mode"] = "HTTP_DOWNLOAD" + + extract_volume_response = Volume.extract( + self.userapiclient, + volume_created.id, + self.zone.id, + self.services["mode"] + ) + self.assertIsNotNone(extract_volume_response, "Extract/Download volume failed") + + self.assertEquals( + "DOWNLOAD_URL_CREATED", + extract_volume_response.state, + "Failed to create Download URL" + ) + self.assertIsNotNone( + extract_volume_response.url, + "Extract/Download volume URL is NULL" + ) + self.assertTrue( + (extract_volume_response.url.find("https://")!=-1), + "Extract/Download volume URL doesnot contain https://" + ) + self.assertEquals( + volume_created.id, + extract_volume_response.id, + "Extracted/Downloaded volume is not matching with original volume" + ) + return + + @attr(tags=["advanced", "basic", "provisioning"]) + def test_12_volume_upload(self): + """ + @summary: Test to verify upload volume + + Step1: Listing the volumes for a user before uploading volume + Step2: Uploading a volume + Step3: Listing the volumes for a user after uploading data volume + Step4: Verifying that the list volume length after upload is increased by 1 + """ + list_volumes_before = Volume.list(self.userapiclient, listall=self.services["listall"]) + + self.assertIsNotNone( + list_volumes_before, + "volume not created for the vm launched at class level" + ) + #Uploading a Volume + volume_uploaded = Volume.upload( + self.userapiclient, + self.services["upload_volume"], + self.zone.id + ) + self.assertIsNotNone(volume_uploaded, "volume uploading failed") + + self.assertEquals( + self.services["upload_volume"]["diskname"], + volume_uploaded.name, + "Uploaded volume name is not matching with name provided while uploading") + + #Listing the volumes for a user after uploading data volume + list_volumes_after = Volume.list(self.userapiclient, listall=self.services["listall"]) + + self.assertIsNotNone( + list_volumes_after, + "volume not created for the vm launched at class level" + ) + #Asserting that the list volume length after upload is increased by 1 + self.assertEquals( + len(list_volumes_before) + 1, + len(list_volumes_after), + "upload volume failed" + ) + return + +class TestListInstances(cloudstackTestCase): + + @classmethod + def setUpClass(cls): + try: + cls._cleanup = [] + cls.testClient = super(TestListInstances, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = cls.testClient.getParsedTestDataConfig() + + # Get Domain, Zone, Template + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client) + cls.template = get_template( + cls.api_client, + cls.zone.id, + cls.services["ostype"] + ) + if cls.zone.localstorageenabled: + cls.storagetype = 'local' + cls.services["service_offerings"]["tiny"]["storagetype"] = 'local' + cls.services["disk_offering"]["storagetype"] = 'local' + else: + cls.storagetype = 'shared' + cls.services["service_offerings"]["tiny"]["storagetype"] = 'shared' + cls.services["disk_offering"]["storagetype"] = 'shared' + + cls.services['mode'] = cls.zone.networktype + cls.services["virtual_machine"]["hypervisor"] = cls.testClient.getHypervisorInfo() + cls.services["virtual_machine"]["zoneid"] = cls.zone.id + cls.services["virtual_machine"]["template"] = cls.template.id + cls.services["custom_volume"]["zoneid"] = cls.zone.id + + # Creating Disk offering, Service Offering and Account + cls.disk_offering = DiskOffering.create( + cls.api_client, + cls.services["disk_offering"] + ) + cls._cleanup.append(cls.disk_offering) + cls.service_offering = ServiceOffering.create( + cls.api_client, + cls.services["service_offerings"]["tiny"] + ) + cls._cleanup.append(cls.service_offering) + cls.account = Account.create( + cls.api_client, + cls.services["account"], + domainid=cls.domain.id + ) + # Getting authentication for user in newly created Account + cls.user = cls.account.user[0] + cls.userapiclient = cls.testClient.getUserApiClient(cls.user.username, cls.domain.name) + # Updating resource Limits + for i in range(0,12): + Resources.updateLimit( + cls.api_client, + account=cls.account.name, + domainid=cls.domain.id, + max=-1, + resourcetype=i + ) + + cls._cleanup.append(cls.account) + except Exception as e: + cls.tearDownClass() + raise Exception("Warning: Exception in setup : %s" % e) + return + + def setUp(self): + + self.apiClient = self.testClient.getApiClient() + self.cleanup = [] + + def tearDown(self): + #Clean up, terminate the created resources + cleanup_resources(self.apiClient, self.cleanup) + return + + @classmethod + def tearDownClass(cls): + try: + cleanup_resources(cls.api_client, cls._cleanup) + except Exception as e: + raise Exception("Warning: Exception during cleanup : %s" % e) + + return + + def __verify_values(self, expected_vals, actual_vals): + """ + @Desc: Function to verify expected and actual values + @Steps: + Step1: Initializing return flag to True + Step1: Verifying length of expected and actual dictionaries is matching. + If not matching returning false + Step2: Listing all the keys from expected dictionary + Step3: Looping through each key from step2 and verifying expected and actual dictionaries have same value + If not making return flag to False + Step4: returning the return flag after all the values are verified + """ + return_flag = True + + if len(expected_vals) != len(actual_vals): + return False + + keys = expected_vals.keys() + for i in range(0, len(expected_vals)): + exp_val = expected_vals[keys[i]] + act_val = actual_vals[keys[i]] + if exp_val == act_val: + return_flag = return_flag and True + else: + return_flag = return_flag and False + self.debug("expected Value: %s, is not matching with actual value: %s" % ( + exp_val, + act_val + )) + return return_flag + + @attr(tags=["advanced", "basic", "selfservice"]) + def test_01_list_instances_pagination(self): + """ + @Desc: Test List Instances pagination + @Steps: + Step1: Listing all the Instances for a user + Step2: Verifying listed Instances for account created at class level + Step3: If number of volumes is less than (page size + 1), then creating them + Step4: Listing all the volumes again after creation of volumes + Step5: Verifying the length of the volumes is (page size + 1) + Step6: Listing all the volumes in page1 + Step7: Verifying that the length of the volumes in page 1 is (page size) + Step8: Listing all the volumes in page2 + Step9: Verifying that the length of the volumes in page 2 is 1 + Step10: Deleting the volume present in page 2 + Step11: Listing for the volumes on page 2 + Step12: Verifying that there are no volumes present in page 2 + """ + # Listing all the instances for a user + list_instances_before = VirtualMachine.list(self.userapiclient, listall=self.services["listall"]) + + # Verifying listed instances for account created at class level + self.assertIsNone( + list_instances_before, + "Virtual Machine already exists for newly created user" + ) + # If number of instances are less than (pagesize + 1), then creating them + for i in range(0, (self.services["pagesize"] + 1)): + vm_created = VirtualMachine.create( + self.userapiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + ) + self.assertIsNotNone( + vm_created, + "VM creation failed" + ) + if(i < (self.services["pagesize"])): + self.cleanup.append(vm_created) + + self.assertEqual( + self.services["virtual_machine"]["displayname"], + vm_created.displayname, + "Newly created VM name and the test data VM name are not matching" + ) + + # Listing all the instances again after creating VM's + list_instances_after = VirtualMachine.list(self.userapiclient, listall=self.services["listall"]) + status = validateList(list_instances_after) + self.assertEquals( + PASS, + status[0], + "Listing of instances after creation failed" + ) + # Verifying the length of the instances is (page size + 1) + self.assertEqual( + len(list_instances_after), + (self.services["pagesize"] + 1), + "Number of instances created is not matching as expected" + ) + + # Listing all the volumes in page1 + list_instances_page1 = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid + ) + status = validateList(list_instances_page1) + self.assertEquals( + PASS, + status[0], + "Listing of instances in page1 failed" + ) + # Verifying that the length of the instances in page 1 is (page size) + self.assertEqual( + self.services["pagesize"], + len(list_instances_page1), + "List VM response is not matching with the page size length for page 1" + ) + + # Listing all the VM's in page2 + list_instances_page2 = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + page=2, + pagesize=self.services["pagesize"], + domainid=self.account.domainid + ) + status = validateList(list_instances_page2) + self.assertEquals( + PASS, + status[0], + "Listing of instances in page2 failed" + ) + # Verifying that the length of the VM's in page 2 is 1 + self.assertEqual( + 1, + len(list_instances_page2), + "List VM response is not matching with the page size length for page 2" + ) + instance_page2 = list_instances_page2[0] + + # Verifying that the VM on page 2 is not present in page1 + for i in range(0, len(list_instances_page1)): + instance_page1 = list_instances_page1[i] + self.assertNotEquals( + instance_page2.id, + instance_page1.id, + "VM listed in page 2 is also listed in page 1" + ) + + # Deleting a single VM + VirtualMachine.delete(vm_created, self.userapiclient) + + # Listing the VM's in page 2 + list_instance_response = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + page=2, + pagesize=self.services["pagesize"], + domainid=self.account.domainid + ) + # verifying that VM does not exists on page 2 + self.assertEqual( + list_instance_response, + None, + "VM was not deleted" + ) + return + + @attr(tags=["advanced", "basic", "selfservice"]) + def test_02_list_Running_vm(self): + """ + @Desc: Test List Running VM's + @Steps: + Step1: Listing all the Running VMs for a user + Step2: Verifying that the size of the list is 0 + Step3: Deploying a VM + Step4: Listing all the Running VMs for a user again + Step5: Verifying that the size of the list is increased by 1 + Step6: Verifying that the details of the Running VM listed are same as the VM deployed in Step3 + """ + # Listing all the Running VM's for a User + list_running_vms_before = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + state="Running" + ) + self.assertIsNone( + list_running_vms_before, + "Virtual Machine already exists for newly created user" + ) + # Deploying a VM + vm_created = VirtualMachine.create( + self.userapiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + ) + self.assertIsNotNone( + vm_created, + "VM creation failed" + ) + self.cleanup.append(vm_created) + # Listing all the Running VM's for a User + list_running_vms_after = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + state="Running" + ) + status = validateList(list_running_vms_after) + self.assertEquals( + PASS, + status[0], + "Newly created VM is not in Running state" + ) + # Verifying list size is 1 + self.assertEquals( + 1, + len(list_running_vms_after), + "Running VM list count is not matching" + ) + running_vm = list_running_vms_after[0] + + #Creating expected and actual values dictionaries + expected_dict = { + "id":vm_created.id, + "name":vm_created.name, + "displayname":vm_created.displayname, + "state":"Running", + "zoneid":vm_created.zoneid, + "account":vm_created.account, + "template":vm_created.templateid + } + actual_dict = { + "id":running_vm.id, + "name":running_vm.name, + "displayname":running_vm.displayname, + "state":running_vm.state, + "zoneid":running_vm.zoneid, + "account":running_vm.account, + "template":running_vm.templateid + } + running_vm_status = self.__verify_values( + expected_dict, + actual_dict + ) + self.assertEqual( + True, + running_vm_status, + "Listed Running VM details are not as expected" + ) + return + + @attr(tags=["advanced", "basic", "selfservice"]) + def test_03_list_Stopped_vm(self): + """ + @Desc: Test List Stopped VM's + @Steps: + Step1: Listing all the Stopped VMs for a user + Step2: Verifying that the size of the list is 0 + Step3: Deploying a VM + Step4: Stopping the VM deployed in step3 + Step5: Listing all the Stopped VMs for a user again + Step6: Verifying that the size of the list is increased by 1 + Step7: Verifying that the details of the Stopped VM listed are same as the VM stopped in Step4 + """ + # Listing all the Stopped VM's for a User + list_stopped_vms_before = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + state="Stopped" + ) + self.assertIsNone( + list_stopped_vms_before, + "Virtual Machine already exists for newly created user" + ) + # Deploying a VM + vm_created = VirtualMachine.create( + self.userapiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + ) + self.assertIsNotNone( + vm_created, + "VM creation failed" + ) + self.cleanup.append(vm_created) + # Stopping the VM + VirtualMachine.stop(vm_created, self.userapiclient) + # Listing all the Stopped VM's for a User + list_stopped_vms_after = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + state="Stopped" + ) + status = validateList(list_stopped_vms_after) + self.assertEquals( + PASS, + status[0], + "Stopped VM is not in Stopped state" + ) + # Verifying list size is 1 + self.assertEquals( + 1, + len(list_stopped_vms_after), + "Stopped VM list count is not matching" + ) + stopped_vm = list_stopped_vms_after[0] + #Creating expected and actual values dictionaries + expected_dict = { + "id":vm_created.id, + "name":vm_created.name, + "displayname":vm_created.displayname, + "state":"Stopped", + "zoneid":vm_created.zoneid, + "account":vm_created.account, + "template":vm_created.templateid + } + actual_dict = { + "id":stopped_vm.id, + "name":stopped_vm.name, + "displayname":stopped_vm.displayname, + "state":stopped_vm.state, + "zoneid":stopped_vm.zoneid, + "account":stopped_vm.account, + "template":stopped_vm.templateid + } + stopped_vm_status = self.__verify_values( + expected_dict, + actual_dict + ) + self.assertEqual( + True, + stopped_vm_status, + "Listed Stopped VM details are not as expected" + ) + return + + @attr(tags=["advanced", "basic", "selfservice"]) + def test_04_list_Destroyed_vm(self): + """ + @Desc: Test List Destroyed VM's + @Steps: + Step1: Listing all the Destroyed VMs for a user + Step2: Verifying that the size of the list is 0 + Step3: Deploying a VM + Step4: Destroyed the VM deployed in step3 + Step5: Listing all the Destroyed VMs for a user again + Step6: Verifying that destroyed VM is not listed for User + Step7: Listing all the destroyed VMs as admin + Step8: Verifying that the size of the list is 1 + Step9: Verifying that the details of the Destroyed VM listed are same as the VM destroyed in Step4 + """ + # Listing all the Destroyed VM's for a User + list_destroyed_vms_before = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + state="Destroyed" + ) + self.assertIsNone( + list_destroyed_vms_before, + "Virtual Machine in Destroyed state already exists for newly created user" + ) + # Deploying a VM + vm_created = VirtualMachine.create( + self.userapiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + ) + self.assertIsNotNone( + vm_created, + "VM creation failed" + ) + # Destroying the VM + VirtualMachine.delete(vm_created, self.userapiclient) + # Listing all the Destroyed VM's for a User + list_destroyed_vms_after = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + state="Destroyed" + ) + self.assertIsNone( + list_destroyed_vms_after, + "Destroyed VM is not in destroyed state" + ) + # Listing destroyed VMs as admin user + list_destroyed_vms_admin = VirtualMachine.list( + self.apiClient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + state="Destroyed", + id=vm_created.id + ) + status = validateList(list_destroyed_vms_admin) + self.assertEquals( + PASS, + status[0], + "Destroyed VM is not in Destroyed state" + ) + # Verifying that the length of the destroyed VMs list should be 1 + self.assertEquals( + 1, + len(list_destroyed_vms_admin), + "Destroyed VM list count is not matching" + ) + destroyed_vm = list_destroyed_vms_admin[0] + #Creating expected and actual values dictionaries + expected_dict = { + "id":vm_created.id, + "name":vm_created.name, + "displayname":vm_created.displayname, + "state":"Destroyed", + "zoneid":vm_created.zoneid, + "account":vm_created.account, + "template":vm_created.templateid + } + actual_dict = { + "id":destroyed_vm.id, + "name":destroyed_vm.name, + "displayname":destroyed_vm.displayname, + "state":destroyed_vm.state, + "zoneid":destroyed_vm.zoneid, + "account":destroyed_vm.account, + "template":destroyed_vm.templateid + } + destroyed_vm_status = self.__verify_values( + expected_dict, + actual_dict + ) + self.assertEqual( + True, + destroyed_vm_status, + "Listed Destroyed VM details are not as expected" + ) + return + + @attr(tags=["advanced", "basic", "selfservice"]) + def test_05_list_vm_by_id(self): + """ + @Desc: Test List VM by Id + @Steps: + Step1: Listing all the VMs for a user + Step2: Verifying that the size of the list is 0 + Step3: Deploying a VM + Step4: Listing all the VMs for a user again + Step5: Verifying that the size of the list is increased by 1 + Step6: List a VM by specifying the Id if the VM deployed in Step3 + Step7: Verifying that the details of the Listed VM are same as the VM deployed in Step3 + """ + # Listing all the VM's for a User + list_vms_before = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + account=self.account.name + ) + self.assertIsNone( + list_vms_before, + "Virtual Machine already exists for newly created user" + ) + # Deploying a VM + vm_created = VirtualMachine.create( + self.userapiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + ) + self.assertIsNotNone( + vm_created, + "VM creation failed" + ) + self.cleanup.append(vm_created) + # Listing all the VM's for a User + list_vms_after = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + account=self.account.name + ) + status = validateList(list_vms_after) + self.assertEquals( + PASS, + status[0], + "Listing of VM after creation failed" + ) + self.assertEquals( + 1, + len(list_vms_after), + "VM list count is not matching" + ) + # Listing a VM by Id + list_vm_byid = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + id=vm_created.id + ) + status = validateList(list_vm_byid) + self.assertEquals( + PASS, + status[0], + "Listing of VM by Id failed" + ) + listed_vm = list_vm_byid[0] + #Creating expected and actual values dictionaries + expected_dict = { + "id":vm_created.id, + "name":vm_created.name, + "displayname":vm_created.displayname, + "state":vm_created.state, + "zoneid":vm_created.zoneid, + "account":vm_created.account, + "template":vm_created.templateid + } + actual_dict = { + "id":listed_vm.id, + "name":listed_vm.name, + "displayname":listed_vm.displayname, + "state":listed_vm.state, + "zoneid":listed_vm.zoneid, + "account":listed_vm.account, + "template":listed_vm.templateid + } + list_vm_status = self.__verify_values( + expected_dict, + actual_dict + ) + self.assertEqual( + True, + list_vm_status, + "Listed VM by Id details are not as expected" + ) + return + + @attr(tags=["advanced", "basic", "selfservice"]) + def test_06_list_vm_by_name(self): + """ + @Desc: Test List VM's by Name + @Steps: + Step1: Listing all the VMs for a user + Step2: Verifying that the size of the list is 0 + Step3: Deploying a 2 VM's + Step4: Listing all the VMs for a user again + Step5: Verifying that list size is increased by 2 + Step6: Listing the VM by specifying complete name of VM-1 created in step3 + Step7: Verifying that the size of the list is 1 + Step8: Verifying that the details of the listed VM are same as the VM-1 created in step3 + Step9: Listing the VM by specifying the partial name of VM + Step10: Verifying that the size of the list is 2 + """ + # Listing all the VM's for a User + list_vms_before = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + ) + self.assertIsNone( + list_vms_before, + "Virtual Machine already exists for newly created user" + ) + vms = {} + for i in range(0, 2): + # Deploying a VM + vm_created = VirtualMachine.create( + self.userapiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + ) + self.assertIsNotNone( + vm_created, + "VM creation failed" + ) + self.cleanup.append(vm_created) + vms.update({i: vm_created}) + + # Listing all the VM's for a User + list_vms_after = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + ) + status = validateList(list_vms_after) + self.assertEquals( + PASS, + status[0], + "VM's creation failed" + ) + self.assertEquals( + 2, + len(list_vms_after), + "VM's list count is not matching" + ) + # Listing the VM by complete name + list_vm_byfullname = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + name=vms[0].name + ) + status = validateList(list_vm_byfullname) + self.assertEquals( + PASS, + status[0], + "Failed to list VM by Name" + ) + # Verifying that the size of the list is 1 + self.assertEquals( + 1, + len(list_vm_byfullname), + "VM list by full name count is not matching" + ) + # Verifying that the details of the listed VM are same as the VM created above + #Creating expected and actual values dictionaries + expected_dict = { + "id":vms[0].id, + "name":vms[0].name, + "displayname":vms[0].displayname, + "state":vms[0].state, + "zoneid":vms[0].zoneid, + "account":vms[0].account, + "template":vms[0].templateid + } + actual_dict = { + "id":list_vm_byfullname[0].id, + "name":list_vm_byfullname[0].name, + "displayname":list_vm_byfullname[0].displayname, + "state":list_vm_byfullname[0].state, + "zoneid":list_vm_byfullname[0].zoneid, + "account":list_vm_byfullname[0].account, + "template":list_vm_byfullname[0].templateid + } + list_vm_status = self.__verify_values( + expected_dict, + actual_dict + ) + self.assertEqual( + True, + list_vm_status, + "Listed VM details are not as expected" + ) + # Listing the VM by partial name + list_vm_bypartialname = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + domainid=self.account.domainid, + name=vms[0].name[:1] + ) + status = validateList(list_vm_bypartialname) + self.assertEquals( + PASS, + status[0], + "Failed to list VM by Name" + ) + # Verifying that the size of the list is 2 + self.assertEquals( + 2, + len(list_vm_bypartialname), + "VM list by full name count is not matching" + ) + return + + @attr(tags=["advanced", "basic", "selfservice"]) + def test_07_list_vm_by_name_state(self): + """ + @Desc: Test List VM's by Name and State + @Steps: + Step1: Listing all the VMs for a user + Step2: Verifying that the size of the list is 0 + Step3: Deploying a VM + Step4: Listing all the VMs for a user again + Step5: Verifying that list size is increased by 1 + Step6: Listing the VM by specifying name of VM created in step3 and state as Running (matching name and state) + Step7: Verifying that the size of the list is 1 + Step8: Verifying that the details of the listed VM are same as the VM created in step3 + Step9: Listing the VM by specifying name of VM created in step3 and state as Stopped (non matching state) + Step10: Verifying that the size of the list is 0 + Step11: Listing the VM by specifying non matching name and state as Running (non matching name) + Step12: Verifying that the size of the list is 0 + """ + # Listing all the VM's for a User + list_vms_before = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + ) + self.assertIsNone( + list_vms_before, + "Virtual Machine already exists for newly created user" + ) + # Deploying a VM + vm_created = VirtualMachine.create( + self.userapiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + ) + self.assertIsNotNone( + vm_created, + "VM creation failed" + ) + self.cleanup.append(vm_created) + # Listing all the VM's for a User + list_vms_after = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + ) + status = validateList(list_vms_after) + self.assertEquals( + PASS, + status[0], + "VM's creation failed" + ) + self.assertEquals( + 1, + len(list_vms_after), + "VM's list count is not matching" + ) + # Listing the VM by matching Name and State + list_running_vm = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + name=vm_created.name, + state="Running" + ) + status = validateList(list_running_vm) + self.assertEquals( + PASS, + status[0], + "List VM by name and state failed" + ) + # Verifying that the size of the list is 1 + self.assertEquals( + 1, + len(list_running_vm), + "Count of VM list by name and state is not matching" + ) + # Verifying that the details of the listed VM are same as the VM created above + #Creating expected and actual values dictionaries + expected_dict = { + "id":vm_created.id, + "name":vm_created.name, + "displayname":vm_created.displayname, + "state":"Running", + "zoneid":vm_created.zoneid, + "account":vm_created.account, + "template":vm_created.templateid + } + actual_dict = { + "id":list_running_vm[0].id, + "name":list_running_vm[0].name, + "displayname":list_running_vm[0].displayname, + "state":list_running_vm[0].state, + "zoneid":list_running_vm[0].zoneid, + "account":list_running_vm[0].account, + "template":list_running_vm[0].templateid + } + list_vm_status = self.__verify_values( + expected_dict, + actual_dict + ) + self.assertEqual( + True, + list_vm_status, + "Listed VM details are not as expected" + ) + # Listing the VM by matching name and non matching state + list_running_vm = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + name=vm_created.name, + state="Stopped" + ) + self.assertIsNone( + list_running_vm, + "Listed VM with non matching state" + ) + # Listing the VM by non matching name and matching state + list_running_vm = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + name="name", + state="Running" + ) + self.assertIsNone( + list_running_vm, + "Listed VM with non matching name" + ) + return + + @attr(tags=["advanced", "basic", "selfservice"]) + def test_08_list_vm_by_zone(self): + """ + @Desc: Test List VM by Zone. + This test case is applicable for a setup having multiple zones. + @Steps: + Step1: Listing all the zones + Step2: Checking if there are multiple zones in the setup. + Continuing below steps only if there are multiple zones + Step3: Listing template for zone + Step4: Listing all the VMs for a user + Step5: Verifying that the size of the list is 0 + Step6: Deploying a VM + Step7: Listing all the VMs for a user again for matching zone + Step8: Verifying that the size of the list is 1 + Step9: Verifying that the details of the Listed VM are same as the VM deployed in Step6 + Step10: Listing all the VMs for a user again for non-matching zone + Step11: Verifying that the size of the list is 0 + """ + # Listing all the zones available + zones_list = Zone.list(self.apiClient) + status = validateList(zones_list) + self.assertEquals( + PASS, + status[0], + "zones not available in the given setup" + ) + current_zone = self.services["virtual_machine"]["zoneid"] + current_template = self.services["virtual_machine"]["template"] + # Checking if there are multiple zones in the setup. + if not len(zones_list) > 1: + self.debug("Setup is not having multiple zones") + else: + # Getting the template available under the zone + template = get_template( + self.apiClient, + zones_list[0].id, + self.services["ostype"] + ) + self.assertIsNotNone( + template, + "Template not found for zone" + ) + self.services["virtual_machine"]["zoneid"] = zones_list[0].id + self.services["virtual_machine"]["template"] = template.id + # Listing all the VM's for a User + list_vms_before = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + zoneid=zones_list[0].id + ) + self.assertIsNone( + list_vms_before, + "Virtual Machine already exists for newly created user" + ) + # Deploying a VM + vm_created = VirtualMachine.create( + self.userapiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + ) + self.assertIsNotNone( + vm_created, + "VM creation failed" + ) + self.cleanup.append(vm_created) + # Listing all the VMs for a user again for matching zone + list_vms_after = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + zoneid=zones_list[0].id + ) + status = validateList(list_vms_after) + self.assertEquals( + PASS, + status[0], + "VM creation failed" + ) + # Verifying that the size of the list is 1 + self.assertEquals( + 1, + len(list_vms_after), + "VM list count is not matching" + ) + listed_vm = list_vms_after[0] + # Verifying that the details of the Listed VM are same as the VM deployed above + #Creating expected and actual values dictionaries + expected_dict = { + "id":vm_created.id, + "name":vm_created.name, + "displayname":vm_created.displayname, + "state":vm_created.state, + "zoneid":vm_created.zoneid, + "account":vm_created.account, + "template":vm_created.templateid + } + actual_dict = { + "id":listed_vm.id, + "name":listed_vm.name, + "displayname":listed_vm.displayname, + "state":listed_vm.state, + "zoneid":listed_vm.zoneid, + "account":listed_vm.account, + "template":listed_vm.templateid + } + list_vm_status = self.__verify_values( + expected_dict, + actual_dict + ) + self.assertEqual( + True, + list_vm_status, + "Listed VM by Id details are not as expected" + ) + # Listing all the VMs for a user again for non-matching zone + list_vms = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + zoneid=zones_list[1].id + ) + self.assertIsNone( + list_vms, + "VM's listed for non matching zone" + ) + self.services["virtual_machine"]["zoneid"] = current_zone + self.services["virtual_machine"]["template"] = current_template + return + + @attr(tags=["advanced", "basic", "selfservice"]) + def test_09_list_vm_by_zone_name(self): + """ + @Desc: Test List VM by Zone. + This test case is applicable for a setup having multiple zones. + @Steps: + Step1: Listing all the zones + Step2: Checking if there are multiple zones in the setup. + Continuing below steps only if there are multiple zones + Step3: Listing template for zone + Step4: Listing all the VMs for a user + Step5: Verifying that the size of the list is 0 + Step6: Deploying a VM + Step7: Listing all the VMs for a user again + Step8: Verifying that list size is increased by 1 + Step9: Listing the VM by specifying name of VM created in step6 and matching zone (matching name and zone) + Step10: Verifying that the size of the list is 1 + Step11: Verifying that the details of the listed VM are same as the VM created in step3 + Step12: Listing the VM by specifying name of VM created in step6 and non matching zone (non matching zone) + Step13: Verifying that the size of the list is 0 + Step14: Listing the VM by specifying non matching name and matching zone (non matching name) + Step15: Verifying that the size of the list is 0 + """ + # Listing all the zones available + zones_list = Zone.list(self.apiClient) + status = validateList(zones_list) + self.assertEquals( + PASS, + status[0], + "zones not available in the given setup" + ) + current_zone = self.services["virtual_machine"]["zoneid"] + current_template = self.services["virtual_machine"]["template"] + # Checking if there are multiple zones in the setup. + if not len(zones_list) > 1: + self.debug("Setup is not having multiple Zones") + else: + # Getting the template available under the zone + template = get_template( + self.apiClient, + zones_list[0].id, + self.services["ostype"] + ) + self.assertIsNotNone( + template, + "Template not found for zone" + ) + self.services["virtual_machine"]["zoneid"] = zones_list[0].id + self.services["virtual_machine"]["template"] = template.id + # Listing all the VM's for a User + list_vms_before = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + zoneid=zones_list[0].id, + account=self.account.name + ) + self.assertIsNone( + list_vms_before, + "Virtual Machine already exists for newly created user" + ) + # Deploying a VM + vm_created = VirtualMachine.create( + self.userapiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + ) + self.assertIsNotNone( + vm_created, + "VM creation failed" + ) + self.cleanup.append(vm_created) + # Listing all the VMs for a user again for matching zone + list_vms_after = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + zoneid=zones_list[0].id, + account=self.account.name + ) + status = validateList(list_vms_after) + self.assertEquals( + PASS, + status[0], + "VM creation failed" + ) + # Verifying that the size of the list is 1 + self.assertEquals( + 1, + len(list_vms_after), + "VM list count is not matching" + ) + # Listing the VM by specifying name of VM created in above and matching zone + list_vms = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + zoneid=zones_list[0].id, + name=vm_created.name + ) + status = validateList(list_vms) + self.assertEquals( + PASS, + status[0], + "Listing VM's by name and zone failed" + ) + # Verifying Verifying that the size of the list is 1 + self.assertEquals( + 1, + len(list_vms), + "Count of listed VM's by name and zone is not as expected" + ) + listed_vm = list_vms[0] + # Verifying that the details of the Listed VM are same as the VM deployed above + #Creating expected and actual values dictionaries + expected_dict = { + "id":vm_created.id, + "name":vm_created.name, + "displayname":vm_created.displayname, + "state":vm_created.state, + "zoneid":vm_created.zoneid, + "account":vm_created.account, + "template":vm_created.templateid + } + actual_dict = { + "id":listed_vm.id, + "name":listed_vm.name, + "displayname":listed_vm.displayname, + "state":listed_vm.state, + "zoneid":listed_vm.zoneid, + "account":listed_vm.account, + "template":listed_vm.templateid + } + list_vm_status = self.__verify_values( + expected_dict, + actual_dict + ) + self.assertEqual( + True, + list_vm_status, + "Listed VM by Id details are not as expected" + ) + # Listing the VM by specifying name of VM created in step3 and non matching zone + list_vms = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + zoneid=zones_list[1].id, + name=vm_created.name + ) + self.assertIsNone( + list_vms, + "VM's listed for non matching zone" + ) + # Listing the VM by specifying non matching name of VM and matching zone + list_vms = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + zoneid=zones_list[0].id, + name="name" + ) + self.assertIsNone( + list_vms, + "VM's listed for non matching zone" + ) + self.services["virtual_machine"]["zoneid"] = current_zone + self.services["virtual_machine"]["template"] = current_template + return + + @attr(tags=["advanced", "basic", "selfservice"]) + def test_10_list_vm_by_zone_name_state(self): + """ + @Desc: Test List VM by Zone. + @Steps: + Step1: Listing all the VMs for a user + Step2: Verifying that the size of the list is 0 + Step3: Deploying a VM + Step4: Listing all the VMs for a user again + Step5: Verifying that list size is increased by 1 + Step6: Listing the VM by specifying name of VM created in step3 and matching zone and state as Running + Step7: Verifying that the size of the list is 1 + Step8: Verifying that the details of the listed VM are same as the VM created in step3 + Step9: Listing the VM by specifying name of VM created in step3 and matching zone and state as Stopped + Step10: Verifying that the size of the list is 0 + Step11: Listing the VM by name, Zone and account + Step12: Verifying that the size of the list is 1 + Step13: Verifying that the details of the listed VM are same as the VM created in step3 + """ + # Listing all the VM's for a User + list_vms_before = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + zoneid=self.zone.id, + account=self.account.name + ) + self.assertIsNone( + list_vms_before, + "Virtual Machine already exists for newly created user" + ) + # Deploying a VM + vm_created = VirtualMachine.create( + self.userapiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + ) + self.assertIsNotNone( + vm_created, + "VM creation failed" + ) + self.cleanup.append(vm_created) + # Listing all the VMs for a user again for matching zone + list_vms_after = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + zoneid=self.zone.id, + account=self.account.name + ) + status = validateList(list_vms_after) + self.assertEquals( + PASS, + status[0], + "VM creation failed" + ) + # Verifying that the size of the list is 1 + self.assertEquals( + 1, + len(list_vms_after), + "VM list count is not matching" + ) + # Listing the VM by specifying name of VM created in step3 and matching zone and state as Running + list_vms = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + zoneid=self.zone.id, + name=vm_created.name, + state="Running" + ) + status = validateList(list_vms) + self.assertEquals( + PASS, + status[0], + "Listing VM's by name and zone failed" + ) + # Verifying Verifying that the size of the list is 1 + self.assertEquals( + 1, + len(list_vms), + "Count of listed VM's by name, zone and state is not as expected" + ) + listed_vm = list_vms[0] + # Verifying that the details of the Listed VM are same as the VM deployed above + #Creating expected and actual values dictionaries + expected_dict = { + "id":vm_created.id, + "name":vm_created.name, + "displayname":vm_created.displayname, + "state":vm_created.state, + "zoneid":vm_created.zoneid, + "account":vm_created.account, + "template":vm_created.templateid + } + actual_dict = { + "id":listed_vm.id, + "name":listed_vm.name, + "displayname":listed_vm.displayname, + "state":listed_vm.state, + "zoneid":listed_vm.zoneid, + "account":listed_vm.account, + "template":listed_vm.templateid + } + list_vm_status = self.__verify_values( + expected_dict, + actual_dict + ) + self.assertEqual( + True, + list_vm_status, + "Listed VM by Id details are not as expected" + ) + # Listing the VM by specifying name of VM created in step3, zone and State as Stopped + list_vms = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + zoneid=self.zone.id, + name=vm_created.name, + state="Stopped" + ) + self.assertIsNone( + list_vms, + "VM's listed for non matching zone" + ) + # Listing the VM by name, zone and account + list_vms = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + zoneid=self.zone.id, + name=vm_created.name, + account=self.account.name + ) + status = validateList(list_vms) + self.assertEquals( + PASS, + status[0], + "Listing VM's by name, account and zone failed" + ) + # Verifying Verifying that the size of the list is 1 + self.assertEquals( + 1, + len(list_vms), + "Count of listed VM's by name, zone and account is not as expected" + ) + listed_vm = list_vms[0] + # Verifying that the details of the Listed VM are same as the VM deployed above + #Creating expected and actual values dictionaries + expected_dict = { + "id":vm_created.id, + "name":vm_created.name, + "displayname":vm_created.displayname, + "state":vm_created.state, + "zoneid":vm_created.zoneid, + "account":vm_created.account, + "template":vm_created.templateid + } + actual_dict = { + "id":listed_vm.id, + "name":listed_vm.name, + "displayname":listed_vm.displayname, + "state":listed_vm.state, + "zoneid":listed_vm.zoneid, + "account":listed_vm.account, + "template":listed_vm.templateid + } + list_vm_status = self.__verify_values( + expected_dict, + actual_dict + ) + self.assertEqual( + True, + list_vm_status, + "Listed VM by Id details are not as expected" + ) + return + + @attr(tags=["advanced", "basic", "provisioning"]) + def test_11_register_reset_vm_sshkey(self): + """ + @Desc: Test to verify registering and reset of SSH Key for VM + @Steps: + Step1: Deploying a VM + Step2: Stopping the VM deployed in step1 + Step3: Listing all the SSH Key pairs + Step4: Registering a SSH Key pair + Step5: Listing all the SSh Key pairs again + Step6: Verifying that the key pairs list is increased by 1 + Step7: Resetting the VM SSH Key to the key pair registered in step4 + Step8: Verifying that the registered SSH Key pair is set to the VM + """ + # Listing all the VM's for a User + list_vms_before = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + ) + self.assertIsNone( + list_vms_before, + "Virtual Machine already exists for newly created user" + ) + # Deploying a VM + vm_created = VirtualMachine.create( + self.userapiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + ) + self.assertIsNotNone( + vm_created, + "VM creation failed" + ) + self.cleanup.append(vm_created) + # Listing all the VMs for a user again + list_vms_after = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + ) + status = validateList(list_vms_after) + self.assertEquals( + PASS, + status[0], + "VM creation failed" + ) + # Verifying that the size of the list is 1 + self.assertEquals( + 1, + len(list_vms_after), + "VM list count is not matching" + ) + # Stopping the VM deployed above + vm_created.stop( + self.userapiclient, + 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 + list_keypairs_before = SSHKeyPair.list( + self.userapiclient + ) + list_keypairs_before_size = 0 + if list_keypairs_before is not None: + list_keypairs_before_size = len(list_keypairs_before) + + # Registering new Key pair + new_keypair = SSHKeyPair.register( + self.userapiclient, + name="keypair1", + publickey="ssh-rsa: e6:9a:1e:b5:98:75:88:5d:56:bc:92:7b:43:48:05:b2" + ) + self.assertIsNotNone( + new_keypair, + "New Key pair generation failed" + ) + self.assertEquals( + "keypair1", + new_keypair.name, + "Key Pair not created with given name" + ) + # Listing all the SSH Key pairs again + list_keypairs_after = SSHKeyPair.list( + self.userapiclient + ) + status = validateList(list_keypairs_after) + self.assertEquals( + PASS, + status[0], + "Listing of Key pairs failed" + ) + # Verifying that list size is increased by 1 + self.assertEquals( + list_keypairs_before_size + 1, + len(list_keypairs_after), + "List count is not matching" + ) + # Resetting the VM SSH key to the Key pair created above + vm_created.resetSshKey( + self.userapiclient, + keypair=new_keypair.name + ) + # Listing VM details again + 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( + 1, + len(list_vm), + "VMs list is not as expected" + ) + # Verifying that VM's SSH keypair is set to newly created keypair + self.assertEquals( + new_keypair.name, + list_vm[0].keypair, + "VM is not set to newly created SSH Key pair" + ) + return + + @attr(tags=["advanced", "provisioning"]) + def test_12_vm_nics(self): + """ + @Desc: Test to verify Nics for a VM + @Steps: + Step1: Deploying a VM + Step2: Listing all the Networks + Step3: Verifying that the list size is 1 + Step4: Creating 1 network + Step5: Listing all the networks again + Step6: Verifying that the list size is 2 + Step7: Verifying that VM deployed in step1 has only 1 nic + and it is same as network listed in step3 + Step8: Adding the networks created in step4 to VM deployed in step1 + Step9: Verifying that VM deployed in step1 has 2 nics + Step10: Verifying that isdefault is set to true for only 1 nic + Step11: Verifying that isdefault is set to true for the Network created when deployed a VM + Step12: Making the nic created in step4 as default nic + Step13: Verifying that isdefault is set to true for only 1 nic + Step14: Verifying that the isdefault is set to true for the nic created in step4 + Step15: Removing the non-default nic from VM + Step16: Verifying that VM deployed in step1 has only 1 nic + """ + # Listing all the VM's for a User + list_vms_before = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + ) + self.assertIsNone( + list_vms_before, + "Virtual Machine already exists for newly created user" + ) + # Deploying a VM + vm_created = VirtualMachine.create( + self.userapiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + ) + self.assertIsNotNone( + vm_created, + "VM creation failed" + ) + self.cleanup.append(vm_created) + # Listing all the VMs for a user again + list_vms_after = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + ) + status = validateList(list_vms_after) + self.assertEquals( + PASS, + status[0], + "VM creation failed" + ) + # Verifying that the size of the list is 1 + self.assertEquals( + 1, + len(list_vms_after), + "VM list count is not matching" + ) + # Listing all the networks before + list_network_before = Network.list( + self.userapiclient, + isdefault="true", + zoneid=self.zone.id, + account=self.account.name, + domainid=self.domain.id + ) + status = validateList(list_network_before) + self.assertEquals( + PASS, + status[0], + "Default Network not created when deploying a VM" + ) + # Verifying that only 1 network is created while deploying a VM + self.assertEquals( + 1, + len(list_network_before), + "More than 1 default network exists" + ) + network1 = list_network_before[0] + # Listing Network Offerings + network_offerings_list = NetworkOffering.list( + self.apiClient, + forvpc="false", + guestiptype="Isolated", + state="Enabled", + supportedservices="SourceNat", + zoneid=self.zone.id + ) + self.assertIsNotNone( + network_offerings_list, + "Isolated Network Offerings with sourceNat enabled are not found" + ) + # Creating one more network + network2 = Network.create( + self.userapiclient, + self.services["network"], + accountid=self.account.name, + domainid=self.domain.id, + networkofferingid=network_offerings_list[0].id, + zoneid=self.zone.id + ) + self.assertIsNotNone( + network2, + "Network creation failed" + ) + self.cleanup.append(network2) + # Listing all the networks again + list_network_after = Network.list( + self.userapiclient, + zoneid=self.zone.id, + account=self.account.name, + domainid=self.domain.id + ) + status = validateList(list_network_after) + self.assertEquals( + PASS, + status[0], + "List of Networks failed" + ) + # Verifying that list size is 2 + self.assertEquals( + 2, + len(list_network_after), + "More than 1 default network exists" + ) + # Verifying that VM created is having only 1 nic + vm_nics_before = vm_created.nic + self.assertIsNotNone( + vm_nics_before, + "Nic not found for the VM deployed" + ) + self.assertEquals( + 1, + len(vm_nics_before), + "VM Nic count is not matching" + ) + # Verifying that the nic is same as the default network listed above + self.assertEquals( + network1.id, + vm_nics_before[0].networkid, + "Default NIC for VM is not as expected" + ) + # Adding network2 created above to VM + VirtualMachine.add_nic( + vm_created, + self.userapiclient, + network2.id + ) + # Listing the Vm details again + list_vms_after = VirtualMachine.list( + self.userapiclient, + id=vm_created.id + ) + status = validateList(list_vms_after) + self.assertEquals( + PASS, + status[0], + "Listing of VM failed" + ) + vm = list_vms_after[0] + # Verifying that VM nics size is 2 now + vm_nics_after = vm.nic + self.assertIsNotNone( + vm_nics_after, + "Nic not found for the deployed VM" + ) + self.assertEquals( + 2, + len(vm_nics_after), + "VM NIC's count is not matching" + ) + # Verifying that isdefault is set to true for only 1 nic + default_count = 0 + for i in range(0, len(vm_nics_after)): + if vm_nics_after[i].isdefault is True: + default_count = default_count + 1 + default_nic = vm_nics_after[i] + else: + non_default_nic = vm_nics_after[i] + + self.assertEquals( + 1, + default_count, + "Default NIC count is not matching" + ) + # Verifying that default NIC is same the network created when VM is deployed + self.assertEquals( + network1.id, + default_nic.networkid, + "Default NIC is not matching for VM" + ) + # Updating network 2 as default NIC + vm_created.update_default_nic( + self.userapiclient, + non_default_nic.id + ) + # Listing the Vm details again + list_vms_after = VirtualMachine.list( + self.userapiclient, + id=vm_created.id + ) + status = validateList(list_vms_after) + self.assertEquals( + PASS, + status[0], + "Listing of VM failed" + ) + vm = list_vms_after[0] + # Verifying that VM nics size is 2 now + vm_nics_after = vm.nic + self.assertIsNotNone( + vm_nics_after, + "Nic not found for the deployed VM" + ) + self.assertEquals( + 2, + len(vm_nics_after), + "VM NIC's count is not matching" + ) + # Verifying that isdefault is set to true for only 1 nic + default_count = 0 + for i in range(0, len(vm_nics_after)): + if vm_nics_after[i].isdefault is True: + default_count = default_count + 1 + default_nic = vm_nics_after[i] + else: + non_default_nic = vm_nics_after[i] + + self.assertEquals( + 1, + default_count, + "Default NIC count is not matching" + ) + # Verifying that default NIC is same the newly updated network (network 2) + self.assertEquals( + network2.id, + default_nic.networkid, + "Default NIC is not matching for VM" + ) + # Deleting non default NIC + vm_created.remove_nic( + self.userapiclient, + non_default_nic.id + ) + # Listing the Vm details again + list_vms_after = VirtualMachine.list( + self.userapiclient, + id=vm_created.id + ) + status = validateList(list_vms_after) + self.assertEquals( + PASS, + status[0], + "Listing of VM failed" + ) + vm = list_vms_after[0] + # Verifying that VM nics size is 1 now + vm_nics_after = vm.nic + self.assertIsNotNone( + vm_nics_after, + "Nic not found for the deployed VM" + ) + self.assertEquals( + 1, + len(vm_nics_after), + "VM NIC's count is not matching" + ) + # Verifying the nic network is same as the default nic network + self.assertEquals( + network2.id, + vm_nics_after[0].networkid, + "VM NIC is not same as expected" + ) + return + +class TestInstances(cloudstackTestCase): + + @classmethod + def setUpClass(cls): + try: + cls._cleanup = [] + cls.testClient = super(TestInstances, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = cls.testClient.getParsedTestDataConfig() + + # Get Domain, Zone, Template + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client) + cls.template = get_template( + cls.api_client, + cls.zone.id, + cls.services["ostype"] + ) + if cls.zone.localstorageenabled: + cls.storagetype = 'local' + cls.services["service_offerings"]["tiny"]["storagetype"] = 'local' + cls.services["disk_offering"]["storagetype"] = 'local' + else: + cls.storagetype = 'shared' + cls.services["service_offerings"]["tiny"]["storagetype"] = 'shared' + cls.services["disk_offering"]["storagetype"] = 'shared' + + cls.services['mode'] = cls.zone.networktype + cls.services["virtual_machine"]["hypervisor"] = cls.testClient.getHypervisorInfo() + cls.services["virtual_machine"]["zoneid"] = cls.zone.id + cls.services["virtual_machine"]["template"] = cls.template.id + cls.services["custom_volume"]["zoneid"] = cls.zone.id + + # Creating Disk offering, Service Offering and Account + cls.disk_offering = DiskOffering.create( + cls.api_client, + cls.services["disk_offering"] + ) + cls._cleanup.append(cls.disk_offering) + cls.service_offering = ServiceOffering.create( + cls.api_client, + cls.services["service_offerings"]["tiny"] + ) + cls._cleanup.append(cls.service_offering) + cls.account = Account.create( + cls.api_client, + cls.services["account"], + domainid=cls.domain.id + ) + # Getting authentication for user in newly created Account + cls.user = cls.account.user[0] + cls.userapiclient = cls.testClient.getUserApiClient(cls.user.username, cls.domain.name) + # Updating resource Limits + for i in range(0,12): + Resources.updateLimit( + cls.api_client, + account=cls.account.name, + domainid=cls.domain.id, + max=-1, + resourcetype=i + ) + cls._cleanup.append(cls.account) + except Exception as e: + cls.tearDownClass() + raise Exception("Warning: Exception in setup : %s" % e) + return + + def setUp(self): + + self.apiClient = self.testClient.getApiClient() + self.cleanup = [] + + def tearDown(self): + #Clean up, terminate the created resources + cleanup_resources(self.apiClient, self.cleanup) + return + + @classmethod + def tearDownClass(cls): + try: + cleanup_resources(cls.api_client, cls._cleanup) + except Exception as e: + raise Exception("Warning: Exception during cleanup : %s" % e) + + return + + def __verify_values(self, expected_vals, actual_vals): + """ + @Desc: Function to verify expected and actual values + @Steps: + Step1: Initializing return flag to True + Step1: Verifying length of expected and actual dictionaries is matching. + If not matching returning false + Step2: Listing all the keys from expected dictionary + Step3: Looping through each key from step2 and verifying expected and actual dictionaries have same value + If not making return flag to False + Step4: returning the return flag after all the values are verified + """ + return_flag = True + + if len(expected_vals) != len(actual_vals): + return False + + keys = expected_vals.keys() + for i in range(0, len(expected_vals)): + exp_val = expected_vals[keys[i]] + act_val = actual_vals[keys[i]] + if exp_val == act_val: + return_flag = return_flag and True + else: + return_flag = return_flag and False + self.debug("expected Value: %s, is not matching with actual value: %s" % ( + exp_val, + act_val + )) + return return_flag + + @attr(tags=["advanced", "basic", "provisioning"]) + def test_13_attach_detach_iso(self): + """ + @Desc: Test Attach ISO to VM and Detach ISO from VM. + @Steps: + Step1: Listing all the VMs for a user + Step2: Verifying that the size of the list is 0 + Step3: Deploying a VM + Step4: Listing all the VMs for a user again + Step5: Verifying that list size is increased by 1 + Step6: Listing all the ready ISO's + Step7: If size of the list is >= 1 continuing to next steps + Step8: Attaching the ISO listed to VM deployed in Step3 + Step9: Verifying that the attached ISO details are associated with VM + Step10: Detaching the ISO attached in step8 + Step11: Verifying that detached ISO details are not associated with VM + """ + # Listing all the VM's for a User + list_vms_before = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + zoneid=self.zone.id, + account=self.account.name + ) + self.assertIsNone( + list_vms_before, + "Virtual Machine already exists for newly created user" + ) + # Deploying a VM + vm_created = VirtualMachine.create( + self.userapiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + ) + self.assertIsNotNone( + vm_created, + "VM creation failed" + ) + self.cleanup.append(vm_created) + # Listing all the VMs for a user again for matching zone + list_vms_after = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"], + domainid=self.account.domainid, + zoneid=self.zone.id, + account=self.account.name + ) + status = validateList(list_vms_after) + self.assertEquals( + PASS, + status[0], + "VM creation failed" + ) + # Verifying that the size of the list is 1 + self.assertEquals( + 1, + len(list_vms_after), + "VM list count is not matching" + ) + # Listing the ISO's in ready state + isos_list = Iso.list( + self.userapiclient, + isready="true", + isofilter="executable", + zoneid=self.zone.id + ) + # Verifying if size of the list is >= 1 + if isos_list is not None: + iso_toattach = isos_list[0] + # Attaching ISO listed to VM deployed + VirtualMachine.attach_iso( + vm_created, + self.userapiclient, + iso_toattach + ) + list_vm = VirtualMachine.list( + self.userapiclient, + id=vm_created.id + ) + status = validateList(list_vm) + self.assertEquals( + PASS, + status[0], + "VM listing by Id failed" + ) + # Verifying that attached ISO details are present in VM + self.assertEquals( + iso_toattach.name, + list_vm[0].isoname, + "Attached ISO name is not matching" + ) + self.assertEquals( + iso_toattach.displaytext, + list_vm[0].isodisplaytext, + "Attached ISO display is not matching" + ) + # Detaching ISO from VM + VirtualMachine.detach_iso( + vm_created, + self.userapiclient + ) + list_vm = VirtualMachine.list( + self.userapiclient, + id=vm_created.id + ) + status = validateList(list_vm) + self.assertEquals( + PASS, + status[0], + "VM listing by Id failed" + ) + # Verifying that ISO details are NOT present in VM + self.assertIsNone( + list_vm[0].isoname, + "ISO not detached from VM" + ) + else: + self.fail("Executable ISO in Ready is not found in the given setup") + + return + + @attr(tags=["advanced", "basic", "provisioning"]) + def test_14_vm_snapshot_pagination(self): + """ + @Desc: Test VM Snapshots pagination. + @Steps: + Step1: Deploying a VM + Step2: Listing all the Snapshots of the VM deployed in Step 1 + Step3: Verifying that the list size is 0 + Step4: Creating (pagesize + 1) number of Snapshots for the VM + Step5: Listing all the Snapshots of the VM deployed in Step 1 + Step6: Verifying that the list size is (pagesize + 1) + Step7: Listing all the VM snapshots in Page 1 with 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 + Step10: Verifying that size of the list is 1 + Step11: Deleting VM snapshot in page 2 + Step12: Listing all the VM snapshots in Page 2 with page size + Step13: Verifying that size of the list is 0 + """ + # Listing all the VM's for a User + list_vms_before = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + ) + self.assertIsNone( + list_vms_before, + "Virtual Machine already exists for newly created user" + ) + # Deploying a VM + vm_created = VirtualMachine.create( + self.userapiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + ) + self.assertIsNotNone( + vm_created, + "VM creation failed" + ) + self.cleanup.append(vm_created) + # Listing all the VMs for a user again + list_vms_after = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + ) + status = validateList(list_vms_after) + self.assertEquals( + PASS, + status[0], + "VM creation failed" + ) + # Verifying that the size of the list is 1 + self.assertEquals( + 1, + len(list_vms_after), + "VM list count is not matching" + ) + # Listing all the VM snapshots for VM deployed above + list_snapshots_before = VmSnapshot.list( + self.userapiclient, + listall=self.services["listall"], + virtualmachineid=vm_created.id + ) + # Verifying that the VM snapshot list is None + self.assertIsNone( + list_snapshots_before, + "Snapshots already exists for newly created VM" + ) + # Creating pagesize + 1 number of VM snapshots + for i in range(0, (self.services["pagesize"] + 1)): + snapshot_created = VmSnapshot.create( + self.userapiclient, + vm_created.id, + ) + self.assertIsNotNone( + snapshot_created, + "Snapshot creation failed" + ) + + # Listing all the VM snapshots for VM again + list_snapshots_after = VmSnapshot.list( + self.userapiclient, + listall=self.services["listall"], + virtualmachineid=vm_created.id + ) + status = validateList(list_snapshots_after) + self.assertEquals( + PASS, + status[0], + "VM Snapshots creation failed" + ) + self.assertEquals( + self.services["pagesize"] + 1, + len(list_snapshots_after), + "Count of VM Snapshots is not matching" + ) + # Listing all the VM snapshots in Page 1 with page size + list_snapshots_page1 = VmSnapshot.list( + self.userapiclient, + listall=self.services["listall"], + virtualmachineid=vm_created.id, + page=1, + pagesize=self.services["pagesize"], + ) + status = validateList(list_snapshots_page1) + self.assertEquals( + PASS, + status[0], + "Listing of VM Snapshots failed in page 1" + ) + # Verifying the list size is equal to pagesize + self.assertEquals( + self.services["pagesize"], + len(list_snapshots_page1), + "List VM Snapshot count is not matching in page 1" + ) + # Listing all the VM Snapshots in page 2 + list_snapshots_page2 = VmSnapshot.list( + self.userapiclient, + listall=self.services["listall"], + virtualmachineid=vm_created.id, + page=2, + pagesize=self.services["pagesize"], + ) + status = validateList(list_snapshots_page2) + self.assertEquals( + PASS, + status[0], + "Listing of VM Snapshots failed in page 2" + ) + # Verifying the list size is equal to 1 + self.assertEquals( + 1, + len(list_snapshots_page2), + "List VM Snapshot count is not matching in page 2" + ) + # Deleting VM Snapshot in page 2 + VmSnapshot.deleteVMSnapshot( + self.userapiclient, + snapshot_created.id + ) + # Listing all the VM Snapshots in page 2 again + list_snapshots_page2 = VmSnapshot.list( + self.userapiclient, + listall=self.services["listall"], + virtualmachineid=vm_created.id, + page=2, + pagesize=self.services["pagesize"], + ) + # Verifying the list size is equal to 0 + self.assertIsNone( + list_snapshots_page2, + "VM Snapshots exists in page 2" + ) + return + + @attr(tags=["advanced", "basic", "provisioning"]) + def test_15_revert_vm_to_snapshot(self): + """ + @Desc: Test Revert VM to Snapshot functionality. + @Steps: + Step1: Deploying a VM + Step2: Listing all the Snapshots of the VM deployed in Step 1 + Step3: Verifying that the list size is 0 + Step4: Creating 2 Snapshots for the VM + Step5: Listing all the Snapshots of the VM deployed in Step 1 + Step6: Verifying that the list size is 2 + Step7: Verifying that only 1 snapshot is have current flag set to True + Step8: Verifying that the VM snapshot with current flag set as true is the latest snapshot created + Step9: Reverting VM to snapshot having current flag as false (non current snapshot) + Step10: Verifying that only 1 VM snapshot is having current flag set as true. + Step11: Verifying that the VM Snapshot with current flag set to true is the reverted snapshot in Step 8 + """ + # Listing all the VM's for a User + list_vms_before = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + ) + self.assertIsNone( + list_vms_before, + "Virtual Machine already exists for newly created user" + ) + # Deploying a VM + vm_created = VirtualMachine.create( + self.userapiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + ) + self.assertIsNotNone( + vm_created, + "VM creation failed" + ) + self.cleanup.append(vm_created) + # Listing all the VMs for a user again + list_vms_after = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + ) + status = validateList(list_vms_after) + self.assertEquals( + PASS, + status[0], + "VM creation failed" + ) + # Verifying that the size of the list is 1 + self.assertEquals( + 1, + len(list_vms_after), + "VM list count is not matching" + ) + # Listing all the VM snapshots for VM deployed above + list_snapshots_before = VmSnapshot.list( + self.userapiclient, + listall=self.services["listall"], + virtualmachineid=vm_created.id + ) + # Verifying that the VM snapshot list is None + self.assertIsNone( + list_snapshots_before, + "Snapshots already exists for newly created VM" + ) + # Creating 2 of VM snapshots + snapshot1 = VmSnapshot.create( + self.userapiclient, + vm_created.id, + ) + self.assertIsNotNone( + snapshot1, + "Snapshot creation failed" + ) + snapshot2 = VmSnapshot.create( + self.userapiclient, + vm_created.id, + ) + self.assertIsNotNone( + snapshot2, + "Snapshot creation failed" + ) + # Listing all the VM snapshots for VM again + list_snapshots_after = VmSnapshot.list( + self.userapiclient, + listall=self.services["listall"], + virtualmachineid=vm_created.id + ) + status = validateList(list_snapshots_after) + self.assertEquals( + PASS, + status[0], + "VM Snapshots creation failed" + ) + self.assertEquals( + 2, + len(list_snapshots_after), + "Count of VM Snapshots is not matching" + ) + # Verifying that only 1 snapshot is having current flag set to true + # and that snapshot is the latest snapshot created (snapshot2) + current_count = 0 + for i in range(0, len(list_snapshots_after)): + if(list_snapshots_after[i].current is True): + current_count = current_count + 1 + current_snapshot = list_snapshots_after[i] + + self.assertEquals( + 1, + current_count, + "count of VM Snapshot with current flag as true is not matching" + ) + self.assertEquals( + snapshot2.id, + current_snapshot.id, + "Latest snapshot taken is not marked as current" + ) + # Reverting the VM to Snapshot 1 + VmSnapshot.revertToSnapshot( + self.userapiclient, + snapshot1.id + ) + # Listing the VM snapshots again + list_snapshots_after = VmSnapshot.list( + self.userapiclient, + listall=self.services["listall"], + virtualmachineid=vm_created.id + ) + status = validateList(list_snapshots_after) + self.assertEquals( + PASS, + status[0], + "VM Snapshots creation failed" + ) + self.assertEquals( + 2, + len(list_snapshots_after), + "Count of VM Snapshots is not matching" + ) + # Verifying that only 1 snapshot is having current flag set to true + # and that snapshot is snapshot1 + current_count = 0 + for i in range(0, len(list_snapshots_after)): + if(list_snapshots_after[i].current is True): + current_count = current_count + 1 + current_snapshot = list_snapshots_after[i] + self.assertEquals( + 1, + current_count, + "count of VM Snapshot with current flag as true is not matching" + ) + self.assertEquals( + snapshot1.id, + current_snapshot.id, + "Current flag was set properly after reverting the VM to snapshot" + ) + return + + @attr(tags=["advanced", "basic", "selfservice"]) + def test_16_list_vm_volumes_pagination(self): + """ + @Desc: Test to verify pagination of Volumes for a VM + @Steps: + Step1: Deploying a VM + Step2: Listing all the Volumes of the VM deployed in Step 1 + Step3: Verifying that the list size is 1 + Step4: Creating page size number of volumes + Step5: Attaching all the volumes created in step4 to VM deployed in Step1 + Step6: Listing all the Volumes for the VM in step1 + Step7: Verifying that the list size is equal to page size + 1 + Step8: Listing all the volumes of VM in page 1 + Step9: Verifying that the list size is equal to page size + Step10: Listing all the Volumes in Page 2 + Step11: Verifying that the list size is 1 + Step12: Detaching the volume from the VM + Step13: Listing all the Volumes in Page 2 + Step14: Verifying that list size is 0 + """ + # Listing all the VM's for a User + list_vms_before = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + ) + self.assertIsNone( + list_vms_before, + "Virtual Machine already exists for newly created user" + ) + # Deploying a VM + vm_created = VirtualMachine.create( + self.userapiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + ) + self.assertIsNotNone( + vm_created, + "VM creation failed" + ) + self.cleanup.append(vm_created) + # Listing all the VMs for a user again + list_vms_after = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + ) + status = validateList(list_vms_after) + self.assertEquals( + PASS, + status[0], + "VM creation failed" + ) + # Verifying that the size of the list is 1 + self.assertEquals( + 1, + len(list_vms_after), + "VM list count is not matching" + ) + # Listing all the Volumes for the VM deployed + list_volumes_before = Volume.list( + self.userapiclient, + listall=self.services["listall"], + virtualmachineid=vm_created.id + ) + status = validateList(list_volumes_before) + self.assertEquals( + PASS, + status[0], + "Root volume is not created for VM deployed" + ) + # Verifying the size of the list is 1 + self.assertEquals( + 1, + len(list_volumes_before), + "Volumes count is not matching" + ) + # Creating Page size number of volumes + for i in range(0, self.services["pagesize"]): + volume_created = Volume.create( + self.userapiclient, + self.services["volume"], + zoneid=self.zone.id, + diskofferingid=self.disk_offering.id + ) + self.assertIsNotNone( + volume_created, + "Volume is not created" + ) + self.cleanup.append(volume_created) + # Attaching all the volumes created to VM + vm_created.attach_volume( + self.userapiclient, + volume_created + ) + + # List all the volumes for the VM again + list_volumes_after = Volume.list( + self.userapiclient, + listall=self.services["listall"], + virtualmachineid=vm_created.id + ) + status = validateList(list_volumes_after) + self.assertEquals( + PASS, + status[0], + "Volumes are not listed" + ) + # Verifying that size of the list is equal to page size + 1 + self.assertEquals( + self.services["pagesize"] + 1, + len(list_volumes_after), + "VM's volume count is not matching" + ) + # Listing all the volumes for a VM in page 1 + list_volumes_page1 = Volume.list( + self.userapiclient, + listall=self.services["listall"], + virtualmachineid=vm_created.id, + page=1, + pagesize=self.services["pagesize"] + ) + status = validateList(list_volumes_page1) + self.assertEquals( + PASS, + status[0], + "Volumes not listed in page1" + ) + # Verifying that list size is equal to page size + self.assertEquals( + self.services["pagesize"], + len(list_volumes_page1), + "VM's volume count is not matching in page 1" + ) + # Listing all the volumes for a VM in page 2 + list_volumes_page2 = Volume.list( + self.userapiclient, + listall=self.services["listall"], + virtualmachineid=vm_created.id, + page=2, + pagesize=self.services["pagesize"] + ) + status = validateList(list_volumes_page2) + self.assertEquals( + PASS, + status[0], + "Volumes not listed in page2" + ) + # Verifying that list size is equal to 1 + self.assertEquals( + 1, + len(list_volumes_page2), + "VM's volume count is not matching in page 1" + ) + # Detaching 1 volume from VM + vm_created.detach_volume( + self.userapiclient, + volume_created + ) + # Listing all the volumes for a VM in page 2 again + list_volumes_page2 = Volume.list( + self.userapiclient, + listall=self.services["listall"], + virtualmachineid=vm_created.id, + page=2, + pagesize=self.services["pagesize"] + ) + # Verifying that there are no volumes present in page 2 + self.assertIsNone( + list_volumes_page2, + "Volumes listed in page 2" + ) + return + + @attr(tags=["advanced", "basic", "provisioning"]) + def test_17_running_vm_scaleup(self): + """ + @Desc: Test to verify change service for Running VM + @Steps: + Step1: Checking if dynamic scaling of virtual machines is enabled in zone and template. + If yes then continuing. + If not then printing message that scale up is not possible for Running VM + Step2: Deploying a VM + Step3: Listing all the existing service offerings + Step4: If there is a matching Service Offering for scale-up of running VM + use that service offering. If not create one service offering for scale up. + Step5: Perform change service (scale up) the Running VM deployed in step1 + Step6: Verifying that VM's service offerings is changed + """ + # Checking if Dynamic scaling of VM is supported or not + list_config = Configurations.list( + self.apiClient, + zoneid=self.zone.id, + name="enable.dynamic.scale.vm" + ) + status = validateList(list_config) + self.assertEquals( + PASS, + status[0], + "Listing of configuration failed" + ) + # Checking if dynamic scaling is allowed in Zone and Template + if not ((list_config[0].value is True) and (self.template.isdynamicallyscalable)): + self.debug("Scale up of Running VM is not possible as Zone/Template does not support") + else: + # Listing all the VM's for a User + list_vms_before = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + ) + self.assertIsNone( + list_vms_before, + "Virtual Machine already exists for newly created user" + ) + # Deploying a VM + vm_created = VirtualMachine.create( + self.userapiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + ) + self.assertIsNotNone( + vm_created, + "VM creation failed" + ) + self.cleanup.append(vm_created) + # Listing details of current Service Offering + vm_so_list = ServiceOffering.list( + self.userapiclient, + id=vm_created.serviceofferingid + ) + status = validateList(vm_so_list) + self.assertEquals( + PASS, + status[0], + "Listing of VM Service offering failed" + ) + current_so = vm_so_list[0] + # Listing all the VMs for a user again + list_vms_after = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + ) + status = validateList(list_vms_after) + self.assertEquals( + PASS, + status[0], + "VM creation failed" + ) + # Verifying that the size of the list is 1 + self.assertEquals( + 1, + len(list_vms_after), + "VM list count is not matching" + ) + # Listing all the existing service offerings + service_offerings_list = ServiceOffering.list( + self.userapiclient, + virtualmachineid=vm_created.id + ) + # Verifying if any Service offering available for scale up of VM + so_exists = False + if service_offerings_list is not None: + for i in range(0, len(service_offerings_list)): + if not ((current_so.cpunumber > service_offerings_list[i].cpunumber or\ + current_so.cpuspeed > service_offerings_list[i].cpuspeed or\ + current_so.memory > service_offerings_list[i].memory) or\ + (current_so.cpunumber == service_offerings_list[i].cpunumber and\ + current_so.cpuspeed == service_offerings_list[i].cpuspeed and\ + current_so.memory == service_offerings_list[i].memory)): + if(current_so.storagetype == service_offerings_list[i].storagetype): + so_exists = True + new_so = service_offerings_list[i] + break + # If service offering does not exists, then creating one service offering for scale up + if not so_exists: + self.services["service_offerings"]["small"]["storagetype"] = current_so.storagetype + new_so = ServiceOffering.create( + self.apiClient, + self.services["service_offerings"]["small"] + ) + self.cleanup.append(new_so) + # Scaling up the VM + vm_created.scale_virtualmachine( + self.userapiclient, + new_so.id + ) + # Listing VM details again + list_vms_after = VirtualMachine.list( + self.userapiclient, + id=vm_created.id + ) + status = validateList(list_vms_after) + self.assertEquals( + PASS, + status[0], + "Listing of VM failed" + ) + self.assertEquals( + 1, + len(list_vms_after), + "VMs list is not as expected" + ) + # Verifying that VM's service offerings is changed + self.assertEquals( + new_so.id, + list_vms_after[0].serviceofferingid, + "VM is not containing New Service Offering" + ) + return + + @attr(tags=["advanced", "basic", "provisioning"]) + def test_18_stopped_vm_change_service(self): + """ + @Desc: Test to verify change service for Stopped VM + @Steps: + Step1: Deploying a VM + Step2: Stopping the VM deployed in step1 + Step3: Listing all the existing service offerings + Step4: If there is a matching Service Offering for change service of stopped VM + use that service offering. If not create one service offering for change service. + Step5: Perform change service for the Stopped VM + Step6: Verifying that VM's service offerings is changed + """ + # Listing all the VM's for a User + list_vms_before = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + ) + self.assertIsNone( + list_vms_before, + "Virtual Machine already exists for newly created user" + ) + # Deploying a VM + vm_created = VirtualMachine.create( + self.userapiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + ) + self.assertIsNotNone( + vm_created, + "VM creation failed" + ) + self.cleanup.append(vm_created) + # Listing details of current Service Offering + vm_so_list = ServiceOffering.list( + self.userapiclient, + id=vm_created.serviceofferingid + ) + status = validateList(vm_so_list) + self.assertEquals( + PASS, + status[0], + "Listing of VM Service offering failed" + ) + current_so = vm_so_list[0] + # Listing all the VMs for a user again + list_vms_after = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + ) + status = validateList(list_vms_after) + self.assertEquals( + PASS, + status[0], + "VM creation failed" + ) + # Verifying that the size of the list is 1 + self.assertEquals( + 1, + len(list_vms_after), + "VM list count is not matching" + ) + # Stopping the VM deployed above + vm_created.stop( + self.userapiclient, + 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 + service_offerings_list = ServiceOffering.list( + self.userapiclient, + virtualmachineid=vm_created.id + ) + # Verifying if any Service offering available for change service of VM + so_exists = False + if service_offerings_list is not None: + for i in range(0, len(service_offerings_list)): + if ((current_so.id != service_offerings_list[i].id) and\ + (current_so.storagetype == service_offerings_list[i].storagetype)): + so_exists = True + new_so = service_offerings_list[i] + break + # If service offering does not exists, then creating one service offering for scale up + if not so_exists: + self.services["service_offerings"]["small"]["storagetype"] = current_so.storagetype + new_so = ServiceOffering.create( + self.apiClient, + self.services["service_offerings"]["small"] + ) + self.cleanup.append(new_so) + # Changing service for the VM + vm_created.scale_virtualmachine( + self.userapiclient, + new_so.id + ) + # Listing VM details again + 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( + 1, + len(list_vm), + "VMs list is not as expected" + ) + # Verifying that VM's service offerings is changed + self.assertEquals( + new_so.id, + list_vm[0].serviceofferingid, + "VM is not containing New Service Offering" + ) + return + + @attr(tags=["advanced", "basic", "provisioning"]) + def test_19_create_reset_vm_sshkey(self): + """ + @Desc: Test to verify creation and reset of SSH Key for VM + @Steps: + Step1: Deploying a VM + Step2: Stopping the VM deployed in step1 + Step3: Listing all the SSH Key pairs + Step4: Creating a new SSH Key pair + Step5: Listing all the SSh Key pairs again + Step6: Verifying that the key pairs list is increased by 1 + Step7: Resetting the VM SSH Key to the key pair created in step4 + Step8: Verifying that the new SSH Key pair is set to the VM + """ + # Listing all the VM's for a User + list_vms_before = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + ) + self.assertIsNone( + list_vms_before, + "Virtual Machine already exists for newly created user" + ) + # Deploying a VM + vm_created = VirtualMachine.create( + self.userapiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + ) + self.assertIsNotNone( + vm_created, + "VM creation failed" + ) + self.cleanup.append(vm_created) + # Listing all the VMs for a user again + list_vms_after = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + ) + status = validateList(list_vms_after) + self.assertEquals( + PASS, + status[0], + "VM creation failed" + ) + # Verifying that the size of the list is 1 + self.assertEquals( + 1, + len(list_vms_after), + "VM list count is not matching" + ) + # Stopping the VM deployed above + vm_created.stop( + self.userapiclient, + 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 + list_keypairs_before = SSHKeyPair.list( + self.userapiclient + ) + list_keypairs_before_size = 0 + if list_keypairs_before is not None: + list_keypairs_before_size = len(list_keypairs_before) + + # Creating a new Key pair + new_keypair = SSHKeyPair.create( + self.userapiclient, + name="keypair1", + account=self.account.name, + domainid=self.domain.id + ) + self.assertIsNotNone( + new_keypair, + "New Key pair generation failed" + ) + self.assertEquals( + "keypair1", + new_keypair.name, + "Key Pair not created with given name" + ) + # Listing all the SSH Key pairs again + list_keypairs_after = SSHKeyPair.list( + self.userapiclient + ) + status = validateList(list_keypairs_after) + self.assertEquals( + PASS, + status[0], + "Listing of Key pairs failed" + ) + # Verifying that list size is increased by 1 + self.assertEquals( + list_keypairs_before_size + 1, + len(list_keypairs_after), + "List count is not matching" + ) + # Resetting the VM SSH key to the Key pair created above + vm_created.resetSshKey( + self.userapiclient, + keypair=new_keypair.name + ) + # Listing VM details again + 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( + 1, + len(list_vm), + "VMs list is not as expected" + ) + # Verifying that VM's SSH keypair is set to newly created keypair + self.assertEquals( + new_keypair.name, + list_vm[0].keypair, + "VM is not set to newly created SSH Key pair" + ) + return + + @attr(tags=["advanced", "basic", "selfservice"]) + def test_20_update_vm_displayname_group(self): + """ + @Desc: Test to verify Update VM details + @Steps: + Step1: List all the VM's for a user + Step2: Deploy a VM with all parameters + Step3: Listing all the VM's again for the user + Step4: Verifying that list size is increased by 1 + Step5: Updating VM details - displayname, group + Step6: Listing the VM deployed in step 2 by ID + Step7: Verifying that displayname, group details of the VM are updated + """ + # Listing all the VM's for a User + list_vms_before = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + ) + self.assertIsNone( + list_vms_before, + "Virtual Machine already exists for newly created user" + ) + self.services["virtual_machine"]["keyboard"] = "us" + # Deploying a VM + vm_created = VirtualMachine.create( + self.userapiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + group="groupName" + ) + self.assertIsNotNone( + vm_created, + "VM creation failed" + ) + self.cleanup.append(vm_created) + # Verifying the displayname and group details for deployed VM + self.assertEquals( + self.services["virtual_machine"]["displayname"], + vm_created.displayname, + "Display name of VM is not as expected" + ) + self.assertEquals( + "groupName", + vm_created.group, + "Group of VM is not as expected" + ) + # Listing all the VMs for a user again + list_vms_after = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + ) + status = validateList(list_vms_after) + self.assertEquals( + PASS, + status[0], + "VM creation failed" + ) + # Verifying that the size of the list is 1 + self.assertEquals( + 1, + len(list_vms_after), + "VM list count is not matching" + ) + # Updating the VM details - displayname and group + vm_created.update( + self.userapiclient, + displayname="DisplayName", + group="Group", + haenable=False + ) + # Listing VM details again + list_vm = VirtualMachine.list( + self.userapiclient, + id=vm_created.id, + ) + status = validateList(list_vm) + self.assertEquals( + PASS, + status[0], + "Listing of VM by Id failed" + ) + self.assertEquals( + 1, + len(list_vm), + "Count of List VM by Id is not matching" + ) + # Verifying that displayname and group details are updated + self.assertEquals( + "DisplayName", + list_vm[0].displayname, + "Displayname of VM is not updated" + ) + self.assertEquals( + "Group", + list_vm[0].group, + "Group of VM is not updated" + ) + return + + @attr(tags=["advanced", "basic", "provisioning"]) + def test_21_restore_vm(self): + """ + @Desc: Test to verify Restore VM + @Steps: + Step1: List all the VM's for a user + Step2: Deploy a VM with all parameters + Step3: Listing all the VM's again for the user + Step4: Verifying that list size is increased by 1 + Step5: Restoring the VM deployed in step2 + Step6: Verifying that restored VM details are same as the VM deployed in step2 + """ + # Listing all the VM's for a User + list_vms_before = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + ) + self.assertIsNone( + list_vms_before, + "Virtual Machine already exists for newly created user" + ) + # Deploying a VM + vm_created = VirtualMachine.create( + self.userapiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + ) + self.assertIsNotNone( + vm_created, + "VM creation failed" + ) + self.cleanup.append(vm_created) + # Listing all the VMs for a user again + list_vms_after = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + ) + status = validateList(list_vms_after) + self.assertEquals( + PASS, + status[0], + "VM creation failed" + ) + # Verifying that the size of the list is 1 + self.assertEquals( + 1, + len(list_vms_after), + "VM list count is not matching" + ) + # Restoring the VM + restored_vm = vm_created.restore(self.userapiclient) + self.assertIsNotNone( + restored_vm, + "VM restore failed" + ) + # Verifying the restored VM details + expected_dict = { + "id":vm_created.id, + "name":vm_created.name, + "displayname":vm_created.displayname, + "state":vm_created.state, + "zoneid":vm_created.zoneid, + "account":vm_created.account, + "template":vm_created.templateid + } + actual_dict = { + "id":restored_vm.id, + "name":restored_vm.name, + "displayname":restored_vm.displayname, + "state":restored_vm.state, + "zoneid":restored_vm.zoneid, + "account":restored_vm.account, + "template":restored_vm.templateid + } + restored_vm_status = self.__verify_values( + expected_dict, + actual_dict + ) + self.assertEqual( + True, + restored_vm_status, + "Restored VM details are not as expected" + ) + return + + @attr(tags=["advanced", "selfservice"]) + def test_22_deploy_vm_multiple_networks(self): + """ + @Desc: Test to verify deploy VM with multiple networks + @Steps: + Step1: List all the networks for user + Step2: If size of list networks is greater than 2 then get all the networks id's + Else create 2 networks and get network id's + Step3: List all the VM's for a user + Step4: Deploy a VM with multiple network id's + Step5: Listing all the VM's again for the user + Step6: Verifying that list size is increased by 1 + Step7: Verify that VM is associated with multiple networks + """ + # Listing all the networks available + networks_list_before = Network.list( + self.userapiclient, + listall=self.services["listall"] + ) + networks_list_size = 0 + if networks_list_before is not None: + networks_list_size = len(networks_list_before) + + # Listing Network Offerings + network_offerings_list = NetworkOffering.list( + self.apiClient, + forvpc="false", + guestiptype="Isolated", + state="Enabled", + supportedservices="SourceNat", + zoneid=self.zone.id + ) + status = validateList(network_offerings_list) + self.assertEquals( + PASS, + status[0], + "Isolated Network Offerings with sourceNat enabled are not found" + ) + while networks_list_size < 2: + # Creating a network + network = Network.create( + self.userapiclient, + self.services["network"], + accountid=self.account.name, + domainid=self.domain.id, + networkofferingid=network_offerings_list[0].id, + zoneid=self.zone.id + ) + self.assertIsNotNone( + network, + "Network creation failed" + ) + self.cleanup.append(network) + networks_list_size = networks_list_size + 1 + + # Listing the networks again + networks_list_after = Network.list( + self.userapiclient, + listall=self.services["listall"] + ) + status = validateList(network_offerings_list) + self.assertEquals( + PASS, + status[0], + "Listing networks failed" + ) + # populating network id's + networkids = networks_list_after[0].id + "," + networks_list_after[1].id + # Listing all the VM's for a User + list_vms_before = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + ) + self.assertIsNone( + list_vms_before, + "Virtual Machine already exists for newly created user" + ) + # Deploying a VM + vm_created = VirtualMachine.create( + self.userapiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + networkids=networkids, + serviceofferingid=self.service_offering.id, + ) + self.assertIsNotNone( + vm_created, + "VM creation failed" + ) + self.cleanup.append(vm_created) + # Listing all the VMs for a user again + list_vms_after = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + ) + status = validateList(list_vms_after) + self.assertEquals( + PASS, + status[0], + "VM creation failed" + ) + # Verifying that the size of the list is 1 + self.assertEquals( + 1, + len(list_vms_after), + "VM list count is not matching" + ) + # Verifying that the NIC's in VM created are same as provided + vm_nics = vm_created.nic + # Verifying that the size of nics is 2 + self.assertEquals( + 2, + len(vm_nics), + "NIC's count in VM created is not matching" + ) + # Verifying that NIC network ID's are as expected + for i in range(0, len(vm_nics)): + if vm_nics[i].isdefault is True: + self.assertEquals( + networks_list_after[0].id, + vm_nics[i].networkid, + "Default NIC is not as expected" + ) + else: + self.assertEquals( + networks_list_after[1].id, + vm_nics[i].networkid, + "Non Default NIC is not as expected" + ) + return + + @attr(tags=["basic", "provisioning"]) + def test_23_deploy_vm_multiple_securitygroups(self): + """ + @Desc: Test to verify deploy VM with multiple Security Groups + @Steps: + Step1: List all the security groups for user + Step2: If size of list security groups is greater than 2 then get all the security groups id's + Else creating 2 security groups and get security groups id's + Step3: List all the VM's for a user + Step4: Deploy a VM with multiple security groups id's + Step5: Listing all the VM's again for the user + Step6: Verifying that list size is increased by 1 + Step7: Verify that VM is associated with multiple security groups + """ + # Listing all the security groups available + security_groups_list = SecurityGroup.list( + self.userapiclient, + listall=self.services["listall"], + domainid=self.domain.id + ) + security_groups_list_size = 0 + if security_groups_list is not None: + security_groups_list_size = len(security_groups_list) + + while security_groups_list_size < 2: + # Creating a security group + security_group = SecurityGroup.create( + self.userapiclient, + self.services["security_group"], + account=self.account.name, + domainid=self.domain.id + ) + self.assertIsNotNone( + security_group, + "Security Group creation failed" + ) + self.cleanup.append(security_group) + security_groups_list_size = security_groups_list_size + 1 + + # Listing the networks again + security_groups_list = SecurityGroup.list( + self.userapiclient, + listall=self.services["listall"], + domainid=self.domain.id + ) + status = validateList(security_groups_list) + self.assertEquals( + PASS, + status[0], + "Listing Security Groups failed" + ) + # populating Security Groups id's + securitygroupids = {security_groups_list[0].id , security_groups_list[1].id} + # Listing all the VM's for a User + list_vms_before = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + ) + self.assertIsNone( + list_vms_before, + "Virtual Machine already exists for newly created user" + ) + # Deploying a VM + vm_created = VirtualMachine.create( + self.userapiclient, + self.services["virtual_machine"], + accountid=self.account.name, + domainid=self.account.domainid, + serviceofferingid=self.service_offering.id, + securitygroupids=securitygroupids, + ) + self.assertIsNotNone( + vm_created, + "VM creation failed" + ) + self.cleanup.append(vm_created) + # Listing all the VMs for a user again + list_vms_after = VirtualMachine.list( + self.userapiclient, + listall=self.services["listall"], + ) + status = validateList(list_vms_after) + self.assertEquals( + PASS, + status[0], + "VM creation failed" + ) + # Verifying that the size of the list is 1 + self.assertEquals( + 1, + len(list_vms_after), + "VM list count is not matching" + ) + # Verifying that the Security Groups's in VM created are same as provided + vm_securitygroups = vm_created.securitygroup + # Verifying that the size of security groups is 2 + self.assertEquals( + 2, + len(vm_securitygroups), + "Security Groups count in VM created is not matching" + ) + # Verifying that Security Group network ID's are as expected + vm_securitygroups_flag = True + for i in range(0, len(vm_securitygroups)): + if ((vm_securitygroups[i].id != security_groups_list[0].id) and\ + (vm_securitygroups[i].id != security_groups_list[1].id)): + vm_securitygroups_flag = False + break + + self.assertEquals( + True, + vm_securitygroups_flag, + "Security Groups in VM are not same as created" + ) + return + +class TestSnapshots(cloudstackTestCase): + + @classmethod + def setUpClass(cls): + try: + cls._cleanup = [] + cls.testClient = super(TestSnapshots, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = cls.testClient.getParsedTestDataConfig() + # Get Domain, Zone, Template + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client) + cls.template = get_template( + cls.api_client, + cls.zone.id, + cls.services["ostype"] + ) + if cls.zone.localstorageenabled: + cls.storagetype = 'local' + cls.services["service_offerings"]["tiny"]["storagetype"] = 'local' + cls.services["disk_offering"]["storagetype"] = 'local' + else: + cls.storagetype = 'shared' + cls.services["service_offerings"]["tiny"]["storagetype"] = 'shared' + cls.services["disk_offering"]["storagetype"] = 'shared' + + cls.services['mode'] = cls.zone.networktype + cls.services["virtual_machine"]["hypervisor"] = cls.testClient.getHypervisorInfo() + cls.services["virtual_machine"]["zoneid"] = cls.zone.id + cls.services["virtual_machine"]["template"] = cls.template.id + cls.services["custom_volume"]["zoneid"] = cls.zone.id + # Creating Disk offering, Service Offering and Account + cls.disk_offering = DiskOffering.create( + cls.api_client, + cls.services["disk_offering"] + ) + cls._cleanup.append(cls.disk_offering) + cls.service_offering = ServiceOffering.create( + cls.api_client, + cls.services["service_offerings"]["tiny"] + ) + cls._cleanup.append(cls.service_offering) + cls.account = Account.create( + cls.api_client, + cls.services["account"], + domainid=cls.domain.id + ) + # Getting authentication for user in newly created Account + cls.user = cls.account.user[0] + cls.userapiclient = cls.testClient.getUserApiClient(cls.user.username, cls.domain.name) + cls._cleanup.append(cls.account) + # Creating Virtual Machine + cls.virtual_machine = VirtualMachine.create( + cls.userapiclient, + cls.services["virtual_machine"], + accountid=cls.account.name, + domainid=cls.account.domainid, + serviceofferingid=cls.service_offering.id, + ) + cls._cleanup.append(cls.virtual_machine) + except Exception as e: + cls.tearDownClass() + raise Exception("Warning: Exception in setup : %s" % e) + return + + def setUp(self): + + self.apiClient = self.testClient.getApiClient() + self.cleanup = [] + + def tearDown(self): + #Clean up, terminate the created resources + cleanup_resources(self.apiClient, self.cleanup) + return + + @classmethod + def tearDownClass(cls): + try: + cleanup_resources(cls.api_client, cls._cleanup) + except Exception as e: + raise Exception("Warning: Exception during cleanup : %s" % e) + + return + + def __verify_values(self, expected_vals, actual_vals): + """ + @Desc: Function to verify expected and actual values + @Steps: + Step1: Initializing return flag to True + Step1: Verifying length of expected and actual dictionaries is matching. + If not matching returning false + Step2: Listing all the keys from expected dictionary + Step3: Looping through each key from step2 and verifying expected and actual dictionaries have same value + If not making return flag to False + Step4: returning the return flag after all the values are verified + """ + return_flag = True + + if len(expected_vals) != len(actual_vals): + return False + + keys = expected_vals.keys() + for i in range(0, len(expected_vals)): + exp_val = expected_vals[keys[i]] + act_val = actual_vals[keys[i]] + if exp_val == act_val: + return_flag = return_flag and True + else: + return_flag = return_flag and False + self.debug("expected Value: %s, is not matching with actual value: %s" % ( + exp_val, + act_val + )) + return return_flag + + @attr(tags=["advanced", "basic", "provisioning"]) + def test_01_list_volume_snapshots_pagination(self): + """ + @Desc: Test to List Volume Snapshots pagination + @steps: + Step1: Listing all the volume snapshots for a user + Step2: Verifying that list size is 0 + Step3: Creating (page size + 1) number of volume snapshots + Step4: Listing all the volume snapshots again for a user + Step5: Verifying that list size is (page size + 1) + Step6: Listing all the volume snapshots in page1 + Step7: Verifying that list size is (page size) + Step8: Listing all the volume snapshots in page2 + Step9: Verifying that list size is 1 + Step10: Deleting the volume snapshot present in page 2 + Step11: Listing all the volume snapshots in page2 + Step12: Verifying that list size is 0 + """ + # Listing all the volume snapshots for a User + list_vol_snaps_before = Snapshot.list( + self.userapiclient, + listall=self.services["listall"] + ) + # Verifying list size is 0 + self.assertIsNone( + list_vol_snaps_before, + "Volume snapshots exists for newly created user" + ) + # Listing the root volumes available for the user + volumes_list = Volume.list( + self.userapiclient, + listall=self.services["listall"] + ) + status = validateList(volumes_list) + self.assertEquals( + PASS, + status[0], + "Root volume did not get created while deploying a VM" + ) + # Verifying list size to be 1 + self.assertEquals( + 1, + len(volumes_list), + "More than 1 root volume created for deployed VM" + ) + root_volume = volumes_list[0] + # Creating pagesize + 1 number of volume snapshots + for i in range(0, (self.services["pagesize"] + 1)): + snapshot_created = Snapshot.create( + self.userapiclient, + root_volume.id, + ) + self.assertIsNotNone( + snapshot_created, + "Snapshot creation failed" + ) + self.cleanup.append(snapshot_created) + + # Listing all the volume snapshots for user again + list_vol_snaps_after = Snapshot.list( + self.userapiclient, + listall=self.services["listall"] + ) + status = validateList(list_vol_snaps_after) + self.assertEquals( + PASS, + status[0], + "Volume snapshot creation failed" + ) + # Verifying that list size is pagesize + 1 + self.assertEquals( + self.services["pagesize"] + 1, + len(list_vol_snaps_after), + "Failed to create pagesize + 1 number of Volume snapshots" + ) + # Listing all the volume snapshots in page 1 + list_vol_snaps_page1 = Snapshot.list( + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"] + ) + status = validateList(list_vol_snaps_page1) + self.assertEquals( + PASS, + status[0], + "Failed to list volume snapshots in page 1" + ) + # Verifying the list size to be equal to pagesize + self.assertEquals( + self.services["pagesize"], + len(list_vol_snaps_page1), + "Size of volume snapshots in page 1 is not matching" + ) + # Listing all the volume snapshots in page 2 + list_vol_snaps_page2 = Snapshot.list( + self.userapiclient, + listall=self.services["listall"], + page=2, + pagesize=self.services["pagesize"] + ) + status = validateList(list_vol_snaps_page2) + self.assertEquals( + PASS, + status[0], + "Failed to list volume snapshots in page 2" + ) + # Verifying the list size to be equal to pagesize + self.assertEquals( + 1, + len(list_vol_snaps_page2), + "Size of volume snapshots in page 2 is not matching" + ) + # Deleting the volume snapshot present in page 2 + Snapshot.delete( + snapshot_created, + self.userapiclient + ) + # Listing all the snapshots in page 2 again + list_vol_snaps_page2 = Snapshot.list( + self.userapiclient, + listall=self.services["listall"], + page=2, + pagesize=self.services["pagesize"] + ) + # Verifying that list size is 0 + self.assertIsNone( + list_vol_snaps_page2, + "Volume snapshot not deleted from page 2" + ) + return + + @attr(tags=["advanced", "basic", "provisioning"]) + def test_02_list_volume_snapshots_byid(self): + """ + @Desc: Test to List Volume Snapshots by Id + @Steps: + Step1: Listing all the volume snapshots for a user + Step2: Verifying that list size is 0 + Step3: Creating a volume snapshot + Step4: Listing all the volume snapshots again for a user + Step5: Verifying that list size is 1 + Step6: Listing all the volume snapshots by specifying snapshot id + Step7: Verifying that list size is 1 + Step8: Verifying details of the listed volume snapshot + """ + # Listing all the volume snapshots for a User + list_vol_snaps_before = Snapshot.list( + self.userapiclient, + listall=self.services["listall"] + ) + # Verifying list size is 0 + self.assertIsNone( + list_vol_snaps_before, + "Volume snapshots exists for newly created user" + ) + # Listing the root volumes available for the user + volumes_list = Volume.list( + self.userapiclient, + listall=self.services["listall"] + ) + status = validateList(volumes_list) + self.assertEquals( + PASS, + status[0], + "Root volume did not get created while deploying a VM" + ) + # Verifying list size to be 1 + self.assertEquals( + 1, + len(volumes_list), + "More than 1 root volume created for deployed VM" + ) + root_volume = volumes_list[0] + # Creating a volume snapshot + snapshot_created = Snapshot.create( + self.userapiclient, + root_volume.id, + ) + self.assertIsNotNone( + snapshot_created, + "Snapshot creation failed" + ) + self.cleanup.append(snapshot_created) + # Listing all the volume snapshots for user again + list_vol_snaps_after = Snapshot.list( + self.userapiclient, + listall=self.services["listall"] + ) + status = validateList(list_vol_snaps_after) + self.assertEquals( + PASS, + status[0], + "Volume snapshot creation failed" + ) + # Verifying that list size is 1 + self.assertEquals( + 1, + len(list_vol_snaps_after), + "Failed to create Volume snapshot" + ) + # Listing volume snapshot by id + list_vol_snapshot = Snapshot.list( + self.userapiclient, + listall=self.services["listall"], + id=snapshot_created.id + ) + status = validateList(list_vol_snapshot) + self.assertEquals( + PASS, + status[0], + "Failed to list Volume snapshot by Id" + ) + # Verifying that list size is 1 + self.assertEquals( + 1, + len(list_vol_snapshot), + "Size of the list volume snapshot by Id is not matching" + ) + # Verifying details of the listed snapshot to be same as snapshot created above + #Creating expected and actual values dictionaries + expected_dict = { + "id":snapshot_created.id, + "name":snapshot_created.name, + "state":snapshot_created.state, + "intervaltype":snapshot_created.intervaltype, + "account":snapshot_created.account, + "domain":snapshot_created.domainid, + "volume":snapshot_created.volumeid + } + actual_dict = { + "id":list_vol_snapshot[0].id, + "name":list_vol_snapshot[0].name, + "state":list_vol_snapshot[0].state, + "intervaltype":list_vol_snapshot[0].intervaltype, + "account":list_vol_snapshot[0].account, + "domain":list_vol_snapshot[0].domainid, + "volume":list_vol_snapshot[0].volumeid + } + vol_snapshot_status = self.__verify_values( + expected_dict, + actual_dict + ) + self.assertEqual( + True, + vol_snapshot_status, + "Listed Volume Snapshot details are not as expected" + ) + return + + @attr(tags=["advanced", "basic", "provisioning"]) + def test_03_list_vm_snapshots_pagination(self): + """ + @Desc: Test to List VM Snapshots pagination + @Steps: + Step1: Listing all the VM snapshots for a user + Step2: Verifying that list size is 0 + Step3: Creating (page size + 1) number of VM snapshots + Step4: Listing all the VM snapshots again for a user + Step5: Verifying that list size is (page size + 1) + Step6: Listing all the VM snapshots in page1 + Step7: Verifying that list size is (page size) + Step8: Listing all the VM snapshots in page2 + Step9: Verifying that list size is 1 + Step10: Deleting the VM snapshot present in page 2 + Step11: Listing all the volume snapshots in page2 + Step12: Verifying that list size is 0 + """ + # Listing all the VM snapshots for a User + list_vm_snaps_before = VmSnapshot.list( + self.userapiclient, + listall=self.services["listall"] + ) + # Verifying list size is 0 + self.assertIsNone( + list_vm_snaps_before, + "VM snapshots exists for newly created user" + ) + # Creating pagesize + 1 number of VM snapshots + for i in range(0, (self.services["pagesize"] + 1)): + snapshot_created = VmSnapshot.create( + self.userapiclient, + self.virtual_machine.id, + ) + self.assertIsNotNone( + snapshot_created, + "Snapshot creation failed" + ) + + # Listing all the VM snapshots for user again + list_vm_snaps_after = VmSnapshot.list( + self.userapiclient, + listall=self.services["listall"] + ) + status = validateList(list_vm_snaps_after) + self.assertEquals( + PASS, + status[0], + "VM snapshot creation failed" + ) + # Verifying that list size is pagesize + 1 + self.assertEquals( + self.services["pagesize"] + 1, + len(list_vm_snaps_after), + "Failed to create pagesize + 1 number of VM snapshots" + ) + # Listing all the VM snapshots in page 1 + list_vm_snaps_page1 = VmSnapshot.list( + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"] + ) + status = validateList(list_vm_snaps_page1) + self.assertEquals( + PASS, + status[0], + "Failed to list vm snapshots in page 1" + ) + # Verifying the list size to be equal to pagesize + self.assertEquals( + self.services["pagesize"], + len(list_vm_snaps_page1), + "Size of vm snapshots in page 1 is not matching" + ) + # Listing all the vm snapshots in page 2 + list_vm_snaps_page2 = VmSnapshot.list( + self.userapiclient, + listall=self.services["listall"], + page=2, + pagesize=self.services["pagesize"] + ) + status = validateList(list_vm_snaps_page2) + self.assertEquals( + PASS, + status[0], + "Failed to list vm snapshots in page 2" + ) + # Verifying the list size to be equal to pagesize + self.assertEquals( + 1, + len(list_vm_snaps_page2), + "Size of vm snapshots in page 2 is not matching" + ) + # Deleting the vm snapshot present in page 2 + VmSnapshot.deleteVMSnapshot( + self.userapiclient, + snapshot_created.id + ) + # Listing all the snapshots in page 2 again + list_vm_snaps_page2 = VmSnapshot.list( + self.userapiclient, + listall=self.services["listall"], + page=2, + pagesize=self.services["pagesize"] + ) + # Verifying that list size is 0 + self.assertIsNone( + list_vm_snaps_page2, + "VM snapshot not deleted from page 2" + ) + # Deleting all the existing VM snapshots + list_vm_snaps = VmSnapshot.list( + self.userapiclient, + listall=self.services["listall"], + ) + status = validateList(list_vm_snaps) + self.assertEquals( + PASS, + status[0], + "All VM snapshots deleted" + ) + # Verifying that list size is equal to page size + self.assertEquals( + self.services["pagesize"], + len(list_vm_snaps), + "VM Snapshots count is not matching" + ) + # Deleting all the existing VM snapshots + for i in range(0, len(list_vm_snaps)): + VmSnapshot.deleteVMSnapshot( + self.userapiclient, + list_vm_snaps[i].id + ) + return + + @attr(tags=["advanced", "basic", "provisioning"]) + def test_04_list_vm_snapshots_byid(self): + """ + @summary: Test to List VM Snapshots by Id + + Step1: Listing all the VM snapshots for a user + Step2: Verifying that list size is 0 + Step3: Creating a VM snapshot + Step4: Listing all the VM snapshots again for a user + Step5: Verifying that list size is 1 + Step6: Listing all the VM snapshots by specifying snapshot id + Step7: Verifying that list size is 1 + Step8: Verifying details of the listed VM snapshot + """ + # Listing all the VM snapshots for a User + list_vm_snaps_before = VmSnapshot.list( + self.userapiclient, + listall=self.services["listall"] + ) + # Verifying list size is 0 + self.assertIsNone( + list_vm_snaps_before, + "VM snapshots exists for newly created user" + ) + # Creating a VM snapshot + snapshot_created = VmSnapshot.create( + self.userapiclient, + self.virtual_machine.id, + ) + self.assertIsNotNone( + snapshot_created, + "Snapshot creation failed" + ) + # Listing all the VM snapshots for user again + list_vm_snaps_after = VmSnapshot.list( + self.userapiclient, + listall=self.services["listall"] + ) + status = validateList(list_vm_snaps_after) + self.assertEquals( + PASS, + status[0], + "VM snapshot creation failed" + ) + # Verifying that list size is 1 + self.assertEquals( + 1, + len(list_vm_snaps_after), + "Failed to create VM snapshot" + ) + # Listing vm snapshot by id + list_vm_snapshot = VmSnapshot.list( + self.userapiclient, + listall=self.services["listall"], + vmsnapshotid=snapshot_created.id + ) + status = validateList(list_vm_snapshot) + self.assertEquals( + PASS, + status[0], + "Failed to list VM snapshot by Id" + ) + # Verifying that list size is 1 + self.assertEquals( + 1, + len(list_vm_snapshot), + "Size of the list vm snapshot by Id is not matching" + ) + # Verifying details of the listed snapshot to be same as snapshot created above + #Creating expected and actual values dictionaries + expected_dict = { + "id":snapshot_created.id, + "name":snapshot_created.name, + "state":snapshot_created.state, + "vmid":snapshot_created.virtualmachineid, + } + actual_dict = { + "id":list_vm_snapshot[0].id, + "name":list_vm_snapshot[0].name, + "state":list_vm_snapshot[0].state, + "vmid":list_vm_snapshot[0].virtualmachineid, + } + vm_snapshot_status = self.__verify_values( + expected_dict, + actual_dict + ) + self.assertEqual( + True, + vm_snapshot_status, + "Listed VM Snapshot details are not as expected" + ) + return + +class TestSecurityGroups(cloudstackTestCase): + + @classmethod + def setUpClass(cls): + try: + cls._cleanup = [] + cls.testClient = super(TestSecurityGroups, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = cls.testClient.getParsedTestDataConfig() + # Get Domain, Zone, Template + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client) + cls.template = get_template( + cls.api_client, + cls.zone.id, + cls.services["ostype"] + ) + cls.services['mode'] = cls.zone.networktype + cls.account = Account.create( + cls.api_client, + cls.services["account"], + domainid=cls.domain.id + ) + # Getting authentication for user in newly created Account + cls.user = cls.account.user[0] + cls.userapiclient = cls.testClient.getUserApiClient(cls.user.username, cls.domain.name) + cls._cleanup.append(cls.account) + except Exception as e: + cls.tearDownClass() + raise Exception("Warning: Exception in setup : %s" % e) + return + + def setUp(self): + + self.apiClient = self.testClient.getApiClient() + self.cleanup = [] + + def tearDown(self): + #Clean up, terminate the created resources + cleanup_resources(self.apiClient, self.cleanup) + return + + @classmethod + def tearDownClass(cls): + try: + cleanup_resources(cls.api_client, cls._cleanup) + except Exception as e: + raise Exception("Warning: Exception during cleanup : %s" % e) + + return + + def __verify_values(self, expected_vals, actual_vals): + """ + @Desc: Function to verify expected and actual values + @Steps: + Step1: Initializing return flag to True + Step1: Verifying length of expected and actual dictionaries is matching. + If not matching returning false + Step2: Listing all the keys from expected dictionary + Step3: Looping through each key from step2 and verifying expected and actual dictionaries have same value + If not making return flag to False + Step4: returning the return flag after all the values are verified + """ + return_flag = True + + if len(expected_vals) != len(actual_vals): + return False + + keys = expected_vals.keys() + for i in range(0, len(expected_vals)): + exp_val = expected_vals[keys[i]] + act_val = actual_vals[keys[i]] + if exp_val == act_val: + return_flag = return_flag and True + else: + return_flag = return_flag and False + self.debug("expected Value: %s, is not matching with actual value: %s" % ( + exp_val, + act_val + )) + return return_flag + + @attr(tags=["basic", "provisioning"]) + def test_01_list_securitygroups_pagination(self): + """ + @Desc: Test to List Security Groups pagination + @steps: + Step1: Listing all the Security Groups for a user + Step2: Verifying that list size is 1 + Step3: Creating (page size) number of Security Groups + Step4: Listing all the Security Groups again for a user + Step5: Verifying that list size is (page size + 1) + Step6: Listing all the Security Groups in page1 + Step7: Verifying that list size is (page size) + Step8: Listing all the Security Groups in page2 + Step9: Verifying that list size is 1 + Step10: Deleting the Security Group present in page 2 + Step11: Listing all the Security Groups in page2 + Step12: Verifying that no security groups are listed + """ + # Listing all the Security Groups for a User + list_securitygroups_before = SecurityGroup.list( + self.userapiclient, + listall=self.services["listall"] + ) + # Verifying that default security group is created + status = validateList(list_securitygroups_before) + self.assertEquals( + PASS, + status[0], + "Default Security Groups creation failed" + ) + # Verifying the size of the list is 1 + self.assertEquals( + 1, + len(list_securitygroups_before), + "Count of Security Groups list is not matching" + ) + # Creating pagesize number of security groups + for i in range(0, (self.services["pagesize"])): + securitygroup_created = SecurityGroup.create( + self.userapiclient, + self.services["security_group"], + account=self.account.name, + domainid=self.domain.id, + description=self.services["security_group"]["name"] + ) + self.assertIsNotNone( + securitygroup_created, + "Security Group creation failed" + ) + if (i < self.services["pagesize"]): + self.cleanup.append(securitygroup_created) + + # Listing all the security groups for user again + list_securitygroups_after = SecurityGroup.list( + self.userapiclient, + listall=self.services["listall"] + ) + status = validateList(list_securitygroups_after) + self.assertEquals( + PASS, + status[0], + "Security Groups creation failed" + ) + # Verifying that list size is pagesize + 1 + self.assertEquals( + self.services["pagesize"] + 1, + len(list_securitygroups_after), + "Failed to create pagesize + 1 number of Security Groups" + ) + # Listing all the security groups in page 1 + list_securitygroups_page1 = SecurityGroup.list( + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"] + ) + status = validateList(list_securitygroups_page1) + self.assertEquals( + PASS, + status[0], + "Failed to list security groups in page 1" + ) + # Verifying the list size to be equal to pagesize + self.assertEquals( + self.services["pagesize"], + len(list_securitygroups_page1), + "Size of security groups in page 1 is not matching" + ) + # Listing all the security groups in page 2 + list_securitygroups_page2 = SecurityGroup.list( + self.userapiclient, + listall=self.services["listall"], + page=2, + pagesize=self.services["pagesize"] + ) + status = validateList(list_securitygroups_page2) + self.assertEquals( + PASS, + status[0], + "Failed to list security groups in page 2" + ) + # Verifying the list size to be equal to pagesize + self.assertEquals( + 1, + len(list_securitygroups_page2), + "Size of security groups in page 2 is not matching" + ) + # Deleting the security group present in page 2 + SecurityGroup.delete( + securitygroup_created, + self.userapiclient) + # Listing all the security groups in page 2 again + list_securitygroups_page2 = SecurityGroup.list( + self.userapiclient, + listall=self.services["listall"], + page=2, + pagesize=self.services["pagesize"] + ) + # Verifying that there are no security groups listed + self.assertIsNone( + list_securitygroups_page2, + "Security Groups not deleted from page 2" + ) + return + + @attr(tags=["basic", "provisioning"]) + def test_02_securitygroups_authorize_revoke_ingress(self): + """ + @Desc: Test to Authorize and Revoke Ingress for Security Group + @steps: + Step1: Listing all the Security Groups for a user + Step2: Verifying that list size is 1 + Step3: Creating a Security Groups + Step4: Listing all the Security Groups again for a user + Step5: Verifying that list size is 2 + Step6: Authorizing Ingress for the security group created in step3 + Step7: Listing the security groups by passing id of security group created in step3 + Step8: Verifying that list size is 1 + Step9: Verifying that Ingress is authorized to the security group + Step10: Verifying the details of the Ingress rule are as expected + Step11: Revoking Ingress for the security group created in step3 + Step12: Listing the security groups by passing id of security group created in step3 + Step13: Verifying that list size is 1 + Step14: Verifying that Ingress is revoked from the security group + """ + # Listing all the Security Groups for a User + list_securitygroups_before = SecurityGroup.list( + self.userapiclient, + listall=self.services["listall"] + ) + # Verifying that default security group is created + status = validateList(list_securitygroups_before) + self.assertEquals( + PASS, + status[0], + "Default Security Groups creation failed" + ) + # Verifying the size of the list is 1 + self.assertEquals( + 1, + len(list_securitygroups_before), + "Count of Security Groups list is not matching" + ) + # Creating a security group + securitygroup_created = SecurityGroup.create( + self.userapiclient, + self.services["security_group"], + account=self.account.name, + domainid=self.domain.id, + description=self.services["security_group"]["name"] + ) + self.assertIsNotNone( + securitygroup_created, + "Security Group creation failed" + ) + self.cleanup.append(securitygroup_created) + + # Listing all the security groups for user again + list_securitygroups_after = SecurityGroup.list( + self.userapiclient, + listall=self.services["listall"] + ) + status = validateList(list_securitygroups_after) + self.assertEquals( + PASS, + status[0], + "Security Groups creation failed" + ) + # Verifying that list size is 2 + self.assertEquals( + 2, + len(list_securitygroups_after), + "Failed to create Security Group" + ) + # Authorizing Ingress for the security group created in step3 + securitygroup_created.authorize( + self.userapiclient, + self.services["ingress_rule"], + self.account.name, + self.domain.id, + ) + # Listing the security group by Id + list_securitygroups_byid = SecurityGroup.list( + self.userapiclient, + listall=self.services["listall"], + id=securitygroup_created.id, + domainid=self.domain.id + ) + # Verifying that security group is listed + status = validateList(list_securitygroups_byid) + self.assertEquals( + PASS, + status[0], + "Listing of Security Groups by id failed" + ) + # Verifying size of the list is 1 + self.assertEquals( + 1, + len(list_securitygroups_byid), + "Count of the listing security group by id is not matching" + ) + securitygroup_ingress = list_securitygroups_byid[0].ingressrule + # Validating the Ingress rule + status = validateList(securitygroup_ingress) + self.assertEquals( + PASS, + status[0], + "Security Groups Ingress rule authorization failed" + ) + self.assertEquals( + 1, + len(securitygroup_ingress), + "Security Group Ingress rules count is not matching" + ) + # Verifying the details of the Ingress rule are as expected + #Creating expected and actual values dictionaries + expected_dict = { + "cidr":self.services["ingress_rule"]["cidrlist"], + "protocol":self.services["ingress_rule"]["protocol"], + "startport":self.services["ingress_rule"]["startport"], + "endport":self.services["ingress_rule"]["endport"], + } + actual_dict = { + "cidr":str(securitygroup_ingress[0].cidr), + "protocol":str(securitygroup_ingress[0].protocol.upper()), + "startport":str(securitygroup_ingress[0].startport), + "endport":str(securitygroup_ingress[0].endport), + } + ingress_status = self.__verify_values( + expected_dict, + actual_dict + ) + self.assertEqual( + True, + ingress_status, + "Listed Security group Ingress rule details are not as expected" + ) + # Revoking the Ingress rule from Security Group + securitygroup_created.revoke(self.userapiclient, securitygroup_ingress[0].ruleid) + # Listing the security group by Id + list_securitygroups_byid = SecurityGroup.list( + self.userapiclient, + listall=self.services["listall"], + id=securitygroup_created.id, + domainid=self.domain.id + ) + # Verifying that security group is listed + status = validateList(list_securitygroups_byid) + self.assertEquals( + PASS, + status[0], + "Listing of Security Groups by id failed" + ) + # Verifying size of the list is 1 + self.assertEquals( + 1, + len(list_securitygroups_byid), + "Count of the listing security group by id is not matching" + ) + securitygroup_ingress = list_securitygroups_byid[0].ingressrule + # Verifying that Ingress rule is empty(revoked) + status = validateList(securitygroup_ingress) + self.assertEquals( + EMPTY_LIST, + status[2], + "Security Groups Ingress rule is not revoked" + ) + return + + @attr(tags=["basic", "provisioning"]) + def test_03_securitygroups_authorize_revoke_egress(self): + """ + @Desc: Test to Authorize and Revoke Egress for Security Group + @steps: + Step1: Listing all the Security Groups for a user + Step2: Verifying that list size is 1 + Step3: Creating a Security Groups + Step4: Listing all the Security Groups again for a user + Step5: Verifying that list size is 2 + Step6: Authorizing Egress for the security group created in step3 + Step7: Listing the security groups by passing id of security group created in step3 + Step8: Verifying that list size is 1 + Step9: Verifying that Egress is authorized to the security group + Step10: Verifying the details of the Egress rule are as expected + Step11: Revoking Egress for the security group created in step3 + Step12: Listing the security groups by passing id of security group created in step3 + Step13: Verifying that list size is 1 + Step14: Verifying that Egress is revoked from the security group + """ + # Listing all the Security Groups for a User + list_securitygroups_before = SecurityGroup.list( + self.userapiclient, + listall=self.services["listall"] + ) + # Verifying that default security group is created + status = validateList(list_securitygroups_before) + self.assertEquals( + PASS, + status[0], + "Default Security Groups creation failed" + ) + # Verifying the size of the list is 1 + self.assertEquals( + 1, + len(list_securitygroups_before), + "Count of Security Groups list is not matching" + ) + # Creating a security group + securitygroup_created = SecurityGroup.create( + self.userapiclient, + self.services["security_group"], + account=self.account.name, + domainid=self.domain.id, + description=self.services["security_group"]["name"] + ) + self.assertIsNotNone( + securitygroup_created, + "Security Group creation failed" + ) + self.cleanup.append(securitygroup_created) + + # Listing all the security groups for user again + list_securitygroups_after = SecurityGroup.list( + self.userapiclient, + listall=self.services["listall"] + ) + status = validateList(list_securitygroups_after) + self.assertEquals( + PASS, + status[0], + "Security Groups creation failed" + ) + # Verifying that list size is 2 + self.assertEquals( + 2, + len(list_securitygroups_after), + "Failed to create Security Group" + ) + # Authorizing Egress for the security group created in step3 + securitygroup_created.authorizeEgress( + self.userapiclient, + self.services["ingress_rule"], + self.account.name, + self.domain.id, + ) + # Listing the security group by Id + list_securitygroups_byid = SecurityGroup.list( + self.userapiclient, + listall=self.services["listall"], + id=securitygroup_created.id, + domainid=self.domain.id + ) + # Verifying that security group is listed + status = validateList(list_securitygroups_byid) + self.assertEquals( + PASS, + status[0], + "Listing of Security Groups by id failed" + ) + # Verifying size of the list is 1 + self.assertEquals( + 1, + len(list_securitygroups_byid), + "Count of the listing security group by id is not matching" + ) + securitygroup_egress = list_securitygroups_byid[0].egressrule + # Validating the Ingress rule + status = validateList(securitygroup_egress) + self.assertEquals( + PASS, + status[0], + "Security Groups Egress rule authorization failed" + ) + self.assertEquals( + 1, + len(securitygroup_egress), + "Security Group Egress rules count is not matching" + ) + # Verifying the details of the Egress rule are as expected + #Creating expected and actual values dictionaries + expected_dict = { + "cidr":self.services["ingress_rule"]["cidrlist"], + "protocol":self.services["ingress_rule"]["protocol"], + "startport":self.services["ingress_rule"]["startport"], + "endport":self.services["ingress_rule"]["endport"], + } + actual_dict = { + "cidr":str(securitygroup_egress[0].cidr), + "protocol":str(securitygroup_egress[0].protocol.upper()), + "startport":str(securitygroup_egress[0].startport), + "endport":str(securitygroup_egress[0].endport), + } + ingress_status = self.__verify_values( + expected_dict, + actual_dict + ) + self.assertEqual( + True, + ingress_status, + "Listed Security group Egress rule details are not as expected" + ) + # Revoking the Egress rule from Security Group + securitygroup_created.revokeEgress(self.userapiclient, securitygroup_egress[0].ruleid) + # Listing the security group by Id + list_securitygroups_byid = SecurityGroup.list( + self.userapiclient, + listall=self.services["listall"], + id=securitygroup_created.id, + domainid=self.domain.id + ) + # Verifying that security group is listed + status = validateList(list_securitygroups_byid) + self.assertEquals( + PASS, + status[0], + "Listing of Security Groups by id failed" + ) + # Verifying size of the list is 1 + self.assertEquals( + 1, + len(list_securitygroups_byid), + "Count of the listing security group by id is not matching" + ) + securitygroup_egress = list_securitygroups_byid[0].egressrule + # Verifying that Ingress rule is empty(revoked) + status = validateList(securitygroup_egress) + self.assertEquals( + EMPTY_LIST, + status[2], + "Security Groups Egress rule is not revoked" + ) + return + +class TestVpnCustomerGateways(cloudstackTestCase): + + @classmethod + def setUpClass(cls): + try: + cls._cleanup = [] + cls.testClient = super(TestVpnCustomerGateways, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = cls.testClient.getParsedTestDataConfig() + # Get Domain, Zone, Template + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client) + cls.template = get_template( + cls.api_client, + cls.zone.id, + cls.services["ostype"] + ) + cls.services['mode'] = cls.zone.networktype + cls.account = Account.create( + cls.api_client, + cls.services["account"], + domainid=cls.domain.id + ) + # Getting authentication for user in newly created Account + cls.user = cls.account.user[0] + cls.userapiclient = cls.testClient.getUserApiClient(cls.user.username, cls.domain.name) + cls._cleanup.append(cls.account) + except Exception as e: + cls.tearDownClass() + raise Exception("Warning: Exception in setup : %s" % e) + return + + def setUp(self): + + self.apiClient = self.testClient.getApiClient() + self.cleanup = [] + + def tearDown(self): + #Clean up, terminate the created resources + cleanup_resources(self.apiClient, self.cleanup) + return + + @classmethod + def tearDownClass(cls): + try: + cleanup_resources(cls.api_client, cls._cleanup) + except Exception as e: + raise Exception("Warning: Exception during cleanup : %s" % e) + + return + + def __verify_values(self, expected_vals, actual_vals): + """ + @Desc: Function to verify expected and actual values + @Steps: + Step1: Initializing return flag to True + Step1: Verifying length of expected and actual dictionaries is matching. + If not matching returning false + Step2: Listing all the keys from expected dictionary + Step3: Looping through each key from step2 and verifying expected and actual dictionaries have same value + If not making return flag to False + Step4: returning the return flag after all the values are verified + """ + return_flag = True + + if len(expected_vals) != len(actual_vals): + return False + + keys = expected_vals.keys() + for i in range(0, len(expected_vals)): + exp_val = expected_vals[keys[i]] + act_val = actual_vals[keys[i]] + if exp_val == act_val: + return_flag = return_flag and True + else: + return_flag = return_flag and False + self.debug("expected Value: %s, is not matching with actual value: %s" % ( + exp_val, + act_val + )) + return return_flag + + @attr(tags=["advanced", "basic", "provisioning"]) + def test_01_list_vpncustomergateways_pagination(self): + """ + @Desc: Test to List VPN Customer Gateways pagination + @steps: + Step1: Listing all the VPN Customer Gateways for a user + Step2: Verifying that no VPN Customer Gateways are listed + Step3: Creating (page size + 1) number of VPN Customer Gateways + Step4: Listing all the VPN Customer Gateways again for a user + Step5: Verifying that list size is (page size + 1) + Step6: Listing all the VPN Customer Gateways in page1 + Step7: Verifying that list size is (page size) + Step8: Listing all the VPN Customer Gateways in page2 + Step9: Verifying that list size is 1 + Step10: Deleting the VPN Customer Gateways present in page 2 + Step11: Listing all the VPN Customer Gateways in page2 + Step12: Verifying that no VPN Customer Gateways are listed + """ + # Listing all the VPN Customer Gateways for a User + list_vpncustomergateways_before = VpnCustomerGateway.list( + self.userapiclient, + listall=self.services["listall"] + ) + # Verifying that no VPN Customer Gateways are listed + self.assertIsNone( + list_vpncustomergateways_before, + "VPN Customer Gateways listed for newly created User" + ) + # Creating pagesize + 1 number of VPN Customer Gateways + for i in range(0, (self.services["pagesize"] + 1)): + vpncustomergateway_created = VpnCustomerGateway.create( + self.userapiclient, + self.services["vpncustomergateway"], + name="VPNCustGateway"+str(i+1), + gateway="10.102.153." + str(i+1), + cidrlist="10.0.0.0/24", + account=self.account.name, + domainid=self.domain.id + ) + self.assertIsNotNone( + vpncustomergateway_created, + "VPN Customer Gateway creation failed" + ) + if (i < self.services["pagesize"] + 1): + self.cleanup.append(vpncustomergateway_created) + + # Listing all the VPN Customer Gateways for a User + list_vpncustomergateways_after = VpnCustomerGateway.list( + self.userapiclient, + listall=self.services["listall"] + ) + status = validateList(list_vpncustomergateways_after) + self.assertEquals( + PASS, + status[0], + "VPN Customer Gateway creation failed" + ) + # Verifying that list size is pagesize + 1 + self.assertEquals( + self.services["pagesize"] + 1, + len(list_vpncustomergateways_after), + "Failed to create pagesize + 1 number of VPN Customer Gateways" + ) + # Listing all the VPN Customer Gateways in page 1 + list_vpncustomergateways_page1 = VpnCustomerGateway.list( + self.userapiclient, + listall=self.services["listall"], + page=1, + pagesize=self.services["pagesize"] + ) + status = validateList(list_vpncustomergateways_page1) + self.assertEquals( + PASS, + status[0], + "Failed to list VPN Customer Gateways in page 1" + ) + # Verifying the list size to be equal to pagesize + self.assertEquals( + self.services["pagesize"], + len(list_vpncustomergateways_page1), + "Size of VPN Customer Gateways in page 1 is not matching" + ) + # Listing all the VPN Customer Gateways in page 2 + list_vpncustomergateways_page2 = VpnCustomerGateway.list( + self.userapiclient, + listall=self.services["listall"], + page=2, + pagesize=self.services["pagesize"] + ) + status = validateList(list_vpncustomergateways_page2) + self.assertEquals( + PASS, + status[0], + "Failed to list VPN Customer Gateways in page 2" + ) + # Verifying the list size to be equal to 1 + self.assertEquals( + 1, + len(list_vpncustomergateways_page2), + "Size of VPN Customer Gateways in page 2 is not matching" + ) + # Deleting the VPM Customer Gateway present in page 2 + VpnCustomerGateway.delete( + vpncustomergateway_created, + self.userapiclient + ) + # Listing all the VPN Customer Gateways in page 2 again + list_vpncustomergateways_page2 = VpnCustomerGateway.list( + self.userapiclient, + listall=self.services["listall"], + page=2, + pagesize=self.services["pagesize"] + ) + # Verifying that there are no VPN Customer Gateways listed + self.assertIsNone( + list_vpncustomergateways_page2, + "VPN Customer Gateways not deleted from page 2" + ) + return + + @attr(tags=["advanced", "basic", "provisioning"]) + def test_02_update_vpncustomergateways(self): + """ + @Desc: Test to update VPN Customer Gateways pagination + @steps: + Step1: Listing all the VPN Customer Gateways for a user + Step2: Verifying that no VPN Customer Gateways are listed + Step3: Creating a VPN Customer Gateways + Step4: Listing all the VPN Customer Gateways again for a user + Step5: Verifying that list size is 1 + Step6: Updating the VPN Customer Gateways created in step3 + Step7: Listing the VPN customer gateway by id + Step8: Verifying that list size is 1 + Step9: Verifying the details of the listed VPN customer gateway are same as updated in step6 + """ + # Listing all the VPN Customer Gateways for a User + list_vpncustomergateways_before = VpnCustomerGateway.list( + self.userapiclient, + listall=self.services["listall"] + ) + # Verifying that no VPN Customer Gateways are listed + self.assertIsNone( + list_vpncustomergateways_before, + "VPN Customer Gateways listed for newly created User" + ) + # Creating A VPN Customer Gateways + vpncustomergateway_created = VpnCustomerGateway.create( + self.userapiclient, + self.services["vpncustomergateway"], + name="VPNCustGateway", + gateway="10.102.153.90", + cidrlist="10.0.0.0/24", + account=self.account.name, + domainid=self.domain.id + ) + self.assertIsNotNone( + vpncustomergateway_created, + "VPN Customer Gateway creation failed" + ) + self.cleanup.append(vpncustomergateway_created) + # Listing all the VPN Customer Gateways for a User + list_vpncustomergateways_after = VpnCustomerGateway.list( + self.userapiclient, + listall=self.services["listall"] + ) + status = validateList(list_vpncustomergateways_after) + self.assertEquals( + PASS, + status[0], + "VPN Customer Gateway creation failed" + ) + # Verifying that list size is 1 + self.assertEquals( + 1, + len(list_vpncustomergateways_after), + "Failed to create VPN Customer Gateways" + ) + # Updating the VPN Customer gateway + vpncustomergateway_updated = VpnCustomerGateway.update( + vpncustomergateway_created, + self.userapiclient, + self.services["vpncustomergateway"], + name="NewVPNCustGateway", + gateway="10.102.153.90", + cidrlist="10.0.0.0/24", + ) + self.assertIsNotNone( + vpncustomergateway_updated, + "Updation of VPN Customer Gateway failed" + ) + # Listing the VPN Customer Gateways by Id + list_vpncustomergateway = VpnCustomerGateway.list( + self.userapiclient, + listall=self.services["listall"], + id=vpncustomergateway_created.id + ) + status = validateList(list_vpncustomergateway) + self.assertEquals( + PASS, + status[0], + "Failed to list VPN Customer Gateways by Id" + ) + # Verifying the list size to be equal to 1 + self.assertEquals( + 1, + len(list_vpncustomergateway), + "Size of VPN Customer Gateways by id is not matching" + ) + # Verifying the details of the listed VPN Customer Gateway are same as updated + #Creating expected and actual values dictionaries + expected_dict = { + "name":vpncustomergateway_updated.name, + "id":vpncustomergateway_updated.id, + "account":vpncustomergateway_updated.account, + "domainid":vpncustomergateway_updated.domainid, + "gateway":vpncustomergateway_updated.gateway, + "cidrlist":vpncustomergateway_updated.cidrlist, + "seckey":vpncustomergateway_updated.ipsecpsk, + "ikepolicy":vpncustomergateway_updated.ikepolicy, + "ikelifetime":vpncustomergateway_updated.ikelifetime, + "esppolicy":vpncustomergateway_updated.esppolicy, + "esplifetime":vpncustomergateway_updated.esplifetime, + } + actual_dict = { + "name":list_vpncustomergateway[0].name, + "id":list_vpncustomergateway[0].id, + "account":list_vpncustomergateway[0].account, + "domainid":list_vpncustomergateway[0].domainid, + "gateway":list_vpncustomergateway[0].gateway, + "cidrlist":list_vpncustomergateway[0].cidrlist, + "seckey":list_vpncustomergateway[0].ipsecpsk, + "ikepolicy":list_vpncustomergateway[0].ikepolicy, + "ikelifetime":list_vpncustomergateway[0].ikelifetime, + "esppolicy":list_vpncustomergateway[0].esppolicy, + "esplifetime":list_vpncustomergateway[0].esplifetime, + } + vpncustomergateway_status = self.__verify_values( + expected_dict, + actual_dict + ) + self.assertEqual( + True, + vpncustomergateway_status, + "Listed VPN Customer Gateway details are not as Updated" + ) + return + +class TestTemplates(cloudstackTestCase): + + @classmethod + def setUpClass(cls): + try: + cls._cleanup = [] + cls.testClient = super(TestTemplates, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = cls.testClient.getParsedTestDataConfig() + # Get Domain, Zone, Template + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client) + cls.template = get_template( + cls.api_client, + cls.zone.id, + cls.services["ostype"] + ) + cls.hypervisor = cls.testClient.getHypervisorInfo() + cls.services['mode'] = cls.zone.networktype + cls.account = Account.create( + cls.api_client, + cls.services["account"], + domainid=cls.domain.id + ) + # Getting authentication for user in newly created Account + cls.user = cls.account.user[0] + cls.userapiclient = cls.testClient.getUserApiClient(cls.user.username, cls.domain.name) + cls._cleanup.append(cls.account) + except Exception as e: + cls.tearDownClass() + raise Exception("Warning: Exception in setup : %s" % e) + return + + def setUp(self): + + self.apiClient = self.testClient.getApiClient() + self.cleanup = [] + + def tearDown(self): + #Clean up, terminate the created resources + cleanup_resources(self.apiClient, self.cleanup) + return + + @classmethod + def tearDownClass(cls): + try: + cleanup_resources(cls.api_client, cls._cleanup) + except Exception as e: + raise Exception("Warning: Exception during cleanup : %s" % e) + + return + + def __verify_values(self, expected_vals, actual_vals): + """ + @Desc: Function to verify expected and actual values + @Steps: + Step1: Initializing return flag to True + Step1: Verifying length of expected and actual dictionaries is matching. + If not matching returning false + Step2: Listing all the keys from expected dictionary + Step3: Looping through each key from step2 and verifying expected and actual dictionaries have same value + If not making return flag to False + Step4: returning the return flag after all the values are verified + """ + return_flag = True + + if len(expected_vals) != len(actual_vals): + return False + + keys = expected_vals.keys() + for i in range(0, len(expected_vals)): + exp_val = expected_vals[keys[i]] + act_val = actual_vals[keys[i]] + if exp_val == act_val: + return_flag = return_flag and True + else: + return_flag = return_flag and False + self.debug("expected Value: %s, is not matching with actual value: %s" % ( + exp_val, + act_val + )) + return return_flag + + @attr(tags=["advanced", "basic", "provisioning"]) + def test_01_list_templates_pagination(self): + """ + @Desc: Test to List Templates pagination + @steps: + Step1: Listing all the Templates for a user + Step2: Verifying that no Templates are listed + Step3: Creating (page size + 1) number of Templates + Step4: Listing all the Templates again for a user + Step5: Verifying that list size is (page size + 1) + Step6: Listing all the Templates in page1 + Step7: Verifying that list size is (page size) + Step8: Listing all the Templates in page2 + Step9: Verifying that list size is 1 + Step10: Listing the template by Id + Step11: Verifying if the template is downloaded and ready. + If yes the continuing + If not waiting and checking for template to be ready till timeout + Step12: Deleting the Template present in page 2 + Step13: Listing all the Templates in page2 + Step14: Verifying that no Templates are listed + """ + # Listing all the Templates for a User + list_templates_before = Template.list( + self.userapiclient, + listall=self.services["listall"], + templatefilter=self.services["templatefilter"] + ) + # Verifying that no Templates are listed + self.assertIsNone( + list_templates_before, + "Templates listed for newly created User" + ) + self.services["template"]["url"] = "http://10.147.28.7/templates/ttylinux_pv.vhd" + self.services["template"]["format"] = "VHD" + self.services["template"]["ostype"] = self.services["ostype"] + # Creating pagesize + 1 number of Templates + for i in range(0, (self.services["pagesize"] + 1)): + template_created = Template.register( + self.userapiclient, + self.services["template"], + self.zone.id, + hypervisor=self.hypervisor + ) + self.assertIsNotNone( + template_created, + "Template creation failed" + ) + if(i < self.services["pagesize"]): + self.cleanup.append(template_created) + + # Listing all the Templates for a User + list_templates_after = Template.list( + self.userapiclient, + listall=self.services["listall"], + templatefilter=self.services["templatefilter"] + ) + status = validateList(list_templates_after) + self.assertEquals( + PASS, + status[0], + "Templates creation failed" + ) + # Verifying that list size is pagesize + 1 + self.assertEquals( + self.services["pagesize"] + 1, + len(list_templates_after), + "Failed to create pagesize + 1 number of Templates" + ) + # Listing all the Templates in page 1 + list_templates_page1 = Template.list( + self.userapiclient, + listall=self.services["listall"], + templatefilter=self.services["templatefilter"], + page=1, + pagesize=self.services["pagesize"] + ) + status = validateList(list_templates_page1) + self.assertEquals( + PASS, + status[0], + "Failed to list Templates in page 1" + ) + # Verifying the list size to be equal to pagesize + self.assertEquals( + self.services["pagesize"], + len(list_templates_page1), + "Size of Templates in page 1 is not matching" + ) + # Listing all the Templates in page 2 + list_templates_page2 = Template.list( + self.userapiclient, + listall=self.services["listall"], + templatefilter=self.services["templatefilter"], + page=2, + pagesize=self.services["pagesize"] + ) + status = validateList(list_templates_page2) + self.assertEquals( + PASS, + status[0], + "Failed to list Templates in page 2" + ) + # Verifying the list size to be equal to 1 + self.assertEquals( + 1, + len(list_templates_page2), + "Size of Templates in page 2 is not matching" + ) + # Verifying the state of the template to be ready. If not waiting for state to become ready + template_ready = False + count = 0 + while template_ready is False: + list_template = Template.list( + self.userapiclient, + id=template_created.id, + listall=self.services["listall"], + templatefilter=self.services["templatefilter"], + ) + status = validateList(list_template) + self.assertEquals( + PASS, + status[0], + "Failed to list Templates by Id" + ) + if list_template[0].isready is True: + template_ready = True + elif (str(list_template[0].status) == "Error"): + self.fail("Created Template is in Errored state") + break + elif count > 10: + self.fail("Timed out before Template came into ready state") + break + else: + time.sleep(self.services["sleep"]) + count = count + 1 + + # Deleting the Template present in page 2 + Template.delete( + template_created, + self.userapiclient + ) + # Listing all the Templates in page 2 again + list_templates_page2 = Template.list( + self.userapiclient, + listall=self.services["listall"], + templatefilter=self.services["templatefilter"], + page=2, + pagesize=self.services["pagesize"] + ) + # Verifying that there are no Templates listed + self.assertIsNone( + list_templates_page2, + "Templates not deleted from page 2" + ) + del self.services["template"]["url"] + del self.services["template"]["format"] + del self.services["template"]["ostype"] + return + + @attr(tags=["advanced", "basic", "provisioning"]) + def test_02_download_template(self): + """ + @Desc: Test to Download Template + @steps: + Step1: Listing all the Templates for a user + Step2: Verifying that no Templates are listed + Step3: Creating a Templates + Step4: Listing all the Templates again for a user + Step5: Verifying that list size is 1 + Step6: Verifying if the template is in ready state. + If yes the continuing + If not waiting and checking for template to be ready till timeout + Step7: Downloading the template (Extract) + Step8: Verifying that Template is downloaded + """ + # Listing all the Templates for a User + list_templates_before = Template.list( + self.userapiclient, + listall=self.services["listall"], + templatefilter=self.services["templatefilter"] + ) + # Verifying that no Templates are listed + self.assertIsNone( + list_templates_before, + "Templates listed for newly created User" + ) + self.services["template"]["url"] = "http://10.147.28.7/templates/ttylinux_pv.vhd" + self.services["template"]["format"] = "VHD" + self.services["template"]["ostype"] = self.services["ostype"] + self.services["template"]["isextractable"] = True + # Creating aTemplate + template_created = Template.register( + self.userapiclient, + self.services["template"], + self.zone.id, + hypervisor=self.hypervisor + ) + self.assertIsNotNone( + template_created, + "Template creation failed" + ) + self.cleanup.append(template_created) + # Listing all the Templates for a User + list_templates_after = Template.list( + self.userapiclient, + listall=self.services["listall"], + templatefilter=self.services["templatefilter"] + ) + status = validateList(list_templates_after) + self.assertEquals( + PASS, + status[0], + "Templates creation failed" + ) + # Verifying that list size is 1 + self.assertEquals( + 1, + len(list_templates_after), + "Failed to create a Template" + ) + # Verifying the state of the template to be ready. If not waiting for state to become ready till time out + template_ready = False + count = 0 + while template_ready is False: + list_template = Template.list( + self.userapiclient, + id=template_created.id, + listall=self.services["listall"], + templatefilter=self.services["templatefilter"], + ) + status = validateList(list_template) + self.assertEquals( + PASS, + status[0], + "Failed to list Templates by Id" + ) + if list_template[0].isready is True: + template_ready = True + elif (str(list_template[0].status) == "Error"): + self.fail("Created Template is in Errored state") + break + elif count > 10: + self.fail("Timed out before Template came into ready state") + break + else: + time.sleep(self.services["sleep"]) + count = count + 1 + + # Downloading the Template name + download_template = Template.extract( + self.userapiclient, + template_created.id, + mode="HTTP_DOWNLOAD", + zoneid=self.zone.id + ) + self.assertIsNotNone( + download_template, + "Download Template failed" + ) + # Verifying the details of downloaded template + self.assertEquals( + "DOWNLOAD_URL_CREATED", + download_template.state, + "Download URL not created for Template" + ) + self.assertIsNotNone( + download_template.url, + "Download URL not created for Template" + ) + self.assertEquals( + template_created.id, + download_template.id, + "Download Template details are not same as Template created" + ) + del self.services["template"]["url"] + del self.services["template"]["format"] + del self.services["template"]["ostype"] + del self.services["template"]["isextractable"] + return + + @attr(tags=["advanced", "basic", "provisioning"]) + def test_03_edit_template_details(self): + """ + @Desc: Test to Edit Template name, displaytext, OSType + @steps: + Step1: Listing all the Templates for a user + Step2: Verifying that no Templates are listed + Step3: Creating a Templates + Step4: Listing all the Templates again for a user + Step5: Verifying that list size is 1 + Step6: Verifying if the template is in ready state. + If yes the continuing + If not waiting and checking for template to be ready till timeout + Step7: Editing the template name + Step8: Verifying that Template name is edited + Step9: Editing the template displaytext + Step10: Verifying that Template displaytext is edited + Step11: Editing the template ostypeid + Step12: Verifying that Template ostypeid is edited + Step13: Editing the template name, displaytext + Step14: Verifying that Template name, displaytext are edited + Step15: Editing the template name, displaytext, ostypeid + Step16: Verifying that Template name, displaytext and ostypeid are edited + """ + # Listing all the Templates for a User + list_templates_before = Template.list( + self.userapiclient, + listall=self.services["listall"], + templatefilter=self.services["templatefilter"] + ) + # Verifying that no Templates are listed + self.assertIsNone( + list_templates_before, + "Templates listed for newly created User" + ) + self.services["template"]["url"] = "http://10.147.28.7/templates/ttylinux_pv.vhd" + self.services["template"]["format"] = "VHD" + self.services["template"]["ostype"] = self.services["ostype"] + # Creating aTemplate + template_created = Template.register( + self.userapiclient, + self.services["template"], + self.zone.id, + hypervisor=self.hypervisor + ) + self.assertIsNotNone( + template_created, + "Template creation failed" + ) + self.cleanup.append(template_created) + # Listing all the Templates for a User + list_templates_after = Template.list( + self.userapiclient, + listall=self.services["listall"], + templatefilter=self.services["templatefilter"] + ) + status = validateList(list_templates_after) + self.assertEquals( + PASS, + status[0], + "Templates creation failed" + ) + # Verifying that list size is 1 + self.assertEquals( + 1, + len(list_templates_after), + "Failed to create a Template" + ) + # Verifying the state of the template to be ready. If not waiting for state to become ready till time out + template_ready = False + count = 0 + while template_ready is False: + list_template = Template.list( + self.userapiclient, + id=template_created.id, + listall=self.services["listall"], + templatefilter=self.services["templatefilter"], + ) + status = validateList(list_template) + self.assertEquals( + PASS, + status[0], + "Failed to list Templates by Id" + ) + if list_template[0].isready is True: + template_ready = True + elif (str(list_template[0].status) == "Error"): + self.fail("Created Template is in Errored state") + break + elif count > 10: + self.fail("Timed out before Template came into ready state") + break + else: + time.sleep(self.services["sleep"]) + count = count + 1 + + # Editing the Template name + edited_template = Template.update( + template_created, + self.userapiclient, + name="NewTemplateName" + ) + self.assertIsNotNone( + edited_template, + "Editing Template failed" + ) + # Verifying the details of edited template + expected_dict = { + "id":template_created.id, + "name":"NewTemplateName", + "displaytest":template_created.displaytext, + "account":template_created.account, + "domainid":template_created.domainid, + "format":template_created.format, + "ostypeid":template_created.ostypeid, + "templatetype":template_created.templatetype, + } + actual_dict = { + "id":edited_template.id, + "name":edited_template.name, + "displaytest":edited_template.displaytext, + "account":edited_template.account, + "domainid":edited_template.domainid, + "format":edited_template.format, + "ostypeid":edited_template.ostypeid, + "templatetype":edited_template.templatetype, + } + edit_template_status = self.__verify_values( + expected_dict, + actual_dict + ) + self.assertEqual( + True, + edit_template_status, + "Edited Template details are not as expected" + ) + # Editing the Template displaytext + edited_template = Template.update( + template_created, + self.userapiclient, + displaytext="TemplateDisplaytext" + ) + self.assertIsNotNone( + edited_template, + "Editing Template failed" + ) + # Verifying the details of edited template + expected_dict = { + "id":template_created.id, + "name":"NewTemplateName", + "displaytest":"TemplateDisplaytext", + "account":template_created.account, + "domainid":template_created.domainid, + "format":template_created.format, + "ostypeid":template_created.ostypeid, + "templatetype":template_created.templatetype, + } + actual_dict = { + "id":edited_template.id, + "name":edited_template.name, + "displaytest":edited_template.displaytext, + "account":edited_template.account, + "domainid":edited_template.domainid, + "format":edited_template.format, + "ostypeid":edited_template.ostypeid, + "templatetype":edited_template.templatetype, + } + edit_template_status = self.__verify_values( + expected_dict, + actual_dict + ) + self.assertEqual( + True, + edit_template_status, + "Edited Template details are not as expected" + ) + # Editing the Template ostypeid + ostype_list = list_os_types(self.userapiclient) + status = validateList(ostype_list) + self.assertEquals( + PASS, + status[0], + "Failed to list OS Types" + ) + for i in range(0, len(ostype_list)): + if ostype_list[i].id != template_created.ostypeid: + newostypeid = ostype_list[i].id + break + + edited_template = Template.update( + template_created, + self.userapiclient, + ostypeid=newostypeid + ) + self.assertIsNotNone( + edited_template, + "Editing Template failed" + ) + # Verifying the details of edited template + expected_dict = { + "id":template_created.id, + "name":"NewTemplateName", + "displaytest":"TemplateDisplaytext", + "account":template_created.account, + "domainid":template_created.domainid, + "format":template_created.format, + "ostypeid":newostypeid, + "templatetype":template_created.templatetype, + } + actual_dict = { + "id":edited_template.id, + "name":edited_template.name, + "displaytest":edited_template.displaytext, + "account":edited_template.account, + "domainid":edited_template.domainid, + "format":edited_template.format, + "ostypeid":edited_template.ostypeid, + "templatetype":edited_template.templatetype, + } + edit_template_status = self.__verify_values( + expected_dict, + actual_dict + ) + self.assertEqual( + True, + edit_template_status, + "Edited Template details are not as expected" + ) + # Editing the Template name, displaytext + edited_template = Template.update( + template_created, + self.userapiclient, + name=template_created.name, + displaytext=template_created.displaytext + ) + self.assertIsNotNone( + edited_template, + "Editing Template failed" + ) + # Verifying the details of edited template + expected_dict = { + "id":template_created.id, + "name":template_created.name, + "displaytest":template_created.displaytext, + "account":template_created.account, + "domainid":template_created.domainid, + "format":template_created.format, + "ostypeid":newostypeid, + "templatetype":template_created.templatetype, + } + actual_dict = { + "id":edited_template.id, + "name":edited_template.name, + "displaytest":edited_template.displaytext, + "account":edited_template.account, + "domainid":edited_template.domainid, + "format":edited_template.format, + "ostypeid":edited_template.ostypeid, + "templatetype":edited_template.templatetype, + } + edit_template_status = self.__verify_values( + expected_dict, + actual_dict + ) + self.assertEqual( + True, + edit_template_status, + "Edited Template details are not as expected" + ) + # Editing the Template name, displaytext, ostypeid + edited_template = Template.update( + template_created, + self.userapiclient, + name="NewTemplateName", + displaytext="TemplateDisplaytext", + ostypeid=template_created.ostypeid + ) + self.assertIsNotNone( + edited_template, + "Editing Template failed" + ) + # Verifying the details of edited template + expected_dict = { + "id":template_created.id, + "name":"NewTemplateName", + "displaytest":"TemplateDisplaytext", + "account":template_created.account, + "domainid":template_created.domainid, + "format":template_created.format, + "ostypeid":template_created.ostypeid, + "templatetype":template_created.templatetype, + } + actual_dict = { + "id":edited_template.id, + "name":edited_template.name, + "displaytest":edited_template.displaytext, + "account":edited_template.account, + "domainid":edited_template.domainid, + "format":edited_template.format, + "ostypeid":edited_template.ostypeid, + "templatetype":edited_template.templatetype, + } + edit_template_status = self.__verify_values( + expected_dict, + actual_dict + ) + self.assertEqual( + True, + edit_template_status, + "Edited Template details are not as expected" + ) + del self.services["template"]["url"] + del self.services["template"]["format"] + del self.services["template"]["ostype"] + return + + @attr(tags=["advanced", "basic", "provisioning"]) + def test_04_copy_template(self): + """ + @Desc: Test to copy Template from one zone to another + @steps: + Step1: Listing Zones available for a user + Step2: Verifying if the zones listed are greater than 1. + If Yes continuing. + If not halting the test. + Step3: Listing all the templates for a user in zone1 + Step4: Verifying that no templates are listed + Step5: Listing all the templates for a user in zone2 + Step6: Verifying that no templates are listed + Step7: Creating a Template in zone 1 + Step8: Listing all the Templates again for a user in zone1 + Step9: Verifying that list size is 1 + Step10: Listing all the templates for a user in zone2 + Step11: Verifying that no templates are listed + Step12: Copying the template created in step7 from zone1 to zone2 + Step13: Listing all the templates for a user in zone2 + Step14: Verifying that list size is 1 + Step15: Listing all the Templates for a user in zone1 + Step16: Verifying that list size is 1 + """ + # Listing Zones available for a user + zones_list = Zone.list( + self.userapiclient, + available=True + ) + status = validateList(zones_list) + self.assertEquals( + PASS, + status[0], + "Failed to list Zones" + ) + if not len(zones_list) > 1: + self.fail("Enough zones doesnot exists to copy template") + else: + # Listing all the Templates for a User in Zone 1 + list_templates_zone1 = Template.list( + self.userapiclient, + listall=self.services["listall"], + templatefilter=self.services["templatefilter"], + zoneid=zones_list[0].id + ) + # Verifying that no Templates are listed + self.assertIsNone( + list_templates_zone1, + "Templates listed for newly created User in Zone1" + ) + # Listing all the Templates for a User in Zone 2 + list_templates_zone2 = Template.list( + self.userapiclient, + listall=self.services["listall"], + templatefilter=self.services["templatefilter"], + zoneid=zones_list[1].id + ) + # Verifying that no Templates are listed + self.assertIsNone( + list_templates_zone2, + "Templates listed for newly created User in Zone2" + ) + self.services["template"]["url"] = "http://10.147.28.7/templates/ttylinux_pv.vhd" + self.services["template"]["format"] = "VHD" + self.services["template"]["ostype"] = self.services["ostype"] + #Listing Hypervisors in Zone 1 + hypervisor_list = Hypervisor.list( + self.apiClient, + zoneid=zones_list[0].id + ) + status = validateList(zones_list) + self.assertEquals( + PASS, + status[0], + "Failed to list Hypervisors in Zone 1" + ) + # Creating aTemplate in Zone 1 + template_created = Template.register( + self.userapiclient, + self.services["template"], + zones_list[0].id, + hypervisor=hypervisor_list[0].name + ) + self.assertIsNotNone( + template_created, + "Template creation failed" + ) + self.cleanup.append(template_created) + # Listing all the Templates for a User in Zone 1 + list_templates_zone1 = Template.list( + self.userapiclient, + listall=self.services["listall"], + templatefilter=self.services["templatefilter"], + zoneid=zones_list[0].id + ) + status = validateList(list_templates_zone1) + self.assertEquals( + PASS, + status[0], + "Templates creation failed in Zone1" + ) + # Verifying that list size is 1 + self.assertEquals( + 1, + len(list_templates_zone1), + "Failed to create a Template" + ) + # Listing all the Templates for a User in Zone 2 + list_templates_zone2 = Template.list( + self.userapiclient, + listall=self.services["listall"], + templatefilter=self.services["templatefilter"], + zoneid=zones_list[1].id + ) + # Verifying that no Templates are listed + self.assertIsNone( + list_templates_zone2, + "Templates listed for newly created User in Zone2" + ) + # Verifying the state of the template to be ready. If not waiting for state to become ready till time out + template_ready = False + count = 0 + while template_ready is False: + list_template = Template.list( + self.userapiclient, + id=template_created.id, + listall=self.services["listall"], + templatefilter=self.services["templatefilter"], + ) + status = validateList(list_template) + self.assertEquals( + PASS, + status[0], + "Failed to list Templates by Id" + ) + if list_template[0].isready is True: + template_ready = True + elif (str(list_template[0].status) == "Error"): + self.fail("Created Template is in Errored state") + break + elif count > 10: + self.fail("Timed out before Template came into ready state") + break + else: + time.sleep(self.services["sleep"]) + count = count + 1 + + # Copying the Template from Zone1 to Zone2 + copied_template = Template.copy( + self.userapiclient, + template_created.id, + sourcezoneid=template_created.zoneid, + destzoneid=zones_list[1].id + ) + self.assertIsNotNone( + copied_template, + "Copying Template from Zone1 to Zone2 failed" + ) + # Listing all the Templates for a User in Zone 1 + list_templates_zone1 = Template.list( + self.userapiclient, + listall=self.services["listall"], + templatefilter=self.services["templatefilter"], + zoneid=zones_list[0].id + ) + status = validateList(list_templates_zone1) + self.assertEquals( + PASS, + status[0], + "Templates creation failed in Zone1" + ) + # Verifying that list size is 1 + self.assertEquals( + 1, + len(list_templates_zone1), + "Failed to create a Template" + ) + # Listing all the Templates for a User in Zone 2 + list_templates_zone2 = Template.list( + self.userapiclient, + listall=self.services["listall"], + templatefilter=self.services["templatefilter"], + zoneid=zones_list[1].id + ) + status = validateList(list_templates_zone2) + self.assertEquals( + PASS, + status[0], + "Template failed to copy into Zone2" + ) + # Verifying that list size is 1 + self.assertEquals( + 1, + len(list_templates_zone2), + "Template failed to copy into Zone2" + ) + self.assertNotEquals( + "Connection refused", + list_templates_zone2[0].status, + "Failed to copy Template" + ) + self.assertEquals( + True, + list_templates_zone2[0].isready, + "Failed to copy Template" + ) + del self.services["template"]["url"] + del self.services["template"]["format"] + del self.services["template"]["ostype"] + return + +class TestIsos(cloudstackTestCase): + + @classmethod + def setUpClass(cls): + try: + cls._cleanup = [] + cls.testClient = super(TestIsos, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = cls.testClient.getParsedTestDataConfig() + # Get Domain, Zone, Template + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client) + cls.template = get_template( + cls.api_client, + cls.zone.id, + cls.services["ostype"] + ) + cls.hypervisor = cls.testClient.getHypervisorInfo() + cls.services['mode'] = cls.zone.networktype + cls.account = Account.create( + cls.api_client, + cls.services["account"], + domainid=cls.domain.id + ) + # Getting authentication for user in newly created Account + cls.user = cls.account.user[0] + cls.userapiclient = cls.testClient.getUserApiClient(cls.user.username, cls.domain.name) + cls._cleanup.append(cls.account) + except Exception as e: + cls.tearDownClass() + raise Exception("Warning: Exception in setup : %s" % e) + return + + def setUp(self): + + self.apiClient = self.testClient.getApiClient() + self.cleanup = [] + + def tearDown(self): + #Clean up, terminate the created resources + cleanup_resources(self.apiClient, self.cleanup) + return + + @classmethod + def tearDownClass(cls): + try: + cleanup_resources(cls.api_client, cls._cleanup) + except Exception as e: + raise Exception("Warning: Exception during cleanup : %s" % e) + + return + + def __verify_values(self, expected_vals, actual_vals): + """ + @Desc: Function to verify expected and actual values + @Steps: + Step1: Initializing return flag to True + Step1: Verifying length of expected and actual dictionaries is matching. + If not matching returning false + Step2: Listing all the keys from expected dictionary + Step3: Looping through each key from step2 and verifying expected and actual dictionaries have same value + If not making return flag to False + Step4: returning the return flag after all the values are verified + """ + return_flag = True + + if len(expected_vals) != len(actual_vals): + return False + + keys = expected_vals.keys() + for i in range(0, len(expected_vals)): + exp_val = expected_vals[keys[i]] + act_val = actual_vals[keys[i]] + if exp_val == act_val: + return_flag = return_flag and True + else: + return_flag = return_flag and False + self.debug("expected Value: %s, is not matching with actual value: %s" % ( + exp_val, + act_val + )) + return return_flag + + @attr(tags=["advanced", "basic", "provisioning"]) + def test_01_list_isos_pagination(self): + """ + @Desc: Test to List ISO's pagination + @steps: + Step1: Listing all the ISO's for a user + Step2: Verifying that no ISO's are listed + Step3: Creating (page size + 1) number of ISO's + Step4: Listing all the ISO's again for a user + Step5: Verifying that list size is (page size + 1) + Step6: Listing all the ISO's in page1 + Step7: Verifying that list size is (page size) + Step8: Listing all the ISO's in page2 + Step9: Verifying that list size is 1 + Step10: Listing the ISO's by Id + Step11: Verifying if the ISO is downloaded and ready. + If yes the continuing + If not waiting and checking for iso to be ready till timeout + Step12: Deleting the ISO present in page 2 + Step13: Listing all the ISO's in page2 + Step14: Verifying that no ISO's are listed + """ + # Listing all the ISO's for a User + list_iso_before = Iso.list( + self.userapiclient, + listall=self.services["listall"], + isofilter=self.services["templatefilter"] + ) + # Verifying that no ISOs are listed + self.assertIsNone( + list_iso_before, + "ISOs listed for newly created User" + ) + self.services["iso"]["zoneid"] = self.zone.id + # Creating pagesize + 1 number of ISO's + for i in range(0, (self.services["pagesize"] + 1)): + iso_created = Iso.create( + self.userapiclient, + self.services["iso"] + ) + self.assertIsNotNone( + iso_created, + "ISO creation failed" + ) + if(i < self.services["pagesize"]): + self.cleanup.append(iso_created) + + # Listing all the ISO's for a User + list_iso_after = Iso.list( + self.userapiclient, + listall=self.services["listall"], + isofilter=self.services["templatefilter"] + ) + status = validateList(list_iso_after) + self.assertEquals( + PASS, + status[0], + "ISO's creation failed" + ) + # Verifying that list size is pagesize + 1 + self.assertEquals( + self.services["pagesize"] + 1, + len(list_iso_after), + "Failed to create pagesize + 1 number of ISO's" + ) + # Listing all the ISO's in page 1 + list_iso_page1 = Iso.list( + self.userapiclient, + listall=self.services["listall"], + isofilter=self.services["templatefilter"], + page=1, + pagesize=self.services["pagesize"] + ) + status = validateList(list_iso_page1) + self.assertEquals( + PASS, + status[0], + "Failed to list ISO's in page 1" + ) + # Verifying the list size to be equal to pagesize + self.assertEquals( + self.services["pagesize"], + len(list_iso_page1), + "Size of ISO's in page 1 is not matching" + ) + # Listing all the Templates in page 2 + list_iso_page2 = Iso.list( + self.userapiclient, + listall=self.services["listall"], + isofilter=self.services["templatefilter"], + page=2, + pagesize=self.services["pagesize"] + ) + status = validateList(list_iso_page2) + self.assertEquals( + PASS, + status[0], + "Failed to list ISo's in page 2" + ) + # Verifying the list size to be equal to 1 + self.assertEquals( + 1, + len(list_iso_page2), + "Size of ISO's in page 2 is not matching" + ) + # Verifying the state of the ISO to be ready. If not waiting for state to become ready + iso_ready = False + count = 0 + while iso_ready is False: + list_iso = Iso.list( + self.userapiclient, + listall=self.services["listall"], + isofilter=self.services["templatefilter"], + id=iso_created.id + ) + status = validateList(list_iso) + self.assertEquals( + PASS, + status[0], + "Failed to list ISO by Id" + ) + if list_iso[0].isready is True: + iso_ready = True + elif (str(list_iso[0].status) == "Error"): + self.fail("Created ISO is in Errored state") + break + elif count > 10: + self.fail("Timed out before ISO came into ready state") + break + else: + time.sleep(self.services["sleep"]) + count = count + 1 + + # Deleting the ISO present in page 2 + Iso.delete( + iso_created, + self.userapiclient + ) + # Listing all the ISO's in page 2 again + list_iso_page2 = Iso.list( + self.userapiclient, + listall=self.services["listall"], + isofilter=self.services["templatefilter"], + page=2, + pagesize=self.services["pagesize"] + ) + # Verifying that there are no ISO's listed + self.assertIsNone( + list_iso_page2, + "ISO's not deleted from page 2" + ) + del self.services["iso"]["zoneid"] + return + + @attr(tags=["advanced", "basic", "provisioning"]) + def test_02_download_iso(self): + """ + @Desc: Test to Download ISO + @steps: + Step1: Listing all the ISO's for a user + Step2: Verifying that no ISO's are listed + Step3: Creating an ISO + Step4: Listing all the ISO's again for a user + Step5: Verifying that list size is 1 + Step6: Verifying if the ISO is in ready state. + If yes the continuing + If not waiting and checking for template to be ready till timeout + Step7: Downloading the ISO (Extract) + Step8: Verifying the details of downloaded ISO + """ + # Listing all the ISO's for a User + list_iso_before = Iso.list( + self.userapiclient, + listall=self.services["listall"], + isofilter=self.services["templatefilter"] + ) + # Verifying that no ISOs are listed + self.assertIsNone( + list_iso_before, + "ISOs listed for newly created User" + ) + self.services["iso"]["zoneid"] = self.zone.id + self.services["iso"]["isextractable"] = True + # Creating an ISO's + iso_created = Iso.create( + self.userapiclient, + self.services["iso"] + ) + self.assertIsNotNone( + iso_created, + "ISO creation failed" + ) + self.cleanup.append(iso_created) + # Listing all the ISO's for a User + list_iso_after = Iso.list( + self.userapiclient, + listall=self.services["listall"], + isofilter=self.services["templatefilter"] + ) + status = validateList(list_iso_after) + self.assertEquals( + PASS, + status[0], + "ISO's creation failed" + ) + # Verifying that list size is 1 + self.assertEquals( + 1, + len(list_iso_after), + "Failed to create an ISO's" + ) + # Verifying the state of the ISO to be ready. If not waiting for state to become ready + iso_ready = False + count = 0 + while iso_ready is False: + list_iso = Iso.list( + self.userapiclient, + listall=self.services["listall"], + isofilter=self.services["templatefilter"], + id=iso_created.id + ) + status = validateList(list_iso) + self.assertEquals( + PASS, + status[0], + "Failed to list ISO by Id" + ) + if list_iso[0].isready is True: + iso_ready = True + elif (str(list_iso[0].status) == "Error"): + self.fail("Created ISO is in Errored state") + break + elif count > 10: + self.fail("Timed out before ISO came into ready state") + break + else: + time.sleep(self.services["sleep"]) + count = count + 1 + + # Downloading the ISO + download_iso = Iso.extract( + self.userapiclient, + iso_created.id, + mode="HTTP_DOWNLOAD", + zoneid=self.zone.id + ) + self.assertIsNotNone( + download_iso, + "Download ISO failed" + ) + # Verifying the details of downloaded ISO + self.assertEquals( + "DOWNLOAD_URL_CREATED", + download_iso.state, + "Download URL not created for ISO" + ) + self.assertIsNotNone( + download_iso.url, + "Download URL not created for ISO" + ) + self.assertEquals( + iso_created.id, + download_iso.id, + "Download ISO details are not same as ISO created" + ) + del self.services["iso"]["zoneid"] + del self.services["iso"]["isextractable"] + return + + @attr(tags=["advanced", "basic", "provisioning"]) + def test_03_edit_iso_details(self): + """ + @Desc: Test to Edit ISO name, displaytext, OSType + @steps: + Step1: Listing all the ISO's for a user + Step2: Verifying that no ISO's are listed + Step3: Creating an ISO + Step4: Listing all the ISO's again for a user + Step5: Verifying that list size is 1 + Step6: Verifying if the ISO is in ready state. + If yes the continuing + If not waiting and checking for template to be ready till timeout + Step7: Editing the ISO's name, displaytext + Step8: Verifying that ISO name and displaytext are edited + Step9: Editing the ISO name, displaytext, ostypeid + Step10: Verifying that ISO name, displaytext and ostypeid are edited + """ + # Listing all the ISO's for a User + list_iso_before = Iso.list( + self.userapiclient, + listall=self.services["listall"], + isofilter=self.services["templatefilter"] + ) + # Verifying that no ISOs are listed + self.assertIsNone( + list_iso_before, + "ISOs listed for newly created User" + ) + self.services["iso"]["zoneid"] = self.zone.id + # Creating an ISO's + iso_created = Iso.create( + self.userapiclient, + self.services["iso"] + ) + self.assertIsNotNone( + iso_created, + "ISO creation failed" + ) + self.cleanup.append(iso_created) + # Listing all the ISO's for a User + list_iso_after = Iso.list( + self.userapiclient, + listall=self.services["listall"], + isofilter=self.services["templatefilter"] + ) + status = validateList(list_iso_after) + self.assertEquals( + PASS, + status[0], + "ISO's creation failed" + ) + # Verifying that list size is 1 + self.assertEquals( + 1, + len(list_iso_after), + "Failed to create an ISO's" + ) + # Verifying the state of the ISO to be ready. If not waiting for state to become ready + iso_ready = False + count = 0 + while iso_ready is False: + list_iso = Iso.list( + self.userapiclient, + listall=self.services["listall"], + isofilter=self.services["templatefilter"], + id=iso_created.id + ) + status = validateList(list_iso) + self.assertEquals( + PASS, + status[0], + "Failed to list ISO by Id" + ) + if list_iso[0].isready is True: + iso_ready = True + elif (str(list_iso[0].status) == "Error"): + self.fail("Created ISO is in Errored state") + break + elif count > 10: + self.fail("Timed out before ISO came into ready state") + break + else: + time.sleep(self.services["sleep"]) + count = count + 1 + + # Editing the ISO name, displaytext + edited_iso = Iso.update( + iso_created, + self.userapiclient, + name="NewISOName", + displaytext="NewISODisplayText" + ) + self.assertIsNotNone( + edited_iso, + "Editing ISO failed" + ) + # Verifying the details of edited template + expected_dict = { + "id":iso_created.id, + "name":"NewISOName", + "displaytest":"NewISODisplayText", + "account":iso_created.account, + "domainid":iso_created.domainid, + "isfeatured":iso_created.isfeatured, + "ostypeid":iso_created.ostypeid, + "ispublic":iso_created.ispublic, + } + actual_dict = { + "id":edited_iso.id, + "name":edited_iso.name, + "displaytest":edited_iso.displaytext, + "account":edited_iso.account, + "domainid":edited_iso.domainid, + "isfeatured":edited_iso.isfeatured, + "ostypeid":edited_iso.ostypeid, + "ispublic":edited_iso.ispublic, + } + edit_iso_status = self.__verify_values( + expected_dict, + actual_dict + ) + self.assertEqual( + True, + edit_iso_status, + "Edited ISO details are not as expected" + ) + # Editing the ISO name, displaytext, ostypeid + ostype_list = list_os_types(self.userapiclient) + status = validateList(ostype_list) + self.assertEquals( + PASS, + status[0], + "Failed to list OS Types" + ) + for i in range(0, len(ostype_list)): + if ostype_list[i].id != iso_created.ostypeid: + newostypeid = ostype_list[i].id + break + + edited_iso = Iso.update( + iso_created, + self.userapiclient, + name=iso_created.name, + displaytext=iso_created.displaytext, + ostypeid=newostypeid + ) + self.assertIsNotNone( + edited_iso, + "Editing ISO failed" + ) + # Verifying the details of edited template + expected_dict = { + "id":iso_created.id, + "name":iso_created.name, + "displaytest":iso_created.displaytext, + "account":iso_created.account, + "domainid":iso_created.domainid, + "isfeatured":iso_created.isfeatured, + "ostypeid":newostypeid, + "ispublic":iso_created.ispublic, + } + actual_dict = { + "id":edited_iso.id, + "name":edited_iso.name, + "displaytest":edited_iso.displaytext, + "account":edited_iso.account, + "domainid":edited_iso.domainid, + "isfeatured":edited_iso.isfeatured, + "ostypeid":edited_iso.ostypeid, + "ispublic":edited_iso.ispublic, + } + edit_iso_status = self.__verify_values( + expected_dict, + actual_dict + ) + self.assertEqual( + True, + edit_iso_status, + "Edited ISO details are not as expected" + ) + del self.services["iso"]["zoneid"] + return + + @attr(tags=["advanced", "basic", "provisioning"]) + def test_04_copy_iso(self): + """ + @Desc: Test to copy ISO from one zone to another + @steps: + Step1: Listing Zones available for a user + Step2: Verifying if the zones listed are greater than 1. + If Yes continuing. + If not halting the test. + Step3: Listing all the ISO's for a user in zone1 + Step4: Verifying that no ISO's are listed + Step5: Listing all the ISO's for a user in zone2 + Step6: Verifying that no ISO's are listed + Step7: Creating an ISO in zone 1 + Step8: Listing all the ISO's again for a user in zone1 + Step9: Verifying that list size is 1 + Step10: Listing all the ISO's for a user in zone2 + Step11: Verifying that no ISO's are listed + Step12: Copying the ISO created in step7 from zone1 to zone2 + Step13: Listing all the ISO's for a user in zone2 + Step14: Verifying that list size is 1 + Step15: Listing all the ISO's for a user in zone1 + Step16: Verifying that list size is 1 + """ + # Listing Zones available for a user + zones_list = Zone.list( + self.userapiclient, + available=True + ) + status = validateList(zones_list) + self.assertEquals( + PASS, + status[0], + "Failed to list Zones" + ) + if not len(zones_list) > 1: + self.fail("Enough zones doesnot exists to copy iso") + else: + # Listing all the ISO's for a User in Zone 1 + list_isos_zone1 = Iso.list( + self.userapiclient, + listall=self.services["listall"], + isofilter=self.services["templatefilter"], + zoneid=zones_list[0].id + ) + # Verifying that no ISO's are listed + self.assertIsNone( + list_isos_zone1, + "ISO's listed for newly created User in Zone1" + ) + # Listing all the ISO's for a User in Zone 2 + list_isos_zone2 = Iso.list( + self.userapiclient, + listall=self.services["listall"], + isofilter=self.services["templatefilter"], + zoneid=zones_list[1].id + ) + # Verifying that no ISO's are listed + self.assertIsNone( + list_isos_zone2, + "ISO's listed for newly created User in Zone2" + ) + self.services["iso"]["zoneid"] = zones_list[0].id + # Creating an ISO in Zone 1 + iso_created = Iso.create( + self.userapiclient, + self.services["iso"] + ) + self.assertIsNotNone( + iso_created, + "ISO creation failed" + ) + self.cleanup.append(iso_created) + # Listing all the ISO's for a User in Zone 1 + list_isos_zone1 = Iso.list( + self.userapiclient, + listall=self.services["listall"], + isofilter=self.services["templatefilter"], + zoneid=zones_list[0].id + ) + status = validateList(list_isos_zone1) + self.assertEquals( + PASS, + status[0], + "ISO creation failed in Zone1" + ) + # Verifying that list size is 1 + self.assertEquals( + 1, + len(list_isos_zone1), + "Failed to create a Template" + ) + # Listing all the ISO's for a User in Zone 2 + list_isos_zone2 = Iso.list( + self.userapiclient, + listall=self.services["listall"], + isofilter=self.services["templatefilter"], + zoneid=zones_list[1].id + ) + # Verifying that no ISO's are listed + self.assertIsNone( + list_isos_zone2, + "ISO's listed for newly created User in Zone2" + ) + # Verifying the state of the ISO to be ready. If not waiting for state to become ready + iso_ready = False + count = 0 + while iso_ready is False: + list_iso = Iso.list( + self.userapiclient, + listall=self.services["listall"], + isofilter=self.services["templatefilter"], + id=iso_created.id + ) + status = validateList(list_iso) + self.assertEquals( + PASS, + status[0], + "Failed to list ISO by Id" + ) + if list_iso[0].isready is True: + iso_ready = True + elif (str(list_iso[0].status) == "Error"): + self.fail("Created ISO is in Errored state") + break + elif count > 10: + self.fail("Timed out before ISO came into ready state") + break + else: + time.sleep(self.services["sleep"]) + count = count + 1 + + # Copying the ISO from Zone1 to Zone2 + copied_iso = Iso.copy( + self.userapiclient, + iso_created.id, + sourcezoneid=iso_created.zoneid, + destzoneid=zones_list[1].id + ) + self.assertIsNotNone( + copied_iso, + "Copying ISO from Zone1 to Zone2 failed" + ) + # Listing all the ISO's for a User in Zone 1 + list_isos_zone1 = Iso.list( + self.userapiclient, + listall=self.services["listall"], + isofilter=self.services["templatefilter"], + zoneid=zones_list[0].id + ) + status = validateList(list_isos_zone1) + self.assertEquals( + PASS, + status[0], + "ISO creation failed in Zone1" + ) + # Verifying that list size is 1 + self.assertEquals( + 1, + len(list_isos_zone1), + "Failed to create a Template" + ) + # Listing all the ISO's for a User in Zone 2 + list_isos_zone2 = Iso.list( + self.userapiclient, + listall=self.services["listall"], + isofilter=self.services["templatefilter"], + zoneid=zones_list[1].id + ) + status = validateList(list_isos_zone2) + self.assertEquals( + PASS, + status[0], + "ISO failed to copy into Zone2" + ) + # Verifying that list size is 1 + self.assertEquals( + 1, + len(list_isos_zone2), + "ISO failed to copy into Zone2" + ) + self.assertNotEquals( + "Connection refused", + list_isos_zone2[0].status, + "Failed to copy ISO" + ) + self.assertEquals( + True, + list_isos_zone2[0].isready, + "Failed to copy ISO" + ) + del self.services["iso"]["zoneid"] + return \ No newline at end of file diff --git a/test/integration/component/test_explicit_dedication.py b/test/integration/component/test_explicit_dedication.py index c589c6ae74f..4ce5c15fa9f 100644 --- a/test/integration/component/test_explicit_dedication.py +++ b/test/integration/component/test_explicit_dedication.py @@ -21,9 +21,9 @@ import marvin from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * from marvin.sshClient import SshClient -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common 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 @@ -96,12 +96,13 @@ class TestExplicitDedication(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestExplicitDedication, cls).getClsTestClient().getApiClient() - cls.services = Services().services + cls.testClient = super(TestExplicitDedication, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype cls.template = get_template( diff --git a/test/integration/component/test_haproxy.py b/test/integration/component/test_haproxy.py index ceea50b7e22..e3b45b5ab3d 100644 --- a/test/integration/component/test_haproxy.py +++ b/test/integration/component/test_haproxy.py @@ -19,7 +19,7 @@ # Import Local Modules from nose.plugins.attrib import attr from marvin.cloudstackTestCase import cloudstackTestCase -from marvin.integration.lib.base import ( +from marvin.lib.base import ( Account, ServiceOffering, VirtualMachine, @@ -31,11 +31,11 @@ from marvin.integration.lib.base import ( Vpn, NATRule ) -from marvin.integration.lib.common import (get_domain, +from marvin.lib.common import (get_domain, get_zone, get_template ) -from marvin.integration.lib.utils import (cleanup_resources, +from marvin.lib.utils import (cleanup_resources, random_gen) from marvin.cloudstackAPI import createLBStickinessPolicy from marvin.sshClient import SshClient @@ -118,12 +118,13 @@ class TestHAProxyStickyness(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestHAProxyStickyness, - cls).getClsTestClient().getApiClient() + cls.testClient = super(TestHAProxyStickyness, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, diff --git a/test/integration/component/test_implicit_planner.py b/test/integration/component/test_implicit_planner.py index 5124e70381a..9cbd73c6f89 100644 --- a/test/integration/component/test_implicit_planner.py +++ b/test/integration/component/test_implicit_planner.py @@ -21,9 +21,9 @@ import marvin from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * from marvin.sshClient import SshClient -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common 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 @@ -91,12 +91,13 @@ class TestImplicitPlanner(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestImplicitPlanner, cls).getClsTestClient().getApiClient() - cls.services = Services().services + cls.testClient = super(TestImplicitPlanner, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype template = get_template( diff --git a/test/integration/component/test_ip_reservation.py b/test/integration/component/test_ip_reservation.py index 46b4edb75be..dea26ab4707 100644 --- a/test/integration/component/test_ip_reservation.py +++ b/test/integration/component/test_ip_reservation.py @@ -23,31 +23,10 @@ Feature Specifications: https://cwiki.apache.org/confluence/display/CLOUDSTACK/FS+-+IP+Range+Reservation+within+a+Network """ from marvin.cloudstackTestCase import cloudstackTestCase, unittest -from marvin.integration.lib.utils import (cleanup_resources, - validateList, - verifyRouterState) -from marvin.integration.lib.base import (Network, - Account, - ServiceOffering, - VirtualMachine, - Router, - NetworkOffering, - VpcOffering, - VPC) -from marvin.integration.lib.common import (get_domain, - get_zone, - get_template, - createEnabledNetworkOffering, - get_free_vlan, - wait_for_cleanup, - createNetworkRulesForVM) -from marvin.codes import (PASS, - NAT_RULE, - STATIC_NAT_RULE, - FAIL, - UNKNOWN, - FAULT, - MASTER) +from marvin.cloudstackException import CloudstackAPIException +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * import netaddr import random @@ -101,18 +80,22 @@ class TestIpReservation(cloudstackTestCase): """ @classmethod def setUpClass(cls): - cloudstackTestClient = super(TestIpReservation, cls).getClsTestClient() - cls.api_client = cloudstackTestClient.getApiClient() - # Fill test data from the external config file - cls.testData = cloudstackTestClient.getConfigParser().parsedDict + cls.testClient = super(TestIpReservation, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + + # Fill services from the external config file + cls.testData = cls.testClient.getParsedTestDataConfig() + # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.testData) - cls.zone = get_zone(cls.api_client, cls.testData) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, cls.testData["ostype"] ) + if cls.template == FAILED: + assert False, "get_template() failed to return template with description %s" % cls.testData["ostype"] cls.testData["domainid"] = cls.domain.id cls.testData["zoneid"] = cls.zone.id cls.testData["virtual_machine"]["zoneid"] = cls.zone.id @@ -545,18 +528,22 @@ class TestRestartNetwork(cloudstackTestCase): """ @classmethod def setUpClass(cls): - cloudstackTestClient = super(TestRestartNetwork, cls).getClsTestClient() - cls.api_client = cloudstackTestClient.getApiClient() - # Fill test data from the external config file - cls.testData = cloudstackTestClient.getConfigParser().parsedDict + cls.testClient = super(TestRestartNetwork, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + + # Fill services from the external config file + cls.testData = cls.testClient.getParsedTestDataConfig() + # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.testData) - cls.zone = get_zone(cls.api_client, cls.testData) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, cls.testData["ostype"] ) + if cls.template == FAILED: + assert False, "get_template() failed to return template with description %s" % cls.testData["ostype"] cls.testData["domainid"] = cls.domain.id cls.testData["zoneid"] = cls.zone.id cls.testData["virtual_machine"]["zoneid"] = cls.zone.id @@ -666,18 +653,22 @@ class TestUpdateIPReservation(cloudstackTestCase): """ @classmethod def setUpClass(cls): - cloudstackTestClient = super(TestUpdateIPReservation, cls).getClsTestClient() - cls.api_client = cloudstackTestClient.getApiClient() - # Fill test data from the external config file - cls.testData = cloudstackTestClient.getConfigParser().parsedDict + cls.testClient = super(TestUpdateIPReservation, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + + # Fill services from the external config file + cls.testData = cls.testClient.getParsedTestDataConfig() + # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.testData) - cls.zone = get_zone(cls.api_client, cls.testData) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, cls.testData["ostype"] ) + if cls.template == FAILED: + assert False, "get_template() failed to return template with description %s" % cls.testData["ostype"] cls.testData["domainid"] = cls.domain.id cls.testData["zoneid"] = cls.zone.id cls.testData["virtual_machine"]["zoneid"] = cls.zone.id @@ -812,18 +803,22 @@ class TestRouterOperations(cloudstackTestCase): """ @classmethod def setUpClass(cls): - cloudstackTestClient = super(TestRouterOperations, cls).getClsTestClient() - cls.api_client = cloudstackTestClient.getApiClient() - # Fill test data from the external config file - cls.testData = cloudstackTestClient.getConfigParser().parsedDict + cls.testClient = super(TestRouterOperations, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + + # Fill services from the external config file + cls.testData = cls.testClient.getParsedTestDataConfig() + # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.testData) - cls.zone = get_zone(cls.api_client, cls.testData) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, cls.testData["ostype"] ) + if cls.template == FAILED: + assert False, "get_template() failed to return template with description %s" % cls.testData["ostype"] cls.testData["domainid"] = cls.domain.id cls.testData["zoneid"] = cls.zone.id cls.testData["virtual_machine"]["zoneid"] = cls.zone.id @@ -978,18 +973,22 @@ class TestFailureScnarios(cloudstackTestCase): """ @classmethod def setUpClass(cls): - cloudstackTestClient = super(TestFailureScnarios, cls).getClsTestClient() - cls.api_client = cloudstackTestClient.getApiClient() - # Fill test data from the external config file - cls.testData = cloudstackTestClient.getConfigParser().parsedDict + cls.testClient = super(TestFailureScnarios, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + + # Fill services from the external config file + cls.testData = cls.testClient.getParsedTestDataConfig() + # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.testData) - cls.zone = get_zone(cls.api_client, cls.testData) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, cls.testData["ostype"] ) + if cls.template == FAILED: + assert False, "get_template() failed to return template with description %s" % cls.testData["ostype"] cls.testData["domainid"] = cls.domain.id cls.testData["zoneid"] = cls.zone.id cls.testData["virtual_machine"]["zoneid"] = cls.zone.id diff --git a/test/integration/component/test_ldap.py b/test/integration/component/test_ldap.py index 965ff36befb..5dd96928374 100644 --- a/test/integration/component/test_ldap.py +++ b/test/integration/component/test_ldap.py @@ -29,9 +29,9 @@ import hashlib import random from marvin.cloudstackAPI import * from marvin.cloudstackAPI import login -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * from nose.plugins.attrib import attr import urllib diff --git a/test/integration/component/test_memory_limits.py b/test/integration/component/test_memory_limits.py index 020f89b5752..5dd3ba0e5be 100644 --- a/test/integration/component/test_memory_limits.py +++ b/test/integration/component/test_memory_limits.py @@ -19,21 +19,21 @@ # Import Local Modules from nose.plugins.attrib import attr from marvin.cloudstackTestCase import cloudstackTestCase, unittest -from marvin.integration.lib.base import ( +from marvin.lib.base import ( Account, ServiceOffering, VirtualMachine, Resources, Domain ) -from marvin.integration.lib.common import (get_domain, +from marvin.lib.common import (get_domain, get_zone, get_template, wait_for_cleanup, findSuitableHostForMigration, get_resource_type ) -from marvin.integration.lib.utils import cleanup_resources +from marvin.lib.utils import cleanup_resources from marvin.codes import ERROR_NO_HOST_FOR_MIGRATION class Services: @@ -91,12 +91,13 @@ class TestMemoryLimits(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestMemoryLimits, - cls).getClsTestClient().getApiClient() + cls.testClient = super(TestMemoryLimits, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services["mode"] = cls.zone.networktype @@ -370,12 +371,13 @@ class TestDomainMemoryLimitsConfiguration(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestDomainMemoryLimitsConfiguration, - cls).getClsTestClient().getApiClient() + cls.testClient = super(TestDomainMemoryLimitsConfiguration, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services["mode"] = cls.zone.networktype cls.template = get_template( @@ -498,7 +500,7 @@ class TestDomainMemoryLimitsConfiguration(cloudstackTestCase): self.account = admin self.domain = domain - api_client = self.testClient.createUserApiClient( + api_client = self.testClient.getUserApiClient( UserName=self.account.name, DomainName=self.account.domain) @@ -570,7 +572,7 @@ class TestDomainMemoryLimitsConfiguration(cloudstackTestCase): self.account = admin self.domain = domain - api_client = self.testClient.createUserApiClient( + api_client = self.testClient.getUserApiClient( UserName=self.account.name, DomainName=self.account.domain) @@ -630,7 +632,7 @@ class TestDomainMemoryLimitsConfiguration(cloudstackTestCase): self.account = admin self.domain = domain - api_client = self.testClient.createUserApiClient( + api_client = self.testClient.getUserApiClient( UserName=self.account.name, DomainName=self.account.domain) @@ -703,7 +705,7 @@ class TestDomainMemoryLimitsConfiguration(cloudstackTestCase): if memory_account_gc[0].max != 8192: self.skipTest("This test case requires configuration value max.account.memory to be 8192") - api_client = self.testClient.createUserApiClient( + api_client = self.testClient.getUserApiClient( UserName=self.account.name, DomainName=self.account.domain) diff --git a/test/integration/component/test_mm_domain_limits.py b/test/integration/component/test_mm_domain_limits.py index 0a8e98b3813..bc8c9ea5532 100644 --- a/test/integration/component/test_mm_domain_limits.py +++ b/test/integration/component/test_mm_domain_limits.py @@ -19,14 +19,14 @@ # Import Local Modules from nose.plugins.attrib import attr from marvin.cloudstackTestCase import cloudstackTestCase, unittest -from marvin.integration.lib.base import ( +from marvin.lib.base import ( Account, ServiceOffering, VirtualMachine, Resources, Domain ) -from marvin.integration.lib.common import (get_domain, +from marvin.lib.common import (get_domain, get_zone, get_template, wait_for_cleanup, @@ -34,7 +34,7 @@ from marvin.integration.lib.common import (get_domain, get_resource_type, update_resource_count ) -from marvin.integration.lib.utils import cleanup_resources +from marvin.lib.utils import cleanup_resources from marvin.codes import ERROR_NO_HOST_FOR_MIGRATION class Services: @@ -92,12 +92,13 @@ class TestDomainMemoryLimits(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestDomainMemoryLimits, - cls).getClsTestClient().getApiClient() + cls.testClient = super(TestDomainMemoryLimits, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services["mode"] = cls.zone.networktype cls.template = get_template( @@ -234,7 +235,7 @@ class TestDomainMemoryLimits(cloudstackTestCase): self.debug("Creating an instance with service offering: %s" % self.service_offering.name) - api_client = self.testClient.createUserApiClient( + api_client = self.testClient.getUserApiClient( UserName=self.account.name, DomainName=self.account.domain) @@ -371,7 +372,7 @@ class TestDomainMemoryLimits(cloudstackTestCase): self.debug("Creating an instance with service offering: %s" % self.service_offering.name) - api_client = self.testClient.createUserApiClient( + api_client = self.testClient.getUserApiClient( UserName=self.account.name, DomainName=self.account.domain) @@ -432,7 +433,7 @@ class TestDomainMemoryLimits(cloudstackTestCase): self.debug("Creating an instance with service offering: %s" % self.service_offering.name) - api_client = self.testClient.createUserApiClient( + api_client = self.testClient.getUserApiClient( UserName=self.account.name, DomainName=self.account.domain) @@ -492,7 +493,7 @@ class TestDomainMemoryLimits(cloudstackTestCase): self.debug("Creating an instance with service offering: %s" % self.service_offering.name) - api_client = self.testClient.createUserApiClient( + api_client = self.testClient.getUserApiClient( UserName=self.account.name, DomainName=self.account.domain) @@ -524,12 +525,13 @@ class TestMultipleChildDomainsMemory(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestMultipleChildDomainsMemory, - cls).getClsTestClient().getApiClient() + cls.testClient = super(TestMultipleChildDomainsMemory, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services["mode"] = cls.zone.networktype cls.template = get_template( @@ -709,11 +711,11 @@ class TestMultipleChildDomainsMemory(cloudstackTestCase): self.debug("Setting up account and domain hierarchy") self.setupAccounts() - api_client_cadmin_1 = self.testClient.createUserApiClient( + api_client_cadmin_1 = self.testClient.getUserApiClient( UserName=self.cadmin_1.name, DomainName=self.cadmin_1.domain) - api_client_cadmin_2 = self.testClient.createUserApiClient( + api_client_cadmin_2 = self.testClient.getUserApiClient( UserName=self.cadmin_2.name, DomainName=self.cadmin_2.domain) diff --git a/test/integration/component/test_mm_max_limits.py b/test/integration/component/test_mm_max_limits.py index 52ff98e1bd1..34d4147b90b 100644 --- a/test/integration/component/test_mm_max_limits.py +++ b/test/integration/component/test_mm_max_limits.py @@ -19,7 +19,7 @@ # Import Local Modules from nose.plugins.attrib import attr from marvin.cloudstackTestCase import cloudstackTestCase, unittest -from marvin.integration.lib.base import ( +from marvin.lib.base import ( Account, ServiceOffering, VirtualMachine, @@ -27,11 +27,11 @@ from marvin.integration.lib.base import ( Domain, Project ) -from marvin.integration.lib.common import (get_domain, +from marvin.lib.common import (get_domain, get_zone, get_template ) -from marvin.integration.lib.utils import cleanup_resources +from marvin.lib.utils import cleanup_resources class Services: """Test memory resource limit services @@ -88,12 +88,13 @@ class TestMaxMemoryLimits(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestMaxMemoryLimits, - cls).getClsTestClient().getApiClient() + cls.testClient = super(TestMaxMemoryLimits, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services["mode"] = cls.zone.networktype cls.template = get_template( @@ -253,7 +254,7 @@ class TestMaxMemoryLimits(cloudstackTestCase): self.debug("Setting up account and domain hierarchy") self.setupAccounts(account_limit=8, domain_limit=4) - api_client = self.testClient.createUserApiClient( + api_client = self.testClient.getUserApiClient( UserName=self.child_do_admin.name, DomainName=self.child_do_admin.domain) @@ -280,7 +281,7 @@ class TestMaxMemoryLimits(cloudstackTestCase): self.debug("Setting up account and domain hierarchy") self.setupAccounts(account_limit=7, domain_limit=14) - api_client = self.testClient.createUserApiClient( + api_client = self.testClient.getUserApiClient( UserName=self.child_do_admin.name, DomainName=self.child_do_admin.domain) @@ -310,7 +311,7 @@ class TestMaxMemoryLimits(cloudstackTestCase): self.debug("Setting up account and domain hierarchy") self.setupAccounts(account_limit=8,domain_limit=8, project_limit=4) - api_client = self.testClient.createUserApiClient( + api_client = self.testClient.getUserApiClient( UserName=self.child_do_admin.name, DomainName=self.child_do_admin.domain) @@ -334,7 +335,7 @@ class TestMaxMemoryLimits(cloudstackTestCase): self.debug("Setting up account and domain hierarchy") self.setupAccounts(account_limit=6, project_limit=12, domain_limit=12) - api_client = self.testClient.createUserApiClient( + api_client = self.testClient.getUserApiClient( UserName=self.child_do_admin.name, DomainName=self.child_do_admin.domain) diff --git a/test/integration/component/test_mm_project_limits.py b/test/integration/component/test_mm_project_limits.py index 00c0ab45508..593b2b64004 100644 --- a/test/integration/component/test_mm_project_limits.py +++ b/test/integration/component/test_mm_project_limits.py @@ -19,21 +19,21 @@ # Import Local Modules from nose.plugins.attrib import attr from marvin.cloudstackTestCase import cloudstackTestCase, unittest -from marvin.integration.lib.base import ( +from marvin.lib.base import ( Account, ServiceOffering, VirtualMachine, Domain, Project ) -from marvin.integration.lib.common import (get_domain, +from marvin.lib.common import (get_domain, get_zone, get_template, wait_for_cleanup, findSuitableHostForMigration, get_resource_type ) -from marvin.integration.lib.utils import cleanup_resources +from marvin.lib.utils import cleanup_resources from marvin.codes import ERROR_NO_HOST_FOR_MIGRATION class Services: @@ -91,12 +91,13 @@ class TestProjectsMemoryLimits(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestProjectsMemoryLimits, - cls).getClsTestClient().getApiClient() + cls.testClient = super(TestProjectsMemoryLimits, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services["mode"] = cls.zone.networktype cls.template = get_template( @@ -137,7 +138,7 @@ class TestProjectsMemoryLimits(cloudstackTestCase): self.debug("Setting up account and domain hierarchy") self.setupProjectAccounts() - api_client = self.testClient.createUserApiClient( + api_client = self.testClient.getUserApiClient( UserName=self.admin.name, DomainName=self.admin.domain) diff --git a/test/integration/component/test_multiple_ip_ranges.py b/test/integration/component/test_multiple_ip_ranges.py index aae90c4cd45..32c39f7c6a0 100644 --- a/test/integration/component/test_multiple_ip_ranges.py +++ b/test/integration/component/test_multiple_ip_ranges.py @@ -18,10 +18,10 @@ """ from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.cloudstackException import cloudstackAPIException -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.cloudstackException import CloudstackAPIException +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * from netaddr import * from nose.plugins.attrib import attr @@ -78,12 +78,14 @@ class TestMultipleIpRanges(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestMultipleIpRanges, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestMultipleIpRanges, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) - cls.pod = get_pod(cls.api_client, cls.zone.id, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) + cls.pod = get_pod(cls.api_client, cls.zone.id) cls.services['mode'] = cls.zone.networktype cls.services["domainid"] = cls.domain.id cls.services["zoneid"] = cls.zone.id @@ -296,7 +298,7 @@ class TestMultipleIpRanges(cloudstackTestCase): #listing vlan ip ranges with the id should through exception , if not mark the test case as failed try: new_vlan.list(self.apiclient, id=new_vlan.vlan.id) - except cloudstackAPIException as cs: + except CloudstackAPIException as cs: self.debug(cs.errorMsg) self.assertTrue(cs.errorMsg.find("entity does not exist")>0, msg="Failed to delete IP range") return @@ -387,7 +389,7 @@ class TestMultipleIpRanges(cloudstackTestCase): self.debug("Adding overlapped ip range") try: new_vlan2 = PublicIpRange.create(self.apiclient, self.services["vlan_ip_range"]) - except cloudstackAPIException as cs: + except CloudstackAPIException as cs: self.debug(cs.errorMsg) self.assertTrue(cs.errorMsg.find("already has IPs that overlap with the new range")>0, msg="Fail:CS allowed adding overlapped ip ranges in guest cidr") return @@ -443,7 +445,7 @@ class TestMultipleIpRanges(cloudstackTestCase): self.debug("Adding ip range overlapped with two cidrs") try: new_vlan3 = PublicIpRange.create(self.apiclient, self.services["vlan_ip_range"]) - except cloudstackAPIException as cs: + except CloudstackAPIException as cs: self.debug(cs.errorMsg) self.assertTrue(cs.errorMsg.find("already has IPs that overlap with the new range")>0, msg="Fail:CS allowed adding overlapped ip ranges in guest cidr") return @@ -496,7 +498,7 @@ class TestMultipleIpRanges(cloudstackTestCase): self.debug("Adding IP range super set to existing CIDR") try: new_vlan2 = PublicIpRange.create(self.apiclient, self.services["vlan_ip_range"]) - except cloudstackAPIException as cs: + except CloudstackAPIException as cs: self.debug(cs.errorMsg) self.assertTrue(cs.errorMsg.find("superset")>0, msg="Fail: CS allowed adding ip range superset to existing CIDR") return @@ -549,7 +551,7 @@ class TestMultipleIpRanges(cloudstackTestCase): self.debug("Adding ip range subset to existing cidr") try: new_vlan2 = PublicIpRange.create(self.apiclient, self.services["vlan_ip_range"]) - except cloudstackAPIException as cs: + except CloudstackAPIException as cs: self.debug(cs.errorMsg) self.assertTrue(cs.errorMsg.find("subset")>0, msg="Fail: CS allowed adding ip range subset to existing CIDR") return diff --git a/test/integration/component/test_multiple_ips_per_nic.py b/test/integration/component/test_multiple_ips_per_nic.py index dcbb453e7eb..27396371ad1 100644 --- a/test/integration/component/test_multiple_ips_per_nic.py +++ b/test/integration/component/test_multiple_ips_per_nic.py @@ -23,32 +23,14 @@ Design Document: https://cwiki.apache.org/confluence/display/CLOUDSTACK/Multiple+IP+address+per+NIC """ from marvin.cloudstackTestCase import cloudstackTestCase -from marvin.integration.lib.utils import (cleanup_resources, - validateList, - random_gen) -from marvin.integration.lib.base import (Account, - ServiceOffering, - Network, - VirtualMachine, - VpcOffering, - VPC, - NIC, - Domain, - PublicIPAddress, - StaticNATRule, - FireWallRule, - NATRule) -from marvin.integration.lib.common import (get_domain, - get_zone, - get_template, - get_free_vlan, - setSharedNetworkParams, - createEnabledNetworkOffering, - shouldTestBeSkipped) +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 PASS, ISOLATED_NETWORK, VPC_NETWORK, SHARED_NETWORK, FAIL from ddt import ddt, data +import time def createNetwork(self, networkType): """Create a network of given type (isolated/shared/isolated in VPC)""" @@ -137,21 +119,23 @@ class TestBasicOperations(cloudstackTestCase): @classmethod def setUpClass(cls): - cloudstackTestClient = super(TestBasicOperations,cls).getClsTestClient() - cls.api_client = cloudstackTestClient.getApiClient() + cls.testClient = super(TestBasicOperations, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() # Fill services from the external config file - cls.services = cloudstackTestClient.getConfigParser().parsedDict + cls.services = cls.testClient.getParsedTestDataConfig() # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) - cls.mode = str(cls.zone.networktype).lower() + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, cls.services["ostype"] ) + if cls.template == FAILED: + assert False, "get_template() failed to return template with description %s" % cls.services["ostype"] + cls.services["virtual_machine"]["zoneid"] = cls.zone.id cls.services["virtual_machine"]["template"] = cls.template.id cls.service_offering = ServiceOffering.create( @@ -486,21 +470,23 @@ class TestNetworkRules(cloudstackTestCase): @classmethod def setUpClass(cls): - cloudstackTestClient = super(TestNetworkRules,cls).getClsTestClient() - cls.api_client = cloudstackTestClient.getApiClient() + cls.testClient = super(TestNetworkRules, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() # Fill services from the external config file - cls.services = cloudstackTestClient.getConfigParser().parsedDict + cls.services = cls.testClient.getParsedTestDataConfig() # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) - cls.mode = str(cls.zone.networktype).lower() + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, cls.services["ostype"] ) + if cls.template == FAILED: + assert False, "get_template() failed to return template with description %s" % cls.services["ostype"] + cls.services["virtual_machine"]["zoneid"] = cls.zone.id cls.services["virtual_machine"]["template"] = cls.template.id cls.service_offering = ServiceOffering.create( @@ -851,3 +837,439 @@ class TestNetworkRules(cloudstackTestCase): public_ip.delete(self.apiclient) return + +@ddt +class TestVmNetworkOperations(cloudstackTestCase): + """Test VM and Network operations with network rules created on secondary IP + """ + + @classmethod + def setUpClass(cls): + cls.testClient = super(TestVmNetworkOperations, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + + # Fill services from the external config file + cls.services = cls.testClient.getParsedTestDataConfig() + + # Get Zone, Domain and templates + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) + cls.template = get_template( + cls.api_client, + cls.zone.id, + cls.services["ostype"] + ) + if cls.template == FAILED: + assert False, "get_template() failed to return template with description %s" % cls.services["ostype"] + cls.services["virtual_machine"]["zoneid"] = cls.zone.id + cls.services["virtual_machine"]["template"] = cls.template.id + cls.service_offering = ServiceOffering.create( + cls.api_client, + cls.services["service_offering"] + ) + cls._cleanup = [cls.service_offering] + cls.services["shared_network_offering"]["specifyVlan"] = "True" + cls.services["shared_network_offering"]["specifyIpRanges"] = "True" + + cls.shared_network_offering = CreateEnabledNetworkOffering(cls.api_client, cls.services["shared_network_offering"]) + cls._cleanup.append(cls.shared_network_offering) + + if cls.mode == "advanced": + cls.isolated_network_offering = CreateEnabledNetworkOffering(cls.api_client, cls.services["isolated_network_offering"]) + cls._cleanup.append(cls.isolated_network_offering) + cls.isolated_network_offering_vpc = CreateEnabledNetworkOffering(cls.api_client, cls.services["nw_offering_isolated_vpc"]) + cls._cleanup.append(cls.isolated_network_offering_vpc) + cls.vpc_off = VpcOffering.create(cls.api_client, cls.services["vpc_offering"]) + cls.vpc_off.update(cls.api_client, state='Enabled') + cls._cleanup.append(cls.vpc_off) + return + + @classmethod + def tearDownClass(cls): + try: + # Cleanup resources used + cleanup_resources(cls.api_client, cls._cleanup) + except Exception as e: + raise Exception("Warning: Exception during cleanup : %s" % e) + return + + def setUp(self): + self.apiclient = self.testClient.getApiClient() + self.dbclient = self.testClient.getDbConnection() + self.cleanup = [ ] + return + + def tearDown(self): + try: + # Clean up, terminate the resources created + cleanup_resources(self.apiclient, self.cleanup) + except Exception as e: + raise Exception("Warning: Exception during cleanup : %s" % e) + return + + def VerifyStaticNatForPublicIp(self, ipaddressid, natrulestatus): + """ List public IP and verify that NAT rule status for the IP is as desired """ + + publiciplist = PublicIPAddress.list(self.apiclient, id=ipaddressid, listall=True) + self.assertEqual(validateList(publiciplist)[0], PASS, "Public IP list validation failed") + self.assertEqual(publiciplist[0].isstaticnat, natrulestatus, "isstaticnat should be %s, it is %s" % + (natrulestatus, publiciplist[0].isstaticnat)) + + return + + @data(ISOLATED_NETWORK, SHARED_NETWORK, VPC_NETWORK) + @attr(tags=["advanced"]) + def test_delete_vm(self, value): + """ Test delete VM and verify network rules are cleaned up""" + + # Steps: + # 1. Create Account and create network in it (isoalted/ shared/ vpc) + # 2. Deploy a VM in this network and account + # 3. Add 2 secondary IPs to the default nic of VM + # 4. Acquire 2 public IPs in the network + # 5. For 1st public IP create nat rule to 1st private IP, for 2nd public IP, create + # static nat rule to 2nd private IP + # 6. Destroy the virtual machine + # 7. Verify that nat rule does not exist and static nat is not enabled for + # secondary IP + + self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id) + self.cleanup.append(self.account) + + network = createNetwork(self, value) + + try: + virtual_machine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"], + networkids=[network.id],serviceofferingid=self.service_offering.id, + accountid=self.account.name,domainid=self.account.domainid) + except Exception as e: + self.fail("vm creation failed: %s" % e) + + # Add secondary IPs to default NIC of VM + try: + ipaddress_1 = NIC.addIp(self.apiclient, id=virtual_machine.nic[0].id) + ipaddress_2 = NIC.addIp(self.apiclient, id=virtual_machine.nic[0].id) + except Exception as e: + self.fail("Failed while adding secondary IP to NIC of vm %s" % virtual_machine.id) + + # Acquire public IP addresses in the network + try: + public_ip_1 = PublicIPAddress.create(self.api_client,accountid=self.account.name, + zoneid=self.zone.id,domainid=self.account.domainid, + networkid=network.id, vpcid = network.vpcid if value == VPC_NETWORK else None) + + public_ip_2 = PublicIPAddress.create(self.api_client,accountid=self.account.name, + zoneid=self.zone.id,domainid=self.account.domainid, + networkid=network.id, vpcid = network.vpcid if value == VPC_NETWORK else None) + except Exception as e: + self.fail("Exception while acquiring public ip address: %s" % e) + + # Create Firewall and natrule for 1st IP and static nat rule for 2nd IP + if value != VPC_NETWORK: + FireWallRule.create(self.apiclient,ipaddressid=public_ip_1.ipaddress.id, + protocol='TCP', cidrlist=[self.services["fwrule"]["cidr"]], + startport=self.services["fwrule"]["startport"],endport=self.services["fwrule"]["endport"]) + + natrule = NATRule.create(self.api_client, virtual_machine, + self.services["natrule"],ipaddressid=public_ip_1.ipaddress.id, + networkid=network.id, vmguestip = ipaddress_1.ipaddress) + + StaticNATRule.enable(self.apiclient, public_ip_2.ipaddress.id, virtual_machine.id, + network.id, vmguestip=ipaddress_2.ipaddress) + + # Delete VM + virtual_machine.delete(self.apiclient) + + # Wait for VMs to expunge + wait_for_cleanup(self.api_client, ["expunge.delay", "expunge.interval"]) + + # Make sure the VM is expunged + retriesCount = 20 + while True: + vms = VirtualMachine.list(self.apiclient, id=virtual_machine.id) + if vms is None: + break + elif retriesCount == 0: + self.fail("Failed to expunge vm even after 20 minutes") + time.sleep(60) + retriesCount -= 1 + + # Try to list nat rule + with self.assertRaises(Exception): + NATRule.list(self.apiclient, id=natrule.id, listall=True) + + # Verify static nat rule is no longer enabled + self.VerifyStaticNatForPublicIp(public_ip_2.ipaddress.id, False) + return + + @data(ISOLATED_NETWORK, SHARED_NETWORK, VPC_NETWORK) + @attr(tags=["advanced"]) + def test_recover_vm(self, value): + """ Test recover VM operation with VM having secondary IPs""" + + # Steps: + # 1. Create Account and create network in it (isoalted/ shared/ vpc) + # 2. Deploy a VM in this network and account + # 3. Add 2 secondary IPs to the default nic of VM + # 4. Acquire 2 public IPs in the network + # 5. For 1st public IP create nat rule to 1st private IP, for 2nd public IP, create + # static nat rule to 2nd private IP + # 6. Destroy the virtual machine and recover it + # 7. Verify that nat and static nat rules exist + + self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id) + self.cleanup.append(self.account) + + network = createNetwork(self, value) + + try: + virtual_machine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"], + networkids=[network.id],serviceofferingid=self.service_offering.id, + accountid=self.account.name,domainid=self.account.domainid) + except Exception as e: + self.fail("vm creation failed: %s" % e) + + try: + ipaddress_1 = NIC.addIp(self.apiclient, id=virtual_machine.nic[0].id) + ipaddress_2 = NIC.addIp(self.apiclient, id=virtual_machine.nic[0].id) + except Exception as e: + self.fail("Failed while adding secondary IP to NIC of vm %s" % virtual_machine.id) + + try: + public_ip_1 = PublicIPAddress.create(self.api_client,accountid=self.account.name, + zoneid=self.zone.id,domainid=self.account.domainid, + networkid=network.id, vpcid = network.vpcid if value == VPC_NETWORK else None) + + public_ip_2 = PublicIPAddress.create(self.api_client,accountid=self.account.name, + zoneid=self.zone.id,domainid=self.account.domainid, + networkid=network.id, vpcid = network.vpcid if value == VPC_NETWORK else None) + except Exception as e: + self.fail("Exception while acquiring public ip address: %s" % e) + + if value != VPC_NETWORK: + FireWallRule.create(self.apiclient,ipaddressid=public_ip_1.ipaddress.id, + protocol='TCP', cidrlist=[self.services["fwrule"]["cidr"]], + startport=self.services["fwrule"]["startport"],endport=self.services["fwrule"]["endport"]) + + natrule = NATRule.create(self.api_client, virtual_machine, + self.services["natrule"],ipaddressid=public_ip_1.ipaddress.id, + networkid=network.id, vmguestip = ipaddress_1.ipaddress) + + StaticNATRule.enable(self.apiclient, public_ip_2.ipaddress.id, virtual_machine.id, + network.id, vmguestip=ipaddress_2.ipaddress) + + virtual_machine.delete(self.apiclient) + virtual_machine.recover(self.apiclient) + + retriesCount = 10 + while True: + vms = VirtualMachine.list(self.apiclient, id=virtual_machine.id) + self.assertEqual(validateList(vms)[0], PASS, "vms list validation failed") + if str(vms[0].state).lower() == "stopped": + break + elif retriesCount == 0: + self.fail("Failed to recover vm even after 10 mins") + time.sleep(60) + retriesCount -= 1 + + natrules = NATRule.list(self.apiclient, id=natrule.id, listall=True) + self.assertEqual(validateList(natrules)[0], PASS, "nat rules validation failed") + + self.VerifyStaticNatForPublicIp(public_ip_2.ipaddress.id, True) + + return + + @data(ISOLATED_NETWORK, SHARED_NETWORK, VPC_NETWORK) + @attr(tags=["advanced"]) + def test_network_restart_cleanup_true(self, value): + """Test network restart (cleanup True) with VM having secondary IPs and related network rules""" + + # Steps: + # 1. Create Account and create network in it (isoalted/ shared/ vpc) + # 2. Deploy a VM in this network and account + # 3. Add 2 secondary IPs to the default nic of VM + # 4. Acquire 2 public IPs in the network + # 5. For 1st public IP create nat rule to 1st private IP, for 2nd public IP, create + # static nat rule to 2nd private IP + # 6. Restart the network with cleanup option True + # 7. Verify that nat and static nat rules exist after network restart + + self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id) + self.cleanup.append(self.account) + + network = createNetwork(self, value) + + try: + virtual_machine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"], + networkids=[network.id],serviceofferingid=self.service_offering.id, + accountid=self.account.name,domainid=self.account.domainid) + except Exception as e: + self.fail("vm creation failed: %s" % e) + + try: + ipaddress_1 = NIC.addIp(self.apiclient, id=virtual_machine.nic[0].id) + ipaddress_2 = NIC.addIp(self.apiclient, id=virtual_machine.nic[0].id) + except Exception as e: + self.fail("Failed while adding secondary IP to NIC of vm %s" % virtual_machine.id) + + try: + public_ip_1 = PublicIPAddress.create(self.api_client,accountid=self.account.name, + zoneid=self.zone.id,domainid=self.account.domainid, + networkid=network.id, vpcid = network.vpcid if value == VPC_NETWORK else None) + + public_ip_2 = PublicIPAddress.create(self.api_client,accountid=self.account.name, + zoneid=self.zone.id,domainid=self.account.domainid, + networkid=network.id, vpcid = network.vpcid if value == VPC_NETWORK else None) + except Exception as e: + self.fail("Exception while acquiring public ip address: %s" % e) + + if value != VPC_NETWORK: + FireWallRule.create(self.apiclient,ipaddressid=public_ip_1.ipaddress.id, + protocol='TCP', cidrlist=[self.services["fwrule"]["cidr"]], + startport=self.services["fwrule"]["startport"],endport=self.services["fwrule"]["endport"]) + + natrule = NATRule.create(self.api_client, virtual_machine, + self.services["natrule"],ipaddressid=public_ip_1.ipaddress.id, + networkid=network.id, vmguestip = ipaddress_1.ipaddress) + + StaticNATRule.enable(self.apiclient, public_ip_2.ipaddress.id, virtual_machine.id, + network.id, vmguestip=ipaddress_2.ipaddress) + + network.restart(self.apiclient, cleanup=True) + + natrulelist = NATRule.list(self.apiclient, id=natrule.id, listall=True) + self.assertEqual(validateList(natrulelist)[0], PASS, "nat rules list validation failed") + + self.VerifyStaticNatForPublicIp(public_ip_2.ipaddress.id, True) + return + + @data(ISOLATED_NETWORK, SHARED_NETWORK, VPC_NETWORK) + @attr(tags=["advanced"]) + def test_network_restart_cleanup_false(self, value): + """Test network restart (cleanup True) with VM having secondary IPs and related network rules""" + + # Steps: + # 1. Create Account and create network in it (isoalted/ shared/ vpc) + # 2. Deploy a VM in this network and account + # 3. Add 2 secondary IPs to the default nic of VM + # 4. Acquire 2 public IPs in the network + # 5. For 1st public IP create nat rule to 1st private IP, for 2nd public IP, create + # static nat rule to 2nd private IP + # 6. Restart the network with cleanup option False + # 7. Verify that nat and static nat rules exist after network restart + + self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id) + self.cleanup.append(self.account) + + network = createNetwork(self, value) + + try: + virtual_machine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"], + networkids=[network.id],serviceofferingid=self.service_offering.id, + accountid=self.account.name,domainid=self.account.domainid) + except Exception as e: + self.fail("vm creation failed: %s" % e) + + try: + ipaddress_1 = NIC.addIp(self.apiclient, id=virtual_machine.nic[0].id) + ipaddress_2 = NIC.addIp(self.apiclient, id=virtual_machine.nic[0].id) + except Exception as e: + self.fail("Failed while adding secondary IP to NIC of vm %s" % virtual_machine.id) + + try: + public_ip_1 = PublicIPAddress.create(self.api_client,accountid=self.account.name, + zoneid=self.zone.id,domainid=self.account.domainid, + networkid=network.id, vpcid = network.vpcid if value == VPC_NETWORK else None) + + public_ip_2 = PublicIPAddress.create(self.api_client,accountid=self.account.name, + zoneid=self.zone.id,domainid=self.account.domainid, + networkid=network.id, vpcid = network.vpcid if value == VPC_NETWORK else None) + except Exception as e: + self.fail("Exception while acquiring public ip address: %s" % e) + + if value != VPC_NETWORK: + FireWallRule.create(self.apiclient,ipaddressid=public_ip_1.ipaddress.id, + protocol='TCP', cidrlist=[self.services["fwrule"]["cidr"]], + startport=self.services["fwrule"]["startport"],endport=self.services["fwrule"]["endport"]) + + natrule = NATRule.create(self.api_client, virtual_machine, + self.services["natrule"],ipaddressid=public_ip_1.ipaddress.id, + networkid=network.id, vmguestip = ipaddress_1.ipaddress) + + StaticNATRule.enable(self.apiclient, public_ip_2.ipaddress.id, virtual_machine.id, + network.id, vmguestip=ipaddress_2.ipaddress) + + network.restart(self.apiclient, cleanup=False) + + natrulelist = NATRule.list(self.apiclient, id=natrule.id, listall=True) + self.assertEqual(validateList(natrulelist)[0], PASS, "nat rules list validation failed") + + self.VerifyStaticNatForPublicIp(public_ip_2.ipaddress.id, True) + return + + @data(ISOLATED_NETWORK, SHARED_NETWORK, VPC_NETWORK) + @attr(tags=["advanced"]) + def test_reboot_router_VM(self, value): + """ Test reboot router and persistence of network rules""" + + # Steps: + # 1. Create Account and create network in it (isoalted/ shared/ vpc) + # 2. Deploy a VM in this network and account + # 3. Add 2 secondary IPs to the default nic of VM + # 4. Acquire 2 public IPs in the network + # 5. For 1st public IP create nat rule to 1st private IP, for 2nd public IP, create + # static nat rule to 2nd private IP + # 6. Reboot router VM + # 7. Verify that nat and static nat rules exist after router restart + + self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id) + self.cleanup.append(self.account) + + network = createNetwork(self, value) + + try: + virtual_machine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"], + networkids=[network.id],serviceofferingid=self.service_offering.id, + accountid=self.account.name,domainid=self.account.domainid) + except Exception as e: + self.fail("vm creation failed: %s" % e) + + try: + ipaddress_1 = NIC.addIp(self.apiclient, id=virtual_machine.nic[0].id) + ipaddress_2 = NIC.addIp(self.apiclient, id=virtual_machine.nic[0].id) + except Exception as e: + self.fail("Failed while adding secondary IP to NIC of vm %s" % virtual_machine.id) + + try: + public_ip_1 = PublicIPAddress.create(self.api_client,accountid=self.account.name, + zoneid=self.zone.id,domainid=self.account.domainid, + networkid=network.id, vpcid = network.vpcid if value == VPC_NETWORK else None) + + public_ip_2 = PublicIPAddress.create(self.api_client,accountid=self.account.name, + zoneid=self.zone.id,domainid=self.account.domainid, + networkid=network.id, vpcid = network.vpcid if value == VPC_NETWORK else None) + except Exception as e: + self.fail("Exception while acquiring public ip address: %s" % e) + + if value != VPC_NETWORK: + FireWallRule.create(self.apiclient,ipaddressid=public_ip_1.ipaddress.id, + protocol='TCP', cidrlist=[self.services["fwrule"]["cidr"]], + startport=self.services["fwrule"]["startport"],endport=self.services["fwrule"]["endport"]) + + natrule = NATRule.create(self.api_client, virtual_machine, + self.services["natrule"],ipaddressid=public_ip_1.ipaddress.id, + networkid=network.id, vmguestip = ipaddress_1.ipaddress) + + StaticNATRule.enable(self.apiclient, public_ip_2.ipaddress.id, virtual_machine.id, + network.id, vmguestip=ipaddress_2.ipaddress) + + routers = Router.list(self.apiclient, networkid=network.id, listall=True) + self.assertEqual(validateList(routers)[0], PASS, "routers list validation failed") + + Router.reboot(self.apiclient, id=routers[0].id) + + natrulelist = NATRule.list(self.apiclient, id=natrule.id, listall=True) + self.assertEqual(validateList(natrulelist)[0], PASS, "nat rules list validation failed") + + self.VerifyStaticNatForPublicIp(public_ip_2.ipaddress.id, True) + return diff --git a/test/integration/component/test_netscaler_configs.py b/test/integration/component/test_netscaler_configs.py index 98613fecc56..592b351375c 100644 --- a/test/integration/component/test_netscaler_configs.py +++ b/test/integration/component/test_netscaler_configs.py @@ -22,9 +22,9 @@ import marvin from nose.plugins.attrib import attr from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * from marvin.sshClient import SshClient import datetime @@ -156,14 +156,13 @@ class TestAddNetScaler(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestAddNetScaler, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestAddNetScaler, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls._cleanup = [] return @@ -282,14 +281,13 @@ class TestInvalidParametersNetscaler(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestInvalidParametersNetscaler, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestInvalidParametersNetscaler, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls._cleanup = [] return @@ -526,14 +524,13 @@ class TestNetScalerDedicated(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestNetScalerDedicated, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestNetScalerDedicated, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, @@ -749,14 +746,13 @@ class TestNetScalerShared(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestNetScalerShared, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestNetScalerShared, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, @@ -992,14 +988,13 @@ class TestNetScalerCustomCapacity(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestNetScalerCustomCapacity, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestNetScalerCustomCapacity, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, @@ -1265,14 +1260,13 @@ class TestNetScalerNoCapacity(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestNetScalerNoCapacity, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestNetScalerNoCapacity, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, @@ -1539,14 +1533,13 @@ class TestGuestNetworkWithNetScaler(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestGuestNetworkWithNetScaler, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestGuestNetworkWithNetScaler, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, @@ -2096,14 +2089,13 @@ class TestGuestNetworkShutDown(cloudstackTestCase): @classmethod def setUpClass(cls): cls._cleanup = [] - cls.api_client = super( - TestGuestNetworkShutDown, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestGuestNetworkShutDown, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, @@ -2502,14 +2494,13 @@ class TestServiceProvider(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestServiceProvider, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestServiceProvider, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, @@ -2817,14 +2808,13 @@ class TestDeleteNetscaler(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestDeleteNetscaler, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestDeleteNetscaler, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, diff --git a/test/integration/component/test_netscaler_lb.py b/test/integration/component/test_netscaler_lb.py index 26df5459b51..732f0f9304b 100644 --- a/test/integration/component/test_netscaler_lb.py +++ b/test/integration/component/test_netscaler_lb.py @@ -22,9 +22,9 @@ import marvin from nose.plugins.attrib import attr from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * from marvin.sshClient import SshClient import datetime @@ -150,14 +150,13 @@ class TestLbSourceNat(cloudstackTestCase): @classmethod def setUpClass(cls): cls._cleanup = [] - cls.api_client = super( - TestLbSourceNat, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestLbSourceNat, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, @@ -359,14 +358,13 @@ class TestLbOnIpWithPf(cloudstackTestCase): @classmethod def setUpClass(cls): cls._cleanup = [] - cls.api_client = super( - TestLbOnIpWithPf, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestLbOnIpWithPf, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, @@ -572,14 +570,13 @@ class TestPfOnIpWithLb(cloudstackTestCase): @classmethod def setUpClass(cls): cls._cleanup = [] - cls.api_client = super( - TestPfOnIpWithLb, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestPfOnIpWithLb, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, @@ -786,14 +783,13 @@ class TestLbOnNonSourceNat(cloudstackTestCase): @classmethod def setUpClass(cls): cls._cleanup = [] - cls.api_client = super( - TestLbOnNonSourceNat, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestLbOnNonSourceNat, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, @@ -1003,14 +999,13 @@ class TestAddMultipleVmsLb(cloudstackTestCase): @classmethod def setUpClass(cls): cls._cleanup = [] - cls.api_client = super( - TestAddMultipleVmsLb, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestAddMultipleVmsLb, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, @@ -1282,14 +1277,13 @@ class TestMultipleLbRules(cloudstackTestCase): @classmethod def setUpClass(cls): cls._cleanup = [] - cls.api_client = super( - TestMultipleLbRules, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestMultipleLbRules, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, @@ -1601,14 +1595,13 @@ class TestMultipleLbRulesSameIp(cloudstackTestCase): @classmethod def setUpClass(cls): cls._cleanup = [] - cls.api_client = super( - TestMultipleLbRulesSameIp, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestMultipleLbRulesSameIp, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, @@ -1926,14 +1919,13 @@ class TestLoadBalancingRule(cloudstackTestCase): @classmethod def setUpClass(cls): cls._cleanup = [] - cls.api_client = super( - TestLoadBalancingRule, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestLoadBalancingRule, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, @@ -2140,14 +2132,13 @@ class TestDeleteCreateLBRule(cloudstackTestCase): @classmethod def setUpClass(cls): cls._cleanup = [] - cls.api_client = super( - TestDeleteCreateLBRule, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestDeleteCreateLBRule, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, @@ -2269,14 +2260,13 @@ class TestVmWithLb(cloudstackTestCase): @classmethod def setUpClass(cls): cls._cleanup = [] - cls.api_client = super( - TestVmWithLb, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestVmWithLb, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, diff --git a/test/integration/component/test_netscaler_lb_algo.py b/test/integration/component/test_netscaler_lb_algo.py index 3c18fcd36d9..6eda9a3f401 100644 --- a/test/integration/component/test_netscaler_lb_algo.py +++ b/test/integration/component/test_netscaler_lb_algo.py @@ -22,11 +22,10 @@ import marvin from nose.plugins.attrib import attr from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * from marvin.sshClient import SshClient -import datetime class Services: @@ -117,14 +116,13 @@ class TestLbWithRoundRobin(cloudstackTestCase): @classmethod def setUpClass(cls): cls._cleanup = [] - cls.api_client = super( - TestLbWithRoundRobin, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestLbWithRoundRobin, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, @@ -330,14 +328,13 @@ class TestLbWithLeastConn(cloudstackTestCase): @classmethod def setUpClass(cls): cls._cleanup = [] - cls.api_client = super( - TestLbWithLeastConn, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestLbWithLeastConn, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, @@ -552,14 +549,13 @@ class TestLbWithSourceIp(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestLbWithSourceIp, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestLbWithSourceIp, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, @@ -768,14 +764,13 @@ class TestLbAlgoRrLc(cloudstackTestCase): @classmethod def setUpClass(cls): cls._cleanup = [] - cls.api_client = super( - TestLbAlgoRrLc, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestLbAlgoRrLc, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, @@ -973,14 +968,13 @@ class TestLbAlgoLcRr(cloudstackTestCase): @classmethod def setUpClass(cls): cls._cleanup = [] - cls.api_client = super( - TestLbAlgoLcRr, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestLbAlgoLcRr, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, @@ -1175,14 +1169,13 @@ class TestLbAlgoRrSb(cloudstackTestCase): @classmethod def setUpClass(cls): cls._cleanup = [] - cls.api_client = super( - TestLbAlgoRrSb, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestLbAlgoRrSb, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, @@ -1380,14 +1373,13 @@ class TestLbAlgoSbRr(cloudstackTestCase): @classmethod def setUpClass(cls): cls._cleanup = [] - cls.api_client = super( - TestLbAlgoSbRr, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestLbAlgoSbRr, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, @@ -1588,14 +1580,13 @@ class TestLbAlgoSbLc(cloudstackTestCase): @classmethod def setUpClass(cls): cls._cleanup = [] - cls.api_client = super( - TestLbAlgoSbLc, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestLbAlgoSbLc, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, @@ -1795,14 +1786,13 @@ class TestLbAlgoLcSb(cloudstackTestCase): @classmethod def setUpClass(cls): cls._cleanup = [] - cls.api_client = super( - TestLbAlgoLcSb, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestLbAlgoLcSb, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, diff --git a/test/integration/component/test_netscaler_lb_sticky.py b/test/integration/component/test_netscaler_lb_sticky.py index 6c27a08052a..c333f60c68f 100644 --- a/test/integration/component/test_netscaler_lb_sticky.py +++ b/test/integration/component/test_netscaler_lb_sticky.py @@ -22,9 +22,9 @@ import marvin from nose.plugins.attrib import attr from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * from marvin.sshClient import SshClient import datetime @@ -117,14 +117,13 @@ class TestLbStickyPolicy(cloudstackTestCase): @classmethod def setUpClass(cls): cls._cleanup = [] - cls.api_client = super( - TestLbStickyPolicy, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestLbStickyPolicy, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, diff --git a/test/integration/component/test_netscaler_nw_off.py b/test/integration/component/test_netscaler_nw_off.py index a94f01d6e7f..d3f1f9e8814 100644 --- a/test/integration/component/test_netscaler_nw_off.py +++ b/test/integration/component/test_netscaler_nw_off.py @@ -22,9 +22,9 @@ import marvin from nose.plugins.attrib import attr from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * from marvin.sshClient import SshClient import datetime @@ -191,14 +191,13 @@ class TestAddMultipleNetScaler(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestAddMultipleNetScaler, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestAddMultipleNetScaler, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls._cleanup = [] return @@ -506,14 +505,13 @@ class TestNetScalerSharedMode(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestNetScalerSharedMode, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestNetScalerSharedMode, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, @@ -1051,14 +1049,13 @@ class TestNwOffDedicatedNetscaler(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestNwOffDedicatedNetscaler, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestNwOffDedicatedNetscaler, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, @@ -1217,14 +1214,13 @@ class TestNwOffNetscaler(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestNwOffNetscaler, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestNwOffNetscaler, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, @@ -1525,14 +1521,13 @@ class TestNwOffSToDUpgrade(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestNwOffSToDUpgrade, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestNwOffSToDUpgrade, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, @@ -1940,14 +1935,13 @@ class TestNwOffDToSUpgrade(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestNwOffDToSUpgrade, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestNwOffDToSUpgrade, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, @@ -2341,15 +2335,13 @@ class TestNOWithNetscaler(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestNOWithNetscaler, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestNOWithNetscaler, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype cls.template = get_template( cls.api_client, diff --git a/test/integration/component/test_network_offering.py b/test/integration/component/test_network_offering.py index 7040722e8fa..b0b6906913a 100644 --- a/test/integration/component/test_network_offering.py +++ b/test/integration/component/test_network_offering.py @@ -22,9 +22,9 @@ import marvin from nose.plugins.attrib import attr from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * import datetime @@ -160,14 +160,13 @@ class TestNOVirtualRouter(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestNOVirtualRouter, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestNOVirtualRouter, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype cls.template = get_template( cls.api_client, @@ -733,14 +732,13 @@ class TestNetworkUpgrade(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestNetworkUpgrade, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestNetworkUpgrade, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype cls.template = get_template( cls.api_client, @@ -1181,14 +1179,13 @@ class TestNetworkUpgrade(cloudstackTestCase): class TestNOWithOnlySourceNAT(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.apiclient = super( - TestNOWithOnlySourceNAT, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestNOWithOnlySourceNAT, cls).getClsTestClient() + cls.apiclient = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.apiclient, cls.services) - cls.zone = get_zone(cls.apiclient, cls.services) + cls.domain = get_domain(cls.apiclient) + cls.zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype cls.template = get_template( cls.apiclient, diff --git a/test/integration/component/test_non_contiguous_vlan.py b/test/integration/component/test_non_contiguous_vlan.py index 3ebaf3a97e3..4609af95f13 100644 --- a/test/integration/component/test_non_contiguous_vlan.py +++ b/test/integration/component/test_non_contiguous_vlan.py @@ -28,17 +28,17 @@ from marvin.cloudstackTestCase import (cloudstackTestCase,unittest) -from marvin.integration.lib.base import (Account, +from marvin.lib.base import (Account, ServiceOffering, PhysicalNetwork, VirtualMachine, ) -from marvin.integration.lib.common import (get_zone, +from marvin.lib.common import (get_zone, get_pod, get_domain, get_template, setNonContiguousVlanIds) -from marvin.integration.lib.utils import (cleanup_resources, +from marvin.lib.utils import (cleanup_resources, xsplit) from nose.plugins.attrib import attr @@ -47,7 +47,7 @@ class Services(): def __init__(self): self.services = { - "vlan": { + "vlan_nc": { "partial_range": ["",""], "full_range": "", }, @@ -89,12 +89,14 @@ class TestNonContiguousVLANRanges(cloudstackTestCase): """ @classmethod def setUpClass(cls): - cls.api_client = super(TestNonContiguousVLANRanges, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestNonContiguousVLANRanges, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services - # Get Zone, pod, domain - cls.zone = get_zone(cls.api_client, cls.services) - cls.pod = get_pod(cls.api_client, cls.zone.id, cls.services) - cls.domain = get_domain(cls.api_client, cls.services) + # Get Zone, Domain and templates + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) + cls.pod = get_pod(cls.api_client, cls.zone.id) + cls.domain = get_domain(cls.api_client) cls.service_offering = ServiceOffering.create( cls.api_client, @@ -123,7 +125,7 @@ class TestNonContiguousVLANRanges(cloudstackTestCase): def setUp(self): self.apiclient = self.testClient.getApiClient() - self.vlan = self.services["vlan"] + self.vlan = self.services["vlan_nc"] self.apiClient = self.testClient.getApiClient() self.physicalnetwork, self.vlan = setNonContiguousVlanIds(self.apiclient, self.zone.id) diff --git a/test/integration/component/test_persistent_networks.py b/test/integration/component/test_persistent_networks.py index 134b9b55977..4c1798ff588 100644 --- a/test/integration/component/test_persistent_networks.py +++ b/test/integration/component/test_persistent_networks.py @@ -14,64 +14,35 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. -""" Tests for Persistent Networks without running VMs feature - - Test Plan: https://cwiki.apache.org/confluence/display/CLOUDSTACK/Persistent+Networks+without+a+running+VM - - Issue Link: https://issues.apache.org/jira/browse/CLOUDSTACK-2232 - - Feature Specifications: https://cwiki.apache.org/confluence/display/CLOUDSTACK/FS+-+Persistent+Networks -""" -from marvin.cloudstackTestCase import cloudstackTestCase, unittest -from marvin.integration.lib.utils import (cleanup_resources, - validateList, - get_hypervisor_type) -from marvin.integration.lib.base import (Account, - ServiceOffering, - NetworkOffering, - Network, - VirtualMachine, - PublicIPAddress, - FireWallRule, - Router, - Host, - NATRule, - Project, - LoadBalancerRule, - VpcOffering, - VPC, - Domain, - StaticNATRule, - NetworkACL) -from marvin.integration.lib.common import (get_domain, - get_zone, - get_template, - wait_for_cleanup, - add_netscaler, - verifyNetworkState) - +""" Tests for Persistent Networks without running VMs feature""" +from marvin.cloudstackException import CloudstackAPIException +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * +import netaddr from nose.plugins.attrib import attr -from marvin.codes import PASS, FAIL +from marvin.codes import PASS, FAIL, FAILED from marvin.sshClient import SshClient +from marvin.cloudstackTestCase import cloudstackTestCase, unittest from ddt import ddt, data import time @ddt class TestPersistentNetworks(cloudstackTestCase): - """Test Persistent Networks without running VMs - """ - + ''' + Test Persistent Networks without running VMs + ''' @classmethod def setUpClass(cls): - cloudstackTestClient = super(TestPersistentNetworks,cls).getClsTestClient() - cls.api_client = cloudstackTestClient.getApiClient() + cls.testClient = super(TestPersistentNetworks, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() # Fill services from the external config file - cls.services = cloudstackTestClient.getConfigParser().parsedDict + cls.services = cls.testClient.getParsedTestDataConfig() # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, @@ -1005,20 +976,22 @@ class TestAssignVirtualMachine(cloudstackTestCase): @classmethod def setUpClass(cls): - cloudstackTestClient = super(TestAssignVirtualMachine,cls).getClsTestClient() - cls.api_client = cloudstackTestClient.getApiClient() + cls.testClient = super(TestAssignVirtualMachine, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() # Fill services from the external config file - cls.services = cloudstackTestClient.getConfigParser().parsedDict + cls.services = cls.testClient.getParsedTestDataConfig() # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, cls.services["ostype"] ) + if cls.template == FAILED: + assert False, "get_template() failed to return template with description %s" % cls.services["ostype"] cls.services["virtual_machine"]["zoneid"] = cls.zone.id cls.services["virtual_machine"]["template"] = cls.template.id cls.service_offering = ServiceOffering.create( @@ -1165,20 +1138,22 @@ class TestProjectAccountOperations(cloudstackTestCase): @classmethod def setUpClass(cls): - cloudstackTestClient = super(TestProjectAccountOperations,cls).getClsTestClient() - cls.api_client = cloudstackTestClient.getApiClient() + cls.testClient = super(TestProjectAccountOperations, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() # Fill services from the external config file - cls.services = cloudstackTestClient.getConfigParser().parsedDict + cls.services = cls.testClient.getParsedTestDataConfig() # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, cls.services["ostype"] ) + if cls.template == FAILED: + assert False, "get_template() failed to return template with description %s" % cls.services["ostype"] cls.services["virtual_machine"]["zoneid"] = cls.zone.id cls.services["virtual_machine"]["template"] = cls.template.id cls.service_offering = ServiceOffering.create( @@ -1338,20 +1313,22 @@ class TestRestartPersistentNetwork(cloudstackTestCase): @classmethod def setUpClass(cls): - cloudstackTestClient = super(TestRestartPersistentNetwork,cls).getClsTestClient() - cls.api_client = cloudstackTestClient.getApiClient() + cls.testClient = super(TestRestartPersistentNetwork, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() # Fill services from the external config file - cls.services = cloudstackTestClient.getConfigParser().parsedDict + cls.services = cls.testClient.getParsedTestDataConfig() # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, cls.services["ostype"] ) + if cls.template == FAILED: + assert False, "get_template() failed to return template with description %s" % cls.services["ostype"] cls.services["virtual_machine"]["zoneid"] = cls.zone.id cls.services["virtual_machine"]["template"] = cls.template.id cls.service_offering = ServiceOffering.create( @@ -1618,25 +1595,28 @@ class TestVPCNetworkOperations(cloudstackTestCase): @classmethod def setUpClass(cls): - cloudstackTestClient = super(TestVPCNetworkOperations,cls).getClsTestClient() - cls.api_client = cloudstackTestClient.getApiClient() + cls.testClient = super(TestVPCNetworkOperations, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() # Fill services from the external config file - cls.services = cloudstackTestClient.getConfigParser().parsedDict + cls.services = cls.testClient.getParsedTestDataConfig() # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, cls.services["ostype"] ) + if cls.template == FAILED: + assert False, "get_template() failed to return template with description %s" % cls.services["ostype"] + cls.services["virtual_machine"]["zoneid"] = cls.zone.id cls.services["virtual_machine"]["template"] = cls.template.id cls.service_offering = ServiceOffering.create( cls.api_client, - cls.services["service_offering"] + cls.services["service_offerings"]["small"] ) cls.persistent_network_offering_NoLB = NetworkOffering.create(cls.api_client, cls.services["nw_off_persistent_VPCVR_NoLB"], conservemode=False) diff --git a/test/integration/component/test_portable_ip.py b/test/integration/component/test_portable_ip.py index e8bf4f5b114..61268ebc7c3 100644 --- a/test/integration/component/test_portable_ip.py +++ b/test/integration/component/test_portable_ip.py @@ -21,25 +21,11 @@ Feature Specifications: https://cwiki.apache.org/confluence/display/CLOUDSTACK/portable+public+IP """ from marvin.cloudstackTestCase import cloudstackTestCase -from marvin.integration.lib.utils import cleanup_resources -from marvin.integration.lib.base import (Account, - NetworkOffering, - ServiceOffering, - Network, - VirtualMachine, - PublicIPAddress, - FireWallRule, - NATRule, - PortablePublicIpRange, - StaticNATRule) -from marvin.integration.lib.common import (get_zone, - get_pod, - get_domain, - get_region, - get_template, - get_portable_ip_range_services, - is_public_ip_in_correct_state) -from netaddr import IPAddress +from marvin.cloudstackException import CloudstackAPIException +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * +from netaddr import * from marvin.sshClient import SshClient from nose.plugins.attrib import attr @@ -144,6 +130,14 @@ class Services: "protocol": 'TCP', }, "ostype": 'CentOS 5.3 (64-bit)', + "portableIpRange": { + "gateway" : "10.223.252.195", + "netmask" : "255.255.255.192", + "startip" : "10.223.252.196", + "endip" : "10.223.252.197", + "vlan" : "1001" + } + } class TestCreatePortablePublicIpRanges(cloudstackTestCase): @@ -153,13 +147,15 @@ class TestCreatePortablePublicIpRanges(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestCreatePortablePublicIpRanges, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestCreatePortablePublicIpRanges, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.region = get_region(cls.api_client, cls.services) - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) - cls.pod = get_pod(cls.api_client, cls.zone.id, cls.services) + cls.region = get_region(cls.api_client) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) + cls.pod = get_pod(cls.api_client, cls.zone.id) cls.services['mode'] = cls.zone.networktype cls.services["domainid"] = cls.domain.id cls.services["zoneid"] = cls.zone.id @@ -199,7 +195,7 @@ class TestCreatePortablePublicIpRanges(cloudstackTestCase): # 1. Create new portable ip range with root admin api # 2. Portable ip range should be created successfully - portable_ip_range_services = get_portable_ip_range_services(self.config) + portable_ip_range_services = self.services["portableIpRange"] self.debug(portable_ip_range_services) @@ -238,12 +234,12 @@ class TestCreatePortablePublicIpRanges(cloudstackTestCase): domainid=self.domain.id ) - self.api_client_user = self.testClient.createUserApiClient( + self.api_client_user = self.testClient.getUserApiClient( UserName=self.account.name, DomainName=self.account.domain ) - portable_ip_range_services = get_portable_ip_range_services(self.config) + portable_ip_range_services = self.services["portableIpRange"] if portable_ip_range_services is None: self.skipTest('Failed to read config values related to portable ip range') @@ -265,7 +261,7 @@ class TestCreatePortablePublicIpRanges(cloudstackTestCase): # 1. Try to create new portable ip range with invalid region id # 2. Portable ip range creation should fail - portable_ip_range_services = get_portable_ip_range_services(self.config) + portable_ip_range_services = self.services["portableIpRange"] if portable_ip_range_services is None: self.skipTest('Failed to read config values related to portable ip range') @@ -289,13 +285,15 @@ class TestDeletePortablePublicIpRanges(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestDeletePortablePublicIpRanges, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestDeletePortablePublicIpRanges, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.region = get_region(cls.api_client, cls.services) - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) - cls.pod = get_pod(cls.api_client, cls.zone.id, cls.services) + cls.region = get_region(cls.api_client) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) + cls.pod = get_pod(cls.api_client, cls.zone.id) cls.services['mode'] = cls.zone.networktype cls.services["domainid"] = cls.domain.id cls.services["zoneid"] = cls.zone.id @@ -317,7 +315,7 @@ class TestDeletePortablePublicIpRanges(cloudstackTestCase): self.apiclient = self.testClient.getApiClient() self.dbclient = self.testClient.getDbConnection() - portable_ip_range_services = get_portable_ip_range_services(self.config) + portable_ip_range_services = self.services["portableIpRange"] if portable_ip_range_services is None: self.skipTest('Failed to read config values related to portable ip range') @@ -378,7 +376,7 @@ class TestDeletePortablePublicIpRanges(cloudstackTestCase): self.cleanup.append(self.account) - self.api_client_user = self.testClient.createUserApiClient( + self.api_client_user = self.testClient.getUserApiClient( UserName=self.account.name, DomainName=self.account.domain ) @@ -461,13 +459,15 @@ class TestListPortablePublicIpRanges(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestListPortablePublicIpRanges, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestListPortablePublicIpRanges, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.region = get_region(cls.api_client, cls.services) - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) - cls.pod = get_pod(cls.api_client, cls.zone.id, cls.services) + cls.region = get_region(cls.api_client) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) + cls.pod = get_pod(cls.api_client, cls.zone.id) cls.services['mode'] = cls.zone.networktype cls.services["domainid"] = cls.domain.id cls.services["zoneid"] = cls.zone.id @@ -490,7 +490,7 @@ class TestListPortablePublicIpRanges(cloudstackTestCase): self.dbclient = self.testClient.getDbConnection() #create new portable ip range - self.portable_ip_range_services = get_portable_ip_range_services(self.config) + self.portable_ip_range_services = self.services["portableIpRange"] if self.portable_ip_range_services is None: self.skipTest('Failed to read config values related to portable ip range') @@ -569,7 +569,7 @@ class TestListPortablePublicIpRanges(cloudstackTestCase): self.cleanup.append(self.account) - self.api_client_user = self.testClient.createUserApiClient( + self.api_client_user = self.testClient.getUserApiClient( UserName=self.account.name, DomainName=self.account.domain ) @@ -585,13 +585,15 @@ class TestAssociatePublicIp(cloudstackTestCase): """ @classmethod def setUpClass(cls): - cls.api_client = super(TestAssociatePublicIp, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestAssociatePublicIp, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.region = get_region(cls.api_client, cls.services) - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) - cls.pod = get_pod(cls.api_client, cls.zone.id, cls.services) + cls.region = get_region(cls.api_client) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) + cls.pod = get_pod(cls.api_client, cls.zone.id) cls.services['mode'] = cls.zone.networktype cls.services["domainid"] = cls.domain.id cls.services["zoneid"] = cls.zone.id @@ -651,7 +653,7 @@ class TestAssociatePublicIp(cloudstackTestCase): self.cleanup = [] - portable_ip_range_services = get_portable_ip_range_services(self.config) + portable_ip_range_services = self.services["portableIpRange"] if portable_ip_range_services is None: self.skipTest('Failed to read config values related to portable ip range') @@ -909,13 +911,15 @@ class TestDisassociatePublicIp(cloudstackTestCase): """ @classmethod def setUpClass(cls): - cls.api_client = super(TestDisassociatePublicIp, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestDisassociatePublicIp, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.region = get_region(cls.api_client, cls.services) - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) - cls.pod = get_pod(cls.api_client, cls.zone.id, cls.services) + cls.region = get_region(cls.api_client) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) + cls.pod = get_pod(cls.api_client, cls.zone.id) cls.services['mode'] = cls.zone.networktype cls.services["domainid"] = cls.domain.id cls.services["zoneid"] = cls.zone.id @@ -993,7 +997,7 @@ class TestDisassociatePublicIp(cloudstackTestCase): self.dbclient = self.testClient.getDbConnection() self.cleanup = [] - portable_ip_range_services = get_portable_ip_range_services(self.config) + portable_ip_range_services = self.services["portableIpRange"] if portable_ip_range_services is None: self.skipTest('Failed to read config values related to portable ip range') @@ -1144,7 +1148,7 @@ class TestDisassociatePublicIp(cloudstackTestCase): domainid=self.domain.id ) - self.api_client_user = self.testClient.createUserApiClient( + self.api_client_user = self.testClient.getUserApiClient( UserName=self.user_account.name, DomainName=self.user_account.domain ) @@ -1168,14 +1172,16 @@ class TestDeleteAccount(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestDeleteAccount, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestDeleteAccount, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.region = get_region(cls.api_client, cls.services) - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.region = get_region(cls.api_client) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype - cls.pod = get_pod(cls.api_client, cls.zone.id, cls.services) + cls.pod = get_pod(cls.api_client, cls.zone.id) cls.services['mode'] = cls.zone.networktype cls.services["domainid"] = cls.domain.id cls.services["zoneid"] = cls.zone.id @@ -1213,7 +1219,7 @@ class TestDeleteAccount(cloudstackTestCase): ) self.cleanup = [] - portable_ip_range_services = get_portable_ip_range_services(self.config) + portable_ip_range_services = self.services["portableIpRange"] if portable_ip_range_services is None: self.skipTest('Failed to read config values related to portable ip range') @@ -1393,13 +1399,15 @@ class TestPortableIpTransferAcrossNetworks(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestPortableIpTransferAcrossNetworks, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestPortableIpTransferAcrossNetworks, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.region = get_region(cls.api_client, cls.services) - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) - cls.pod = get_pod(cls.api_client, cls.zone.id, cls.services) + cls.region = get_region(cls.api_client) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) + cls.pod = get_pod(cls.api_client, cls.zone.id) cls.services['mode'] = cls.zone.networktype cls.services["domainid"] = cls.domain.id cls.services["zoneid"] = cls.zone.id @@ -1488,7 +1496,7 @@ class TestPortableIpTransferAcrossNetworks(cloudstackTestCase): self.dbclient = self.testClient.getDbConnection() #create new portable ip range - self.portable_ip_range_services = get_portable_ip_range_services(self.config) + self.portable_ip_range_services = self.services["portableIpRange"] if self.portable_ip_range_services is None: self.skipTest('Failed to read config values related to portable ip range') diff --git a/test/integration/component/test_project_configs.py b/test/integration/component/test_project_configs.py index 4d878f73f83..4b777fececd 100644 --- a/test/integration/component/test_project_configs.py +++ b/test/integration/component/test_project_configs.py @@ -21,9 +21,9 @@ import marvin from nose.plugins.attrib import attr from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * from marvin.sshClient import SshClient import datetime @@ -109,13 +109,11 @@ class TestUserProjectCreation(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestUserProjectCreation, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestUserProjectCreation, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services - # Get Zone - cls.zone = get_zone(cls.api_client, cls.services) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype configs = Configurations.list( @@ -275,13 +273,11 @@ class TestProjectCreationNegative(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestProjectCreationNegative, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestProjectCreationNegative, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services - # Get Zone - cls.zone = get_zone(cls.api_client, cls.services) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype # Checking for prereqisits - global configs @@ -420,17 +416,15 @@ class TestProjectInviteRequired(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestProjectInviteRequired, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestProjectInviteRequired, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services - # Get Zone - cls.zone = get_zone(cls.api_client, cls.services) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype # Create domains, account etc. - cls.domain = get_domain(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) # Verify 'project.invite.required' is set to false configs = Configurations.list( @@ -572,17 +566,15 @@ class TestProjectInviteRequiredTrue(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestProjectInviteRequiredTrue, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestProjectInviteRequiredTrue, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services - # Get Zone - cls.zone = get_zone(cls.api_client, cls.services) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype # Create domains, account etc. - cls.domain = get_domain(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) # Verify 'project.invite.required' is set to true configs = Configurations.list( @@ -725,17 +717,15 @@ class TestProjectInviteTimeout(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestProjectInviteTimeout, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestProjectInviteTimeout, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services - # Get Zone - cls.zone = get_zone(cls.api_client, cls.services) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype # Create domains, account etc. - cls.domain = get_domain(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) # Verify 'project.invite.required' is set to true configs = Configurations.list( diff --git a/test/integration/component/test_project_limits.py b/test/integration/component/test_project_limits.py index 7d938764b8f..79413131824 100644 --- a/test/integration/component/test_project_limits.py +++ b/test/integration/component/test_project_limits.py @@ -21,9 +21,9 @@ import marvin from nose.plugins.attrib import attr from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * from marvin.codes import PASS import datetime @@ -124,13 +124,11 @@ class TestProjectLimits(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestProjectLimits, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestProjectLimits, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services - # Get Zone - cls.zone = get_zone(cls.api_client, cls.services) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype # Create domains, account etc. @@ -502,10 +500,11 @@ class TestResourceLimitsProject(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestResourceLimitsProject, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestResourceLimitsProject, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services - # Get Zone, Domain and templates - cls.zone = get_zone(cls.api_client, cls.services) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype cls.template = get_template( @@ -945,14 +944,12 @@ class TestMaxProjectNetworks(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestMaxProjectNetworks, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestMaxProjectNetworks, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services - # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) + cls.domain = get_domain(cls.api_client) cls.services['mode'] = cls.zone.networktype cls.template = get_template( cls.api_client, diff --git a/test/integration/component/test_project_resources.py b/test/integration/component/test_project_resources.py index 7fb23a42e4a..8f81cf9dc35 100644 --- a/test/integration/component/test_project_resources.py +++ b/test/integration/component/test_project_resources.py @@ -19,7 +19,7 @@ #Import Local Modules from nose.plugins.attrib import attr from marvin.cloudstackTestCase import cloudstackTestCase, unittest -from marvin.integration.lib.base import (VirtualMachine, +from marvin.lib.base import (VirtualMachine, Account, Project, NATRule, @@ -35,7 +35,7 @@ from marvin.integration.lib.base import (VirtualMachine, DiskOffering, LoadBalancerRule) -from marvin.integration.lib.common import (get_zone, +from marvin.lib.common import (get_zone, get_template, get_domain, list_volumes, @@ -44,7 +44,7 @@ from marvin.integration.lib.common import (get_zone, get_free_vlan, wait_for_cleanup) -from marvin.integration.lib.utils import cleanup_resources +from marvin.lib.utils import cleanup_resources import random @@ -161,13 +161,11 @@ class TestOfferings(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestOfferings, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestOfferings, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services - # Get Zone and template - cls.zone = get_zone(cls.api_client, cls.services) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype cls.template = get_template( cls.api_client, @@ -342,13 +340,11 @@ class TestNetwork(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestNetwork, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestNetwork, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services - # Get Zone and template - cls.zone = get_zone(cls.api_client, cls.services) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype cls.template = get_template( cls.api_client, @@ -550,13 +546,11 @@ class TestTemplates(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestTemplates, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestTemplates, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services - # Get Zone, Domain and templates - cls.zone = get_zone(cls.api_client, cls.services) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype cls.template = get_template( @@ -780,13 +774,11 @@ class TestSnapshots(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestSnapshots, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestSnapshots, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services - # Get Zone, Domain and templates - cls.zone = get_zone(cls.api_client, cls.services) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype cls.template = get_template( @@ -928,13 +920,11 @@ class TestPublicIpAddress(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestPublicIpAddress, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestPublicIpAddress, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services - # Get Zone, Domain and templates - cls.zone = get_zone(cls.api_client, cls.services) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype cls.template = get_template( @@ -1213,15 +1203,12 @@ class TestSecurityGroup(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.services = Services().services - cls.api_client = super( - TestSecurityGroup, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestSecurityGroup, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() - # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.services = Services().services + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) + cls.domain = get_domain(cls.api_client) cls.services['mode'] = cls.zone.networktype template = get_template( diff --git a/test/integration/component/test_project_usage.py b/test/integration/component/test_project_usage.py index 10f48a68eff..16ca8c1ba64 100644 --- a/test/integration/component/test_project_usage.py +++ b/test/integration/component/test_project_usage.py @@ -21,9 +21,9 @@ import marvin from nose.plugins.attrib import attr from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * from marvin.sshClient import SshClient import datetime @@ -116,14 +116,13 @@ class TestVmUsage(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestVmUsage, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestVmUsage, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype template = get_template( @@ -311,14 +310,13 @@ class TestPublicIPUsage(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestPublicIPUsage, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestPublicIPUsage, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype cls.template = get_template( @@ -483,14 +481,13 @@ class TestVolumeUsage(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestVolumeUsage, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestVolumeUsage, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype cls.disk_offering = DiskOffering.create( cls.api_client, @@ -668,14 +665,13 @@ class TestTemplateUsage(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestTemplateUsage, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestTemplateUsage, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype cls.services["server"]["zoneid"] = cls.zone.id template = get_template( @@ -844,11 +840,13 @@ class TestISOUsage(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestISOUsage, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestISOUsage, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype cls.services["server"]["zoneid"] = cls.zone.id cls.services["iso"]["zoneid"] = cls.zone.id @@ -990,14 +988,13 @@ class TestLBRuleUsage(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestLBRuleUsage, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestLBRuleUsage, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype template = get_template( cls.api_client, @@ -1173,14 +1170,13 @@ class TestSnapshotUsage(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestSnapshotUsage, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestSnapshotUsage, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype template = get_template( @@ -1351,14 +1347,13 @@ class TestNatRuleUsage(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestNatRuleUsage, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestNatRuleUsage, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype template = get_template( cls.api_client, @@ -1534,14 +1529,13 @@ class TestVpnUsage(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestVpnUsage, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestVpnUsage, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype template = get_template( cls.api_client, diff --git a/test/integration/component/test_projects.py b/test/integration/component/test_projects.py index 1a00f587dc3..c593fb6d9ef 100644 --- a/test/integration/component/test_projects.py +++ b/test/integration/component/test_projects.py @@ -21,9 +21,9 @@ import marvin from nose.plugins.attrib import attr from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * from marvin.sshClient import SshClient import datetime @@ -103,20 +103,14 @@ class TestMultipleProjectCreation(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestMultipleProjectCreation, - cls - ).getClsTestClient().getApiClient() - cls.services = Services().services - # Get Zone - cls.zone = get_zone(cls.api_client, cls.services) - cls.services['mode'] = cls.zone.networktype + cls.testClient = super(TestMultipleProjectCreation, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() - # Create domains, account etc. - cls.domain = get_domain( - cls.api_client, - cls.services - ) + cls.services = Services().services + # Get Zone, Domain and templates + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) + cls.services['mode'] = cls.zone.networktype configs = Configurations.list( cls.api_client, @@ -320,18 +314,14 @@ class TestCrossDomainAccountAdd(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestCrossDomainAccountAdd, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestCrossDomainAccountAdd, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services - # Get Zone - cls.zone = get_zone(cls.api_client, cls.services) + # Get Zone, Domain and templates + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype - cls.domain = get_domain( - cls.api_client, - cls.services - ) configs = Configurations.list( cls.api_client, @@ -454,18 +444,14 @@ class TestDeleteAccountWithProject(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestDeleteAccountWithProject, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestDeleteAccountWithProject, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services - # Get Zone - cls.zone = get_zone(cls.api_client, cls.services) + # Get Zone, Domain and templates + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype - cls.domain = get_domain( - cls.api_client, - cls.services - ) configs = Configurations.list( cls.api_client, @@ -567,13 +553,12 @@ class TestDeleteDomainWithProject(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestDeleteDomainWithProject, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestDeleteDomainWithProject, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone - cls.zone = get_zone(cls.api_client, cls.services) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype configs = Configurations.list( @@ -708,17 +693,13 @@ class TestProjectOwners(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestProjectOwners, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestProjectOwners, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone - cls.domain = get_domain( - cls.api_client, - cls.services - ) - cls.zone = get_zone(cls.api_client, cls.services) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) + cls.domain = get_domain(cls.api_client) cls.services['mode'] = cls.zone.networktype configs = Configurations.list( @@ -1136,18 +1117,14 @@ class TestProjectResources(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestProjectResources, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestProjectResources, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone - cls.zone = get_zone(cls.api_client, cls.services) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) + cls.domain = get_domain(cls.api_client) cls.services['mode'] = cls.zone.networktype - cls.domain = get_domain( - cls.api_client, - cls.services - ) configs = Configurations.list( cls.api_client, @@ -1440,18 +1417,14 @@ class TestProjectSuspendActivate(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestProjectSuspendActivate, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestProjectSuspendActivate, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services - # Get Zone, domain, template etc - cls.zone = get_zone(cls.api_client, cls.services) + # Get Zone + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) + cls.domain = get_domain(cls.api_client) cls.services['mode'] = cls.zone.networktype - cls.domain = get_domain( - cls.api_client, - cls.services - ) cls.template = get_template( cls.api_client, cls.zone.id, diff --git a/test/integration/component/test_recurring_snapshots.py b/test/integration/component/test_recurring_snapshots.py index fd1b57da071..2ef2bc3678c 100644 --- a/test/integration/component/test_recurring_snapshots.py +++ b/test/integration/component/test_recurring_snapshots.py @@ -18,9 +18,9 @@ from nose.plugins.attrib import attr from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * class Services: """Test Snapshots Services @@ -126,11 +126,13 @@ class TestRecurringSnapshots(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestRecurringSnapshots, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestRecurringSnapshots, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype cls.disk_offering = DiskOffering.create( cls.api_client, @@ -402,4 +404,4 @@ class TestRecurringSnapshots(cloudstackTestCase): self.services["recurring_snapshot"]["maxsnaps"], "Check maximum number of recurring snapshots retained" ) - return \ No newline at end of file + return diff --git a/test/integration/component/test_redundant_router_cleanups.py b/test/integration/component/test_redundant_router_cleanups.py index 84cbc6ffc8b..2220d510df6 100644 --- a/test/integration/component/test_redundant_router_cleanups.py +++ b/test/integration/component/test_redundant_router_cleanups.py @@ -16,9 +16,9 @@ # under the License. from nose.plugins.attrib import attr -from marvin.integration.lib.base import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.common import * +from marvin.lib.base import * +from marvin.lib.utils import * +from marvin.lib.common import * #Import Local Modules from marvin.cloudstackTestCase import cloudstackTestCase @@ -137,14 +137,13 @@ class TestRedundantRouterNetworkCleanups(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestRedundantRouterNetworkCleanups, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestRedundantRouterNetworkCleanups, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, diff --git a/test/integration/component/test_redundant_router_services.py b/test/integration/component/test_redundant_router_services.py index 5204d6f500d..707b673b537 100644 --- a/test/integration/component/test_redundant_router_services.py +++ b/test/integration/component/test_redundant_router_services.py @@ -17,9 +17,9 @@ from nose.plugins.attrib import attr -from marvin.integration.lib.base import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.common import * +from marvin.lib.base import * +from marvin.lib.utils import * +from marvin.lib.common import * #Import Local Modules from marvin.cloudstackTestCase import cloudstackTestCase @@ -138,14 +138,13 @@ class TestEnableVPNOverRvR(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestEnableVPNOverRvR, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestEnableVPNOverRvR, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, diff --git a/test/integration/component/test_redundant_router_upgrades.py b/test/integration/component/test_redundant_router_upgrades.py index bd38c14e02d..6c177effa25 100644 --- a/test/integration/component/test_redundant_router_upgrades.py +++ b/test/integration/component/test_redundant_router_upgrades.py @@ -17,9 +17,9 @@ from nose.plugins.attrib import attr -from marvin.integration.lib.base import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.common import * +from marvin.lib.base import * +from marvin.lib.utils import * +from marvin.lib.common import * #Import Local Modules from marvin.cloudstackTestCase import cloudstackTestCase @@ -137,14 +137,13 @@ class TestRvRUpgradeDowngrade(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestRvRUpgradeDowngrade, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestRvRUpgradeDowngrade, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, diff --git a/test/integration/component/test_region_vpc.py b/test/integration/component/test_region_vpc.py index 2cd9de9073a..e34806521de 100644 --- a/test/integration/component/test_region_vpc.py +++ b/test/integration/component/test_region_vpc.py @@ -23,9 +23,9 @@ import marvin from nose.plugins.attrib import attr from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * from marvin.sshClient import SshClient import datetime @@ -159,24 +159,30 @@ class TestRegionVpcOffering(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestRegionVpcOffering, - cls - ).getClsTestClient().getApiClient() - cls.services = Services().services + testClient = super(TestRegionVpcOffering, cls).getClsTestClient() + cls.apiclient = testClient.getApiClient() + cls.services = testClient.getParsedTestDataConfig() + # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.apiclient) + cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests()) + cls.services['mode'] = cls.zone.networktype + + cls.template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) + cls.apiclient, + cls.zone.id, + cls.services["ostype"] + ) + if cls.template == FAILED: + assert False, "get_template() failed to return template with description %s" % cls.services["ostype"] + + cls.services["virtual_machine"]["zoneid"] = cls.zone.id cls.services["virtual_machine"]["template"] = cls.template.id cls.service_offering = ServiceOffering.create( - cls.api_client, + cls.apiclient, cls.services["service_offering"] ) cls._cleanup = [ @@ -188,7 +194,7 @@ class TestRegionVpcOffering(cloudstackTestCase): def tearDownClass(cls): try: #Cleanup resources used - cleanup_resources(cls.api_client, cls._cleanup) + cleanup_resources(cls.apiclient, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) return diff --git a/test/integration/component/test_regions.py b/test/integration/component/test_regions.py index 2a84943db72..40e65cfa9ea 100644 --- a/test/integration/component/test_regions.py +++ b/test/integration/component/test_regions.py @@ -17,9 +17,9 @@ from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * from nose.plugins.attrib import attr from random import choice @@ -41,7 +41,7 @@ class TestRegions(cloudstackTestCase): def setUpClass(cls): cls.api_client = super(TestRegions, cls).getClsTestClient().getApiClient() cls.services = Services().services - cls.domain = get_domain(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) cls.cleanup = [] return diff --git a/test/integration/component/test_regions_accounts.py b/test/integration/component/test_regions_accounts.py index 51620e50fec..a554893468f 100644 --- a/test/integration/component/test_regions_accounts.py +++ b/test/integration/component/test_regions_accounts.py @@ -17,9 +17,9 @@ from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * from nose.plugins.attrib import attr class Services: @@ -57,7 +57,7 @@ class TestRegionsAccounts(cloudstackTestCase): def setUpClass(cls): cls.api_client = super(TestRegionsAccounts, cls).getClsTestClient().getApiClient() cls.services = Services().services - cls.domain = get_domain(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) cls.cleanup = [] return diff --git a/test/integration/component/test_reset_ssh_keypair.py b/test/integration/component/test_reset_ssh_keypair.py index ded25293816..307e8dc7aff 100644 --- a/test/integration/component/test_reset_ssh_keypair.py +++ b/test/integration/component/test_reset_ssh_keypair.py @@ -19,18 +19,18 @@ """ #Import Local Modules -from marvin.integration.lib.base import (VirtualMachine, +from marvin.lib.base import (VirtualMachine, SSHKeyPair, Account, Template, ServiceOffering, EgressFireWallRule) -from marvin.integration.lib.common import (get_domain, +from marvin.lib.common import (get_domain, get_zone, get_template, list_virtual_machines, list_volumes) -from marvin.integration.lib.utils import (cleanup_resources, +from marvin.lib.utils import (cleanup_resources, random_gen, validateList) from marvin.cloudstackTestCase import cloudstackTestCase, unittest @@ -114,14 +114,13 @@ class TestResetSSHKeypair(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestResetSSHKeypair, - cls).getClsTestClient().getApiClient() + cls.testClient = super(TestResetSSHKeypair, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() cls.services = Services().services # Get Zone, Domain and templates - domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype # Set Zones and disk offerings @@ -955,14 +954,13 @@ class TestResetSSHKeyUserRights(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestResetSSHKeyUserRights, - cls).getClsTestClient().getApiClient() + cls.testClient = super(TestResetSSHKeyUserRights, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype # Set Zones and disk offerings diff --git a/test/integration/component/test_resource_limits.py b/test/integration/component/test_resource_limits.py index 9f991611cdc..09d9658802e 100644 --- a/test/integration/component/test_resource_limits.py +++ b/test/integration/component/test_resource_limits.py @@ -19,7 +19,7 @@ #Import Local Modules from nose.plugins.attrib import attr from marvin.cloudstackTestCase import cloudstackTestCase -from marvin.integration.lib.base import (VirtualMachine, +from marvin.lib.base import (VirtualMachine, Snapshot, Template, PublicIPAddress, @@ -31,14 +31,14 @@ from marvin.integration.lib.base import (VirtualMachine, NetworkOffering, ServiceOffering, Configurations) -from marvin.integration.lib.common import (list_volumes, +from marvin.lib.common import (list_volumes, get_domain, get_zone, get_template, update_resource_limit, list_configurations, wait_for_cleanup) -from marvin.integration.lib.utils import cleanup_resources +from marvin.lib.utils import cleanup_resources import time @@ -127,11 +127,13 @@ class TestResourceLimitsAccount(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestResourceLimitsAccount, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestResourceLimitsAccount, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype cls.template = get_template( @@ -897,10 +899,11 @@ class TestResourceLimitsDomain(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestResourceLimitsDomain, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestResourceLimitsDomain, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services - # Get Zone, Domain and templates - cls.zone = get_zone(cls.api_client, cls.services) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype cls.template = get_template( @@ -1354,14 +1357,12 @@ class TestMaxAccountNetworks(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestMaxAccountNetworks, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestMaxAccountNetworks, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services - # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) + cls.domain = get_domain(cls.api_client) cls.services['mode'] = cls.zone.networktype cls.template = get_template( cls.api_client, diff --git a/test/integration/component/test_routers.py b/test/integration/component/test_routers.py index 29e2e9fbeaa..d729a0779d1 100644 --- a/test/integration/component/test_routers.py +++ b/test/integration/component/test_routers.py @@ -21,9 +21,9 @@ import marvin from nose.plugins.attrib import attr from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * #Import System modules import time @@ -98,11 +98,13 @@ class TestRouterServices(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestRouterServices, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestRouterServices, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype cls.template = get_template( cls.api_client, @@ -641,11 +643,13 @@ class TestRouterStopCreatePF(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestRouterStopCreatePF, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestRouterStopCreatePF, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype template = get_template( cls.api_client, @@ -853,11 +857,13 @@ class TestRouterStopCreateLB(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestRouterStopCreateLB, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestRouterStopCreateLB, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype template = get_template( cls.api_client, @@ -1065,11 +1071,13 @@ class TestRouterStopCreateFW(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestRouterStopCreateFW, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestRouterStopCreateFW, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype template = get_template( cls.api_client, @@ -1122,6 +1130,7 @@ class TestRouterStopCreateFW(cloudstackTestCase): def setUp(self): self.apiclient = self.testClient.getApiClient() + self.hypervisor = self.testClient.getHypervisorInfo() self.cleanup = [] return @@ -1255,8 +1264,8 @@ class TestRouterStopCreateFW(cloudstackTestCase): "Check end port of firewall rule" ) # For DNS and DHCP check 'dnsmasq' process status - if (self.apiclient.hypervisor.lower() == 'vmware' - or self.apiclient.hypervisor.lower() == 'hyperv'): + if (self.hypervisor.lower() == 'vmware' + or self.hypervisor.lower() == 'hyperv'): result = get_process_status( self.apiclient.connection.mgtSvr, 22, @@ -1264,7 +1273,7 @@ class TestRouterStopCreateFW(cloudstackTestCase): self.apiclient.connection.passwd, router.linklocalip, 'iptables -t nat -L', - hypervisor=self.apiclient.hypervisor + hypervisor=self.hypervisor ) else: hosts = list_hosts( diff --git a/test/integration/component/test_security_groups.py b/test/integration/component/test_security_groups.py index 8e0739658ae..f5c47273ba5 100644 --- a/test/integration/component/test_security_groups.py +++ b/test/integration/component/test_security_groups.py @@ -22,9 +22,9 @@ import marvin from nose.plugins.attrib import attr from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * from marvin.sshClient import SshClient #Import System modules @@ -117,12 +117,13 @@ class TestDefaultSecurityGroup(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.services = Services().services - cls.api_client = super(TestDefaultSecurityGroup, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestDefaultSecurityGroup, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype template = get_template( @@ -390,12 +391,13 @@ class TestAuthorizeIngressRule(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.services = Services().services - cls.api_client = super(TestAuthorizeIngressRule, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestAuthorizeIngressRule, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype template = get_template( @@ -526,12 +528,13 @@ class TestRevokeIngressRule(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.services = Services().services - cls.api_client = super(TestRevokeIngressRule, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestRevokeIngressRule, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype template = get_template( @@ -684,12 +687,13 @@ class TestDhcpOnlyRouter(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.services = Services().services - cls.api_client = super(TestDhcpOnlyRouter, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestDhcpOnlyRouter, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype template = get_template( @@ -821,12 +825,13 @@ class TestdeployVMWithUserData(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.services = Services().services - cls.api_client = super(TestdeployVMWithUserData, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestdeployVMWithUserData, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype template = get_template( @@ -985,8 +990,8 @@ class TestDeleteSecurityGroup(cloudstackTestCase): self.services = Services().services # Get Zone, Domain and templates - self.domain = get_domain(self.apiclient, self.services) - self.zone = get_zone(self.apiclient, self.services) + self.domain = get_domain(self.apiclient) + self.zone = get_zone(self.apiclient, self.testClient.getZoneForTests()) self.services['mode'] = self.zone.networktype template = get_template( @@ -1232,8 +1237,8 @@ class TestIngressRule(cloudstackTestCase): self.services = Services().services # Get Zone, Domain and templates - self.domain = get_domain(self.apiclient, self.services) - self.zone = get_zone(self.apiclient, self.services) + self.domain = get_domain(self.apiclient) + self.zone = get_zone(self.apiclient, self.testClient.getZoneForTests()) self.services['mode'] = self.zone.networktype template = get_template( diff --git a/test/integration/component/test_shared_networks.py b/test/integration/component/test_shared_networks.py index 9d96fd6f95e..f99bfbf8ed3 100644 --- a/test/integration/component/test_shared_networks.py +++ b/test/integration/component/test_shared_networks.py @@ -20,7 +20,7 @@ #Import Local Modules from nose.plugins.attrib import attr from marvin.cloudstackTestCase import cloudstackTestCase, unittest -from marvin.integration.lib.base import (Account, +from marvin.lib.base import (Account, Network, NetworkOffering, VirtualMachine, @@ -31,9 +31,9 @@ from marvin.integration.lib.base import (Account, FireWallRule, ServiceOffering, PublicIPAddress) -from marvin.integration.lib.utils import (cleanup_resources, +from marvin.lib.utils import (cleanup_resources, xsplit) -from marvin.integration.lib.common import (get_domain, +from marvin.lib.common import (get_domain, get_zone, get_template, wait_for_cleanup, @@ -154,16 +154,13 @@ class TestSharedNetworks(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestSharedNetworks, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestSharedNetworks, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() cls.services = Services().services - # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, diff --git a/test/integration/component/test_snapshot_gc.py b/test/integration/component/test_snapshot_gc.py index 68586704273..42c361cdff6 100644 --- a/test/integration/component/test_snapshot_gc.py +++ b/test/integration/component/test_snapshot_gc.py @@ -18,10 +18,10 @@ from nose.plugins.attrib import attr from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * -from marvin.integration.lib.utils import is_snapshot_on_nfs +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * +from marvin.lib.utils import is_snapshot_on_nfs class Services: @@ -122,11 +122,13 @@ class TestAccountSnapshotClean(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestAccountSnapshotClean, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestAccountSnapshotClean, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype template = get_template( diff --git a/test/integration/component/test_snapshot_limits.py b/test/integration/component/test_snapshot_limits.py index e204f4c3c14..95c64322e48 100644 --- a/test/integration/component/test_snapshot_limits.py +++ b/test/integration/component/test_snapshot_limits.py @@ -18,10 +18,10 @@ from nose.plugins.attrib import attr from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * -from marvin.integration.lib.utils import is_snapshot_on_nfs +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * +from marvin.lib.utils import is_snapshot_on_nfs import os @@ -123,11 +123,13 @@ class TestSnapshotLimit(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestSnapshotLimit, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestSnapshotLimit, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype cls._cleanup = [] diff --git a/test/integration/component/test_snapshots.py b/test/integration/component/test_snapshots.py index 034af9c971e..f874bd37704 100644 --- a/test/integration/component/test_snapshots.py +++ b/test/integration/component/test_snapshots.py @@ -20,7 +20,7 @@ from nose.plugins.attrib import attr from marvin.cloudstackTestCase import cloudstackTestCase, unittest -from marvin.integration.lib.base import (Snapshot, +from marvin.lib.base import (Snapshot, Template, VirtualMachine, Account, @@ -28,7 +28,7 @@ from marvin.integration.lib.base import (Snapshot, DiskOffering, Volume) -from marvin.integration.lib.common import (get_domain, +from marvin.lib.common import (get_domain, get_zone, get_template, list_events, @@ -38,7 +38,7 @@ from marvin.integration.lib.common import (get_domain, list_virtual_machines, ) -from marvin.integration.lib.utils import (cleanup_resources, +from marvin.lib.utils import (cleanup_resources, format_volume_to_ext3, random_gen, is_snapshot_on_nfs, @@ -158,11 +158,13 @@ class TestSnapshots(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestSnapshots, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestSnapshots, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype cls.disk_offering = DiskOffering.create( cls.api_client, @@ -229,6 +231,7 @@ class TestSnapshots(cloudstackTestCase): def setUp(self): self.apiclient = self.testClient.getApiClient() + self.hypervisor = self.testClient.getHypervisorInfo() self.dbclient = self.testClient.getDbConnection() self.cleanup = [] return @@ -910,11 +913,13 @@ class TestCreateVMSnapshotTemplate(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestCreateVMSnapshotTemplate, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestCreateVMSnapshotTemplate, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype cls.template = get_template( @@ -956,6 +961,7 @@ class TestCreateVMSnapshotTemplate(cloudstackTestCase): def setUp(self): self.apiclient = self.testClient.getApiClient() + self.hypervisor = self.testClient.getHypervisorInfo() self.dbclient = self.testClient.getDbConnection() self.cleanup = [] return @@ -1108,11 +1114,14 @@ class TestSnapshotEvents(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestSnapshotEvents, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestSnapshotEvents, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype template = get_template( @@ -1163,6 +1172,7 @@ class TestSnapshotEvents(cloudstackTestCase): def setUp(self): self.apiclient = self.testClient.getApiClient() + self.hypervisor = self.testClient.getHypervisorInfo() self.dbclient = self.testClient.getDbConnection() self.cleanup = [] return diff --git a/test/integration/component/test_snapshots_improvement.py b/test/integration/component/test_snapshots_improvement.py index 52979c43a1e..b2b0a546d52 100644 --- a/test/integration/component/test_snapshots_improvement.py +++ b/test/integration/component/test_snapshots_improvement.py @@ -20,10 +20,10 @@ # Import Local Modules from nose.plugins.attrib import attr from marvin.cloudstackTestCase import cloudstackTestCase, unittest -from marvin.integration.lib.utils import (random_gen, +from marvin.lib.utils import (random_gen, is_snapshot_on_nfs, cleanup_resources) -from marvin.integration.lib.base import ( +from marvin.lib.base import ( Account, ServiceOffering, VirtualMachine, @@ -32,7 +32,7 @@ from marvin.integration.lib.base import ( Volume, DiskOffering ) -from marvin.integration.lib.common import (get_domain, +from marvin.lib.common import (get_domain, get_zone, get_template, list_snapshots @@ -126,11 +126,13 @@ class TestSnapshotOnRootVolume(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestSnapshotOnRootVolume, - cls).getClsTestClient().getApiClient() + cls.testClient = super(TestSnapshotOnRootVolume, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + # Get Zone, Domain and templates + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, @@ -299,13 +301,13 @@ class TestCreateSnapshot(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestCreateSnapshot, - cls).getClsTestClient().getApiClient() + cls.testClient = super(TestCreateSnapshot, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, diff --git a/test/integration/component/test_stopped_vm.py b/test/integration/component/test_stopped_vm.py index 53ad7e2be66..6c776796f0b 100644 --- a/test/integration/component/test_stopped_vm.py +++ b/test/integration/component/test_stopped_vm.py @@ -22,9 +22,9 @@ import marvin from nose.plugins.attrib import attr from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * #Import System modules import time @@ -108,14 +108,13 @@ class TestDeployVM(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestDeployVM, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestDeployVM, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, @@ -962,14 +961,13 @@ class TestDeployHaEnabledVM(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestDeployHaEnabledVM, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestDeployHaEnabledVM, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, @@ -1194,14 +1192,13 @@ class TestRouterStateAfterDeploy(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestRouterStateAfterDeploy, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestRouterStateAfterDeploy, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, @@ -1409,14 +1406,13 @@ class TestDeployVMBasicZone(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestDeployVMBasicZone, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestDeployVMBasicZone, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, @@ -1477,14 +1473,13 @@ class TestDeployVMFromTemplate(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestDeployVMFromTemplate, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestDeployVMFromTemplate, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) # Create service, disk offerings etc cls.service_offering = ServiceOffering.create( @@ -1511,8 +1506,8 @@ class TestDeployVMFromTemplate(cloudstackTestCase): raise Exception("Warning: Exception during cleanup : %s" % e) def setUp(self): - self.apiclient = self.testClient.getApiClient() + self.hypervisor = self.testClient.getHypervisorInfo() self.dbclient = self.testClient.getDbConnection() self.services = Services().services self.services["virtual_machine"]["zoneid"] = self.zone.id @@ -1533,7 +1528,8 @@ class TestDeployVMFromTemplate(cloudstackTestCase): self.services["template"], zoneid=self.zone.id, account=self.account.name, - domainid=self.account.domainid + domainid=self.account.domainid, + hypervisor=self.hypervisor ) self.debug( "Registered a template of format: %s with ID: %s" % ( @@ -1638,14 +1634,13 @@ class TestVMAccountLimit(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestVMAccountLimit, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestVMAccountLimit, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, @@ -1754,14 +1749,13 @@ class TestUploadAttachVolume(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestUploadAttachVolume, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestUploadAttachVolume, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, @@ -1864,14 +1858,13 @@ class TestDeployOnSpecificHost(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestDeployOnSpecificHost, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestDeployOnSpecificHost, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, diff --git a/test/integration/component/test_storage_motion.py b/test/integration/component/test_storage_motion.py index e1fd40fe034..5b9086bdc32 100644 --- a/test/integration/component/test_storage_motion.py +++ b/test/integration/component/test_storage_motion.py @@ -20,9 +20,9 @@ import marvin from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common 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 @@ -89,12 +89,13 @@ class TestStorageMotion(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestStorageMotion, cls).getClsTestClient().getApiClient() - cls.services = Services().services + cls.testClient = super(TestStorageMotion, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype template = get_template( diff --git a/test/integration/component/test_tags.py b/test/integration/component/test_tags.py index 1e8667d163e..d6b43d97d19 100644 --- a/test/integration/component/test_tags.py +++ b/test/integration/component/test_tags.py @@ -21,9 +21,9 @@ import marvin from nose.plugins.attrib import attr from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * import datetime @@ -174,30 +174,28 @@ class TestResourceTags(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestResourceTags, - cls - ).getClsTestClient().getApiClient() - cls.services = Services().services - # Get Zone - cls.zone = get_zone(cls.api_client, cls.services) + cls.testClient = super(TestResourceTags, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() - # Create domains, account etc. - cls.domain = get_domain(cls.api_client, cls.services) + cls.services = Services().services + + # Get Zone, Domain and templates + + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) + cls.domain = get_domain(cls.api_client) + cls.template = get_template( + cls.api_client, + cls.zone.id, + cls.services["ostype"] + ) + if cls.template == FAILED: + assert False, "get_template() failed to return template with description %s" % cls.services["ostype"] cls.account = Account.create( cls.api_client, cls.services["account"], admin=True, ) - cls.zone = get_zone(cls.api_client, cls.services) - - cls.template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) - # Create service offerings, disk offerings etc cls.service_offering = ServiceOffering.create( cls.api_client, diff --git a/test/integration/component/test_templates.py b/test/integration/component/test_templates.py index 1e612c2d143..98b1cbc9d02 100644 --- a/test/integration/component/test_templates.py +++ b/test/integration/component/test_templates.py @@ -21,9 +21,9 @@ import marvin from nose.plugins.attrib import attr from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * import urllib from random import random #Import System modules @@ -101,8 +101,8 @@ class Services: class TestCreateTemplate(cloudstackTestCase): def setUp(self): - self.apiclient = self.testClient.getApiClient() + self.hypervisor = self.testClient.getHypervisorInfo() self.dbclient = self.testClient.getDbConnection() self.cleanup = [] return @@ -118,12 +118,13 @@ class TestCreateTemplate(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.services = Services().services - cls.api_client = super(TestCreateTemplate, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestCreateTemplate, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype cls.services["virtual_machine"]["zoneid"] = cls.zone.id @@ -184,7 +185,8 @@ class TestCreateTemplate(cloudstackTestCase): self.services["templates"][0], zoneid=self.zone.id, account=self.account.name, - domainid=self.account.domainid + domainid=self.account.domainid, + hypervisor=self.hypervisor ) self.debug( "Registered a template of format: %s with ID: %s" % ( @@ -276,12 +278,13 @@ class TestTemplates(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.services = Services().services - cls.api_client = super(TestTemplates, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestTemplates, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() - # Get Zone, templates etc - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.services = Services().services + # Get Zone, Domain and templates + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype #populate second zone id for iso copy cmd = listZones.listZonesCmd() diff --git a/test/integration/component/test_update_vm.py b/test/integration/component/test_update_vm.py index 6d847080b5d..1c5c2362508 100644 --- a/test/integration/component/test_update_vm.py +++ b/test/integration/component/test_update_vm.py @@ -17,9 +17,9 @@ from marvin.cloudstackTestCase import cloudstackTestCase -from marvin.integration.lib.base import Account, VirtualMachine, ServiceOffering -from marvin.integration.lib.utils import cleanup_resources -from marvin.integration.lib.common import get_zone, get_domain, get_template +from marvin.lib.base import Account, VirtualMachine, ServiceOffering +from marvin.lib.utils import cleanup_resources +from marvin.lib.common import get_zone, get_domain, get_template from nose.plugins.attrib import attr class TestData(object): @@ -61,8 +61,8 @@ class TestUpdateVirtualMachine(cloudstackTestCase): self.apiclient = self.testClient.getApiClient() # Get Zone, Domain and Default Built-in template - self.domain = get_domain(self.apiclient, self.testdata) - self.zone = get_zone(self.apiclient, self.testdata) + self.domain = get_domain(self.apiclient) + self.zone = get_zone(self.apiclient, self.testClient.getZoneForTests()) self.testdata["mode"] = self.zone.networktype self.template = get_template(self.apiclient, self.zone.id, self.testdata["ostype"]) @@ -156,4 +156,4 @@ class TestUpdateVirtualMachine(cloudstackTestCase): try: cleanup_resources(self.apiclient, self.cleanup) except Exception as e: - self.debug("Warning! Exception in tearDown: %s" % e) \ No newline at end of file + self.debug("Warning! Exception in tearDown: %s" % e) diff --git a/test/integration/component/test_usage.py b/test/integration/component/test_usage.py index d18d2eaf3e3..eb920111370 100644 --- a/test/integration/component/test_usage.py +++ b/test/integration/component/test_usage.py @@ -21,9 +21,9 @@ import marvin from nose.plugins.attrib import attr from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * from marvin.sshClient import SshClient import datetime @@ -112,11 +112,13 @@ class TestVmUsage(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestVmUsage, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestVmUsage, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype template = get_template( @@ -296,11 +298,13 @@ class TestPublicIPUsage(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestPublicIPUsage, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestPublicIPUsage, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype template = get_template( @@ -448,11 +452,13 @@ class TestVolumeUsage(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestVolumeUsage, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestVolumeUsage, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype cls.disk_offering = DiskOffering.create( cls.api_client, @@ -622,11 +628,13 @@ class TestTemplateUsage(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestTemplateUsage, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestTemplateUsage, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype cls.services["server"]["zoneid"] = cls.zone.id template = get_template( @@ -787,11 +795,13 @@ class TestISOUsage(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestISOUsage, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestISOUsage, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype cls.services["server"]["zoneid"] = cls.zone.id cls.services["iso"]["zoneid"] = cls.zone.id @@ -924,11 +934,13 @@ class TestLBRuleUsage(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestLBRuleUsage, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestLBRuleUsage, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype template = get_template( cls.api_client, @@ -1086,11 +1098,13 @@ class TestSnapshotUsage(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestSnapshotUsage, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestSnapshotUsage, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype template = get_template( @@ -1253,11 +1267,13 @@ class TestNatRuleUsage(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestNatRuleUsage, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestNatRuleUsage, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype template = get_template( cls.api_client, @@ -1415,11 +1431,13 @@ class TestVpnUsage(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestVpnUsage, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestVpnUsage, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype template = get_template( cls.api_client, diff --git a/test/integration/component/test_vm_passwdenabled.py b/test/integration/component/test_vm_passwdenabled.py index 5cfa52556f7..2f68257f893 100644 --- a/test/integration/component/test_vm_passwdenabled.py +++ b/test/integration/component/test_vm_passwdenabled.py @@ -18,9 +18,9 @@ import marvin from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * from marvin.sshClient import SshClient -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * from nose.plugins.attrib import attr @@ -92,15 +92,13 @@ class TestVMPasswordEnabled(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestVMPasswordEnabled, - cls - ).getClsTestClient().getApiClient() - cls.services = Services().services + cls.testClient = super(TestVMPasswordEnabled, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - domain = get_domain(cls.api_client, cls.services) - zone = get_zone(cls.api_client, cls.services) + domain = get_domain(cls.api_client) + zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = zone.networktype template = get_template( cls.api_client, diff --git a/test/integration/component/test_vmware_drs.py b/test/integration/component/test_vmware_drs.py index 9a07d912a5e..7d3ab7f5cb1 100644 --- a/test/integration/component/test_vmware_drs.py +++ b/test/integration/component/test_vmware_drs.py @@ -23,19 +23,19 @@ from nose.plugins.attrib import attr from marvin.cloudstackTestCase import cloudstackTestCase, unittest -from marvin.integration.lib.base import (Account, +from marvin.lib.base import (Account, AffinityGroup, Host, VirtualMachine, ServiceOffering) -from marvin.integration.lib.common import (get_zone, +from marvin.lib.common import (get_zone, get_template, get_domain, get_pod ) -from marvin.integration.lib.utils import (validateList, +from marvin.lib.utils import (validateList, cleanup_resources, random_gen) @@ -111,25 +111,16 @@ class TestVMPlacement(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestVMPlacement, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestVMPlacement, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain( - cls.api_client, - cls.services - ) - cls.zone = get_zone( - cls.api_client, - cls.services - ) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.pod = get_pod( cls.api_client, - zoneid=cls.zone.id, - services=cls.services - ) + zone_id=cls.zone.id) cls.template = get_template( cls.api_client, cls.zone.id, @@ -280,20 +271,13 @@ class TestAntiAffinityRules(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestAntiAffinityRules, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestAntiAffinityRules, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain( - cls.api_client, - cls.services - ) - cls.zone = get_zone( - cls.api_client, - cls.services - ) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, @@ -515,20 +499,13 @@ class TestAffinityRules(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestAffinityRules, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestAffinityRules, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain( - cls.api_client, - cls.services - ) - cls.zone = get_zone( - cls.api_client, - cls.services - ) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, diff --git a/test/integration/component/test_volumes.py b/test/integration/component/test_volumes.py index bcf552ab43b..a3104723737 100644 --- a/test/integration/component/test_volumes.py +++ b/test/integration/component/test_volumes.py @@ -20,9 +20,9 @@ from nose.plugins.attrib import attr from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * #Import System modules import time @@ -88,13 +88,14 @@ class TestAttachVolume(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestAttachVolume, cls).getClsTestClient().getApiClient() - cls.services = Services().services + cls.testClient = super(TestAttachVolume, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) - cls.pod = get_pod(cls.api_client, cls.zone.id, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) + cls.pod = get_pod(cls.api_client, cls.zone.id) cls.services['mode'] = cls.zone.networktype cls.disk_offering = DiskOffering.create( cls.api_client, @@ -378,13 +379,14 @@ class TestAttachDetachVolume(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestAttachDetachVolume, cls).getClsTestClient().getApiClient() - cls.services = Services().services + cls.testClient = super(TestAttachDetachVolume, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) - cls.pod = get_pod(cls.api_client, cls.zone.id, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) + cls.pod = get_pod(cls.api_client, cls.zone.id) cls.services['mode'] = cls.zone.networktype cls.disk_offering = DiskOffering.create( cls.api_client, @@ -641,13 +643,14 @@ class TestAttachVolumeISO(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestAttachVolumeISO, cls).getClsTestClient().getApiClient() - cls.services = Services().services + cls.testClient = super(TestAttachVolumeISO, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) - cls.pod = get_pod(cls.api_client, cls.zone.id, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) + cls.pod = get_pod(cls.api_client, cls.zone.id) cls.services['mode'] = cls.zone.networktype cls.disk_offering = DiskOffering.create( cls.api_client, @@ -852,11 +855,13 @@ class TestVolumes(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestVolumes, cls).getClsTestClient().getApiClient() + cls.testClient = super(TestVolumes, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype cls.disk_offering = DiskOffering.create( cls.api_client, @@ -1105,7 +1110,7 @@ class TestVolumes(cloudstackTestCase): ) self.assertTrue(domuser is not None) - domapiclient = self.testClient.getUserApiClient(account=domuser.name, domain=dom.name) + domapiclient = self.testClient.getUserApiClient(UserName=domuser.name, DomainName=dom.name) diskoffering = DiskOffering.list(self.apiclient) self.assertTrue(isinstance(diskoffering, list), msg="DiskOffering list is not a list?") @@ -1133,15 +1138,12 @@ class TestDeployVmWithCustomDisk(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestDeployVmWithCustomDisk, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestDeployVmWithCustomDisk, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() cls.services = Services().services - # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype cls.disk_offering = DiskOffering.create( cls.api_client, diff --git a/test/integration/component/test_vpc.py b/test/integration/component/test_vpc.py index 5c55cb6c736..e9d396e8b89 100644 --- a/test/integration/component/test_vpc.py +++ b/test/integration/component/test_vpc.py @@ -20,11 +20,11 @@ #Import Local Modules from nose.plugins.attrib import attr from marvin.cloudstackTestCase import * -from marvin.cloudstackException import cloudstackAPIException +from marvin.cloudstackException import CloudstackAPIException from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * class Services: @@ -175,14 +175,13 @@ class TestVPC(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestVPC, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestVPC, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, @@ -1934,10 +1933,10 @@ class TestVPC(cloudstackTestCase): self.debug("creating a VPC network in the account: %s" % user.name) - userapiclient = self.testClient.createUserApiClient( + userapiclient = self.testClient.getUserApiClient( UserName=user.name, DomainName=user.domain, - acctType=0) + type=0) vpc = VPC.create( @@ -2017,8 +2016,8 @@ class TestVPC(cloudstackTestCase): #0 - User, 1 - Root Admin, 2 - Domain Admin userapiclient = self.testClient.getUserApiClient( - account=user.name, - domain=self.services["domain"]["name"], + UserName=user.name, + DomainName=self.services["domain"]["name"], type=2) vpc = VPC.create( @@ -2092,8 +2091,8 @@ class TestVPC(cloudstackTestCase): user.name) userapiclient = self.testClient.getUserApiClient( - account=user.name, - domain=user.domain, + UserName=user.name, + DomainName=user.domain, type=0) vpc = VPC.create( @@ -2171,8 +2170,8 @@ class TestVPC(cloudstackTestCase): self.debug("Created account: %s" % domain_admin.name) self.cleanup.append(domain_admin) da_apiclient = self.testClient.getUserApiClient( - account=domain_admin.name, - domain=domain_admin.domain, + UserName=domain_admin.name, + DomainName=domain_admin.domain, type=2) user = Account.create( @@ -2188,11 +2187,11 @@ class TestVPC(cloudstackTestCase): #0 - User, 1 - Root Admin, 2 - Domain Admin userapiclient = self.testClient.getUserApiClient( - account=user.name, - domain=user.domain, + UserName=user.name, + DomainName=user.domain, type=0) - with self.assertRaises(cloudstackAPIException): + with self.assertRaises(CloudstackAPIException): vpc = VPC.create( da_apiclient, self.services["vpc"], @@ -2222,8 +2221,8 @@ class TestVPC(cloudstackTestCase): self.debug("Created account: %s" % domain_admin.name) self.cleanup.append(domain_admin) da_apiclient = self.testClient.getUserApiClient( - account=domain_admin.name, - domain=self.services["domain"]["name"], + UserName=domain_admin.name, + DomainName=self.services["domain"]["name"], type=2) user = Account.create( @@ -2239,8 +2238,8 @@ class TestVPC(cloudstackTestCase): #0 - User, 1 - Root Admin, 2 - Domain Admin userapiclient = self.testClient.getUserApiClient( - account=user.name, - domain=user.domain, + UserName=user.name, + DomainName=user.domain, type=0) vpc = VPC.create( diff --git a/test/integration/component/test_vpc_distributed_routing_offering.py b/test/integration/component/test_vpc_distributed_routing_offering.py index 0fa7de7934f..cc9a19154f8 100644 --- a/test/integration/component/test_vpc_distributed_routing_offering.py +++ b/test/integration/component/test_vpc_distributed_routing_offering.py @@ -23,9 +23,9 @@ import marvin from nose.plugins.attrib import attr from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * from marvin.sshClient import SshClient import datetime @@ -154,24 +154,27 @@ class TestVPCDistributedRouterOffering(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestVPCDistributedRouterOffering, - cls - ).getClsTestClient().getApiClient() - cls.services = Services().services + testClient = super(TestVPCDistributedRouterOffering, cls).getClsTestClient() + cls.apiclient = testClient.getApiClient() + cls.services = testClient.getParsedTestDataConfig() + # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.apiclient) + cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests()) + cls.services['mode'] = cls.zone.networktype + cls.template = get_template( - cls.api_client, - cls.zone.id, - cls.services["ostype"] - ) + cls.apiclient, + cls.zone.id, + cls.services["ostype"] + ) + if cls.template == FAILED: + assert False, "get_template() failed to return template with description %s" % cls.services["ostype"] cls.services["virtual_machine"]["zoneid"] = cls.zone.id cls.services["virtual_machine"]["template"] = cls.template.id cls.service_offering = ServiceOffering.create( - cls.api_client, + cls.apiclient, cls.services["service_offering"] ) cls._cleanup = [ @@ -183,7 +186,7 @@ class TestVPCDistributedRouterOffering(cloudstackTestCase): def tearDownClass(cls): try: #Cleanup resources used - cleanup_resources(cls.api_client, cls._cleanup) + cleanup_resources(cls.apiclient, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) return diff --git a/test/integration/component/test_vpc_network.py b/test/integration/component/test_vpc_network.py index 6f280b88614..2924b72be9f 100644 --- a/test/integration/component/test_vpc_network.py +++ b/test/integration/component/test_vpc_network.py @@ -21,8 +21,8 @@ from nose.plugins.attrib import attr from marvin.cloudstackTestCase import cloudstackTestCase, unittest from marvin.cloudstackAPI import startVirtualMachine, stopVirtualMachine -from marvin.integration.lib.utils import cleanup_resources, validateList -from marvin.integration.lib.base import (VirtualMachine, +from marvin.lib.utils import cleanup_resources, validateList +from marvin.lib.base import (VirtualMachine, ServiceOffering, Account, NATRule, @@ -35,7 +35,7 @@ from marvin.integration.lib.base import (VirtualMachine, StaticNATRule, NetworkACL, PublicIPAddress) -from marvin.integration.lib.common import (get_zone, +from marvin.lib.common import (get_zone, get_domain, get_template, wait_for_cleanup, @@ -239,17 +239,17 @@ class TestVPCNetwork(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestVPCNetwork, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestVPCNetwork, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services + # Added an attribute to track if Netscaler addition was successful. # Value is checked in tests and if not configured, Netscaler tests will be skipped cls.ns_configured = False # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, @@ -1003,17 +1003,17 @@ class TestVPCNetworkRanges(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestVPCNetworkRanges, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestVPCNetworkRanges, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services + # Added an attribute to track if Netscaler addition was successful. # Value is checked in tests and if not configured, Netscaler tests will be skipped cls.ns_configured = False # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, @@ -1541,14 +1541,14 @@ class TestVPCNetworkUpgrade(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestVPCNetworkUpgrade, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestVPCNetworkUpgrade, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services + # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, @@ -2123,14 +2123,14 @@ class TestVPCNetworkGc(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestVPCNetworkGc, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestVPCNetworkGc, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services + # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, diff --git a/test/integration/component/test_vpc_network_lbrules.py b/test/integration/component/test_vpc_network_lbrules.py index 9d75550d572..a5625e72166 100644 --- a/test/integration/component/test_vpc_network_lbrules.py +++ b/test/integration/component/test_vpc_network_lbrules.py @@ -20,7 +20,7 @@ #Import Local Modules from nose.plugins.attrib import attr from marvin.cloudstackTestCase import cloudstackTestCase, unittest -from marvin.integration.lib.base import (stopRouter, +from marvin.lib.base import (stopRouter, startRouter, Account, VpcOffering, @@ -34,11 +34,11 @@ from marvin.integration.lib.base import (stopRouter, VirtualMachine, LoadBalancerRule, StaticNATRule) -from marvin.integration.lib.common import (get_domain, +from marvin.lib.common import (get_domain, get_zone, get_template, list_routers) -from marvin.integration.lib.utils import cleanup_resources +from marvin.lib.utils import cleanup_resources import socket import time @@ -181,14 +181,13 @@ class TestVPCNetworkLBRules(cloudstackTestCase): # We want to fail quicker if it's failure socket.setdefaulttimeout(60) - cls.api_client = super( - TestVPCNetworkLBRules, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestVPCNetworkLBRules, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, diff --git a/test/integration/component/test_vpc_network_pfrules.py b/test/integration/component/test_vpc_network_pfrules.py index e5bb158bdc0..31e73202677 100644 --- a/test/integration/component/test_vpc_network_pfrules.py +++ b/test/integration/component/test_vpc_network_pfrules.py @@ -19,7 +19,7 @@ """ from nose.plugins.attrib import attr from marvin.cloudstackTestCase import cloudstackTestCase, unittest -from marvin.integration.lib.base import (stopRouter, +from marvin.lib.base import (stopRouter, startRouter, Account, VpcOffering, @@ -32,11 +32,11 @@ from marvin.integration.lib.base import (stopRouter, Network, VirtualMachine, LoadBalancerRule) -from marvin.integration.lib.common import (get_domain, +from marvin.lib.common import (get_domain, get_zone, get_template, list_routers) -from marvin.integration.lib.utils import cleanup_resources +from marvin.lib.utils import cleanup_resources import socket import time @@ -182,14 +182,13 @@ class TestVPCNetworkPFRules(cloudstackTestCase): # We want to fail quicker if it's failure socket.setdefaulttimeout(60) - cls.api_client = super( - TestVPCNetworkPFRules, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestVPCNetworkPFRules, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, diff --git a/test/integration/component/test_vpc_network_staticnatrule.py b/test/integration/component/test_vpc_network_staticnatrule.py index ddc3c4c7040..65cb044c9a9 100644 --- a/test/integration/component/test_vpc_network_staticnatrule.py +++ b/test/integration/component/test_vpc_network_staticnatrule.py @@ -19,7 +19,7 @@ """ from nose.plugins.attrib import attr from marvin.cloudstackTestCase import cloudstackTestCase, unittest -from marvin.integration.lib.base import (Account, +from marvin.lib.base import (Account, VpcOffering, VPC, ServiceOffering, @@ -32,11 +32,11 @@ from marvin.integration.lib.base import (Account, StaticNATRule) from marvin.cloudstackAPI import (stopRouter, startRouter) -from marvin.integration.lib.common import (get_domain, +from marvin.lib.common import (get_domain, get_zone, get_template, list_routers) -from marvin.integration.lib.utils import cleanup_resources +from marvin.lib.utils import cleanup_resources import socket import time @@ -182,14 +182,13 @@ class TestVPCNetworkPFRules(cloudstackTestCase): # We want to fail quicker if it's failure socket.setdefaulttimeout(60) - cls.api_client = super( - TestVPCNetworkPFRules, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestVPCNetworkPFRules, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, diff --git a/test/integration/component/test_vpc_offerings.py b/test/integration/component/test_vpc_offerings.py index 9e3064bf2c1..f190773aab6 100644 --- a/test/integration/component/test_vpc_offerings.py +++ b/test/integration/component/test_vpc_offerings.py @@ -23,9 +23,9 @@ import marvin from nose.plugins.attrib import attr from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * from marvin.sshClient import SshClient import datetime @@ -137,14 +137,13 @@ class TestVPCOffering(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestVPCOffering, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestVPCOffering, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, diff --git a/test/integration/component/test_vpc_routers.py b/test/integration/component/test_vpc_routers.py index fb5aed55fc9..3cf537ae0b6 100644 --- a/test/integration/component/test_vpc_routers.py +++ b/test/integration/component/test_vpc_routers.py @@ -22,9 +22,9 @@ import marvin from nose.plugins.attrib import attr from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * import datetime @@ -169,16 +169,15 @@ class TestVPCRoutersBasic(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.apiclient = super( - TestVPCRoutersBasic, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestVPCRoutersBasic, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.apiclient, cls.services) - cls.zone = get_zone(cls.apiclient, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( - cls.apiclient, + cls.api_client, cls.zone.id, cls.services["ostype"] ) @@ -186,16 +185,16 @@ class TestVPCRoutersBasic(cloudstackTestCase): cls.services["virtual_machine"]["template"] = cls.template.id cls.service_offering = ServiceOffering.create( - cls.apiclient, + cls.api_client, cls.services["service_offering"] ) cls.vpc_off = VpcOffering.create( - cls.apiclient, + cls.api_client, cls.services["vpc_offering"] ) - cls.vpc_off.update(cls.apiclient, state='Enabled') + cls.vpc_off.update(cls.api_client, state='Enabled') cls.account = Account.create( - cls.apiclient, + cls.api_client, cls.services["account"], admin=True, domainid=cls.domain.id @@ -203,13 +202,13 @@ class TestVPCRoutersBasic(cloudstackTestCase): cls._cleanup = [cls.account] cls._cleanup.append(cls.vpc_off) #cls.debug("Enabling the VPC offering created") - cls.vpc_off.update(cls.apiclient, state='Enabled') + cls.vpc_off.update(cls.api_client, state='Enabled') #cls.debug("creating a VPC network in the account: %s" % # cls.account.name) cls.services["vpc"]["cidr"] = '10.1.1.1/16' cls.vpc = VPC.create( - cls.apiclient, + cls.api_client, cls.services["vpc"], vpcofferingid=cls.vpc_off.id, zoneid=cls.zone.id, @@ -224,13 +223,13 @@ class TestVPCRoutersBasic(cloudstackTestCase): def tearDownClass(cls): try: #Cleanup resources used - cleanup_resources(cls.apiclient, cls._cleanup) + cleanup_resources(cls.api_client, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) return def setUp(self): - self.apiclient = self.testClient.getApiClient() + self.api_client = self.testClient.getApiClient() return @@ -242,7 +241,7 @@ class TestVPCRoutersBasic(cloudstackTestCase): self.debug("Check if the VPC offering is created successfully?") vpc_offs = VpcOffering.list( - self.apiclient, + self.api_client, id=vpc_offering.id ) self.assertEqual( @@ -265,7 +264,7 @@ class TestVPCRoutersBasic(cloudstackTestCase): self.debug("Check if the VPC network is created successfully?") vpc_networks = VPC.list( - self.apiclient, + self.api_client, id=network.id ) self.assertEqual( @@ -291,7 +290,7 @@ class TestVPCRoutersBasic(cloudstackTestCase): """ Migrate the router """ self.debug("Checking if the host is available for migration?") - hosts = Host.list(self.apiclient, zoneid=self.zone.id, type='Routing') + hosts = Host.list(self.api_client, zoneid=self.zone.id, type='Routing') self.assertEqual( isinstance(hosts, list), @@ -319,7 +318,7 @@ class TestVPCRoutersBasic(cloudstackTestCase): cmd.isAsync = "false" cmd.hostid = host.id cmd.virtualmachineid = router.id - self.apiclient.migrateSystemVm(cmd) + self.api_client.migrateSystemVm(cmd) except Exception as e: self.fail("Failed to migrate instance, %s" % e) @@ -329,7 +328,7 @@ class TestVPCRoutersBasic(cloudstackTestCase): #List routers to check state of router router_response = list_routers( - self.apiclient, + self.api_client, id=router.id ) self.assertEqual( @@ -358,7 +357,7 @@ class TestVPCRoutersBasic(cloudstackTestCase): # Stop the VPC Router routers = Router.list( - self.apiclient, + self.api_client, account=self.account.name, domainid=self.account.domainid, listall=True @@ -374,11 +373,11 @@ class TestVPCRoutersBasic(cloudstackTestCase): #Stop the router cmd = stopRouter.stopRouterCmd() cmd.id = router.id - self.apiclient.stopRouter(cmd) + self.api_client.stopRouter(cmd) #List routers to check state of router router_response = list_routers( - self.apiclient, + self.api_client, id=router.id ) self.assertEqual( @@ -399,11 +398,11 @@ class TestVPCRoutersBasic(cloudstackTestCase): self.debug("Starting the router with ID: %s" % router.id) cmd = startRouter.startRouterCmd() cmd.id = router.id - self.apiclient.startRouter(cmd) + self.api_client.startRouter(cmd) #List routers to check state of router router_response = list_routers( - self.apiclient, + self.api_client, id=router.id ) self.assertEqual( @@ -433,7 +432,7 @@ class TestVPCRoutersBasic(cloudstackTestCase): self.validate_vpc_offering(self.vpc_off) self.validate_vpc_network(self.vpc) routers = Router.list( - self.apiclient, + self.api_client, account=self.account.name, domainid=self.account.domainid, listall=True @@ -449,11 +448,11 @@ class TestVPCRoutersBasic(cloudstackTestCase): #Reboot the router cmd = rebootRouter.rebootRouterCmd() cmd.id = router.id - self.apiclient.rebootRouter(cmd) + self.api_client.rebootRouter(cmd) #List routers to check state of router router_response = list_routers( - self.apiclient, + self.api_client, id=router.id ) self.assertEqual( @@ -478,7 +477,7 @@ class TestVPCRoutersBasic(cloudstackTestCase): self.validate_vpc_network(self.vpc) routers = Router.list( - self.apiclient, + self.api_client, account=self.account.name, domainid=self.account.domainid, listall=True @@ -505,7 +504,7 @@ class TestVPCRoutersBasic(cloudstackTestCase): self.validate_vpc_network(self.vpc) routers = Router.list( - self.apiclient, + self.api_client, account=self.account.name, domainid=self.account.domainid, listall=True @@ -521,15 +520,15 @@ class TestVPCRoutersBasic(cloudstackTestCase): self.debug("Stopping the router with ID: %s" % router.id) cmd = stopRouter.stopRouterCmd() cmd.id = router.id - self.apiclient.stopRouter(cmd) + self.api_client.stopRouter(cmd) service_offering = ServiceOffering.create( - self.apiclient, + self.api_client, self.services["service_offering_new"] ) self.debug("Changing service offering for the Router %s" % router.id) try: - router = Router.change_service_offering(self.apiclient, + router = Router.change_service_offering(self.api_client, router.id, service_offering.id ) @@ -538,7 +537,7 @@ class TestVPCRoutersBasic(cloudstackTestCase): self.debug("Router %s" % router) routers = Router.list( - self.apiclient, + self.api_client, account=self.account.name, domainid=self.account.domainid, listall=True @@ -562,7 +561,7 @@ class TestVPCRoutersBasic(cloudstackTestCase): self.validate_vpc_offering(self.vpc_off) self.validate_vpc_network(self.vpc) routers = Router.list( - self.apiclient, + self.api_client, account=self.account.name, domainid=self.account.domainid, listall=True @@ -573,12 +572,12 @@ class TestVPCRoutersBasic(cloudstackTestCase): "List Routers should return a valid list" ) - Router.destroy( self.apiclient, + Router.destroy( self.api_client, id=routers[0].id ) routers = Router.list( - self.apiclient, + self.api_client, account=self.account.name, domainid=self.account.domainid, listall=True @@ -594,17 +593,16 @@ class TestVPCRouterOneNetwork(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.apiclient = super( - TestVPCRouterOneNetwork, - cls - ).getClsTestClient().getApiClient() cls._cleanup = [] + cls.testClient = super(TestVPCRouterOneNetwork, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.apiclient, cls.services) - cls.zone = get_zone(cls.apiclient, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( - cls.apiclient, + cls.api_client, cls.zone.id, cls.services["ostype"] ) @@ -612,19 +610,19 @@ class TestVPCRouterOneNetwork(cloudstackTestCase): cls.services["virtual_machine"]["template"] = cls.template.id cls.service_offering = ServiceOffering.create( - cls.apiclient, + cls.api_client, cls.services["service_offering"] ) cls._cleanup.append(cls.service_offering) cls.vpc_off = VpcOffering.create( - cls.apiclient, + cls.api_client, cls.services["vpc_offering"] ) - cls.vpc_off.update(cls.apiclient, state='Enabled') + cls.vpc_off.update(cls.api_client, state='Enabled') cls._cleanup.append(cls.vpc_off) cls.account = Account.create( - cls.apiclient, + cls.api_client, cls.services["account"], admin=True, domainid=cls.domain.id @@ -633,7 +631,7 @@ class TestVPCRouterOneNetwork(cloudstackTestCase): cls.services["vpc"]["cidr"] = '10.1.1.1/16' cls.vpc = VPC.create( - cls.apiclient, + cls.api_client, cls.services["vpc"], vpcofferingid=cls.vpc_off.id, zoneid=cls.zone.id, @@ -642,7 +640,7 @@ class TestVPCRouterOneNetwork(cloudstackTestCase): ) private_gateway = PrivateGateway.create( - cls.apiclient, + cls.api_client, gateway='10.1.3.1', ipaddress='10.1.3.100', netmask='255.255.255.0', @@ -650,34 +648,34 @@ class TestVPCRouterOneNetwork(cloudstackTestCase): vpcid=cls.vpc.id ) cls.gateways = PrivateGateway.list( - cls.apiclient, + cls.api_client, id=private_gateway.id, listall=True ) static_route = StaticRoute.create( - cls.apiclient, + cls.api_client, cidr='11.1.1.1/24', gatewayid=private_gateway.id ) cls.static_routes = StaticRoute.list( - cls.apiclient, + cls.api_client, id=static_route.id, listall=True ) cls.nw_off = NetworkOffering.create( - cls.apiclient, + cls.api_client, cls.services["network_offering"], conservemode=False ) # Enable Network offering - cls.nw_off.update(cls.apiclient, state='Enabled') + cls.nw_off.update(cls.api_client, state='Enabled') cls._cleanup.append(cls.nw_off) # Creating network using the network offering created cls.network_1 = Network.create( - cls.apiclient, + cls.api_client, cls.services["network"], accountid=cls.account.name, domainid=cls.account.domainid, @@ -689,7 +687,7 @@ class TestVPCRouterOneNetwork(cloudstackTestCase): # Spawn an instance in that network vm_1 = VirtualMachine.create( - cls.apiclient, + cls.api_client, cls.services["virtual_machine"], accountid=cls.account.name, domainid=cls.account.domainid, @@ -697,7 +695,7 @@ class TestVPCRouterOneNetwork(cloudstackTestCase): networkids=[str(cls.network_1.id)] ) vm_2 = VirtualMachine.create( - cls.apiclient, + cls.api_client, cls.services["virtual_machine"], accountid=cls.account.name, domainid=cls.account.domainid, @@ -707,7 +705,7 @@ class TestVPCRouterOneNetwork(cloudstackTestCase): # Spawn an instance in that network vm_3 = VirtualMachine.create( - cls.apiclient, + cls.api_client, cls.services["virtual_machine"], accountid=cls.account.name, domainid=cls.account.domainid, @@ -716,14 +714,14 @@ class TestVPCRouterOneNetwork(cloudstackTestCase): ) vms = VirtualMachine.list( - cls.apiclient, + cls.api_client, account=cls.account.name, domainid=cls.account.domainid, listall=True ) public_ip_1 = PublicIPAddress.create( - cls.apiclient, + cls.api_client, accountid=cls.account.name, zoneid=cls.zone.id, domainid=cls.account.domainid, @@ -732,7 +730,7 @@ class TestVPCRouterOneNetwork(cloudstackTestCase): ) nat_rule = NATRule.create( - cls.apiclient, + cls.api_client, vm_1, cls.services["natrule"], ipaddressid=public_ip_1.ipaddress.id, @@ -742,14 +740,14 @@ class TestVPCRouterOneNetwork(cloudstackTestCase): ) nwacl_nat = NetworkACL.create( - cls.apiclient, + cls.api_client, networkid=cls.network_1.id, services=cls.services["natrule"], traffictype='Ingress' ) public_ip_2 = PublicIPAddress.create( - cls.apiclient, + cls.api_client, accountid=cls.account.name, zoneid=cls.zone.id, domainid=cls.account.domainid, @@ -758,7 +756,7 @@ class TestVPCRouterOneNetwork(cloudstackTestCase): ) try: StaticNATRule.enable( - cls.apiclient, + cls.api_client, ipaddressid=public_ip_2.ipaddress.id, virtualmachineid=vm_2.id, networkid=cls.network_1.id @@ -768,7 +766,7 @@ class TestVPCRouterOneNetwork(cloudstackTestCase): public_ip_2.ipaddress.ipaddress, e)) public_ips = PublicIPAddress.list( - cls.apiclient, + cls.api_client, networkid=cls.network_1.id, listall=True, isstaticnat=True, @@ -776,7 +774,7 @@ class TestVPCRouterOneNetwork(cloudstackTestCase): domainid=cls.account.domainid ) public_ip_3 = PublicIPAddress.create( - cls.apiclient, + cls.api_client, accountid=cls.account.name, zoneid=cls.zone.id, domainid=cls.account.domainid, @@ -785,7 +783,7 @@ class TestVPCRouterOneNetwork(cloudstackTestCase): ) lb_rule = LoadBalancerRule.create( - cls.apiclient, + cls.api_client, cls.services["lbrule"], ipaddressid=public_ip_3.ipaddress.id, accountid=cls.account.name, @@ -794,17 +792,17 @@ class TestVPCRouterOneNetwork(cloudstackTestCase): domainid=cls.account.domainid ) - lb_rule.assign(cls.apiclient, [vm_3]) + lb_rule.assign(cls.api_client, [vm_3]) nwacl_lb = NetworkACL.create( - cls.apiclient, + cls.api_client, networkid=cls.network_1.id, services=cls.services["lbrule"], traffictype='Ingress' ) nwacl_internet_1 = NetworkACL.create( - cls.apiclient, + cls.api_client, networkid=cls.network_1.id, services=cls.services["http_rule"], traffictype='Egress' @@ -814,20 +812,20 @@ class TestVPCRouterOneNetwork(cloudstackTestCase): def tearDownClass(cls): try: #Cleanup resources used - cleanup_resources(cls.apiclient, cls._cleanup) + cleanup_resources(cls.api_client, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) return def setUp(self): - self.apiclient = self.testClient.getApiClient() + self.api_client = self.testClient.getApiClient() self.cleanup = [] return def tearDown(self): try: #Clean up, terminate the created network offerings - cleanup_resources(self.apiclient, self.cleanup) + cleanup_resources(self.api_client, self.cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) @@ -838,7 +836,7 @@ class TestVPCRouterOneNetwork(cloudstackTestCase): self.debug("Check if the VPC offering is created successfully?") vpc_offs = VpcOffering.list( - self.apiclient, + self.api_client, id=vpc_offering.id ) self.assertEqual( @@ -861,7 +859,7 @@ class TestVPCRouterOneNetwork(cloudstackTestCase): self.debug("Check if the VPC network is created successfully?") vpc_networks = VPC.list( - self.apiclient, + self.api_client, id=network.id ) self.assertEqual( @@ -887,13 +885,13 @@ class TestVPCRouterOneNetwork(cloudstackTestCase): """ Validate network rules """ vms = VirtualMachine.list( - self.apiclient, + self.api_client, account=self.account.name, domainid=self.account.domainid, listall=True ) public_ips = PublicIPAddress.list( - self.apiclient, + self.api_client, account=self.account.name, domainid=self.account.domainid, listall=True @@ -927,7 +925,7 @@ class TestVPCRouterOneNetwork(cloudstackTestCase): """ Migrate the router """ self.debug("Checking if the host is available for migration?") - hosts = Host.list(self.apiclient, zoneid=self.zone.id, type='Routing') + hosts = Host.list(self.api_client, zoneid=self.zone.id, type='Routing') self.assertEqual( isinstance(hosts, list), @@ -955,7 +953,7 @@ class TestVPCRouterOneNetwork(cloudstackTestCase): cmd.isAsync = "false" cmd.hostid = host.id cmd.virtualmachineid = router.id - self.apiclient.migrateSystemVm(cmd) + self.api_client.migrateSystemVm(cmd) except Exception as e: self.fail("Failed to migrate instance, %s" % e) @@ -965,7 +963,7 @@ class TestVPCRouterOneNetwork(cloudstackTestCase): #List routers to check state of router router_response = list_routers( - self.apiclient, + self.api_client, id=router.id ) self.assertEqual( @@ -1012,7 +1010,7 @@ class TestVPCRouterOneNetwork(cloudstackTestCase): # Stop the VPC Router routers = Router.list( - self.apiclient, + self.api_client, account=self.account.name, domainid=self.account.domainid, listall=True @@ -1028,11 +1026,11 @@ class TestVPCRouterOneNetwork(cloudstackTestCase): #Stop the router cmd = stopRouter.stopRouterCmd() cmd.id = router.id - self.apiclient.stopRouter(cmd) + self.api_client.stopRouter(cmd) #List routers to check state of router router_response = list_routers( - self.apiclient, + self.api_client, id=router.id ) self.assertEqual( @@ -1053,11 +1051,11 @@ class TestVPCRouterOneNetwork(cloudstackTestCase): self.debug("Starting the router with ID: %s" % router.id) cmd = startRouter.startRouterCmd() cmd.id = router.id - self.apiclient.startRouter(cmd) + self.api_client.startRouter(cmd) #List routers to check state of router router_response = list_routers( - self.apiclient, + self.api_client, id=router.id ) self.assertEqual( @@ -1106,7 +1104,7 @@ class TestVPCRouterOneNetwork(cloudstackTestCase): ) routers = Router.list( - self.apiclient, + self.api_client, account=self.account.name, domainid=self.account.domainid, listall=True @@ -1122,11 +1120,11 @@ class TestVPCRouterOneNetwork(cloudstackTestCase): #Reboot the router cmd = rebootRouter.rebootRouterCmd() cmd.id = router.id - self.apiclient.rebootRouter(cmd) + self.api_client.rebootRouter(cmd) #List routers to check state of router router_response = list_routers( - self.apiclient, + self.api_client, id=router.id ) self.assertEqual( @@ -1172,7 +1170,7 @@ class TestVPCRouterOneNetwork(cloudstackTestCase): "List static route should return a valid response" ) routers = Router.list( - self.apiclient, + self.api_client, account=self.account.name, domainid=self.account.domainid, listall=True @@ -1216,7 +1214,7 @@ class TestVPCRouterOneNetwork(cloudstackTestCase): ) routers = Router.list( - self.apiclient, + self.api_client, account=self.account.name, domainid=self.account.domainid, listall=True @@ -1232,15 +1230,15 @@ class TestVPCRouterOneNetwork(cloudstackTestCase): self.debug("Stopping the router with ID: %s" % router.id) cmd = stopRouter.stopRouterCmd() cmd.id = router.id - self.apiclient.stopRouter(cmd) + self.api_client.stopRouter(cmd) service_offering = ServiceOffering.create( - self.apiclient, + self.api_client, self.services["service_offering_new"] ) self.debug("Changing service offering for the Router %s" % router.id) try: - router = Router.change_service_offering(self.apiclient, + router = Router.change_service_offering(self.api_client, router.id, service_offering.id ) @@ -1249,7 +1247,7 @@ class TestVPCRouterOneNetwork(cloudstackTestCase): self.debug("Router %s" % router) routers = Router.list( - self.apiclient, + self.api_client, account=self.account.name, domainid=self.account.domainid, listall=True @@ -1294,7 +1292,7 @@ class TestVPCRouterOneNetwork(cloudstackTestCase): ) routers = Router.list( - self.apiclient, + self.api_client, account=self.account.name, domainid=self.account.domainid, listall=True @@ -1305,12 +1303,12 @@ class TestVPCRouterOneNetwork(cloudstackTestCase): "List Routers should return a valid list" ) - Router.destroy( self.apiclient, + Router.destroy( self.api_client, id=routers[0].id ) routers = Router.list( - self.apiclient, + self.api_client, account=self.account.name, domainid=self.account.domainid, listall=True diff --git a/test/integration/component/test_vpc_vm_life_cycle.py b/test/integration/component/test_vpc_vm_life_cycle.py index e40067ea86d..95f46d0474e 100644 --- a/test/integration/component/test_vpc_vm_life_cycle.py +++ b/test/integration/component/test_vpc_vm_life_cycle.py @@ -20,8 +20,8 @@ #Import Local Modules from nose.plugins.attrib import attr from marvin.cloudstackTestCase import cloudstackTestCase, unittest -from marvin.integration.lib.utils import cleanup_resources, validateList -from marvin.integration.lib.base import (VirtualMachine, +from marvin.lib.utils import cleanup_resources, validateList +from marvin.lib.base import (VirtualMachine, NATRule, LoadBalancerRule, StaticNATRule, @@ -35,7 +35,7 @@ from marvin.integration.lib.base import (VirtualMachine, Account, ServiceOffering, Host) -from marvin.integration.lib.common import (get_domain, +from marvin.lib.common import (get_domain, get_zone, get_template, get_free_vlan, @@ -212,14 +212,13 @@ class TestVMLifeCycleVPC(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestVMLifeCycleVPC, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestVMLifeCycleVPC, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, @@ -873,14 +872,13 @@ class TestVMLifeCycleSharedNwVPC(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestVMLifeCycleSharedNwVPC, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestVMLifeCycleSharedNwVPC, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, @@ -1660,14 +1658,13 @@ class TestVMLifeCycleBothIsolated(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestVMLifeCycleBothIsolated, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestVMLifeCycleBothIsolated, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, @@ -1995,14 +1992,13 @@ class TestVMLifeCycleStoppedVPCVR(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestVMLifeCycleStoppedVPCVR, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestVMLifeCycleStoppedVPCVR, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, @@ -2681,14 +2677,13 @@ class TestVMLifeCycleDiffHosts(cloudstackTestCase): def setUpClass(cls): try: - cls.api_client = super( - TestVMLifeCycleDiffHosts, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestVMLifeCycleDiffHosts, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, diff --git a/test/integration/component/test_vpc_vms_deployment.py b/test/integration/component/test_vpc_vms_deployment.py index 0ef51b43b16..1c1f93d37e2 100644 --- a/test/integration/component/test_vpc_vms_deployment.py +++ b/test/integration/component/test_vpc_vms_deployment.py @@ -20,7 +20,7 @@ #Import Local Modules from nose.plugins.attrib import attr from marvin.cloudstackTestCase import cloudstackTestCase, unittest -from marvin.integration.lib.base import (VirtualMachine, +from marvin.lib.base import (VirtualMachine, NetworkOffering, VpcOffering, VPC, @@ -36,13 +36,13 @@ from marvin.integration.lib.base import (VirtualMachine, StaticNATRule, Configurations) -from marvin.integration.lib.common import (get_domain, +from marvin.lib.common import (get_domain, get_zone, get_template, wait_for_cleanup, get_free_vlan) -from marvin.integration.lib.utils import cleanup_resources +from marvin.lib.utils import cleanup_resources from marvin.cloudstackAPI import rebootRouter @@ -166,14 +166,13 @@ class TestVMDeployVPC(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestVMDeployVPC, - cls - ).getClsTestClient().getApiClient() + cls.testClient = super(TestVMDeployVPC, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.template = get_template( cls.api_client, cls.zone.id, diff --git a/test/integration/component/test_vpn_users.py b/test/integration/component/test_vpn_users.py index 710055a0ab8..c8b3a2dbac3 100644 --- a/test/integration/component/test_vpn_users.py +++ b/test/integration/component/test_vpn_users.py @@ -19,9 +19,9 @@ """ # Import Local Modules from nose.plugins.attrib import attr -from marvin.cloudstackException import cloudstackAPIException +from marvin.cloudstackException import CloudstackAPIException from marvin.cloudstackTestCase import cloudstackTestCase -from marvin.integration.lib.base import ( +from marvin.lib.base import ( Account, ServiceOffering, VirtualMachine, @@ -31,11 +31,11 @@ from marvin.integration.lib.base import ( Configurations, NATRule ) -from marvin.integration.lib.common import (get_domain, +from marvin.lib.common import (get_domain, get_zone, get_template ) -from marvin.integration.lib.utils import cleanup_resources +from marvin.lib.utils import cleanup_resources class Services: @@ -94,12 +94,13 @@ class Services: class TestVPNUsers(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestVPNUsers, - cls).getClsTestClient().getApiClient() + cls.testClient = super(TestVPNUsers, cls).getClsTestClient() + cls.api_client = cls.testClient.getApiClient() + cls.services = Services().services # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.api_client) + cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests()) cls.services["mode"] = cls.zone.networktype @@ -155,7 +156,7 @@ class TestVPNUsers(cloudstackTestCase): services=self.services["virtual_machine"] ) return - except cloudstackAPIException as e: + except CloudstackAPIException as e: self.tearDown() raise e @@ -396,7 +397,7 @@ class TestVPNUsers(cloudstackTestCase): domainid=self.account.domainid) self.cleanup.append(admin) self.debug("Creating API client for newly created user") - api_client = self.testClient.createUserApiClient( + api_client = self.testClient.getUserApiClient( UserName=self.account.name, DomainName=self.account.domain) @@ -438,7 +439,7 @@ class TestVPNUsers(cloudstackTestCase): domainid=self.account.domainid) self.cleanup.append(admin) self.debug("Creating API client for newly created user") - api_client = self.testClient.createUserApiClient( + api_client = self.testClient.getUserApiClient( UserName=self.account.name, DomainName=self.account.domain) diff --git a/test/integration/smoke/test_affinity_groups.py b/test/integration/smoke/test_affinity_groups.py index b1183647688..4f3f9ec875f 100644 --- a/test/integration/smoke/test_affinity_groups.py +++ b/test/integration/smoke/test_affinity_groups.py @@ -16,52 +16,15 @@ # specific language governing permissions and limitations # under the License. +from marvin.codes import FAILED from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * from marvin.sshClient import SshClient from nose.plugins.attrib import attr -class Services: - """Test Account Services - """ - - def __init__(self): - self.services = { - "domain": { - "name": "Domain", - }, - "account": { - "email": "test@test.com", - "firstname": "Test", - "lastname": "User", - "username": "test", - # Random characters are appended for unique - # username - "password": "password", - }, - "service_offering": { - "name": "Tiny Instance", - "displaytext": "Tiny Instance", - "cpunumber": 1, - "cpuspeed": 100, - # in MHz - "memory": 128, - # In MBs - }, - "ostype": 'CentOS 5.3 (64-bit)', - "virtual_machine" : { - "affinity": { - "name": "webvms", - "type": "host anti-affinity", - }, - "hypervisor" : "XenServer", - } - } - - class TestDeployVmWithAffinityGroup(cloudstackTestCase): """ This test deploys a virtual machine into a user account @@ -70,36 +33,40 @@ class TestDeployVmWithAffinityGroup(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestDeployVmWithAffinityGroup, cls).getClsTestClient().getApiClient() - cls.services = Services().services + cls.testClient = super(TestDeployVmWithAffinityGroup, cls).getClsTestClient() + zone_name = cls.testClient.getZoneForTests() + cls.apiclient = cls.testClient.getApiClient() + cls.domain = get_domain(cls.apiclient) + cls.services = cls.testClient.getParsedTestDataConfig() # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests()) + cls.template = get_template( - cls.api_client, + cls.apiclient, cls.zone.id, cls.services["ostype"] ) + + if cls.template == FAILED: + assert False, "get_template() failed to return template with description %s" % cls.services["ostype"] + cls.services["virtual_machine"]["zoneid"] = cls.zone.id cls.services["template"] = cls.template.id cls.services["zoneid"] = cls.zone.id cls.account = Account.create( - cls.api_client, + cls.apiclient, cls.services["account"], domainid=cls.domain.id ) - - cls.services["account"] = cls.account.name - cls.service_offering = ServiceOffering.create( - cls.api_client, - cls.services["service_offering"] + cls.apiclient, + cls.services["service_offerings"] ) - cls.ag = AffinityGroup.create(cls.api_client, cls.services["virtual_machine"]["affinity"], - account=cls.services["account"], domainid=cls.domain.id) + cls.ag = AffinityGroup.create(cls.apiclient, cls.services["virtual_machine"]["affinity"], + account=cls.account.name, domainid=cls.domain.id) cls._cleanup = [ cls.service_offering, @@ -118,7 +85,7 @@ class TestDeployVmWithAffinityGroup(cloudstackTestCase): """ #deploy VM1 in affinity group created in setUp vm1 = VirtualMachine.create( - self.api_client, + self.apiclient, self.services["virtual_machine"], templateid=self.template.id, accountid=self.account.name, @@ -128,7 +95,7 @@ class TestDeployVmWithAffinityGroup(cloudstackTestCase): ) list_vm1 = list_virtual_machines( - self.api_client, + self.apiclient, id=vm1.id ) self.assertEqual( @@ -151,7 +118,7 @@ class TestDeployVmWithAffinityGroup(cloudstackTestCase): #deploy VM2 in affinity group created in setUp vm2 = VirtualMachine.create( - self.api_client, + self.apiclient, self.services["virtual_machine"], templateid=self.template.id, accountid=self.account.name, @@ -160,7 +127,7 @@ class TestDeployVmWithAffinityGroup(cloudstackTestCase): affinitygroupnames=[self.ag.name] ) list_vm2 = list_virtual_machines( - self.api_client, + self.apiclient, id=vm2.id ) self.assertEqual( @@ -189,6 +156,6 @@ class TestDeployVmWithAffinityGroup(cloudstackTestCase): def tearDownClass(cls): try: #Clean up, terminate the created templates - cleanup_resources(cls.api_client, cls._cleanup) + cleanup_resources(cls.apiclient, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) diff --git a/test/integration/smoke/test_deploy_vgpu_enabled_vm.py b/test/integration/smoke/test_deploy_vgpu_enabled_vm.py index 38c6d129ee0..fa33bdcdc7b 100644 --- a/test/integration/smoke/test_deploy_vgpu_enabled_vm.py +++ b/test/integration/smoke/test_deploy_vgpu_enabled_vm.py @@ -23,16 +23,19 @@ from marvin.cloudstackTestCase import cloudstackTestCase #Import Integration Libraries #base - contains all resources as entities and defines create, delete, list operations on them -from marvin.integration.lib.base import Account, VirtualMachine, ServiceOffering +from marvin.lib.base import Account, VirtualMachine, ServiceOffering #utils - utility classes for common cleanup, external library wrappers etc -from marvin.integration.lib.utils import cleanup_resources +from marvin.lib.utils import cleanup_resources #common - commonly used methods for all tests are listed here -from marvin.integration.lib.common import get_zone, get_domain, get_template +from marvin.lib.common import get_zone, get_domain, get_template + +from marvin.codes import FAILED from nose.plugins.attrib import attr + class Services: """Test VM Life Cycle Services """ @@ -116,12 +119,15 @@ class TestDeployvGPUenabledVM(cloudstackTestCase): self.apiclient = self.testClient.getApiClient() # Get Zone, Domain and Default Built-in template - self.domain = get_domain(self.apiclient, self.services) - self.zone = get_zone(self.apiclient, self.services) + self.domain = get_domain(self.apiclient) + self.zone = get_zone(self.apiclient, self.testClient.getZoneForTests()) self.services["mode"] = self.zone.networktype # Before running this test, register a windows template with ostype as 'Windows 7 (32-bit)' - self.template = get_template(self.apiclient, self.zone.id, self.services["ostype"], templatetype='USER') + self.services["ostype"] = 'Windows 7 (32-bit)' + self.template = get_template(self.apiclient, self.zone.id, self.services["ostype"]) + if self.template == FAILED: + assert False, "get_template() failed to return template with description %s" % self.services["ostype"] #create a user account self.account = Account.create( self.apiclient, diff --git a/test/integration/smoke/test_deploy_vm.py b/test/integration/smoke/test_deploy_vm.py index 6ff7346aab3..ca4891d415d 100644 --- a/test/integration/smoke/test_deploy_vm.py +++ b/test/integration/smoke/test_deploy_vm.py @@ -22,72 +22,36 @@ from marvin.cloudstackTestCase import cloudstackTestCase #Import Integration Libraries +from marvin.codes import FAILED #base - contains all resources as entities and defines create, delete, list operations on them -from marvin.integration.lib.base import Account, VirtualMachine, ServiceOffering, SimulatorMock +from marvin.lib.base import Account, VirtualMachine, ServiceOffering, SimulatorMock #utils - utility classes for common cleanup, external library wrappers etc -from marvin.integration.lib.utils import cleanup_resources +from marvin.lib.utils import cleanup_resources #common - commonly used methods for all tests are listed here -from marvin.integration.lib.common import get_zone, get_domain, get_template +from marvin.lib.common import get_zone, get_domain, get_template from nose.plugins.attrib import attr -class TestData(object): - """Test data object that is required to create resources - """ - def __init__(self): - self.testdata = { - #data to create an account - "account": { - "email": "test@test.com", - "firstname": "Test", - "lastname": "User", - "username": "test", - "password": "password", - }, - #data reqd for virtual machine creation - "virtual_machine" : { - "name" : "testvm", - "displayname" : "Test VM", - }, - #data reqd for virtual machine creation - "virtual_machine2" : { - "name" : "testvm2", - "displayname" : "Test VM2", - }, - "virtual_machine3" : { - "name" : "testvm3", - "displayname" : "Test VM3", - }, - #small service offering - "service_offering": { - "small": { - "name": "Small Instance", - "displaytext": "Small Instance", - "cpunumber": 1, - "cpuspeed": 100, - "memory": 256, - }, - }, - "ostype": 'CentOS 5.3 (64-bit)', - } - - class TestDeployVM(cloudstackTestCase): """Test deploy a VM into a user account """ def setUp(self): - self.testdata = TestData().testdata self.apiclient = self.testClient.getApiClient() + self.testdata = self.testClient.getParsedTestDataConfig() + # Get Zone, Domain and Default Built-in template - self.domain = get_domain(self.apiclient, self.testdata) - self.zone = get_zone(self.apiclient, self.testdata) + self.domain = get_domain(self.apiclient) + self.zone = get_zone(self.apiclient, self.testClient.getZoneForTests()) self.testdata["mode"] = self.zone.networktype self.template = get_template(self.apiclient, self.zone.id, self.testdata["ostype"]) + if self.template == FAILED: + self.fail("get_template() failed to return template with description %s" % self.testdata["ostype"]) + #create a user account self.account = Account.create( self.apiclient, @@ -97,7 +61,7 @@ class TestDeployVM(cloudstackTestCase): #create a service offering self.service_offering = ServiceOffering.create( self.apiclient, - self.testdata["service_offering"]["small"] + self.testdata["service_offerings"]["small"] ) #build cleanup list self.cleanup = [ diff --git a/test/integration/smoke/test_deploy_vm_root_resize.py b/test/integration/smoke/test_deploy_vm_root_resize.py index aa88beb28c1..e758ffd169a 100644 --- a/test/integration/smoke/test_deploy_vm_root_resize.py +++ b/test/integration/smoke/test_deploy_vm_root_resize.py @@ -23,13 +23,15 @@ from marvin.cloudstackTestCase import cloudstackTestCase #Import Integration Libraries #base - contains all resources as entities and defines create, delete, list operations on them -from marvin.integration.lib.base import Account, VirtualMachine, ServiceOffering +from marvin.lib.base import Account, VirtualMachine, ServiceOffering #utils - utility classes for common cleanup, external library wrappers etc -from marvin.integration.lib.utils import cleanup_resources +from marvin.lib.utils import cleanup_resources #common - commonly used methods for all tests are listed here -from marvin.integration.lib.common import get_zone, get_domain, get_template, list_volumes +from marvin.lib.common import get_zone, get_domain, get_template, list_volumes + +from marvin.codes import FAILED from nose.plugins.attrib import attr @@ -71,12 +73,15 @@ class TestDeployVM(cloudstackTestCase): def setUp(self): self.testdata = TestData().testdata self.apiclient = self.testClient.getApiClient() + self.hypervisor = self.testClient.getHypervisorInfo() # Get Zone, Domain and Default Built-in template - self.domain = get_domain(self.apiclient, self.testdata) - self.zone = get_zone(self.apiclient, self.testdata) + self.domain = get_domain(self.apiclient) + self.zone = get_zone(self.apiclient, self.testClient.getZoneForTests()) self.testdata["mode"] = self.zone.networktype self.template = get_template(self.apiclient, self.zone.id, self.testdata["ostype"]) + if self.template == FAILED: + assert False, "get_template() failed to return template with description %s" % self.services["ostype"] # for testing with specific template # self.template = get_template(self.apiclient, self.zone.id, self.testdata["ostype"], templatetype='USER', services = {"template":'31f52a4d-5681-43f7-8651-ad4aaf823618'}) @@ -107,7 +112,7 @@ class TestDeployVM(cloudstackTestCase): # 2. root disk has new size per listVolumes # 3. Rejects non-supported hypervisor types """ - if(self.apiclient.hypervisor == 'kvm'): + if(self.hypervisor == 'kvm'): newrootsize = (self.template.size >> 30) + 2 self.virtual_machine = VirtualMachine.create( self.apiclient, @@ -174,7 +179,7 @@ class TestDeployVM(cloudstackTestCase): "Check if the root volume resized appropriately" ) else: - self.debug("hypervisor %s unsupported for test 00, verifying it errors properly" % self.apiclient.hypervisor) + self.debug("hypervisor %s unsupported for test 00, verifying it errors properly" % self.hypervisor) newrootsize = (self.template.size >> 30) + 2 success = False @@ -195,13 +200,13 @@ class TestDeployVM(cloudstackTestCase): else: self.debug("virtual machine create did not fail appropriately. Error was actually : " + str(ex)); - self.assertEqual(success, True, "Check if unsupported hypervisor %s fails appropriately" % self.apiclient.hypervisor) + self.assertEqual(success, True, "Check if unsupported hypervisor %s fails appropriately" % self.hypervisor) @attr(tags = ['advanced', 'simulator', 'basic', 'sg', 'provisioning']) def test_01_deploy_vm_root_resize(self): """Test proper failure to deploy virtual machine with rootdisksize of 0 """ - if (self.apiclient.hypervisor == 'kvm'): + if (self.hypervisor == 'kvm'): newrootsize = 0 success = False try: @@ -223,13 +228,13 @@ class TestDeployVM(cloudstackTestCase): self.assertEqual(success, True, "Check if passing 0 as rootdisksize fails appropriately") else: - self.debug("test 01 does not support hypervisor type " + self.apiclient.hypervisor); + self.debug("test 01 does not support hypervisor type " + self.hypervisor); @attr(tags = ['advanced', 'simulator', 'basic', 'sg', 'provisioning']) def test_02_deploy_vm_root_resize(self): """Test proper failure to deploy virtual machine with rootdisksize less than template size """ - if (self.apiclient.hypervisor == 'kvm'): + if (self.hypervisor == 'kvm'): newrootsize = (self.template.size >> 30) - 1 self.assertEqual(newrootsize > 0, True, "Provided template is less than 1G in size, cannot run test") @@ -254,7 +259,7 @@ class TestDeployVM(cloudstackTestCase): self.assertEqual(success, True, "Check if passing rootdisksize < templatesize fails appropriately") else: - self.debug("test 01 does not support hypervisor type " + self.apiclient.hypervisor); + self.debug("test 01 does not support hypervisor type " + self.hypervisor); def tearDown(self): try: diff --git a/test/integration/smoke/test_deploy_vm_with_userdata.py b/test/integration/smoke/test_deploy_vm_with_userdata.py index b8be83a17e0..7616b82d4be 100644 --- a/test/integration/smoke/test_deploy_vm_with_userdata.py +++ b/test/integration/smoke/test_deploy_vm_with_userdata.py @@ -16,62 +16,33 @@ # under the License. from marvin.cloudstackTestCase import cloudstackTestCase -from marvin.integration.lib.base import (ServiceOffering, +from marvin.lib.base import (ServiceOffering, VirtualMachine, Account) -from marvin.integration.lib.common import get_template, get_zone, list_virtual_machines -from marvin.integration.lib.utils import cleanup_resources +from marvin.lib.common import get_template, get_zone, list_virtual_machines +from marvin.lib.utils import cleanup_resources from nose.plugins.attrib import attr - +from marvin.codes import FAILED import random import string -class Services: - def __init__(self): - self.services = { - "account": { - "email": "test@test.com", - "firstname": "Test", - "lastname": "User", - "username": "test", - "password": "password", - }, - "virtual_machine": { - "displayname": "Test VM", - "username": "root", - "password": "password", - "ssh_port": 22, - "hypervisor": 'XenServer', - "privateport": 22, - "publicport": 22, - "protocol": 'TCP', - }, - "ostype": 'CentOS 5.3 (64-bit)', - "service_offering": { - "name": "Tiny Instance", - "displaytext": "Tiny Instance", - "cpunumber": 1, - "cpuspeed": 100, - "memory": 256, - }, - } - - class TestDeployVmWithUserData(cloudstackTestCase): """Tests for UserData """ @classmethod def setUpClass(cls): - cls.apiClient = super(TestDeployVmWithUserData, cls).getClsTestClient().getApiClient() - cls.services = Services().services - cls.zone = get_zone(cls.apiClient, cls.services) + testClient = super(TestDeployVmWithUserData, cls).getClsTestClient() + cls.apiClient = testClient.getApiClient() + cls.services = testClient.getParsedTestDataConfig() + + cls.zone = get_zone(cls.apiClient, testClient.getZoneForTests()) if cls.zone.localstorageenabled: #For devcloud since localstroage is enabled - cls.services["service_offering"]["storagetype"] = "local" + cls.services["service_offerings"]["storagetype"] = "local" cls.service_offering = ServiceOffering.create( cls.apiClient, - cls.services["service_offering"] + cls.services["service_offerings"] ) cls.account = Account.create(cls.apiClient, services=cls.services["account"]) cls.cleanup = [cls.account] @@ -80,6 +51,10 @@ class TestDeployVmWithUserData(cloudstackTestCase): cls.zone.id, cls.services["ostype"] ) + + if cls.template == FAILED: + assert False, "get_template() failed to return template with description %s" % cls.services["ostype"] + cls.debug("Successfully created account: %s, id: \ %s" % (cls.account.name,\ cls.account.id)) @@ -92,7 +67,10 @@ class TestDeployVmWithUserData(cloudstackTestCase): user_data = ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(2500)) cls.services["virtual_machine"]["userdata"] = user_data - @attr(tags=["simulator", "devcloud", "basic", "advanced", "provisioning"]) + def setup(self): + self.hypervisor = self.testClient.getHypervisorInfo() + + @attr(tags=["simulator", "devcloud", "basic", "advanced", "post", "provisioning"]) def test_deployvm_userdata_post(self): """Test userdata as POST, size > 2k """ diff --git a/test/integration/smoke/test_deploy_vms_with_varied_deploymentplanners.py b/test/integration/smoke/test_deploy_vms_with_varied_deploymentplanners.py index fc11549c8c6..420925e3781 100644 --- a/test/integration/smoke/test_deploy_vms_with_varied_deploymentplanners.py +++ b/test/integration/smoke/test_deploy_vms_with_varied_deploymentplanners.py @@ -15,40 +15,13 @@ # specific language governing permissions and limitations # under the License. +from marvin.codes import FAILED from marvin.cloudstackTestCase import cloudstackTestCase -from marvin.integration.lib.base import Account, VirtualMachine, ServiceOffering, Host, Cluster -from marvin.integration.lib.common import get_zone, get_domain, get_template -from marvin.integration.lib.utils import cleanup_resources +from marvin.lib.base import Account, VirtualMachine, ServiceOffering, Host, Cluster +from marvin.lib.common import get_zone, get_domain, get_template +from marvin.lib.utils import cleanup_resources from nose.plugins.attrib import attr -class Services: - def __init__(self): - self.services = { - "account": { - "email": "test@test.com", - "firstname": "Test", - "lastname": "User", - "username": "test", - # Random characters are appended for unique - # username - "password": "password", - }, - "service_offering": { - "name": "Planner Service Offering", - "displaytext": "Planner Service Offering", - "cpunumber": 1, - "cpuspeed": 100, - # in MHz - "memory": 128, - # In MBs - }, - "ostype": 'CentOS 5.3 (64-bit)', - "virtual_machine": { - "hypervisor": "XenServer", - } - } - - class TestDeployVmWithVariedPlanners(cloudstackTestCase): """ Test to create services offerings for deployment planners - firstfit, userdispersing @@ -56,16 +29,22 @@ class TestDeployVmWithVariedPlanners(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.apiclient = super(TestDeployVmWithVariedPlanners, cls).getClsTestClient().getApiClient() - cls.services = Services().services + testClient = super(TestDeployVmWithVariedPlanners, cls).getClsTestClient() + cls.apiclient = testClient.getApiClient() + cls.services = testClient.getParsedTestDataConfig() + # Get Zone, Domain and templates - cls.domain = get_domain(cls.apiclient, cls.services) - cls.zone = get_zone(cls.apiclient, cls.services) + cls.domain = get_domain(cls.apiclient) + cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests()) cls.template = get_template( cls.apiclient, cls.zone.id, cls.services["ostype"] ) + + if cls.template == FAILED: + assert false, "get_template() failed to return template with description %s" % cls.services["ostype"] + cls.services["virtual_machine"]["zoneid"] = cls.zone.id cls.services["template"] = cls.template.id cls.services["zoneid"] = cls.zone.id @@ -75,7 +54,6 @@ class TestDeployVmWithVariedPlanners(cloudstackTestCase): cls.services["account"], domainid=cls.domain.id ) - cls.services["account"] = cls.account.name cls.hosts = Host.list(cls.apiclient, type='Routing') cls.clusters = Cluster.list(cls.apiclient) cls.cleanup = [ @@ -89,7 +67,7 @@ class TestDeployVmWithVariedPlanners(cloudstackTestCase): #FIXME: How do we know that first fit actually happened? self.service_offering_firstfit = ServiceOffering.create( self.apiclient, - self.services["service_offering"], + self.services["service_offerings"], deploymentplanner='FirstFitPlanner' ) @@ -132,7 +110,7 @@ class TestDeployVmWithVariedPlanners(cloudstackTestCase): """ self.service_offering_userdispersing = ServiceOffering.create( self.apiclient, - self.services["service_offering"], + self.services["service_offerings"], deploymentplanner='UserDispersingPlanner' ) @@ -191,7 +169,7 @@ class TestDeployVmWithVariedPlanners(cloudstackTestCase): """ self.service_offering_userconcentrated = ServiceOffering.create( self.apiclient, - self.services["service_offering"], + self.services["service_offerings"], deploymentplanner='UserConcentratedPodPlanner' ) diff --git a/test/integration/smoke/test_disk_offerings.py b/test/integration/smoke/test_disk_offerings.py index 4c8a34c953e..780c1542703 100644 --- a/test/integration/smoke/test_disk_offerings.py +++ b/test/integration/smoke/test_disk_offerings.py @@ -20,30 +20,17 @@ import marvin from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * from nose.plugins.attrib import attr _multiprocess_shared_ = True -class Services: - """Test Disk offerings Services - """ - - def __init__(self): - self.services = { - "off": { - "name": "Disk offering", - "displaytext": "Disk offering", - "disksize": 1 # in GB - }, - } - class TestCreateDiskOffering(cloudstackTestCase): def setUp(self): - self.services = Services().services + self.services = self.testClient.getParsedTestDataConfig() self.apiclient = self.testClient.getApiClient() self.dbclient = self.testClient.getDbConnection() self.cleanup = [] @@ -68,7 +55,7 @@ class TestCreateDiskOffering(cloudstackTestCase): """ disk_offering = DiskOffering.create( self.apiclient, - self.services["off"] + self.services["disk_offering"] ) self.cleanup.append(disk_offering) @@ -92,16 +79,96 @@ class TestCreateDiskOffering(cloudstackTestCase): self.assertEqual( disk_response.displaytext, - self.services["off"]["displaytext"], + self.services["disk_offering"]["displaytext"], "Check server id in createServiceOffering" ) self.assertEqual( disk_response.name, - self.services["off"]["name"], + self.services["disk_offering"]["name"], "Check name in createServiceOffering" ) return + @attr(hypervisor="kvm") + @attr(tags = ["advanced", "basic", "eip", "sg", "advancedns", "simulator", "smoke"]) + def test_02_create_sparse_type_disk_offering(self): + """Test to create a sparse type disk offering""" + + # Validate the following: + # 1. createDiskOfferings should return valid info for new offering + # 2. The Cloud Database contains the valid information + + disk_offering = DiskOffering.create( + self.apiclient, + self.services["sparse"] + ) + self.cleanup.append(disk_offering) + + self.debug("Created Disk offering with ID: %s" % disk_offering.id) + + list_disk_response = list_disk_offering( + self.apiclient, + id=disk_offering.id + ) + self.assertEqual( + isinstance(list_disk_response, list), + True, + "Check list response returns a valid list" + ) + self.assertNotEqual( + len(list_disk_response), + 0, + "Check Disk offering is created" + ) + disk_response = list_disk_response[0] + + self.assertEqual( + disk_response.provisioningtype, + self.services["sparse"]["provisioningtype"], + "Check provisionig type in createServiceOffering" + ) + return + + + @attr(hypervisor="kvm") + @attr(tags = ["advanced", "basic", "eip", "sg", "advancedns", "simulator", "smoke"]) + def test_04_create_fat_type_disk_offering(self): + """Test to create a sparse type disk offering""" + + # Validate the following: + # 1. createDiskOfferings should return valid info for new offering + # 2. The Cloud Database contains the valid information + + disk_offering = DiskOffering.create( + self.apiclient, + self.services["fat"] + ) + self.cleanup.append(disk_offering) + + self.debug("Created Disk offering with ID: %s" % disk_offering.id) + + list_disk_response = list_disk_offering( + self.apiclient, + id=disk_offering.id + ) + self.assertEqual( + isinstance(list_disk_response, list), + True, + "Check list response returns a valid list" + ) + self.assertNotEqual( + len(list_disk_response), + 0, + "Check Disk offering is created" + ) + disk_response = list_disk_response[0] + + self.assertEqual( + disk_response.provisioningtype, + self.services["fat"]["provisioningtype"], + "Check provisionig type in createServiceOffering" + ) + return class TestDiskOfferings(cloudstackTestCase): @@ -122,15 +189,17 @@ class TestDiskOfferings(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.services = Services().services - cls.api_client = super(TestDiskOfferings, cls).getClsTestClient().getApiClient() + testClient = super(TestDiskOfferings, cls).getClsTestClient() + cls.apiclient = cls.testClient.getApiClient() + cls.services = cls.testClient.getParsedTestDataConfig() + cls.disk_offering_1 = DiskOffering.create( - cls.api_client, - cls.services["off"] + cls.apiclient, + cls.services["disk_offering"] ) cls.disk_offering_2 = DiskOffering.create( - cls.api_client, - cls.services["off"] + cls.apiclient, + cls.services["disk_offering"] ) cls._cleanup = [cls.disk_offering_1] return @@ -138,8 +207,8 @@ class TestDiskOfferings(cloudstackTestCase): @classmethod def tearDownClass(cls): try: - cls.api_client = super(TestDiskOfferings, cls).getClsTestClient().getApiClient() - cleanup_resources(cls.api_client, cls._cleanup) + cls.apiclient = super(TestDiskOfferings, cls).getClsTestClient().getApiClient() + cleanup_resources(cls.apiclient, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) return diff --git a/test/integration/smoke/test_global_settings.py b/test/integration/smoke/test_global_settings.py index f94cf940b16..ace2db31917 100644 --- a/test/integration/smoke/test_global_settings.py +++ b/test/integration/smoke/test_global_settings.py @@ -19,9 +19,9 @@ #Import Local Modules from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common 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 diff --git a/test/integration/smoke/test_guest_vlan_range.py b/test/integration/smoke/test_guest_vlan_range.py index 27225a54695..bfef4a8e657 100644 --- a/test/integration/smoke/test_guest_vlan_range.py +++ b/test/integration/smoke/test_guest_vlan_range.py @@ -21,43 +21,22 @@ import marvin from nose.plugins.attrib import attr from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * import datetime - -class Services: - """Test Dedicating Guest Vlan Ranges - """ - - def __init__(self): - self.services = { - "domain": { - "name": "Domain", - }, - "account": { - "email": "test@test.com", - "firstname": "Test", - "lastname": "User", - "username": "test", - "password": "password", - }, - "name": "testphysicalnetwork", - - "vlan": "2118-2120", - } - - class TestDedicateGuestVlanRange(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.apiclient = super(TestDedicateGuestVlanRange, cls).getClsTestClient().getApiClient() - cls.services = Services().services + testClient = super(TestDedicateGuestVlanRange, cls).getClsTestClient() + cls.apiclient = testClient.getApiClient() + cls.services = testClient.getParsedTestDataConfig() + # Get Zone, Domain - cls.domain = get_domain(cls.apiclient, cls.services) - cls.zone = get_zone(cls.apiclient, cls.services) + cls.domain = get_domain(cls.apiclient) + cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests()) # Create Account cls.account = Account.create( diff --git a/test/integration/smoke/test_hosts.py b/test/integration/smoke/test_hosts.py index 0810baca55a..52827aa7fed 100644 --- a/test/integration/smoke/test_hosts.py +++ b/test/integration/smoke/test_hosts.py @@ -20,9 +20,9 @@ import marvin from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common 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 @@ -30,81 +30,15 @@ import time _multiprocess_shared_ = True -class Services: - """Test Hosts & Clusters Services - """ - - def __init__(self): - self.services = { - "clusters": { - 0: { - "clustername": "Xen Cluster", - "clustertype": "CloudManaged", - # CloudManaged or ExternalManaged" - "hypervisor": "XenServer", - # Hypervisor type - }, - 1: { - "clustername": "KVM Cluster", - "clustertype": "CloudManaged", - # CloudManaged or ExternalManaged" - "hypervisor": "KVM", - # Hypervisor type - }, - 2: { - "hypervisor": 'VMware', - # Hypervisor type - "clustertype": 'ExternalManaged', - # CloudManaged or ExternalManaged" - "username": 'administrator', - "password": 'fr3sca', - "url": 'http://192.168.100.17/CloudStack-Clogeny-Pune/Pune-1', - # Format:http://vCenter Host/Datacenter/Cluster - "clustername": 'VMWare Cluster', - }, - }, - "hosts": { - "xenserver": { - # Must be name of corresponding Hypervisor type - # in cluster in small letters - "hypervisor": 'XenServer', - # Hypervisor type - "clustertype": 'CloudManaged', - # CloudManaged or ExternalManaged" - "url": 'http://192.168.100.211', - "username": "root", - "password": "fr3sca", - }, - "kvm": { - "hypervisor": 'KVM', - # Hypervisor type - "clustertype": 'CloudManaged', - # CloudManaged or ExternalManaged" - "url": 'http://192.168.100.212', - "username": "root", - "password": "fr3sca", - }, - "vmware": { - "hypervisor": 'VMware', - # Hypervisor type - "clustertype": 'ExternalManaged', - # CloudManaged or ExternalManaged" - "url": 'http://192.168.100.203', - "username": "administrator", - "password": "fr3sca", - }, - }, - } - class TestHosts(cloudstackTestCase): def setUp(self): - self.apiclient = self.testClient.getApiClient() + self.hypervisor = self.testClient.getHypervisorInfo() self.dbclient = self.testClient.getDbConnection() - self.services = Services().services - self.zone = get_zone(self.apiclient, self.services) - self.pod = get_pod(self.apiclient, self.zone.id, self.services) + self.services = self.testClient.getParsedTestDataConfig() + self.zone = get_zone(self.apiclient, self.testClient.getZoneForTests()) + self.pod = get_pod(self.apiclient, self.zone.id) self.cleanup = [] return @@ -136,7 +70,8 @@ class TestHosts(cloudstackTestCase): self.apiclient, v, zoneid=self.zone.id, - podid=self.pod.id + podid=self.pod.id, + hypervisor=self.hypervisor ) self.debug( "Created Cluster for hypervisor type %s & ID: %s" %( @@ -167,8 +102,11 @@ class TestHosts(cloudstackTestCase): cluster, self.services["hosts"][hypervisor_type], zoneid=self.zone.id, - podid=self.pod.id + podid=self.pod.id, + hypervisor=self.hypervisor ) + if host == FAILED: + self.fail("Host Creation Failed") self.debug( "Created host (ID: %s) in cluster ID %s" %( host.id, diff --git a/test/integration/smoke/test_internal_lb.py b/test/integration/smoke/test_internal_lb.py index 875df04fc42..d6f34775956 100644 --- a/test/integration/smoke/test_internal_lb.py +++ b/test/integration/smoke/test_internal_lb.py @@ -17,80 +17,29 @@ """ Tests for configuring Internal Load Balancing Rules. """ #Import Local Modules +from marvin.codes import FAILED from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * from nose.plugins.attrib import attr - -class Services: - def __init__(self): - self.services = { - "account": { - "email": "test@test.com", - "firstname": "Test", - "lastname": "User", - "username": "test", - "password": "password", - }, - "virtual_machine": { - "displayname": "Test VM", - "username": "root", - "password": "password", - "ssh_port": 22, - "hypervisor": 'XenServer', - "privateport": 22, - "publicport": 22, - "protocol": 'TCP', - }, - "ostype": 'CentOS 5.3 (64-bit)', - "service_offering": { - "name": "Tiny Instance", - "displaytext": "Tiny Instance", - "cpunumber": 1, - "cpuspeed": 100, - "memory": 256, - }, - "network_offering": { - "name": "Network offering for internal lb service", - "displaytext": "Network offering for internal lb service", - "guestiptype": "Isolated", - "traffictype": "Guest", - "supportedservices": "Vpn,Dhcp,Dns,Lb,UserData,SourceNat,StaticNat,PortForwarding,NetworkACL", - "serviceProviderList": { - "Dhcp": "VpcVirtualRouter", - "Dns": "VpcVirtualRouter", - "Vpn": "VpcVirtualRouter", - "UserData": "VpcVirtualRouter", - "Lb": "InternalLbVM", - "SourceNat": "VpcVirtualRouter", - "StaticNat": "VpcVirtualRouter", - "PortForwarding": "VpcVirtualRouter", - "NetworkACL": "VpcVirtualRouter", - }, - "serviceCapabilityList": { - "SourceNat": {"SupportedSourceNatTypes": "peraccount"}, - "Lb": {"lbSchemes": "internal", "SupportedLbIsolation": "dedicated"} - } - } - } - - class TestInternalLb(cloudstackTestCase): """Test Internal LB """ @classmethod def setUpClass(cls): - cls.apiclient = super(TestInternalLb, cls).getClsTestClient().getApiClient() - cls.services = Services().services - cls.zone = get_zone(cls.apiclient, cls.services) + testClient = super(TestInternalLb, cls).getClsTestClient() + cls.apiclient = testClient.getApiClient() + cls.services = testClient.getParsedTestDataConfig() + + cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests()) cls.domain = get_domain(cls.apiclient) cls.service_offering = ServiceOffering.create( cls.apiclient, - cls.services["service_offering"] + cls.services["service_offerings"] ) cls.account = Account.create(cls.apiclient, services=cls.services["account"]) cls.template = get_template( @@ -98,6 +47,10 @@ class TestInternalLb(cloudstackTestCase): cls.zone.id, cls.services["ostype"] ) + + if cls.template == FAILED: + assert False, "get_template() failed to return template with description %s" % cls.services["ostype"] + cls.debug("Successfully created account: %s, id: \ %s" % (cls.account.name,\ cls.account.id)) @@ -106,10 +59,10 @@ class TestInternalLb(cloudstackTestCase): @attr(tags=["smoke", "advanced", "provisioning"]) def test_internallb(self): """Test create, delete, assign, remove of internal loadbalancer + """ #1) Create and enable network offering with Internal Lb vm service - """ + self.networkOffering = NetworkOffering.create(self.apiclient, self.services["network_offering_internal_lb"], conservemode=False) #TODO: SIMENH:modify this test to verify lb rules by sending request from another tier - self.networkOffering = NetworkOffering.create(self.apiclient, self.services["network_offering"], conservemode=False) self.networkOffering.update(self.apiclient, state="Enabled") #2) Create VPC and network in it diff --git a/test/integration/smoke/test_iso.py b/test/integration/smoke/test_iso.py index 01ce2fdfd98..4a22850b1d4 100644 --- a/test/integration/smoke/test_iso.py +++ b/test/integration/smoke/test_iso.py @@ -20,9 +20,9 @@ import marvin from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * from nose.plugins.attrib import attr import urllib from random import random @@ -31,70 +31,19 @@ import time _multiprocess_shared_ = True -class Services: - """Test ISO Services - """ - - def __init__(self): - self.services = { - "account": { - "email": "test@test.com", - "firstname": "Test", - "lastname": "User", - "username": "test", - # Random characters are appended in create account to - # ensure unique username generated each time - "password": "password", - }, - "iso_1": - { - "displaytext": "Test ISO 1", - "name": "ISO 1", - "url": "http://people.apache.org/~tsp/dummy.iso", - # Source URL where ISO is located - "isextractable": True, - "isfeatured": True, - "ispublic": True, - "ostype": "CentOS 5.3 (64-bit)", - }, - "iso_2": - { - "displaytext": "Test ISO 2", - "name": "ISO 2", - "url": "http://people.apache.org/~tsp/dummy.iso", - # Source URL where ISO is located - "isextractable": True, - "isfeatured": True, - "ispublic": True, - "ostype": "CentOS 5.3 (64-bit)", - "mode": 'HTTP_DOWNLOAD', - # Used in Extract template, value must be HTTP_DOWNLOAD - }, - "isfeatured": True, - "ispublic": True, - "isextractable": True, - "bootable": True, # For edit template - "passwordenabled": True, - "sleep": 60, - "timeout": 10, - "ostype": "CentOS 5.3 (64-bit)", - # CentOS 5.3 (64 bit) - } - - class TestCreateIso(cloudstackTestCase): #TODO: SIMENH: check the existence of registered of ISO in secondary deploy a VM with registered ISO. can be added \ # as another test def setUp(self): - self.services = Services().services + self.services = self.testClient.getParsedTestDataConfig() self.apiclient = self.testClient.getApiClient() self.dbclient = self.testClient.getDbConnection() # Get Zone, Domain and templates - self.domain = get_domain(self.apiclient, self.services) - self.zone = get_zone(self.apiclient, self.services) + self.domain = get_domain(self.apiclient) + self.zone = get_zone(self.apiclient, self.testClient.getZoneForTests()) self.services['mode'] = self.zone.networktype self.services["domainid"] = self.domain.id - self.services["iso_2"]["zoneid"] = self.zone.id + self.services["iso2"]["zoneid"] = self.zone.id self.account = Account.create( self.apiclient, @@ -109,8 +58,8 @@ class TestCreateIso(cloudstackTestCase): if not isinstance(ostypes, list): raise unittest.SkipTest("OSTypeId for given description not found") - self.services["iso_1"]["ostypeid"] = ostypes[0].id - self.services["iso_2"]["ostypeid"] = ostypes[0].id + self.services["iso1"]["ostypeid"] = ostypes[0].id + self.services["iso2"]["ostypeid"] = ostypes[0].id self.services["ostypeid"] = ostypes[0].id self.cleanup = [self.account] @@ -139,7 +88,7 @@ class TestCreateIso(cloudstackTestCase): iso = Iso.create( self.apiclient, - self.services["iso_2"], + self.services["iso2"], account=self.account.name, domainid=self.account.domainid ) @@ -170,17 +119,17 @@ class TestCreateIso(cloudstackTestCase): self.assertEqual( iso_response.displaytext, - self.services["iso_2"]["displaytext"], + self.services["iso2"]["displaytext"], "Check display text of newly created ISO" ) self.assertEqual( iso_response.name, - self.services["iso_2"]["name"], + self.services["iso2"]["name"], "Check name of newly created ISO" ) self.assertEqual( iso_response.zoneid, - self.services["iso_2"]["zoneid"], + self.services["iso2"]["zoneid"], "Check zone ID of newly created ISO" ) return @@ -191,62 +140,62 @@ class TestISO(cloudstackTestCase): @classmethod @attr(BugId="CLOUDSTACK-6769, CLOUDSTACK-6774") def setUpClass(cls): - cls.services = Services().services - cls.api_client = super(TestISO, cls).getClsTestClient().getApiClient() + testClient = super(TestISO, cls).getClsTestClient() + cls.apiclient = testClient.getApiClient() + cls.services = testClient.getParsedTestDataConfig() # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.apiclient) + cls.zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests()) cls.services["domainid"] = cls.domain.id - cls.services["iso_1"]["zoneid"] = cls.zone.id - cls.services["iso_2"]["zoneid"] = cls.zone.id + cls.services["iso1"]["zoneid"] = cls.zone.id + cls.services["iso2"]["zoneid"] = cls.zone.id cls.services["sourcezoneid"] = cls.zone.id #populate second zone id for iso copy cmd = listZones.listZonesCmd() - cls.zones = cls.api_client.listZones(cmd) + cls.zones = cls.apiclient.listZones(cmd) if not isinstance(cls.zones, list): raise Exception("Failed to find zones.") #Create an account, ISOs etc. cls.account = Account.create( - cls.api_client, + cls.apiclient, cls.services["account"], domainid=cls.domain.id ) - cls.services["account"] = cls.account.name # Finding the OsTypeId from Ostype ostypes = list_os_types( - cls.api_client, + cls.apiclient, description=cls.services["ostype"] ) if not isinstance(ostypes, list): raise unittest.SkipTest("OSTypeId for given description not found") - cls.services["iso_1"]["ostypeid"] = ostypes[0].id - cls.services["iso_2"]["ostypeid"] = ostypes[0].id + cls.services["iso1"]["ostypeid"] = ostypes[0].id + cls.services["iso2"]["ostypeid"] = ostypes[0].id cls.services["ostypeid"] = ostypes[0].id cls.iso_1 = Iso.create( - cls.api_client, - cls.services["iso_1"], + cls.apiclient, + cls.services["iso1"], account=cls.account.name, domainid=cls.account.domainid ) try: - cls.iso_1.download(cls.api_client) + cls.iso_1.download(cls.apiclient) except Exception as e: raise Exception("Exception while downloading ISO %s: %s"\ % (cls.iso_1.id, e)) cls.iso_2 = Iso.create( - cls.api_client, - cls.services["iso_2"], + cls.apiclient, + cls.services["iso2"], account=cls.account.name, domainid=cls.account.domainid ) try: - cls.iso_2.download(cls.api_client) + cls.iso_2.download(cls.apiclient) except Exception as e: raise Exception("Exception while downloading ISO %s: %s"\ % (cls.iso_2.id, e)) @@ -257,9 +206,9 @@ class TestISO(cloudstackTestCase): @classmethod def tearDownClass(cls): try: - cls.api_client = super(TestISO, cls).getClsTestClient().getApiClient() + cls.apiclient = super(TestISO, cls).getClsTestClient().getApiClient() #Clean up, terminate the created templates - cleanup_resources(cls.api_client, cls._cleanup) + cleanup_resources(cls.apiclient, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) @@ -388,8 +337,8 @@ class TestISO(cloudstackTestCase): cmd = extractIso.extractIsoCmd() cmd.id = self.iso_2.id - cmd.mode = self.services["iso_2"]["mode"] - cmd.zoneid = self.services["iso_2"]["zoneid"] + cmd.mode = self.services["iso2"]["mode"] + cmd.zoneid = self.services["iso2"]["zoneid"] list_extract_response = self.apiclient.extractIso(cmd) try: @@ -410,12 +359,12 @@ class TestISO(cloudstackTestCase): ) self.assertEqual( list_extract_response.extractMode, - self.services["iso_2"]["mode"], + self.services["iso2"]["mode"], "Check mode of extraction" ) self.assertEqual( list_extract_response.zoneid, - self.services["iso_2"]["zoneid"], + self.services["iso2"]["zoneid"], "Check zone ID of extraction" ) self.assertEqual( diff --git a/test/integration/smoke/test_loadbalance.py b/test/integration/smoke/test_loadbalance.py index 46eb7d49dce..daa5fee3d25 100644 --- a/test/integration/smoke/test_loadbalance.py +++ b/test/integration/smoke/test_loadbalance.py @@ -15,154 +15,86 @@ # specific language governing permissions and limitations # under the License. +from marvin.codes import FAILED from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * from marvin.sshClient import SshClient -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common 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 Services: - """Test Network Services - """ - - def __init__(self): - self.services = { - "ostype": "CentOS 5.3 (64-bit)", - # Cent OS 5.3 (64 bit) - "lb_switch_wait": 10, - # Time interval after which LB switches the requests - "sleep": 60, - "timeout":10, - "network_offering": { - "name": 'Test Network offering', - "displaytext": 'Test Network offering', - "guestiptype": 'Isolated', - "supportedservices": 'Dhcp,Dns,SourceNat,PortForwarding', - "traffictype": 'GUEST', - "availability": 'Optional', - "serviceProviderList" : { - "Dhcp": 'VirtualRouter', - "Dns": 'VirtualRouter', - "SourceNat": 'VirtualRouter', - "PortForwarding": 'VirtualRouter', - }, - }, - "network": { - "name": "Test Network", - "displaytext": "Test Network", - }, - "service_offering": { - "name": "Tiny Instance", - "displaytext": "Tiny Instance", - "cpunumber": 1, - "cpuspeed": 100, - # in MHz - "memory": 256, - # In MBs - }, - "account": { - "email": "test@test.com", - "firstname": "Test", - "lastname": "User", - "username": "test", - "password": "password", - }, - "server": - { - "displayname": "Small Instance", - "username": "root", - "password": "password", - "hypervisor": 'XenServer', - "privateport": 22, - "publicport": 22, - "ssh_port": 22, - "protocol": 'TCP', - }, - "natrule": - { - "privateport": 22, - "publicport": 2222, - "protocol": "TCP" - }, - "lbrule": - { - "name": "SSH", - "alg": "roundrobin", - # Algorithm used for load balancing - "privateport": 22, - "publicport": 2222, - "protocol": 'TCP' - } - } - class TestLoadBalance(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestLoadBalance, cls).getClsTestClient().getApiClient() - cls.services = Services().services + testClient = super(TestLoadBalance, cls).getClsTestClient() + cls.apiclient = testClient.getApiClient() + cls.services = testClient.getParsedTestDataConfig() + # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.apiclient) + cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests()) template = get_template( - cls.api_client, + cls.apiclient, cls.zone.id, cls.services["ostype"] ) - cls.services["server"]["zoneid"] = cls.zone.id + if template == FAILED: + assert False, "get_template() failed to return template with description %s" % cls.services["ostype"] + + cls.services["virtual_machine"]["zoneid"] = cls.zone.id #Create an account, network, VM and IP addresses cls.account = Account.create( - cls.api_client, + cls.apiclient, cls.services["account"], admin=True, domainid=cls.domain.id ) cls.service_offering = ServiceOffering.create( - cls.api_client, - cls.services["service_offering"] + cls.apiclient, + cls.services["service_offerings"] ) cls.vm_1 = VirtualMachine.create( - cls.api_client, - cls.services["server"], + cls.apiclient, + cls.services["virtual_machine"], templateid=template.id, accountid=cls.account.name, domainid=cls.account.domainid, serviceofferingid=cls.service_offering.id ) cls.vm_2 = VirtualMachine.create( - cls.api_client, - cls.services["server"], + cls.apiclient, + cls.services["virtual_machine"], templateid=template.id, accountid=cls.account.name, domainid=cls.account.domainid, serviceofferingid=cls.service_offering.id ) cls.vm_3 = VirtualMachine.create( - cls.api_client, - cls.services["server"], + cls.apiclient, + cls.services["virtual_machine"], templateid=template.id, accountid=cls.account.name, domainid=cls.account.domainid, serviceofferingid=cls.service_offering.id ) cls.non_src_nat_ip = PublicIPAddress.create( - cls.api_client, + cls.apiclient, cls.account.name, cls.zone.id, cls.account.domainid, - cls.services["server"] + cls.services["virtual_machine"] ) # Open up firewall port for SSH cls.fw_rule = FireWallRule.create( - cls.api_client, + cls.apiclient, ipaddressid=cls.non_src_nat_ip.ipaddress.id, protocol=cls.services["lbrule"]["protocol"], cidrlist=['0.0.0.0/0'], @@ -185,7 +117,7 @@ class TestLoadBalance(cloudstackTestCase): @classmethod def tearDownClass(cls): - cleanup_resources(cls.api_client, cls._cleanup) + cleanup_resources(cls.apiclient, cls._cleanup) return def try_ssh(self, ip_addr, hostnames): @@ -208,7 +140,7 @@ class TestLoadBalance(cloudstackTestCase): except Exception as e: self.fail("%s: SSH failed for VM with IP Address: %s" % (e, ip_addr)) - time.sleep(self.services["lb_switch_wait"]) + time.sleep(10) return @attr(tags = ["advanced", "advancedns", "smoke", "provisioning"]) diff --git a/test/integration/smoke/test_multipleips_per_nic.py b/test/integration/smoke/test_multipleips_per_nic.py index 0c6c02a05b4..ad3a3cf2e0e 100644 --- a/test/integration/smoke/test_multipleips_per_nic.py +++ b/test/integration/smoke/test_multipleips_per_nic.py @@ -16,6 +16,7 @@ # under the License. #Test from the Marvin - Testing in Python wiki +from marvin.codes import FAILED #All tests inherit from cloudstackTestCase from marvin.cloudstackTestCase import cloudstackTestCase @@ -23,13 +24,13 @@ from marvin.cloudstackTestCase import cloudstackTestCase #Import Integration Libraries #base - contains all resources as entities and defines create, delete, list operations on them -from marvin.integration.lib.base import Account, VirtualMachine, ServiceOffering +from marvin.lib.base import Account, VirtualMachine, ServiceOffering #utils - utility classes for common cleanup, external library wrappers etc -from marvin.integration.lib.utils import cleanup_resources +from marvin.lib.utils import cleanup_resources #common - commonly used methods for all tests are listed here -from marvin.integration.lib.common import get_zone, get_domain, get_template +from marvin.lib.common import get_zone, get_domain, get_template from marvin.cloudstackAPI.addIpToNic import addIpToNicCmd from marvin.cloudstackAPI.removeIpFromNic import removeIpFromNicCmd @@ -38,52 +39,23 @@ from marvin.cloudstackAPI.listNics import listNicsCmd from nose.plugins.attrib import attr -class TestData(object): - """Test data object that is required to create resources - """ - def __init__(self): - self.testdata = { - #data to create an account - "account": { - "email": "test@test.com", - "firstname": "Test", - "lastname": "User", - "username": "test", - "password": "password", - }, - #data reqd for virtual machine creation - "virtual_machine" : { - "name" : "testvm", - "displayname" : "Test VM", - }, - #small service offering - "service_offering": { - "small": { - "name": "Small Instance", - "displaytext": "Small Instance", - "cpunumber": 1, - "cpuspeed": 100, - "memory": 256, - }, - }, - "ostype": 'CentOS 5.3 (64-bit)', - } - - class TestDeployVM(cloudstackTestCase): """Test deploy a VM into a user account """ def setUp(self): - self.testdata = TestData().testdata + self.testdata = self.testClient.getParsedTestDataConfig() self.apiclient = self.testClient.getApiClient() # Get Zone, Domain and Default Built-in template - self.domain = get_domain(self.apiclient, self.testdata) - self.zone = get_zone(self.apiclient, self.testdata) + self.domain = get_domain(self.apiclient) + self.zone = get_zone(self.apiclient, self.testClient.getZoneForTests()) self.testdata["mode"] = self.zone.networktype self.template = get_template(self.apiclient, self.zone.id, self.testdata["ostype"]) + if self.template == FAILED: + assert False, "get_template() failed to return template with description %s" % self.testdata["ostype"] + #create a user account self.account = Account.create( self.apiclient, @@ -93,7 +65,7 @@ class TestDeployVM(cloudstackTestCase): #create a service offering self.service_offering = ServiceOffering.create( self.apiclient, - self.testdata["service_offering"]["small"] + self.testdata["service_offerings"]["small"] ) #build cleanup list self.cleanup = [ diff --git a/test/integration/smoke/test_network.py b/test/integration/smoke/test_network.py index 2cdcfa277b6..a9e0c25a36d 100644 --- a/test/integration/smoke/test_network.py +++ b/test/integration/smoke/test_network.py @@ -18,139 +18,67 @@ """ #Import Local Modules import marvin -from marvin.cloudstackException import cloudstackAPIException +from marvin.codes import FAILED +from marvin.cloudstackException import CloudstackAPIException from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * from marvin.sshClient import SshClient -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common 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 Services: - """Test Network Services - """ - - def __init__(self): - self.services = { - "ostype": "CentOS 5.3 (64-bit)", - # Cent OS 5.3 (64 bit) - "lb_switch_wait": 10, - # Time interval after which LB switches the requests - "sleep": 60, - "timeout":10, - "network_offering": { - "name": 'Test Network offering', - "displaytext": 'Test Network offering', - "guestiptype": 'Isolated', - "supportedservices": 'Dhcp,Dns,SourceNat,PortForwarding', - "traffictype": 'GUEST', - "availability": 'Optional', - "serviceProviderList" : { - "Dhcp": 'VirtualRouter', - "Dns": 'VirtualRouter', - "SourceNat": 'VirtualRouter', - "PortForwarding": 'VirtualRouter', - }, - }, - "network": { - "name": "Test Network", - "displaytext": "Test Network", - }, - "service_offering": { - "name": "Tiny Instance", - "displaytext": "Tiny Instance", - "cpunumber": 1, - "cpuspeed": 100, - # in MHz - "memory": 256, - # In MBs - }, - "account": { - "email": "test@test.com", - "firstname": "Test", - "lastname": "User", - "username": "test", - "password": "password", - }, - "server": - { - "displayname": "Small Instance", - "username": "root", - "password": "password", - "hypervisor": 'XenServer', - "privateport": 22, - "publicport": 22, - "ssh_port": 22, - "protocol": 'TCP', - }, - "natrule": - { - "privateport": 22, - "publicport": 22, - "protocol": "TCP" - }, - "lbrule": - { - "name": "SSH", - "alg": "roundrobin", - # Algorithm used for load balancing - "privateport": 22, - "publicport": 2222, - "protocol": 'TCP' - } - } - class TestPublicIP(cloudstackTestCase): def setUp(self): self.apiclient = self.testClient.getApiClient() - self.services = Services().services @classmethod def setUpClass(cls): - cls.api_client = super(TestPublicIP, cls).getClsTestClient().getApiClient() - cls.services = Services().services + testClient = super(TestPublicIP, cls).getClsTestClient() + cls.apiclient = testClient.getApiClient() + cls.services = testClient.getParsedTestDataConfig() + # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.apiclient) + cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype # Create Accounts & networks cls.account = Account.create( - cls.api_client, + cls.apiclient, cls.services["account"], admin=True, domainid=cls.domain.id ) cls.user = Account.create( - cls.api_client, + cls.apiclient, cls.services["account"], domainid=cls.domain.id ) cls.services["network"]["zoneid"] = cls.zone.id cls.network_offering = NetworkOffering.create( - cls.api_client, + cls.apiclient, cls.services["network_offering"], ) # Enable Network offering - cls.network_offering.update(cls.api_client, state='Enabled') + cls.network_offering.update(cls.apiclient, state='Enabled') cls.services["network"]["networkoffering"] = cls.network_offering.id cls.account_network = Network.create( - cls.api_client, + cls.apiclient, cls.services["network"], cls.account.name, cls.account.domainid ) cls.user_network = Network.create( - cls.api_client, + cls.apiclient, cls.services["network"], cls.user.name, cls.user.domainid @@ -158,13 +86,13 @@ class TestPublicIP(cloudstackTestCase): # Create Source NAT IP addresses account_src_nat_ip = PublicIPAddress.create( - cls.api_client, + cls.apiclient, cls.account.name, cls.zone.id, cls.account.domainid ) user_src_nat_ip = PublicIPAddress.create( - cls.api_client, + cls.apiclient, cls.user.name, cls.zone.id, cls.user.domainid @@ -182,7 +110,7 @@ class TestPublicIP(cloudstackTestCase): def tearDownClass(cls): try: #Cleanup resources used - cleanup_resources(cls.api_client, cls._cleanup) + cleanup_resources(cls.apiclient, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) return @@ -223,6 +151,7 @@ class TestPublicIP(cloudstackTestCase): ) ip_address.delete(self.apiclient) + time.sleep(30) # Validate the following: # 1.listPublicIpAddresses should no more return the released address @@ -231,10 +160,15 @@ class TestPublicIP(cloudstackTestCase): id=ip_address.ipaddress.id ) self.assertEqual( - list_pub_ip_addr_resp, - None, - "Check if disassociated IP Address is no longer available" - ) + isinstance(list_pub_ip_addr_resp, list), + True, + "Check list response returns a valid list" + ) + self.assertEqual( + len(list_pub_ip_addr_resp), + 0, + "Check if the list public ip api response is not zero" + ) return @attr(tags = ["advanced", "advancedns", "smoke", "selfservice"]) @@ -293,32 +227,35 @@ class TestPortForwarding(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestPortForwarding, cls).getClsTestClient().getApiClient() - cls.services = Services().services - + testClient = super(TestPortForwarding, cls).getClsTestClient() + cls.apiclient = testClient.getApiClient() + cls.services = testClient.getParsedTestDataConfig() # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.apiclient) + cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests()) template = get_template( - cls.api_client, + cls.apiclient, cls.zone.id, cls.services["ostype"] ) + if template == FAILED: + assert False, "get_template() failed to return template with description %s" % cls.services["ostype"] + #Create an account, network, VM and IP addresses cls.account = Account.create( - cls.api_client, + cls.apiclient, cls.services["account"], admin=True, domainid=cls.domain.id ) - cls.services["server"]["zoneid"] = cls.zone.id + cls.services["virtual_machine"]["zoneid"] = cls.zone.id cls.service_offering = ServiceOffering.create( - cls.api_client, - cls.services["service_offering"] + cls.apiclient, + cls.services["service_offerings"] ) cls.virtual_machine = VirtualMachine.create( - cls.api_client, - cls.services["server"], + cls.apiclient, + cls.services["virtual_machine"], templateid=template.id, accountid=cls.account.name, domainid=cls.account.domainid, @@ -338,8 +275,8 @@ class TestPortForwarding(cloudstackTestCase): @classmethod def tearDownClass(cls): try: - cls.api_client = super(TestPortForwarding, cls).getClsTestClient().getApiClient() - cleanup_resources(cls.api_client, cls._cleanup) + cls.apiclient = super(TestPortForwarding, cls).getClsTestClient().getApiClient() + cleanup_resources(cls.apiclient, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) @@ -437,22 +374,27 @@ class TestPortForwarding(cloudstackTestCase): )) self.virtual_machine.get_ssh_client(src_nat_ip_addr.ipaddress) - + vm_response = VirtualMachine.list( + self.apiclient, + id=self.virtual_machine.id + ) + if vm_response[0].state != 'Running': + self.fail("State of VM : %s is not found to be Running" % str(self.virtual_machine.ipaddress)) + except Exception as e: self.fail( "SSH Access failed for %s: %s" % \ (self.virtual_machine.ipaddress, e) ) - nat_rule.delete(self.apiclient) - try: + nat_rule.delete(self.apiclient) list_nat_rule_response = list_nat_rules( self.apiclient, id=nat_rule.id ) - except cloudstackAPIException: - self.debug("Nat Rule is deleted") + except CloudstackAPIException: + self.fail("Nat Rule Deletion or Listing Failed") # Check if the Public SSH port is inaccessible with self.assertRaises(Exception): @@ -464,9 +406,7 @@ class TestPortForwarding(cloudstackTestCase): src_nat_ip_addr.ipaddress, self.virtual_machine.ssh_port, self.virtual_machine.username, - self.virtual_machine.password, - retries=2, - delay=0 + self.virtual_machine.password ) return @@ -483,7 +423,7 @@ class TestPortForwarding(cloudstackTestCase): self.account.name, self.zone.id, self.account.domainid, - self.services["server"] + self.services["virtual_machine"] ) self.cleanup.append(ip_address) @@ -569,7 +509,7 @@ class TestPortForwarding(cloudstackTestCase): self.apiclient, id=nat_rule.id ) - except cloudstackAPIException: + except CloudstackAPIException: self.debug("Nat Rule is deleted") # Check if the Public SSH port is inaccessible @@ -596,17 +536,19 @@ class TestRebootRouter(cloudstackTestCase): def setUp(self): self.apiclient = self.testClient.getApiClient() - self.services = Services().services + self.services = self.testClient.getParsedTestDataConfig() # Get Zone, Domain and templates - self.domain = get_domain(self.apiclient, self.services) - self.zone = get_zone(self.apiclient, self.services) + self.domain = get_domain(self.apiclient) + self.zone = get_zone(self.apiclient, self.testClient.getZoneForTests()) template = get_template( self.apiclient, self.zone.id, self.services["ostype"] ) - self.services["server"]["zoneid"] = self.zone.id + if template == FAILED: + self.fail("get_template() failed to return template with description %s" % self.services["ostype"]) + self.services["virtual_machine"]["zoneid"] = self.zone.id #Create an account, network, VM and IP addresses self.account = Account.create( @@ -617,11 +559,11 @@ class TestRebootRouter(cloudstackTestCase): ) self.service_offering = ServiceOffering.create( self.apiclient, - self.services["service_offering"] + self.services["service_offerings"] ) self.vm_1 = VirtualMachine.create( self.apiclient, - self.services["server"], + self.services["virtual_machine"], templateid=template.id, accountid=self.account.name, domainid=self.account.domainid, @@ -646,7 +588,7 @@ class TestRebootRouter(cloudstackTestCase): self.vm_1.account, self.vm_1.zoneid, self.vm_1.domainid, - self.services["server"] + self.services["virtual_machine"] ) #Open up firewall port for SSH fw_rule = FireWallRule.create( @@ -762,17 +704,17 @@ class TestReleaseIP(cloudstackTestCase): def setUp(self): self.apiclient = self.testClient.getApiClient() - self.services = Services().services + self.services = self.testClient.getParsedTestDataConfig() # Get Zone, Domain and templates - self.domain = get_domain(self.apiclient, self.services) - self.zone = get_zone(self.apiclient, self.services) + self.domain = get_domain(self.apiclient) + self.zone = get_zone(self.apiclient, self.testClient.getZoneForTests()) template = get_template( self.apiclient, self.zone.id, self.services["ostype"] ) - self.services["server"]["zoneid"] = self.zone.id + self.services["virtual_machine"]["zoneid"] = self.zone.id #Create an account, network, VM, Port forwarding rule, LB rules self.account = Account.create( @@ -784,12 +726,12 @@ class TestReleaseIP(cloudstackTestCase): self.service_offering = ServiceOffering.create( self.apiclient, - self.services["service_offering"] + self.services["service_offerings"] ) self.virtual_machine = VirtualMachine.create( self.apiclient, - self.services["server"], + self.services["virtual_machine"], templateid=template.id, accountid=self.account.name, domainid=self.account.domainid, @@ -867,7 +809,7 @@ class TestReleaseIP(cloudstackTestCase): id=self.nat_rule.id ) self.debug("List NAT Rule response" + str(list_nat_rule)) - except cloudstackAPIException: + except CloudstackAPIException: self.debug("Port Forwarding Rule is deleted") # listLoadBalancerRules should not list @@ -878,7 +820,7 @@ class TestReleaseIP(cloudstackTestCase): id=self.lb_rule.id ) self.debug("List LB Rule response" + str(list_lb_rule)) - except cloudstackAPIException: + except CloudstackAPIException: self.debug("Port Forwarding Rule is deleted") # SSH Attempt though public IP should fail @@ -899,17 +841,17 @@ class TestDeleteAccount(cloudstackTestCase): def setUp(self): self.apiclient = self.testClient.getApiClient() - self.services = Services().services + self.services = self.testClient.getParsedTestDataConfig() # Get Zone, Domain and templates - self.domain = get_domain(self.apiclient, self.services) - self.zone = get_zone(self.apiclient, self.services) + self.domain = get_domain(self.apiclient) + self.zone = get_zone(self.apiclient, self.testClient.getZoneForTests()) template = get_template( self.apiclient, self.zone.id, self.services["ostype"] ) - self.services["server"]["zoneid"] = self.zone.id + self.services["virtual_machine"]["zoneid"] = self.zone.id #Create an account, network, VM and IP addresses self.account = Account.create( @@ -920,11 +862,11 @@ class TestDeleteAccount(cloudstackTestCase): ) self.service_offering = ServiceOffering.create( self.apiclient, - self.services["service_offering"] + self.services["service_offerings"] ) self.vm_1 = VirtualMachine.create( self.apiclient, - self.services["server"], + self.services["virtual_machine"], templateid=template.id, accountid=self.account.name, domainid=self.account.domainid, @@ -993,7 +935,7 @@ class TestDeleteAccount(cloudstackTestCase): account=self.account.name, domainid=self.account.domainid ) - except cloudstackAPIException: + except CloudstackAPIException: self.debug("Port Forwarding Rule is deleted") # ListPortForwardingRules should not @@ -1004,7 +946,7 @@ class TestDeleteAccount(cloudstackTestCase): account=self.account.name, domainid=self.account.domainid ) - except cloudstackAPIException: + except CloudstackAPIException: self.debug("NATRule is deleted") #Retrieve router for the user account @@ -1019,7 +961,7 @@ class TestDeleteAccount(cloudstackTestCase): None, "Check routers are properly deleted." ) - except cloudstackAPIException: + except CloudstackAPIException: self.debug("Router is deleted") except Exception as e: diff --git a/test/integration/smoke/test_network_acl.py b/test/integration/smoke/test_network_acl.py index 69134e565c5..68e5067da8f 100644 --- a/test/integration/smoke/test_network_acl.py +++ b/test/integration/smoke/test_network_acl.py @@ -17,77 +17,27 @@ """ Tests for Network ACLs in VPC """ #Import Local Modules +from marvin.codes import FAILED from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * from nose.plugins.attrib import attr -class Services: - def __init__(self): - self.services = { - "account": { - "email": "test@test.com", - "firstname": "Test", - "lastname": "User", - "username": "test", - "password": "password", - }, - "virtual_machine": { - "displayname": "Test VM", - "username": "root", - "password": "password", - "ssh_port": 22, - "hypervisor": 'XenServer', - "privateport": 22, - "publicport": 22, - "protocol": 'TCP', - }, - "ostype": 'CentOS 5.3 (64-bit)', - "service_offering": { - "name": "Tiny Instance", - "displaytext": "Tiny Instance", - "cpunumber": 1, - "cpuspeed": 100, - "memory": 256, - }, - "network_offering": { - "name": "Network offering for internal lb service", - "displaytext": "Network offering for internal lb service", - "guestiptype": "Isolated", - "traffictype": "Guest", - "supportedservices": "Vpn,Dhcp,Dns,Lb,UserData,SourceNat,StaticNat,PortForwarding,NetworkACL", - "serviceProviderList": { - "Dhcp": "VpcVirtualRouter", - "Dns": "VpcVirtualRouter", - "Vpn": "VpcVirtualRouter", - "UserData": "VpcVirtualRouter", - "Lb": "InternalLbVM", - "SourceNat": "VpcVirtualRouter", - "StaticNat": "VpcVirtualRouter", - "PortForwarding": "VpcVirtualRouter", - "NetworkACL": "VpcVirtualRouter", - }, - "serviceCapabilityList": { - "SourceNat": {"SupportedSourceNatTypes": "peraccount"}, - "Lb": {"lbSchemes": "internal", "SupportedLbIsolation": "dedicated"} - } - } - } - - class TestNetworkACL(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.apiclient = super(TestNetworkACL, cls).getClsTestClient().getApiClient() - cls.services = Services().services - cls.zone = get_zone(cls.apiclient, cls.services) + testClient = super(TestNetworkACL, cls).getClsTestClient() + cls.apiclient = testClient.getApiClient() + cls.services = testClient.getParsedTestDataConfig() + + cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests()) cls.domain = get_domain(cls.apiclient) cls.service_offering = ServiceOffering.create( cls.apiclient, - cls.services["service_offering"] + cls.services["service_offerings"] ) cls.account = Account.create(cls.apiclient, services=cls.services["account"]) cls.template = get_template( @@ -95,6 +45,10 @@ class TestNetworkACL(cloudstackTestCase): cls.zone.id, cls.services["ostype"] ) + + if cls.template == FAILED: + assert False, "get_template() failed to return template with description %s" % cls.services["ostype"] + cls.debug("Successfully created account: %s, id: \ %s" % (cls.account.name,\ cls.account.id)) diff --git a/test/integration/smoke/test_nic.py b/test/integration/smoke/test_nic.py index 9b29403b355..e12bb33b607 100644 --- a/test/integration/smoke/test_nic.py +++ b/test/integration/smoke/test_nic.py @@ -16,119 +16,19 @@ # under the License. """ NIC tests for VM """ import marvin +from marvin.codes import FAILED from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * from marvin.sshClient import SshClient -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * from nose.plugins.attrib import attr import signal import sys import time -class Services: - def __init__(self): - self.services = { - "disk_offering":{ - "displaytext": "Small", - "name": "Small", - "disksize": 1 - }, - "account": { - "email": "test@test.com", - "firstname": "Test", - "lastname": "User", - "username": "test", - # Random characters are appended in create account to - # ensure unique username generated each time - "password": "password", - }, - # Create a small virtual machine instance with disk offering - "small": { - "displayname": "testserver", - "username": "root", # VM creds for SSH - "password": "password", - "ssh_port": 22, - "hypervisor": 'XenServer', - "privateport": 22, - "publicport": 22, - "protocol": 'TCP', - }, - "service_offerings": { - "tiny": { - "name": "Tiny Instance", - "displaytext": "Tiny Instance", - "cpunumber": 1, - "cpuspeed": 100, # in MHz - "memory": 128, # In MBs - }, - }, - "network_offering": { - "name": 'Test Network offering', - "displaytext": 'Test Network offering', - "guestiptype": 'Isolated', - "supportedservices": 'Dhcp,Dns,SourceNat,PortForwarding', - "traffictype": 'GUEST', - "availability": 'Optional', - "serviceProviderList" : { - "Dhcp": 'VirtualRouter', - "Dns": 'VirtualRouter', - "SourceNat": 'VirtualRouter', - "PortForwarding": 'VirtualRouter', - }, - }, - "network_offering_shared": { - "name": 'Test Network offering shared', - "displaytext": 'Test Network offering Shared', - "guestiptype": 'Shared', - "supportedservices": 'Dhcp,Dns,UserData', - "traffictype": 'GUEST', - "specifyVlan" : "True", - "specifyIpRanges" : "True", - "serviceProviderList" : { - "Dhcp": 'VirtualRouter', - "Dns": 'VirtualRouter', - "UserData": 'VirtualRouter', - }, - }, - "network": { - "name": "Test Network", - "displaytext": "Test Network", - "acltype": "Account", - }, - "network2": { - "name": "Test Network Shared", - "displaytext": "Test Network Shared", - "vlan" :1201, - "gateway" :"172.16.15.1", - "netmask" :"255.255.255.0", - "startip" :"172.16.15.21", - "endip" :"172.16.15.41", - "acltype": "Account", - }, - # ISO settings for Attach/Detach ISO tests - "iso": { - "displaytext": "Test ISO", - "name": "testISO", - "url": "http://people.apache.org/~tsp/dummy.iso", - # Source URL where ISO is located - "ostype": 'CentOS 5.3 (64-bit)', - "mode": 'HTTP_DOWNLOAD', # Downloading existing ISO - }, - "template": { - "displaytext": "Cent OS Template", - "name": "Cent OS Template", - "passwordenabled": True, - }, - "sleep": 60, - "timeout": 10, - #Migrate VM to hostid - "ostype": 'CentOS 5.3 (64-bit)', - # CentOS 5.3 (64-bit) - } - class TestNic(cloudstackTestCase): def setUp(self): @@ -143,11 +43,11 @@ class TestNic(cloudstackTestCase): try: self.apiclient = self.testClient.getApiClient() self.dbclient = self.testClient.getDbConnection() - self.services = Services().services + self.services = self.testClient.getParsedTestDataConfig() # Get Zone, Domain and templates - domain = get_domain(self.apiclient, self.services) - zone = get_zone(self.apiclient, self.services) + domain = get_domain(self.apiclient) + zone = get_zone(self.apiclient, self.testClient.getZoneForTests()) self.services['mode'] = zone.networktype #if local storage is enabled, alter the offerings to use localstorage @@ -164,7 +64,7 @@ class TestNic(cloudstackTestCase): self.services["small"]["zoneid"] = zone.id self.services["small"]["template"] = template.id - self.services["iso"]["zoneid"] = zone.id + self.services["iso1"]["zoneid"] = zone.id self.services["network"]["zoneid"] = zone.id # Create Account, VMs, NAT Rules etc @@ -219,7 +119,7 @@ class TestNic(cloudstackTestCase): except Exception as ex: self.debug("Exception during NIC test SETUP!: " + str(ex)) - @attr(tags = ["devcloud", "advanced", "advancedns", "smoke", "basic", "sg", "provisioning"]) + @attr(tags = ["devcloud", "smoke", "basic", "sg", "provisioning"]) def test_01_nic(self): #TODO: SIMENH: add validation """Test to add and update added nic to a virtual machine""" diff --git a/test/integration/smoke/test_non_contigiousvlan.py b/test/integration/smoke/test_non_contigiousvlan.py index d21391eec39..90235ecd2c1 100644 --- a/test/integration/smoke/test_non_contigiousvlan.py +++ b/test/integration/smoke/test_non_contigiousvlan.py @@ -18,8 +18,8 @@ from marvin import cloudstackTestCase from marvin.cloudstackAPI import * from marvin.cloudstackTestCase import cloudstackTestCase -from marvin.integration.lib.base import Account -from marvin.integration.lib.base import PhysicalNetwork +from marvin.lib.base import Account +from marvin.lib.base import PhysicalNetwork from nose.plugins.attrib import attr class Services(): diff --git a/test/integration/smoke/test_over_provisioning.py b/test/integration/smoke/test_over_provisioning.py index 7d10fc77e85..1c5d8a520f6 100644 --- a/test/integration/smoke/test_over_provisioning.py +++ b/test/integration/smoke/test_over_provisioning.py @@ -19,9 +19,9 @@ #Import Local Modules from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common 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 @@ -67,7 +67,11 @@ class TestUpdateOverProvision(cloudstackTestCase): self.poolId = pool.id """ list overprovisioning factor for storage pool """ - factorOld = float(pool.overprovisionfactor) + failed = 0 + if pool.overprovisionfactor is None: + failed = 1 + self.assertNotEqual(failed,1,"pool.overprovisionfactor is none") + factorOld = float(str(pool.overprovisionfactor)) factorNew = str(factorOld + 1.0) """ update setting for the pool""" @@ -85,7 +89,11 @@ class TestUpdateOverProvision(cloudstackTestCase): id = self.poolId ) pool = storage_pools[0] - factorNew = float(pool.overprovisionfactor) + failed = 0 + if pool.overprovisionfactor is None: + failed = 1 + self.assertNotEqual(failed,1,"pool.overprovisionfactor is none") + factorNew = float(str(pool.overprovisionfactor)) self.assertNotEqual(int(factorNew), int(factorOld)," Check if overprovision factor of storage pool has changed") self.assertEqual(int(factorNew), int(factorOld + 1.0)," Check if overprovision factor of storage pool has increased by 1") @@ -100,8 +108,11 @@ class TestUpdateOverProvision(cloudstackTestCase): pool = storage_pools[0] updateConfigurationCmd = updateConfiguration.updateConfigurationCmd() updateConfigurationCmd.name = "storage.overprovisioning.factor" - factorOld = float(pool.overprovisionfactor) + factorOld = 0 + if pool.overprovisionfactor is not None: + factorOld = float(str(pool.overprovisionfactor)) factorNew = str(factorOld - 1.0) - updateConfigurationCmd.value = factorNew - updateConfigurationCmd.storageid = pool.id - updateConfigurationResponse = self.apiClient.updateConfiguration(updateConfigurationCmd) + if factorNew > 0: + updateConfigurationCmd.value = factorNew + updateConfigurationCmd.storageid = pool.id + updateConfigurationResponse = self.apiClient.updateConfiguration(updateConfigurationCmd) diff --git a/test/integration/smoke/test_portable_publicip.py b/test/integration/smoke/test_portable_publicip.py index efbd4836c6b..2d02a7114e5 100644 --- a/test/integration/smoke/test_portable_publicip.py +++ b/test/integration/smoke/test_portable_publicip.py @@ -18,73 +18,11 @@ from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * from nose.plugins.attrib import attr -class Services: - """Test Data - """ - - def __init__(self): - self.services = { - "domain": { - "name": "Domain", - }, - "account": { - "email": "test@test.com", - "firstname": "Test", - "lastname": "User", - "username": "test", - # Random characters are appended for unique - # username - "password": "password", - }, - "service_offering": { - "name": "Tiny Instance", - "displaytext": "Tiny Instance", - "cpunumber": 1, - "cpuspeed": 100, - # in MHz - "memory": 128, - # In MBs - }, - "network_offering": { - "name": 'Test Network offering', - "displaytext": 'Test Network offering', - "guestiptype": 'Isolated', - "supportedservices": 'Dhcp,Dns,SourceNat,PortForwarding', - "traffictype": 'GUEST', - "availability": 'Optional', - "serviceProviderList" : { - "Dhcp": 'VirtualRouter', - "Dns": 'VirtualRouter', - "SourceNat": 'VirtualRouter', - "PortForwarding": 'VirtualRouter', - }, - }, - "network": { - "name": "Test Network", - "displaytext": "Test Network", - }, - "ostype": 'CentOS 5.3 (64-bit)', - "gateway" : "172.1.1.1", - "netmask" : "255.255.255.0", - "startip" : "172.1.1.10", - "endip" : "172.1.1.20", - "regionid" : "1", - "vlan" :"10", - "isportable" : "true", - "virtual_machine" : { - "affinity": { - "name": "webvms", - "type": "host anti-affinity", - }, - "hypervisor" : "XenServer", - } - } - class TestPortablePublicIPRange(cloudstackTestCase): """ @@ -95,15 +33,17 @@ class TestPortablePublicIPRange(cloudstackTestCase): """ @classmethod def setUpClass(cls): - cls.api_client = super(TestPortablePublicIPRange, cls).getClsTestClient().getApiClient() - cls.services = Services().services + testClient = super(TestPortablePublicIPRange, cls).getClsTestClient() + cls.apiclient = testClient.getApiClient() + cls.services = testClient.getParsedTestDataConfig() + # Get Zone, Domain - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.apiclient) + cls.zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests()) # Create Account cls.account = Account.create( - cls.api_client, + cls.apiclient, cls.services["account"], domainid=cls.domain.id ) @@ -116,7 +56,7 @@ class TestPortablePublicIPRange(cloudstackTestCase): def tearDownClass(cls): try: # Cleanup resources used - cleanup_resources(cls.api_client, cls._cleanup) + cleanup_resources(cls.apiclient, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) return @@ -141,7 +81,7 @@ class TestPortablePublicIPRange(cloudstackTestCase): """ self.debug("attempting to create a portable Public IP range") self.portable_ip_range = PortablePublicIpRange.create( - self.api_client, + self.apiclient, self.services ) self.debug("attempting to verify portable Public IP range is created") @@ -161,29 +101,31 @@ class TestPortablePublicIPAcquire(cloudstackTestCase): """ @classmethod def setUpClass(cls): - cls.api_client = super(TestPortablePublicIPAcquire, cls).getClsTestClient().getApiClient() - cls.services = Services().services + testClient = super(TestPortablePublicIPAcquire, cls).getClsTestClient() + cls.apiclient = testClient.getApiClient() + cls.services = testClient.getParsedTestDataConfig() + # Get Zone, Domain - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.apiclient) + cls.zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests()) # Create Account cls.account = Account.create( - cls.api_client, + cls.apiclient, cls.services["account"], domainid=cls.domain.id ) cls.services["network"]["zoneid"] = cls.zone.id cls.network_offering = NetworkOffering.create( - cls.api_client, + cls.apiclient, cls.services["network_offering"], ) # Enable Network offering - cls.network_offering.update(cls.api_client, state='Enabled') + cls.network_offering.update(cls.apiclient, state='Enabled') cls.services["network"]["networkoffering"] = cls.network_offering.id cls.account_network = Network.create( - cls.api_client, + cls.apiclient, cls.services["network"], cls.account.name, cls.account.domainid @@ -200,7 +142,7 @@ class TestPortablePublicIPAcquire(cloudstackTestCase): def tearDownClass(cls): try: # Cleanup resources used - cleanup_resources(cls.api_client, cls._cleanup) + cleanup_resources(cls.apiclient, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) return @@ -225,13 +167,13 @@ class TestPortablePublicIPAcquire(cloudstackTestCase): """ self.debug("attempting to create a portable Public IP range") self.portable_ip_range = PortablePublicIpRange.create( - self.api_client, + self.apiclient, self.services ) - ip_address = PublicIPAddress.create(self.api_client, self.account.name, + ip_address = PublicIPAddress.create(self.apiclient, self.account.name, self.zone.id, self.account.domainid, isportable=True) - ip_address.delete(self.api_client) + ip_address.delete(self.apiclient) self.portable_ip_range.delete(self.apiclient) return diff --git a/test/integration/smoke/test_primary_storage.py b/test/integration/smoke/test_primary_storage.py index f102078260f..3c1aa622d02 100644 --- a/test/integration/smoke/test_primary_storage.py +++ b/test/integration/smoke/test_primary_storage.py @@ -20,43 +20,24 @@ import marvin from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common 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 Services: - """Test Primary storage Services - """ - - def __init__(self): - self.services = { - "nfs": - { - "url": "nfs://10.147.28.7/export/home/talluri/testprimary", - # Format: File_System_Type/Location/Path - "name": "Primary XEN" - }, - "iscsi": { - "url": "iscsi://192.168.100.21/iqn.2012-01.localdomain.clo-cstack-cos6:iser/1", - # Format : iscsi://IP Address/IQN number/LUN# - "name": "Primary iSCSI" - } - } - class TestPrimaryStorageServices(cloudstackTestCase): def setUp(self): self.apiclient = self.testClient.getApiClient() - self.services = Services().services + self.services = self.testClient.getParsedTestDataConfig() self.cleanup = [] # Get Zone and pod - self.zone = get_zone(self.apiclient, self.services) + self.zone = get_zone(self.apiclient, self.testClient.getZoneForTests()) self.pod = get_pod(self.apiclient, self.zone.id) return @@ -218,7 +199,7 @@ class TestPrimaryStorageServices(cloudstackTestCase): self.assertEqual( storage.type, - 'NetworkFilesystem', + 'IscsiLUN', "Check storage pool type " ) diff --git a/test/integration/smoke/test_privategw_acl.py b/test/integration/smoke/test_privategw_acl.py index ec5ef8b60c3..8d207705b45 100644 --- a/test/integration/smoke/test_privategw_acl.py +++ b/test/integration/smoke/test_privategw_acl.py @@ -19,9 +19,9 @@ #Import Local Modules from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * from nose.plugins.attrib import attr diff --git a/test/integration/smoke/test_public_ip_range.py b/test/integration/smoke/test_public_ip_range.py index 759e1077992..b961dc34773 100644 --- a/test/integration/smoke/test_public_ip_range.py +++ b/test/integration/smoke/test_public_ip_range.py @@ -21,50 +21,26 @@ import marvin from nose.plugins.attrib import attr from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * import datetime -class Services: - """Test Dedicating Public IP addresses - """ - - def __init__(self): - self.services = { - "domain": { - "name": "Domain", - }, - "account": { - "email": "test@test.com", - "firstname": "Test", - "lastname": "User", - "username": "test", - "password": "password", - }, - "gateway": "10.102.197.1", - "netmask": "255.255.255.0", - "forvirtualnetwork": "true", - "startip": "10.102.197.70", - "endip": "10.102.197.73", - "zoneid": "1", - "podid": "", - "vlan": "4444", - } - class TestDedicatePublicIPRange(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestDedicatePublicIPRange, cls).getClsTestClient().getApiClient() - cls.services = Services().services + cls.testClient = super(TestDedicatePublicIPRange, cls).getClsTestClient() + cls.apiclient = cls.testClient.getApiClient() + cls.services = cls.testClient.getParsedTestDataConfig() # Get Zone, Domain - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) - + cls.domain = get_domain(cls.apiclient) + cls.zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests()) + cls.services["zoneid"] = cls.zone.id + cls.pod = get_pod(cls.apiclient, cls.zone.id) # Create Account cls.account = Account.create( - cls.api_client, + cls.apiclient, cls.services["account"], domainid=cls.domain.id ) @@ -77,7 +53,7 @@ class TestDedicatePublicIPRange(cloudstackTestCase): def tearDownClass(cls): try: # Cleanup resources used - cleanup_resources(cls.api_client, cls._cleanup) + cleanup_resources(cls.apiclient, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) return @@ -112,7 +88,7 @@ class TestDedicatePublicIPRange(cloudstackTestCase): self.debug("Creating Public IP range") self.public_ip_range = PublicIpRange.create( - self.api_client, + self.apiclient, self.services ) list_public_ip_range_response = PublicIpRange.list( diff --git a/test/integration/smoke/test_pvlan.py b/test/integration/smoke/test_pvlan.py index 38afd41bd90..a1c146b09a0 100644 --- a/test/integration/smoke/test_pvlan.py +++ b/test/integration/smoke/test_pvlan.py @@ -21,9 +21,9 @@ import marvin from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * from marvin.sshClient import SshClient -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * from nose.plugins.attrib import attr import telnetlib @@ -80,12 +80,6 @@ class TestPVLAN(cloudstackTestCase): createNetworkCmd.ip6cidr="fc00:1234::/64" createNetworkCmd.startipv6="fc00:1234::10" createNetworkCmd.endipv6="fc00:1234::20" - err = 0; - try: - createNetworkResponse = self.apiClient.createNetwork(createNetworkCmd) - except Exception as e: - err = 1; - self.debug("Try alloc with ipv6, got:%s" % e) - self.assertEqual(err, 1, "Shouldn't allow create PVLAN network with IPv6"); - - + err = 0 + createNetworkResponse = self.apiClient.createNetwork(createNetworkCmd) + self.assertEqual(createNetworkResponse, FAILED, "Creating PVLAN with IPv6 should fail") diff --git a/test/integration/smoke/test_regions.py b/test/integration/smoke/test_regions.py index 71900b4a6b1..389f8787563 100644 --- a/test/integration/smoke/test_regions.py +++ b/test/integration/smoke/test_regions.py @@ -17,42 +17,33 @@ from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * from nose.plugins.attrib import attr -class Services: - def __init__(self): - self.services = { - "region": { - "regionid": "2", - "regionname": "Region2", - "regionendpoint": "http://region2:8080/client" - } - } - - class TestRegions(cloudstackTestCase): """Test Regions - basic region creation """ @classmethod def setUpClass(cls): - cls.api_client = super(TestRegions, cls).getClsTestClient().getApiClient() - cls.services = Services().services - cls.domain = get_domain(cls.api_client, cls.services) + testClient = super(TestRegions, cls).getClsTestClient() + cls.apiclient = testClient.getApiClient() + cls.services = testClient.getParsedTestDataConfig() + + cls.domain = get_domain(cls.apiclient) cls.cleanup = [] @attr(tags=["simulator", "basic", "advanced", "selfservice"]) def test_createRegion(self): """ Test for create region """ - region = Region.create(self.api_client, + region = Region.create(self.apiclient, self.services["region"] ) - list_region = Region.list(self.api_client, + list_region = Region.list(self.apiclient, id=self.services["region"]["regionid"] ) @@ -86,8 +77,8 @@ class TestRegions(cloudstackTestCase): def tearDownClass(cls): try: #Clean up - cleanup_resources(cls.api_client, cls.cleanup) - list_region = Region.list(cls.api_client, id=cls.services["region"]["regionid"]) + cleanup_resources(cls.apiclient, cls.cleanup) + list_region = Region.list(cls.apiclient, id=cls.services["region"]["regionid"]) assert list_region is None, "Region deletion fails" except Exception as e: - raise Exception("Warning: Region cleanup/delete fails with : %s" % e) \ No newline at end of file + raise Exception("Warning: Region cleanup/delete fails with : %s" % e) diff --git a/test/integration/smoke/test_reset_vm_on_reboot.py b/test/integration/smoke/test_reset_vm_on_reboot.py index 6cb63e36478..4709df4d093 100644 --- a/test/integration/smoke/test_reset_vm_on_reboot.py +++ b/test/integration/smoke/test_reset_vm_on_reboot.py @@ -18,106 +18,56 @@ """ #Import Local Modules import marvin +from marvin.codes import FAILED from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * from nose.plugins.attrib import attr _multiprocess_shared_ = True -class Services: - """Test VM Life Cycle Services - """ - - def __init__(self): - self.services = { - - "account": { - "email": "test@test.com", - "firstname": "Test", - "lastname": "User", - "username": "test", - # Random characters are appended in create account to - # ensure unique username generated each time - "password": "password", - }, - "small": - # Create a small virtual machine instance with disk offering - { - "displayname": "testserver", - "username": "root", # VM creds for SSH - "password": "password", - "ssh_port": 22, - "hypervisor": 'XenServer', - "privateport": 22, - "publicport": 22, - "protocol": 'TCP', - }, - "service_offerings": - { - "small": - { - # Small service offering ID to for change VM - # service offering from medium to small - "name": "SmallInstance_volatile", - "displaytext": "SmallInstance_volatile", - "cpunumber": 1, - "cpuspeed": 100, - "memory": 256, - }, - }, - #Change this - "template": { - "displaytext": "xs", - "name": "xs", - "passwordenabled": False, - }, - "sleep": 60, - "timeout": 10, - #Migrate VM to hostid - "ostype": 'CentOS 5.3 (64-bit)', - # CentOS 5.3 (64-bit) - } - - class TestResetVmOnReboot(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestResetVmOnReboot, cls).getClsTestClient().getApiClient() - cls.services = Services().services + testClient = super(TestResetVmOnReboot, cls).getClsTestClient() + cls.apiclient = testClient.getApiClient() + cls.services = testClient.getParsedTestDataConfig() # Get Zone, Domain and templates - domain = get_domain(cls.api_client, cls.services) - zone = get_zone(cls.api_client, cls.services) + domain = get_domain(cls.apiclient) + zone = get_zone(cls.apiclient, testClient.getZoneForTests()) cls.services['mode'] = zone.networktype template = get_template( - cls.api_client, + cls.apiclient, zone.id, cls.services["ostype"] ) + if template == FAILED: + assert False, "get_template() failed to return template with description %s" % cls.services["ostype"] + # Set Zones and disk offerings ?? cls.services["small"]["zoneid"] = zone.id cls.services["small"]["template"] = template.id # Create account, service offerings, vm. cls.account = Account.create( - cls.api_client, + cls.apiclient, cls.services["account"], domainid=domain.id ) cls.small_offering = ServiceOffering.create( - cls.api_client, + cls.apiclient, cls.services["service_offerings"]["small"], isvolatile="true" ) #create a virtual machine cls.virtual_machine = VirtualMachine.create( - cls.api_client, + cls.apiclient, cls.services["small"], accountid=cls.account.name, domainid=cls.account.domainid, @@ -131,8 +81,8 @@ class TestResetVmOnReboot(cloudstackTestCase): @classmethod def tearDownClass(cls): - cls.api_client = super(TestResetVmOnReboot, cls).getClsTestClient().getApiClient() - cleanup_resources(cls.api_client, cls._cleanup) + cls.apiclient = super(TestResetVmOnReboot, cls).getClsTestClient().getApiClient() + cleanup_resources(cls.apiclient, cls._cleanup) return def setUp(self): diff --git a/test/integration/smoke/test_resource_detail.py b/test/integration/smoke/test_resource_detail.py index a0cac9b21b0..7f4a6e76869 100644 --- a/test/integration/smoke/test_resource_detail.py +++ b/test/integration/smoke/test_resource_detail.py @@ -21,113 +21,46 @@ import marvin from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * from marvin.sshClient import SshClient -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common 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 Services: - """Test VM Life Cycle Services - """ - - def __init__(self): - self.services = { - - "account": { - "email": "test@test.com", - "firstname": "Test", - "lastname": "User", - "username": "test", - # Random characters are appended in create account to - # ensure unique username generated each time - "password": "password", - }, - "small": - # Create a small virtual machine instance with disk offering - { - "displayname": "testserver", - "username": "root", # VM creds for SSH - "password": "password", - "ssh_port": 22, - "hypervisor": 'XenServer', - "privateport": 22, - "publicport": 22, - "protocol": 'TCP', - }, - "disk_offering": { - "displaytext": "Small", - "name": "Small", - "storagetype": "shared", - "disksize": 1 - }, - "service_offerings": - { - "small": - { - # Small service offering ID to for change VM - # service offering from medium to small - "name": "SmallInstance", - "displaytext": "SmallInstance", - "cpunumber": 1, - "cpuspeed": 100, - "memory": 256, - }, - "big": - { - # Big service offering ID to for change VM - "name": "BigInstance", - "displaytext": "BigInstance", - "cpunumber": 1, - "cpuspeed": 100, - "memory": 512, - } - }, - #Change this - "template": { - "displaytext": "xs", - "name": "xs", - "passwordenabled": False, - }, - "sleep": 60, - "timeout": 10, - #Migrate VM to hostid - "ostype": 'CentOS 5.6 (64-bit)', - # CentOS 5.3 (64-bit) - } class TestResourceDetail(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestResourceDetail, cls).getClsTestClient().getApiClient() - cls.services = Services().services + testClient = super(TestResourceDetail, cls).getClsTestClient() + cls.apiclient = testClient.getApiClient() + cls.services = testClient.getParsedTestDataConfig() # Get Zone, Domain and templates - domain = get_domain(cls.api_client, cls.services) - zone = get_zone(cls.api_client, cls.services) + domain = get_domain(cls.apiclient) + zone = get_zone(cls.apiclient, testClient.getZoneForTests()) cls.services['mode'] = zone.networktype # Set Zones and disk offerings ?? # Create account, service offerings, vm. cls.account = Account.create( - cls.api_client, + cls.apiclient, cls.services["account"], domainid=domain.id ) cls.disk_offering = DiskOffering.create( - cls.api_client, + cls.apiclient, cls.services["disk_offering"] ) #create a volume cls.volume = Volume.create( - cls.api_client, + cls.apiclient, { "diskname" : "ndm"}, zoneid=zone.id, account=cls.account.name, @@ -142,8 +75,8 @@ class TestResourceDetail(cloudstackTestCase): @classmethod def tearDownClass(cls): - cls.api_client = super(TestResourceDetail, cls).getClsTestClient().getApiClient() - cleanup_resources(cls.api_client, cls._cleanup) + cls.apiclient = super(TestResourceDetail, cls).getClsTestClient().getApiClient() + cleanup_resources(cls.apiclient, cls._cleanup) return def setUp(self): @@ -175,7 +108,7 @@ class TestResourceDetail(cloudstackTestCase): listResourceDetailCmd = listResourceDetails.listResourceDetailsCmd() listResourceDetailCmd.resourceid = self.volume.id listResourceDetailCmd.resourcetype = "Volume" - listResourceDetailResponse = self.api_client.listResourceDetails(listResourceDetailCmd) + listResourceDetailResponse = self.apiclient.listResourceDetails(listResourceDetailCmd) self.assertEqual(listResourceDetailResponse, None, "Check if the list API \ returns an empty response") diff --git a/test/integration/smoke/test_routers.py b/test/integration/smoke/test_routers.py index 2bd1d5ecfd3..2aa83c32c6a 100644 --- a/test/integration/smoke/test_routers.py +++ b/test/integration/smoke/test_routers.py @@ -18,88 +18,55 @@ """ #Import Local Modules import marvin +from marvin.codes import FAILED from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * from marvin.sshClient import SshClient -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common 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 Services: - """Test router Services - """ - - def __init__(self): - self.services = { - "service_offering": { - "name": "Tiny Instance", - "displaytext": "Tiny Instance", - "cpunumber": 1, - "cpuspeed": 100, # in MHz - "memory": 128, # In MBs - }, - "virtual_machine": - { - "displayname": "Test VM", - "username": "root", - "password": "password", - "ssh_port": 22, - "hypervisor": 'XenServer', - "privateport": 22, - "publicport": 22, - "protocol": 'TCP', - }, - "account": { - "email": "test@test.com", - "firstname": "Test", - "lastname": "User", - "username": "testuser", - "password": "password", - }, - "ostype": "CentOS 5.3 (64-bit)", - "sleep": 60, - "timeout": 10, - } - class TestRouterServices(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super( - TestRouterServices, - cls - ).getClsTestClient().getApiClient() - cls.services = Services().services + testClient = super(TestRouterServices, cls).getClsTestClient() + cls.apiclient = testClient.getApiClient() + cls.services = testClient.getParsedTestDataConfig() + # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.apiclient) + cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype template = get_template( - cls.api_client, + cls.apiclient, cls.zone.id, cls.services["ostype"] ) + if template == FAILED: + cls.fail("get_template() failed to return template with description %s" % cls.services["ostype"]) + cls.services["virtual_machine"]["zoneid"] = cls.zone.id #Create an account, network, VM and IP addresses cls.account = Account.create( - cls.api_client, + cls.apiclient, cls.services["account"], domainid=cls.domain.id ) cls.service_offering = ServiceOffering.create( - cls.api_client, - cls.services["service_offering"] + cls.apiclient, + cls.services["service_offerings"] ) cls.vm_1 = VirtualMachine.create( - cls.api_client, + cls.apiclient, cls.services["virtual_machine"], templateid=template.id, accountid=cls.account.name, @@ -115,12 +82,12 @@ class TestRouterServices(cloudstackTestCase): @classmethod def tearDownClass(cls): try: - cls.api_client = super( + cls.apiclient = super( TestRouterServices, cls ).getClsTestClient().getApiClient() #Clean up, terminate the created templates - cleanup_resources(cls.api_client, cls.cleanup) + cleanup_resources(cls.apiclient, cls.cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) @@ -128,6 +95,7 @@ class TestRouterServices(cloudstackTestCase): def setUp(self): self.apiclient = self.testClient.getApiClient() + self.hypervisor = self.testClient.getHypervisorInfo() return @attr(tags = ["advanced", "basic", "sg", "smoke", "provisioning"]) @@ -180,7 +148,7 @@ class TestRouterServices(cloudstackTestCase): "Check list router response for router state" ) - if self.apiclient.hypervisor.lower() == 'vmware': + if self.hypervisor.lower() == 'vmware': result = get_process_status( self.apiclient.connection.mgtSvr, 22, @@ -188,7 +156,7 @@ class TestRouterServices(cloudstackTestCase): self.apiclient.connection.passwd, router.linklocalip, "service dnsmasq status", - hypervisor=self.apiclient.hypervisor + hypervisor=self.hypervisor ) else: try: @@ -262,7 +230,7 @@ class TestRouterServices(cloudstackTestCase): "Check list router response for router state" ) - if self.apiclient.hypervisor.lower() == 'vmware': + if self.hypervisor.lower() == 'vmware': result = get_process_status( self.apiclient.connection.mgtSvr, 22, @@ -270,7 +238,7 @@ class TestRouterServices(cloudstackTestCase): self.apiclient.connection.passwd, router.linklocalip, "service dnsmasq status", - hypervisor=self.apiclient.hypervisor + hypervisor=self.hypervisor ) else: try: @@ -294,7 +262,7 @@ class TestRouterServices(cloudstackTestCase): "Check dnsmasq service is running or not" ) - if self.apiclient.hypervisor.lower() == 'vmware': + if self.hypervisor.lower() == 'vmware': result = get_process_status( self.apiclient.connection.mgtSvr, 22, @@ -302,7 +270,7 @@ class TestRouterServices(cloudstackTestCase): self.apiclient.connection.passwd, router.linklocalip, "service haproxy status", - hypervisor=self.apiclient.hypervisor + hypervisor=self.hypervisor ) else: try: @@ -473,7 +441,7 @@ class TestRouterServices(cloudstackTestCase): ) host = hosts[0] - if self.apiclient.hypervisor.lower() == 'vmware': + if self.hypervisor.lower() == 'vmware': res = get_process_status( self.apiclient.connection.mgtSvr, 22, @@ -481,7 +449,7 @@ class TestRouterServices(cloudstackTestCase): self.apiclient.connection.passwd, router.linklocalip, "uptime", - hypervisor=self.apiclient.hypervisor + hypervisor=self.hypervisor ) else: try: diff --git a/test/integration/smoke/test_scale_vm.py b/test/integration/smoke/test_scale_vm.py index 026ac1336a2..03d2e87bb40 100644 --- a/test/integration/smoke/test_scale_vm.py +++ b/test/integration/smoke/test_scale_vm.py @@ -18,119 +18,60 @@ """ #Import Local Modules import marvin +from marvin.codes import FAILED from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * from nose.plugins.attrib import attr _multiprocess_shared_ = True -class Services: - """Test VM Life Cycle Services - """ - - def __init__(self): - self.services = { - - "account": { - "email": "test@test.com", - "firstname": "Test", - "lastname": "User", - "username": "test", - # Random characters are appended in create account to - # ensure unique username generated each time - "password": "password", - }, - "small": - # Create a small virtual machine instance with disk offering - { - "displayname": "testserver", - "username": "root", # VM creds for SSH - "password": "password", - "ssh_port": 22, - "hypervisor": 'XenServer', - "privateport": 22, - "publicport": 22, - "protocol": 'TCP', - }, - "service_offerings": - { - "small": - { - # Small service offering ID to for change VM - # service offering from medium to small - "name": "SmallInstance", - "displaytext": "SmallInstance", - "cpunumber": 1, - "cpuspeed": 100, - "memory": 256, - }, - "big": - { - # Big service offering ID to for change VM - "name": "BigInstance", - "displaytext": "BigInstance", - "cpunumber": 1, - "cpuspeed": 100, - "memory": 512, - } - }, - #Change this - "template": { - "displaytext": "xs", - "name": "xs", - "passwordenabled": False, - }, - "sleep": 60, - "timeout": 10, - #Migrate VM to hostid - "ostype": 'CentOS 5.3 (64-bit)', - # CentOS 5.3 (64-bit) - } - - class TestScaleVm(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestScaleVm, cls).getClsTestClient().getApiClient() - cls.services = Services().services + testClient = super(TestScaleVm, cls).getClsTestClient() + cls.apiclient = testClient.getApiClient() + cls.services = testClient.getParsedTestDataConfig() # Get Zone, Domain and templates - domain = get_domain(cls.api_client, cls.services) - zone = get_zone(cls.api_client, cls.services) + domain = get_domain(cls.apiclient) + zone = get_zone(cls.apiclient, testClient.getZoneForTests()) cls.services['mode'] = zone.networktype template = get_template( - cls.api_client, + cls.apiclient, zone.id, cls.services["ostype"] ) + if template == FAILED: + assert False, "get_template() failed to return template with description %s" % cls.services["ostype"] + # Set Zones and disk offerings ?? cls.services["small"]["zoneid"] = zone.id cls.services["small"]["template"] = template.id # Create account, service offerings, vm. cls.account = Account.create( - cls.api_client, + cls.apiclient, cls.services["account"], domainid=domain.id ) cls.small_offering = ServiceOffering.create( - cls.api_client, + cls.apiclient, cls.services["service_offerings"]["small"] ) cls.big_offering = ServiceOffering.create( - cls.api_client, + cls.apiclient, cls.services["service_offerings"]["big"] ) #create a virtual machine cls.virtual_machine = VirtualMachine.create( - cls.api_client, + cls.apiclient, cls.services["small"], accountid=cls.account.name, domainid=cls.account.domainid, @@ -144,8 +85,8 @@ class TestScaleVm(cloudstackTestCase): @classmethod def tearDownClass(cls): - cls.api_client = super(TestScaleVm, cls).getClsTestClient().getApiClient() - cleanup_resources(cls.api_client, cls._cleanup) + cls.apiclient = super(TestScaleVm, cls).getClsTestClient().getApiClient() + cleanup_resources(cls.apiclient, cls._cleanup) return def setUp(self): diff --git a/test/integration/smoke/test_secondary_storage.py b/test/integration/smoke/test_secondary_storage.py index 240f54f942f..ac809562e0e 100644 --- a/test/integration/smoke/test_secondary_storage.py +++ b/test/integration/smoke/test_secondary_storage.py @@ -20,9 +20,9 @@ import marvin from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common 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 @@ -33,7 +33,7 @@ class TestSecStorageServices(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestSecStorageServices, cls).getClsTestClient().getApiClient() + cls.apiclient = super(TestSecStorageServices, cls).getClsTestClient().getApiClient() cls._cleanup = [] return @@ -41,7 +41,7 @@ class TestSecStorageServices(cloudstackTestCase): def tearDownClass(cls): try: #Cleanup resources used - cleanup_resources(cls.api_client, cls._cleanup) + cleanup_resources(cls.apiclient, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) return @@ -187,6 +187,8 @@ class TestSecStorageServices(cloudstackTestCase): listall=True, account='system' ) + self.assertEqual(validateList(list_template_response)[0], PASS,\ + "templates list validation failed") # Ensure all BUILTIN templates are downloaded templateid = None diff --git a/test/integration/smoke/test_service_offerings.py b/test/integration/smoke/test_service_offerings.py index 70865b45441..3c918598639 100644 --- a/test/integration/smoke/test_service_offerings.py +++ b/test/integration/smoke/test_service_offerings.py @@ -17,15 +17,16 @@ """ BVT tests for Service offerings""" #Import Local Modules +from marvin.codes import FAILED from marvin.cloudstackTestCase import cloudstackTestCase from marvin.cloudstackAPI import changeServiceForVirtualMachine,updateServiceOffering -from marvin.integration.lib.utils import (isAlmostEqual, +from marvin.lib.utils import (isAlmostEqual, cleanup_resources, random_gen) -from marvin.integration.lib.base import (ServiceOffering, +from marvin.lib.base import (ServiceOffering, Account, VirtualMachine) -from marvin.integration.lib.common import (list_service_offering, +from marvin.lib.common import (list_service_offering, list_virtual_machines, get_domain, get_zone, @@ -35,93 +36,13 @@ from nose.plugins.attrib import attr _multiprocess_shared_ = True -class Services: - """Test Service offerings Services - """ - - def __init__(self): - self.services = { - "account": { - "email": "test@test.com", - "firstname": "Test", - "lastname": "User", - "username": "test", - # Random characters are appended in create account to - # ensure unique username generated each time - "password": "password", - }, - "off": - { - "name": "Service Offering", - "displaytext": "Service Offering", - "cpunumber": 1, - "cpuspeed": 100, # MHz - "memory": 128, # in MBs - }, - "small": - # Create a small virtual machine instance with disk offering - { - "displayname": "testserver", - "username": "root", # VM creds for SSH - "password": "password", - "ssh_port": 22, - "hypervisor": 'XenServer', - "privateport": 22, - "publicport": 22, - "protocol": 'TCP', - }, - "medium": # Create a medium virtual machine instance - { - "displayname": "testserver", - "username": "root", - "password": "password", - "ssh_port": 22, - "hypervisor": 'XenServer', - "privateport": 22, - "publicport": 22, - "protocol": 'TCP', - }, - "service_offerings": - { - "tiny": - { - "name": "Tiny Instance", - "displaytext": "Tiny Instance", - "cpunumber": 1, - "cpuspeed": 100, # in MHz - "memory": 128, # In MBs - }, - "small": - { - # Small service offering ID to for change VM - # service offering from medium to small - "name": "Small Instance", - "displaytext": "Small Instance", - "cpunumber": 1, - "cpuspeed": 100, - "memory": 128, - }, - "medium": - { - # Medium service offering ID to for - # change VM service offering from small to medium - "name": "Medium Instance", - "displaytext": "Medium Instance", - "cpunumber": 1, - "cpuspeed": 100, - "memory": 256, - } - }, - "ostype": 'CentOS 5.3 (64-bit)', - } - class TestCreateServiceOffering(cloudstackTestCase): def setUp(self): self.apiclient = self.testClient.getApiClient() self.dbclient = self.testClient.getDbConnection() self.cleanup = [] - self.services = Services().services + self.services = self.testClient.getParsedTestDataConfig() def tearDown(self): try: @@ -143,7 +64,7 @@ class TestCreateServiceOffering(cloudstackTestCase): service_offering = ServiceOffering.create( self.apiclient, - self.services["off"] + self.services["service_offerings"] ) self.cleanup.append(service_offering) @@ -168,27 +89,27 @@ class TestCreateServiceOffering(cloudstackTestCase): self.assertEqual( list_service_response[0].cpunumber, - self.services["off"]["cpunumber"], + self.services["service_offerings"]["cpunumber"], "Check server id in createServiceOffering" ) self.assertEqual( list_service_response[0].cpuspeed, - self.services["off"]["cpuspeed"], + self.services["service_offerings"]["cpuspeed"], "Check cpuspeed in createServiceOffering" ) self.assertEqual( list_service_response[0].displaytext, - self.services["off"]["displaytext"], + self.services["service_offerings"]["displaytext"], "Check server displaytext in createServiceOfferings" ) self.assertEqual( list_service_response[0].memory, - self.services["off"]["memory"], + self.services["service_offerings"]["memory"], "Check memory in createServiceOffering" ) self.assertEqual( list_service_response[0].name, - self.services["off"]["name"], + self.services["service_offerings"]["name"], "Check name in createServiceOffering" ) return @@ -212,25 +133,30 @@ class TestServiceOfferings(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestServiceOfferings, cls).getClsTestClient().getApiClient() - cls.services = Services().services - domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + testClient = super(TestServiceOfferings, cls).getClsTestClient() + cls.apiclient = testClient.getApiClient() + cls.services = testClient.getParsedTestDataConfig() + + domain = get_domain(cls.apiclient) + cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype cls.service_offering_1 = ServiceOffering.create( - cls.api_client, - cls.services["off"] + cls.apiclient, + cls.services["service_offerings"] ) cls.service_offering_2 = ServiceOffering.create( - cls.api_client, - cls.services["off"] + cls.apiclient, + cls.services["service_offerings"] ) template = get_template( - cls.api_client, + cls.apiclient, cls.zone.id, cls.services["ostype"] ) + if template == FAILED: + assert False, "get_template() failed to return template with description %s" % cls.services["ostype"] + # Set Zones and disk offerings cls.services["small"]["zoneid"] = cls.zone.id cls.services["small"]["template"] = template.id @@ -240,22 +166,22 @@ class TestServiceOfferings(cloudstackTestCase): # Create VMs, NAT Rules etc cls.account = Account.create( - cls.api_client, + cls.apiclient, cls.services["account"], domainid=domain.id ) cls.small_offering = ServiceOffering.create( - cls.api_client, + cls.apiclient, cls.services["service_offerings"]["small"] ) cls.medium_offering = ServiceOffering.create( - cls.api_client, + cls.apiclient, cls.services["service_offerings"]["medium"] ) cls.medium_virtual_machine = VirtualMachine.create( - cls.api_client, + cls.apiclient, cls.services["medium"], accountid=cls.account.name, domainid=cls.account.domainid, @@ -272,9 +198,9 @@ class TestServiceOfferings(cloudstackTestCase): @classmethod def tearDownClass(cls): try: - cls.api_client = super(TestServiceOfferings, cls).getClsTestClient().getApiClient() + cls.apiclient = super(TestServiceOfferings, cls).getClsTestClient().getApiClient() #Clean up, terminate the created templates - cleanup_resources(cls.api_client, cls._cleanup) + cleanup_resources(cls.apiclient, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) diff --git a/test/integration/smoke/test_snapshots.py b/test/integration/smoke/test_snapshots.py index e3bd186b3a6..a9be4e22015 100644 --- a/test/integration/smoke/test_snapshots.py +++ b/test/integration/smoke/test_snapshots.py @@ -15,129 +15,35 @@ # specific language governing permissions and limitations # under the License. +from marvin.codes import FAILED from nose.plugins.attrib import attr from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * - -class Services: - """Test Snapshots Services - """ - - def __init__(self): - self.services = { - "account": { - "email": "test@test.com", - "firstname": "Test", - "lastname": "User", - "username": "test", - # Random characters are appended for unique - # username - "password": "password", - }, - "service_offering": { - "name": "Tiny Instance", - "displaytext": "Tiny Instance", - "cpunumber": 1, - "cpuspeed": 200, # in MHz - "memory": 256, # In MBs - }, - "disk_offering": { - "displaytext": "Small Disk", - "name": "Small Disk", - "disksize": 1 - }, - "server_with_disk": - { - "displayname": "Test VM -With Disk", - "username": "root", - "password": "password", - "ssh_port": 22, - "hypervisor": 'XenServer', - "privateport": 22, - "publicport": 22, - "protocol": 'TCP', - }, - - "server_without_disk": - { - "displayname": "Test VM-No Disk", - "username": "root", - "password": "password", - "ssh_port": 22, - "hypervisor": 'XenServer', - "privateport": 22, - # For NAT rule creation - "publicport": 22, - "protocol": 'TCP', - }, - "server": { - "displayname": "TestVM", - "username": "root", - "password": "password", - "ssh_port": 22, - "hypervisor": 'XenServer', - "privateport": 22, - "publicport": 22, - "protocol": 'TCP', - }, - "mgmt_server": { - "ipaddress": '192.168.100.21', - "username": "root", - "password": "password", - "port": 22, - }, - "recurring_snapshot": { - "intervaltype": 'HOURLY', - # Frequency of snapshots - "maxsnaps": 1, # Should be min 2 - "schedule": 1, - "timezone": 'US/Arizona', - # Timezone Formats - http://cloud.mindtouch.us/CloudStack_Documentation/Developer's_Guide%3A_CloudStack - }, - "templates": { - "displaytext": 'Template', - "name": 'Template', - "ostype": "CentOS 5.3 (64-bit)", - "templatefilter": 'self', - }, - "volume": { - "diskname": "APP Data Volume", - "size": 1, # in GBs - "diskdevice": ['/dev/xvdb', '/dev/sdb', '/dev/hdb', '/dev/vdb' ], # Data Disk - }, - "paths": { - "mount_dir": "/mnt/tmp", - "sub_dir": "test", - "sub_lvl_dir1": "test1", - "sub_lvl_dir2": "test2", - "random_data": "random.data", - }, - "ostype": "CentOS 5.3 (64-bit)", - # Cent OS 5.3 (64 bit) - "sleep": 60, - "timeout": 10, - } - +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * class TestSnapshotRootDisk(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestSnapshotRootDisk, cls).getClsTestClient().getApiClient() - cls.services = Services().services + testClient = super(TestSnapshotRootDisk, cls).getClsTestClient() + cls.apiclient = testClient.getApiClient() + cls.services = testClient.getParsedTestDataConfig() + # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.apiclient) + cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype template = get_template( - cls.api_client, + cls.apiclient, cls.zone.id, cls.services["ostype"] ) + if template == FAILED: + assert False, "get_template() failed to return template with description %s" % cls.services["ostype"] + cls.services["domainid"] = cls.domain.id cls.services["server_without_disk"]["zoneid"] = cls.zone.id cls.services["templates"]["ostypeid"] = template.ostypeid @@ -145,20 +51,17 @@ class TestSnapshotRootDisk(cloudstackTestCase): # Create VMs, NAT Rules etc cls.account = Account.create( - cls.api_client, + cls.apiclient, cls.services["account"], domainid=cls.domain.id ) - - cls.services["account"] = cls.account.name - cls.service_offering = ServiceOffering.create( - cls.api_client, - cls.services["service_offering"] + cls.apiclient, + cls.services["service_offerings"] ) cls.virtual_machine = cls.virtual_machine_with_disk = \ VirtualMachine.create( - cls.api_client, + cls.apiclient, cls.services["server_without_disk"], templateid=template.id, accountid=cls.account.name, @@ -176,7 +79,7 @@ class TestSnapshotRootDisk(cloudstackTestCase): def tearDownClass(cls): try: #Cleanup resources used - cleanup_resources(cls.api_client, cls._cleanup) + cleanup_resources(cls.apiclient, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) return diff --git a/test/integration/smoke/test_ssvm.py b/test/integration/smoke/test_ssvm.py index cf40907209e..ffa620b2db0 100644 --- a/test/integration/smoke/test_ssvm.py +++ b/test/integration/smoke/test_ssvm.py @@ -21,9 +21,9 @@ import marvin from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * from marvin.sshClient import SshClient -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * from nose.plugins.attrib import attr import telnetlib @@ -31,24 +31,14 @@ import telnetlib import time _multiprocess_shared_ = True -class Services: - """Test SSVM Services - """ - - def __init__(self): - self.services = { - "sleep": 60, - "timeout": 10, - } - class TestSSVMs(cloudstackTestCase): def setUp(self): - self.apiclient = self.testClient.getApiClient() + self.hypervisor = self.testClient.getHypervisorInfo() self.cleanup = [] - self.services = Services().services - self.zone = get_zone(self.apiclient, self.services) + self.services = self.testClient.getParsedTestDataConfig() + self.zone = get_zone(self.apiclient, self.testClient.getZoneForTests()) return def tearDown(self): @@ -329,7 +319,7 @@ class TestSSVMs(cloudstackTestCase): self.debug("Running SSVM check script") - if self.apiclient.hypervisor.lower() == 'vmware': + if self.hypervisor.lower() == 'vmware': #SSH into SSVMs is done via management server for Vmware result = get_process_status( self.apiclient.connection.mgtSvr, @@ -338,7 +328,7 @@ class TestSSVMs(cloudstackTestCase): self.apiclient.connection.passwd, ssvm.privateip, "/usr/local/cloud/systemvm/ssvm-check.sh |grep -e ERROR -e WARNING -e FAIL", - hypervisor=self.apiclient.hypervisor + hypervisor=self.hypervisor ) else: try: @@ -369,7 +359,7 @@ class TestSSVMs(cloudstackTestCase): ) #Check status of cloud service - if self.apiclient.hypervisor.lower() == 'vmware': + if self.hypervisor.lower() == 'vmware': #SSH into SSVMs is done via management server for Vmware result = get_process_status( self.apiclient.connection.mgtSvr, @@ -378,7 +368,7 @@ class TestSSVMs(cloudstackTestCase): self.apiclient.connection.passwd, ssvm.privateip, "service cloud status", - hypervisor=self.apiclient.hypervisor + hypervisor=self.hypervisor ) else: try: @@ -453,7 +443,7 @@ class TestSSVMs(cloudstackTestCase): self.debug("Checking cloud process status") - if self.apiclient.hypervisor.lower() == 'vmware': + if self.hypervisor.lower() == 'vmware': #SSH into SSVMs is done via management server for vmware result = get_process_status( self.apiclient.connection.mgtSvr, @@ -462,7 +452,7 @@ class TestSSVMs(cloudstackTestCase): self.apiclient.connection.passwd, cpvm.privateip, "service cloud status", - hypervisor=self.apiclient.hypervisor + hypervisor=self.hypervisor ) else: try: diff --git a/test/integration/smoke/test_templates.py b/test/integration/smoke/test_templates.py index 32b3696d035..4865ee3a2cb 100644 --- a/test/integration/smoke/test_templates.py +++ b/test/integration/smoke/test_templates.py @@ -18,12 +18,13 @@ """ #Import Local Modules import marvin +from marvin.codes import FAILED from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * from marvin.sshClient import SshClient -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * from nose.plugins.attrib import attr import urllib from random import random @@ -32,72 +33,6 @@ import datetime _multiprocess_shared_ = True -class Services: - """Test Templates Services - """ - - def __init__(self): - self.services = { - "account": { - "email": "test@test.com", - "firstname": "Test", - "lastname": "User", - "username": "test", - # Random characters are appended for unique - # username - "password": "password", - }, - "service_offering": { - "name": "Tiny Instance", - "displaytext": "Tiny Instance", - "cpunumber": 1, - "cpuspeed": 100, # in MHz - "memory": 128, # In MBs - }, - "disk_offering": { - "displaytext": "Small", - "name": "Small", - "disksize": 1 - }, - "virtual_machine": { - "displayname": "testVM", - "hypervisor": 'XenServer', - "protocol": 'TCP', - "ssh_port": 22, - "username": "root", - "password": "password", - "privateport": 22, - "publicport": 22, - }, - "volume": { - "diskname": "Test Volume", - }, - "template_1": { - "displaytext": "Cent OS Template", - "name": "Cent OS Template", - "ostype": "CentOS 5.3 (64-bit)", - }, - "template_2": { - "displaytext": "Public Template", - "name": "Public template", - "ostype": "CentOS 5.3 (64-bit)", - "isfeatured": True, - "ispublic": True, - "isextractable": True, - "mode": "HTTP_DOWNLOAD", - }, - "templatefilter": 'self', - "isfeatured": True, - "ispublic": True, - "isextractable": False, - "bootable": True, - "passwordenabled": True, - "ostype": "CentOS 5.3 (64-bit)", - "sleep": 30, - "timeout": 10, - } - - class TestCreateTemplate(cloudstackTestCase): def setUp(self): @@ -118,23 +53,28 @@ class TestCreateTemplate(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.services = Services().services - cls.api_client = super(TestCreateTemplate, cls).getClsTestClient().getApiClient() + + testClient = super(TestCreateTemplate, cls).getClsTestClient() + cls.apiclient = testClient.getApiClient() + cls.services = testClient.getParsedTestDataConfig() # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.apiclient) + cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype cls.disk_offering = DiskOffering.create( - cls.api_client, + cls.apiclient, cls.services["disk_offering"] ) template = get_template( - cls.api_client, + cls.apiclient, cls.zone.id, cls.services["ostype"] ) - cls.services["template_1"]["ostypeid"] = template.ostypeid + if template == FAILED: + assert False, "get_template() failed to return template with description %s" % cls.services["ostype"] + + cls.services["template"]["ostypeid"] = template.ostypeid cls.services["template_2"]["ostypeid"] = template.ostypeid cls.services["ostypeid"] = template.ostypeid @@ -144,19 +84,17 @@ class TestCreateTemplate(cloudstackTestCase): cls.services["sourcezoneid"] = cls.zone.id cls.account = Account.create( - cls.api_client, + cls.apiclient, cls.services["account"], domainid=cls.domain.id ) - cls.services["account"] = cls.account.name - cls.service_offering = ServiceOffering.create( - cls.api_client, - cls.services["service_offering"] + cls.apiclient, + cls.services["service_offerings"] ) #create virtual machine cls.virtual_machine = VirtualMachine.create( - cls.api_client, + cls.apiclient, cls.services["virtual_machine"], templateid=template.id, accountid=cls.account.name, @@ -166,7 +104,7 @@ class TestCreateTemplate(cloudstackTestCase): ) #Stop virtual machine - cls.virtual_machine.stop(cls.api_client) + cls.virtual_machine.stop(cls.apiclient) # Poll listVM to ensure VM is stopped properly timeout = cls.services["timeout"] @@ -175,7 +113,7 @@ class TestCreateTemplate(cloudstackTestCase): # Ensure that VM is in stopped state list_vm_response = list_virtual_machines( - cls.api_client, + cls.apiclient, id=cls.virtual_machine.id ) @@ -193,7 +131,7 @@ class TestCreateTemplate(cloudstackTestCase): timeout = timeout - 1 list_volume = list_volumes( - cls.api_client, + cls.apiclient, virtualmachineid=cls.virtual_machine.id, type='ROOT', listall=True @@ -210,9 +148,9 @@ class TestCreateTemplate(cloudstackTestCase): @classmethod def tearDownClass(cls): try: - cls.api_client = super(TestCreateTemplate, cls).getClsTestClient().getApiClient() + cls.apiclient = super(TestCreateTemplate, cls).getClsTestClient().getApiClient() #Cleanup resources used - cleanup_resources(cls.api_client, cls._cleanup) + cleanup_resources(cls.apiclient, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) @@ -233,7 +171,7 @@ class TestCreateTemplate(cloudstackTestCase): #Create template from Virtual machine and Volume ID template = Template.create( self.apiclient, - self.services["template_1"], + self.services["template"], self.volume.id, account=self.account.name, domainid=self.account.domainid @@ -264,18 +202,18 @@ class TestCreateTemplate(cloudstackTestCase): self.assertEqual( template_response.displaytext, - self.services["template_1"]["displaytext"], + self.services["template"]["displaytext"], "Check display text of newly created template" ) name = template_response.name self.assertEqual( - name.count(self.services["template_1"]["name"]), + name.count(self.services["template"]["name"]), 1, "Check name of newly created template" ) self.assertEqual( template_response.ostypeid, - self.services["template_1"]["ostypeid"], + self.services["template"]["ostypeid"], "Check osTypeID of newly created template" ) return @@ -286,60 +224,61 @@ class TestTemplates(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.services = Services().services - cls.api_client = super(TestTemplates, cls).getClsTestClient().getApiClient() + testClient = super(TestTemplates, cls).getClsTestClient() + cls.apiclient = testClient.getApiClient() + cls.services = testClient.getParsedTestDataConfig() # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.apiclient) + cls.zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype #populate second zone id for iso copy cmd = listZones.listZonesCmd() - cls.zones = cls.api_client.listZones(cmd) + cls.zones = cls.apiclient.listZones(cmd) if not isinstance(cls.zones, list): raise Exception("Failed to find zones.") cls.disk_offering = DiskOffering.create( - cls.api_client, + cls.apiclient, cls.services["disk_offering"] ) template = get_template( - cls.api_client, + cls.apiclient, cls.zone.id, cls.services["ostype"] ) + if template == FAILED: + assert False, "get_template() failed to return template with description %s" % cls.services["ostype"] + cls.services["virtual_machine"]["zoneid"] = cls.zone.id cls.services["volume"]["diskoffering"] = cls.disk_offering.id cls.services["volume"]["zoneid"] = cls.zone.id cls.services["template_2"]["zoneid"] = cls.zone.id cls.services["sourcezoneid"] = cls.zone.id - cls.services["template_1"]["ostypeid"] = template.ostypeid + cls.services["template"]["ostypeid"] = template.ostypeid cls.services["template_2"]["ostypeid"] = template.ostypeid cls.services["ostypeid"] = template.ostypeid - + print "Before:",cls.services cls.account = Account.create( - cls.api_client, + cls.apiclient, cls.services["account"], admin=True, domainid=cls.domain.id ) - + print "After:",cls.services cls.user = Account.create( - cls.api_client, + cls.apiclient, cls.services["account"], domainid=cls.domain.id ) - - cls.services["account"] = cls.account.name - cls.service_offering = ServiceOffering.create( - cls.api_client, - cls.services["service_offering"] + cls.apiclient, + cls.services["service_offerings"] ) #create virtual machine cls.virtual_machine = VirtualMachine.create( - cls.api_client, + cls.apiclient, cls.services["virtual_machine"], templateid=template.id, accountid=cls.account.name, @@ -348,7 +287,7 @@ class TestTemplates(cloudstackTestCase): mode=cls.services["mode"] ) #Stop virtual machine - cls.virtual_machine.stop(cls.api_client) + cls.virtual_machine.stop(cls.apiclient) # Poll listVM to ensure VM is stopped properly timeout = cls.services["timeout"] @@ -357,7 +296,7 @@ class TestTemplates(cloudstackTestCase): # Ensure that VM is in stopped state list_vm_response = list_virtual_machines( - cls.api_client, + cls.apiclient, id=cls.virtual_machine.id ) @@ -375,7 +314,7 @@ class TestTemplates(cloudstackTestCase): timeout = timeout - 1 list_volume = list_volumes( - cls.api_client, + cls.apiclient, virtualmachineid=cls.virtual_machine.id, type='ROOT', listall=True @@ -389,14 +328,14 @@ class TestTemplates(cloudstackTestCase): #Create templates for Edit, Delete & update permissions testcases cls.template_1 = Template.create( - cls.api_client, - cls.services["template_1"], + cls.apiclient, + cls.services["template"], cls.volume.id, account=cls.account.name, domainid=cls.account.domainid ) cls.template_2 = Template.create( - cls.api_client, + cls.apiclient, cls.services["template_2"], cls.volume.id, account=cls.account.name, @@ -412,9 +351,9 @@ class TestTemplates(cloudstackTestCase): @classmethod def tearDownClass(cls): try: - cls.api_client = super(TestTemplates, cls).getClsTestClient().getApiClient() + cls.apiclient = super(TestTemplates, cls).getClsTestClient().getApiClient() #Cleanup created resources such as templates and VMs - cleanup_resources(cls.api_client, cls._cleanup) + cleanup_resources(cls.apiclient, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) @@ -438,7 +377,7 @@ class TestTemplates(cloudstackTestCase): return - @attr(tags = ["advanced", "advancedns", "smoke", "basic", "sg", "selfservice"]) + @attr(tags = ["advanced", "advancedns", "smoke", "basic", "sg", "selfservice", "test"]) def test_02_edit_template(self): """Test Edit template """ diff --git a/test/integration/smoke/test_vm_ha.py b/test/integration/smoke/test_vm_ha.py index 2dd514dc4ff..f549243729b 100644 --- a/test/integration/smoke/test_vm_ha.py +++ b/test/integration/smoke/test_vm_ha.py @@ -25,13 +25,13 @@ from marvin.cloudstackTestCase import cloudstackTestCase #Import Integration Libraries #base - contains all resources as entities and defines create, delete, list operations on them -from marvin.integration.lib.base import Account, VirtualMachine, Cluster, Host, ServiceOffering, Configurations, SimulatorMock +from marvin.lib.base import Account, VirtualMachine, Cluster, Host, ServiceOffering, Configurations, SimulatorMock #utils - utility classes for common cleanup, external library wrappers etc -from marvin.integration.lib.utils import cleanup_resources +from marvin.lib.utils import cleanup_resources #common - commonly used methods for all tests are listed here -from marvin.integration.lib.common import get_zone, get_domain, get_template +from marvin.lib.common import get_zone, get_domain, get_template from nose.plugins.attrib import attr diff --git a/test/integration/smoke/test_vm_iam.py b/test/integration/smoke/test_vm_iam.py new file mode 100644 index 00000000000..be75a79737f --- /dev/null +++ b/test/integration/smoke/test_vm_iam.py @@ -0,0 +1,719 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +""" BVT tests for Virtual Machine IAM effect +""" +#Import Local Modules +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 marvin.codes import FAILED +from nose.plugins.attrib import attr +#Import System modules +import time + +_multiprocess_shared_ = True +class Services: + """Test VM Life Cycle Services + """ + + def __init__(self): + self.services = { + #data for domains and accounts + "domain1": { + "name": "Domain1", + }, + "account1A": { + "email": "test1A@test.com", + "firstname": "test1A", + "lastname": "User", + "username": "test1A", + "password": "password", + }, + "account1B": { + "email": "test1B@test.com", + "firstname": "test1B", + "lastname": "User", + "username": "test1B", + "password": "password", + }, + "domain2": { + "name": "Domain2", + }, + "account2A": { + "email": "test2A@test.com", + "firstname": "test2A", + "lastname": "User", + "username": "test2A", + "password": "password", + }, + #data reqd for virtual machine creation + "virtual_machine1A" : { + "name" : "test1Avm", + "displayname" : "Test1A VM", + }, + "virtual_machine1B" : { + "name" : "test1Bvm", + "displayname" : "Test1B VM", + }, + "virtual_machine2A" : { + "name" : "test2Avm", + "displayname" : "Test2A VM", + }, + #small service offering + "service_offering": { + "small": { + "name": "Small Instance", + "displaytext": "Small Instance", + "cpunumber": 1, + "cpuspeed": 100, + "memory": 128, + }, + }, + "ostype": 'CentOS 5.6 (64-bit)', + # iam group and policy information + "service_desk_iam_grp" : { + "name" : "Service Desk", + "description" : "Service Desk IAM Group" + }, + "vm_readonly_iam_policy" : { + "name" : "VM Read Only Access", + "description" : "VM read only access iam policy" + }, + } + + + +class TestVMIam(cloudstackTestCase): + + @classmethod + def setUpClass(self): + testClient = super(TestVMIam, self).getClsTestClient() + self.apiclient = testClient.getApiClient() + self.services = Services().services + + # backup default apikey and secretkey + self.default_apikey = self.apiclient.connection.apiKey + self.default_secretkey = self.apiclient.connection.securityKey + + # Create domains and accounts etc + self.domain_1 = Domain.create( + self.apiclient, + self.services["domain1"] + ) + self.domain_2 = Domain.create( + self.apiclient, + self.services["domain2"] + ) + # Create two accounts for doamin_1 + self.account_1A = Account.create( + self.apiclient, + self.services["account1A"], + admin=False, + domainid=self.domain_1.id + ) + + self.account_1B = Account.create( + self.apiclient, + self.services["account1B"], + admin=False, + domainid=self.domain_1.id + ) + + # Create an account for domain_2 + self.account_2A = Account.create( + self.apiclient, + self.services["account2A"], + admin=False, + domainid=self.domain_2.id + ) + + # Fetch user details to register apiKey for them + self.user_1A = User.list( + self.apiclient, + account=self.account_1A.name, + domainid=self.account_1A.domainid + )[0] + + user_1A_key = User.registerUserKeys( + self.apiclient, + self.user_1A.id + ) + self.user_1A_apikey = user_1A_key.apikey + self.user_1A_secretkey = user_1A_key.secretkey + + + self.user_1B = User.list( + self.apiclient, + account=self.account_1B.name, + domainid=self.account_1B.domainid + )[0] + + user_1B_key = User.registerUserKeys( + self.apiclient, + self.user_1B.id + ) + + self.user_1B_apikey = user_1B_key.apikey + self.user_1B_secretkey = user_1B_key.secretkey + + + self.user_2A = User.list( + self.apiclient, + account=self.account_2A.name, + domainid=self.account_2A.domainid + )[0] + + user_2A_key = User.registerUserKeys( + self.apiclient, + self.user_2A.id + ) + self.user_2A_apikey = user_2A_key.apikey + self.user_2A_secretkey = user_2A_key.secretkey + + # create service offering + self.service_offering = ServiceOffering.create( + self.apiclient, + self.services["service_offering"]["small"] + ) + + self.zone = get_zone(self.apiclient, testClient.getZoneForTests()) + self.services['mode'] = self.zone.networktype + self.template = get_template(self.apiclient, self.zone.id, self.services["ostype"]) + + # deploy 3 VMs for three accounts + self.virtual_machine_1A = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine1A"], + accountid=self.account_1A.name, + zoneid=self.zone.id, + domainid=self.account_1A.domainid, + serviceofferingid=self.service_offering.id, + templateid=self.template.id + ) + + self.virtual_machine_1B = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine1B"], + accountid=self.account_1B.name, + zoneid=self.zone.id, + domainid=self.account_1B.domainid, + serviceofferingid=self.service_offering.id, + templateid=self.template.id + ) + + self.virtual_machine_2A = VirtualMachine.create( + self.apiclient, + self.services["virtual_machine2A"], + accountid=self.account_2A.name, + zoneid=self.zone.id, + domainid=self.account_2A.domainid, + serviceofferingid=self.service_offering.id, + templateid=self.template.id + ) + + self.srv_desk_grp = IAMGroup.create( + self.apiclient, + self.services["service_desk_iam_grp"] + ) + + self.vm_read_policy = IAMPolicy.create( + self.apiclient, + self.services["vm_readonly_iam_policy"] + ) + + self.srv_desk_grp.attachPolicy( + self.apiclient, [self.vm_read_policy] + ) + + vm_grant_policy_params = {} + vm_grant_policy_params['name'] = "policyGrantVirtualMachine" + self.virtual_machine_1A.id + vm_grant_policy_params['description'] = "Policy to grant permission to VirtualMachine " + self.virtual_machine_1A.id + self.vm_grant_policy = IAMPolicy.create( + self.apiclient, + vm_grant_policy_params + ) + + self._cleanup = [ + self.account_1A, + self.account_1B, + self.domain_1, + self.account_2A, + self.domain_2, + self.service_offering, + self.vm_read_policy, + self.srv_desk_grp, + self.vm_grant_policy + ] + + @classmethod + def tearDownClass(self): + self.apiclient = super(TestVMIam, self).getClsTestClient().getApiClient() + cleanup_resources(self.apiclient, self._cleanup) + return + + def setUp(self): + self.apiclient = self.testClient.getApiClient() + self.dbclient = self.testClient.getDbConnection() + self.cleanup = [] + + def tearDown(self): + # restore back default apikey and secretkey + self.apiclient.connection.apiKey = self.default_apikey + self.apiclient.connection.securityKey = self.default_secretkey + cleanup_resources(self.apiclient, self.cleanup) + return + + + + @attr(tags = ["devcloud", "advanced", "advancedns", "smoke", "basic", "sg", "selfservice"]) + def test_01_list_own_vm(self): + # listVM command should return owne's VM + + self.debug("Listing VM for account: %s" % self.account_1A.name) + + self.apiclient.connection.apiKey = self.user_1A_apikey + self.apiclient.connection.securityKey = self.user_1A_secretkey + list_vm_response = list_virtual_machines( + self.apiclient + ) + self.assertEqual( + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) + self.assertEqual( + len(list_vm_response), + 1, + "Check VM available in List Virtual Machines" + ) + + self.assertEqual( + list_vm_response[0].name, + self.virtual_machine_1A.name, + "Virtual Machine names do not match" + ) + + self.debug("Listing VM for account: %s" % self.account_1B.name) + self.apiclient.connection.apiKey = self.user_1B_apikey + self.apiclient.connection.securityKey = self.user_1B_secretkey + list_vm_response = list_virtual_machines( + self.apiclient + ) + self.assertEqual( + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) + self.assertEqual( + len(list_vm_response), + 1, + "Check VM available in List Virtual Machines" + ) + + self.assertEqual( + list_vm_response[0].name, + self.virtual_machine_1B.name, + "Virtual Machine names do not match" + ) + + self.debug("Listing VM for account: %s" % self.account_2A.name) + + self.apiclient.connection.apiKey = self.user_2A_apikey + self.apiclient.connection.securityKey = self.user_2A_secretkey + list_vm_response = list_virtual_machines( + self.apiclient + ) + self.assertEqual( + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) + self.assertEqual( + len(list_vm_response), + 1, + "Check VM available in List Virtual Machines" + ) + + self.assertEqual( + list_vm_response[0].name, + self.virtual_machine_2A.name, + "Virtual Machine names do not match" + ) + + return + + @attr(tags = ["devcloud", "advanced", "advancedns", "smoke", "basic", "sg", "selfservice"]) + def test_02_grant_domain_vm(self): + + # Validate the following + # 1. Grant domain2 VM access to account_1B + # 2. listVM command should return account_1B and domain_2 VMs. + + self.debug("Granting Domain %s VM read only access to account: %s" % (self.domain_2.name, self.account_1B.name)) + + self.srv_desk_grp.addAccount(self.apiclient, [self.account_1B]) + domain_permission = {} + domain_permission['action'] = "listVirtualMachines" + domain_permission['entitytype'] = "VirtualMachine" + domain_permission['scope'] = "DOMAIN" + domain_permission['scopeid'] = self.domain_2.id + self.vm_read_policy.addPermission(self.apiclient, domain_permission) + + self.debug("Listing VM for account: %s" % self.account_1B.name) + self.apiclient.connection.apiKey = self.user_1B_apikey + self.apiclient.connection.securityKey = self.user_1B_secretkey + list_vm_response = list_virtual_machines( + self.apiclient + ) + self.assertEqual( + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) + self.assertEqual( + len(list_vm_response), + 2, + "Check VM available in List Virtual Machines" + ) + + list_vm_names = [list_vm_response[0].name, list_vm_response[1].name] + + self.assertEqual( self.virtual_machine_1B.name in list_vm_names, + True, + "Accessible Virtual Machine names do not match" + ) + + self.assertEqual( self.virtual_machine_2A.name in list_vm_names, + True, + "Accessible Virtual Machine names do not match" + ) + + return + + + @attr(tags = ["devcloud", "advanced", "advancedns", "smoke", "basic", "sg", "selfservice"]) + def test_03_grant_account_vm(self): + + # Validate the following + # 1. Grant account_1A VM access to account_1B + # 2. listVM command should return account_1A and account_1B VMs. + + self.debug("Granting Account %s VM read only access to account: %s" % (self.account_1A.name, self.account_1B.name)) + + account_permission = {} + account_permission['action'] = "listVirtualMachines" + account_permission['entitytype'] = "VirtualMachine" + account_permission['scope'] = "ACCOUNT" + account_permission['scopeid'] = self.account_1A.id + self.vm_read_policy.addPermission(self.apiclient, account_permission) + + self.debug("Listing VM for account: %s" % self.account_1B.name) + self.apiclient.connection.apiKey = self.user_1B_apikey + self.apiclient.connection.securityKey = self.user_1B_secretkey + list_vm_response = list_virtual_machines( + self.apiclient + ) + self.assertEqual( + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) + self.assertEqual( + len(list_vm_response), + 3, + "Check VM available in List Virtual Machines" + ) + + list_vm_names = [list_vm_response[0].name, list_vm_response[1].name, list_vm_response[2].name] + + self.assertEqual( self.virtual_machine_1B.name in list_vm_names, + True, + "Accessible Virtual Machine names do not match" + ) + + self.assertEqual( self.virtual_machine_1A.name in list_vm_names, + True, + "Accessible Virtual Machine names do not match" + ) + + self.assertEqual( self.virtual_machine_2A.name in list_vm_names, + True, + "Accessible Virtual Machine names do not match" + ) + + return + + + @attr(tags = ["devcloud", "advanced", "advancedns", "smoke", "basic", "sg", "selfservice"]) + def test_04_revoke_account_vm(self): + + # Validate the following + # 1. Revoke account_1A VM access from account_1B + # 2. listVM command should not return account_1A VMs. + + self.debug("Revoking Account %s VM read only access from account: %s" % (self.account_1A.name, self.account_1B.name)) + + account_permission = {} + account_permission['action'] = "listVirtualMachines" + account_permission['entitytype'] = "VirtualMachine" + account_permission['scope'] = "ACCOUNT" + account_permission['scopeid'] = self.account_1A.id + self.vm_read_policy.removePermission(self.apiclient, account_permission) + + self.debug("Listing VM for account: %s" % self.account_1B.name) + self.apiclient.connection.apiKey = self.user_1B_apikey + self.apiclient.connection.securityKey = self.user_1B_secretkey + list_vm_response = list_virtual_machines( + self.apiclient + ) + self.assertEqual( + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) + self.assertEqual( + len(list_vm_response), + 2, + "Check VM available in List Virtual Machines" + ) + + list_vm_names = [list_vm_response[0].name, list_vm_response[1].name] + + + self.assertEqual( self.virtual_machine_1A.name in list_vm_names, + False, + "Accessible Virtual Machine names do not match" + ) + return + + + @attr(tags = ["devcloud", "advanced", "advancedns", "smoke", "basic", "sg", "selfservice"]) + def test_05_revoke_domain_vm(self): + + # Validate the following + # 1. Revoke account_1A VM access from account_1B + # 2. listVM command should not return account_1A VMs. + + self.debug("Revoking Domain %s VM read only access from account: %s" % (self.domain_1.name, self.account_1B.name)) + + domain_permission = {} + domain_permission['action'] = "listVirtualMachines" + domain_permission['entitytype'] = "VirtualMachine" + domain_permission['scope'] = "DOMAIN" + domain_permission['scopeid'] = self.domain_2.id + self.vm_read_policy.removePermission(self.apiclient, domain_permission) + + self.debug("Listing VM for account: %s" % self.account_1B.name) + self.apiclient.connection.apiKey = self.user_1B_apikey + self.apiclient.connection.securityKey = self.user_1B_secretkey + list_vm_response = list_virtual_machines( + self.apiclient + ) + self.assertEqual( + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) + self.assertEqual( + len(list_vm_response), + 1, + "Check VM available in List Virtual Machines" + ) + + self.assertEqual( + list_vm_response[0].name, + self.virtual_machine_1B.name, + "Virtual Machine names do not match" + ) + + return + + @attr(tags = ["devcloud", "advanced", "advancedns", "smoke", "basic", "sg", "selfservice"]) + def test_06_grant_resource_vm(self): + + # Validate the following + # 1. Grant a particular vm access to account_1B + # 2. listVM command should return account_1B VMs and granted VM. + + self.debug("Granting VM %s read only access to account: %s" % (self.virtual_machine_1A.name, self.account_1B.name)) + + res_permission = {} + res_permission['action'] = "listVirtualMachines" + res_permission['entitytype'] = "VirtualMachine" + res_permission['scope'] = "RESOURCE" + res_permission['scopeid'] = self.virtual_machine_1A.id + self.vm_read_policy.addPermission(self.apiclient, res_permission) + + self.debug("Listing VM for account: %s" % self.account_1B.name) + self.apiclient.connection.apiKey = self.user_1B_apikey + self.apiclient.connection.securityKey = self.user_1B_secretkey + list_vm_response = list_virtual_machines( + self.apiclient + ) + self.assertEqual( + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) + self.assertEqual( + len(list_vm_response), + 2, + "Check VM available in List Virtual Machines" + ) + + list_vm_names = [list_vm_response[0].name, list_vm_response[1].name] + + self.assertEqual( self.virtual_machine_1B.name in list_vm_names, + True, + "Accessible Virtual Machine names do not match" + ) + + self.assertEqual( self.virtual_machine_1A.name in list_vm_names, + True, + "Accessible Virtual Machine names do not match" + ) + + return + + @attr(tags = ["devcloud", "advanced", "advancedns", "smoke", "basic", "sg", "selfservice"]) + def test_07_revoke_resource_vm(self): + + # Validate the following + # 1. Grant a particular vm access to account_1B + # 2. listVM command should return account_1B VMs and granted VM. + + self.debug("Revoking VM %s read only access from account: %s" % (self.virtual_machine_1A.name, self.account_1B.name)) + + res_permission = {} + res_permission['action'] = "listVirtualMachines" + res_permission['entitytype'] = "VirtualMachine" + res_permission['scope'] = "RESOURCE" + res_permission['scopeid'] = self.virtual_machine_1A.id + self.vm_read_policy.removePermission(self.apiclient, res_permission) + + self.debug("Listing VM for account: %s" % self.account_1B.id) + self.apiclient.connection.apiKey = self.user_1B_apikey + self.apiclient.connection.securityKey = self.user_1B_secretkey + list_vm_response = list_virtual_machines( + self.apiclient + ) + self.assertEqual( + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) + self.assertEqual( + len(list_vm_response), + 1, + "Check VM available in List Virtual Machines" + ) + + self.assertEqual( + list_vm_response[0].name, + self.virtual_machine_1B.name, + "Virtual Machine names do not match" + ) + + return + + + @attr(tags = ["devcloud", "advanced", "advancedns", "smoke", "basic", "sg", "selfservice"]) + def test_08_policy_attach_account(self): + + # Validate the following + # 1. Grant a particular vm access to account_1B by directly attaching policy to account + # 2. listVM command should return account_1B VMs and granted VM. + + self.debug("Granting VM %s read only access to account: %s by attaching policy to account" % (self.virtual_machine_1A.name, self.account_1B.name)) + + res_permission = {} + res_permission['action'] = "listVirtualMachines" + res_permission['entitytype'] = "VirtualMachine" + res_permission['scope'] = "RESOURCE" + res_permission['scopeid'] = self.virtual_machine_1A.id + self.vm_grant_policy.addPermission(self.apiclient, res_permission) + self.vm_grant_policy.attachAccount(self.apiclient, [self.account_1B]) + + self.debug("Listing VM for account: %s" % self.account_1B.id) + self.apiclient.connection.apiKey = self.user_1B_apikey + self.apiclient.connection.securityKey = self.user_1B_secretkey + list_vm_response = list_virtual_machines( + self.apiclient + ) + self.assertEqual( + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) + self.assertEqual( + len(list_vm_response), + 2, + "Check VM available in List Virtual Machines" + ) + + list_vm_names = [list_vm_response[0].name, list_vm_response[1].name] + + self.assertEqual( self.virtual_machine_1B.name in list_vm_names, + True, + "Accessible Virtual Machine names do not match" + ) + + self.assertEqual( self.virtual_machine_1A.name in list_vm_names, + True, + "Accessible Virtual Machine names do not match" + ) + + return + + @attr(tags = ["devcloud", "advanced", "advancedns", "smoke", "basic", "sg", "selfservice"]) + def test_09_policy_detach_account(self): + + # Validate the following + # 1. Revoking a particular vm access from account_1B by detaching policy from account + # 2. listVM command should return account_1B VMs. + + self.debug("Revoking VM %s read only access from account: %s by detaching policy from account" % (self.virtual_machine_1A.name, self.account_1B.name)) + + self.vm_grant_policy.detachAccount(self.apiclient, [self.account_1B]) + + self.debug("Listing VM for account: %s" % self.account_1B.id) + self.apiclient.connection.apiKey = self.user_1B_apikey + self.apiclient.connection.securityKey = self.user_1B_secretkey + list_vm_response = list_virtual_machines( + self.apiclient + ) + self.assertEqual( + isinstance(list_vm_response, list), + True, + "Check list response returns a valid list" + ) + self.assertEqual( + len(list_vm_response), + 1, + "Check VM available in List Virtual Machines" + ) + + self.assertEqual( + list_vm_response[0].name, + self.virtual_machine_1B.name, + "Virtual Machine names do not match" + ) + + return \ No newline at end of file diff --git a/test/integration/smoke/test_vm_life_cycle.py b/test/integration/smoke/test_vm_life_cycle.py index 7d47f70f263..f114ec9024b 100644 --- a/test/integration/smoke/test_vm_life_cycle.py +++ b/test/integration/smoke/test_vm_life_cycle.py @@ -18,138 +18,28 @@ """ #Import Local Modules from marvin.cloudstackTestCase import cloudstackTestCase -from marvin.cloudstackAPI import (detachIso, - attachIso, - recoverVirtualMachine, - destroyVirtualMachine) -from marvin.integration.lib.utils import (cleanup_resources, - validateList, - get_hypervisor_type) -from marvin.integration.lib.base import (Account, - ServiceOffering, - VirtualMachine, - Iso, - Host) -from marvin.integration.lib.common import (get_domain, - get_zone, - get_template, - list_virtual_machines, - list_configurations, - list_routers, - list_isos) -from marvin.codes import PASS +from marvin.codes import FAILED +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 Services: - """Test VM Life Cycle Services - """ - - def __init__(self): - self.services = { - "disk_offering":{ - "displaytext": "Small", - "name": "Small", - "disksize": 1 - }, - "account": { - "email": "test@test.com", - "firstname": "Test", - "lastname": "User", - "username": "test", - # Random characters are appended in create account to - # ensure unique username generated each time - "password": "password", - }, - "small": - # Create a small virtual machine instance with disk offering - { - "displayname": "testserver", - "username": "root", # VM creds for SSH - "password": "password", - "ssh_port": 22, - "hypervisor": 'XenServer', - "privateport": 22, - "publicport": 22, - "protocol": 'TCP', - }, - "medium": # Create a medium virtual machine instance - { - "displayname": "testserver", - "username": "root", - "password": "password", - "ssh_port": 22, - "hypervisor": 'XenServer', - "privateport": 22, - "publicport": 22, - "protocol": 'TCP', - }, - "service_offerings": - { - "tiny": - { - "name": "Tiny Instance", - "displaytext": "Tiny Instance", - "cpunumber": 1, - "cpuspeed": 100, # in MHz - "memory": 128, # In MBs - }, - "small": - { - # Small service offering ID to for change VM - # service offering from medium to small - "name": "Small Instance", - "displaytext": "Small Instance", - "cpunumber": 1, - "cpuspeed": 100, - "memory": 256, - }, - "medium": - { - # Medium service offering ID to for - # change VM service offering from small to medium - "name": "Medium Instance", - "displaytext": "Medium Instance", - "cpunumber": 1, - "cpuspeed": 100, - "memory": 256, - } - }, - "iso": # ISO settings for Attach/Detach ISO tests - { - "displaytext": "Test ISO", - "name": "testISO", - "url": "http://people.apache.org/~tsp/dummy.iso", - # Source URL where ISO is located - "ostype": 'CentOS 5.3 (64-bit)', - "mode": 'HTTP_DOWNLOAD', # Downloading existing ISO - }, - "template": { - "displaytext": "Cent OS Template", - "name": "Cent OS Template", - "passwordenabled": True, - }, - "diskdevice": ['/dev/vdc', '/dev/vdb', '/dev/hdb', '/dev/hdc', '/dev/xvdd', '/dev/cdrom', '/dev/sr0', '/dev/cdrom1' ], - # Disk device where ISO is attached to instance - "mount_dir": "/mnt/tmp", - "sleep": 60, - "timeout": 10, - #Migrate VM to hostid - "ostype": 'CentOS 5.3 (64-bit)', - # CentOS 5.3 (64-bit) - } - class TestDeployVM(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.services = Services().services - cls.apiclient = super(TestDeployVM, cls).getClsTestClient().getApiClient() + testClient = super(TestDeployVM, cls).getClsTestClient() + cls.apiclient = testClient.getApiClient() + cls.services = testClient.getParsedTestDataConfig() + # Get Zone, Domain and templates - domain = get_domain(cls.apiclient, cls.services) - cls.zone = get_zone(cls.apiclient, cls.services) + domain = get_domain(cls.apiclient) + cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype #If local storage is enabled, alter the offerings to use localstorage @@ -164,13 +54,16 @@ class TestDeployVM(cloudstackTestCase): cls.zone.id, cls.services["ostype"] ) + if template == FAILED: + assert False, "get_template() failed to return template with description %s" % cls.services["ostype"] + # Set Zones and disk offerings cls.services["small"]["zoneid"] = cls.zone.id cls.services["small"]["template"] = template.id cls.services["medium"]["zoneid"] = cls.zone.id cls.services["medium"]["template"] = template.id - cls.services["iso"]["zoneid"] = cls.zone.id + cls.services["iso1"]["zoneid"] = cls.zone.id cls.account = Account.create( cls.apiclient, @@ -303,12 +196,13 @@ class TestVMLifeCycle(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestVMLifeCycle, cls).getClsTestClient().getApiClient() - cls.services = Services().services + testClient = super(TestVMLifeCycle, cls).getClsTestClient() + cls.apiclient = testClient.getApiClient() + cls.services = testClient.getParsedTestDataConfig() # Get Zone, Domain and templates - domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + domain = get_domain(cls.apiclient) + cls.zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype #if local storage is enabled, alter the offerings to use localstorage @@ -319,37 +213,40 @@ class TestVMLifeCycle(cloudstackTestCase): cls.services["service_offerings"]["medium"]["storagetype"] = 'local' template = get_template( - cls.api_client, + cls.apiclient, cls.zone.id, cls.services["ostype"] ) + if template == FAILED: + assert False, "get_template() failed to return template with description %s" % cls.services["ostype"] + # Set Zones and disk offerings cls.services["small"]["zoneid"] = cls.zone.id cls.services["small"]["template"] = template.id cls.services["medium"]["zoneid"] = cls.zone.id cls.services["medium"]["template"] = template.id - cls.services["iso"]["zoneid"] = cls.zone.id + cls.services["iso1"]["zoneid"] = cls.zone.id # Create VMs, NAT Rules etc cls.account = Account.create( - cls.api_client, + cls.apiclient, cls.services["account"], domainid=domain.id ) cls.small_offering = ServiceOffering.create( - cls.api_client, + cls.apiclient, cls.services["service_offerings"]["small"] ) cls.medium_offering = ServiceOffering.create( - cls.api_client, + cls.apiclient, cls.services["service_offerings"]["medium"] ) #create small and large virtual machines cls.small_virtual_machine = VirtualMachine.create( - cls.api_client, + cls.apiclient, cls.services["small"], accountid=cls.account.name, domainid=cls.account.domainid, @@ -357,7 +254,7 @@ class TestVMLifeCycle(cloudstackTestCase): mode=cls.services["mode"] ) cls.medium_virtual_machine = VirtualMachine.create( - cls.api_client, + cls.apiclient, cls.services["medium"], accountid=cls.account.name, domainid=cls.account.domainid, @@ -365,7 +262,7 @@ class TestVMLifeCycle(cloudstackTestCase): mode=cls.services["mode"] ) cls.virtual_machine = VirtualMachine.create( - cls.api_client, + cls.apiclient, cls.services["small"], accountid=cls.account.name, domainid=cls.account.domainid, @@ -380,8 +277,8 @@ class TestVMLifeCycle(cloudstackTestCase): @classmethod def tearDownClass(cls): - cls.api_client = super(TestVMLifeCycle, cls).getClsTestClient().getApiClient() - cleanup_resources(cls.api_client, cls._cleanup) + cls.apiclient = super(TestVMLifeCycle, cls).getClsTestClient().getApiClient() + cleanup_resources(cls.apiclient, cls._cleanup) return def setUp(self): @@ -628,7 +525,7 @@ class TestVMLifeCycle(cloudstackTestCase): #deploy VM on target host self.vm_to_migrate = VirtualMachine.create( - self.api_client, + self.apiclient, self.services["small"], accountid=self.account.name, domainid=self.account.domainid, @@ -641,7 +538,7 @@ class TestVMLifeCycle(cloudstackTestCase): migrate_host.id )) - self.vm_to_migrate.migrate(self.api_client, migrate_host.id) + self.vm_to_migrate.migrate(self.apiclient, migrate_host.id) list_vm_response = list_virtual_machines( self.apiclient, @@ -733,7 +630,7 @@ class TestVMLifeCycle(cloudstackTestCase): iso = Iso.create( self.apiclient, - self.services["iso"], + self.services["iso1"], account=self.account.name, domainid=self.account.domainid ) @@ -760,12 +657,13 @@ class TestVMLifeCycle(cloudstackTestCase): except Exception as e: self.fail("SSH failed for virtual machine: %s - %s" % (self.virtual_machine.ipaddress, e)) - - cmds = "mkdir -p %s" % self.services["mount_dir"] + + mount_dir = "/mnt/tmp" + cmds = "mkdir -p %s" % mount_dir self.assert_(ssh_client.execute(cmds) == [], "mkdir failed within guest") for diskdevice in self.services["diskdevice"]: - res = ssh_client.execute("mount -rt iso9660 {} {}".format(diskdevice, self.services["mount_dir"])) + res = ssh_client.execute("mount -rt iso9660 {} {}".format(diskdevice, mount_dir)) if res == []: self.services["mount"] = diskdevice break @@ -790,7 +688,7 @@ class TestVMLifeCycle(cloudstackTestCase): try: #Unmount ISO - command = "umount %s" % self.services["mount_dir"] + command = "umount %s" % mount_dir ssh_client.execute(command) except Exception as e: self.fail("SSH failed for virtual machine: %s - %s" % diff --git a/test/integration/smoke/test_vm_snapshots.py b/test/integration/smoke/test_vm_snapshots.py index 65a5acbce39..e884d42dcfd 100644 --- a/test/integration/smoke/test_vm_snapshots.py +++ b/test/integration/smoke/test_vm_snapshots.py @@ -16,83 +16,33 @@ # under the License. # Import Local Modules -import marvin +from marvin.codes import FAILED from nose.plugins.attrib import attr from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * - -class Services: - """Test Snapshots Services - """ - - def __init__(self): - self.services = { - "account": { - "email": "test@test.com", - "firstname": "Test", - "lastname": "User", - "username": "test", - # Random characters are appended for unique - # username - "password": "password", - }, - "service_offering": { - "name": "Tiny Instance", - "displaytext": "Tiny Instance", - "cpunumber": 1, - "cpuspeed": 200, # in MHz - "memory": 256, # In MBs - }, - "server": { - "displayname": "TestVM", - "username": "root", - "password": "password", - "ssh_port": 22, - "hypervisor": 'XenServer', - "privateport": 22, - "publicport": 22, - "protocol": 'TCP', - }, - "mgmt_server": { - "ipaddress": '1.2.2.152', - "username": "root", - "password": "password", - "port": 22, - }, - "templates": { - "displaytext": 'Template', - "name": 'Template', - "ostype": "CentOS 5.3 (64-bit)", - "templatefilter": 'self', - }, - "test_dir": "/tmp", - "random_data": "random.data", - "snapshot_name": "TestSnapshot", - "snapshot_displaytext": "Test", - "ostype": "CentOS 5.3 (64-bit)", - "sleep": 60, - "timeout": 10, - "mode": 'advanced', # Networking mode: Advanced, Basic - } +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * class TestVmSnapshot(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestVmSnapshot, cls).getClsTestClient().getApiClient() - cls.services = Services().services + testClient = super(TestVmSnapshot, cls).getClsTestClient() + cls.apiclient = testClient.getApiClient() + cls.services = testClient.getParsedTestDataConfig() # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.apiclient) + cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests()) template = get_template( - cls.api_client, + cls.apiclient, cls.zone.id, cls.services["ostype"] ) + if template == FAILED: + assert False, "get_template() failed to return template with description %s" % cls.services["ostype"] + cls.services["domainid"] = cls.domain.id cls.services["server"]["zoneid"] = cls.zone.id cls.services["templates"]["ostypeid"] = template.ostypeid @@ -100,27 +50,27 @@ class TestVmSnapshot(cloudstackTestCase): # Create VMs, NAT Rules etc cls.account = Account.create( - cls.api_client, + cls.apiclient, cls.services["account"], domainid=cls.domain.id ) - cls.services["account"] = cls.account.name - cls.service_offering = ServiceOffering.create( - cls.api_client, - cls.services["service_offering"] + cls.apiclient, + cls.services["service_offerings"] ) cls.virtual_machine = VirtualMachine.create( - cls.api_client, + cls.apiclient, cls.services["server"], templateid=template.id, accountid=cls.account.name, domainid=cls.account.domainid, serviceofferingid=cls.service_offering.id, - mode=cls.services["mode"] + mode=cls.zone.networktype ) cls.random_data_0 = random_gen(size=100) + cls.test_dir = "/tmp" + cls.random_data = "random.data" cls._cleanup = [ cls.service_offering, cls.account, @@ -131,7 +81,7 @@ class TestVmSnapshot(cloudstackTestCase): def tearDownClass(cls): try: # Cleanup resources used - cleanup_resources(cls.api_client, cls._cleanup) + cleanup_resources(cls.apiclient, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) return @@ -160,8 +110,8 @@ class TestVmSnapshot(cloudstackTestCase): ssh_client = self.virtual_machine.get_ssh_client() cmds = [ - "echo %s > %s/%s" % (self.random_data_0, self.services["test_dir"], self.services["random_data"]), - "cat %s/%s" % (self.services["test_dir"], self.services["random_data"]) + "echo %s > %s/%s" % (self.random_data_0, self.test_dir, self.random_data), + "cat %s/%s" % (self.test_dir, self.random_data) ] for c in cmds: @@ -184,8 +134,8 @@ class TestVmSnapshot(cloudstackTestCase): self.apiclient, self.virtual_machine.id, "false", - self.services["snapshot_name"], - self.services["snapshot_displaytext"] + "TestSnapshot", + "Dsiplay Text" ) self.assertEqual( vm_snapshot.state, @@ -203,8 +153,8 @@ class TestVmSnapshot(cloudstackTestCase): ssh_client = self.virtual_machine.get_ssh_client() cmds = [ - "rm -rf %s/%s" % (self.services["test_dir"], self.services["random_data"]), - "ls %s/%s" % (self.services["test_dir"], self.services["random_data"]) + "rm -rf %s/%s" % (self.test_dir, self.random_data), + "ls %s/%s" % (self.test_dir, self.random_data) ] for c in cmds: @@ -263,7 +213,7 @@ class TestVmSnapshot(cloudstackTestCase): ssh_client = self.virtual_machine.get_ssh_client(reconnect=True) cmds = [ - "cat %s/%s" % (self.services["test_dir"], self.services["random_data"]) + "cat %s/%s" % (self.test_dir, self.random_data) ] for c in cmds: diff --git a/test/integration/smoke/test_volumes.py b/test/integration/smoke/test_volumes.py index d358c8ad339..f3115afb1df 100644 --- a/test/integration/smoke/test_volumes.py +++ b/test/integration/smoke/test_volumes.py @@ -17,14 +17,15 @@ """ BVT tests for Volumes """ #Import Local Modules -import marvin from marvin.cloudstackTestCase import * from marvin.cloudstackException import * from marvin.cloudstackAPI import * from marvin.sshClient import SshClient -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * +from marvin.lib.utils import checkVolumeSize +from marvin.codes import SUCCESS from nose.plugins.attrib import attr #Import System modules import os @@ -34,103 +35,55 @@ import tempfile _multiprocess_shared_ = True -class Services: - """Test Volume Services - """ - - def __init__(self): - self.services = { - "account": { - "email": "test@test.com", - "firstname": "Test", - "lastname": "User", - "username": "test", - # Random characters are appended for unique - # username - "password": "password", - }, - "service_offering": { - "name": "Tiny Instance", - "displaytext": "Tiny Instance", - "cpunumber": 1, - "cpuspeed": 100, # in MHz - "memory": 260 # In MBs - - }, - "disk_offering": { - "displaytext": "Small", - "name": "Small", - "disksize": 1 - }, - 'resized_disk_offering': { - "displaytext": "Resized", - "name": "Resized", - "disksize": 3 - }, - "volume_offerings": { - 0: { - "diskname": "TestDiskServ", - }, - }, - "customdisksize": 1, # GBs - "username": "root", # Creds for SSH to VM - "password": "password", - "ssh_port": 22, - "diskname": "TestDiskServ", - "hypervisor": 'KVM', - "privateport": 22, - "publicport": 22, - "protocol": 'TCP', - "ostype": 'CentOS 5.5 (64-bit)', - "sleep": 10, - "timeout": 600, - } - - class TestCreateVolume(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestCreateVolume, cls).getClsTestClient().getApiClient() - cls.services = Services().services - + testClient = super(TestCreateVolume, cls).getClsTestClient() + cls.apiclient = testClient.getApiClient() + cls.services = testClient.getParsedTestDataConfig() # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.apiclient) + cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype cls.disk_offering = DiskOffering.create( - cls.api_client, + cls.apiclient, cls.services["disk_offering"] ) + cls.sparse_disk_offering = DiskOffering.create( + cls.apiclient, + cls.services["sparse_disk_offering"] + ) cls.custom_disk_offering = DiskOffering.create( - cls.api_client, + cls.apiclient, cls.services["disk_offering"], custom=True ) template = get_template( - cls.api_client, + cls.apiclient, cls.zone.id, cls.services["ostype"] ) + if template == FAILED: + assert False, "get_template() failed to return template with description %s" % cls.services["ostype"] + cls.services["domainid"] = cls.domain.id cls.services["zoneid"] = cls.zone.id cls.services["template"] = template.id cls.services["customdiskofferingid"] = cls.custom_disk_offering.id - + cls.services["diskname"] = cls.services["volume"]["diskname"] # Create VMs, NAT Rules etc cls.account = Account.create( - cls.api_client, + cls.apiclient, cls.services["account"], domainid=cls.domain.id ) - - cls.services["account"] = cls.account.name cls.service_offering = ServiceOffering.create( - cls.api_client, - cls.services["service_offering"] + cls.apiclient, + cls.services["service_offerings"] ) cls.virtual_machine = VirtualMachine.create( - cls.api_client, + cls.apiclient, cls.services, accountid=cls.account.name, domainid=cls.account.domainid, @@ -172,6 +125,18 @@ class TestCreateVolume(cloudstackTestCase): self.debug("Created a volume with ID: %s" % volume.id) self.volumes.append(volume) + if self.virtual_machine.hypervisor == "KVM": + sparse_volume = Volume.create( + self.apiClient, + self.services, + zoneid=self.zone.id, + account=self.account.name, + domainid=self.account.domainid, + diskofferingid=self.sparse_disk_offering.id + ) + self.debug("Created a sparse volume: %s" % sparse_volume.id) + self.volumes.append(sparse_volume) + volume = Volume.create_custom_disk( self.apiClient, self.services, @@ -227,7 +192,6 @@ class TestCreateVolume(cloudstackTestCase): ) if isinstance(list_vm_response, list): - vm = list_vm_response[0] if vm.state == 'Running': self.debug("VM state: %s" % vm.state) @@ -236,31 +200,17 @@ class TestCreateVolume(cloudstackTestCase): if timeout == 0: raise Exception( "Failed to start VM (ID: %s) " % vm.id) - timeout = timeout - 1 - try: - ssh = self.virtual_machine.get_ssh_client( + vol_sz = str(list_volume_response[0].size) + ssh = self.virtual_machine.get_ssh_client( reconnect=True ) - c = "/sbin/fdisk -l" - res = ssh.execute(c) - - except Exception as e: - self.fail("SSH access failed for VM: %s - %s" % - (self.virtual_machine.ipaddress, e)) - - # Disk /dev/sda doesn't contain a valid partition table - # Disk /dev/sda: 21.5 GB, 21474836480 bytes - result = str(res) - self.debug("fdisk result: %s" % result) - - self.assertEqual( - str(list_volume_response[0].size) in result, - True, - "Check if promised disk size actually available" - ) + ret = checkVolumeSize(ssh_handle=ssh,size_to_verify=vol_sz) + self.debug(" Volume Size Expected %s Actual :%s" %(vol_sz,ret[1])) self.virtual_machine.detach_volume(self.apiClient, volume) + self.assertEqual(ret[0],SUCCESS,"Check if promised disk size actually available") + time.sleep(self.services["sleep"]) def tearDown(self): #Clean up, terminate the created volumes @@ -270,8 +220,8 @@ class TestCreateVolume(cloudstackTestCase): @classmethod def tearDownClass(cls): try: - cls.api_client = super(TestCreateVolume, cls).getClsTestClient().getApiClient() - cleanup_resources(cls.api_client, cls._cleanup) + cls.apiclient = super(TestCreateVolume, cls).getClsTestClient().getApiClient() + cleanup_resources(cls.apiclient, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) @@ -280,31 +230,36 @@ class TestVolumes(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.api_client = super(TestVolumes, cls).getClsTestClient().getApiClient() - cls.services = Services().services + testClient = super(TestVolumes, cls).getClsTestClient() + cls.apiclient = testClient.getApiClient() + cls.services = testClient.getParsedTestDataConfig() + # Get Zone, Domain and templates - cls.domain = get_domain(cls.api_client, cls.services) - cls.zone = get_zone(cls.api_client, cls.services) + cls.domain = get_domain(cls.apiclient) + cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests()) cls.services['mode'] = cls.zone.networktype cls.disk_offering = DiskOffering.create( - cls.api_client, + cls.apiclient, cls.services["disk_offering"] ) cls.resized_disk_offering = DiskOffering.create( - cls.api_client, + cls.apiclient, cls.services["resized_disk_offering"] ) cls.custom_resized_disk_offering = DiskOffering.create( - cls.api_client, + cls.apiclient, cls.services["resized_disk_offering"], custom=True ) template = get_template( - cls.api_client, + cls.apiclient, cls.zone.id, cls.services["ostype"] ) + if template == FAILED: + assert False, "get_template() failed to return template with description %s" % cls.services["ostype"] + cls.services["domainid"] = cls.domain.id cls.services["zoneid"] = cls.zone.id cls.services["template"] = template.id @@ -314,18 +269,16 @@ class TestVolumes(cloudstackTestCase): # Create VMs, VMs etc cls.account = Account.create( - cls.api_client, + cls.apiclient, cls.services["account"], domainid=cls.domain.id ) - - cls.services["account"] = cls.account.name cls.service_offering = ServiceOffering.create( - cls.api_client, - cls.services["service_offering"] + cls.apiclient, + cls.services["service_offerings"] ) cls.virtual_machine = VirtualMachine.create( - cls.api_client, + cls.apiclient, cls.services, accountid=cls.account.name, domainid=cls.account.domainid, @@ -334,7 +287,7 @@ class TestVolumes(cloudstackTestCase): ) cls.volume = Volume.create( - cls.api_client, + cls.apiclient, cls.services, account=cls.account.name, domainid=cls.account.domainid @@ -351,7 +304,7 @@ class TestVolumes(cloudstackTestCase): @classmethod def tearDownClass(cls): try: - cleanup_resources(cls.api_client, cls._cleanup) + cleanup_resources(cls.apiclient, cls._cleanup) except Exception as e: raise Exception("Warning: Exception during cleanup : %s" % e) @@ -767,7 +720,7 @@ class TestVolumes(cloudstackTestCase): self.debug("Delete Volume ID: %s" % self.volume.id) self.volume_1 = Volume.create( - self.api_client, + self.apiclient, self.services, account=self.account.name, domainid=self.account.domainid diff --git a/test/integration/smoke/test_vpc_vpn.py b/test/integration/smoke/test_vpc_vpn.py index d06fd29abb2..1b2844781a2 100644 --- a/test/integration/smoke/test_vpc_vpn.py +++ b/test/integration/smoke/test_vpc_vpn.py @@ -17,105 +17,29 @@ """ Tests for VPN in VPC """ #Import Local Modules +from marvin.codes import FAILED from marvin.cloudstackTestCase import * from marvin.cloudstackAPI import * -from marvin.integration.lib.utils import * -from marvin.integration.lib.base import * -from marvin.integration.lib.common import * +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.lib.common import * from nose.plugins.attrib import attr import time -class Services: - def __init__(self): - self.services = { - "account": { - "email": "test@test.com", - "firstname": "Test", - "lastname": "User", - "username": "test", - "password": "password", - }, - "virtual_machine": { - "displayname": "Test VM", - "username": "root", - "password": "password", - "ssh_port": 22, - "hypervisor": 'XenServer', - "privateport": 22, - "publicport": 22, - "protocol": 'TCP', - }, - "ostype": 'CentOS 5.3 (64-bit)', - "service_offering": { - "name": "Tiny Instance", - "displaytext": "Tiny Instance", - "cpunumber": 1, - "cpuspeed": 100, - "memory": 256, - }, - "network_offering": { - "name": "Network offering for internal vpc", - "displaytext": "Network offering for internal vpc", - "guestiptype": "Isolated", - "traffictype": "Guest", - "supportedservices": "Vpn,Dhcp,Dns,Lb,UserData,SourceNat,StaticNat,PortForwarding,NetworkACL", - "serviceProviderList": { - "Dhcp": "VpcVirtualRouter", - "Dns": "VpcVirtualRouter", - "Vpn": "VpcVirtualRouter", - "UserData": "VpcVirtualRouter", - "Lb": "InternalLbVM", - "SourceNat": "VpcVirtualRouter", - "StaticNat": "VpcVirtualRouter", - "PortForwarding": "VpcVirtualRouter", - "NetworkACL": "VpcVirtualRouter", - }, - "serviceCapabilityList": { - "SourceNat": {"SupportedSourceNatTypes": "peraccount"}, - "Lb": {"lbSchemes": "internal", "SupportedLbIsolation": "dedicated"} - } - }, - "vpn_user": { - "username": "test", - "password": "password", - }, - "vpc": { - "name": "vpc_vpn", - "displaytext": "vpc-vpn", - "cidr": "10.1.1.0/24" - }, - "ntwk": { - "name": "tier1", - "displaytext": "vpc-tier1", - "gateway" : "10.1.1.1", - "netmask" : "255.255.255.192" - }, - "vpc2": { - "name": "vpc2_vpn", - "displaytext": "vpc2-vpn", - "cidr": "10.2.1.0/24" - }, - "ntwk2": { - "name": "tier2", - "displaytext": "vpc-tier2", - "gateway" : "10.2.1.1", - "netmask" : "255.255.255.192" - } - } - - class TestVpcRemoteAccessVpn(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.apiclient = super(TestVpcRemoteAccessVpn, cls).getClsTestClient().getApiClient() - cls.services = Services().services - cls.zone = get_zone(cls.apiclient, cls.services) + testClient = super(TestVpcRemoteAccessVpn, cls).getClsTestClient() + cls.apiclient = testClient.getApiClient() + cls.services = testClient.getParsedTestDataConfig() + + cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests()) cls.domain = get_domain(cls.apiclient) cls.service_offering = ServiceOffering.create( cls.apiclient, - cls.services["service_offering"] + cls.services["service_offerings"] ) cls.account = Account.create(cls.apiclient, services=cls.services["account"]) cls.template = get_template( @@ -123,6 +47,9 @@ class TestVpcRemoteAccessVpn(cloudstackTestCase): cls.zone.id, cls.services["ostype"] ) + if cls.template == FAILED: + assert False, "get_template() failed to return template with description %s" % cls.services["ostype"] + cls.cleanup = [cls.account] @attr(tags=["advanced", "selfservice"]) @@ -211,13 +138,15 @@ class TestVpcSite2SiteVpn(cloudstackTestCase): @classmethod def setUpClass(cls): - cls.apiclient = super(TestVpcSite2SiteVpn, cls).getClsTestClient().getApiClient() - cls.services = Services().services - cls.zone = get_zone(cls.apiclient, cls.services) + testClient = super(TestVpcSite2SiteVpn, cls).getClsTestClient() + cls.apiclient = testClient.getApiClient() + cls.services = testClient.getParsedTestDataConfig() + + cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests()) cls.domain = get_domain(cls.apiclient) cls.service_offering = ServiceOffering.create( cls.apiclient, - cls.services["service_offering"] + cls.services["service_offerings"] ) cls.account = Account.create(cls.apiclient, services=cls.services["account"]) cls.template = get_template( @@ -225,6 +154,9 @@ class TestVpcSite2SiteVpn(cloudstackTestCase): cls.zone.id, cls.services["ostype"] ) + if cls.template == FAILED: + assert False, "get_template() failed to return template with description %s" % cls.services["ostype"] + cls.cleanup = [cls.account] @attr(tags=["advanced", "selfservice"], BugId="CLOUDSTACK-6879") diff --git a/tools/marvin/marvin/__init__.py b/tools/marvin/marvin/__init__.py index 7af168e20bc..7102e3f3107 100644 --- a/tools/marvin/marvin/__init__.py +++ b/tools/marvin/marvin/__init__.py @@ -15,4 +15,4 @@ # specific language governing permissions and limitations # under the License. -#Marvin - The cloudstack test client +# Marvin - The cloudstack test client diff --git a/tools/marvin/marvin/asyncJobMgr.py b/tools/marvin/marvin/asyncJobMgr.py index e24170e18ff..00e8c19b3ce 100644 --- a/tools/marvin/marvin/asyncJobMgr.py +++ b/tools/marvin/marvin/asyncJobMgr.py @@ -16,7 +16,7 @@ # under the License. import threading -import cloudstackException +from marvin import cloudstackException import time import Queue import copy @@ -26,12 +26,14 @@ import datetime class job(object): + def __init__(self): self.id = None self.cmd = None class jobStatus(object): + def __init__(self): self.result = None self.status = None @@ -47,6 +49,7 @@ class jobStatus(object): class workThread(threading.Thread): + def __init__(self, in_queue, outqueue, apiClient, db=None, lock=None): threading.Thread.__init__(self) self.inqueue = in_queue @@ -62,7 +65,7 @@ class workThread(threading.Thread): try: self.lock.acquire() result = self.connection.poll(job.jobId, job.responsecls).jobresult - except cloudstackException.cloudstackAPIException, e: + except cloudstackException.CloudstackAPIException as e: result = str(e) finally: self.lock.release() @@ -102,7 +105,7 @@ class workThread(threading.Thread): except: pass jobstatus.status = True - except cloudstackException.cloudstackAPIException, e: + except cloudstackException.CloudstackAPIException as e: jobstatus.result = str(e) jobstatus.status = False except: @@ -129,6 +132,7 @@ class workThread(threading.Thread): class jobThread(threading.Thread): + def __init__(self, inqueue, interval): threading.Thread.__init__(self) self.inqueue = inqueue @@ -149,12 +153,14 @@ class jobThread(threading.Thread): class outputDict(object): + def __init__(self): self.lock = threading.Condition() self.dict = {} class asyncJobMgr(object): + def __init__(self, apiClient, db): self.inqueue = Queue.Queue() self.output = outputDict() diff --git a/tools/marvin/marvin/cloudstackConnection.py b/tools/marvin/marvin/cloudstackConnection.py index fb03e3be3ac..d006002ae0f 100644 --- a/tools/marvin/marvin/cloudstackConnection.py +++ b/tools/marvin/marvin/cloudstackConnection.py @@ -21,21 +21,35 @@ import base64 import hmac import hashlib import time -import cloudstackException from cloudstackAPI import * 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 GetDetailExceptionInfo -class cloudConnection(object): +class CSConnection(object): + + ''' + @Desc: Connection Class to make API\Command calls to the + CloudStack Management Server + Sends the GET\POST requests to CS based upon the + information provided and retrieves the parsed response. + ''' - """ Connections to make API calls to the cloudstack management server - """ def __init__(self, mgmtDet, asyncTimeout=3600, logger=None, path='client/api'): self.apiKey = mgmtDet.apiKey @@ -44,68 +58,93 @@ class cloudConnection(object): self.port = mgmtDet.port self.user = mgmtDet.user self.passwd = mgmtDet.passwd - self.certCAPath = mgmtDet.certCAPath - self.certPath = mgmtDet.certPath + self.certPath = () + if mgmtDet.certCAPath != "NA" and mgmtDet.certPath != "NA": + self.certPath = (mgmtDet.certCAPath, mgmtDet.certPath) self.logger = logger self.path = path self.retries = 5 + self.__lastError = '' self.mgtDetails = mgmtDet - self.protocol = "http" self.asyncTimeout = asyncTimeout self.auth = True if self.port == 8096 or \ (self.apiKey is None and self.securityKey is None): self.auth = False - if mgmtDet.useHttps == "True": - self.protocol = "https" - self.baseurl = "%s://%s:%d/%s"\ + self.protocol = "https" if mgmtDet.useHttps == "True" else "http" + self.httpsFlag = True if self.protocol == "https" else False + self.baseUrl = "%s://%s:%d/%s"\ % (self.protocol, self.mgtSvr, self.port, self.path) def __copy__(self): - return cloudConnection(self.mgtDetails, - self.asyncTimeout, - self.logger, - self.path) + return CSConnection(self.mgtDetails, + self.asyncTimeout, + self.logger, + self.path) - def poll(self, jobid, response): + def __poll(self, jobid, response_cmd): + ''' + @Name : __poll + @Desc: polls for the completion of a given jobid + @Input 1. jobid: Monitor the Jobid for CS + 2. response_cmd:response command for request cmd + @return: FAILED if jobid is cancelled,failed + Else return async_response + ''' + try: + cmd = queryAsyncJobResult.queryAsyncJobResultCmd() + cmd.jobid = jobid + timeout = self.asyncTimeout + start_time = time.time() + end_time = time.time() + async_response = FAILED + self.logger.debug("=== Jobid: %s Started ===" % (str(jobid))) + while timeout > 0: + async_response = self.\ + marvinRequest(cmd, response_type=response_cmd) + if async_response != FAILED: + job_status = async_response.jobstatus + if job_status in [JOB_FAILED, + JOB_CANCELLED, + JOB_SUCCEEDED]: + break + time.sleep(5) + timeout -= 5 + self.logger.debug("=== JobId:%s is Still Processing, " + "Will TimeOut in:%s ====" % (str(jobid), + str(timeout))) + end_time = time.time() + tot_time = int(start_time - end_time) + self.logger.debug( + "===Jobid:%s ; StartTime:%s ; EndTime:%s ; " + "TotalTime:%s===" % + (str(jobid), str(time.ctime(start_time)), + str(time.ctime(end_time)), str(tot_time))) + return async_response + except Exception as e: + self.__lastError = e + self.logger.exception("==== __poll: Exception Occurred :%s ====" % + str(self.__lastError)) + return FAILED + + def getLastError(self): + ''' + @Name : getLastError + @Desc : Returns the last error from marvinRequest + ''' + return self.__lastError + + def __sign(self, payload): """ - polls the completion of a given jobid - @param jobid: - @param response: - @return: - """ - cmd = queryAsyncJobResult.queryAsyncJobResultCmd() - cmd.jobid = jobid - timeout = self.asyncTimeout - - while timeout > 0: - asyncResonse = self.marvinRequest(cmd, response_type=response) - - if asyncResonse.jobstatus == 2: - raise cloudstackException.cloudstackAPIException( - "asyncquery", asyncResonse.jobresult) - elif asyncResonse.jobstatus == 1: - return asyncResonse - - time.sleep(5) - if self.logger is not None: - self.logger.debug("job: %s still processing," - "will timeout in %ds" % (jobid, timeout)) - timeout = timeout - 5 - - raise cloudstackException.cloudstackAPIException( - "asyncquery", "Async job timeout %s" % jobid) - - def sign(self, payload): - """ - signs a given request URL when the apiKey and secretKey are known - - @param payload: dict of GET params to be signed - @return: the signature of the payload + @Name : __sign + @Desc:signs a given request URL when the apiKey and + secretKey are known + @Input: payload: dictionary of params be signed + @Output: the signature of the payload """ params = zip(payload.keys(), payload.values()) params.sort(key=lambda k: str.lower(k[0])) - hashStr = "&".join( + hash_str = "&".join( ["=".join( [str.lower(r[0]), str.lower( @@ -114,168 +153,219 @@ class cloudConnection(object): ) for r in params] ) signature = base64.encodestring(hmac.new( - self.securityKey, hashStr, hashlib.sha1).digest()).strip() - self.logger.debug("Computed Signature by Marvin: %s" % signature) + self.securityKey, hash_str, hashlib.sha1).digest()).strip() return signature - def request(self, command, auth=True, payload={}, method='GET'): - """ - Makes requests using auth or over integration port - @param command: cloudstack API command name - eg: deployVirtualMachineCommand - @param auth: Authentication (apikey,secretKey) => True - else False for integration.api.port - @param payload: request data composed as a dictionary - @param method: GET/POST via HTTP - @return: - """ - payload["command"] = command - payload["response"] = "json" - - if auth: - payload["apiKey"] = self.apiKey - signature = self.sign(payload) - payload["signature"] = signature - + def __sendPostReqToCS(self, url, payload): + ''' + @Name : __sendPostReqToCS + @Desc : Sends the POST Request to CS + @Input : url: URL to send post req + payload:Payload information as part of request + @Output: Returns response from POST output + else FAILED + ''' try: - #https_flag : Signifies whether to verify connection over \ - #http or https, \ - #initialized to False, will be set to true if user provided https - #connection - https_flag = False - cert_path = () - if self.protocol == "https": - https_flag = True - if self.certCAPath != "NA" and self.certPath != "NA": - cert_path = (self.certCAPath, self.certPath) - - #Verify whether protocol is "http", then call the request over http - if self.protocol == "http": - if method == 'POST': - response = requests.post(self.baseurl, params=payload, - verify=https_flag) - else: - response = requests.get(self.baseurl, params=payload, - verify=https_flag) - else: - ''' - If protocol is https, then create the connection url with \ - user provided certificates \ - provided as part of cert - ''' - try: - if method == 'POST': - response = requests.post(self.baseurl, - params=payload, - cert=cert_path, - verify=https_flag) - else: - response = requests.get(self.baseurl, params=payload, - cert=cert_path, - verify=https_flag) - except Exception, e: - ''' - If an exception occurs with user provided CA certs, \ - then try with default certs, \ - we dont need to mention here the cert path - ''' - self.logger.debug("Creating CS connection over https \ - didnt worked with user provided certs \ - , so trying with no certs %s" % e) - if method == 'POST': - response = requests.post(self.baseurl, - params=payload, - verify=https_flag) - else: - response = requests.get(self.baseurl, - params=payload, - verify=https_flag) - except ConnectionError, c: - self.logger.debug("Connection refused. Reason: %s : %s" % - (self.baseurl, c)) - raise c - except HTTPError, h: - self.logger.debug("Http Error.Server returned error code: %s" % h) - raise h - except Timeout, t: - self.logger.debug("Connection timed out with %s" % t) - raise t - except RequestException, r: - self.logger.debug("RequestException from server %s" % r) - raise r - except Exception, e: - self.logger.debug("Error returned by server %s" % r) - raise e - else: + response = requests.post(url, + params=payload, + cert=self.certPath, + verify=self.httpsFlag) return response + except Exception as e: + self.__lastError = e + self.logger.\ + exception("__sendPostReqToCS : Exception " + "Occurred: %s" % str(self.__lastError)) + return FAILED - def sanitizeCommand(self, cmd): - """ - Removes None values, Validates all required params are present - @param cmd: Cmd object eg: createPhysicalNetwork - @return: - """ - requests = {} - required = [] - for attribute in dir(cmd): - if not attribute.startswith('__'): - if attribute == "isAsync": - isAsync = getattr(cmd, attribute) - elif attribute == "required": - required = getattr(cmd, attribute) - else: - requests[attribute] = getattr(cmd, attribute) + def __sendGetReqToCS(self, url, payload): + ''' + @Name : __sendGetReqToCS + @Desc : Sends the GET Request to CS + @Input : url: URL to send post req + payload:Payload information as part of request + @Output: Returns response from GET output + else FAILED + ''' + try: + response = requests.get(url, + params=payload, + cert=self.certPath, + verify=self.httpsFlag) + return response + except Exception as e: + self.__lastError = e + self.logger.exception("__sendGetReqToCS : Exception Occurred: %s" % + str(self.__lastError)) + return FAILED - cmdname = cmd.__class__.__name__.replace("Cmd", "") - for requiredPara in required: - if requests[requiredPara] is None: - raise cloudstackException.cloudstackAPIException( - cmdname, "%s is required" % requiredPara) - for param, value in requests.items(): - if value is None: - requests.pop(param) - elif isinstance(value, list): - if len(value) == 0: - requests.pop(param) - else: - if not isinstance(value[0], dict): - requests[param] = ",".join(value) + def __sendCmdToCS(self, command, auth=True, payload={}, method='GET'): + """ + @Name : __sendCmdToCS + @Desc : Makes requests to CS using the Inputs provided + @Input: command: cloudstack API command name + eg: deployVirtualMachineCommand + auth: Authentication (apikey,secretKey) => True + else False for integration.api.port + payload: request data composed as a dictionary + method: GET/POST via HTTP + @output: FAILED or else response from CS + """ + try: + payload["command"] = command + payload["response"] = "json" + + if auth: + payload["apiKey"] = self.apiKey + payload["signature"] = self.__sign(payload) + + # Verify whether protocol is "http" or "https", then send the + # request + if self.protocol in ["http", "https"]: + self.logger.debug("Payload: %s" % str(payload)) + if method == 'POST': + self.logger.debug("=======Sending POST Cmd : %s=======" + % str(command)) + return self.__sendPostReqToCS(self.baseUrl, payload) + if method == "GET": + self.logger.debug("========Sending GET Cmd : %s=======" + % str(command)) + return self.__sendGetReqToCS(self.baseUrl, payload) + else: + self.logger.exception("__sendCmdToCS: Invalid Protocol") + return FAILED + except Exception as e: + self.logger.exception("__sendCmdToCS: Exception:%s" % + GetDetailExceptionInfo(e)) + return FAILED + + def __sanitizeCmd(self, cmd): + """ + @Name : __sanitizeCmd + @Desc : Removes None values, Validates all required params are present + @Input: cmd: Cmd object eg: createPhysicalNetwork + @Output: Returns command name, asynchronous or not,request payload + FAILED for failed cases + """ + try: + cmd_name = '' + payload = {} + required = [] + isAsync = "false" + for attribute in dir(cmd): + if not attribute.startswith('__'): + if attribute == "isAsync": + isAsync = getattr(cmd, attribute) + elif attribute == "required": + required = getattr(cmd, attribute) else: - requests.pop(param) - i = 0 - for val in value: - for k, v in val.iteritems(): - requests["%s[%d].%s" % (param, i, k)] = v - i = i + 1 - return cmdname.strip(), isAsync, requests + payload[attribute] = getattr(cmd, attribute) + cmd_name = cmd.__class__.__name__.replace("Cmd", "") + for required_param in required: + if payload[required_param] is None: + self.logger.debug("CmdName: %s Parameter : %s is Required" + % (cmd_name, required_param)) + return FAILED + for param, value in payload.items(): + if value is None: + payload.pop(param) + elif isinstance(value, list): + if len(value) == 0: + payload.pop(param) + else: + if not isinstance(value[0], dict): + payload[param] = ",".join(value) + else: + payload.pop(param) + i = 0 + for val in value: + for k, v in val.iteritems(): + payload["%s[%d].%s" % (param, i, k)] = v + i += 1 + return cmd_name.strip(), isAsync, payload + except Exception as e: + self.logger.\ + exception("__sanitizeCmd: CmdName : " + "%s : Exception:%s" % (cmd_name, + GetDetailExceptionInfo(e))) + return FAILED + + def __parseAndGetResponse(self, cmd_response, response_cls, is_async): + ''' + @Name : __parseAndGetResponse + @Desc : Verifies the Response(from CS) and returns an + appropriate json parsed Response + @Input: cmd_response: Command Response from cs + response_cls : Mapping class for this Response + is_async: Whether the cmd is async or not. + @Output:Response output from CS + ''' + try: + ret = jsonHelper.getResultObj(cmd_response.json(), response_cls) + except TypeError: + ret = jsonHelper.getResultObj(cmd_response.json, response_cls) + + ''' + If the response is asynchronous, poll and return response + else return response as it is + ''' + if is_async == "false": + self.logger.debug("Response : %s" % str(ret)) + return ret + else: + response = self.__poll(ret.jobid, response_cls) + self.logger.debug("Response : %s" % str(response)) + return response.jobresult if response != FAILED else FAILED def marvinRequest(self, cmd, response_type=None, method='GET', data=''): """ - Requester for marvin command objects - @param cmd: marvin's command from cloudstackAPI - @param response_type: response type of the command in cmd - @param method: HTTP GET/POST, defaults to GET - @return: + @Name : marvinRequest + @Desc: Handles Marvin Requests + @Input cmd: marvin's command from cloudstackAPI + response_type: response type of the command in cmd + method: HTTP GET/POST, defaults to GET + @Output: Response received from CS + FAILED In case of Error\Exception """ - cmdname, isAsync, payload = self.sanitizeCommand(cmd) - self.logger.debug("sending %s request: %s %s" % (method, cmdname, - str(payload))) - response = self.request(cmdname, - self.auth, - payload=payload, - method=method) - if response is None: - return None - self.logger.debug("Request: %s Response: %s" % (response.url, - response.text)) try: - response = jsonHelper.getResultObj(response.json(), response_type) - except TypeError: - response = jsonHelper.getResultObj(response.json, response_type) + ''' + 1. Verify the Inputs Provided + ''' + if (cmd is None or cmd == '')or \ + (response_type is None or response_type == ''): + self.logger.exception("marvinRequest : Invalid Command Input") + return FAILED - if isAsync == "false": - return response - else: - asyncJobId = response.jobid - response = self.poll(asyncJobId, response_type) - return response.jobresult + ''' + 2. Sanitize the Command + ''' + sanitize_cmd_out = self.__sanitizeCmd(cmd) + + if sanitize_cmd_out == FAILED: + return FAILED + + cmd_name, is_async, payload = sanitize_cmd_out + ''' + 3. Send Command to CS + ''' + cmd_response = self.__sendCmdToCS(cmd_name, + self.auth, + payload=payload, + method=method) + if cmd_response == FAILED: + raise self.__lastError + + ''' + 4. Check if the Command Response received above is valid or Not. + If not return Invalid Response + ''' + ret = self.__parseAndGetResponse(cmd_response, + response_type, + is_async) + if ret == FAILED: + raise self.__lastError + return ret + except Exception as e: + self.logger.exception("marvinRequest : CmdName: %s Exception: %s" % + (str(cmd), GetDetailExceptionInfo(e))) + return FAILED diff --git a/tools/marvin/marvin/cloudstackException.py b/tools/marvin/marvin/cloudstackException.py index 6200003bbc3..c2eb57a4231 100644 --- a/tools/marvin/marvin/cloudstackException.py +++ b/tools/marvin/marvin/cloudstackException.py @@ -15,8 +15,13 @@ # specific language governing permissions and limitations # under the License. +import sys +import traceback +from marvin.codes import (INVALID_INPUT, EXCEPTION_OCCURRED) + + +class CloudstackAPIException(Exception): -class cloudstackAPIException(Exception): def __init__(self, cmd="", result=""): self.errorMsg = "Execute cmd: %s failed, due to: %s" % (cmd, result) @@ -25,6 +30,7 @@ class cloudstackAPIException(Exception): class InvalidParameterException(Exception): + def __init__(self, msg=''): self.errorMsg = msg @@ -33,6 +39,7 @@ class InvalidParameterException(Exception): class dbException(Exception): + def __init__(self, msg=''): self.errorMsg = msg @@ -41,8 +48,18 @@ class dbException(Exception): class internalError(Exception): + def __init__(self, msg=''): self.errorMsg = msg def __str__(self): return self.errorMsg + + +def GetDetailExceptionInfo(e): + if e is not None: + exc_type, exc_value, exc_traceback = sys.exc_info() + return str(repr(traceback.format_exception( + exc_type, exc_value, exc_traceback))) + else: + return EXCEPTION_OCCURRED diff --git a/tools/marvin/marvin/cloudstackTestCase.py b/tools/marvin/marvin/cloudstackTestCase.py index 6456bb1fe61..5cb4a109286 100644 --- a/tools/marvin/marvin/cloudstackTestCase.py +++ b/tools/marvin/marvin/cloudstackTestCase.py @@ -16,7 +16,7 @@ # under the License. import unittest -from marvin.integration.lib.utils import verifyElementInList +from marvin.lib.utils import verifyElementInList from marvin.codes import PASS @@ -37,7 +37,7 @@ def user(Name, DomainName, AcctType): class cloudstackTestCase(unittest.case.TestCase): clstestclient = None - def assertElementInList(inp, toverify, responsevar=None, pos=0, + def assertElementInList(inp, toverify, responsevar=None, pos=0, assertmsg="TC Failed for reason"): ''' @Name: assertElementInList @@ -46,7 +46,7 @@ class cloudstackTestCase(unittest.case.TestCase): Takes one additional argument of what message to assert with when failed ''' - out = verifyElementInList(inp, toverify, responsevar, pos) + out = verifyElementInList(inp, toverify, responsevar, pos) unittest.TestCase.assertEquals(out[0], PASS, "msg:%s" % out[1]) @classmethod diff --git a/tools/marvin/marvin/cloudstackTestClient.py b/tools/marvin/marvin/cloudstackTestClient.py index 4ac510b03ab..53d48ab10d7 100644 --- a/tools/marvin/marvin/cloudstackTestClient.py +++ b/tools/marvin/marvin/cloudstackTestClient.py @@ -15,201 +15,433 @@ # specific language governing permissions and limitations # under the License. -import cloudstackConnection -import asyncJobMgr -import dbConnection -from cloudstackAPI import * -import random -import string -import hashlib -from configGenerator import ConfigManager -from marvin.integration.lib.utils import random_gen +from marvin.cloudstackConnection import CSConnection +from marvin.asyncJobMgr import asyncJobMgr +from marvin.dbConnection import DbConnection +from marvin.cloudstackAPI import * +from marvin.codes import (FAILED, PASS, ADMIN, DOMAIN_ADMIN, + USER, SUCCESS, XEN_SERVER) +from marvin.configGenerator import ConfigManager +from marvin.cloudstackException import GetDetailExceptionInfo +from marvin.lib.utils import (random_gen, validateList) +from marvin.cloudstackAPI.cloudstackAPIClient import CloudStackAPIClient -''' -@Desc : CloudStackTestClient is encapsulated class for getting various \ - clients viz., apiclient,dbconnection etc -@Input : mgmtDetails : Management Server Details - dbSvrDetails: Database Server details of Management \ + +class CSTestClient(object): + + ''' + @Desc : CloudStackTestClient is encapsulated entity for creating and + getting various clients viz., apiclient, + user api client, dbconnection, test Data parsed + information etc + @Input : + mgmt_details : Management Server Details + dbsvr_details: Database Server details of Management \ Server. Retrieved from configuration file. - asyncTimeout : - defaultWorkerThreads : - logger : provides logging facilities for this library -''' + async_timeout : Timeout for Async queries + default_worker_threads : Number of worker threads + logger : provides logging facilities for this library + zone : The zone on which test suites using this test client will run + ''' - -class cloudstackTestClient(object): - def __init__(self, mgmtDetails, - dbSvrDetails, asyncTimeout=3600, - defaultWorkerThreads=10, - logger=None): - self.mgmtDetails = mgmtDetails - self.connection = \ - cloudstackConnection.cloudConnection(self.mgmtDetails, - asyncTimeout, - logger) - self.apiClient =\ - cloudstackAPIClient.CloudStackAPIClient(self.connection) - self.dbConnection = None - if dbSvrDetails is not None: - self.createDbConnection(dbSvrDetails.dbSvr, dbSvrDetails.port, - dbSvrDetails.user, - dbSvrDetails.passwd, dbSvrDetails.db) - ''' - Provides the Configuration Object to users through getConfigParser - The purpose of this object is to parse the config - and provide dictionary of the config so users can - use that configuration.Users can later call getConfig - on this object and it will return the default parsed - config dictionary from default configuration file, - they can overwrite it with providing their own - configuration file as well. - ''' - self.configObj = ConfigManager() - self.asyncJobMgr = None - self.id = None - self.defaultWorkerThreads = defaultWorkerThreads + def __init__(self, mgmt_details, + dbsvr_details, + async_timeout=3600, + logger=None, + test_data_filepath=None, + zone=None, + hypervisor_type=None): + self.__mgmtDetails = mgmt_details + self.__dbSvrDetails = dbsvr_details + self.__csConnection = None + self.__dbConnection = None + self.__testClient = None + self.__asyncTimeOut = async_timeout + self.__logger = logger + self.__apiClient = None + self.__userApiClient = None + self.__asyncJobMgr = None + self.__id = None + self.__hypervisor = hypervisor_type + self.__testDataFilePath = test_data_filepath + self.__parsedTestDataConfig = None + self.__zone = zone + self.__setHypervisorInfo() @property def identifier(self): - return self.id + return self.__id @identifier.setter def identifier(self, id): - self.id = id + self.__id = id - def createDbConnection(self, host="localhost", port=3306, user='cloud', - passwd='cloud', db='cloud'): - self.dbConnection = dbConnection.dbConnection(host, port, user, - passwd, db) + def getParsedTestDataConfig(self): + ''' + @Name : getParsedTestDataConfig + @Desc : Provides the TestData Config needed for + Tests are to Run + @Output : Returns the Parsed Test Data Dictionary + ''' + return self.__parsedTestDataConfig + + def getZoneForTests(self): + ''' + @Name : getZoneForTests + @Desc : Provides the Zone against which Tests are to run + If zone name provided to marvin plugin is none + it will get it from Test Data Config File + Even, if it is not available, return None + @Output : Returns the Zone Name + ''' + return self.__zone + + def getHypervisorInfo(self): + ''' + @Name : getHypervisorInfo + @Desc : Provides the hypervisor Information to test users + @Output : Return Hypervisor Information + ''' + return self.__hypervisor + + def __setHypervisorInfo(self): + ''' + @Name : __setHypervisorInfo + @Desc: Set the HyperVisor details; + default to XenServer + ''' + try: + if not self.__hypervisor: + self.__hypervisor = XEN_SERVER + return SUCCESS + except Exception as e: + print "\n Exception Occurred Under __setHypervisorInfo " \ + "%s" % GetDetailExceptionInfo(e) + return FAILED + + def __createApiClient(self): + try: + ''' + Step1 : Create a CS Connection Object + ''' + self.__csConnection = CSConnection(self.__mgmtDetails, + self.__asyncTimeOut, + self.__logger) + + ''' + Step2 : Create API Client with earlier created connection object + ''' + self.__apiClient = CloudStackAPIClient(self.__csConnection) + + ''' + Step3: If API Key is not provided as part of Management Details, + then verify and register + ''' + if self.__mgmtDetails.apiKey is None: + list_user = listUsers.listUsersCmd() + list_user.account = "admin" + list_user_res = self.__apiClient.listUsers(list_user) + if list_user_res is None or\ + (validateList(list_user_res)[0] != PASS): + self.__logger.error("__createApiClient: API " + "Client Creation Failed") + return FAILED + user_id = list_user_res[0].id + api_key = list_user_res[0].apikey + security_key = list_user_res[0].secretkey + if api_key is None: + ret = self.__getKeys(user_id) + if ret != FAILED: + self.__mgmtDetails.port = 8080 + self.__mgmtDetails.apiKey = ret[0] + self.__mgmtDetails.securityKey = ret[1] + else: + self.__logger.error("__createApiClient: API Client " + "Creation Failed while " + "Registering User") + return FAILED + else: + self.__mgmtDetails.port = 8080 + self.__mgmtDetails.apiKey = api_key + self.__mgmtDetails.securityKey = security_key + ''' + Now Create the Connection objects and Api Client using + new details + ''' + self.__csConnection = CSConnection(self.__mgmtDetails, + self.__asyncTimeOut, + self.__logger) + self.__apiClient = CloudStackAPIClient(self.__csConnection) + return SUCCESS + except Exception as e: + self.__logger.exception(" Exception Occurred Under " + "__createApiClient: %s" % + GetDetailExceptionInfo(e)) + return FAILED + + def __createDbConnection(self): + ''' + @Name : ___createDbConnection + @Desc : Creates the CloudStack DB Connection + ''' + host = "localhost" if self.__dbSvrDetails.dbSvr is None \ + else self.__dbSvrDetails.dbSvr + port = 3306 if self.__dbSvrDetails.port is None \ + else self.__dbSvrDetails.port + user = "cloud" if self.__dbSvrDetails.user is None \ + else self.__dbSvrDetails.user + passwd = 'cloud' if self.__dbSvrDetails.passd is None \ + else self.__dbSvrDetails.passd + db = 'cloud' if self.__dbSvrDetails.db is None \ + else self.__dbSvrDetails.db + self.__dbConnection = DbConnection(host, port, user, passwd, db) + + def __getKeys(self, userid): + ''' + @Name : ___getKeys + @Desc : Retrieves the API and Secret Key for the provided Userid + @Input: userid: Userid to register + @Output: FAILED or tuple with apikey and secretkey + ''' + try: + register_user = registerUserKeys.registerUserKeysCmd() + register_user.id = userid + register_user_res = \ + self.__apiClient.registerUserKeys(register_user) + if not register_user_res: + return FAILED + return (register_user_res.apikey, register_user_res.secretkey) + except Exception as e: + self.__logger.exception("Exception Occurred Under __geKeys : " + "%s" % GetDetailExceptionInfo(e)) + return FAILED + + def createTestClient(self): + ''' + @Name : createTestClient + @Desc : Creates the Test Client. + The test Client is used by test suites + Here we create ParsedTestData Config. + Creates a DB Connection. + Creates an API Client + @Output : FAILED In case of an issue\Failure + SUCCESS in case of Success of this function + ''' + try: + ''' + 1. Create Config Object + Provides the Configuration Object to test suites through + getConfigParser. The purpose of this config object is to + parse the default config and provide dictionary of the + config so users can use that configuration. + Users can later call getConfig on this object and it will + return the default parsed config dictionary from default + configuration file. They can overwrite it with + providing their own configuration file as well. + ''' + ''' + 1. Check Config,Zone,Hypervisor Information + ''' + self.__configObj = ConfigManager(self.__testDataFilePath) + + if not self.__configObj or not self.__hypervisor: + self.__logger.error("createTestClient : " + "Either Hypervisor is None or " + "Not able to create " + "ConfigManager Object") + return FAILED + + self.__parsedTestDataConfig = self.__configObj.getConfig() + self.__logger.debug("Parsing Test data successful") + + ''' + 2. Create DB Connection + ''' + self.__createDbConnection() + ''' + 3. Creates API Client + ''' + ret = self.__createApiClient() + if ret == FAILED: + self.__logger.\ + error("==== Test Client Creation Failed ====") + else: + self.__logger.\ + debug("==== Test Client Creation Successful ====") + return ret + except Exception as e: + self.__logger.exception("Exception Occurred " + "Under createTestClient " + ": %s" % GetDetailExceptionInfo(e)) + return FAILED def isAdminContext(self): """ - A user is a regular user if he fails to listDomains; + @Name : isAdminContext + @Desc:A user is a regular user if he fails to listDomains; if he is a domain-admin, he can list only domains that are non-ROOT; if he is an admin, he can list the ROOT domain successfully """ try: listdom = listDomains.listDomainsCmd() listdom.name = 'ROOT' - listdomres = self.apiClient.listDomains(listdom) - rootdom = listdomres[0].name - if rootdom == 'ROOT': - return 1 # admin + listdomres = self.__apiClient.listDomains(listdom) + if listdomres != FAILED: + rootdom = listdomres[0].name + if rootdom == 'ROOT': + return ADMIN + else: + return DOMAIN_ADMIN + return USER + except: + return USER + + def __createUserApiClient(self, UserName, DomainName, acctType=0): + ''' + @Name : ___createUserApiClient + @Desc : Creates a User API Client with given + UserName\DomainName Parameters + @Input: UserName: Username to be created in cloudstack + DomainName: Domain under which the above account be created + accType: Type of Account EX: Root,Non Root etc + @Output: Return the API client for the user + ''' + try: + if not self.isAdminContext(): + return self.__apiClient + + listDomain = listDomains.listDomainsCmd() + listDomain.listall = True + listDomain.name = DomainName + try: + domains = self.__apiClient.listDomains(listDomain) + domId = domains[0].id + except: + cdomain = createDomain.createDomainCmd() + cdomain.name = DomainName + domain = self.__apiClient.createDomain(cdomain) + domId = domain.id + + cmd = listAccounts.listAccountsCmd() + cmd.name = UserName + cmd.domainid = domId + try: + accounts = self.__apiClient.listAccounts(cmd) + acctId = accounts[0].id + except: + createAcctCmd = createAccount.createAccountCmd() + createAcctCmd.accounttype = acctType + createAcctCmd.domainid = domId + createAcctCmd.email = "test-" + random_gen()\ + + "@cloudstack.org" + createAcctCmd.firstname = UserName + createAcctCmd.lastname = UserName + createAcctCmd.password = 'password' + createAcctCmd.username = UserName + acct = self.__apiClient.createAccount(createAcctCmd) + acctId = acct.id + + listuser = listUsers.listUsersCmd() + listuser.username = UserName + + listuserRes = self.__apiClient.listUsers(listuser) + userId = listuserRes[0].id + apiKey = listuserRes[0].apikey + securityKey = listuserRes[0].secretkey + + if apiKey is None: + ret = self.__getKeys(userId) + if ret != FAILED: + mgtDetails = self.__mgmtDetails + mgtDetails.apiKey = ret[0] + mgtDetails.securityKey = ret[1] + else: + self.__logger.error("__createUserApiClient: " + "User API Client Creation." + " While Registering User Failed") + return FAILED else: - return 2 # domain-admin - except: - return 0 # user + mgtDetails = self.__mgmtDetails + mgtDetails.apiKey = apiKey + mgtDetails.securityKey = securityKey - def createUserApiClient(self, UserName, DomainName, acctType=0): - if not self.isAdminContext(): - return self.apiClient - - listDomain = listDomains.listDomainsCmd() - listDomain.listall = True - listDomain.name = DomainName - try: - domains = self.apiClient.listDomains(listDomain) - domId = domains[0].id - except: - cdomain = createDomain.createDomainCmd() - cdomain.name = DomainName - domain = self.apiClient.createDomain(cdomain) - domId = domain.id - - cmd = listAccounts.listAccountsCmd() - cmd.name = UserName - cmd.domainid = domId - try: - accounts = self.apiClient.listAccounts(cmd) - acctId = accounts[0].id - except: - createAcctCmd = createAccount.createAccountCmd() - createAcctCmd.accounttype = acctType - createAcctCmd.domainid = domId - createAcctCmd.email = "test-" + random_gen()\ - + "@cloudstack.org" - createAcctCmd.firstname = UserName - createAcctCmd.lastname = UserName - createAcctCmd.password = 'password' - createAcctCmd.username = UserName - acct = self.apiClient.createAccount(createAcctCmd) - acctId = acct.id - - listuser = listUsers.listUsersCmd() - listuser.username = UserName - - listuserRes = self.apiClient.listUsers(listuser) - userId = listuserRes[0].id - apiKey = listuserRes[0].apikey - securityKey = listuserRes[0].secretkey - - if apiKey is None: - registerUser = registerUserKeys.registerUserKeysCmd() - registerUser.id = userId - registerUserRes = self.apiClient.registerUserKeys(registerUser) - apiKey = registerUserRes.apikey - securityKey = registerUserRes.secretkey - - mgtDetails = self.mgmtDetails - mgtDetails.apiKey = apiKey - mgtDetails.securityKey = securityKey - - newUserConnection =\ - cloudstackConnection.cloudConnection(mgtDetails, - self.connection.asyncTimeout, - self.connection.logger) - self.userApiClient =\ - cloudstackAPIClient.CloudStackAPIClient(newUserConnection) - self.userApiClient.connection = newUserConnection - self.userApiClient.hypervisor = self.apiClient.hypervisor - return self.userApiClient + newUserConnection =\ + CSConnection(mgtDetails, + self.__csConnection.asyncTimeout, + self.__csConnection.logger) + self.__userApiClient = CloudStackAPIClient(newUserConnection) + self.__userApiClient.connection = newUserConnection + self.__userApiClient.hypervisor = self.__hypervisor + return self.__userApiClient + except Exception as e: + self.__logger.exception("Exception Occurred " + "Under getUserApiClient : %s" % + GetDetailExceptionInfo(e)) + return FAILED def close(self): - if self.connection is not None: - self.connection.close() + if self.__csConnection is not None: + self.__csConnection.close() def getDbConnection(self): - return self.dbConnection + ''' + @Name : getDbConnection + @Desc : Retrieves the DB Connection Handle + ''' + return self.__dbConnection def getConfigParser(self): - return self.configObj + ''' + @Name : getConfigParser + @Desc : Provides the ConfigManager Interface to TestClients + ''' + return self.__configObj def getApiClient(self): - self.apiClient.id = self.identifier - return self.apiClient - - def getUserApiClient(self, account, domain, type=0): - """ - 0 - user - 1 - admin - 2 - domain admin - """ - self.createUserApiClient(account, domain, type) - if hasattr(self, "userApiClient"): - return self.userApiClient + if self.__apiClient: + self.__apiClient.id = self.identifier + return self.__apiClient return None + def getUserApiClient(self, UserName=None, DomainName=None, type=0): + """ + @Name : getUserApiClient + @Desc : Provides the User API Client to test Users + 0 - user ; 1 - admin;2 - domain admin + @OutPut : FAILED In case of an issue + else User API Client + """ + if UserName is None or DomainName is None: + return FAILED + return self.__createUserApiClient(UserName, DomainName, type) + def submitCmdsAndWait(self, cmds, workers=1): - '''FixME, httplib has issue if more than one thread submitted''' - if self.asyncJobMgr is None: - self.asyncJobMgr = asyncJobMgr.asyncJobMgr(self.apiClient, - self.dbConnection) - return self.asyncJobMgr.submitCmdsAndWait(cmds, workers) + ''' + @Desc : FixME, httplib has issue if more than one thread submitted + ''' + if self.__asyncJobMgr is None: + self.__asyncJobMgr = asyncJobMgr(self.__apiClient, + self.__dbConnection) + return self.__asyncJobMgr.submitCmdsAndWait(cmds, workers) def submitJob(self, job, ntimes=1, nums_threads=10, interval=1): ''' - submit one job and execute the same job ntimes, with nums_threads - of threads + @Desc : submit one job and execute the same job + ntimes, with nums_threads of threads ''' - if self.asyncJobMgr is None: - self.asyncJobMgr = asyncJobMgr.asyncJobMgr(self.apiClient, - self.dbConnection) - self.asyncJobMgr.submitJobExecuteNtimes(job, ntimes, nums_threads, - interval) + if self.__asyncJobMgr is None: + self.__asyncJobMgr = asyncJobMgr(self.__apiClient, + self.__dbConnection) + self.__asyncJobMgr.submitJobExecuteNtimes(job, ntimes, + nums_threads, + interval) def submitJobs(self, jobs, nums_threads=10, interval=1): - '''submit n jobs, execute them with nums_threads of threads''' - if self.asyncJobMgr is None: - self.asyncJobMgr = asyncJobMgr.asyncJobMgr(self.apiClient, - self.dbConnection) - self.asyncJobMgr.submitJobs(jobs, nums_threads, interval) + ''' + @Desc :submit n jobs, execute them with nums_threads + of threads + ''' + if self.__asyncJobMgr is None: + self.__asyncJobMgr = asyncJobMgr(self.__apiClient, + self.__dbConnection) + self.__asyncJobMgr.submitJobs(jobs, nums_threads, interval) diff --git a/tools/marvin/marvin/codegenerator.py b/tools/marvin/marvin/codegenerator.py index e0f056f66a0..1e02ddfb379 100644 --- a/tools/marvin/marvin/codegenerator.py +++ b/tools/marvin/marvin/codegenerator.py @@ -25,6 +25,7 @@ import urllib2 class cmdParameterProperty(object): + def __init__(self): self.name = None self.required = False @@ -34,6 +35,7 @@ class cmdParameterProperty(object): class cloudStackCmd(object): + def __init__(self): self.name = "" self.desc = "" @@ -42,7 +44,8 @@ class cloudStackCmd(object): self.response = [] -class codeGenerator(object): +class CodeGenerator(object): + """ Apache CloudStack- marvin python classes can be generated from the json returned by API discovery or from the xml spec of commands generated by @@ -208,12 +211,12 @@ class codeGenerator(object): body += self.space + '@property' + self.newline body += self.space + 'def id(self):' + self.newline - body += self.space*2 + 'return self._id' + self.newline + body += self.space * 2 + 'return self._id' + self.newline body += self.newline body += self.space + '@id.setter' + self.newline body += self.space + 'def id(self, identifier):' + self.newline - body += self.space*2 + 'self._id = identifier' + self.newline + body += self.space * 2 + 'self._id = identifier' + self.newline body += self.newline for cmdName in self.cmdsName: @@ -340,7 +343,7 @@ class codeGenerator(object): paramProperty.desc = response['description'] if 'type' in response: if response['type'] in ['list', 'map', 'set']: - #Here list becomes a subproperty + # Here list becomes a subproperty if 'response' in response: for innerResponse in response['response']: subProperty =\ @@ -394,7 +397,7 @@ class codeGenerator(object): csCmd.request.append(paramProperty) for response in cmd['response']: - #FIXME: ExtractImage related APIs return empty dicts in response + # FIXME: ExtractImage related APIs return empty dicts in response if len(response) > 0: paramProperty = self.constructResponseFromJSON(response) csCmd.response.append(paramProperty) @@ -454,7 +457,7 @@ if __name__ == "__main__": print parser.print_help() exit(1) - cg = codeGenerator(folder) + cg = CodeGenerator(folder) if options.spec is not None: cg.generateCodeFromXML(apiSpecFile) elif options.endpoint is not None: diff --git a/tools/marvin/marvin/codes.py b/tools/marvin/marvin/codes.py index 92d6cf9d208..28e907cbcd8 100644 --- a/tools/marvin/marvin/codes.py +++ b/tools/marvin/marvin/codes.py @@ -47,13 +47,32 @@ YES = "yes" FAILED = "FAILED" UNKNOWN_ERROR = "Unknown Error" EXCEPTION = "EXCEPTION" +INVALID_RESPONSE = "Invalid Response" +''' +Async Job Related Codes +''' +JOB_INPROGRESS = 0 +JOB_SUCCEEDED = 1 +JOB_FAILED = 2 +JOB_CANCELLED = 3 +''' +User Related Codes +''' BASIC_ZONE = "basic" ISOLATED_NETWORK = "ISOLATED" SHARED_NETWORK = "SHARED" VPC_NETWORK = "VPC" -ERROR_NO_HOST_FOR_MIGRATION = "Could not find suitable host for migration, please ensure setup has required no. of hosts" +ERROR_NO_HOST_FOR_MIGRATION = \ + "Could not find suitable host for migration, " \ + "please ensure setup has required no. of hosts" NAT_RULE = "nat rule" STATIC_NAT_RULE = "static nat rule" UNKNOWN = "UNKNOWN" FAULT = "FAULT" MASTER = "MASTER" +ADMIN = 1 +DOMAIN_ADMIN = 2 +USER = 0 +XEN_SERVER = "XenServer" +ADMIN_ACCOUNT='ADMIN_ACCOUNT' +USER_ACCOUNT='USER_ACCOUNT' diff --git a/tools/marvin/marvin/integration/__init__.py b/tools/marvin/marvin/config/__init__.py similarity index 98% rename from tools/marvin/marvin/integration/__init__.py rename to tools/marvin/marvin/config/__init__.py index 57823fcc162..13a83393a91 100644 --- a/tools/marvin/marvin/integration/__init__.py +++ b/tools/marvin/marvin/config/__init__.py @@ -5,14 +5,12 @@ # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. - - diff --git a/tools/marvin/marvin/config/config.cfg b/tools/marvin/marvin/config/config.cfg index a27806808e3..a4bbe9dcfe0 100644 --- a/tools/marvin/marvin/config/config.cfg +++ b/tools/marvin/marvin/config/config.cfg @@ -24,7 +24,7 @@ } , "project": - { + { "name": "Project", "displaytext": "Test project" }, @@ -35,6 +35,15 @@ "username": "test-account", "password": "password" }, + "user": { + "email": "user@test.com", + "firstname": "User", + "lastname": "User", + "username": "User", + # Random characters are appended for unique + # username + "password": "fr3sca", + }, "service_offering": { "name": "Tiny Instance", "displaytext": "Tiny Instance", @@ -74,6 +83,18 @@ "publicport": 22, "protocol": "TCP" }, + "template": { + "displaytext": "Public Template", + "name": "Public template", + "ostype": 'CentOS 5.3 (64-bit)', + "url": "", + "hypervisor": '', + "format": '', + "isfeatured": True, + "ispublic": True, + "isextractable": True, + "templatefilter": "self" + }, "shared_network": { "name": "Test Shared Network", "displaytext": "Test Shared Network", @@ -126,17 +147,28 @@ "name": "SharedNwOffering", "displaytext": "SharedNwOffering", "guestiptype": "Shared", - "supportedservices": "Dhcp,Dns,UserData", + "supportedservices": "Dhcp,Dns,SourceNat,PortForwarding,Vpn,Firewall,Lb,UserData,StaticNat", "specifyVlan" : "False", "specifyIpRanges" : "False", "traffictype": "GUEST", "serviceProviderList" : { "Dhcp": "VirtualRouter", "Dns": "VirtualRouter", - "UserData": "VirtualRouter" + "SourceNat": "VirtualRouter", + "PortForwarding": "VirtualRouter", + "Vpn": "VirtualRouter", + "Firewall": "VirtualRouter", + "Lb": "VirtualRouter", + "UserData": "VirtualRouter", + "StaticNat": "VirtualRouter" } }, "security_group" : { "name": "custom_Sec_Grp" }, + "natrule": { + "publicport": 22, + "privateport": 22, + "protocol": 'TCP', + }, "ingress_rule": { "protocol": "TCP", "startport": "22", diff --git a/tools/marvin/marvin/config/test_data.cfg b/tools/marvin/marvin/config/test_data.cfg new file mode 100644 index 00000000000..5a3d8aaef30 --- /dev/null +++ b/tools/marvin/marvin/config/test_data.cfg @@ -0,0 +1,427 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +{ + "region": { + "regionid": "2", + "regionname": "Region2", + "regionendpoint": "http://region2:8080/client" + }, + "zone": "NA", + + "domain": { "name": "domain" }, + + "project": { + "name": "Project", + "displaytext": "Test project" + }, + "account": { + "email": "test-account@test.com", + "firstname": "test", + "lastname": "test", + "username": "test-account", + "password": "password" + }, + "small": { + "displayname": "testserver", + "username": "root", + "password": "password", + "ssh_port": 22, + "hypervisor": "XenServer", + "privateport": 22, + "publicport": 22, + "protocol": 'TCP', + }, + "medium": { + "displayname": "testserver", + "username": "root", + "password": "password", + "ssh_port": 22, + "hypervisor": 'XenServer', + "privateport": 22, + "publicport": 22, + "protocol": 'TCP', + }, + "service_offerings": { + "name": "Tiny Instance", + "displaytext": "Tiny Instance", + "cpunumber": 1, + "cpuspeed": 100, + "memory": 128, + + "tiny": { + "name": "Tiny Instance", + "displaytext": "Tiny Instance", + "cpunumber": 1, + "cpuspeed": 100, + "memory": 128, + }, + "small": { + "name": "Small Instance", + "displaytext": "Small Instance", + "cpunumber": 1, + "cpuspeed": 100, + "memory": 256 + }, + "medium": { + "name": "Medium Instance", + "displaytext": "Medium Instance", + "cpunumber": 1, + "cpuspeed": 100, + "memory": 256, + }, + "big": { + "name": "BigInstance", + "displaytext": "BigInstance", + "cpunumber": 1, + "cpuspeed": 100, + "memory": 512, + } + }, + "disk_offering": { + "name": "Disk offering", + "displaytext": "Disk offering", + "disksize": 1 + }, + 'resized_disk_offering': { + "displaytext": "Resized", + "name": "Resized", + "disksize": 3 + }, + "network": { + "name": "Test Network", + "displaytext": "Test Network", + "acltype": "Account", + }, + "network2": { + "name": "Test Network Shared", + "displaytext": "Test Network Shared", + "vlan" :1201, + "gateway" :"172.16.15.1", + "netmask" :"255.255.255.0", + "startip" :"172.16.15.21", + "endip" :"172.16.15.41", + "acltype": "Account", + }, + "network_offering": { + "name": 'Test Network offering', + "displaytext": 'Test Network offering', + "guestiptype": 'Isolated', + "supportedservices": 'Dhcp,Dns,SourceNat,PortForwarding', + "traffictype": 'GUEST', + "availability": 'Optional', + "serviceProviderList" : { + "Dhcp": 'VirtualRouter', + "Dns": 'VirtualRouter', + "SourceNat": 'VirtualRouter', + "PortForwarding": 'VirtualRouter', + }, + }, + "isolated_network_offering": { + "name": "Network offering-DA services", + "displaytext": "Network offering-DA services", + "guestiptype": "Isolated", + "supportedservices": "Dhcp,Dns,SourceNat,PortForwarding,Vpn,Firewall,Lb,UserData,StaticNat", + "traffictype": "GUEST", + "availability": "Optional'", + "serviceProviderList": { + "Dhcp": "VirtualRouter", + "Dns": "VirtualRouter", + "SourceNat": "VirtualRouter", + "PortForwarding": "VirtualRouter", + "Vpn": "VirtualRouter", + "Firewall": "VirtualRouter", + "Lb": "VirtualRouter", + "UserData": "VirtualRouter", + "StaticNat": "VirtualRouter" + } + }, + "isolated_network": { + "name": "Isolated Network", + "displaytext": "Isolated Network" + }, + "virtual_machine": { + "displayname": "Test VM", + "username": "root", + "password": "password", + "ssh_port": 22, + "privateport": 22, + "publicport": 22, + "protocol": "TCP", + "affinity": { + "name": "webvms", + "type": "host anti-affinity", + }, + }, + "server_without_disk": { + "displayname": "Test VM-No Disk", + "username": "root", + "password": "password", + "ssh_port": 22, + "hypervisor": 'XenServer', + "privateport": 22, + "publicport": 22, + "protocol": 'TCP', + }, + "shared_network": { + "name": "MySharedNetwork - Test", + "displaytext": "MySharedNetwork", + "vlan" : "", + "gateway" :"", + "netmask" :"", + "startip" :"", + "endip" :"", + "acltype" : "Domain", + "scope":"all" + }, + "shared_network_offering_sg": { + "name": "MySharedOffering-sg", + "displaytext": "MySharedOffering-sg", + "guestiptype": "Shared", + "supportedservices": "Dhcp,Dns,UserData,SecurityGroup", + "specifyVlan" : "False", + "specifyIpRanges" : "False", + "traffictype": "GUEST", + "serviceProviderList" : { + "Dhcp": "VirtualRouter", + "Dns": "VirtualRouter", + "UserData": "VirtualRouter", + "SecurityGroup": "SecurityGroupProvider" + } + }, + "shared_network_sg": { + "name": "Shared-Network-SG-Test", + "displaytext": "Shared-Network_SG-Test", + "networkofferingid":"1", + "vlan" : "", + "gateway" :"", + "netmask" :"255.255.255.0", + "startip" :"", + "endip" :"", + "acltype" : "Domain", + "scope":"all" + }, + "vpc_offering": { + "name": "VPC off", + "displaytext": "VPC off", + "supportedservices": "Dhcp,Dns,SourceNat,PortForwarding,Vpn,Lb,UserData,StaticNat,NetworkACL" + }, + "vpc": { + "name": "TestVPC", + "displaytext": "TestVPC", + "cidr": "10.0.0.1/24" + }, + "clusters": { + 0: { + "clustername": "Xen Cluster", + "clustertype": "CloudManaged", + "hypervisor": "XenServer", + }, + 1: { + "clustername": "KVM Cluster", + "clustertype": "CloudManaged", + "hypervisor": "KVM", + }, + 2: { + "hypervisor": 'VMware', + "clustertype": 'ExternalManaged', + "username": 'administrator', + "password": 'fr3sca', + "url": 'http://192.168.100.17/CloudStack-Clogeny-Pune/Pune-1', + "clustername": 'VMWare Cluster', + }, + }, + "hosts": { + "xenserver": { + "hypervisor": 'XenServer', + "clustertype": 'CloudManaged', + "url": 'http://192.168.100.211', + "username": "root", + "password": "fr3sca", + }, + "kvm": { + "hypervisor": 'KVM', + "clustertype": 'CloudManaged', + "url": 'http://192.168.100.212', + "username": "root", + "password": "fr3sca", + }, + "vmware": { + "hypervisor": 'VMware', + "clustertype": 'ExternalManaged', + "url": 'http://192.168.100.203', + "username": "administrator", + "password": "fr3sca", + }, + }, + "network_offering_shared": { + "name": 'Test Network offering shared', + "displaytext": 'Test Network offering Shared', + "guestiptype": 'Shared', + "supportedservices": 'Dhcp,Dns,UserData', + "traffictype": 'GUEST', + "specifyVlan" : "True", + "specifyIpRanges" : "True", + "serviceProviderList" : { + "Dhcp": 'VirtualRouter', + "Dns": 'VirtualRouter', + "UserData": 'VirtualRouter', + }, + }, + "network_offering_internal_lb": { + "name": "Network offering for internal lb service", + "displaytext": "Network offering for internal lb service", + "guestiptype": "Isolated", + "traffictype": "Guest", + "supportedservices": "Vpn,Dhcp,Dns,Lb,UserData,SourceNat,StaticNat,PortForwarding,NetworkACL", + "serviceProviderList": { + "Dhcp": "VpcVirtualRouter", + "Dns": "VpcVirtualRouter", + "Vpn": "VpcVirtualRouter", + "UserData": "VpcVirtualRouter", + "Lb": "InternalLbVM", + "SourceNat": "VpcVirtualRouter", + "StaticNat": "VpcVirtualRouter", + "PortForwarding": "VpcVirtualRouter", + "NetworkACL": "VpcVirtualRouter", + }, + "serviceCapabilityList": { + "SourceNat": {"SupportedSourceNatTypes": "peraccount"}, + "Lb": {"lbSchemes": "internal", "SupportedLbIsolation": "dedicated"} + } + }, + + "natrule": { + "privateport": 22, + "publicport": 2222, + "protocol": "TCP" + }, + "lbrule": { + "name": "SSH", + "alg": "roundrobin", + "privateport": 22, + "publicport": 2222, + "protocol": 'TCP' + }, + + "iso1": { + "displaytext": "Test ISO 1", + "name": "ISO 1", + "url": "http://people.apache.org/~tsp/dummy.iso", + "isextractable": True, + "isfeatured": True, + "ispublic": True, + "ostype": "CentOS 5.3 (64-bit)", + }, + "iso2": { + "displaytext": "Test ISO 2", + "name": "ISO 2", + "url": "http://people.apache.org/~tsp/dummy.iso", + "isextractable": True, + "isfeatured": True, + "ispublic": True, + "ostype": "CentOS 5.3 (64-bit)", + "mode": 'HTTP_DOWNLOAD', + }, + "isfeatured": True, + "ispublic": True, + "isextractable": True, + "bootable": True, + "passwordenabled": True, + + "template": { + "displaytext": "xs", + "name": "xs", + "passwordenabled": False, + }, + "template_2": { + "displaytext": "Public Template", + "name": "Public template", + "ostype": "CentOS 5.3 (64-bit)", + "isfeatured": True, + "ispublic": True, + "isextractable": True, + "mode": "HTTP_DOWNLOAD", + }, + "templatefilter": 'self', + + "security_group" : { "name": "custom_Sec_Grp" }, + "ingress_rule": { + "protocol": "TCP", + "startport": "22", + "endport": "22", + "cidrlist": "0.0.0.0/0" + }, + "ostype": "CentOS 5.3 (64-bit)", + "sleep": 90, + "timeout": 10, + "advanced_sg": { + "zone": { + "name": "", + "dns1": "8.8.8.8", + "internaldns1": "192.168.100.1", + "networktype": "Advanced", + "securitygroupenabled": "true" + }, + "securitygroupenabled": "true" + }, + "vlan": { + "part": ["4090-4091", "4092-4095"], + "full": "4090-4095", + }, + "nfs": { + "url": "nfs://10.147.28.7/export/home/talluri/testprimary", + "name": "Primary XEN" + }, + "iscsi": { + "url": "iscsi://192.168.100.21/iqn.2012-01.localdomain.clo-cstack-cos6:iser/1", + "name": "Primary iSCSI" + }, + "volume": {"diskname": "Test Volume"}, + "volume_offerings": { + 0: {"diskname": "TestDiskServ"}, + }, + "diskdevice": ['/dev/vdc', '/dev/vdb', '/dev/hdb', '/dev/hdc', '/dev/xvdd', '/dev/cdrom', '/dev/sr0', '/dev/cdrom1' ], + + #test_vpc_vpn.py + "vpn_user": { + "username": "test", + "password": "password", + }, + "vpc": { + "name": "vpc_vpn", + "displaytext": "vpc-vpn", + "cidr": "10.1.1.0/24" + }, + "ntwk": { + "name": "tier1", + "displaytext": "vpc-tier1", + "gateway" : "10.1.1.1", + "netmask" : "255.255.255.192" + }, + "vpc2": { + "name": "vpc2_vpn", + "displaytext": "vpc2-vpn", + "cidr": "10.2.1.0/24" + }, + "ntwk2": { + "name": "tier2", + "displaytext": "vpc-tier2", + "gateway" : "10.2.1.1", + "netmask" : "255.255.255.192" + } +} diff --git a/tools/marvin/marvin/config/test_data.py b/tools/marvin/marvin/config/test_data.py new file mode 100644 index 00000000000..1a29ed93a27 --- /dev/null +++ b/tools/marvin/marvin/config/test_data.py @@ -0,0 +1,629 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +test_data = { + "region": { + "regionid": "2", + "regionname": "Region2", + "regionendpoint": "http://region2:8080/client" + }, + "zone": "NA", + "hypervisor": "XenServer", + "deleteDC": True, + "vdomain": { + "name": "domain" + }, + "email": "test@test.com", + "gateway": "172.1.1.1", + "netmask": "255.255.255.0", + "startip": "172.1.1.10", + "endip": "172.1.1.20", + "regionid": "1", + "vlan": "10", + "isportable": "true", + + "project": { + "name": "Project", + "displaytext": "Test project" + }, + "account": { + "email": "test-account@test.com", + "firstname": "test", + "lastname": "test", + "username": "test-account", + "password": "password" + }, + "small": { + "displayname": "testserver", + "username": "root", + "password": "password", + "ssh_port": 22, + "hypervisor": "XenServer", + "privateport": 22, + "publicport": 22, + "protocol": 'TCP', + }, + "medium": { + "displayname": "testserver", + "username": "root", + "password": "password", + "ssh_port": 22, + "hypervisor": 'XenServer', + "privateport": 22, + "publicport": 22, + "protocol": 'TCP', + }, + "service_offering": { + "name": "Tiny Instance", + "displaytext": "Tiny Instance", + "cpunumber": 1, + "cpuspeed": 100, # in MHz + "memory": 128, # In MBs + }, + "service_offerings": { + "name": "Tiny Instance", + "displaytext": "Tiny Instance", + "cpunumber": 1, + "cpuspeed": 100, + "memory": 128, + + "tiny": { + "name": "Tiny Instance", + "displaytext": "Tiny Instance", + "cpunumber": 1, + "cpuspeed": 100, + "memory": 128, + }, + "small": { + "name": "Small Instance", + "displaytext": "Small Instance", + "cpunumber": 1, + "cpuspeed": 100, + "memory": 256 + }, + "medium": { + "name": "Medium Instance", + "displaytext": "Medium Instance", + "cpunumber": 1, + "cpuspeed": 100, + "memory": 256, + }, + "big": { + "name": "BigInstance", + "displaytext": "BigInstance", + "cpunumber": 1, + "cpuspeed": 100, + "memory": 512, + } + }, + "disk_offering": { + "name": "Disk offering", + "displaytext": "Disk offering", + "disksize": 1 + }, + 'resized_disk_offering': { + "displaytext": "Resized", + "name": "Resized", + "disksize": 3 + }, + "network": { + "name": "Test Network", + "displaytext": "Test Network", + "acltype": "Account", + }, + "network2": { + "name": "Test Network Shared", + "displaytext": "Test Network Shared", + "vlan": 1201, + "gateway": "172.16.15.1", + "netmask": "255.255.255.0", + "startip": "172.16.15.21", + "endip": "172.16.15.41", + "acltype": "Account", + }, + "network_offering": { + "name": 'Test Network offering', + "displaytext": 'Test Network offering', + "guestiptype": 'Isolated', + "supportedservices": 'Dhcp,Dns,SourceNat,PortForwarding', + "traffictype": 'GUEST', + "availability": 'Optional', + "serviceProviderList": { + "Dhcp": 'VirtualRouter', + "Dns": 'VirtualRouter', + "SourceNat": 'VirtualRouter', + "PortForwarding": 'VirtualRouter', + }, + }, + "nw_off_isolated_persistent": { + "name": 'Test Nw off isolated persistent', + "displaytext": 'Test Nw off isolated persistent', + "guestiptype": 'Isolated', + "supportedservices": 'Dhcp,Dns,SourceNat,PortForwarding', + "traffictype": 'GUEST', + "isPersistent": 'True', + "availability": 'Optional', + "serviceProviderList": { + "Dhcp": 'VirtualRouter', + "Dns": 'VirtualRouter', + "SourceNat": 'VirtualRouter', + "PortForwarding": 'VirtualRouter', + }, + }, + "isolated_network_offering": { + "name": "Network offering-DA services", + "displaytext": "Network offering-DA services", + "guestiptype": "Isolated", + "supportedservices": + "Dhcp,Dns,SourceNat,PortForwarding,Vpn,Firewall,Lb,UserData,StaticNat", + "traffictype": "GUEST", + "availability": "Optional'", + "serviceProviderList": { + "Dhcp": "VirtualRouter", + "Dns": "VirtualRouter", + "SourceNat": "VirtualRouter", + "PortForwarding": "VirtualRouter", + "Vpn": "VirtualRouter", + "Firewall": "VirtualRouter", + "Lb": "VirtualRouter", + "UserData": "VirtualRouter", + "StaticNat": "VirtualRouter" + } + }, + "isolated_network": { + "name": "Isolated Network", + "displaytext": "Isolated Network" + }, + "virtual_machine": { + "displayname": "Test VM", + "username": "root", + "password": "password", + "ssh_port": 22, + "privateport": 22, + "publicport": 22, + "protocol": "TCP", + "affinity": { + "name": "webvms", + "type": "host anti-affinity", + }, + }, + "virtual_machine2": { + "name": "testvm2", + "displayname": "Test VM2", + }, + "virtual_machine3": { + "name": "testvm3", + "displayname": "Test VM3", + }, + "server_without_disk": { + "displayname": "Test VM-No Disk", + "username": "root", + "password": "password", + "ssh_port": 22, + "hypervisor": 'XenServer', + "privateport": 22, + "publicport": 22, + "protocol": 'TCP', + }, + "shared_network": { + "name": "MySharedNetwork - Test", + "displaytext": "MySharedNetwork", + "vlan": "", + "gateway": "", + "netmask": "", + "startip": "", + "endip": "", + "acltype": "Domain", + "scope": "all" + }, + "shared_network_offering_sg": { + "name": "MySharedOffering-sg", + "displaytext": "MySharedOffering-sg", + "guestiptype": "Shared", + "supportedservices": "Dhcp,Dns,UserData,SecurityGroup", + "specifyVlan": "False", + "specifyIpRanges": "False", + "traffictype": "GUEST", + "serviceProviderList": { + "Dhcp": "VirtualRouter", + "Dns": "VirtualRouter", + "UserData": "VirtualRouter", + "SecurityGroup": "SecurityGroupProvider" + } + }, + "shared_network_sg": { + "name": "Shared-Network-SG-Test", + "displaytext": "Shared-Network_SG-Test", + "networkofferingid": "1", + "vlan": "", + "gateway": "", + "netmask": "255.255.255.0", + "startip": "", + "endip": "", + "acltype": "Domain", + "scope": "all" + }, + "vpc_offering": { + "name": "VPC off", + "displaytext": "VPC off", + "supportedservices": + "Dhcp,Dns,SourceNat,PortForwarding,Vpn,Lb,UserData,StaticNat,NetworkACL" + }, + "vpc": { + "name": "TestVPC", + "displaytext": "TestVPC", + "cidr": "10.0.0.1/24" + }, + "clusters": { + 0: { + "clustername": "Xen Cluster", + "clustertype": "CloudManaged", + "hypervisor": "XenServer", + }, + 1: { + "clustername": "KVM Cluster", + "clustertype": "CloudManaged", + "hypervisor": "KVM", + }, + 2: { + "hypervisor": 'VMware', + "clustertype": 'ExternalManaged', + "username": 'administrator', + "password": 'fr3sca', + "url": 'http://192.168.100.17/CloudStack-Clogeny-Pune/Pune-1', + "clustername": 'VMWare Cluster', + }, + }, + "hosts": { + "xenserver": { + "hypervisor": 'XenServer', + "clustertype": 'CloudManaged', + "url": 'http://192.168.100.211', + "username": "root", + "password": "fr3sca", + }, + "kvm": { + "hypervisor": 'KVM', + "clustertype": 'CloudManaged', + "url": 'http://192.168.100.212', + "username": "root", + "password": "fr3sca", + }, + "vmware": { + "hypervisor": 'VMware', + "clustertype": 'ExternalManaged', + "url": 'http://192.168.100.203', + "username": "administrator", + "password": "fr3sca", + }, + }, + "network_offering_shared": { + "name": 'Test Network offering shared', + "displaytext": 'Test Network offering Shared', + "guestiptype": 'Shared', + "supportedservices": 'Dhcp,Dns,UserData', + "traffictype": 'GUEST', + "specifyVlan": "True", + "specifyIpRanges": "True", + "serviceProviderList": { + "Dhcp": 'VirtualRouter', + "Dns": 'VirtualRouter', + "UserData": 'VirtualRouter', + }, + }, + "nw_off_persistent_RVR": { + "name": 'Network offering-RVR services', + "displaytext": 'Network off-RVR services', + "guestiptype": 'Isolated', + "supportedservices": + 'Vpn,Dhcp,Dns,SourceNat,PortForwarding,Firewall,Lb,UserData,StaticNat', + "traffictype": 'GUEST', + "isPersistent": 'True', + "availability": 'Optional', + "serviceProviderList": { + "Vpn": 'VirtualRouter', + "Dhcp": 'VirtualRouter', + "Dns": 'VirtualRouter', + "SourceNat": 'VirtualRouter', + "PortForwarding": 'VirtualRouter', + "Firewall": 'VirtualRouter', + "Lb": 'VirtualRouter', + "UserData": 'VirtualRouter', + "StaticNat": 'VirtualRouter', + }, + "serviceCapabilityList": { + "SourceNat": { + "SupportedSourceNatTypes": "peraccount", + "RedundantRouter": "true", + }, + "lb": { + "SupportedLbIsolation": "dedicated" + }, + }, + }, + "nw_off_isolated_persistent_netscaler": { + "name": 'Netscaler', + "displaytext": 'Netscaler', + "guestiptype": 'Isolated', + "supportedservices": + 'Dhcp,Dns,SourceNat,PortForwarding,Vpn,Firewall,Lb,UserData,StaticNat', + "traffictype": 'GUEST', + "isPersistent": 'True', + "availability": 'Optional', + "serviceProviderList": { + "Dhcp": 'VirtualRouter', + "Dns": 'VirtualRouter', + "SourceNat": 'VirtualRouter', + "PortForwarding": 'VirtualRouter', + "Vpn": 'VirtualRouter', + "Firewall": 'VirtualRouter', + "Lb": 'Netscaler', + "UserData": 'VirtualRouter', + "StaticNat": 'VirtualRouter', + }, + + }, + "nw_off_persistent_VPCVR_NoLB": { + "name": 'VPC Network offering', + "displaytext": 'VPC Network off', + "guestiptype": 'Isolated', + "supportedservices": + 'Vpn,Dhcp,Dns,SourceNat,PortForwarding,UserData,StaticNat,NetworkACL', + "traffictype": 'GUEST', + "availability": 'Optional', + "isPersistent": 'True', + "useVpc": 'on', + "serviceProviderList": { + "Vpn": 'VpcVirtualRouter', + "Dhcp": 'VpcVirtualRouter', + "Dns": 'VpcVirtualRouter', + "SourceNat": 'VpcVirtualRouter', + "PortForwarding": 'VpcVirtualRouter', + "UserData": 'VpcVirtualRouter', + "StaticNat": 'VpcVirtualRouter', + "NetworkACL": 'VpcVirtualRouter' + }, + + }, + "network_offering_internal_lb": { + "name": "Network offering for internal lb service", + "displaytext": "Network offering for internal lb service", + "guestiptype": "Isolated", + "traffictype": "Guest", + "supportedservices": + "Vpn,Dhcp,Dns,Lb,UserData,SourceNat,StaticNat,PortForwarding,NetworkACL", + "serviceProviderList": { + "Dhcp": "VpcVirtualRouter", + "Dns": "VpcVirtualRouter", + "Vpn": "VpcVirtualRouter", + "UserData": "VpcVirtualRouter", + "Lb": "InternalLbVM", + "SourceNat": "VpcVirtualRouter", + "StaticNat": "VpcVirtualRouter", + "PortForwarding": "VpcVirtualRouter", + "NetworkACL": "VpcVirtualRouter", + }, + "serviceCapabilityList": { + "SourceNat": {"SupportedSourceNatTypes": "peraccount"}, + "Lb": {"lbSchemes": "internal", "SupportedLbIsolation": "dedicated"} + } + }, + "natrule": { + "privateport": 22, + "publicport": 2222, + "protocol": "TCP" + }, + "lbrule": { + "name": "SSH", + "alg": "roundrobin", + "privateport": 22, + "publicport": 2222, + "protocol": 'TCP' + }, + "iso": { + "displaytext": "Test ISO", + "name": "ISO", + "url": "http://people.apache.org/~tsp/dummy.iso", + "bootable": False, + "ispublic": False, + "ostype": "CentOS 5.6 (64-bit)", + }, + "iso1": { + "displaytext": "Test ISO 1", + "name": "ISO 1", + "url": "http://people.apache.org/~tsp/dummy.iso", + "isextractable": True, + "isfeatured": True, + "ispublic": True, + "ostype": "CentOS 5.6 (64-bit)", + }, + "iso2": { + "displaytext": "Test ISO 2", + "name": "ISO 2", + "url": "http://people.apache.org/~tsp/dummy.iso", + "isextractable": True, + "isfeatured": True, + "ispublic": True, + "ostype": "CentOS 5.6 (64-bit)", + "mode": 'HTTP_DOWNLOAD', + }, + "isfeatured": True, + "ispublic": True, + "isextractable": True, + "bootable": True, + "passwordenabled": True, + + "template": { + "displaytext": "xs", + "name": "xs", + "passwordenabled": False, + }, + "template_2": { + "displaytext": "Public Template", + "name": "Public template", + "ostype": "CentOS 5.6 (64-bit)", + "isfeatured": True, + "ispublic": True, + "isextractable": True, + "mode": "HTTP_DOWNLOAD", + }, + "templatefilter": 'self', + + "templates": { + "displaytext": 'Template', + "name": 'Template', + "ostype": "CentOS 5.3 (64-bit)", + "templatefilter": 'self', + }, + "security_group": {"name": "custom_Sec_Grp"}, + "ingress_rule": { + "protocol": "TCP", + "startport": "22", + "endport": "22", + "cidrlist": "0.0.0.0/0" + }, + "vpncustomergateway": { + "ipsecpsk": "secreatKey", + "ikepolicy": "aes128-sha1", + "ikelifetime": "86400", + "esppolicy": "aes128-sha1", + "epslifetime": "3600", + "dpd": "false" + }, + "ostype": "CentOS 5.6 (64-bit)", + "sleep": 90, + "timeout": 10, + "page": 1, + "pagesize": 2, + "listall": 'true', + "advanced_sg": { + "zone": { + "name": "", + "dns1": "8.8.8.8", + "internaldns1": "192.168.100.1", + "networktype": "Advanced", + "securitygroupenabled": "true" + }, + "securitygroupenabled": "true" + }, + "vlan": "10", + "portableiprange_vlan": { + "part": ["4090-4091", "4092-4095"], + "full": "4090-4095" + }, + "nfs": { + "url": "nfs://nfs/export/automation/1/testprimary", + "name": "Primary XEN" + }, + "iscsi": { + "url": + "iscsi://192.168.100.21/iqn.2012-01.localdomain.clo-cstack-cos6:iser/1", + "name": "Primary iSCSI" + }, + "volume": {"diskname": "Test Volume"}, + "custom_volume": { + "customdisksize": 1, + "diskname": "Custom disk", + }, + "upload_volume": { + "diskname": "UploadVol", + "format": "VHD", + "url": + "http://10.147.28.7/templates/393d3550-05ef-330f-9b8c-745b0e699759.vhd", + "checksum": "", + }, + "recurring_snapshot": { + "maxsnaps": 2, + "timezone": "US/Arizona", + }, + "volume_offerings": { + 0: {"diskname": "TestDiskServ"}, + }, + "diskdevice": ['/dev/vdc', '/dev/vdb', '/dev/hdb', '/dev/hdc', + '/dev/xvdd', '/dev/cdrom', '/dev/sr0', '/dev/cdrom1'], + + # test_vpc_vpn.py + "vpn_user": { + "username": "test", + "password": "password", + }, + "vpc": { + "name": "vpc_vpn", + "displaytext": "vpc-vpn", + "cidr": "10.1.1.0/24" + }, + "ntwk": { + "name": "tier1", + "displaytext": "vpc-tier1", + "gateway": "10.1.1.1", + "netmask": "255.255.255.192" + }, + "vpc2": { + "name": "vpc2_vpn", + "displaytext": "vpc2-vpn", + "cidr": "10.2.1.0/24" + }, + "ntwk2": { + "name": "tier2", + "displaytext": "vpc-tier2", + "gateway": "10.2.1.1", + "netmask": "255.255.255.192" + }, + "server": { + "displayname": "TestVM", + "username": "root", + "password": "password", + "ssh_port": 22, + "hypervisor": 'XenServer', + "privateport": 22, + "publicport": 22, + "protocol": 'TCP' + }, + "privateport": 22, + "publicport": 22, + "protocol": 'TCP', + "forvirtualnetwork": "true", + "customdisksize": 1, + "diskname": "Test Volume", + "portableIpRange": { + "gateway": "10.223.252.195", + "netmask": "255.255.255.192", + "startip": "10.223.252.196", + "endip": "10.223.252.197", + "vlan": "1001" + }, + "sparse": { + "name": "Sparse Type Disk offering", + "displaytext": + "Sparse Type Disk offering", + "disksize": 1, # in GB + "provisioningtype": "sparse" + }, + "fat": { + "name": "Fat Type Disk offering", + "displaytext": + "Fat Type Disk offering", + "disksize": 1, # in GB + "provisioningtype": "fat" + }, + "sparse_disk_offering": { + "displaytext": "Sparse", + "name": "Sparse", + "provisioningtype": "sparse", + "disksize": 1 + } +} diff --git a/tools/marvin/marvin/configGenerator.py b/tools/marvin/marvin/configGenerator.py index 0b4a0a132bc..68ec24eb2bc 100644 --- a/tools/marvin/marvin/configGenerator.py +++ b/tools/marvin/marvin/configGenerator.py @@ -20,9 +20,12 @@ import os from optparse import OptionParser import jsonHelper from marvin.codes import * +from marvin.cloudstackException import GetDetailExceptionInfo +from marvin.config.test_data import test_data class managementServer(object): + def __init__(self): self.mgtSvrIp = None self.port = 8096 @@ -34,6 +37,7 @@ class managementServer(object): class dbServer(object): + def __init__(self): self.dbSvr = None self.port = 3306 @@ -50,8 +54,7 @@ class configuration(object): class logger(object): def __init__(self): - '''TestCase/TestClient''' - self.logFolderPath = None + self.LogFolderPath = None class cloudstackConfiguration(object): @@ -61,6 +64,7 @@ class cloudstackConfiguration(object): self.dbSvr = None self.globalConfig = [] self.logger = None + self.TestData = None class zone(object): @@ -83,6 +87,7 @@ class zone(object): class trafficType(object): + def __init__(self, typ, labeldict=None): self.typ = typ # Guest/Management/Public if labeldict: @@ -95,6 +100,7 @@ class trafficType(object): class pod(object): + def __init__(self): self.gateway = None self.name = None @@ -109,6 +115,7 @@ class pod(object): class VmwareDc(object): + def __init__(self): self.zoneid = None self.name = None @@ -118,6 +125,7 @@ class VmwareDc(object): class cluster(object): + def __init__(self): self.clustername = None self.clustertype = None @@ -132,6 +140,7 @@ class cluster(object): class host(object): + def __init__(self): self.hypervisor = None self.password = None @@ -149,6 +158,7 @@ class host(object): class physicalNetwork(object): + def __init__(self): self.name = None self.tags = [] @@ -163,6 +173,7 @@ class physicalNetwork(object): class provider(object): + def __init__(self, name=None): self.name = name self.state = None @@ -173,6 +184,7 @@ class provider(object): class network(object): + def __init__(self): self.displaytext = None self.name = None @@ -185,6 +197,7 @@ class network(object): class iprange(object): + def __init__(self): '''tagged/untagged''' self.gateway = None @@ -198,12 +211,14 @@ class iprange(object): class primaryStorage(object): + def __init__(self): self.name = None self.url = None class secondaryStorage(object): + def __init__(self): self.url = None self.provider = None @@ -211,6 +226,7 @@ class secondaryStorage(object): class cacheStorage(object): + def __init__(self): self.url = None self.provider = None @@ -218,6 +234,7 @@ class cacheStorage(object): class s3(object): + def __init__(self): self.accesskey = None self.secretkey = None @@ -230,6 +247,7 @@ class s3(object): class netscaler(object): + def __init__(self, hostname=None, username='nsroot', password='nsroot'): self.hostname = hostname self.username = username @@ -246,11 +264,12 @@ class netscaler(object): def __repr__(self): req = zip(self.__dict__.keys(), self.__dict__.values()) - return self.hostname+"?" + "&".join(["=".join([r[0], r[1]]) - for r in req]) + return self.hostname + "?" + "&".join(["=".join([r[0], r[1]]) + for r in req]) class srx(object): + def __init__(self, hostname=None, username='root', password='admin'): self.hostname = hostname self.username = username @@ -269,11 +288,12 @@ class srx(object): def __repr__(self): req = zip(self.__dict__.keys(), self.__dict__.values()) - return self.hostname+"?" + "&".join(["=".join([r[0], r[1]]) - for r in req]) + return self.hostname + "?" + "&".join(["=".join([r[0], r[1]]) + for r in req]) class bigip(object): + def __init__(self, hostname=None, username='root', password='default'): self.hostname = hostname self.username = username @@ -290,14 +310,14 @@ class bigip(object): def __repr__(self): req = zip(self.__dict__.keys(), self.__dict__.values()) - return self.hostname+"?" + "&".join(["=".join([r[0], r[1]]) - for r in req]) + return self.hostname + "?" + "&".join(["=".join([r[0], r[1]]) + for r in req]) class ConfigManager(object): ''' - @Name: configManager + @Name: ConfigManager @Desc: 1. It provides the basic configuration facilities to marvin. 2. User can just add configuration files for his tests, deployment etc, under one config folder before running their tests. @@ -328,16 +348,21 @@ class ConfigManager(object): "getConfig" API,once configObj is returned. ''' - def __init__(self): - # Joining path with current directory will avoid relative path issue - # It will take correct path irrespective of from where the test case is run - dirPath = os.path.dirname(__file__) - self.filePath = os.path.join(dirPath, 'config/config.cfg') - self.parsedDict = None - if self.__verifyFile(self.filePath) is not False: - self.parsedDict = self.__parseConfig(self.filePath) + def __init__(self, cfg_file=None): + self.__filePath = cfg_file + self.__parsedCfgDict = None + ''' + Set the Configuration + ''' + self.__setConfig() - def __parseConfig(self, file): + def __setConfig(self): + if not self.__verifyFile(): + dirPath = os.path.dirname(__file__) + self.__filePath = str(os.path.join(dirPath, "config/test_data.py")) + self.__parsedCfgDict = self.__parseConfig() + + def __parseConfig(self): ''' @Name : __parseConfig @Description: Parses the Input configuration Json file @@ -348,36 +373,38 @@ class ConfigManager(object): ''' config_dict = None try: - configlines = [] - with open(file, 'r') as fp: - for line in fp: - if len(line) != 0: + if self.__filePath.endswith(".py"): + config_dict = test_data + else: + configLines = [] + with open(file, 'r') as fp: + for line in fp: ws = line.strip() - if ws[0] not in ["#"]: - configlines.append(ws) - config_dict = json.loads("\n".join(configlines)) - except Exception, e: - #Will replace with log once we have logging done - print "\n Exception occurred under __parseConfig", e + if not ws.startswith("#"): + configLines.append(ws) + config = json.loads("\n".join(configLines)) + config_dict = config + except Exception as e: + # Will replace with log once we have logging done + print "\n Exception occurred under ConfigManager:__parseConfig" \ + " :%s", GetDetailExceptionInfo(e) finally: return config_dict - def __verifyFile(self, file): + def __verifyFile(self): ''' @Name : __parseConfig @Description: Parses the Input configuration Json file and returns a dictionary from the file. - @Input : file NA + @Input : NA @Output : True or False based upon file input validity and availability ''' - if file is None or file == '': + if self.__filePath is None or self.__filePath == '': return False - if os.path.exists(file) is False: - return False - return True + return os.path.exists(self.__filePath) - def __getSectionData(self, return_dict, section=None): + def getSectionData(self, section=None): ''' @Name: getSectionData @Desc: Gets the Section data of a particular section @@ -386,43 +413,29 @@ class ConfigManager(object): section to be returned from this dict @Output:Section matching inside the parsed data ''' - if return_dict is not None: - inp = return_dict - elif self.parsedDict is None: + if self.__parsedCfgDict is None or section is None: + print "\nEither Parsed Dictionary is None or Section is None" return INVALID_INPUT - else: - inp = self.parsedDict - if section is not None: - return inp.get(section) - else: - return inp + return self.__parsedCfgDict.get(section) - def getConfig(self, file_path=None, section=None): + def getConfig(self): ''' - @Name: getConfig - @Desc : Parses and converts the given configuration file to dictionary - @Input : file_path: path where the configuration needs to be passed - section: specific section inside the file - @Output: INVALID_INPUT: This value is returned if the input - is invalid or not able to be parsed - Parsed configuration dictionary from json file + @Name : getConfig + @Desc : Returns the Parsed Dictionary of Config Provided + @Input : NA + @Output: ParsedDict if successful if cfg file provided is valid + None if cfg file is invalid or not able to be parsed ''' - ret = None - if file not in [None, '']: - if self.__verifyFile(file_path) is False: - return INVALID_INPUT - else: - ret = self.__parseConfig(file_path) - return self.__getSectionData(ret, section) + return self.__parsedCfgDict def getDeviceUrl(obj): req = zip(obj.__dict__.keys(), obj.__dict__.values()) if obj.hostname: - return "http://" + obj.hostname+"?" + "&".join(["=".join([r[0], - r[1]]) - for r in req]) + return "http://" + obj.hostname + "?" + "&".join(["=".join([r[0], + r[1]]) + for r in req]) else: return None @@ -437,11 +450,11 @@ def descSetupInBasicMode(): z.dns2 = "8.8.4.4" z.internaldns1 = "192.168.110.254" z.internaldns2 = "192.168.110.253" - z.name = "test"+str(l) + z.name = "test" + str(l) z.networktype = 'Basic' z.securitygroupenabled = 'True' - #If security groups are reqd + # If security groups are reqd sgprovider = provider() sgprovider.broadcastdomainrange = 'Pod' sgprovider.name = 'SecurityGroupProvider' @@ -467,15 +480,15 @@ def descSetupInBasicMode(): ip = iprange() ip.gateway = p.gateway ip.netmask = p.netmask - ip.startip = "192.168.%d.%d" % (i, j*20) - ip.endip = "192.168.%d.%d" % (i, j*20+10) + ip.startip = "192.168.%d.%d" % (i, j * 20) + ip.endip = "192.168.%d.%d" % (i, j * 20 + 10) p.guestIpRanges.append(ip) '''add 10 clusters''' for j in range(2): c = cluster() - c.clustername = "test"+str(l)+str(i) + str(j) + c.clustername = "test" + str(l) + str(i) + str(j) c.clustertype = "CloudManaged" c.hypervisor = "Simulator" @@ -484,15 +497,16 @@ def descSetupInBasicMode(): h = host() h.username = "root" h.password = "password" - memory = 8*1024*1024*1024 - localstorage = 1*1024*1024*1024*1024 + memory = 8 * 1024 * 1024 * 1024 + localstorage = 1 * 1024 * 1024 * 1024 * 1024 h.url = "http://sim/%d%d%d%d" % (l, i, j, k) c.hosts.append(h) '''add 2 primary storages''' for m in range(2): primary = primaryStorage() - primary.name = "primary"+str(l) + str(i) + str(j) + str(m) + primary.name = "primary" + \ + str(l) + str(i) + str(j) + str(m) primary.url = "nfs://localhost/path%s" % (str(l) + str(i) + str(j) + str(m)) c.primaryStorages.append(primary) @@ -504,7 +518,7 @@ def descSetupInBasicMode(): '''add two secondary''' for i in range(5): secondary = secondaryStorage() - secondary.url = "nfs://localhost/path"+str(l) + str(i) + secondary.url = "nfs://localhost/path" + str(l) + str(i) z.secondaryStorages.append(secondary) zs.zones.append(z) @@ -546,7 +560,7 @@ def descSetupInEipMode(): z.dns2 = "8.8.4.4" z.internaldns1 = "192.168.110.254" z.internaldns2 = "192.168.110.253" - z.name = "test"+str(l) + z.name = "test" + str(l) z.networktype = 'Basic' ips = iprange() @@ -557,7 +571,7 @@ def descSetupInEipMode(): ips.netmask = "255.255.255.0" z.ipranges.append(ips) - #If security groups are reqd + # If security groups are reqd sgprovider = provider() sgprovider.broadcastdomainrange = 'Pod' sgprovider.name = 'SecurityGroupProvider' @@ -591,15 +605,15 @@ def descSetupInEipMode(): ip = iprange() ip.gateway = p.gateway ip.netmask = p.netmask - ip.startip = "192.168.%d.%d" % (i, j*20) - ip.endip = "192.168.%d.%d" % (i, j*20+10) + ip.startip = "192.168.%d.%d" % (i, j * 20) + ip.endip = "192.168.%d.%d" % (i, j * 20 + 10) p.guestIpRanges.append(ip) '''add 10 clusters''' for j in range(2): c = cluster() - c.clustername = "test"+str(l)+str(i) + str(j) + c.clustername = "test" + str(l) + str(i) + str(j) c.clustertype = "CloudManaged" c.hypervisor = "Simulator" @@ -614,7 +628,8 @@ def descSetupInEipMode(): '''add 2 primary storages''' for m in range(2): primary = primaryStorage() - primary.name = "primary"+str(l) + str(i) + str(j) + str(m) + primary.name = "primary" + \ + str(l) + str(i) + str(j) + str(m) primary.url = "nfs://localhost/path%s" % (str(l) + str(i) + str(j) + str(m)) @@ -627,7 +642,7 @@ def descSetupInEipMode(): '''add two secondary''' for i in range(5): secondary = secondaryStorage() - secondary.url = "nfs://localhost/path"+str(l) + str(i) + secondary.url = "nfs://localhost/path" + str(l) + str(i) z.secondaryStorages.append(secondary) zs.zones.append(z) @@ -667,7 +682,7 @@ def descSetupInAdvancedMode(): z.dns2 = "8.8.4.4" z.internaldns1 = "192.168.110.254" z.internaldns2 = "192.168.110.253" - z.name = "test"+str(l) + z.name = "test" + str(l) z.networktype = 'Advanced' z.guestcidraddress = "10.1.1.0/24" z.vlan = "100-2000" @@ -703,7 +718,7 @@ def descSetupInAdvancedMode(): '''add 10 clusters''' for j in range(2): c = cluster() - c.clustername = "test"+str(l)+str(i) + str(j) + c.clustername = "test" + str(l) + str(i) + str(j) c.clustertype = "CloudManaged" c.hypervisor = "Simulator" @@ -714,7 +729,7 @@ def descSetupInAdvancedMode(): h.password = "password" memory = 8 * 1024 * 1024 * 1024 localstorage = 1 * 1024 * 1024 * 1024 * 1024 - #h.url = "http://sim/%d%d%d%d/cpucore=1&cpuspeed=8000&\ + # h.url = "http://sim/%d%d%d%d/cpucore=1&cpuspeed=8000&\ # memory=%d&localstorage=%d"%(l, i, j, k, memory, # localstorage) h.url = "http://sim/%d%d%d%d" % (l, i, j, k) @@ -723,8 +738,9 @@ def descSetupInAdvancedMode(): '''add 2 primary storages''' for m in range(2): primary = primaryStorage() - primary.name = "primary"+str(l) + str(i) + str(j) + str(m) - #primary.url = "nfs://localhost/path%s/size=%d" % + primary.name = "primary" + \ + str(l) + str(i) + str(j) + str(m) + # primary.url = "nfs://localhost/path%s/size=%d" % # (str(l) + str(i) + str(j) + str(m), size) primary.url = "nfs://localhost/path%s" % (str(l) + str(i) + str(j) @@ -738,7 +754,7 @@ def descSetupInAdvancedMode(): '''add two secondary''' for i in range(5): secondary = secondaryStorage() - secondary.url = "nfs://localhost/path"+str(l) + str(i) + secondary.url = "nfs://localhost/path" + str(l) + str(i) z.secondaryStorages.append(secondary) '''add default public network''' @@ -788,7 +804,7 @@ def descSetupInAdvancedsgMode(): z.dns2 = "8.8.4.4" z.internaldns1 = "192.168.110.254" z.internaldns2 = "192.168.110.253" - z.name = "test"+str(l) + z.name = "test" + str(l) z.networktype = 'Advanced' z.vlan = "100-2000" z.securitygroupenabled = "true" @@ -797,7 +813,7 @@ def descSetupInAdvancedsgMode(): pn.name = "test-network" pn.traffictypes = [trafficType("Guest"), trafficType("Management")] - #If security groups are reqd + # If security groups are reqd sgprovider = provider() sgprovider.broadcastdomainrange = 'ZONE' sgprovider.name = 'SecurityGroupProvider' @@ -817,7 +833,7 @@ def descSetupInAdvancedsgMode(): '''add 10 clusters''' for j in range(2): c = cluster() - c.clustername = "test"+str(l)+str(i) + str(j) + c.clustername = "test" + str(l) + str(i) + str(j) c.clustertype = "CloudManaged" c.hypervisor = "Simulator" @@ -828,17 +844,18 @@ def descSetupInAdvancedsgMode(): h.password = "password" memory = 8 * 1024 * 1024 * 1024 localstorage = 1 * 1024 * 1024 * 1024 * 1024 - #h.url = "http://sim/%d%d%d%d/cpucore=1&cpuspeed=8000&\ - #memory=%d&localstorage=%d" % (l, i, j, k, memory, - #localstorage) + # h.url = "http://sim/%d%d%d%d/cpucore=1&cpuspeed=8000&\ + # memory=%d&localstorage=%d" % (l, i, j, k, memory, + # localstorage) h.url = "http://sim/%d%d%d%d" % (l, i, j, k) c.hosts.append(h) '''add 2 primary storages''' for m in range(2): primary = primaryStorage() - primary.name = "primary"+str(l) + str(i) + str(j) + str(m) - #primary.url = "nfs://localhost/path%s/size=%d" % \ + primary.name = "primary" + \ + str(l) + str(i) + str(j) + str(m) + # primary.url = "nfs://localhost/path%s/size=%d" % \ #(str(l) + str(i) + str(j) + str(m), size) primary.url = "nfs://localhost/path%s" % \ (str(l) + str(i) + str(j) + str(m)) @@ -851,7 +868,7 @@ def descSetupInAdvancedsgMode(): '''add two secondary''' for i in range(5): secondary = secondaryStorage() - secondary.url = "nfs://localhost/path"+str(l) + str(i) + secondary.url = "nfs://localhost/path" + str(l) + str(i) z.secondaryStorages.append(secondary) '''add default guest network''' @@ -901,18 +918,19 @@ def generate_setup_config(config, file=None): def getSetupConfig(file): - if not os.path.exists(file): - raise IOError("config file %s not found. \ - please specify a valid config file" % file) - config = cloudstackConfiguration() - configLines = [] - with open(file, 'r') as fp: - for line in fp: - ws = line.strip() - if not ws.startswith("#"): - configLines.append(ws) - config = json.loads("\n".join(configLines)) - return jsonHelper.jsonLoader(config) + try: + config = cloudstackConfiguration() + configLines = [] + with open(file, 'r') as fp: + for line in fp: + ws = line.strip() + if not ws.startswith("#"): + configLines.append(ws) + config = json.loads("\n".join(configLines)) + return jsonHelper.jsonLoader(config) + except Exception as e: + print "\nException Occurred under getSetupConfig %s" % \ + GetDetailExceptionInfo(e) if __name__ == "__main__": parser = OptionParser() diff --git a/tools/marvin/marvin/dbConnection.py b/tools/marvin/marvin/dbConnection.py index 99014abfa20..66c6cb17738 100644 --- a/tools/marvin/marvin/dbConnection.py +++ b/tools/marvin/marvin/dbConnection.py @@ -20,12 +20,13 @@ import contextlib from mysql import connector from mysql.connector import errors from contextlib import closing -import cloudstackException +from marvin import cloudstackException import sys import os -class dbConnection(object): +class DbConnection(object): + def __init__(self, host="localhost", port=3306, user='cloud', passwd='cloud', db='cloud'): self.host = host @@ -51,7 +52,7 @@ class dbConnection(object): try: resultRow = cursor.fetchall() except errors.InterfaceError: - #Raised on empty result - DML + # Raised on empty result - DML resultRow = [] return resultRow @@ -68,7 +69,7 @@ class dbConnection(object): return self.execute(sqls) if __name__ == "__main__": - db = dbConnection() + db = DbConnection() ''' try: diff --git a/tools/marvin/marvin/deployAndRun.py b/tools/marvin/marvin/deployAndRun.py index 56747a7cb2d..d3b6b8606b0 100644 --- a/tools/marvin/marvin/deployAndRun.py +++ b/tools/marvin/marvin/deployAndRun.py @@ -15,13 +15,13 @@ # specific language governing permissions and limitations # under the License. -from tcExecuteEngine import TestCaseExecuteEngine +from .tcExecuteEngine import TestCaseExecuteEngine import sys import os import traceback import time from argparse import ArgumentParser -from marvinInit import MarvinInit +from .marvinInit import MarvinInit from marvin.codes import (SUCCESS, FAILED, EXCEPTION, @@ -96,7 +96,7 @@ def startMarvin(cfg_file, load_flag): else: print "\nMarvin Initialization Failed" exit(1) - except Exception, e: + except Exception as e: print "\n Exception occurred while starting Marvin %s" % str(e) exit(1) diff --git a/tools/marvin/marvin/deployDataCenter.py b/tools/marvin/marvin/deployDataCenter.py index e5a0749593d..31f663e9d31 100644 --- a/tools/marvin/marvin/deployDataCenter.py +++ b/tools/marvin/marvin/deployDataCenter.py @@ -15,469 +15,768 @@ # specific language governing permissions and limitations # under the License. -"""Deploy datacenters according to a json configuration file""" -import configGenerator -import cloudstackException -import cloudstackTestClient -import logging -from cloudstackAPI import * -from os import path -from time import sleep +""" +@Desc : +class DeployDataCenters: Deploys DeleteDataCenters according to a json + configuration file. +class DeleteDataCenters: Deletes a DataCenter based upon the dc cfg + settings provided. + This settings file is the exported + configuration from DeployDataCenters post + its success +""" +from marvin import configGenerator +from marvin.cloudstackException import ( + InvalidParameterException, + GetDetailExceptionInfo) +from marvin.cloudstackAPI import * +from marvin.codes import (FAILED, SUCCESS) +from marvin.lib.utils import (random_gen) +from marvin.config.test_data import test_data +from sys import exit +import os +import pickle +from time import sleep, strftime, localtime from optparse import OptionParser -class deployDataCenters(object): +class DeployDataCenters(object): - def __init__(self, cfg, logger=None): - self.config = cfg - self.tcRunLogger = logger + ''' + @Desc : Deploys the Data Center with information provided. + Once the Deployment is successful, it will export + the DataCenter settings to an obj file + ( can be used if wanted to delete the created DC) + ''' + + def __init__(self, + test_client, + cfg, + logger=None, + log_folder_path=None + ): + self.__testClient = test_client + self.__config = cfg + self.__tcRunLogger = logger + self.__logFolderPath = log_folder_path + self.__apiClient = None + self.__cleanUp = {} + + def __persistDcConfig(self): + try: + if self.__logFolderPath: + dc_file_path = self.__logFolderPath + "/dc_entries.obj" + else: + ts = strftime("%b_%d_%Y_%H_%M_%S", localtime()) + dc_file_path = "dc_entries_" + str(ts) + ".obj" + file_to_write = open(dc_file_path, 'w') + if file_to_write: + pickle.dump(self.__cleanUp, file_to_write) + print "\n=== Data Center Settings are dumped to %s===" % \ + dc_file_path + self.__tcRunLogger.debug( + "\n=== Data Center Settings are dumped to %s===" % + dc_file_path) + except Exception as e: + print "Exception Occurred while persisting DC Settings: %s" % \ + GetDetailExceptionInfo(e) + + def __cleanAndExit(self): + try: + print "\n===deploy dc failed, so cleaning the created entries===" + if not test_data.get("deleteDC", None): + print "\n=== Deploy DC Clean Up flag not set. So, exiting ===" + exit(1) + self.__tcRunLogger.debug( + "===Deploy DC Failed, So Cleaning to Exit===") + remove_dc_obj = DeleteDataCenters(self.__testClient, + dc_cfg=self.__cleanUp, + tc_run_logger=self.__tcRunLogger + ) + if remove_dc_obj: + if remove_dc_obj.removeDataCenter() == FAILED: + print "\n===Removing DataCenter Failed===" + self.__tcRunLogger.debug( + "===Removing DataCenter Failed===") + else: + print "\n===Removing DataCenter Successful===" + self.__tcRunLogger.debug( + "===Removing DataCenter Successful===") + exit(1) + except Exception as e: + print "Exception Occurred during DC CleanUp: %s" % \ + GetDetailExceptionInfo(e) + + def __addToCleanUp(self, type, id): + if type not in self.__cleanUp.keys(): + self.__cleanUp[type] = [] + self.__cleanUp[type].append(id) + if "order" not in self.__cleanUp.keys(): + self.__cleanUp["order"] = [] + if type not in self.__cleanUp["order"]: + self.__cleanUp["order"].append(type) def addHosts(self, hosts, zoneId, podId, clusterId, hypervisor): - if hosts is None: - return - for host in hosts: - hostcmd = addHost.addHostCmd() - hostcmd.clusterid = clusterId - hostcmd.cpunumber = host.cpunumer - hostcmd.cpuspeed = host.cpuspeed - hostcmd.hostmac = host.hostmac - hostcmd.hosttags = host.hosttags - hostcmd.hypervisor = host.hypervisor - hostcmd.memory = host.memory - hostcmd.password = host.password - hostcmd.podid = podId - hostcmd.url = host.url - hostcmd.username = host.username - hostcmd.zoneid = zoneId - hostcmd.hypervisor = hypervisor - self.apiClient.addHost(hostcmd) + try: + if hosts is None: + return + for host in hosts: + hostcmd = addHost.addHostCmd() + hostcmd.clusterid = clusterId + hostcmd.cpunumber = host.cpunumer + hostcmd.cpuspeed = host.cpuspeed + hostcmd.hostmac = host.hostmac + hostcmd.hosttags = host.hosttags + hostcmd.hypervisor = host.hypervisor + hostcmd.memory = host.memory + hostcmd.password = host.password + hostcmd.podid = podId + hostcmd.url = host.url + hostcmd.username = host.username + hostcmd.zoneid = zoneId + hostcmd.hypervisor = hypervisor + ret = self.__apiClient.addHost(hostcmd) + if ret: + self.__tcRunLogger.debug("=== Add Host Successful ===") + self.__addToCleanUp("Host", ret[0].id) + except Exception as e: + print "Exception Occurred %s" % GetDetailExceptionInfo(e) + self.__tcRunLogger.exception("=== Adding Host Failed ===") + self.__cleanAndExit() def addVmWareDataCenter(self, vmwareDc): - vdc = addVmwareDc.addVmwareDcCmd() - vdc.zoneid = vmwareDc.zoneid - vdc.name = vmwareDc.name - vdc.vcenter = vmwareDc.vcenter - vdc.username = vmwareDc.username - vdc.password = vmwareDc.password - self.apiClient.addVmwareDc(vdc) + try: + vdc = addVmwareDc.addVmwareDcCmd() + vdc.zoneid = vmwareDc.zoneid + vdc.name = vmwareDc.name + vdc.vcenter = vmwareDc.vcenter + vdc.username = vmwareDc.username + vdc.password = vmwareDc.password + ret = self.__apiClient.addVmwareDc(vdc) + if ret.id: + self.__tcRunLogger.debug("=== Adding VmWare DC Successful===") + self.__addToCleanUp("VmwareDc", ret.id) + except Exception as e: + print "Exception Occurred: %s" % GetDetailExceptionInfo(e) + self.__tcRunLogger.exception("=== Adding VmWare DC Failed===") + self.__cleanAndExit() def createClusters(self, clusters, zoneId, podId, vmwareDc=None): - if clusters is None: - return + try: + if clusters is None: + return + if vmwareDc is not None: + vmwareDc.zoneid = zoneId + self.addVmWareDataCenter(vmwareDc) - if vmwareDc is not None: - vmwareDc.zoneid = zoneId - self.addVmWareDataCenter(vmwareDc) - - for cluster in clusters: - clustercmd = addCluster.addClusterCmd() - clustercmd.clustername = cluster.clustername - clustercmd.clustertype = cluster.clustertype - clustercmd.hypervisor = cluster.hypervisor - clustercmd.password = cluster.password - clustercmd.podid = podId - clustercmd.url = cluster.url - clustercmd.username = cluster.username - clustercmd.zoneid = zoneId - clusterresponse = self.apiClient.addCluster(clustercmd) - clusterId = clusterresponse[0].id - - if cluster.hypervisor.lower() != "vmware": - self.addHosts(cluster.hosts, zoneId, podId, clusterId, - cluster.hypervisor) - self.waitForHost(zoneId, clusterId) - self.createPrimaryStorages(cluster.primaryStorages, zoneId, podId, - clusterId) + for cluster in clusters: + clustercmd = addCluster.addClusterCmd() + clustercmd.clustername = cluster.clustername + clustercmd.clustertype = cluster.clustertype + clustercmd.hypervisor = cluster.hypervisor + clustercmd.password = cluster.password + clustercmd.podid = podId + clustercmd.url = cluster.url + clustercmd.username = cluster.username + clustercmd.zoneid = zoneId + clusterresponse = self.__apiClient.addCluster(clustercmd) + if clusterresponse[0].id: + clusterId = clusterresponse[0].id + self.__tcRunLogger.\ + debug("Cluster Name : %s Id : %s Created Successfully" + % (str(cluster.clustername), str(clusterId))) + self.__addToCleanUp("Cluster", clusterId) + if cluster.hypervisor.lower() != "vmware": + self.addHosts(cluster.hosts, zoneId, podId, clusterId, + cluster.hypervisor) + self.waitForHost(zoneId, clusterId) + self.createPrimaryStorages(cluster.primaryStorages, + zoneId, + podId, + clusterId) + except Exception as e: + print "Exception Occurred %s" % GetDetailExceptionInfo(e) + self.__tcRunLogger.exception("====Cluster %s Creation Failed" + "=====" % + str(cluster.clustername)) + self.__cleanAndExit() def waitForHost(self, zoneId, clusterId): """ Wait for the hosts in the zoneid, clusterid to be up - 2 retries with 30s delay """ - retry, timeout = 2, 30 - cmd = listHosts.listHostsCmd() - cmd.clusterid, cmd.zoneid = clusterId, zoneId - hosts = self.apiClient.listHosts(cmd) - while retry != 0: - for host in hosts: - if host.state != 'Up': - break - sleep(timeout) - retry = retry - 1 + try: + retry, timeout = 2, 30 + cmd = listHosts.listHostsCmd() + cmd.clusterid, cmd.zoneid = clusterId, zoneId + hosts = self.__apiClient.listHosts(cmd) + while retry != 0: + for host in hosts: + if host.state != 'Up': + break + sleep(timeout) + retry = retry - 1 + except Exception as e: + print "\nException Occurred:%s" %\ + GetDetailExceptionInfo(e) + self.__tcRunLogger.exception("=== List Hosts Failed===") + self.__cleanAndExit() - def createPrimaryStorages(self, primaryStorages, zoneId, podId, clusterId): - if primaryStorages is None: - return - for primary in primaryStorages: - primarycmd = createStoragePool.createStoragePoolCmd() - primarycmd.details = primary.details - primarycmd.name = primary.name - primarycmd.podid = podId - primarycmd.tags = primary.tags - primarycmd.url = primary.url - primarycmd.zoneid = zoneId - primarycmd.clusterid = clusterId - self.apiClient.createStoragePool(primarycmd) + def createPrimaryStorages(self, + primaryStorages, + zoneId, + podId, + clusterId): + try: + if primaryStorages is None: + return + for primary in primaryStorages: + primarycmd = createStoragePool.createStoragePoolCmd() + primarycmd.details = primary.details + primarycmd.name = primary.name + primarycmd.podid = podId + primarycmd.tags = primary.tags + primarycmd.url = primary.url + primarycmd.zoneid = zoneId + primarycmd.clusterid = clusterId + ret = self.__apiClient.createStoragePool(primarycmd) + if ret.id: + self.__tcRunLogger.debug( + "=== Creating Storage Pool Successful===") + self.__addToCleanUp("StoragePool", ret.id) + except Exception as e: + print "Exception Occurred: %s" % GetDetailExceptionInfo(e) + self.__tcRunLogger.\ + exception("=== Create Storage Pool Failed===") + self.__cleanAndExit() - def createPods(self, pods, zoneId, networkId=None): - if pods is None: - return - for pod in pods: - createpod = createPod.createPodCmd() - createpod.name = pod.name - createpod.gateway = pod.gateway - createpod.netmask = pod.netmask - createpod.startip = pod.startip - createpod.endip = pod.endip - createpod.zoneid = zoneId - createpodResponse = self.apiClient.createPod(createpod) - podId = createpodResponse.id - - if pod.guestIpRanges is not None and networkId is not None: - self.createVlanIpRanges("Basic", pod.guestIpRanges, zoneId, - podId, networkId) - - self.createClusters(pod.clusters, zoneId, podId, - vmwareDc=pod.vmwaredc) + def createPods(self, + pods, + zoneId, + networkId=None): + try: + if pods is None: + return + for pod in pods: + createpod = createPod.createPodCmd() + createpod.name = pod.name + createpod.gateway = pod.gateway + createpod.netmask = pod.netmask + createpod.startip = pod.startip + createpod.endip = pod.endip + createpod.zoneid = zoneId + createpodResponse = self.__apiClient.createPod(createpod) + if createpodResponse.id: + podId = createpodResponse.id + self.__tcRunLogger.debug("Pod Name : %s Id : %s " + "Created Successfully" % + (str(pod.name), str(podId))) + self.__addToCleanUp("Pod", podId) + if pod.guestIpRanges is not None and networkId is not None: + self.createVlanIpRanges("Basic", pod.guestIpRanges, zoneId, + podId, networkId) + self.createClusters(pod.clusters, zoneId, podId, + vmwareDc=pod.vmwaredc) + except Exception as e: + print "Exception Occurred: %s" % GetDetailExceptionInfo(e) + self.__tcRunLogger.\ + exception("====Pod: %s Creation " + "Failed=====" % str(pod.name)) + self.__cleanAndExit() def createVlanIpRanges(self, mode, ipranges, zoneId, podId=None, networkId=None, forvirtualnetwork=None): - if ipranges is None: - return - for iprange in ipranges: - vlanipcmd = createVlanIpRange.createVlanIpRangeCmd() - vlanipcmd.account = iprange.account - vlanipcmd.domainid = iprange.domainid - vlanipcmd.endip = iprange.endip - vlanipcmd.gateway = iprange.gateway - vlanipcmd.netmask = iprange.netmask - vlanipcmd.networkid = networkId - vlanipcmd.podid = podId - vlanipcmd.startip = iprange.startip - vlanipcmd.zoneid = zoneId - vlanipcmd.vlan = iprange.vlan - if mode == "Basic": - if forvirtualnetwork: - vlanipcmd.forvirtualnetwork = "true" + try: + if ipranges is None: + return + for iprange in ipranges: + vlanipcmd = createVlanIpRange.createVlanIpRangeCmd() + vlanipcmd.account = iprange.account + vlanipcmd.domainid = iprange.domainid + vlanipcmd.endip = iprange.endip + vlanipcmd.gateway = iprange.gateway + vlanipcmd.netmask = iprange.netmask + vlanipcmd.networkid = networkId + vlanipcmd.podid = podId + vlanipcmd.startip = iprange.startip + vlanipcmd.zoneid = zoneId + vlanipcmd.vlan = iprange.vlan + if mode == "Basic": + if forvirtualnetwork: + vlanipcmd.forvirtualnetwork = "true" + else: + vlanipcmd.forvirtualnetwork = "false" else: - vlanipcmd.forvirtualnetwork = "false" - else: - vlanipcmd.forvirtualnetwork = "true" - self.apiClient.createVlanIpRange(vlanipcmd) + vlanipcmd.forvirtualnetwork = "true" + ret = self.__apiClient.createVlanIpRange(vlanipcmd) + if ret.id: + self.__tcRunLogger.debug( + "=== Creating Vlan Ip Range Successful===") + self.__addToCleanUp("VlanIpRange", ret.id) + except Exception as e: + print "Exception Occurred: %s" % GetDetailExceptionInfo(e) + self.__tcRunLogger.\ + exception("=== Create Vlan Ip Range Failed===") + self.__cleanAndExit() def createSecondaryStorages(self, secondaryStorages, zoneId): - if secondaryStorages is None: - return - for secondary in secondaryStorages: - secondarycmd = addImageStore.addImageStoreCmd() - secondarycmd.url = secondary.url - secondarycmd.provider = secondary.provider - secondarycmd.details = [] + try: + if secondaryStorages is None: + return + for secondary in secondaryStorages: + secondarycmd = addImageStore.addImageStoreCmd() + secondarycmd.url = secondary.url + secondarycmd.provider = secondary.provider + secondarycmd.details = [] - if secondarycmd.provider == 'S3' \ - or secondarycmd.provider == "Swift": - for key, value in vars(secondary.details).iteritems(): - secondarycmd.details.append({ + if secondarycmd.provider == 'S3' \ + or secondarycmd.provider == "Swift": + for key, value in vars(secondary.details).iteritems(): + secondarycmd.details.append({ + 'key': key, + 'value': value + }) + if secondarycmd.provider == "NFS": + secondarycmd.zoneid = zoneId + ret = self.__apiClient.addImageStore(secondarycmd) + if ret.id: + self.__tcRunLogger.debug( + "===Add Image Store Successful===") + self.__addToCleanUp("ImageStore", ret.id) + except Exception as e: + print "Exception Occurred: %s" % GetDetailExceptionInfo(e) + self.__tcRunLogger.\ + exception("=== Add Image Store Failed===") + self.__cleanAndExit() + + def createCacheStorages(self, cacheStorages, zoneId): + try: + if cacheStorages is None: + return + for cache in cacheStorages: + cachecmd = createSecondaryStagingStore.\ + createSecondaryStagingStoreCmd() + cachecmd.url = cache.url + cachecmd.provider = cache.provider + cachecmd.zoneid = zoneId + cachecmd.details = [] + + if cache.details: + for key, value in vars(cache.details).iteritems(): + cachecmd.details.append({ 'key': key, 'value': value }) - if secondarycmd.provider == "NFS": - secondarycmd.zoneid = zoneId - self.apiClient.addImageStore(secondarycmd) - - def createCacheStorages(self, cacheStorages, zoneId): - if cacheStorages is None: - return - for cache in cacheStorages: - cachecmd = createSecondaryStagingStore.\ - createSecondaryStagingStoreCmd() - cachecmd.url = cache.url - cachecmd.provider = cache.provider - cachecmd.zoneid = zoneId - cachecmd.details = [] - - if cache.details: - for key, value in vars(cache.details).iteritems(): - cachecmd.details.append({ - 'key': key, - 'value': value - }) - self.apiClient.createSecondaryStagingStore(cachecmd) + ret = self.__apiClient.createSecondaryStagingStore(cachecmd) + if ret.id: + self.__tcRunLogger.debug( + "===Creating Secondary StagingStore Successful===") + self.__addToCleanUp("SecondaryStagingStore", ret.id) + except Exception as e: + print "Exception Occurred: %s" % GetDetailExceptionInfo(e) + self.__tcRunLogger.\ + exception("=== Creating " + "SecondaryStagingStorage Failed===") + self.__cleanAndExit() def createNetworks(self, networks, zoneId): - if networks is None: - return - for network in networks: - networkcmd = createNetwork.createNetworkCmd() - networkcmd.displaytext = network.displaytext - networkcmd.name = network.name - networkcmd.networkofferingid = network.networkofferingid - networkcmd.zoneid = zoneId - - ipranges = network.ipranges - if ipranges: - iprange = ipranges.pop() - networkcmd.startip = iprange.startip - networkcmd.endip = iprange.endip - networkcmd.gateway = iprange.gateway - networkcmd.netmask = iprange.netmask - - networkcmdresponse = self.apiClient.createNetwork(networkcmd) - networkId = networkcmdresponse.id - return networkId - - def createPhysicalNetwork(self, net, zoneid): - phynet = createPhysicalNetwork.createPhysicalNetworkCmd() - phynet.zoneid = zoneid - phynet.name = net.name - phynet.isolationmethods = net.isolationmethods - phynetwrk = self.apiClient.createPhysicalNetwork(phynet) - self.addTrafficTypes(phynetwrk.id, net.traffictypes) - return phynetwrk - - def updatePhysicalNetwork(self, networkid, state="Enabled", vlan=None): - upnet = updatePhysicalNetwork.updatePhysicalNetworkCmd() - upnet.id = networkid - upnet.state = state - if vlan: - upnet.vlan = vlan - return self.apiClient.updatePhysicalNetwork(upnet) - - def enableProvider(self, provider_id): - upnetprov =\ - updateNetworkServiceProvider.updateNetworkServiceProviderCmd() - upnetprov.id = provider_id - upnetprov.state = "Enabled" - self.apiClient.updateNetworkServiceProvider(upnetprov) - - def configureProviders(self, phynetwrk, providers): - """ - We will enable the virtualrouter elements for all zones. Other - providers like NetScalers, SRX, etc are explicitly added/configured - """ - - for provider in providers: - pnetprov = listNetworkServiceProviders.\ - listNetworkServiceProvidersCmd() - pnetprov.physicalnetworkid = phynetwrk.id - pnetprov.state = "Disabled" - pnetprov.name = provider.name - pnetprovres = self.apiClient.listNetworkServiceProviders(pnetprov) - - if pnetprovres and len(pnetprovres) > 0: - if provider.name == 'VirtualRouter'\ - or provider.name == 'VpcVirtualRouter': - vrprov = listVirtualRouterElements.\ - listVirtualRouterElementsCmd() - vrprov.nspid = pnetprovres[0].id - vrprovresponse = self.apiClient.\ - listVirtualRouterElements(vrprov) - vrprovid = vrprovresponse[0].id - - vrconfig = \ - configureVirtualRouterElement.\ - configureVirtualRouterElementCmd() - vrconfig.enabled = "true" - vrconfig.id = vrprovid - self.apiClient.configureVirtualRouterElement(vrconfig) - self.enableProvider(pnetprovres[0].id) - elif provider.name == 'InternalLbVm': - internallbprov = listInternalLoadBalancerElements.\ - listInternalLoadBalancerElementsCmd() - internallbprov.nspid = pnetprovres[0].id - internallbresponse = self.apiClient.\ - listInternalLoadBalancerElements(internallbprov) - internallbid = internallbresponse[0].id - - internallbconfig = \ - configureInternalLoadBalancerElement.\ - configureInternalLoadBalancerElementCmd() - internallbconfig.enabled = "true" - internallbconfig.id = internallbid - self.apiClient.\ - configureInternalLoadBalancerElement(internallbconfig) - self.enableProvider(pnetprovres[0].id) - elif provider.name == 'SecurityGroupProvider': - self.enableProvider(pnetprovres[0].id) - elif provider.name in ['JuniperContrailRouter', 'JuniperContrailVpcRouter']: - netprov = addNetworkServiceProvider.\ - addNetworkServiceProviderCmd() - netprov.name = provider.name - netprov.physicalnetworkid = phynetwrk.id - result = self.apiClient.addNetworkServiceProvider(netprov) - self.enableProvider(result.id) - elif provider.name in ['Netscaler', 'JuniperSRX', 'F5BigIp']: - netprov = addNetworkServiceProvider.\ - addNetworkServiceProviderCmd() - netprov.name = provider.name - netprov.physicalnetworkid = phynetwrk.id - result = self.apiClient.addNetworkServiceProvider(netprov) - for device in provider.devices: - if provider.name == 'Netscaler': - dev = addNetscalerLoadBalancer.\ - addNetscalerLoadBalancerCmd() - dev.username = device.username - dev.password = device.password - dev.networkdevicetype = device.networkdevicetype - dev.url = configGenerator.getDeviceUrl(device) - dev.physicalnetworkid = phynetwrk.id - self.apiClient.addNetscalerLoadBalancer(dev) - elif provider.name == 'JuniperSRX': - dev = addSrxFirewall.addSrxFirewallCmd() - dev.username = device.username - dev.password = device.password - dev.networkdevicetype = device.networkdevicetype - dev.url = configGenerator.getDeviceUrl(device) - dev.physicalnetworkid = phynetwrk.id - self.apiClient.addSrxFirewall(dev) - elif provider.name == 'F5BigIp': - dev = addF5LoadBalancer.addF5LoadBalancerCmd() - dev.username = device.username - dev.password = device.password - dev.networkdevicetype = device.networkdevicetype - dev.url = configGenerator.getDeviceUrl(device) - dev.physicalnetworkid = phynetwrk.id - self.apiClient.addF5LoadBalancer(dev) - else: - raise cloudstackException.\ - InvalidParameterException("Device %s doesn't match\ - any know provider type" % device) - self.enableProvider(result.id) - - def addTrafficTypes(self, physical_network_id, traffictypes): - [self.addTrafficType(physical_network_id, traffic_type) - for traffic_type in traffictypes] - - def addTrafficType(self, physical_network_id, traffictype): - traffic_type = addTrafficType.addTrafficTypeCmd() - traffic_type.physicalnetworkid = physical_network_id - traffic_type.traffictype = traffictype.typ - traffic_type.kvmnetworklabel = traffictype.kvm\ - if traffictype.kvm is not None else None - traffic_type.xennetworklabel = traffictype.xen\ - if traffictype.xen is not None else None - traffic_type.vmwarenetworklabel = traffictype.vmware\ - if traffictype.vmware is not None else None - traffic_type.simulatorlabel = traffictype.simulator\ - if traffictype.simulator is not None else None - return self.apiClient.addTrafficType(traffic_type) - - def enableZone(self, zoneid, allocation_state="Enabled"): - zoneCmd = updateZone.updateZoneCmd() - zoneCmd.id = zoneid - zoneCmd.allocationstate = allocation_state - return self.apiClient.updateZone(zoneCmd) - - def updateZoneDetails(self, zoneid, details): - zoneCmd = updateZone.updateZoneCmd() - zoneCmd.id = zoneid - zoneCmd.details = details - return self.apiClient.updateZone(zoneCmd) - - def createZones(self, zones): - for zone in zones: - createzone = createZone.createZoneCmd() - createzone.dns1 = zone.dns1 - createzone.dns2 = zone.dns2 - createzone.internaldns1 = zone.internaldns1 - createzone.internaldns2 = zone.internaldns2 - createzone.name = zone.name - createzone.securitygroupenabled = zone.securitygroupenabled - createzone.localstorageenabled = zone.localstorageenabled - createzone.networktype = zone.networktype - if zone.securitygroupenabled != "true": - createzone.guestcidraddress = zone.guestcidraddress - - zoneresponse = self.apiClient.createZone(createzone) - zoneId = zoneresponse.id - - for pnet in zone.physical_networks: - phynetwrk = self.createPhysicalNetwork(pnet, zoneId) - self.configureProviders(phynetwrk, pnet.providers) - self.updatePhysicalNetwork(phynetwrk.id, "Enabled", - vlan=pnet.vlan) - - if zone.networktype == "Basic": - listnetworkoffering =\ - listNetworkOfferings.listNetworkOfferingsCmd() - listnetworkoffering.name =\ - "DefaultSharedNetscalerEIPandELBNetworkOffering" \ - if len(filter(lambda x: - x.typ == 'Public', - zone.physical_networks[0]. - traffictypes)) > 0 \ - else "DefaultSharedNetworkOfferingWithSGService" - if zone.networkofferingname is not None: - listnetworkoffering.name = zone.networkofferingname - - listnetworkofferingresponse = \ - self.apiClient.listNetworkOfferings(listnetworkoffering) - - guestntwrk = configGenerator.network() - guestntwrk.displaytext = "guestNetworkForBasicZone" - guestntwrk.name = "guestNetworkForBasicZone" - guestntwrk.zoneid = zoneId - guestntwrk.networkofferingid = \ - listnetworkofferingresponse[0].id - - networkid = self.createNetworks([guestntwrk], zoneId) - self.createPods(zone.pods, zoneId, networkid) - if self.isEipElbZone(zone): - self.createVlanIpRanges(zone.networktype, zone.ipranges, - zoneId, forvirtualnetwork=True) - - isPureAdvancedZone = (zone.networktype == "Advanced" - and zone.securitygroupenabled != "true") - if isPureAdvancedZone: - self.createPods(zone.pods, zoneId) - self.createVlanIpRanges(zone.networktype, zone.ipranges, - zoneId) - elif (zone.networktype == "Advanced" - and zone.securitygroupenabled == "true"): - listnetworkoffering =\ - listNetworkOfferings.listNetworkOfferingsCmd() - listnetworkoffering.name =\ - "DefaultSharedNetworkOfferingWithSGService" - if zone.networkofferingname is not None: - listnetworkoffering.name = zone.networkofferingname - - listnetworkofferingresponse = \ - self.apiClient.listNetworkOfferings(listnetworkoffering) - + try: + if networks is None: + return + for network in networks: networkcmd = createNetwork.createNetworkCmd() - networkcmd.displaytext = "Shared SG enabled network" - networkcmd.name = "Shared SG enabled network" - networkcmd.networkofferingid =\ - listnetworkofferingresponse[0].id + networkcmd.displaytext = network.displaytext + networkcmd.name = network.name + networkcmd.networkofferingid = network.networkofferingid networkcmd.zoneid = zoneId - ipranges = zone.ipranges + ipranges = network.ipranges if ipranges: iprange = ipranges.pop() networkcmd.startip = iprange.startip networkcmd.endip = iprange.endip networkcmd.gateway = iprange.gateway networkcmd.netmask = iprange.netmask - networkcmd.vlan = iprange.vlan + networkcmdresponse = self.__apiClient.createNetwork(networkcmd) + if networkcmdresponse.id: + networkId = networkcmdresponse.id + self.__tcRunLogger.\ + debug("Creating Network Name : %s Id : %s Successful" + % (str(network.name), str(networkId))) + self.__addToCleanUp("Network", networkId) + return networkId + except Exception as e: + print "Exception Occurred %s" % GetDetailExceptionInfo(e) + self.__tcRunLogger.\ + exception("====Network : %s " + "Creation Failed=====" % str(network.name)) + self.__cleanAndExit() - networkcmdresponse = self.apiClient.createNetwork(networkcmd) - networkId = networkcmdresponse.id - self.createPods(zone.pods, zoneId, networkId) + def createPhysicalNetwork(self, net, zoneid): + try: + phynet = createPhysicalNetwork.createPhysicalNetworkCmd() + phynet.zoneid = zoneid + phynet.name = net.name + phynet.isolationmethods = net.isolationmethods + phynetwrk = self.__apiClient.createPhysicalNetwork(phynet) + if phynetwrk.id: + self.__tcRunLogger.\ + debug("Creating Physical Network Name : " + "%s Id : %s Successful" % (str(phynet.name), + str(phynetwrk.id))) + self.__addToCleanUp("PhysicalNetwork", phynetwrk.id) + self.addTrafficTypes(phynetwrk.id, net.traffictypes) + return phynetwrk + except Exception as e: + print "Exception Occurred: %s" % GetDetailExceptionInfo(e) + self.__tcRunLogger.exception("====Physical Network " + "Creation Failed=====") + self.__cleanAndExit() - '''Note: Swift needs cache storage first''' - self.createCacheStorages(zone.cacheStorages, zoneId) - self.createSecondaryStorages(zone.secondaryStorages, zoneId) + def updatePhysicalNetwork(self, networkid, state="Enabled", + vlan=None): + try: + upnet = updatePhysicalNetwork.updatePhysicalNetworkCmd() + upnet.id = networkid + upnet.state = state + if vlan: + upnet.vlan = vlan + ret = self.__apiClient.updatePhysicalNetwork(upnet) + return ret + except Exception as e: + print "Exception Occurred: %s" % GetDetailExceptionInfo(e) + self.__tcRunLogger.\ + exception("====Update Physical Network Failed=====") + self.__cleanAndExit() - enabled = getattr(zone, 'enabled', 'True') - if enabled == 'True' or enabled is None: - self.enableZone(zoneId, "Enabled") - details = getattr(zone, 'details') - if details is not None: - det = [d.__dict__ for d in details] - self.updateZoneDetails(zoneId, det) + def enableProvider(self, provider_id): + try: + upnetprov =\ + updateNetworkServiceProvider.updateNetworkServiceProviderCmd() + upnetprov.id = provider_id + upnetprov.state = "Enabled" + ret = self.__apiClient.updateNetworkServiceProvider(upnetprov) + if ret.id: + self.__tcRunLogger.debug( + "===Update Network Service Provider Successfull===") + except Exception as e: + print "Exception Occurred: %s" % GetDetailExceptionInfo(e) + self.__tcRunLogger.\ + exception( + "====Update Network Service Provider Failed=====") + self.__cleanAndExit() - return + def configureProviders(self, phynetwrk, providers): + """ + We will enable the virtualrouter elements for all zones. Other + providers like NetScalers, SRX, etc are explicitly added/configured + """ + try: + for provider in providers: + pnetprov = listNetworkServiceProviders.\ + listNetworkServiceProvidersCmd() + pnetprov.physicalnetworkid = phynetwrk.id + pnetprov.state = "Disabled" + pnetprov.name = provider.name + pnetprovres = self.__apiClient.listNetworkServiceProviders( + pnetprov) + if pnetprovres and len(pnetprovres) > 0: + if provider.name == 'VirtualRouter'\ + or provider.name == 'VpcVirtualRouter': + vrprov = listVirtualRouterElements.\ + listVirtualRouterElementsCmd() + vrprov.nspid = pnetprovres[0].id + vrprovresponse = self.__apiClient.\ + listVirtualRouterElements(vrprov) + vrprovid = vrprovresponse[0].id + vrconfig = \ + configureVirtualRouterElement.\ + configureVirtualRouterElementCmd() + vrconfig.enabled = "true" + vrconfig.id = vrprovid + self.__apiClient.\ + configureVirtualRouterElement(vrconfig) + self.enableProvider(pnetprovres[0].id) + elif provider.name == 'InternalLbVm': + internallbprov = listInternalLoadBalancerElements.\ + listInternalLoadBalancerElementsCmd() + internallbprov.nspid = pnetprovres[0].id + internallbresponse = self.__apiClient.\ + listInternalLoadBalancerElements(internallbprov) + internallbid = internallbresponse[0].id + internallbconfig = \ + configureInternalLoadBalancerElement.\ + configureInternalLoadBalancerElementCmd() + internallbconfig.enabled = "true" + internallbconfig.id = internallbid + self.__apiClient.\ + configureInternalLoadBalancerElement( + internallbconfig) + self.enableProvider(pnetprovres[0].id) + elif provider.name == 'SecurityGroupProvider': + self.enableProvider(pnetprovres[0].id) + elif provider.name in ['Netscaler', 'JuniperSRX', 'F5BigIp']: + netprov = addNetworkServiceProvider.\ + addNetworkServiceProviderCmd() + netprov.name = provider.name + netprov.physicalnetworkid = phynetwrk.id + result = self.__apiClient.addNetworkServiceProvider( + netprov) + if result.id: + self.__tcRunLogger.\ + debug("==== AddNetworkServiceProvider " + "Successful=====") + self.__addToCleanUp( + "NetworkServiceProvider", + result.id) + for device in provider.devices: + if provider.name == 'Netscaler': + dev = addNetscalerLoadBalancer.\ + addNetscalerLoadBalancerCmd() + dev.username = device.username + dev.password = device.password + dev.networkdevicetype = device.networkdevicetype + dev.url = configGenerator.getDeviceUrl(device) + dev.physicalnetworkid = phynetwrk.id + ret = self.__apiClient.addNetscalerLoadBalancer( + dev) + if ret.id: + self.__tcRunLogger.\ + debug("==== AddNetScalerLB " + "Successful=====") + self.__addToCleanUp( + "NetscalerLoadBalancer", + ret.id) + elif provider.name == 'JuniperSRX': + dev = addSrxFirewall.addSrxFirewallCmd() + dev.username = device.username + dev.password = device.password + dev.networkdevicetype = device.networkdevicetype + dev.url = configGenerator.getDeviceUrl(device) + dev.physicalnetworkid = phynetwrk.id + ret = self.__apiClient.addSrxFirewall(dev) + if ret.id: + self.__tcRunLogger.\ + debug("==== AddSrx " + "Successful=====") + self.__addToCleanUp("SrxFirewall", ret.id) + elif provider.name == 'F5BigIp': + dev = addF5LoadBalancer.addF5LoadBalancerCmd() + dev.username = device.username + dev.password = device.password + dev.networkdevicetype = device.networkdevicetype + dev.url = configGenerator.getDeviceUrl(device) + dev.physicalnetworkid = phynetwrk.id + ret = self.__apiClient.addF5LoadBalancer(dev) + if ret.id: + self.__tcRunLogger.\ + debug("==== AddF5 " + "Successful=====") + self.__addToCleanUp("F5LoadBalancer", ret.id) + else: + raise InvalidParameterException( + "Device %s doesn't match " + "any know provider " + "type" % device) + self.enableProvider(result.id) + except Exception as e: + print "Exception Occurred: %s" % GetDetailExceptionInfo(e) + self.__tcRunLogger.\ + exception("====List Network " + "Service Providers Failed=====") + self.__cleanAndExit() + + def addTrafficTypes(self, physical_network_id, traffictypes): + [self.addTrafficType(physical_network_id, traffic_type) + for traffic_type in traffictypes] + + def addTrafficType(self, physical_network_id, traffictype): + try: + traffic_type = addTrafficType.addTrafficTypeCmd() + traffic_type.physicalnetworkid = physical_network_id + traffic_type.traffictype = traffictype.typ + traffic_type.kvmnetworklabel = traffictype.kvm\ + if traffictype.kvm is not None else None + traffic_type.xennetworklabel = traffictype.xen\ + if traffictype.xen is not None else None + traffic_type.vmwarenetworklabel = traffictype.vmware\ + if traffictype.vmware is not None else None + traffic_type.simulatorlabel = traffictype.simulator\ + if traffictype.simulator is not None else None + ret = self.__apiClient.addTrafficType(traffic_type) + if ret.id: + self.__tcRunLogger.debug("===Add TrafficType Successful====") + self.__addToCleanUp("TrafficType", ret.id) + return ret + except Exception as e: + print "Exception Occurred: %s" % GetDetailExceptionInfo(e) + self.__tcRunLogger.\ + exception("==== Add TrafficType Failed=====") + self.__cleanAndExit() + + def enableZone(self, zoneid, allocation_state="Enabled"): + try: + zoneCmd = updateZone.updateZoneCmd() + zoneCmd.id = zoneid + zoneCmd.allocationstate = allocation_state + ret = self.__apiClient.updateZone(zoneCmd) + if ret.id: + self.__tcRunLogger.debug("==== Enable Zone SuccessFul=====") + return ret + except Exception as e: + print "Exception Occurred: %s" % GetDetailExceptionInfo(e) + self.__tcRunLogger.exception("==== Enable Zone Failed=====") + self.__cleanAndExit() + + def updateZoneDetails(self, zoneid, details): + try: + zoneCmd = updateZone.updateZoneCmd() + zoneCmd.id = zoneid + zoneCmd.details = details + ret = self.__apiClient.updateZone(zoneCmd) + if ret.id: + self.__tcRunLogger.debug("=== Update Zone SuccessFul===") + return ret + except Exception as e: + print "Exception Occurred: %s" % GetDetailExceptionInfo(e) + self.__tcRunLogger.exception("==== Update Zone Failed=====") + self.__cleanAndExit() + + def createZone(self, zone, rec=0): + try: + zoneresponse = self.__apiClient.createZone(zone) + if zoneresponse.id: + self.__addToCleanUp("Zone", zoneresponse.id) + self.__tcRunLogger.\ + debug("Zone Name : %s Id : %s Created Successfully" % + (str(zone.name), str(zoneresponse.id))) + return zoneresponse.id + else: + self.__tcRunLogger.\ + exception("====Zone : %s Creation Failed=====" % + str(zone.name)) + print "\n====Zone : %s Creation Failed=====" % str(zone.name) + if not rec: + zone.name = zone.name + "_" + random_gen() + self.__tcRunLogger.\ + debug("====Recreating Zone With New Name : " + "%s" % zone.name) + print "\n====Recreating Zone With New Name ====", \ + str(zone.name) + return self.createZone(zone, 1) + except Exception as e: + print "\nException Occurred under createZone : %s" % \ + GetDetailExceptionInfo(e) + self.__tcRunLogger.exception("====Create Zone Failed ===") + return FAILED + + def createZones(self, zones): + try: + for zone in zones: + zonecmd = createZone.createZoneCmd() + zonecmd.dns1 = zone.dns1 + zonecmd.dns2 = zone.dns2 + zonecmd.internaldns1 = zone.internaldns1 + zonecmd.internaldns2 = zone.internaldns2 + zonecmd.name = zone.name + zonecmd.securitygroupenabled = zone.securitygroupenabled + zonecmd.localstorageenabled = zone.localstorageenabled + zonecmd.networktype = zone.networktype + if zone.securitygroupenabled != "true": + zonecmd.guestcidraddress = zone.guestcidraddress + zoneId = self.createZone(zonecmd) + if zoneId == FAILED: + self.__tcRunLogger.\ + exception( + "====Zone: %s Creation Failed. So Exiting=====" % + str(zone.name)) + self.__cleanAndExit() + for pnet in zone.physical_networks: + phynetwrk = self.createPhysicalNetwork(pnet, zoneId) + self.configureProviders(phynetwrk, pnet.providers) + self.updatePhysicalNetwork(phynetwrk.id, "Enabled", + vlan=pnet.vlan) + if zone.networktype == "Basic": + listnetworkoffering =\ + listNetworkOfferings.listNetworkOfferingsCmd() + listnetworkoffering.name =\ + "DefaultSharedNetscalerEIPandELBNetworkOffering" \ + if len(filter(lambda x: + x.typ == 'Public', + zone.physical_networks[0]. + traffictypes)) > 0 \ + else "DefaultSharedNetworkOfferingWithSGService" + if zone.networkofferingname is not None: + listnetworkoffering.name = zone.networkofferingname + listnetworkofferingresponse = \ + self.__apiClient.listNetworkOfferings( + listnetworkoffering) + guestntwrk = configGenerator.network() + guestntwrk.displaytext = "guestNetworkForBasicZone" + guestntwrk.name = "guestNetworkForBasicZone" + guestntwrk.zoneid = zoneId + guestntwrk.networkofferingid = \ + listnetworkofferingresponse[0].id + networkid = self.createNetworks([guestntwrk], zoneId) + self.createPods(zone.pods, zoneId, networkid) + if self.isEipElbZone(zone): + self.createVlanIpRanges( + zone.networktype, zone.ipranges, + zoneId, forvirtualnetwork=True) + isPureAdvancedZone = (zone.networktype == "Advanced" + and zone.securitygroupenabled != "true") + if isPureAdvancedZone: + self.createPods(zone.pods, zoneId) + self.createVlanIpRanges(zone.networktype, zone.ipranges, + zoneId) + elif (zone.networktype == "Advanced" + and zone.securitygroupenabled == "true"): + listnetworkoffering =\ + listNetworkOfferings.listNetworkOfferingsCmd() + listnetworkoffering.name =\ + "DefaultSharedNetworkOfferingWithSGService" + if zone.networkofferingname is not None: + listnetworkoffering.name = zone.networkofferingname + listnetworkofferingresponse = \ + self.__apiClient.listNetworkOfferings( + listnetworkoffering) + networkcmd = createNetwork.createNetworkCmd() + networkcmd.displaytext = "Shared SG enabled network" + networkcmd.name = "Shared SG enabled network" + networkcmd.networkofferingid =\ + listnetworkofferingresponse[0].id + networkcmd.zoneid = zoneId + ipranges = zone.ipranges + if ipranges: + iprange = ipranges.pop() + networkcmd.startip = iprange.startip + networkcmd.endip = iprange.endip + networkcmd.gateway = iprange.gateway + networkcmd.netmask = iprange.netmask + networkcmd.vlan = iprange.vlan + networkcmdresponse = self.__apiClient.createNetwork( + networkcmd) + if networkcmdresponse.id: + self.__addToCleanUp("Network", networkcmdresponse.id) + self.__tcRunLogger.\ + debug("create Network Successful. NetworkId : %s " + % str(networkcmdresponse.id)) + self.createPods(zone.pods, zoneId, networkcmdresponse.id) + '''Note: Swift needs cache storage first''' + self.createCacheStorages(zone.cacheStorages, zoneId) + self.createSecondaryStorages(zone.secondaryStorages, zoneId) + enabled = getattr(zone, 'enabled', 'True') + if enabled == 'True' or enabled is None: + self.enableZone(zoneId, "Enabled") + details = getattr(zone, 'details') + if details is not None: + det = [d.__dict__ for d in details] + self.updateZoneDetails(zoneId, det) + return + except Exception as e: + print "\nException Occurred %s" % GetDetailExceptionInfo(e) + self.__tcRunLogger.exception("==== Create Zones Failed ===") def isEipElbZone(self, zone): if (zone.networktype == "Basic" @@ -486,64 +785,30 @@ class deployDataCenters(object): return True return False - def registerApiKey(self): - listuser = listUsers.listUsersCmd() - listuser.account = "admin" - listuserRes = self.testClient.getApiClient().listUsers(listuser) - userId = listuserRes[0].id - apiKey = listuserRes[0].apikey - securityKey = listuserRes[0].secretkey - if apiKey is None: - registerUser = registerUserKeys.registerUserKeysCmd() - registerUser.id = userId - registerUserRes = \ - self.testClient.getApiClient().registerUserKeys(registerUser) - - apiKey = registerUserRes.apikey - securityKey = registerUserRes.secretkey - - self.config.mgtSvr[0].port = 8080 - self.config.mgtSvr[0].apiKey = apiKey - self.config.mgtSvr[0].securityKey = securityKey - return apiKey, securityKey - - def loadCfg(self): - ''' Retrieving Management Server Connection Details ''' - mgtDetails = self.config.mgtSvr[0] - ''' Retrieving Database Connection Details''' - dbSvrDetails = self.config.dbSvr - - self.testClient = \ - cloudstackTestClient.\ - cloudstackTestClient(mgtDetails, - dbSvrDetails, - logger=self.tcRunLogger) - - if mgtDetails.apiKey is None: - mgtDetails.apiKey, mgtDetails.securityKey = self.registerApiKey() - mgtDetails.port = 8080 - self.testClient = \ - cloudstackTestClient.cloudstackTestClient( - mgtDetails, - dbSvrDetails, - logger=self.tcRunLogger) - - self.apiClient = self.testClient.getApiClient() - """set hypervisor""" - if mgtDetails.hypervisor: - self.apiClient.hypervisor = mgtDetails.hypervisor - else: - self.apiClient.hypervisor = "XenServer" # Defaults to Xenserver + def setClient(self): + ''' + @Name : setClient + @Desc : Sets the API Client retrieved from test client + ''' + self.__apiClient = self.__testClient.getApiClient() def updateConfiguration(self, globalCfg): - if globalCfg is None: - return None - - for config in globalCfg: - updateCfg = updateConfiguration.updateConfigurationCmd() - updateCfg.name = config.name - updateCfg.value = config.value - self.apiClient.updateConfiguration(updateCfg) + try: + if globalCfg is None or self.__apiClient is None: + return None + for config in globalCfg: + updateCfg = updateConfiguration.updateConfigurationCmd() + updateCfg.name = config.name + updateCfg.value = config.value + ret = self.__apiClient.updateConfiguration(updateCfg) + if ret.id: + self.__tcRunLogger.debug( + "==UpdateConfiguration Successfull===") + except Exception as e: + print "Exception Occurred %s" % GetDetailExceptionInfo(e) + self.__tcRunLogger.\ + exception("===UpdateConfiguration Failed===") + self.__cleanAndExit() def copyAttributesToCommand(self, source, command): map(lambda attr: setattr(command, attr, getattr(source, attr, None)), @@ -551,42 +816,307 @@ class deployDataCenters(object): ["required", "isAsync"], dir(command))) def configureS3(self, s3): - if s3 is None: - return - command = addS3.addS3Cmd() - self.copyAttributesToCommand(s3, command) - self.apiClient.addS3(command) + try: + if s3 is None: + return + command = addS3.addS3Cmd() + self.copyAttributesToCommand(s3, command) + ret = self.__apiClient.addS3(command) + if ret.id: + self.__tcRunLogger.debug("===AddS3 Successfull===") + self.__addToCleanUp("s3", ret.id) + except Exception as e: + self.__tcRunLogger.exception("====AddS3 Failed===") + self.__cleanAndExit() def deploy(self): - self.loadCfg() - self.updateConfiguration(self.config.globalConfig) - self.createZones(self.config.zones) - self.configureS3(self.config.s3) + try: + print "\n==== Deploy DC Started ====" + self.__tcRunLogger.debug("\n==== Deploy DC Started ====") + ''' + Step1 : Set the Client + ''' + self.setClient() + ''' + Step2: Update the Configuration + ''' + self.updateConfiguration(self.__config.globalConfig) + ''' + Step3 :Deploy the Zone + ''' + self.createZones(self.__config.zones) + self.configureS3(self.__config.s3) + ''' + Persist the Configuration to an external file post DC creation + ''' + self.__persistDcConfig() + print "\n====Deploy DC Successful=====" + self.__tcRunLogger.debug("\n====Deploy DC Successful====") + return SUCCESS + except Exception as e: + print "\nException Occurred Under deploy :%s" % \ + GetDetailExceptionInfo(e) + self.__tcRunLogger.debug("\n====Deploy DC Failed====") + print "\n====Deploy DC Failed====" + self.__cleanAndExit() + return FAILED + + +class DeleteDataCenters: + + ''' + @Desc : Deletes the Data Center using the settings provided. + tc_client :Client for deleting the DC. + dc_cfg_file : obj file exported by DeployDataCenter + when successfully created DC. + This file is serialized one containing + entries with successful DC. + dc_cfg: If dc_cfg_file, is not available, we can use + the dictionary of elements to delete. + tc_run_logger: Logger to dump log messages. + ''' + + def __init__(self, + tc_client, + dc_cfg_file=None, + dc_cfg=None, + tc_run_logger=None + ): + self.__dcCfgFile = dc_cfg_file + self.__dcCfg = dc_cfg + self.__tcRunLogger = tc_run_logger + self.__apiClient = None + self.__testClient = tc_client + + def __deleteCmds(self, cmd_name, cmd_obj): + ''' + @Name : __deleteCmds + @Desc : Deletes the entities provided by cmd + ''' + if cmd_name.lower() == "deletehostcmd": + cmd_obj.forcedestroylocalstorage = "true" + cmd_obj.force = "true" + ''' + Step1 : Prepare Host For Maintenance + ''' + host_maint_cmd = prepareHostForMaintenance.\ + prepareHostForMaintenanceCmd() + host_maint_cmd.id = cmd_obj.id + host_maint_resp = self.__apiClient.prepareHostForMaintenance( + host_maint_cmd) + if host_maint_resp: + ''' + Step2 : List Hosts for Resource State + ''' + list_host_cmd = listHosts.listHostsCmd() + list_host_cmd.id = cmd_obj.id + retries = 3 + for i in xrange(retries): + list_host_resp = self.__apiClient.\ + listHosts(list_host_cmd) + if (list_host_resp) and\ + (list_host_resp[0].resourcestate == 'Maintenance'): + break + sleep(30) + if cmd_name.lower() == "deletestoragepoolcmd": + cmd_obj.forced = "true" + store_maint_cmd = enableStorageMaintenance.\ + enableStorageMaintenanceCmd() + store_maint_cmd.id = cmd_obj.id + store_maint_resp = self.__apiClient.\ + enableStorageMaintenance(store_maint_cmd) + if store_maint_resp: + list_store_cmd = listStoragePools.listStoragePoolsCmd() + list_store_cmd.id = cmd_obj.id + retries = 3 + for i in xrange(retries): + store_maint_resp = self.__apiClient.\ + listStoragePools(list_store_cmd) + if (store_maint_resp) and \ + (store_maint_resp[0].state == 'Maintenance'): + break + sleep(30) + return cmd_obj + + def __setClient(self): + ''' + @Name : setClient + @Desc : Sets the API Client retrieved from test client + ''' + self.__apiClient = self.__testClient.getApiClient() + + def __cleanEntries(self): + ''' + @Name : __cleanAndEntries + @Description: Cleans up the created DC in order of creation + ''' + try: + ret = FAILED + if "order" in self.__dcCfg.keys() and len(self.__dcCfg["order"]): + self.__dcCfg["order"].reverse() + print "\n====Clean Up Entries===", self.__dcCfg + for type in self.__dcCfg["order"]: + self.__tcRunLogger.debug( + "====CleanUp Started For Type: %s====" % + type) + if type: + temp_ids = self.__dcCfg[type] + ids = [items for items in temp_ids if items] + for id in ids: + del_mod = "delete" + type + del_cmd = getattr( + globals()[del_mod], + del_mod + "Cmd") + del_cmd_obj = del_cmd() + del_cmd_resp = getattr( + globals()[del_mod], + del_mod + "Response") + del_cmd_obj.id = id + del_cmd_obj = self.__deleteCmds( + del_mod + + "Cmd", + del_cmd_obj) + del_func = getattr(self.__apiClient, del_mod) + del_cmd_resp = del_func(del_cmd_obj) + if del_cmd_resp: + self.__tcRunLogger.debug( + "====%s CleanUp Failed. ID: %s ===" % + (type, id)) + else: + self.__tcRunLogger.debug( + "====%s CleanUp Successful. ID : %s===" % + (type, id)) + ret = SUCCESS + except Exception as e: + print "\n==== Exception Under __cleanEntries: %s ==== % " \ + % GetDetailExceptionInfo(e) + self.__tcRunLogger.exception( + "\n==== Exception Under __cleanEntries: %s ==== % " % + GetDetailExceptionInfo(e)) + finally: + return ret + + def removeDataCenter(self): + ''' + @Name : removeDataCenter + @Desc : Removes the Data Center provided by Configuration + If Input dc file configuration is None, uses the cfg provided + else uses the dc file to get the configuration + ''' + try: + self.__setClient() + self.__tcRunLogger.debug("====DeployDC: CleanUp Started====") + print "\n====DeployDC: CleanUp Started====" + ret = FAILED + if self.__dcCfgFile: + file_to_read = open(self.__dcCfgFile, 'r') + if file_to_read: + self.__dcCfg = pickle.load(file_to_read) + if self.__dcCfg: + ret = self.__cleanEntries() + except Exception as e: + print "\n==== Exception Under removeDataCenter: %s ====" % \ + GetDetailExceptionInfo(e) + self.__tcRunLogger.exception( + "===DeployDC CleanUp FAILED: %s ====" % + GetDetailExceptionInfo(e)) + finally: + return ret + if __name__ == "__main__": + ''' + @Desc : This module facilitates the following: + 1. Deploying DataCenter by using the input provided + configuration. + EX: python deployDataCenter.py -i + 2. Removes a created DataCenter by providing + the input configuration file and data center settings file + EX: python deployDataCenter.py -i + -r + ''' parser = OptionParser() parser.add_option("-i", "--input", action="store", - default="./datacenterCfg", dest="input", help="the path \ - where the json config file generated, by default is \ - ./datacenterCfg") + default=None, dest="input", + help="the path \ + where the json config file generated") + parser.add_option("-r", "--remove", action="store", + default=None, dest="remove", + help="path to file\ + where the created dc entries are kept") (options, args) = parser.parse_args() + + ''' + Verify the input validity + ''' + if options.input is None and options.remove is None: + print "\n==== For DeployDataCenter: Please Specify a " \ + "Valid Input Configuration File====" + print "\n==== For DeleteDataCenters: Please Specify a " \ + "Valid Input Configuration File and DC Settings====" + exit(1) + + ''' + Imports the Modules Required + ''' from marvin.marvinLog import MarvinLog - cfg = configGenerator.getSetupConfig(options.input) + from marvin.cloudstackTestClient import CSTestClient + + ''' + Step1: Create the Logger + ''' log_obj = MarvinLog("CSLog") - tcRunLogger = log_obj.setLogHandler("/tmp/debug.log") - deploy = deployDataCenters(cfg, tcRunLogger) - deploy.deploy() + cfg = configGenerator.getSetupConfig(options.input) + log = cfg.logger - """ - create = createStoragePool.createStoragePoolCmd() - create.clusterid = 1 - create.podid = 2 - create.name = "fdffdf" - create.url = "nfs://jfkdjf/fdkjfkd" - create.zoneid = 2 + ret = log_obj.createLogs("DeployDataCenter", + log) + if ret != FAILED: + log_folder_path = log_obj.getLogFolderPath() + tc_run_logger = log_obj.getLogger() + else: + print "\n===Log Creation Failed. Please Check===" + exit(1) - deploy = deployDataCenters("./datacenterCfg") - deploy.loadCfg() - deploy.apiClient.createStoragePool(create) - """ + ''' + Step2 : Create Test Client + ''' + obj_tc_client = CSTestClient(cfg.mgtSvr[0], cfg.dbSvr, + logger=tc_run_logger) + if obj_tc_client and obj_tc_client.createTestClient() == FAILED: + print "\n=== TestClient Creation Failed===" + exit(1) + + ''' + Step3: Verify and continue whether to deploy a DC or remove a DC + ''' + + if (options.input) and (os.path.isfile(options.input)) and \ + (options.remove is None): + ''' + @Desc : Deploys a Data Center with provided Config + ''' + deploy = DeployDataCenters(obj_tc_client, + cfg, + tc_run_logger, + log_folder_path=log_folder_path) + deploy.deploy() + exit(1) + + if options.remove and os.path.isfile(options.remove) and options.input: + ''' + @Desc : Removes a Data Center with provided Config + ''' + remove_dc_obj = DeleteDataCenters(obj_tc_client, + dc_cfg_file=options.remove, + tc_run_logger=tc_run_logger + ) + if remove_dc_obj: + if remove_dc_obj.removeDataCenter() == FAILED: + print "\n===Removing DataCenter Failed===" + tc_run_logger.debug("\n===Removing DataCenter Failed===") + else: + print "\n===Removing DataCenter Successful===" + tc_run_logger.debug("\n===Removing DataCenter Successful===") + exit(1) diff --git a/tools/marvin/marvin/jsonHelper.py b/tools/marvin/marvin/jsonHelper.py index ae40b8dabf0..3f48a00ba68 100644 --- a/tools/marvin/marvin/jsonHelper.py +++ b/tools/marvin/marvin/jsonHelper.py @@ -18,11 +18,13 @@ import cloudstackException import json import inspect -from cloudstackAPI import * +from marvin.cloudstackAPI import * class jsonLoader(object): + '''The recursive class for building and representing objects with.''' + def __init__(self, obj): for k in obj: v = obj[k] @@ -52,6 +54,7 @@ class jsonLoader(object): class jsonDump(object): + @staticmethod def __serialize(obj): """Recursively walk object's hierarchy.""" @@ -145,7 +148,7 @@ def getResultObj(returnObj, responsecls=None): errMsg = "errorCode: %s, errorText:%s" % (result.errorcode, result.errortext) respname = responseName.replace("response", "") - raise cloudstackException.cloudstackAPIException(respname, errMsg) + raise cloudstackException.CloudstackAPIException(respname, errMsg) if result.count is not None: for key in result.__dict__.iterkeys(): @@ -247,7 +250,7 @@ due to missing parameter jobid" }''' try: asynJob = getResultObj(result) - except cloudstackException.cloudstackAPIException, e: + except cloudstackException.CloudstackAPIException as e: print e result = '{ "queryasyncjobresultresponse" : {} }' diff --git a/tools/marvin/marvin/integration/lib/__init__.py b/tools/marvin/marvin/lib/__init__.py similarity index 100% rename from tools/marvin/marvin/integration/lib/__init__.py rename to tools/marvin/marvin/lib/__init__.py diff --git a/tools/marvin/marvin/integration/lib/base.py b/tools/marvin/marvin/lib/base.py old mode 100755 new mode 100644 similarity index 94% rename from tools/marvin/marvin/integration/lib/base.py rename to tools/marvin/marvin/lib/base.py index c23ea8a98a8..ca7fdc6f124 --- a/tools/marvin/marvin/integration/lib/base.py +++ b/tools/marvin/marvin/lib/base.py @@ -22,6 +22,9 @@ import marvin from utils import is_server_ssh_ready, random_gen from marvin.cloudstackAPI import * +from marvin.codes import FAILED, PASS +from marvin.cloudstackException import GetDetailExceptionInfo +from marvin.lib.utils import validateList # Import System modules import time import hashlib @@ -325,7 +328,7 @@ class VirtualMachine: domainid=None, zoneid=None, networkids=None, serviceofferingid=None, securitygroupids=None, projectid=None, startvm=None, diskofferingid=None, affinitygroupnames=None, affinitygroupids=None, group=None, - hostid=None, keypair=None, ipaddress=None, mode='default', method='GET', + hostid=None, keypair=None, ipaddress=None, mode='default', method='GET',hypervisor=None, customcpunumber=None, customcpuspeed=None, custommemory=None, rootdisksize=None): """Create the instance""" @@ -340,7 +343,7 @@ class VirtualMachine: cmd.zoneid = zoneid elif "zoneid" in services: cmd.zoneid = services["zoneid"] - cmd.hypervisor = apiclient.hypervisor + cmd.hypervisor = hypervisor if "displayname" in services: cmd.displayname = services["displayname"] @@ -461,10 +464,12 @@ class VirtualMachine: cmd.id = self.id apiclient.startVirtualMachine(cmd) - def stop(self, apiclient): + def stop(self, apiclient, forced=None): """Stop the instance""" cmd = stopVirtualMachine.stopVirtualMachineCmd() cmd.id = self.id + if forced: + cmd.forced = forced apiclient.stopVirtualMachine(cmd) def reboot(self, apiclient): @@ -595,8 +600,15 @@ class VirtualMachine: def detach_iso(self, apiclient): """Detach ISO to instance""" cmd = detachIso.detachIsoCmd() - cmd.id = self.id + cmd.virtualmachineid = self.id return apiclient.detachIso(cmd) + + def scale_virtualmachine(self, apiclient, serviceOfferingId): + """ Scale up of service offering for the Instance""" + cmd = scaleVirtualMachine.scaleVirtualMachineCmd() + cmd.id = self.id + cmd.serviceofferingid = serviceOfferingId + return apiclient.scaleVirtualMachine(cmd) def change_service_offering(self, apiclient, serviceOfferingId): """Change service offering of the instance""" @@ -825,6 +837,16 @@ class Volume: timeout = timeout - 1 return + @classmethod + def extract(cls, apiclient, volume_id, zoneid, mode): + """Extracts the volume""" + + cmd = extractVolume.extractVolumeCmd() + cmd.id = volume_id + cmd.zoneid = zoneid + cmd.mode = mode + return Volume(apiclient.extractVolume(cmd).__dict__) + @classmethod def migrate(cls, apiclient, **kwargs): """Migrate a volume""" @@ -918,7 +940,7 @@ class Template: @classmethod def register(cls, apiclient, services, zoneid=None, - account=None, domainid=None): + account=None, domainid=None, hypervisor=None): """Create template from URL""" # Create template from Virtual machine and Volume ID @@ -926,7 +948,7 @@ class Template: cmd.displaytext = services["displaytext"] cmd.name = "-".join([services["name"], random_gen()]) cmd.format = services["format"] - cmd.hypervisor = apiclient.hypervisor + cmd.hypervisor = hypervisor if "ostypeid" in services: cmd.ostypeid = services["ostypeid"] @@ -1065,6 +1087,25 @@ class Template: [setattr(cmd, k, v) for k, v in kwargs.items()] return(apiclient.updateTemplatePermissions(cmd)) + def update(self, apiclient, **kwargs): + """Updates the template details""" + + cmd = updateTemplate.updateTemplateCmd() + cmd.id = self.id + [setattr(cmd, k, v) for k, v in kwargs.items()] + return(apiclient.updateTemplate(cmd)) + + @classmethod + def copy(cls, apiclient, id, sourcezoneid, destzoneid): + "Copy Template from source Zone to Destination Zone" + + cmd = copyTemplate.copyTemplateCmd() + cmd.id = id + cmd.sourcezoneid = sourcezoneid + cmd.destzoneid = destzoneid + + return apiclient.copyTemplate(cmd) + @classmethod def list(cls, apiclient, **kwargs): """List all templates matching criteria""" @@ -1164,6 +1205,36 @@ class Iso: timeout = timeout - 1 return + @classmethod + def extract(cls, apiclient, id, mode, zoneid=None): + "Extract ISO " + + cmd = extractIso.extractIsoCmd() + cmd.id = id + cmd.mode = mode + cmd.zoneid = zoneid + + return apiclient.extractIso(cmd) + + def update(self, apiclient, **kwargs): + """Updates the ISO details""" + + cmd = updateIso.updateIsoCmd() + cmd.id = self.id + [setattr(cmd, k, v) for k, v in kwargs.items()] + return(apiclient.updateIso(cmd)) + + @classmethod + def copy(cls, apiclient, id, sourcezoneid, destzoneid): + "Copy ISO from source Zone to Destination Zone" + + cmd = copyIso.copyIsoCmd() + cmd.id = id + cmd.sourcezoneid = sourcezoneid + cmd.destzoneid = destzoneid + + return apiclient.copyIso(cmd) + @classmethod def list(cls, apiclient, **kwargs): """Lists all available ISO files.""" @@ -1237,7 +1308,8 @@ class NATRule: @classmethod def create(cls, apiclient, virtual_machine, services, ipaddressid=None, - projectid=None, openfirewall=False, networkid=None, vpcid=None): + projectid=None, openfirewall=False, networkid=None, vpcid=None, + vmguestip=None): """Create Port forwarding rule""" cmd = createPortForwardingRule.createPortForwardingRuleCmd() @@ -1266,6 +1338,10 @@ class NATRule: if vpcid: cmd.vpcid = vpcid + + if vmguestip: + cmd.vmguestip = vmguestip + return NATRule(apiclient.createPortForwardingRule(cmd).__dict__) def delete(self, apiclient): @@ -1332,7 +1408,8 @@ class StaticNATRule: return(apiclient.listIpForwardingRules(cmd)) @classmethod - def enable(cls, apiclient, ipaddressid, virtualmachineid, networkid=None): + def enable(cls, apiclient, ipaddressid, virtualmachineid, networkid=None, + vmguestip=None): """Enables Static NAT rule""" cmd = enableStaticNat.enableStaticNatCmd() @@ -1340,6 +1417,9 @@ class StaticNATRule: cmd.virtualmachineid = virtualmachineid if networkid: cmd.networkid = networkid + + if vmguestip: + cmd.vmguestip = vmguestip apiclient.enableStaticNat(cmd) return @@ -1650,6 +1730,20 @@ class SnapshotPolicy: [setattr(cmd, k, v) for k, v in kwargs.items()] return(apiclient.listSnapshotPolicies(cmd)) +class Hypervisor: + """Manage Hypervisor""" + + def __init__(self, items): + self.__dict__.update(items) + + @classmethod + def list(cls, apiclient, **kwargs): + """Lists hypervisors""" + + cmd = listHypervisors.listHypervisorsCmd() + [setattr(cmd, k, v) for k, v in kwargs.items()] + return(apiclient.listHypervisors(cmd)) + class LoadBalancerRule: """Manage Load Balancer rule""" @@ -1778,11 +1872,11 @@ class Cluster: self.__dict__.update(items) @classmethod - def create(cls, apiclient, services, zoneid=None, podid=None): + def create(cls, apiclient, services, zoneid=None, podid=None, hypervisor=None): """Create Cluster""" cmd = addCluster.addClusterCmd() cmd.clustertype = services["clustertype"] - cmd.hypervisor = apiclient.hypervisor + cmd.hypervisor = hypervisor if zoneid: cmd.zoneid = zoneid @@ -1828,36 +1922,59 @@ class Host: self.__dict__.update(items) @classmethod - def create(cls, apiclient, cluster, services, zoneid=None, podid=None): - """Create Host in cluster""" + def create(cls, apiclient, cluster, services, zoneid=None, podid=None, hypervisor=None): + """ + 1. Creates the host based upon the information provided. + 2. Verifies the output of the adding host and its state post addition + Returns FAILED in case of an issue, else an instance of Host + """ + try: + cmd = addHost.addHostCmd() + cmd.hypervisor = hypervisor + cmd.url = services["url"] + cmd.clusterid = cluster.id - cmd = addHost.addHostCmd() - cmd.hypervisor = apiclient.hypervisor - cmd.url = services["url"] - cmd.clusterid = cluster.id + if zoneid: + cmd.zoneid = zoneid + else: + cmd.zoneid = services["zoneid"] - if zoneid: - cmd.zoneid = zoneid - else: - cmd.zoneid = services["zoneid"] + if podid: + cmd.podid = podid + else: + cmd.podid = services["podid"] - if podid: - cmd.podid = podid - else: - cmd.podid = services["podid"] + if "clustertype" in services: + cmd.clustertype = services["clustertype"] + if "username" in services: + cmd.username = services["username"] + if "password" in services: + cmd.password = services["password"] - if "clustertype" in services: - cmd.clustertype = services["clustertype"] - if "username" in services: - cmd.username = services["username"] - if "password" in services: - cmd.password = services["password"] - - # Add host - host = apiclient.addHost(cmd) - - if isinstance(host, list): - return Host(host[0].__dict__) + ''' + Adds a Host, + If response is valid and host is up return + an instance of Host. + If response is invalid, returns FAILED. + If host state is not up, verify through listHosts call + till host status is up and return accordingly. Max 3 retries + ''' + host = apiclient.addHost(cmd) + ret = validateList(host) + if ret[0] == PASS: + if str(host[0].state).lower() == 'up': + return Host(host[0].__dict__) + retries = 3 + while retries: + lh_resp = apiclient.listHosts(host[0].id) + ret = validateList(lh_resp) + if (ret[0] == PASS) and (str(ret[1].state).lower() == 'up'): + return Host(host[0].__dict__) + retries += -1 + return FAILED + except Exception, e: + print "Exception Occurred Under Host.create : %s" % GetDetailExceptionInfo(e) + return FAILED def delete(self, apiclient): """Delete Host""" @@ -2390,7 +2507,8 @@ class PublicIpRange: cmd.startip = services["startip"] cmd.endip = services["endip"] cmd.zoneid = services["zoneid"] - cmd.podid = services["podid"] + if "podid" in services: + cmd.podid = services["podid"] cmd.vlan = services["vlan"] return PublicIpRange(apiclient.createVlanIpRange(cmd).__dict__) @@ -2624,7 +2742,7 @@ class SecurityGroup: """Create security group""" cmd = createSecurityGroup.createSecurityGroupCmd() - cmd.name = services["name"] + cmd.name = "-".join([services["name"], random_gen()]) if account: cmd.account = account if domainid: @@ -2726,6 +2844,76 @@ class SecurityGroup: return(apiclient.listSecurityGroups(cmd)) +class VpnCustomerGateway: + """Manage VPN Customer Gateway""" + + def __init__(self, items): + self.__dict__.update(items) + + @classmethod + def create(cls, apiclient, services, name, gateway, cidrlist, + account=None, domainid=None): + """Create VPN Customer Gateway""" + cmd = createVpnCustomerGateway.createVpnCustomerGatewayCmd() + cmd.name = name + cmd.gateway = gateway + cmd.cidrlist = cidrlist + if "ipsecpsk" in services: + cmd.ipsecpsk = services["ipsecpsk"] + if "ikepolicy" in services: + cmd.ikepolicy = services["ikepolicy"] + if "ikelifetime" in services: + cmd.ikelifetime = services["ikelifetime"] + if "esppolicy" in services: + cmd.esppolicy = services["esppolicy"] + if "esplifetime" in services: + cmd.esplifetime = services["esplifetime"] + if "dpd" in services: + cmd.dpd = services["dpd"] + if account: + cmd.account = account + if domainid: + cmd.domainid = domainid + return VpnCustomerGateway(apiclient.createVpnCustomerGateway(cmd).__dict__) + + def update(self, apiclient, services, name, gateway, cidrlist): + """Updates VPN Customer Gateway""" + + cmd = updateVpnCustomerGateway.updateVpnCustomerGatewayCmd() + cmd.id = self.id + cmd.name = name + cmd.gateway = gateway + cmd.cidrlist = cidrlist + if "ipsecpsk" in services: + cmd.ipsecpsk = services["ipsecpsk"] + if "ikepolicy" in services: + cmd.ikepolicy = services["ikepolicy"] + if "ikelifetime" in services: + cmd.ikelifetime = services["ikelifetime"] + if "esppolicy" in services: + cmd.esppolicy = services["esppolicy"] + if "esplifetime" in services: + cmd.esplifetime = services["esplifetime"] + if "dpd" in services: + cmd.dpd = services["dpd"] + return(apiclient.updateVpnCustomerGateway(cmd)) + + def delete(self, apiclient): + """Delete VPN Customer Gateway""" + + cmd = deleteVpnCustomerGateway.deleteVpnCustomerGatewayCmd() + cmd.id = self.id + apiclient.deleteVpnCustomerGateway(cmd) + + @classmethod + def list(cls, apiclient, **kwargs): + """List all VPN customer Gateway""" + + cmd = listVpnCustomerGateways.listVpnCustomerGatewaysCmd() + [setattr(cmd, k, v) for k, v in kwargs.items()] + return(apiclient.listVpnCustomerGateways(cmd)) + + class Project: """Manage Project life cycle""" @@ -3347,6 +3535,14 @@ class SSHKeyPair: cmd.projectid = projectid return (apiclient.createSSHKeyPair(cmd)) + @classmethod + def register(cls, apiclient, name, publickey): + """Registers SSH keypair""" + cmd = registerSSHKeyPair.registerSSHKeyPairCmd() + cmd.name = name + cmd.publickey = publickey + return (apiclient.registerSSHKeyPair(cmd)) + def delete(self, apiclient): """Delete SSH key pair""" cmd = deleteSSHKeyPair.deleteSSHKeyPairCmd() @@ -3742,8 +3938,8 @@ class IAMGroup: def list(cls, apiclient, **kwargs): cmd = listIAMGroups.listIAMGroupsCmd() [setattr(cmd, k, v) for k, v in kwargs.items()] - return apiclient.listIAMGroups(cmd) - + return apiclient.listIAMGroupsCmd(cmd) + def addAccount(self, apiclient, accts): """Add accounts to iam group""" cmd = addAccountToIAMGroup.addAccountToIAMGroupCmd() @@ -3803,7 +3999,7 @@ class IAMPolicy: def list(cls, apiclient, **kwargs): cmd = listIAMPolicies.listIAMPoliciesCmd() [setattr(cmd, k, v) for k, v in kwargs.items()] - return apiclient.listIAMPolicies(cmd) + return apiclient.listIAMPoliciesCmd(cmd) def addPermission(self, apiclient, permission): """Add permission to iam policy""" diff --git a/tools/marvin/marvin/integration/lib/common.py b/tools/marvin/marvin/lib/common.py similarity index 68% rename from tools/marvin/marvin/integration/lib/common.py rename to tools/marvin/marvin/lib/common.py index 02fa5f1f1c9..8868d2d51ea 100644 --- a/tools/marvin/marvin/integration/lib/common.py +++ b/tools/marvin/marvin/lib/common.py @@ -5,9 +5,9 @@ # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -17,7 +17,7 @@ """Common functions """ -#Import Local Modules +# Import Local Modules from marvin.cloudstackAPI import (listConfigurations, listPhysicalNetworks, listRegions, @@ -57,28 +57,20 @@ from marvin.cloudstackAPI import (listConfigurations, listNetworkOfferings, listResourceLimits, listVPCOfferings) -from marvin.integration.lib.base import (Configurations, - NetScaler, - Template, - Resources, - PhysicalNetwork, - Host, - PublicIPAddress, - NetworkOffering, - Network, - FireWallRule, - NATRule, - StaticNATRule) -from marvin.integration.lib.utils import (get_process_status, - xsplit, - validateList) + + + from marvin.sshClient import SshClient from marvin.codes import (PASS, ISOLATED_NETWORK, VPC_NETWORK, BASIC_ZONE, FAIL, NAT_RULE, STATIC_NAT_RULE) import random +from marvin.lib.utils import * +from marvin.lib.base import * +from marvin.codes import PASS -#Import System modules + +# Import System modules import time @@ -88,9 +80,14 @@ def is_config_suitable(apiclient, name, value): @return: true if value is set, else false """ configs = Configurations.list(apiclient, name=name) - assert(configs is not None and isinstance(configs, list) and len(configs) > 0) + assert( + configs is not None and isinstance( + configs, + list) and len( + configs) > 0) return configs[0].value == value + def wait_for_cleanup(apiclient, configs=None): """Sleeps till the cleanup configs passed""" @@ -114,6 +111,7 @@ def wait_for_cleanup(apiclient, configs=None): time.sleep(int(config_desc.value)) return + def add_netscaler(apiclient, zoneid, NSservice): """ Adds Netscaler device and enables NS provider""" @@ -121,11 +119,11 @@ def add_netscaler(apiclient, zoneid, NSservice): cmd.zoneid = zoneid physical_networks = apiclient.listPhysicalNetworks(cmd) if isinstance(physical_networks, list): - physical_network = physical_networks[0] + physical_network = physical_networks[0] cmd = listNetworkServiceProviders.listNetworkServiceProvidersCmd() cmd.name = 'Netscaler' - cmd.physicalnetworkid=physical_network.id + cmd.physicalnetworkid = physical_network.id nw_service_providers = apiclient.listNetworkServiceProviders(cmd) if isinstance(nw_service_providers, list): @@ -137,111 +135,152 @@ def add_netscaler(apiclient, zoneid, NSservice): netscaler_provider = apiclient.addNetworkServiceProvider(cmd1) netscaler = NetScaler.add( - apiclient, - NSservice, - physicalnetworkid=physical_network.id - ) + apiclient, + NSservice, + physicalnetworkid=physical_network.id + ) if netscaler_provider.state != 'Enabled': - cmd = updateNetworkServiceProvider.updateNetworkServiceProviderCmd() - cmd.id = netscaler_provider.id - cmd.state = 'Enabled' - apiclient.updateNetworkServiceProvider(cmd) + cmd = updateNetworkServiceProvider.updateNetworkServiceProviderCmd() + cmd.id = netscaler_provider.id + cmd.state = 'Enabled' + apiclient.updateNetworkServiceProvider(cmd) return netscaler -def get_region(apiclient, services=None): - "Returns a default region" +def get_region(apiclient, region_id=None, region_name=None): + ''' + @name : get_region + @Desc : Returns the Region Information for a given region id or region name + @Input : region_name: Name of the Region + region_id : Id of the region + @Output : 1. Region Information for the passed inputs else first Region + 2. FAILED In case the cmd failed + ''' cmd = listRegions.listRegionsCmd() - if services: - if "regionid" in services: - cmd.id = services["regionid"] + if region_name is not None: + cmd.name = region_name + if region_id is not None: + cmd.id = region_id + cmd_out = apiclient.listRegions(cmd) + return FAILED if validateList(cmd_out)[0] != PASS else cmd_out[0] - regions = apiclient.listRegions(cmd) - - if isinstance(regions, list): - assert len(regions) > 0 - return regions[0] - else: - raise Exception("Failed to find specified region.") - -def get_domain(apiclient, services=None): - "Returns a default domain" +def get_domain(apiclient, domain_id=None, domain_name=None): + ''' + @name : get_domain + @Desc : Returns the Domain Information for a given domain id or domain name + @Input : domain id : Id of the Domain + domain_name : Name of the Domain + @Output : 1. Domain Information for the passed inputs else first Domain + 2. FAILED In case the cmd failed + ''' cmd = listDomains.listDomainsCmd() - if services: - if "domainid" in services: - cmd.id = services["domainid"] - domains = apiclient.listDomains(cmd) - - if isinstance(domains, list): - assert len(domains) > 0 - return domains[0] - else: - raise Exception("Failed to find specified domain.") + if domain_name is not None: + cmd.name = domain_name + if domain_id is not None: + cmd.id = domain_id + cmd_out = apiclient.listDomains(cmd) + if validateList(cmd_out)[0] != PASS: + return FAILED + return cmd_out[0] -def get_zone(apiclient, services=None): - "Returns a default zone" - +def get_zone(apiclient, zone_name=None, zone_id=None): + ''' + @name : get_zone + @Desc :Returns the Zone Information for a given zone id or Zone Name + @Input : zone_name: Name of the Zone + zone_id : Id of the zone + @Output : 1. Zone Information for the passed inputs else first zone + 2. FAILED In case the cmd failed + ''' cmd = listZones.listZonesCmd() - if services: - if "zoneid" in services: - cmd.id = services["zoneid"] + if zone_name is not None: + cmd.name = zone_name + if zone_id is not None: + cmd.id = zone_id - zones = apiclient.listZones(cmd) + cmd_out = apiclient.listZones(cmd) - if isinstance(zones, list): - assert len(zones) > 0, "There are no available zones in the deployment" - return zones[0] - else: - raise Exception("Failed to find specified zone.") + if validateList(cmd_out)[0] != PASS: + return FAILED + ''' + Check if input zone name and zone id is None, + then return first element of List Zones command + ''' + return cmd_out[0] -def get_pod(apiclient, zoneid, services=None): - "Returns a default pod for specified zone" - +def get_pod(apiclient, zone_id=None, pod_id=None, pod_name=None): + ''' + @name : get_pod + @Desc : Returns the Pod Information for a given zone id or Zone Name + @Input : zone_id: Id of the Zone + pod_name : Name of the Pod + pod_id : Id of the Pod + @Output : 1. Pod Information for the pod + 2. FAILED In case the cmd failed + ''' cmd = listPods.listPodsCmd() - cmd.zoneid = zoneid - if services: - if "podid" in services: - cmd.id = services["podid"] + if pod_name is not None: + cmd.name = pod_name + if pod_id is not None: + cmd.id = pod_id + if zone_id is not None: + cmd.zoneid = zone_id - pods = apiclient.listPods(cmd) - - if isinstance(pods, list): - assert len(pods) > 0, "No pods found for zone %s"%zoneid - return pods[0] - else: - raise Exception("Exception: Failed to find specified pod.") - - -def get_template(apiclient, zoneid, ostype, services=None, - templatefilter='featured', - templatetype='BUILTIN'): - "Returns a featured built in template in given zone" + cmd_out = apiclient.listPods(cmd) + if validateList(cmd_out)[0] != PASS: + return FAILED + return cmd_out[0] +def get_template( + apiclient, zone_id=None, ostype_desc=None, template_filter="featured", template_type='BUILTIN', + template_id=None, template_name=None, account=None, domain_id=None, project_id=None, + hypervisor=None): + ''' + @Name : get_template + @Desc : Retrieves the template Information based upon inputs provided + Template is retrieved based upon either of the inputs matched + condition + @Input : returns a template" + @Output : FAILED in case of any failure + template Information matching the inputs + ''' cmd = listTemplates.listTemplatesCmd() - cmd.templatefilter = templatefilter - cmd.zoneid = zoneid + cmd.templatefilter = template_filter + if domain_id is not None: + cmd.domainid = domain_id + if zone_id is not None: + cmd.zoneid = zone_id + if template_id is not None: + cmd.id = template_id + if template_name is not None: + cmd.name = template_name + if hypervisor is not None: + cmd.hypervisor = hypervisor + if project_id is not None: + cmd.projectid = project_id + if account is not None: + cmd.account = account - if services: - if "template" in services: - cmd.id = services["template"] + ''' + Get the Templates pertaining to the inputs provided + ''' + list_templatesout = apiclient.listTemplates(cmd) + if validateList(list_templatesout)[0] != PASS: + return FAILED - list_templates = apiclient.listTemplates(cmd) - - if isinstance(list_templates, list): - assert len(list_templates) > 0, "received empty response on featured templates" - for template in list_templates: - if template.isready and template.templatetype == templatetype: - return template - - raise Exception("Exception: Failed to find built in template which is in " - "ready state: %s" % templatetype) - return + for template in list_templatesout: + if template.isready and template.templatetype == template_type: + return template + ''' + Return default first template, if no template matched + ''' + return list_templatesout[0] def download_systemplates_sec_storage(server, services): @@ -250,29 +289,29 @@ def download_systemplates_sec_storage(server, services): try: # Login to management server ssh = SshClient( - server["ipaddress"], - server["port"], - server["username"], - server["password"] - ) + server["ipaddress"], + server["port"], + server["username"], + server["password"] + ) except Exception: - raise Exception("SSH access failted for server with IP address: %s" % - server["ipaddess"]) + raise Exception("SSH access failed for server with IP address: %s" % + server["ipaddess"]) # Mount Secondary Storage on Management Server cmds = [ - "mkdir -p %s" % services["mnt_dir"], - "mount -t nfs %s:/%s %s" % ( - services["sec_storage"], - services["path"], - services["mnt_dir"] - ), - "%s -m %s -u %s -h %s -F" % ( - services["command"], - services["mnt_dir"], - services["download_url"], - services["hypervisor"] - ) - ] + "mkdir -p %s" % services["mnt_dir"], + "mount -t nfs %s:/%s %s" % ( + services["sec_storage"], + services["path"], + services["mnt_dir"] + ), + "%s -m %s -u %s -h %s -F" % ( + services["command"], + services["mnt_dir"], + services["download_url"], + services["hypervisor"] + ) + ] for c in cmds: result = ssh.execute(c) @@ -294,84 +333,86 @@ def wait_for_ssvms(apiclient, zoneid, podid, interval=60): time.sleep(interval) timeout = 40 while True: - list_ssvm_response = list_ssvms( - apiclient, - systemvmtype='secondarystoragevm', - zoneid=zoneid, - podid=podid - ) - ssvm = list_ssvm_response[0] - if ssvm.state != 'Running': - # Sleep to ensure SSVMs are Up and Running - time.sleep(interval) - timeout = timeout - 1 - elif ssvm.state == 'Running': - break - elif timeout == 0: - raise Exception("SSVM failed to come up") - break + list_ssvm_response = list_ssvms( + apiclient, + systemvmtype='secondarystoragevm', + zoneid=zoneid, + podid=podid + ) + ssvm = list_ssvm_response[0] + if ssvm.state != 'Running': + # Sleep to ensure SSVMs are Up and Running + time.sleep(interval) + timeout = timeout - 1 + elif ssvm.state == 'Running': + break + elif timeout == 0: + raise Exception("SSVM failed to come up") + break timeout = 40 while True: - list_ssvm_response = list_ssvms( - apiclient, - systemvmtype='consoleproxy', - zoneid=zoneid, - podid=podid - ) - cpvm = list_ssvm_response[0] - if cpvm.state != 'Running': - # Sleep to ensure SSVMs are Up and Running - time.sleep(interval) - timeout = timeout - 1 - elif cpvm.state == 'Running': - break - elif timeout == 0: - raise Exception("CPVM failed to come up") - break + list_ssvm_response = list_ssvms( + apiclient, + systemvmtype='consoleproxy', + zoneid=zoneid, + podid=podid + ) + cpvm = list_ssvm_response[0] + if cpvm.state != 'Running': + # Sleep to ensure SSVMs are Up and Running + time.sleep(interval) + timeout = timeout - 1 + elif cpvm.state == 'Running': + break + elif timeout == 0: + raise Exception("CPVM failed to come up") + break return + def get_builtin_template_info(apiclient, zoneid): """Returns hypervisor specific infor for templates""" list_template_response = Template.list( - apiclient, - templatefilter='featured', - zoneid=zoneid, - ) + apiclient, + templatefilter='featured', + zoneid=zoneid, + ) for b_template in list_template_response: - if b_template.templatetype == 'BUILTIN': - break + if b_template.templatetype == 'BUILTIN': + break extract_response = Template.extract(apiclient, - b_template.id, - 'HTTP_DOWNLOAD', - zoneid) + b_template.id, + 'HTTP_DOWNLOAD', + zoneid) return extract_response.url, b_template.hypervisor, b_template.format + def download_builtin_templates(apiclient, zoneid, hypervisor, host, - linklocalip, interval=60): + linklocalip, interval=60): """After setup wait till builtin templates are downloaded""" # Change IPTABLES Rules get_process_status( - host["ipaddress"], - host["port"], - host["username"], - host["password"], - linklocalip, - "iptables -P INPUT ACCEPT" - ) + host["ipaddress"], + host["port"], + host["username"], + host["password"], + linklocalip, + "iptables -P INPUT ACCEPT" + ) time.sleep(interval) # Find the BUILTIN Templates for given Zone, Hypervisor list_template_response = list_templates( - apiclient, - hypervisor=hypervisor, - zoneid=zoneid, - templatefilter='self' - ) + apiclient, + hypervisor=hypervisor, + zoneid=zoneid, + templatefilter='self' + ) if not isinstance(list_template_response, list): raise Exception("Failed to download BUILTIN templates") @@ -380,18 +421,18 @@ def download_builtin_templates(apiclient, zoneid, hypervisor, host, templateid = None for template in list_template_response: if template.templatetype == "BUILTIN": - templateid = template.id + templateid = template.id # Sleep to ensure that template is in downloading state after adding # Sec storage time.sleep(interval) while True: template_response = list_templates( - apiclient, - id=templateid, - zoneid=zoneid, - templatefilter='self' - ) + apiclient, + id=templateid, + zoneid=zoneid, + templatefilter='self' + ) template = template_response[0] # If template is ready, # template.status = Download Complete @@ -410,7 +451,7 @@ def download_builtin_templates(apiclient, zoneid, hypervisor, host, def update_resource_limit(apiclient, resourcetype, account=None, - domainid=None, max=None, projectid=None): + domainid=None, max=None, projectid=None): """Updates the resource limit to 'max' for given account""" cmd = updateResourceLimit.updateResourceLimitCmd() @@ -684,6 +725,7 @@ def list_resource_limits(apiclient, **kwargs): [setattr(cmd, k, v) for k, v in kwargs.items()] return(apiclient.listResourceLimits(cmd)) + def list_vpc_offerings(apiclient, **kwargs): """ Lists VPC offerings """ @@ -691,30 +733,31 @@ def list_vpc_offerings(apiclient, **kwargs): [setattr(cmd, k, v) for k, v in kwargs.items()] return(apiclient.listVPCOfferings(cmd)) + def update_resource_count(apiclient, domainid, accountid=None, projectid=None, rtype=None): - """updates the resource count - 0 - VM - 1 - Public IP - 2 - Volume - 3 - Snapshot - 4 - Template - 5 - Projects - 6 - Network - 7 - VPC - 8 - CPUs - 9 - RAM - 10 - Primary (shared) storage (Volumes) - 11 - Secondary storage (Snapshots, Templates & ISOs) - """ + """updates the resource count + 0 - VM + 1 - Public IP + 2 - Volume + 3 - Snapshot + 4 - Template + 5 - Projects + 6 - Network + 7 - VPC + 8 - CPUs + 9 - RAM + 10 - Primary (shared) storage (Volumes) + 11 - Secondary storage (Snapshots, Templates & ISOs) + """ - Resources.updateCount(apiclient, - domainid=domainid, - account=accountid if accountid else None, - projectid=projectid if projectid else None, - resourcetype=rtype if rtype else None - ) - return + Resources.updateCount(apiclient, + domainid=domainid, + account=accountid if accountid else None, + projectid=projectid if projectid else None, + resourcetype=rtype if rtype else None + ) + return def findSuitableHostForMigration(apiclient, vmid): """Returns a suitable host for VM migration""" @@ -734,59 +777,27 @@ def findSuitableHostForMigration(apiclient, vmid): return suitableHost + def get_resource_type(resource_id): - """Returns resource type""" + """Returns resource type""" - lookup = { 0: "VM", - 1: "Public IP", - 2: "Volume", - 3: "Snapshot", - 4: "Template", - 5: "Projects", - 6: "Network", - 7: "VPC", - 8: "CPUs", - 9: "RAM", - 10: "Primary (shared) storage (Volumes)", - 11: "Secondary storage (Snapshots, Templates & ISOs)" - } + lookup = {0: "VM", + 1: "Public IP", + 2: "Volume", + 3: "Snapshot", + 4: "Template", + 5: "Projects", + 6: "Network", + 7: "VPC", + 8: "CPUs", + 9: "RAM", + 10: "Primary (shared) storage (Volumes)", + 11: "Secondary storage (Snapshots, Templates & ISOs)" + } - return lookup[resource_id] + return lookup[resource_id] -def get_portable_ip_range_services(config): - """ Reads config values related to portable ip and fills up - services accordingly""" - services = {} - attributeError = False - - if config.portableIpRange.startip: - services["startip"] = config.portableIpRange.startip - else: - attributeError = True - - if config.portableIpRange.endip: - services["endip"] = config.portableIpRange.endip - else: - attributeError = True - - if config.portableIpRange.netmask: - services["netmask"] = config.portableIpRange.netmask - else: - attributeError = True - - if config.portableIpRange.gateway: - services["gateway"] = config.portableIpRange.gateway - else: - attributeError = True - - if config.portableIpRange.vlan: - services["vlan"] = config.portableIpRange.vlan - - if attributeError: - services = None - - return services def get_free_vlan(apiclient, zoneid): """ @@ -797,23 +808,25 @@ def get_free_vlan(apiclient, zoneid): @return: physical_network, shared_vlan_tag """ list_physical_networks_response = PhysicalNetwork.list( - apiclient, - zoneid=zoneid - ) + apiclient, + zoneid=zoneid + ) assert isinstance(list_physical_networks_response, list) - assert len(list_physical_networks_response) > 0, "No physical networks found in zone %s" % zoneid + assert len( + list_physical_networks_response) > 0, "No physical networks found in zone %s" % zoneid physical_network = list_physical_networks_response[0] - networks = list_networks(apiclient, zoneid= zoneid, type='Shared') + networks = list_networks(apiclient, zoneid=zoneid, type='Shared') usedVlanIds = [] if isinstance(networks, list) and len(networks) > 0: - usedVlanIds = [int(nw.vlan) for nw in networks if nw.vlan!="untagged"] + usedVlanIds = [int(nw.vlan) + for nw in networks if nw.vlan != "untagged"] if hasattr(physical_network, "vlan") is False: while True: - shared_ntwk_vlan = random.randrange(1,4095) + shared_ntwk_vlan = random.randrange(1, 4095) if shared_ntwk_vlan in usedVlanIds: continue else: @@ -822,9 +835,11 @@ def get_free_vlan(apiclient, zoneid): vlans = xsplit(physical_network.vlan, ['-', ',']) assert len(vlans) > 0 - assert int(vlans[0]) < int(vlans[-1]), "VLAN range %s was improperly split" % physical_network.vlan + assert int(vlans[0]) < int( + vlans[-1]), "VLAN range %s was improperly split" % physical_network.vlan - retriesCount = 20 #Assuming random function will give different integer each time + # Assuming random function will give different integer each time + retriesCount = 20 shared_ntwk_vlan = None @@ -846,6 +861,7 @@ def get_free_vlan(apiclient, zoneid): return physical_network, shared_ntwk_vlan + def setNonContiguousVlanIds(apiclient, zoneid): """ Form the non contiguous ranges based on currently assigned range in physical network @@ -858,14 +874,16 @@ def setNonContiguousVlanIds(apiclient, zoneid): zoneid=zoneid ) assert isinstance(list_physical_networks_response, list) - assert len(list_physical_networks_response) > 0, "No physical networks found in zone %s" % zoneid + assert len( + list_physical_networks_response) > 0, "No physical networks found in zone %s" % zoneid for physical_network in list_physical_networks_response: vlans = xsplit(physical_network.vlan, ['-', ',']) assert len(vlans) > 0 - assert int(vlans[0]) < int(vlans[-1]), "VLAN range %s was improperly split" % physical_network.vlan + assert int(vlans[0]) < int( + vlans[-1]), "VLAN range %s was improperly split" % physical_network.vlan # Keep some gap between existing vlan and the new vlans which we are going to add # So that they are non contiguous @@ -874,30 +892,38 @@ def setNonContiguousVlanIds(apiclient, zoneid): non_contig_start_vlan_id = int(vlans[0]) - 6 # Form ranges which are consecutive to existing ranges but not immediately contiguous - # There should be gap in between existing range and new non contiguous ranage + # There should be gap in between existing range and new non contiguous + # ranage # If you can't add range after existing range, because it's crossing 4095, then # select VLAN ids before the existing range such that they are greater than 0, and # then add this non contiguoud range - vlan = { "partial_range": ["",""], "full_range": ""} + vlan = {"partial_range": ["", ""], "full_range": ""} if non_contig_end_vlan_id < 4095: - vlan["partial_range"][0] = str(non_contig_end_vlan_id - 4) + '-' + str(non_contig_end_vlan_id - 3) - vlan["partial_range"][1] = str(non_contig_end_vlan_id - 1) + '-' + str(non_contig_end_vlan_id) - vlan["full_range"] = str(non_contig_end_vlan_id - 4) + '-' + str(non_contig_end_vlan_id) + vlan["partial_range"][0] = str( + non_contig_end_vlan_id - 4) + '-' + str(non_contig_end_vlan_id - 3) + vlan["partial_range"][1] = str( + non_contig_end_vlan_id - 1) + '-' + str(non_contig_end_vlan_id) + vlan["full_range"] = str( + non_contig_end_vlan_id - 4) + '-' + str(non_contig_end_vlan_id) NonContigVlanIdsAcquired = True elif non_contig_start_vlan_id > 0: - vlan["partial_range"][0] = str(non_contig_start_vlan_id) + '-' + str(non_contig_start_vlan_id + 1) - vlan["partial_range"][1] = str(non_contig_start_vlan_id + 3) + '-' + str(non_contig_start_vlan_id + 4) - vlan["full_range"] = str(non_contig_start_vlan_id) + '-' + str(non_contig_start_vlan_id + 4) + vlan["partial_range"][0] = str( + non_contig_start_vlan_id) + '-' + str(non_contig_start_vlan_id + 1) + vlan["partial_range"][1] = str( + non_contig_start_vlan_id + 3) + '-' + str(non_contig_start_vlan_id + 4) + vlan["full_range"] = str( + non_contig_start_vlan_id) + '-' + str(non_contig_start_vlan_id + 4) NonContigVlanIdsAcquired = True else: NonContigVlanIdsAcquired = False # If failed to get relevant vlan ids, continue to next physical network - # else break from loop as we have hot the non contiguous vlan ids for the test purpose + # else break from loop as we have hot the non contiguous vlan ids for + # the test purpose if not NonContigVlanIdsAcquired: continue diff --git a/tools/marvin/marvin/integration/lib/utils.py b/tools/marvin/marvin/lib/utils.py similarity index 89% rename from tools/marvin/marvin/integration/lib/utils.py rename to tools/marvin/marvin/lib/utils.py index 7e11d521be3..cb5dcfbd810 100644 --- a/tools/marvin/marvin/integration/lib/utils.py +++ b/tools/marvin/marvin/lib/utils.py @@ -29,12 +29,17 @@ import socket import urlparse import datetime from marvin.cloudstackAPI import cloudstackAPIClient, listHosts, listRouters +from platform import system +from marvin.cloudstackException import GetDetailExceptionInfo from marvin.sshClient import SshClient -from marvin.codes import (FAIL, +from marvin.codes import ( + SUCCESS, + FAIL, PASS, MATCH_NOT_FOUND, INVALID_INPUT, - EMPTY_LIST) + EMPTY_LIST, + FAILED) def restart_mgmt_server(server): """Restarts the management server""" @@ -267,7 +272,8 @@ def is_snapshot_on_nfs(apiclient, dbconn, config, zoneid, snapshotid): # snapshot extension to be appended to the snapshot path obtained from db snapshot_extensions = {"vmware": ".ovf", "kvm": "", - "xenserver": ".vhd"} + "xenserver": ".vhd", + "simulator":""} qresultset = dbconn.execute( "select id from snapshots where uuid = '%s';" \ @@ -429,6 +435,44 @@ def verifyElementInList(inp, toverify, responsevar=None, pos=0): else: return [FAIL, MATCH_NOT_FOUND] +def checkVolumeSize(ssh_handle=None, + volume_name="/dev/sda", + cmd_inp="/sbin/fdisk -l | grep Disk", + size_to_verify=0): + ''' + @Name : getDiskUsage + @Desc : provides facility to verify the volume size against the size to verify + @Input: 1. ssh_handle : machine against which to execute the disk size cmd + 2. volume_name : The name of the volume against which to verify the size + 3. cmd_inp : Input command used to veify the size + 4. size_to_verify: size against which to compare. + @Output: Returns FAILED in case of an issue, else SUCCESS + ''' + try: + if ssh_handle is None or cmd_inp is None or volume_name is None: + return INVALID_INPUT + + cmd = cmd_inp + ''' + Retrieve the cmd output + ''' + if system().lower() != "windows": + fdisk_output = ssh_handle.runCommand(cmd_inp) + if fdisk_output["status"] != SUCCESS: + return FAILED + temp_out = fdisk_output["stdout"] + for line in temp_out.split("\n"): + if volume_name in line: + parts = line.split() + if str(parts[-2]) == str(size_to_verify): + return [SUCCESS,str(parts[-2])] + return [FAILED,"Volume Not Found"] + except Exception, e: + print "\n Exception Occurred under getDiskUsage: " \ + "%s" %GetDetailExceptionInfo(e) + return [FAILED,GetDetailExceptionInfo(e)] + + def verifyRouterState(apiclient, routerid, allowedstates): """List the router and verify that its state is in allowed states @output: List, containing [Result, Reason] @@ -451,3 +495,4 @@ def verifyRouterState(apiclient, routerid, allowedstates): return [FAIL, "Redundant state of the router should be in %s but is %s" % (allowedstates, routers[0].redundantstate)] return [PASS, None] + \ No newline at end of file diff --git a/tools/marvin/marvin/marvinInit.py b/tools/marvin/marvin/marvinInit.py index f722058a9fe..c35fec6adc1 100644 --- a/tools/marvin/marvin/marvinInit.py +++ b/tools/marvin/marvin/marvinInit.py @@ -15,56 +15,67 @@ # specific language governing permissions and limitations # under the License. ''' -@Desc: Initializes the marvin and does required prerequisites +Initializes the marvin and does required prerequisites for starting it. -1. Parses the configuration file passed to marvin and creates a - parsed config + 1. Parses the configuration file passed to marvin and creates a + parsed config. 2. Initializes the logging required for marvin.All logs are now made available under a single timestamped folder. - 3. Deploys the Data Center based upon input + 3. Deploys the Data Center based upon input. ''' - -from marvin import configGenerator -from marvin import cloudstackException +from marvin.configGenerator import getSetupConfig from marvin.marvinLog import MarvinLog -from marvin.deployDataCenter import deployDataCenters +from marvin.deployDataCenter import DeployDataCenters +from marvin.cloudstackTestClient import CSTestClient +from marvin.cloudstackException import GetDetailExceptionInfo from marvin.codes import( - YES, - NO, + XEN_SERVER, SUCCESS, FAILED - ) -import sys -import time +) import os -import logging -import string -import random class MarvinInit: - def __init__(self, config_file, load_flag, log_folder_path=None): + + def __init__(self, config_file, + deploy_dc_flag=None, + test_mod_name="deploydc", + zone=None, + hypervisor_type=None, + user_logfolder_path=None): self.__configFile = config_file - self.__loadFlag = load_flag - self.__parsedConfig = None - self.__logFolderPath = log_folder_path + self.__deployFlag = deploy_dc_flag + self.__logFolderPath = None self.__tcRunLogger = None + self.__testModName = test_mod_name self.__testClient = None - self.__tcRunDebugFile = None + self.__tcResultFile = None + self.__testDataFilePath = None + self.__zoneForTests = zone + self.__parsedConfig = None + self.__hypervisorType = hypervisor_type + self.__userLogFolderPath = user_logfolder_path def __parseConfig(self): ''' + @Name: __parseConfig @Desc : Parses the configuration file passed and assigns the parsed configuration + @Output : SUCCESS or FAILED ''' try: - self.__parsedConfig = configGenerator.\ - getSetupConfig(self.__configFile) + if not os.path.isfile(self.__configFile): + print "\n=== Marvin Parse Config Init Failed ===" + return FAILED + self.__parsedConfig = getSetupConfig(self.__configFile) + print "\n=== Marvin Parse Config Successful ===" return SUCCESS - except Exception, e: - print "\n Exception Occurred Under __parseConfig : %s" % str(e) - return None + except Exception as e: + print "\nException Occurred Under __parseConfig : " \ + "%s" % GetDetailExceptionInfo(e) + return FAILED def getParsedConfig(self): return self.__parsedConfig @@ -78,33 +89,67 @@ class MarvinInit: def getLogger(self): return self.__tcRunLogger - def getDebugFile(self): - return self.__tcRunDebugFile + def getResultFile(self): + ''' + @Name : getDebugFile + @Desc : Creates the result file at a given path. + @Output : Returns the Result file to be used for writing + test outputs + ''' + if self.__logFolderPath is not None: + self.__tcResultFile = open(self.__logFolderPath + + "/results.txt", "w") + return self.__tcResultFile + + def __setHypervisorAndZoneInfo(self): + ''' + @Name : __setHypervisorAndZoneInfo + @Desc: Set the HyperVisor and Zone details; + default to XenServer + ''' + try: + if not self.__hypervisorType: + self.__hypervisorType = XEN_SERVER + if not self.__zoneForTests: + if self.__parsedConfig: + for zone in self.__parsedConfig.zones: + self.__zoneForTests = zone.name + break + return SUCCESS + except Exception as e: + print "\n Exception Occurred Under init " \ + "%s" % GetDetailExceptionInfo(e) + return FAILED def init(self): ''' + @Name : init @Desc :Initializes the marvin by 1. Parsing the configuration and creating a parsed config structure 2. Creates a timestamped log folder and provides all logs to be dumped there 3. Creates the DataCenter based upon configuration provided + @Output : SUCCESS or FAILED ''' try: - if ((self.__parseConfig() is not None) and - (self.__initLogging() is not None) and - (self.__deployDC() is not None)): + if ((self.__parseConfig() != FAILED) and + (self.__setHypervisorAndZoneInfo())and + (self.__setTestDataPath() != FAILED) and + (self.__initLogging() != FAILED) and + (self.__createTestClient() != FAILED) and + (self.__deployDC() != FAILED)): return SUCCESS - else: - return FAILED - except Exception, e: - print "\n Exception Occurred Under init %s" % str(e) + return FAILED + except Exception as e: + print "\n Exception Occurred Under init " \ + "%s" % GetDetailExceptionInfo(e) return FAILED def __initLogging(self): - try: - ''' - @Desc : 1. Initializes the logging for marvin and so provides + ''' + @Name : __initLogging + @Desc : 1. Initializes the logging for marvin and so provides various log features for automation run. 2. Initializes all logs to be available under given Folder Path,where all test run logs @@ -112,58 +157,87 @@ class MarvinInit: 3. All logging like exception log,results, run info etc for a given test run are available under a given timestamped folder - ''' - temp_path = "".join(str(time.time()).split(".")) - if self.__logFolderPath is None: - log_config = self.__parsedConfig.logger - if log_config is not None: - if log_config.LogFolderPath is not None: - self.logFolderPath = log_config.LogFolderPath + '/' \ - + temp_path - else: - self.logFolderPath = temp_path - else: - self.logFolderPath = temp_path - else: - self.logFolderPath = self.__logFolderPath + '/' + temp_path - if os.path.exists(self.logFolderPath): - self.logFolderPath += ''.join(random.choice( - string.ascii_uppercase + - string.digits for x in range(3))) - os.makedirs(self.logFolderPath) - ''' - Log File Paths - ''' - tc_failed_exceptionlog = self.logFolderPath + "/failed_" \ - "plus_" \ - "exceptions.txt" - tc_run_log = self.logFolderPath + "/runinfo.txt" - self.__tcRunDebugFile = open(self.logFolderPath + - "/results.txt", "w") - + @Output : SUCCESS or FAILED + ''' + try: log_obj = MarvinLog("CSLog") - self.__tcRunLogger = log_obj.setLogHandler(tc_run_log) - log_obj.setLogHandler(tc_failed_exceptionlog, - log_level=logging.FATAL) + if log_obj: + ret = log_obj.\ + createLogs(self.__testModName, + self.__parsedConfig.logger, + self.__userLogFolderPath) + if ret != FAILED: + self.__logFolderPath = log_obj.getLogFolderPath() + self.__tcRunLogger = log_obj.getLogger() + print "\n=== Marvin Init Logging Successful===" + return SUCCESS + return FAILED + except Exception as e: + print "\n Exception Occurred Under __initLogging " \ + ":%s" % GetDetailExceptionInfo(e) + return FAILED + + def __createTestClient(self): + ''' + @Name : __createTestClient + @Desc : Creates the TestClient during init + based upon the parameters provided + @Output: Returns SUCCESS or FAILED + ''' + try: + mgt_details = self.__parsedConfig.mgtSvr[0] + dbsvr_details = self.__parsedConfig.dbSvr + self.__testClient = CSTestClient(mgt_details, dbsvr_details, + logger=self.__tcRunLogger, + test_data_filepath= + self.__testDataFilePath, + zone=self.__zoneForTests, + hypervisor_type= + self.__hypervisorType) + if self.__testClient: + return self.__testClient.createTestClient() + return FAILED + except Exception as e: + print "\n Exception Occurred Under __createTestClient : %s" % \ + GetDetailExceptionInfo(e) + return FAILED + + def __setTestDataPath(self): + ''' + @Name : __setTestDataPath + @Desc : Sets the TestData Path for tests to run + @Output:Returns SUCCESS or FAILED + ''' + try: + if ((self.__parsedConfig.TestData is not None) and + (self.__parsedConfig.TestData.Path is not None)): + self.__testDataFilePath = self.__parsedConfig.TestData.Path + print "\n=== Marvin Setting TestData Successful===" return SUCCESS - except Exception, e: - print "\n Exception Occurred Under __initLogging :%s" % str(e) - return None + except Exception as e: + print "\nException Occurred Under __setTestDataPath : %s" % \ + GetDetailExceptionInfo(e) + return FAILED def __deployDC(self): + ''' + @Name : __deployDC + @Desc : Deploy the DataCenter and returns accordingly. + @Output: SUCCESS or FAILED + ''' try: - ''' - Deploy the DataCenter and retrieves test client. - ''' - deploy_obj = deployDataCenters(self.__parsedConfig, - self.__tcRunLogger) - if self.__loadFlag: - deploy_obj.loadCfg() - else: - deploy_obj.deploy() - - self.__testClient = deploy_obj.testClient - return SUCCESS - except Exception, e: - print "\n Exception Occurred Under __deployDC : %s" % str(e) - return None + ret = SUCCESS + if self.__deployFlag: + deploy_obj = DeployDataCenters(self.__testClient, + self.__parsedConfig, + self.__tcRunLogger) + ret = deploy_obj.deploy() + if ret == SUCCESS: + print "Deploy DC Successful" + else: + print "Deploy DC Failed" + return ret + except Exception as e: + print "\n Exception Occurred Under __deployDC : %s" % \ + GetDetailExceptionInfo(e) + return FAILED diff --git a/tools/marvin/marvin/marvinLog.py b/tools/marvin/marvin/marvinLog.py index 76de185421b..65687aadde5 100644 --- a/tools/marvin/marvin/marvinLog.py +++ b/tools/marvin/marvin/marvinLog.py @@ -20,17 +20,22 @@ import logging import sys import time -from marvin.codes import (NO, - YES +import os +from marvin.codes import (SUCCESS, + FAILED ) +from marvin.cloudstackException import GetDetailExceptionInfo +from marvin.lib.utils import random_gen class MarvinLog: + ''' + @Name : MarvinLog @Desc : provides interface for logging to marvin @Input : logger_name : name for logger ''' - logFormat = logging.Formatter("%(asctime)s - %(levelname)s - %(name)s - %(message)s") + logFormat = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s") _instance = None def __new__(cls, logger_name): @@ -39,21 +44,39 @@ class MarvinLog: return cls._instance def __init__(self, logger_name): - self.loggerName = logger_name - self.logger = None + ''' + @Name: __init__ + @Input: logger_name for logger + ''' + self.__loggerName = logger_name + ''' + Logger for Logging Info + ''' + self.__logger = None + ''' + Log Folder Directory + ''' + self.__logFolderDir = None self.__setLogger() def __setLogger(self): - self.logger = logging.getLogger(self.loggerName) - self.logger.setLevel(logging.DEBUG) - - def setLogHandler(self, log_file_path, log_format=None, - log_level=logging.DEBUG): ''' + @Name : __setLogger + @Desc : Sets the Logger and Level + ''' + self.__logger = logging.getLogger(self.__loggerName) + self.__logger.setLevel(logging.DEBUG) + + def __setLogHandler(self, log_file_path, + log_format=None, + log_level=logging.DEBUG): + ''' + @Name : __setLogHandler @Desc: Adds the given Log handler to the current logger @Input: log_file_path: Log File Path as where to store the logs log_format : Format of log messages to be dumped log_level : Determines the level of logging for this logger + @Output: SUCCESS if no issues else FAILED ''' try: if log_file_path is not None: @@ -66,8 +89,98 @@ class MarvinLog: else: stream.setFormatter(self.__class__.logFormat) stream.setLevel(log_level) - self.logger.addHandler(stream) - except Exception, e: - print "\n Exception Occurred Under setLogHandler %s" % str(e) - finally: - return self.logger + self.__logger.addHandler(stream) + return SUCCESS + except Exception as e: + print "\nException Occurred Under " \ + "__setLogHandler %s" % GetDetailExceptionInfo(e) + return FAILED + + def __cleanPreviousLogs(self, logfolder_to_remove): + ''' + @Name : __cleanPreviousLogs + @Desc : Removes the Previous Logs + @Return: N\A + @Input: logfolder_to_remove: Path of Log to remove + ''' + try: + if os.path.isdir(logfolder_to_remove): + os.rmdir(logfolder_to_remove) + except Exception as e: + print "\n Exception Occurred Under __cleanPreviousLogs :%s" % \ + GetDetailExceptionInfo(e) + return FAILED + + def getLogger(self): + ''' + @Name:getLogger + @Desc : Returns the Logger + ''' + return self.__logger + + def getLogFolderPath(self): + ''' + @Name : getLogFolderPath + @Desc : Returns the final log directory path for marvin run + ''' + return self.__logFolderDir + + def createLogs(self, + test_module_name=None, + log_cfg=None, + user_provided_logpath=None): + ''' + @Name : createLogs + @Desc : Gets the Logger with file paths initialized and created + @Inputs :test_module_name: Test Module Name to use for logs while + creating log folder path + log_cfg: Log Configuration provided inside of + Configuration + user_provided_logpath:LogPath provided by user + If user provided log path + is available, then one in cfg + will not be picked up. + @Output : SUCCESS\FAILED + ''' + try: + temp_ts = time.strftime("%b_%d_%Y_%H_%M_%S", + time.localtime()) + if test_module_name is None: + temp_path = temp_ts + "_" + random_gen() + else: + temp_path = str(test_module_name) + \ + "__" + str(temp_ts) + "_" + random_gen() + + if user_provided_logpath: + temp_dir = user_provided_logpath + elif ((log_cfg is not None) and + ('LogFolderPath' in log_cfg.__dict__.keys()) and + (log_cfg.__dict__.get('LogFolderPath') is not None)): + temp_dir = \ + log_cfg.__dict__.get('LogFolderPath') + "/MarvinLogs" + + self.__logFolderDir = temp_dir + "//" + temp_path + print "\n==== Log Folder Path: %s. " \ + "All logs will be available here ====" \ + % str(self.__logFolderDir) + os.makedirs(self.__logFolderDir) + + ''' + Log File Paths + 1. FailedExceptionLog + 2. RunLog contains the complete Run Information for Test Run + 3. ResultFile contains the TC result information for Test Run + ''' + tc_failed_exception_log = \ + self.__logFolderDir + "/failed_plus_exceptions.txt" + tc_run_log = self.__logFolderDir + "/runinfo.txt" + if self.__setLogHandler(tc_run_log, + log_level=logging.DEBUG) != FAILED: + self.__setLogHandler(tc_failed_exception_log, + log_level=logging.FATAL) + return SUCCESS + return FAILED + except Exception as e: + print "\n Exception Occurred Under createLogs :%s" % \ + GetDetailExceptionInfo(e) + return FAILED diff --git a/tools/marvin/marvin/marvinPlugin.py b/tools/marvin/marvin/marvinPlugin.py index df7d7a3123a..4200a657e71 100644 --- a/tools/marvin/marvin/marvinPlugin.py +++ b/tools/marvin/marvin/marvinPlugin.py @@ -14,25 +14,24 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. - import marvin -import sys +from sys import stdout, exit import logging +import time +import os import nose.core from marvin.cloudstackTestCase import cloudstackTestCase from marvin.marvinInit import MarvinInit from nose.plugins.base import Plugin from marvin.codes import (SUCCESS, FAILED, - EXCEPTION, - UNKNOWN_ERROR - ) -import traceback -import time -import os + EXCEPTION) +from marvin.lib.utils import random_gen +from marvin.cloudstackException import GetDetailExceptionInfo class MarvinPlugin(Plugin): + """ Custom plugin for the cloudstackTestCases to be run using nose """ @@ -40,18 +39,35 @@ class MarvinPlugin(Plugin): name = "marvin" def __init__(self): - self.identifier = None - self.testClient = None - self.parsedConfig = None - self.configFile = None - self.loadFlag = None + self.__identifier = None + self.__testClient = None + self.__logFolderPath = None + self.__parsedConfig = None + ''' + Contains Config File + ''' + self.__configFile = None + ''' + Signifies the Zone against which all tests will be Run + ''' + self.__zoneForTests = None + ''' + Signifies the flag whether to deploy the New DC or Not + ''' + self.__deployDcFlag = None self.conf = None - self.debugStream = sys.stdout - self.testRunner = None - self.testResult = SUCCESS - self.startTime = None - self.testName = None - self.tcRunLogger = None + self.__resultStream = stdout + self.__testRunner = None + self.__testResult = SUCCESS + self.__startTime = None + self.__testName = None + self.__tcRunLogger = None + self.__testModName = '' + self.__hypervisorType = None + ''' + The Log Path provided by user where all logs are routed to + ''' + self.__userLogPath = None Plugin.__init__(self) def configure(self, options, conf): @@ -60,20 +76,20 @@ class MarvinPlugin(Plugin): self.enabled (True|False) determines whether marvin's tests will run. By default non-default plugins like marvin will be disabled """ + self.enabled = True if hasattr(options, self.enableOpt): if not getattr(options, self.enableOpt): self.enabled = False return - else: - self.enabled = True - self.configFile = options.config_file - self.loadFlag = options.load - self.logFolderPath = options.log_folder_path + self.__configFile = options.configFile + self.__deployDcFlag = options.deployDc + self.__zoneForTests = options.zone + self.__hypervisorType = options.hypervisor_type + self.__userLogPath = options.logFolder self.conf = conf - ''' - Initializes the marvin with required settings - ''' - self.startMarvin() + if self.startMarvin() == FAILED: + print "\nStarting Marvin Failed, exiting. Please Check" + exit(1) def options(self, parser, env): """ @@ -82,20 +98,31 @@ class MarvinPlugin(Plugin): parser.add_option("--marvin-config", action="store", default=env.get('MARVIN_CONFIG', './datacenter.cfg'), - dest="config_file", - help="Marvin's configuration file where the " + - "datacenter information is specified" + - " [MARVIN_CONFIG]") - parser.add_option("--load", action="store_true", + dest="configFile", + help="Marvin's configuration file is required." + "The config file containing the datacenter and " + "other management server " + "information is specified") + parser.add_option("--deploy", action="store_true", default=False, - dest="load", - help="Only load the deployment configuration given") - parser.add_option("--log-folder-path", - action="store", + dest="deployDc", + help="Deploys the DC with Given Configuration." + "Requires only when DC needs to be deployed") + parser.add_option("--zone", action="store", default=None, - dest="log_folder_path", - help="Path to the folder " - "where log files will be stored") + dest="zone", + help="Runs all tests against this specified zone") + parser.add_option("--hypervisor", action="store", + default=None, + dest="hypervisor_type", + help="Runs all tests against the specified " + "zone and hypervisor Type") + parser.add_option("--log-folder-path", action="store", + default=None, + dest="logFolder", + help="Collects all logs under the user specified" + "folder" + ) Plugin.options(self, parser, env) def wantClass(self, cls): @@ -105,93 +132,124 @@ class MarvinPlugin(Plugin): return True return None + def __checkImport(self, filename): + ''' + @Name : __checkImport + @Desc : Verifies to run the available test module for any Import + Errors before running and check + whether if it is importable. + This will check for test modules which has some issues to be + getting imported. + Returns False or True based upon the result. + ''' + try: + if os.path.isfile(filename): + ret = os.path.splitext(filename) + if ret[1] == ".py": + os.system("python " + filename) + return True + return False + except ImportError as e: + print "FileName :%s : Error : %s" % \ + (filename, GetDetailExceptionInfo(e)) + return False + def wantFile(self, filename): ''' - Only python files will be used as test modules + @Desc : Only python files will be used as test modules ''' - parts = filename.split(os.path.sep) - base, ext = os.path.splitext(parts[-1]) - if ext == '.py': - return True - else: - return False + return self.__checkImport(filename) def loadTestsFromTestCase(self, cls): if cls.__name__ != 'cloudstackTestCase': - self.identifier = cls.__name__ + self.__identifier = cls.__name__ self._injectClients(cls) def beforeTest(self, test): - self.testName = test.__str__().split()[0] - self.testClient.identifier = '-'.join([self.identifier, self.testName]) - self.tcRunLogger.name = test.__str__() - - def prepareTestRunner(self, runner): - return self.testRunner + self.__testModName = test.__str__() + self.__testName = test.__str__().split()[0] + self.__testClient.identifier = '-'.\ + join([self.__identifier, self.__testName]) + if self.__tcRunLogger: + self.__tcRunLogger.name = test.__str__() def startTest(self, test): """ Currently used to record start time for tests Dump Start Msg of TestCase to Log """ - self.tcRunLogger.debug("::::::::::::STARTED : TC: " + - str(self.testName) + " :::::::::::") - self.startTime = time.time() + if self.__tcRunLogger: + self.__tcRunLogger.debug("\n\n::::::::::::STARTED : TC: " + + str(self.__testName) + " :::::::::::") + self.__startTime = time.time() - def getErrorInfo(self, err): + def printMsg(self, status, tname, err): + if status in [FAILED, EXCEPTION] and self.__tcRunLogger: + self.__tcRunLogger.\ + fatal("%s: %s: %s" % (status, + tname, + GetDetailExceptionInfo(err))) + write_str = "=== TestName: %s | Status : %s ===\n" % (tname, status) + self.__resultStream.write(write_str) + print write_str + + def addSuccess(self, test, capt): ''' - Extracts and returns the sanitized error message + Adds the Success Messages to logs ''' - if err is not None: - return str(traceback.format_exc()) - else: - return UNKNOWN_ERROR + self.printMsg(SUCCESS, self.__testName, "Test Case Passed") + self.__testresult = SUCCESS def handleError(self, test, err): ''' Adds Exception throwing test cases and information to log. ''' - err_msg = self.getErrorInfo(err) - self.tcRunLogger.fatal("%s: %s: %s" % - (EXCEPTION, self.testName, err_msg)) - self.testResult = EXCEPTION + self.printMsg(EXCEPTION, self.__testName, GetDetailExceptionInfo(err)) + self.__testResult = EXCEPTION + + def prepareTestRunner(self, runner): + if self.__testRunner: + return self.__testRunner def handleFailure(self, test, err): ''' Adds Failing test cases and information to log. ''' - err_msg = self.getErrorInfo(err) - self.tcRunLogger.fatal("%s: %s: %s" % - (FAILED, self.testName, err_msg)) - self.testResult = FAILED + self.printMsg(FAILED, self.__testName, GetDetailExceptionInfo(err)) + self.__testResult = FAILED def startMarvin(self): ''' - Initializes the Marvin - creates the test Client - creates the runlogger for logging - Parses the config and creates a parsedconfig - Creates a debugstream for tc debug log + @Name : startMarvin + @Desc : Initializes the Marvin + creates the test Client + creates the runlogger for logging + Parses the config and creates a parsedconfig + Creates a debugstream for tc debug log ''' try: - obj_marvininit = MarvinInit(self.configFile, - self.loadFlag, - self.logFolderPath) - if obj_marvininit.init() == SUCCESS: - self.testClient = obj_marvininit.getTestClient() - self.tcRunLogger = obj_marvininit.getLogger() - self.parsedConfig = obj_marvininit.getParsedConfig() - self.debugStream = obj_marvininit.getDebugFile() - self.testRunner = nose.core.TextTestRunner(stream= - self.debugStream, - descriptions=True, - verbosity=2, - config=self.conf) + obj_marvininit = MarvinInit(self.__configFile, + self.__deployDcFlag, + None, + self.__zoneForTests, + self.__hypervisorType, + self.__userLogPath) + if obj_marvininit and obj_marvininit.init() == SUCCESS: + self.__testClient = obj_marvininit.getTestClient() + self.__tcRunLogger = obj_marvininit.getLogger() + self.__parsedConfig = obj_marvininit.getParsedConfig() + self.__resultStream = obj_marvininit.getResultFile() + self.__logFolderPath = obj_marvininit.getLogFolderPath() + self.__testRunner = nose.core.\ + TextTestRunner(stream=self.__resultStream, + descriptions=True, + verbosity=2, + config=self.conf) return SUCCESS - else: - return FAILED - except Exception, e: - print "Exception Occurred under startMarvin: %s" % str(e) + return FAILED + except Exception as e: + print "Exception Occurred under startMarvin: %s" % \ + GetDetailExceptionInfo(e) return FAILED def stopTest(self, test): @@ -199,27 +257,51 @@ class MarvinPlugin(Plugin): Currently used to record end time for tests """ endTime = time.time() - if self.startTime is not None: - totTime = int(endTime - self.startTime) - self.tcRunLogger.debug("TestCaseName: %s; Time Taken: " - "%s Seconds; " - "StartTime: %s; EndTime: %s; Result: %s" - % (self.testName, str(totTime), - str(time.ctime(self.startTime)), - str(time.ctime(endTime)), - self.testResult)) + if self.__startTime: + totTime = int(endTime - self.__startTime) + if self.__tcRunLogger: + self.__tcRunLogger.\ + debug("TestCaseName: %s; " + "Time Taken: %s Seconds; StartTime: %s; " + "EndTime: %s; Result: %s" % + (self.__testName, str(totTime), + str(time.ctime(self.__startTime)), + str(time.ctime(endTime)), + self.__testResult)) def _injectClients(self, test): - setattr(test, "debug", self.tcRunLogger.debug) - setattr(test, "info", self.tcRunLogger.info) - setattr(test, "warn", self.tcRunLogger.warning) - setattr(test, "error", self.tcRunLogger.error) - setattr(test, "testClient", self.testClient) - setattr(test, "config", self.parsedConfig) - if self.testClient.identifier is None: - self.testClient.identifier = self.identifier - setattr(test, "clstestclient", self.testClient) + setattr(test, "debug", self.__tcRunLogger.debug) + setattr(test, "info", self.__tcRunLogger.info) + setattr(test, "warn", self.__tcRunLogger.warning) + setattr(test, "error", self.__tcRunLogger.error) + setattr(test, "testClient", self.__testClient) + setattr(test, "config", self.__parsedConfig) + if self.__testClient.identifier is None: + self.__testClient.identifier = self.__identifier + setattr(test, "clstestclient", self.__testClient) if hasattr(test, "user"): # when the class-level attr applied. all test runs as 'user' - self.testClient.createUserApiClient(test.UserName, test.DomainName, - test.AcctType) + self.__testClient.getUserApiClient(test.UserName, + test.DomainName, + test.AcctType) + + def finalize(self, result): + try: + if not self.__userLogPath: + src = self.__logFolderPath + log_cfg = self.__parsedConfig.logger + tmp = log_cfg.__dict__.get('LogFolderPath') + "/MarvinLogs" + dst = tmp + "//" + random_gen() + mod_name = "test_suite" + if self.__testModName: + mod_name = self.__testModName.split(".") + if len(mod_name) > 2: + mod_name = mod_name[-2] + if mod_name: + dst = tmp + "/" + mod_name + "_" + random_gen() + cmd = "mv " + src + " " + dst + os.system(cmd) + print "===final results are now copied to: %s===" % str(dst) + except Exception, e: + print "=== Exception occurred under finalize :%s ===" % \ + str(GetDetailExceptionInfo(e)) diff --git a/tools/marvin/marvin/src/__init__.py b/tools/marvin/marvin/src/__init__.py new file mode 100644 index 00000000000..13a83393a91 --- /dev/null +++ b/tools/marvin/marvin/src/__init__.py @@ -0,0 +1,16 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. diff --git a/tools/marvin/marvin/sshClient.py b/tools/marvin/marvin/sshClient.py index fd8726cee37..611c8b5312c 100644 --- a/tools/marvin/marvin/sshClient.py +++ b/tools/marvin/marvin/sshClient.py @@ -16,29 +16,49 @@ # under the License. import paramiko +from paramiko import (BadHostKeyException, + AuthenticationException, + SSHException, + SSHClient, + AutoAddPolicy, + Transport, + SFTPClient) +import socket import time -import cloudstackException +from marvin.cloudstackException import ( + internalError, + GetDetailExceptionInfo +) import contextlib import logging from marvin.codes import ( - SUCCESS, FAIL, INVALID_INPUT, EXCEPTION_OCCURRED - ) + SUCCESS, FAILED, INVALID_INPUT, EXCEPTION_OCCURRED +) from contextlib import closing class SshClient(object): + ''' - Added timeout flag for ssh connect calls.Default to 3.0 seconds + @Desc : SSH Library for Marvin. + Facilitates SSH,SCP services to marvin users + @Input: host: Host to connect + port: port on host to connect + user: Username to be used for connecting + passwd: Password for connection + retries and delay applies for establishing connection + timeout : Applies while executing command ''' - def __init__(self, host, port, user, passwd, retries=20, delay=30, - log_lvl=logging.INFO, keyPairFiles=None, timeout=10.0): + + def __init__(self, host, port, user, passwd, retries=60, delay=10, + log_lvl=logging.DEBUG, keyPairFiles=None, timeout=10.0): self.host = None self.port = 22 self.user = user self.passwd = passwd self.keyPairFiles = keyPairFiles - self.ssh = paramiko.SSHClient() - self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) + self.ssh = SSHClient() + self.ssh.set_missing_host_key_policy(AutoAddPolicy()) self.logger = logging.getLogger('sshClient') self.retryCnt = 0 self.delay = 0 @@ -47,8 +67,8 @@ class SshClient(object): ch.setLevel(log_lvl) self.logger.addHandler(ch) - #Check invalid host value and raise exception - #Atleast host is required for connection + # Check invalid host value and raise exception + # Atleast host is required for connection if host is not None and host != '': self.host = host if retries is not None and retries > 0: @@ -57,11 +77,10 @@ class SshClient(object): self.delay = delay if timeout is not None and timeout > 0: self.timeout = timeout - if port is not None or port >= 0: + if port is not None and port >= 0: self.port = port - if self.createConnection() == FAIL: - raise cloudstackException.\ - internalError("Connection Failed") + if self.createConnection() == FAILED: + raise internalError("SSH Connection Failed") def execute(self, command): stdin, stdout, stderr = self.ssh.exec_command(command) @@ -86,15 +105,16 @@ class SshClient(object): @Desc: Creates an ssh connection for retries mentioned,along with sleep mentioned @Output: SUCCESS on successful connection - FAIL If connection through ssh failed + FAILED If connection through ssh failed ''' - ret = FAIL + ret = FAILED + except_msg = '' while self.retryCnt >= 0: try: - self.logger.debug("SSH Connection: Host:%s User:%s\ - Port:%s" % - (self.host, self.user, str(self.port) - )) + self.logger.debug("====Trying SSH Connection: Host:%s User:%s\ + Port:%s RetryCnt:%s===" % + (self.host, self.user, str(self.port), + str(self.retryCnt))) if self.keyPairFiles is None: self.ssh.connect(hostname=self.host, port=self.port, @@ -102,22 +122,39 @@ class SshClient(object): password=self.passwd, timeout=self.timeout) else: + self.ssh.load_host_keys(self.keyPairFiles) self.ssh.connect(hostname=self.host, port=self.port, username=self.user, password=self.passwd, key_filename=self.keyPairFiles, timeout=self.timeout, - look_for_keys=False + look_for_keys=True ) + self.logger.debug("===SSH to Host %s port : %s SUCCESSFUL===" + % (str(self.host), str(self.port))) ret = SUCCESS break - except Exception as se: - self.retryCnt = self.retryCnt - 1 - if self.retryCnt == 0: + except BadHostKeyException as e: + except_msg = GetDetailExceptionInfo(e) + except AuthenticationException as e: + except_msg = GetDetailExceptionInfo(e) + except SSHException as e: + except_msg = GetDetailExceptionInfo(e) + except socket.error as e: + except_msg = GetDetailExceptionInfo(e) + except Exception as e: + except_msg = GetDetailExceptionInfo(e) + finally: + if self.retryCnt == 0 or ret == SUCCESS: break + if except_msg != '': + self.logger.\ + exception("SshClient: Exception under " + "createConnection: %s" % except_msg) + self.retryCnt = self.retryCnt - 1 time.sleep(self.delay) - return ret + return ret def runCommand(self, command): ''' @@ -126,57 +163,54 @@ class SshClient(object): returns the result along with status code @Input: command to execute @Output: 1: status of command executed. - Default to None SUCCESS : If command execution is successful - FAIL : If command execution has failed - EXCEPTION_OCCURRED: Exception occurred while executing - command - INVALID_INPUT : If invalid value for command is passed + FAILED : If command execution has failed 2: stdin,stdout,stderr values of command output ''' - excep_msg = '' - ret = {"status": None, "stdin": None, "stdout": None, "stderr": None} + ret = {"status": FAILED, "stdin": None, "stdout": None, + "stderr": INVALID_INPUT} if command is None or command == '': - ret["status"] = INVALID_INPUT return ret try: status_check = 1 - stdin, stdout, stderr = self.ssh.exec_command(command) - output = stdout.readlines() - errors = stderr.readlines() - inp = stdin.readlines() - ret["stdin"] = inp - ret["stdout"] = output - ret["stderr"] = errors + stdin, stdout, stderr = self.ssh.\ + exec_command(command, timeout=self.timeout) if stdout is not None: status_check = stdout.channel.recv_exit_status() - if status_check == 0: - ret["status"] = SUCCESS - else: - ret["status"] = FAIL + if status_check == 0: + ret["status"] = SUCCESS + ret["stdout"] = stdout.readlines() + if stderr is not None: + ret["stderr"] = stderr.readlines() except Exception as e: - excep_msg = str(e) - ret["status"] = EXCEPTION_OCCURRED + ret["stderr"] = GetDetailExceptionInfo(e) + self.logger.exception("SshClient: Exception under runCommand :%s" % + GetDetailExceptionInfo(e)) finally: - self.logger.debug(" Host: %s Cmd: %s Output:%s Exception: %s" % - (self.host, command, str(ret), excep_msg)) + self.logger.debug(" Host: %s Cmd: %s Output:%s" % + (self.host, command, str(ret))) return ret def scp(self, srcFile, destPath): - transport = paramiko.Transport((self.host, int(self.port))) + transport = Transport((self.host, int(self.port))) transport.connect(username=self.user, password=self.passwd) - sftp = paramiko.SFTPClient.from_transport(transport) + sftp = SFTPClient.from_transport(transport) try: sftp.put(srcFile, destPath) - except IOError, e: + except IOError as e: raise e + def __del__(self): + self.close() + def close(self): if self.ssh is not None: self.ssh.close() + self.ssh = None if __name__ == "__main__": - with contextlib.closing(SshClient("10.223.75.10", 22, "root", - "password")) as ssh: - print ssh.execute("ls -l") + with contextlib.closing(SshClient("127.0.0.1", 22, "root", + "asdf!@34")) as ssh: + ret = ssh.runCommand("ls -l") + print ret diff --git a/tools/marvin/marvin/tcExecuteEngine.py b/tools/marvin/marvin/tcExecuteEngine.py index f959e7e935f..e2f4d114b79 100644 --- a/tools/marvin/marvin/tcExecuteEngine.py +++ b/tools/marvin/marvin/tcExecuteEngine.py @@ -23,6 +23,7 @@ from functools import partial class TestCaseExecuteEngine(object): + def __init__(self, testclient, config, tc_logger=None, debug_stream=None): """ Initialize the testcase execution engine, just the basics here @@ -53,7 +54,7 @@ class TestCaseExecuteEngine(object): if isinstance(test, unittest.BaseTestSuite): self.injectTestCase(test) else: - #inject testclient and logger into each unittest + # inject testclient and logger into each unittest self.tcRunLogger.name = test.__str__() setattr(test, "testClient", self.testclient) setattr(test, "config", self.config) @@ -61,9 +62,10 @@ class TestCaseExecuteEngine(object): setattr(test.__class__, "clstestclient", self.testclient) if hasattr(test, "user"): # attribute when test is entirely executed as user - self.testclient.createUserApiClient(test.UserName, - test.DomainName, - test.AcctType) + self.testclient.\ + getUserApiClient(test.UserName, + test.DomainName, + test.AcctType) def run(self): if self.suite: diff --git a/tools/marvin/marvin/testSetupSuccess.py b/tools/marvin/marvin/testSetupSuccess.py index 1701626a820..8b000f9e97c 100644 --- a/tools/marvin/marvin/testSetupSuccess.py +++ b/tools/marvin/marvin/testSetupSuccess.py @@ -23,6 +23,7 @@ from time import sleep as delay class TestSetupSuccess(cloudstackTestCase): + """ Test to verify if the cloudstack is ready to launch tests upon 1. Verify that system VMs are up and running in all zones diff --git a/tools/marvin/setup.py b/tools/marvin/setup.py index 9ce3951fdeb..4c775ad6144 100644 --- a/tools/marvin/setup.py +++ b/tools/marvin/setup.py @@ -6,9 +6,9 @@ # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at -# +# # http://www.apache.org/licenses/LICENSE-2.0 -# +# # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY @@ -30,33 +30,37 @@ except ImportError: VERSION = '0.1.0' import os + + def read(fname): return open(os.path.join(os.path.dirname(__file__), fname)).read().strip() setup(name="Marvin", - version=VERSION, - description="Marvin - Python client for Apache CloudStack", - author="Edison Su", - author_email="Edison.Su@citrix.com", - maintainer="Prasanna Santhanam", - maintainer_email="tsp@apache.org", - long_description="Marvin is the Apache CloudStack python client written around the unittest framework", - platforms=("Any",), - url="https://builds.apache.org/job/cloudstack-marvin/", - packages=["marvin", "marvin.cloudstackAPI", "marvin.integration", - "marvin.integration.lib", "marvin.sandbox", - "marvin.sandbox.advanced", "marvin.sandbox.advancedsg", "marvin.sandbox.basic"], - license="LICENSE.txt", - install_requires=[ - "mysql-connector-python", - "requests", - "paramiko", - "nose", - "ddt >= 0.4.0" - ], - py_modules=['marvin.marvinPlugin'], - zip_safe=False, - entry_points={ - 'nose.plugins': ['marvinPlugin = marvin.marvinPlugin:MarvinPlugin'] - }, -) + version=VERSION, + description="Marvin - Python client for Apache CloudStack", + author="Edison Su", + author_email="Edison.Su@citrix.com", + maintainer="Prasanna Santhanam", + maintainer_email="tsp@apache.org", + long_description="Marvin is the Apache CloudStack python " + "client written around the unittest framework", + platforms=("Any",), + url="https://builds.apache.org/job/cloudstack-marvin/", + packages=["marvin", "marvin.cloudstackAPI", + "marvin.lib", "marvin.config", "marvin.sandbox", + "marvin.sandbox.advanced", "marvin.sandbox.advancedsg", + "marvin.sandbox.basic"], + license="LICENSE.txt", + install_requires=[ + "mysql-connector-python", + "requests", + "paramiko", + "nose", + "ddt >= 0.4.0" + ], + py_modules=['marvin.marvinPlugin'], + zip_safe=False, + entry_points={ + 'nose.plugins': ['marvinPlugin = marvin.marvinPlugin:MarvinPlugin'] + }, + )