def setUpClass(cls):
        cls.testClient = super(TestMultiplePublicIpSubnets,
                               cls).getClsTestClient()
        cls.apiclient = cls.testClient.getApiClient()
        cls.services = cls.testClient.getParsedTestDataConfig()

        zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests())
        cls.zone = Zone(zone.__dict__)
        cls.template = get_template(cls.apiclient, cls.zone.id)
        cls._cleanup = []
        cls.skip = False

        if str(cls.zone.securitygroupsenabled) == "True":
            cls.skip = True
            return

        cls.hypervisor = cls.testClient.getHypervisorInfo()
        if cls.hypervisor.lower() not in ['kvm']:
            cls.skip = True
            return

        cls.logger = logging.getLogger("TestMultiplePublicIpSubnets")
        cls.stream_handler = logging.StreamHandler()
        cls.logger.setLevel(logging.DEBUG)
        cls.logger.addHandler(cls.stream_handler)

        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.apiclient)

        # Create small service offering
        cls.service_offering = ServiceOffering.create(
            cls.apiclient, cls.services["service_offerings"]["small"])
        cls._cleanup.append(cls.service_offering)
Example #2
0
    def setUpClass(cls):
        cls.testClient = super(TestHosts, cls).getClsTestClient()
        cls.testdata = cls.testClient.getParsedTestDataConfig()
        cls.apiclient = cls.testClient.getApiClient()
        cls.dbclient = cls.testClient.getDbConnection()
        cls._cleanup = []

        # get zone, domain etc
        cls.zone = Zone(get_zone(cls.apiclient, cls.testClient.getZoneForTests()).__dict__)
        cls.domain = get_domain(cls.apiclient)
        cls.pod = get_pod(cls.apiclient, cls.zone.id)

        cls.logger = logging.getLogger('TestHosts')
        cls.stream_handler = logging.StreamHandler()
        cls.logger.setLevel(logging.DEBUG)
        cls.logger.addHandler(cls.stream_handler)

        cls.storage_pool_db_id = None
        # list hosts
        hosts = list_hosts(cls.apiclient, type="Routing")
        i = 0
        while (i < len(hosts)):
            host_id = hosts[i].id
            cls.logger.debug("Trying host id : %s" % host_id)
            host_db_id = cls.dbclient.execute(
                "select id from host where uuid='%s';" %
                host_id)

            if host_db_id and host_db_id[0]:
                cls.logger.debug("found host db id : %s" % host_db_id)
                storage_pool_db_id = cls.dbclient.execute(
                    "select id from storage_pool where id='%s' and removed is null;" %
                    host_db_id[0][0])

                if storage_pool_db_id and storage_pool_db_id[0]:
                    cls.logger.debug("Found storage_pool_db_id  : %s" % storage_pool_db_id[0][0])
                    capacity_state = cls.dbclient.execute(
                        "select count(capacity_state) from op_host_capacity where host_id='%s' and capacity_type in (0,1,3) and capacity_state = 'Enabled'" %
                        host_db_id[0][0])

                    if capacity_state and capacity_state[0]:
                        cls.logger.debug("Check capacity count  : %s" % capacity_state[0][0])

                        if capacity_state[0][0] == 3:
                            cls.logger.debug("found host id : %s, can be used for this test" % host_id)
                            cls.my_host_id = host_id
                            cls.host_db_id = host_db_id
                            cls.storage_pool_db_id = storage_pool_db_id
                            break
            if not cls.storage_pool_db_id:
                i = i + 1


        if cls.storage_pool_db_id is None:
            raise unittest.SkipTest("There is no host and storage pool available in the setup to run this test")
 def tearDownClass(cls):
     try:
         zoneList = Zone.list(cls.apiclient, id=cls.zone.id)
         if zoneList[0].allocationstate == DISABLED:
             cmd = updateZone.updateZoneCmd()
             cmd.id = zoneList[0].id
             cmd.allocationstate = ENABLED
             cls.apiclient.updateZone(cmd)
         cleanup_resources(cls.apiclient, cls._cleanup)
     except Exception as e:
         raise Exception("Warning: Exception during cleanup : %s" % e)
    def setUpClass(cls):
        cls.testClient = super(
            TestProtocolNumberSecurityGroup,
            cls).getClsTestClient()
        cls.apiclient = cls.testClient.getApiClient()
        cls.testdata = cls.testClient.getParsedTestDataConfig()
        cls.services = cls.testClient.getParsedTestDataConfig()

        zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests())
        cls.zone = Zone(zone.__dict__)
        cls.template = get_template(cls.apiclient, cls.zone.id)
        cls._cleanup = []

        if str(cls.zone.securitygroupsenabled) != "True":
            sys.exit(1)

        cls.logger = logging.getLogger("TestProtocolNumberSecurityGroup")
        cls.stream_handler = logging.StreamHandler()
        cls.logger.setLevel(logging.DEBUG)
        cls.logger.addHandler(cls.stream_handler)

        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.apiclient)
        testClient = super(TestProtocolNumberSecurityGroup, cls).getClsTestClient()
        cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())
        cls.services['mode'] = cls.zone.networktype

        # Create new domain, account, network and VM
        cls.user_domain = Domain.create(
            cls.apiclient,
            services=cls.testdata["acl"]["domain2"],
            parentdomainid=cls.domain.id)

        # Create account
        cls.account = Account.create(
            cls.apiclient,
            cls.testdata["acl"]["accountD2"],
            admin=True,
            domainid=cls.user_domain.id
        )

        cls.service_offering = ServiceOffering.create(
            cls.apiclient,
            cls.testdata["service_offering"]
        )

        cls.testdata["domainid"] = cls.domain.id
        cls.testdata["virtual_machine_userdata"]["zoneid"] = cls.zone.id
        cls.testdata["virtual_machine_userdata"]["template"] = cls.template.id

        cls._cleanup.append(cls.service_offering)
        cls._cleanup.append(cls.account)
        cls._cleanup.append(cls.user_domain)
Example #5
0
    def test_01_zones(self):
        """Check the status of zones"""

        # Validate the following
        # 1. List zones
        # 2. Check allocation state is "enabled" or not

        zones = Zone.list(self.apiclient, id=self.zone.id, listall=True)
        self.assertEqual(isinstance(zones, list), True,
                         "Check if listZones returns a valid response")
        for zone in zones:
            self.assertEqual(zone.allocationstate, 'Enabled',
                             "Zone allocation state should be enabled")
        return
    def test_nuage_vpc_network_multizone(self):
        """ Test basic VPC Network functionality with Nuage VSP SDN plugin on multiple zones
        """

        # Repeat the tests in the above testcase "test_nuage_vpc_network" on multiple zones

        self.debug("Testing basic VPC Network functionality with Nuage VSP SDN plugin on multiple zones...")
        zones = Zone.list(self.api_client)
        if len(zones) == 1:
            self.skipTest("There is only one Zone configured: skipping test")
        for zone in zones:
            self.debug("Zone - %s" % zone.name)
            self.setUpClass(zone=zone)
            self.test_nuage_vpc_network()
Example #7
0
    def test_nuage_vpc_network_multizone(self):
        """ Test basic VPC Network functionality with Nuage VSP SDN plugin on multiple zones
        """

        # Repeat the tests in the above testcase "test_nuage_vpc_network" on multiple zones

        self.debug(
            "Testing basic VPC Network functionality with Nuage VSP SDN plugin on multiple zones..."
        )
        zones = Zone.list(self.api_client)
        if len(zones) == 1:
            self.skipTest("There is only one Zone configured: skipping test")
        for zone in zones:
            self.debug("Zone - %s" % zone.name)
            self.setUpClass(zone=zone)
            self.test_nuage_vpc_network()
    def test_04_list_zones_with_no_params(self):
        """
        Test list zones
        """
        zonesavailable = 0
        listallzones = Zone.list(self.user_api_client)

        self.assertEqual(isinstance(listallzones, list), True,
                         "Check list zones response returns a valid list")

        for zone1 in listallzones:
            if zone1.allocationstate == "Enabled":
                zonesavailable = zonesavailable + 1

        if zonesavailable < 1:
            self.fail("Check if zones are listed")

        return
    def test_04_list_zones_with_no_params(self):

        """
        Test list zones
        """
        zonesavailable=0
        listallzones=Zone.list(self.user_api_client)

        self.assertEqual(
                            isinstance(listallzones, list),
                            True,
                            "Check list zones response returns a valid list"
                        )

        for zone1 in listallzones:
            if zone1.allocationstate=="Enabled":
                zonesavailable=zonesavailable+1
 
        if zonesavailable<1:
            self.fail("Check if zones are listed")

        return
    def setUpClass(cls):
        cls.testClient = super(TestHosts, cls).getClsTestClient()
        cls.testdata = cls.testClient.getParsedTestDataConfig()
        cls.apiclient = cls.testClient.getApiClient()
        cls.dbclient = cls.testClient.getDbConnection()
        cls._cleanup = []

        # get zone, domain etc
        cls.zone = Zone(
            get_zone(cls.apiclient, cls.testClient.getZoneForTests()).__dict__)
        cls.domain = get_domain(cls.apiclient)
        cls.pod = get_pod(cls.apiclient, cls.zone.id)

        # list hosts
        hosts = list_hosts(cls.apiclient, type="Routing")
        if len(hosts) > 0:
            cls.my_host_id = hosts[0].id
            cls.host_db_id = cls.dbclient.execute(
                "select id from host where uuid='%s';" % cls.my_host_id)
            cls.my_cluster_id = hosts[0].clusterid
        else:
            raise unittest.SkipTest("There is no host available in the setup")
Example #11
0
    def setUpClass(cls):
        cls.testClient = super(TestNetworkManagement, cls).getClsTestClient()
        cls.apiclient = cls.testClient.getApiClient()
        cls.dbclient = cls.testClient.getDbConnection()
        cls.testdata = cls.testClient.getParsedTestDataConfig()
        cls.services = cls.testClient.getParsedTestDataConfig()
        zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests())
        cls.zone = Zone(zone.__dict__)
        cls._cleanup = []

        cls.logger = logging.getLogger("TestNetworkManagement")
        cls.stream_handler = logging.StreamHandler()
        cls.logger.setLevel(logging.DEBUG)
        cls.logger.addHandler(cls.stream_handler)

        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.apiclient)
        testClient = super(TestNetworkManagement, cls).getClsTestClient()
        cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())
        cls.services['mode'] = cls.zone.networktype
        # Create new domain, account, network and VM
        cls.user_domain = Domain.create(
            cls.apiclient,
            services=cls.testdata["acl"]["domain2"],
            parentdomainid=cls.domain.id)

        # Create account
        cls.account = Account.create(cls.apiclient,
                                     cls.testdata["acl"]["accountD2"],
                                     admin=True,
                                     domainid=cls.user_domain.id)

        # Create small service offering
        cls.service_offering = ServiceOffering.create(
            cls.apiclient, cls.testdata["service_offerings"]["small"])

        cls._cleanup.append(cls.service_offering)
        cls._cleanup.append(cls.account)
        cls._cleanup.append(cls.user_domain)
    def test_01_zones(self):
        """Check the status of zones"""

        # Validate the following
        # 1. List zones
        # 2. Check allocation state is "enabled" or not

        zones = Zone.list(
                          self.apiclient,
                          id=self.zone.id,
              listall=True
                          )
        self.assertEqual(
                         isinstance(zones, list),
                         True,
                         "Check if listZones returns a valid response"
                         )
        for zone in zones:
            self.assertEqual(
                             zone.allocationstate,
                             'Enabled',
                             "Zone allocation state should be enabled"
                             )
        return
    def setUpClass(cls):
        cls.testClient = super(
            TestAcquireSpecifiedPublicIp,
            cls).getClsTestClient()
        cls.apiclient = cls.testClient.getApiClient()
        cls.services = cls.testClient.getParsedTestDataConfig()

        zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests())
        cls.zone = Zone(zone.__dict__)
        cls.template = get_template(cls.apiclient, cls.zone.id)
        cls._cleanup = []

        if str(cls.zone.securitygroupsenabled) == "True":
            sys.exit(1)

        cls.logger = logging.getLogger("TestAcquireSpecifiedPublicIp")
        cls.stream_handler = logging.StreamHandler()
        cls.logger.setLevel(logging.DEBUG)
        cls.logger.addHandler(cls.stream_handler)

        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.apiclient)

        # Create new domain1
        cls.domain1 = Domain.create(
            cls.apiclient,
            services=cls.services["acl"]["domain1"],
            parentdomainid=cls.domain.id)

        # Create account1
        cls.account1 = Account.create(
            cls.apiclient,
            cls.services["acl"]["accountD1"],
            domainid=cls.domain1.id
        )

        # Create domain2
        cls.domain2 = Domain.create(
            cls.apiclient,
            services=cls.services["acl"]["domain2"],
            parentdomainid=cls.domain.id)

        # Create account2
        cls.account2 = Account.create(
            cls.apiclient,
            cls.services["acl"]["accountD2"],
            domainid=cls.domain2.id
        )

        cls.services["publiciprange"]["zoneid"] = cls.zone.id
        cls.services["publiciprange"]["forvirtualnetwork"] = "true"

        # Create public ip range 1
        cls.services["publiciprange"]["vlan"] = get_free_vlan(
            cls.apiclient,
            cls.zone.id)[1]
        random_subnet_number = random.randrange(10,20)
        cls.services["publiciprange"]["gateway"] = "172.16." + \
            str(random_subnet_number) + ".1"
        cls.services["publiciprange"]["startip"] = "172.16." + \
            str(random_subnet_number) + ".2"
        cls.services["publiciprange"]["endip"] = "172.16." + \
            str(random_subnet_number) + ".10"
        cls.services["publiciprange"]["netmask"] = "255.255.255.0"
        cls.public_ip_range1 = PublicIpRange.create(
            cls.apiclient,
            cls.services["publiciprange"]
        )
        PublicIpRange.dedicate(
            cls.apiclient,
            cls.public_ip_range1.vlan.id,
            domainid=cls.account1.domainid
        )

        # Create public ip range 2
        cls.services["publiciprange"]["vlan"] = get_free_vlan(
            cls.apiclient,
            cls.zone.id)[1]
        cls.services["publiciprange"]["gateway"] = "172.16." + \
            str(random_subnet_number + 1) + ".1"
        cls.services["publiciprange"]["startip"] = "172.16." + \
            str(random_subnet_number + 1) + ".2"
        cls.services["publiciprange"]["endip"] = "172.16." + \
            str(random_subnet_number + 1) + ".10"
        cls.services["publiciprange"]["netmask"] = "255.255.255.0"
        cls.public_ip_range2 = PublicIpRange.create(
            cls.apiclient,
            cls.services["publiciprange"]
        )
        PublicIpRange.dedicate(
            cls.apiclient,
            cls.public_ip_range2.vlan.id,
            account=cls.account1.name,
            domainid=cls.account1.domainid
        )

        # Create public ip range 3
        cls.services["publiciprange"]["vlan"] = get_free_vlan(
            cls.apiclient,
            cls.zone.id)[1]
        cls.services["publiciprange"]["gateway"] = "172.16." + \
            str(random_subnet_number + 2) + ".1"
        cls.services["publiciprange"]["startip"] = "172.16." + \
            str(random_subnet_number + 2) + ".2"
        cls.services["publiciprange"]["endip"] = "172.16." + \
            str(random_subnet_number + 2) + ".10"
        cls.services["publiciprange"]["netmask"] = "255.255.255.0"
        cls.public_ip_range3 = PublicIpRange.create(
            cls.apiclient,
            cls.services["publiciprange"]
        )
        PublicIpRange.dedicate(
            cls.apiclient,
            cls.public_ip_range3.vlan.id,
            domainid=cls.account2.domainid
        )

        # Create public ip range 4
        cls.services["publiciprange"]["vlan"] = get_free_vlan(
            cls.apiclient,
            cls.zone.id)[1]
        cls.services["publiciprange"]["gateway"] = "172.16." + \
            str(random_subnet_number + 3) + ".1"
        cls.services["publiciprange"]["startip"] = "172.16." + \
            str(random_subnet_number + 3) + ".2"
        cls.services["publiciprange"]["endip"] = "172.16." + \
            str(random_subnet_number + 3) + ".10"
        cls.services["publiciprange"]["netmask"] = "255.255.255.0"
        cls.public_ip_range4 = PublicIpRange.create(
            cls.apiclient,
            cls.services["publiciprange"]
        )
        PublicIpRange.dedicate(
            cls.apiclient,
            cls.public_ip_range4.vlan.id,
            account=cls.account2.name,
            domainid=cls.account2.domainid
        )

        # Create public ip range 5
        cls.services["publiciprange"]["vlan"] = get_free_vlan(
            cls.apiclient,
            cls.zone.id)[1]
        cls.services["publiciprange"]["gateway"] = "172.16." + \
            str(random_subnet_number + 4) + ".1"
        cls.services["publiciprange"]["startip"] = "172.16." + \
            str(random_subnet_number + 4) + ".2"
        cls.services["publiciprange"]["endip"] = "172.16." + \
            str(random_subnet_number + 4) + ".10"
        cls.services["publiciprange"]["netmask"] = "255.255.255.0"
        cls.public_ip_range5 = PublicIpRange.create(
            cls.apiclient,
            cls.services["publiciprange"]
        )

        cls._cleanup.append(cls.account1)
        cls._cleanup.append(cls.domain1)
        cls._cleanup.append(cls.account2)
        cls._cleanup.append(cls.domain2)
        cls._cleanup.append(cls.public_ip_range1)
        cls._cleanup.append(cls.public_ip_range2)
        cls._cleanup.append(cls.public_ip_range3)
        cls._cleanup.append(cls.public_ip_range4)
        cls._cleanup.append(cls.public_ip_range5)
Example #14
0
    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:
            raise unittest.SkipTest("Not enough zones exist 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["privatetemplate"][
                "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["privatetemplate"],
                zones_list[0].id,
                hypervisor=hypervisor_list[0].name
            )
            self.assertIsNotNone(
                template_created,
                "Template creation 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
            )
            # 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_created.copy(
                self.userapiclient,
                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["privatetemplate"]["ostype"]
        return
Example #15
0
    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.skipTest("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
Example #16
0
    tc_run_logger = log_obj.getLogger()
  else:
    print "\n=== Log Creation Failed. Please Check ==="
    exit(1)

  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)

  if (options.input) and (os.path.isfile(options.input)):
    apiClient = obj_tc_client.getApiClient()
    tmp_dict = {}

    zones = Zone.list(apiClient)
    if zones:
      for zone in zones:
        print "zone name={}, id={}".format(zone.name, zone.id)
        if zone.allocationstate == 'Enabled':
          print "Disable zone"
          zoneCmd = updateZone.updateZoneCmd()
          zoneCmd.id = zone.id
          zoneCmd.allocationstate = 'Disabled'
          apiClient.updateZone(zoneCmd)

    ssvms = list_ssvms(apiClient)
    if ssvms:
      for ssvm in ssvms:
        print "ssvm name={}, id={}".format(ssvm.name, ssvm.id)
        print "Destroy SSVM"
Example #17
0
    def setUpClass(cls):

        testClient = super(TestTemplates, cls).getClsTestClient()
        cls.apiclient = testClient.getApiClient()
        cls._cleanup = []
        cls.services = testClient.getParsedTestDataConfig()
        cls.unsupportedHypervisor = False
        cls.hypervisor = testClient.getHypervisorInfo()
        if cls.hypervisor.lower() in ['lxc']:
            # Template creation from root volume is not supported in LXC
            cls.unsupportedHypervisor = True
            return

        # Get Zone, Domain and templates
        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
        cls.zones = Zone.list(cls.apiclient)
        if not isinstance(cls.zones, list):
            raise Exception("Failed to find zones.")

        cls.disk_offering = DiskOffering.create(
                                    cls.apiclient,
                                    cls.services["disk_offering"]
                                    )
        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["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"]["ostypeid"] = template.ostypeid
        cls.services["template_2"]["ostypeid"] = template.ostypeid
        cls.services["ostypeid"] = template.ostypeid
        cls.account = Account.create(
                            cls.apiclient,
                            cls.services["account"],
                            admin=True,
                            domainid=cls.domain.id
                            )
        cls.user = Account.create(
                            cls.apiclient,
                            cls.services["account"],
                            domainid=cls.domain.id
                            )
        cls.service_offering = ServiceOffering.create(
                                            cls.apiclient,
                                            cls.services["service_offerings"]["tiny"]
                                        )
        #create virtual machine
        cls.virtual_machine = VirtualMachine.create(
                                    cls.apiclient,
                                    cls.services["virtual_machine"],
                                    templateid=template.id,
                                    accountid=cls.account.name,
                                    domainid=cls.account.domainid,
                                    serviceofferingid=cls.service_offering.id,
                                    mode=cls.services["mode"]
                                    )
        #Stop virtual machine
        cls.virtual_machine.stop(cls.apiclient)

        list_volume = Volume.list(
                                   cls.apiclient,
                                   virtualmachineid=cls.virtual_machine.id,
                                   type='ROOT',
                                   listall=True
                                   )
        try:
            cls.volume = list_volume[0]
        except Exception as e:
            raise Exception(
                "Exception: Unable to find root volume foe VM: %s - %s" %
                 (cls.virtual_machine.id, e))

        #Create templates for Edit, Delete & update permissions testcases
        cls.template_1 = Template.create(
                                         cls.apiclient,
                                         cls.services["template"],
                                         cls.volume.id,
                                         account=cls.account.name,
                                         domainid=cls.account.domainid
                                         )
        cls.template_2 = Template.create(
                                         cls.apiclient,
                                         cls.services["template_2"],
                                         cls.volume.id,
                                         account=cls.account.name,
                                         domainid=cls.account.domainid
                                         )
        cls._cleanup = [
                        cls.service_offering,
                        cls.disk_offering,
                        cls.account,
                        cls.user
                        ]
Example #18
0
    def setUpClass(cls):
        # Set up API client
        testclient = super(TestManagedSystemVMs, cls).getClsTestClient()

        cls.apiClient = testclient.getApiClient()
        cls.configData = testclient.getParsedTestDataConfig()
        cls.dbConnection = testclient.getDbConnection()

        cls.testdata = TestData().testdata

        cls._connect_to_hypervisor()

        # Set up SolidFire connection
        solidfire = cls.testdata[TestData.solidFire]

        cls.sfe = ElementFactory.create(solidfire[TestData.mvip], solidfire[TestData.username], solidfire[TestData.password])

        # Get Resources from Cloud Infrastructure
        cls.zone = Zone(get_zone(cls.apiClient, zone_id=cls.testdata[TestData.zoneId]).__dict__)
        cls.cluster = list_clusters(cls.apiClient)[0]
        cls.template = get_template(cls.apiClient, cls.zone.id, cls.configData["ostype"])
        cls.domain = get_domain(cls.apiClient, cls.testdata[TestData.domainId])

        # Create test account
        cls.account = Account.create(
            cls.apiClient,
            cls.testdata["account"],
            admin=1
        )

        # Set up connection to make customized API calls
        cls.user = User.create(
            cls.apiClient,
            cls.testdata["user"],
            account=cls.account.name,
            domainid=cls.domain.id
        )

        url = cls.testdata[TestData.url]

        api_url = "http://" + url + ":8080/client/api"
        userkeys = User.registerUserKeys(cls.apiClient, cls.user.id)

        cls.cs_api = SignedAPICall.CloudStack(api_url, userkeys.apikey, userkeys.secretkey)

        cls.compute_offering = ServiceOffering.create(
            cls.apiClient,
            cls.testdata[TestData.computeOffering]
        )

        systemoffering = cls.testdata[TestData.systemOffering]

        systemoffering[TestData.name] = "Managed SSVM"
        systemoffering['systemvmtype'] = "secondarystoragevm"

        cls.secondary_storage_offering = ServiceOffering.create(
            cls.apiClient,
            systemoffering
        )

        systemoffering[TestData.name] = "Managed CPVM"
        systemoffering['systemvmtype'] = "consoleproxy"

        cls.console_proxy_offering = ServiceOffering.create(
            cls.apiClient,
            systemoffering
        )

        systemoffering[TestData.name] = "Managed VR"
        systemoffering['systemvmtype'] = "domainrouter"

        cls.virtual_router_offering = ServiceOffering.create(
            cls.apiClient,
            systemoffering
        )

        # Resources that are to be destroyed
        cls._cleanup = [
            cls.secondary_storage_offering,
            cls.console_proxy_offering,
            cls.virtual_router_offering,
            cls.compute_offering,
            cls.user,
            cls.account
        ]
Example #19
0
    def setUpClass(cls):
        cls.testClient = super(TestNetworkPermissions, cls).getClsTestClient()
        cls.apiclient = cls.testClient.getApiClient()
        cls.services = cls.testClient.getParsedTestDataConfig()

        zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests())
        cls.zone = Zone(zone.__dict__)
        cls.template = get_template(cls.apiclient, cls.zone.id)
        cls._cleanup = []

        cls.logger = logging.getLogger("TestNetworkPermissions")
        cls.stream_handler = logging.StreamHandler()
        cls.logger.setLevel(logging.DEBUG)
        cls.logger.addHandler(cls.stream_handler)

        cls.domain = get_domain(cls.apiclient)

        # Create small service offering
        cls.service_offering = ServiceOffering.create(
            cls.apiclient, cls.services["service_offerings"]["small"])
        cls._cleanup.append(cls.service_offering)

        # Create network offering for isolated networks
        cls.network_offering_isolated = NetworkOffering.create(
            cls.apiclient, cls.services["isolated_network_offering"])
        cls.network_offering_isolated.update(cls.apiclient, state='Enabled')
        cls._cleanup.append(cls.network_offering_isolated)

        # Create sub-domain
        cls.sub_domain = Domain.create(cls.apiclient,
                                       cls.services["acl"]["domain1"])
        cls._cleanup.append(cls.sub_domain)

        # Create domain admin and normal user
        cls.domain_admin = Account.create(cls.apiclient,
                                          cls.services["acl"]["accountD1A"],
                                          admin=True,
                                          domainid=cls.sub_domain.id)
        cls._cleanup.append(cls.domain_admin)

        cls.network_owner = Account.create(cls.apiclient,
                                           cls.services["acl"]["accountD11A"],
                                           domainid=cls.sub_domain.id)
        cls._cleanup.append(cls.network_owner)

        cls.other_user = Account.create(cls.apiclient,
                                        cls.services["acl"]["accountD11B"],
                                        domainid=cls.sub_domain.id)
        cls._cleanup.append(cls.other_user)

        # Create project
        cls.project = Project.create(cls.apiclient,
                                     cls.services["project"],
                                     account=cls.domain_admin.name,
                                     domainid=cls.domain_admin.domainid)
        cls._cleanup.append(cls.project)

        # Create api clients for domain admin and normal user
        cls.domainadmin_user = cls.domain_admin.user[0]
        cls.domainadmin_apiclient = cls.testClient.getUserApiClient(
            cls.domainadmin_user.username, cls.sub_domain.name)
        cls.networkowner_user = cls.network_owner.user[0]
        cls.user_apiclient = cls.testClient.getUserApiClient(
            cls.networkowner_user.username, cls.sub_domain.name)

        cls.otheruser_user = cls.other_user.user[0]
        cls.otheruser_apiclient = cls.testClient.getUserApiClient(
            cls.otheruser_user.username, cls.sub_domain.name)

        # Create networks for domain admin, normal user and project
        cls.services["network"]["name"] = "Test Network Isolated - Project"
        cls.project_network = Network.create(
            cls.apiclient,
            cls.services["network"],
            networkofferingid=cls.network_offering_isolated.id,
            domainid=cls.sub_domain.id,
            projectid=cls.project.id,
            zoneid=cls.zone.id)
        cls._cleanup.append(cls.project_network)

        cls.services["network"][
            "name"] = "Test Network Isolated - Domain admin"
        cls.domainadmin_network = Network.create(
            cls.apiclient,
            cls.services["network"],
            networkofferingid=cls.network_offering_isolated.id,
            domainid=cls.sub_domain.id,
            accountid=cls.domain_admin.name,
            zoneid=cls.zone.id)
        cls._cleanup.append(cls.domainadmin_network)

        cls.services["network"]["name"] = "Test Network Isolated - Normal user"
        cls.user_network = Network.create(
            cls.apiclient,
            cls.services["network"],
            networkofferingid=cls.network_offering_isolated.id,
            domainid=cls.sub_domain.id,
            accountid=cls.network_owner.name,
            zoneid=cls.zone.id)
        cls._cleanup.append(cls.user_network)
Example #20
0
    def setUpClass(cls):
        cls.testClient = super(TestVolumeDestroyRecover,
                               cls).getClsTestClient()
        cls.apiclient = cls.testClient.getApiClient()
        cls.services = cls.testClient.getParsedTestDataConfig()
        zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests())
        cls.zone = Zone(zone.__dict__)
        cls._cleanup = []

        cls.logger = logging.getLogger("TestVolumeDestroyRecover")
        cls.stream_handler = logging.StreamHandler()
        cls.logger.setLevel(logging.DEBUG)
        cls.logger.addHandler(cls.stream_handler)

        # Get Domain and templates
        cls.domain = get_domain(cls.apiclient)

        cls.template = get_template(cls.apiclient,
                                    cls.zone.id,
                                    hypervisor="KVM")
        if cls.template == FAILED:
            sys.exit(1)
        cls.templatesize = (cls.template.size / (1024**3))

        cls.services['mode'] = cls.zone.networktype
        # Create Account
        cls.account = Account.create(cls.apiclient,
                                     cls.services["account"],
                                     admin=True,
                                     domainid=cls.domain.id)
        cls._cleanup.append(cls.account)
        accounts = Account.list(cls.apiclient, id=cls.account.id)
        cls.expectedCount = int(accounts[0].primarystoragetotal)
        cls.volumeTotal = int(accounts[0].volumetotal)

        if cls.zone.securitygroupsenabled:
            cls.services["shared_network_offering"]["specifyVlan"] = 'True'
            cls.services["shared_network_offering"]["specifyIpRanges"] = 'True'

            cls.network_offering = NetworkOffering.create(
                cls.apiclient, cls.services["shared_network_offering"])
            cls._cleanup.append(cls.network_offering)
            cls.network_offering.update(cls.apiclient, state='Enabled')

            cls.account_network = Network.create(
                cls.apiclient,
                cls.services["network2"],
                networkofferingid=cls.network_offering.id,
                zoneid=cls.zone.id,
                accountid=cls.account.name,
                domainid=cls.account.domainid)
            cls._cleanup.append(cls.account_network)
        else:
            cls.network_offering = NetworkOffering.create(
                cls.apiclient,
                cls.services["isolated_network_offering"],
            )
            cls._cleanup.append(cls.network_offering)
            # Enable Network offering
            cls.network_offering.update(cls.apiclient, state='Enabled')

            # Create account network
            cls.services["network"]["zoneid"] = cls.zone.id
            cls.services["network"][
                "networkoffering"] = cls.network_offering.id
            cls.account_network = Network.create(cls.apiclient,
                                                 cls.services["network"],
                                                 cls.account.name,
                                                 cls.account.domainid)
            cls._cleanup.append(cls.account_network)

        # Create small service offering
        cls.service_offering = ServiceOffering.create(
            cls.apiclient, cls.services["service_offerings"]["small"])
        cls._cleanup.append(cls.service_offering)

        # Create disk offering
        cls.disk_offering = DiskOffering.create(
            cls.apiclient,
            cls.services["disk_offering"],
        )
        cls._cleanup.append(cls.disk_offering)
Example #21
0
        log_folder_path = log_obj.getLogFolderPath()
        tc_run_logger = log_obj.getLogger()
    else:
        print "\n=== Log Creation Failed. Please Check ==="
        exit(1)

    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)

    if (options.input) and (os.path.isfile(options.input)):
        apiClient = obj_tc_client.getApiClient()
        zones = Zone.list(apiClient)
        if zones:
            for zone in zones:
                print "zone name={}, id={}".format(zone.name, zone.id)
                if zone.allocationstate == 'Enabled':
                    services = {}
                    services["displaytext"] = "Debian"
                    services["name"] = "deb"
                    if options.upload_tmpl is not None:
                        services["hypervisor"] = "KVM"
                        services["format"] = "QCOW2"
                        services["url"] = options.upload_tmpl
                    if options.upload_iso is not None:
                        services["url"] = options.upload_iso
                    services["ostype"] = "Debian GNU/Linux 7(64-bit)"
                    services["zoneid"] = zone.id
Example #22
0
  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)

  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)

  if (options.input) and (os.path.isfile(options.input)):
    apiClient = obj_tc_client.getApiClient()
    zones = Zone.list(apiClient)
    if zones:
      for zone in zones:
        print "zone name={}, id={}".format(zone.name, zone.id)
        if zone.allocationstate == 'Enabled':
          services = {}
          services["displaytext"] = "Debian"
          services["name"] = "deb"
          if options.upload_tmpl is not None:
            services["hypervisor"] = "KVM"
            services["format"] = "QCOW2"
            services["url"] = options.upload_tmpl
          if options.upload_iso is not None:
            services["url"] = options.upload_iso
          services["ostype"] = "Debian GNU/Linux 7(64-bit)"
          services["zoneid"] = zone.id
    def test_01_disable_enable_zone(self):
        """disable enable zone
            1. Disable zone and verify following things:
                For admin user:
                    1. Should be create to start/stop exsiting vms
                    2. Should be create to deploy new vm, snapshot,volume,
                       template,iso in the same zone
                For Non-admin user:
                    1. Should be create to start/stop exsiting vms
                    2. Should not be create to deploy new vm, snapshot,volume,
                       template,iso in the same zone
            2. Enable the above disabled zone and verify that:
                -All users should be create to deploy new vm,
                    snapshot,volume,template,iso in the same zone
            3. Try to delete the zone and it should fail with error message:
                -"The zone is not deletable because there are
                    servers running in this zone"
        """
        # Step 1
        vm_user = VirtualMachine.create(
            self.userapiclient,
            self.testdata["small"],
            templateid=self.template.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
            zoneid=self.zone.id,
        )

        vm_root = VirtualMachine.create(
            self.apiclient,
            self.testdata["small"],
            templateid=self.template.id,
            accountid=self.admin_account.name,
            domainid=self.admin_account.domainid,
            serviceofferingid=self.service_offering.id,
            zoneid=self.zone.id,
        )

        cmd = updateZone.updateZoneCmd()
        cmd.id = self.zone.id
        cmd.allocationstate = DISABLED
        self.apiclient.updateZone(cmd)
        zoneList = Zone.list(self.apiclient, id=self.zone.id)

        self.assertEqual(zoneList[0].allocationstate, DISABLED, "Check if the zone is in disabled state")

        # Both user and admin vms shoul be running
        self.assertEqual(vm_user.state.lower(), "running", "Verify that the user vm is running")

        self.assertEqual(vm_root.state.lower(), "running", "Verify that the admin vm is running")

        vm_root.stop(self.apiclient)
        vm_user.stop(self.apiclient)

        root_state = self.dbclient.execute("select state from vm_instance where name='%s'" % vm_root.name)[0][0]

        user_state = self.dbclient.execute("select state from vm_instance where name='%s'" % vm_user.name)[0][0]

        self.assertEqual(root_state.lower(), "stopped", "verify that vm is Stopped")

        self.assertEqual(user_state.lower(), "stopped", "verify that vm is stopped")

        root_volume = list_volumes(self.apiclient, virtualmachineid=vm_root.id, type="ROOT", listall=True)

        self.assertEqual(validateList(root_volume)[0], PASS, "list volume  is empty for vmid %s" % vm_root.id)
        root_vm_new = VirtualMachine.create(
            self.apiclient,
            self.testdata["small"],
            templateid=self.template.id,
            accountid=self.admin_account.name,
            domainid=self.admin_account.domainid,
            serviceofferingid=self.service_offering.id,
            zoneid=self.zone.id,
        )

        self.assertEqual(root_vm_new.state.lower(), "running", "Verify that admin should create new VM")

        if self.snapshotSupported:
            Snapshot.create(self.apiclient, root_volume[0].id)

            snapshots = list_snapshots(self.apiclient, volumeid=root_volume[0].id, listall=True)

            self.assertEqual(
                validateList(snapshots)[0], PASS, "list snapshot  is empty for volume id %s" % root_volume[0].id
            )

            Template.create_from_snapshot(self.apiclient, snapshots[0], self.testdata["privatetemplate"])

        builtin_info = get_builtin_template_info(self.apiclient, self.zone.id)
        self.testdata["privatetemplate"]["url"] = builtin_info[0]
        self.testdata["privatetemplate"]["hypervisor"] = builtin_info[1]
        self.testdata["privatetemplate"]["format"] = builtin_info[2]
        """
        //commenting it for now will uncomment  once expected behaviour is known
        Template.register(
            self.apiclient,
            self.testdata["privatetemplate"],
            zoneid=self.zone.id)
        """
        Volume.create(
            self.apiclient,
            self.testdata["volume"],
            zoneid=self.zone.id,
            account=self.admin_account.name,
            domainid=self.admin_account.domainid,
            diskofferingid=self.disk_offering.id,
        )
        """
        //commenting it for now will uncomment  once expected behaviour is known
        Iso.create(
            self.apiclient,
            self.testdata["iso2"],
            zoneid=self.zone.id,
            account=self.admin_account.name,
            domainid=self.admin_account.domainid,
        )
        """
        # non-admin user should fail to create vm, snap, temp etc
        with self.assertRaises(Exception):
            VirtualMachine.create(
                self.userapiclient,
                self.testdata["small"],
                templateid=self.template.id,
                accountid=self.account.name,
                domainid=self.account.domainid,
                serviceofferingid=self.service_offering.id,
                zoneid=self.zone.id,
            )

        root_volume = list_volumes(self.userapiclient, virtualmachineid=vm_user.id, type="ROOT", listall=True)
        self.assertEqual(validateList(root_volume)[0], PASS, "list volume  is empty for vmid id %s" % vm_user.id)

        if self.snapshotSupported:
            with self.assertRaises(Exception):
                Snapshot.create(self.userapiclient, root_volume[0].id)

        with self.assertRaises(Exception):
            Template.register(self.userapiclient, self.testdata["privatetemplate"], zoneid=self.zone.id)

        with self.assertRaises(Exception):
            Volume.create(
                self.userapiclient,
                self.testdata["volume"],
                zoneid=self.zone.id,
                account=self.account.name,
                domainid=self.account.domainid,
                diskofferingid=self.disk_offering.id,
            )

        with self.assertRaises(Exception):
            Iso.create(
                self.userapiclient,
                self.testdata["iso2"],
                zoneid=self.zone.id,
                account=self.account.name,
                domainid=self.account.domainid,
            )

        # Step 2
        cmd.allocationstate = ENABLED
        self.apiclient.updateZone(cmd)

        # After enabling the zone all users should be able to add new VM,
        # volume, template and iso

        root_vm_new = VirtualMachine.create(
            self.apiclient,
            self.testdata["small"],
            templateid=self.template.id,
            accountid=self.admin_account.name,
            domainid=self.admin_account.domainid,
            serviceofferingid=self.service_offering.id,
            zoneid=self.zone.id,
        )

        self.assertEqual(root_vm_new.state.lower(), "running", "Verify that admin should create new VM")

        if self.snapshotSupported:
            Snapshot.create(self.apiclient, root_volume[0].id)

            snapshots = list_snapshots(self.apiclient, volumeid=root_volume[0].id, listall=True)

            self.assertEqual(
                validateList(snapshots)[0], PASS, "list snapshot  is empty for volume id %s" % root_volume[0].id
            )

            Template.create_from_snapshot(self.apiclient, snapshots[0], self.testdata["privatetemplate"])

        Template.register(self.apiclient, self.testdata["privatetemplate"], zoneid=self.zone.id)

        Volume.create(
            self.apiclient,
            self.testdata["volume"],
            zoneid=self.zone.id,
            account=self.admin_account.name,
            domainid=self.admin_account.domainid,
            diskofferingid=self.disk_offering.id,
        )

        Iso.create(
            self.apiclient,
            self.testdata["iso2"],
            zoneid=self.zone.id,
            account=self.admin_account.name,
            domainid=self.admin_account.domainid,
        )

        # Non root user
        user_vm_new = VirtualMachine.create(
            self.userapiclient,
            self.testdata["small"],
            templateid=self.template.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
            zoneid=self.zone.id,
        )

        self.assertEqual(user_vm_new.state.lower(), "running", "Verify that admin should create new VM")

        if self.snapshotSupported:
            Snapshot.create(self.userapiclient, root_volume[0].id)

            snapshots = list_snapshots(self.userapiclient, volumeid=root_volume[0].id, listall=True)

            self.assertEqual(
                validateList(snapshots)[0], PASS, "list snapshot  is empty for volume id %s" % root_volume[0].id
            )

        Template.register(self.userapiclient, self.testdata["privatetemplate"], zoneid=self.zone.id)

        Volume.create(
            self.userapiclient,
            self.testdata["volume"],
            zoneid=self.zone.id,
            account=self.account.name,
            domainid=self.account.domainid,
            diskofferingid=self.disk_offering.id,
        )
        Iso.create(
            self.userapiclient,
            self.testdata["iso2"],
            zoneid=self.zone.id,
            account=self.account.name,
            domainid=self.account.domainid,
        )

        # Step 3
        # Deletion of zone should fail if vm,volume is present on the zone
        with self.assertRaises(Exception):
            self.zone.delete(self.apiclient)

        return
Example #24
0
    def setUpClass(cls):

        testClient = super(TestTemplates, cls).getClsTestClient()
        cls.apiclient = testClient.getApiClient()
        cls._cleanup = []
        cls.services = testClient.getParsedTestDataConfig()
        cls.unsupportedHypervisor = False
        cls.hypervisor = testClient.getHypervisorInfo()
        if cls.hypervisor.lower() in ['lxc']:
            # Template creation from root volume is not supported in LXC
            cls.unsupportedHypervisor = True
            return

        # Get Zone, Domain and templates
        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
        cls.zones = Zone.list(cls.apiclient)
        if not isinstance(cls.zones, list):
            raise Exception("Failed to find zones.")

        cls.disk_offering = DiskOffering.create(cls.apiclient,
                                                cls.services["disk_offering"])
        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["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"]["ostypeid"] = template.ostypeid
        cls.services["template_2"]["ostypeid"] = template.ostypeid
        cls.services["ostypeid"] = template.ostypeid
        cls.account = Account.create(cls.apiclient,
                                     cls.services["account"],
                                     admin=True,
                                     domainid=cls.domain.id)
        cls.user = Account.create(cls.apiclient,
                                  cls.services["account"],
                                  domainid=cls.domain.id)
        cls.service_offering = ServiceOffering.create(
            cls.apiclient, cls.services["service_offerings"]["tiny"])
        #create virtual machine
        cls.virtual_machine = VirtualMachine.create(
            cls.apiclient,
            cls.services["virtual_machine"],
            templateid=template.id,
            accountid=cls.account.name,
            domainid=cls.account.domainid,
            serviceofferingid=cls.service_offering.id,
            mode=cls.services["mode"])
        #Stop virtual machine
        cls.virtual_machine.stop(cls.apiclient)

        list_volume = Volume.list(cls.apiclient,
                                  virtualmachineid=cls.virtual_machine.id,
                                  type='ROOT',
                                  listall=True)
        try:
            cls.volume = list_volume[0]
        except Exception as e:
            raise Exception(
                "Exception: Unable to find root volume foe VM: %s - %s" %
                (cls.virtual_machine.id, e))

        #Create templates for Edit, Delete & update permissions testcases
        cls.template_1 = Template.create(cls.apiclient,
                                         cls.services["template"],
                                         cls.volume.id,
                                         account=cls.account.name,
                                         domainid=cls.account.domainid)
        cls.template_2 = Template.create(cls.apiclient,
                                         cls.services["template_2"],
                                         cls.volume.id,
                                         account=cls.account.name,
                                         domainid=cls.account.domainid)
        cls._cleanup = [
            cls.service_offering, cls.disk_offering, cls.account, cls.user
        ]
    def setUpClass(cls):
        cls.testClient = super(TestUserPrivateGateways, cls).getClsTestClient()
        cls.apiclient = cls.testClient.getApiClient()
        cls.apiclient = cls.testClient.getApiClient()
        cls.services = cls.testClient.getParsedTestDataConfig()

        zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests())
        cls.zone = Zone(zone.__dict__)
        cls.template = get_template(cls.apiclient, cls.zone.id)
        cls._cleanup = []

        cls.logger = logging.getLogger("TestUserPrivateGateways")
        cls.stream_handler = logging.StreamHandler()
        cls.logger.setLevel(logging.DEBUG)
        cls.logger.addHandler(cls.stream_handler)

        cls.domain = get_domain(cls.apiclient)

        # Create small service offering
        cls.service_offering = ServiceOffering.create(
            cls.apiclient, cls.services["service_offerings"]["small"])
        cls._cleanup.append(cls.service_offering)

        # Create network offering for isolated networks
        cls.network_offering_isolated = NetworkOffering.create(
            cls.apiclient, cls.services["network_offering"])
        cls.network_offering_isolated.update(cls.apiclient, state='Enabled')
        cls._cleanup.append(cls.network_offering_isolated)

        # Create vpc offering
        cls.vpc_offering = VpcOffering.create(
            cls.apiclient, cls.services["vpc_offering_multi_lb"])
        cls.vpc_offering.update(cls.apiclient, state='Enabled')
        cls._cleanup.append(cls.vpc_offering)

        # Create network offering for vpc tiers
        cls.network_offering_vpc = NetworkOffering.create(
            cls.apiclient,
            cls.services["nw_offering_isolated_vpc"],
            conservemode=False)
        cls.network_offering_vpc.update(cls.apiclient, state='Enabled')
        cls._cleanup.append(cls.network_offering_vpc)

        # Create sub-domain
        cls.sub_domain = Domain.create(cls.apiclient,
                                       cls.services["acl"]["domain1"])
        cls._cleanup.append(cls.sub_domain)

        # Create domain admin and normal user
        cls.domain_admin = Account.create(cls.apiclient,
                                          cls.services["acl"]["accountD1A"],
                                          admin=True,
                                          domainid=cls.sub_domain.id)
        cls._cleanup.append(cls.domain_admin)

        cls.normal_user = Account.create(cls.apiclient,
                                         cls.services["acl"]["accountD1B"],
                                         domainid=cls.sub_domain.id)
        cls._cleanup.append(cls.normal_user)

        # Create project
        cls.project = Project.create(cls.apiclient,
                                     cls.services["project"],
                                     account=cls.domain_admin.name,
                                     domainid=cls.domain_admin.domainid)
        cls._cleanup.append(cls.project)

        # Create api clients for domain admin and normal user
        cls.domainadmin_user = cls.domain_admin.user[0]
        cls.domainapiclient = cls.testClient.getUserApiClient(
            cls.domainadmin_user.username, cls.sub_domain.name)
        cls.normaluser_user = cls.normal_user.user[0]
        cls.normaluser_apiclient = cls.testClient.getUserApiClient(
            cls.normaluser_user.username, cls.sub_domain.name)
    def setUpClass(cls):
        cls.testClient = super(TestMulipleNicSupport, cls).getClsTestClient()
        cls.apiclient = cls.testClient.getApiClient()
        cls.testdata = cls.testClient.getParsedTestDataConfig()
        cls.services = cls.testClient.getParsedTestDataConfig()
        zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests())
        cls.zone = Zone(zone.__dict__)
        cls._cleanup = []

        cls.skip = False
        if str(cls.zone.securitygroupsenabled) != "True":
            cls.skip = True
            return

        cls.logger = logging.getLogger("TestMulipleNicSupport")
        cls.stream_handler = logging.StreamHandler()
        cls.logger.setLevel(logging.DEBUG)
        cls.logger.addHandler(cls.stream_handler)

        # Get Domain and templates
        cls.domain = get_domain(cls.apiclient)
        cls.services['mode'] = cls.zone.networktype

        cls.template = get_template(cls.apiclient,
                                    cls.zone.id,
                                    hypervisor="KVM")
        if cls.template == FAILED:
            cls.skip = True
            return

        # Create new domain, account, network and VM
        cls.user_domain = Domain.create(
            cls.apiclient,
            services=cls.testdata["acl"]["domain2"],
            parentdomainid=cls.domain.id)

        # Create account
        cls.account1 = Account.create(cls.apiclient,
                                      cls.testdata["acl"]["accountD2"],
                                      admin=True,
                                      domainid=cls.user_domain.id)

        # Create small service offering
        cls.service_offering = ServiceOffering.create(
            cls.apiclient, cls.testdata["service_offerings"]["small"])

        cls._cleanup.append(cls.service_offering)
        cls.services["network"]["zoneid"] = cls.zone.id
        cls.network_offering = NetworkOffering.create(
            cls.apiclient,
            cls.services["network_offering"],
        )
        # Enable Network offering
        cls.network_offering.update(cls.apiclient, state='Enabled')

        cls._cleanup.append(cls.network_offering)
        cls.testdata["virtual_machine"]["zoneid"] = cls.zone.id
        cls.testdata["virtual_machine"]["template"] = cls.template.id

        if cls.zone.securitygroupsenabled:
            # Enable networking for reaching to VM thorugh SSH
            security_group = SecurityGroup.create(
                cls.apiclient,
                cls.testdata["security_group"],
                account=cls.account1.name,
                domainid=cls.account1.domainid)

            # Authorize Security group to SSH to VM
            ingress_rule = security_group.authorize(
                cls.apiclient,
                cls.testdata["ingress_rule"],
                account=cls.account1.name,
                domainid=cls.account1.domainid)

            # Authorize Security group to SSH to VM
            ingress_rule2 = security_group.authorize(
                cls.apiclient,
                cls.testdata["ingress_rule_ICMP"],
                account=cls.account1.name,
                domainid=cls.account1.domainid)

        cls.testdata["shared_network_offering_sg"]["specifyVlan"] = 'True'
        cls.testdata["shared_network_offering_sg"]["specifyIpRanges"] = 'True'
        cls.shared_network_offering = NetworkOffering.create(
            cls.apiclient,
            cls.testdata["shared_network_offering_sg"],
            conservemode=False)

        NetworkOffering.update(cls.shared_network_offering,
                               cls.apiclient,
                               id=cls.shared_network_offering.id,
                               state="enabled")

        physical_network, vlan = get_free_vlan(cls.apiclient, cls.zone.id)
        cls.testdata["shared_network_sg"][
            "physicalnetworkid"] = physical_network.id

        random_subnet_number = random.randrange(90, 99)
        cls.testdata["shared_network_sg"][
            "name"] = "Shared-Network-SG-Test-vlan" + str(random_subnet_number)
        cls.testdata["shared_network_sg"][
            "displaytext"] = "Shared-Network-SG-Test-vlan" + str(
                random_subnet_number)
        cls.testdata["shared_network_sg"]["vlan"] = "vlan://" + str(
            random_subnet_number)
        cls.testdata["shared_network_sg"]["startip"] = "192.168." + str(
            random_subnet_number) + ".240"
        cls.testdata["shared_network_sg"]["endip"] = "192.168." + str(
            random_subnet_number) + ".250"
        cls.testdata["shared_network_sg"]["gateway"] = "192.168." + str(
            random_subnet_number) + ".254"
        cls.network1 = Network.create(
            cls.apiclient,
            cls.testdata["shared_network_sg"],
            networkofferingid=cls.shared_network_offering.id,
            zoneid=cls.zone.id,
            accountid=cls.account1.name,
            domainid=cls.account1.domainid)

        random_subnet_number = random.randrange(100, 110)
        cls.testdata["shared_network_sg"][
            "name"] = "Shared-Network-SG-Test-vlan" + str(random_subnet_number)
        cls.testdata["shared_network_sg"][
            "displaytext"] = "Shared-Network-SG-Test-vlan" + str(
                random_subnet_number)
        cls.testdata["shared_network_sg"]["vlan"] = "vlan://" + str(
            random_subnet_number)
        cls.testdata["shared_network_sg"]["startip"] = "192.168." + str(
            random_subnet_number) + ".240"
        cls.testdata["shared_network_sg"]["endip"] = "192.168." + str(
            random_subnet_number) + ".250"
        cls.testdata["shared_network_sg"]["gateway"] = "192.168." + str(
            random_subnet_number) + ".254"
        cls.network2 = Network.create(
            cls.apiclient,
            cls.testdata["shared_network_sg"],
            networkofferingid=cls.shared_network_offering.id,
            zoneid=cls.zone.id,
            accountid=cls.account1.name,
            domainid=cls.account1.domainid)

        random_subnet_number = random.randrange(111, 120)
        cls.testdata["shared_network_sg"][
            "name"] = "Shared-Network-SG-Test-vlan" + str(random_subnet_number)
        cls.testdata["shared_network_sg"][
            "displaytext"] = "Shared-Network-SG-Test-vlan" + str(
                random_subnet_number)
        cls.testdata["shared_network_sg"]["vlan"] = "vlan://" + str(
            random_subnet_number)
        cls.testdata["shared_network_sg"]["startip"] = "192.168." + str(
            random_subnet_number) + ".240"
        cls.testdata["shared_network_sg"]["endip"] = "192.168." + str(
            random_subnet_number) + ".250"
        cls.testdata["shared_network_sg"]["gateway"] = "192.168." + str(
            random_subnet_number) + ".254"
        cls.network3 = Network.create(
            cls.apiclient,
            cls.testdata["shared_network_sg"],
            networkofferingid=cls.shared_network_offering.id,
            zoneid=cls.zone.id,
            accountid=cls.account1.name,
            domainid=cls.account1.domainid)

        try:
            cls.virtual_machine1 = VirtualMachine.create(
                cls.apiclient,
                cls.testdata["virtual_machine"],
                accountid=cls.account1.name,
                domainid=cls.account1.domainid,
                serviceofferingid=cls.service_offering.id,
                templateid=cls.template.id,
                securitygroupids=[security_group.id],
                networkids=cls.network1.id)
            for nic in cls.virtual_machine1.nic:
                if nic.isdefault:
                    cls.virtual_machine1.ssh_ip = nic.ipaddress
                    cls.virtual_machine1.default_network_id = nic.networkid
                    break
        except Exception as e:
            cls.fail("Exception while deploying virtual machine: %s" % e)

        try:
            cls.virtual_machine2 = VirtualMachine.create(
                cls.apiclient,
                cls.testdata["virtual_machine"],
                accountid=cls.account1.name,
                domainid=cls.account1.domainid,
                serviceofferingid=cls.service_offering.id,
                templateid=cls.template.id,
                securitygroupids=[security_group.id],
                networkids=[str(cls.network1.id),
                            str(cls.network2.id)])
            for nic in cls.virtual_machine2.nic:
                if nic.isdefault:
                    cls.virtual_machine2.ssh_ip = nic.ipaddress
                    cls.virtual_machine2.default_network_id = nic.networkid
                    break
        except Exception as e:
            cls.fail("Exception while deploying virtual machine: %s" % e)

        cls._cleanup.append(cls.virtual_machine1)
        cls._cleanup.append(cls.virtual_machine2)
        cls._cleanup.append(cls.network1)
        cls._cleanup.append(cls.network2)
        cls._cleanup.append(cls.network3)
        cls._cleanup.append(cls.shared_network_offering)
        if cls.zone.securitygroupsenabled:
            cls._cleanup.append(security_group)
        cls._cleanup.append(cls.account1)
        cls._cleanup.append(cls.user_domain)
    def test_01_disable_enable_zone(self):
        """disable enable zone
            1. Disable zone and verify following things:
                For admin user:
                    1. Should be create to start/stop exsiting vms
                    2. Should be create to deploy new vm, snapshot,volume,
                       template,iso in the same zone
                For Non-admin user:
                    1. Should be create to start/stop exsiting vms
                    2. Should not be create to deploy new vm, snapshot,volume,
                       template,iso in the same zone
            2. Enable the above disabled zone and verify that:
                -All users should be create to deploy new vm,
                    snapshot,volume,template,iso in the same zone
            3. Try to delete the zone and it should fail with error message:
                -"The zone is not deletable because there are
                    servers running in this zone"
        """
        # Step 1
        vm_user = VirtualMachine.create(
            self.userapiclient,
            self.testdata["small"],
            templateid=self.template.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
            zoneid=self.zone.id
        )

        vm_root = VirtualMachine.create(
            self.apiclient,
            self.testdata["small"],
            templateid=self.template.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
            zoneid=self.zone.id
        )

        cmd = updateZone.updateZoneCmd()
        cmd.id = self.zone.id
        cmd.allocationstate = DISABLED
        self.apiclient.updateZone(cmd)
        zoneList = Zone.list(self.apiclient, id=self.zone.id)

        self.assertEqual(zoneList[0].allocationstate,
                         DISABLED,
                         "Check if the zone is in disabled state"
                         )

        # Both user and admin vms shoul be running
        self.assertEqual(vm_user.state,
                         RUNNING,
                         "Verify that the user vm is running")

        self.assertEqual(vm_root.state,
                         RUNNING,
                         "Verify that the admin vm is running")

        vm_root.stop(self.apiclient)
        vm_user.stop(self.apiclient)

        root_state = self.dbclient.execute(
            "select state from vm_instance where name='%s'" %
            vm_root.name)[0][0]

        user_state = self.dbclient.execute(
            "select state from vm_instance where name='%s'" %
            vm_user.name)[0][0]

        self.assertEqual(root_state,
                         STOPPED,
                         "verify that vm is Stopped")

        self.assertEqual(user_state,
                         STOPPED,
                         "verify that vm is stopped")

        root_volume = list_volumes(
            self.userapiclient,
            virtualmachineid=vm_root.id,
            type='ROOT',
            listall=True
        )

        snap = Snapshot.create(
            self.apiclient,
            root_volume[0].id)

        self.assertNotEqual(snap,
                            None,
                            "Verify that admin should be \
                                    able to create snapshot")

        snapshots = list_snapshots(
            self.apiclient,
            volumeid=root_volume[0].id,
            listall=True)

        template_from_snapshot = Template.create_from_snapshot(
            self.apiclient,
            snapshots[0],
            self.testdata["privatetemplate"])

        self.assertNotEqual(
            template_from_snapshot,
            None,
            "Verify that admin should be able to create template"
        )

        builtin_info = get_builtin_template_info(self.apiclient, self.zone.id)
        self.testdata["privatetemplate"]["url"] = builtin_info[0]
        self.testdata["privatetemplate"]["hypervisor"] = builtin_info[1]
        self.testdata["privatetemplate"]["format"] = builtin_info[2]

        template_regis = Template.register(
            self.apiclient,
            self.testdata["privatetemplate"],
            zoneid=self.zone.id)

        self.assertNotEqual(
            template_regis,
            None,
            "Check if template gets created"
        )
        self.assertNotEqual(
            template_from_snapshot,
            None,
            "Check if template gets created"
        )

        data_volume = Volume.create(
            self.apiclient,
            self.testdata["volume"],
            zoneid=self.zone.id,
            account=self.account.name,
            domainid=self.account.domainid,
            diskofferingid=self.disk_offering.id
        )
        self.assertNotEqual(
            data_volume,
            None,
            "Check if volume gets created"
        )

        ISO = Iso.create(
            self.apiclient,
            self.testdata["iso2"],
            zoneid=self.zone.id,
            account=self.account.name,
            domainid=self.account.domainid,
        )

        self.assertNotEqual(
            ISO,
            None,
            "Check if volume gets created"
        )
        # non-admin user should fail to create vm, snap, temp etc
        with self.assertRaises(Exception):
            VirtualMachine.create(self.userapiclient,
                                  self.testdata["small"],
                                  templateid=self.template.id,
                                  accountid=self.account.name,
                                  domainid=self.account.domainid,
                                  serviceofferingid=self.service_offering.id,
                                  zoneid=self.zone.id
                                  )

        root_volume = list_volumes(
            self.userapiclient,
            virtualmachineid=vm_user.id,
            type='ROOT',
            listall=True
        )

        with self.assertRaises(Exception):
            snap = Snapshot.create(
                self.userapiclient,
                root_volume[0].id)

        with self.assertRaises(Exception):
            Template.register(
                self.userapiclient,
                self.testdata["privatetemplate"],
                zoneid=self.zone.id)

        with self.assertRaises(Exception):
            Volume.create(
                self.userapiclient,
                self.testdata["volume"],
                zoneid=self.zone.id,
                account=self.account.name,
                domainid=self.account.domainid,
                diskofferingid=self.disk_offering.id
            )

        with self.assertRaises(Exception):
            ISO = Iso.create(
                self.userapiclient,
                self.testdata["iso2"],
                zoneid=self.zone.id,
                account=self.account.name,
                domainid=self.account.domainid,
            )

        # Step 2
        cmd.allocationstate = ENABLED
        self.apiclient.updateZone(cmd)

        # After enabling the zone all users should be able to add new VM,
        # volume, template and iso

        root_vm_new = VirtualMachine.create(
            self.apiclient,
            self.testdata["small"],
            templateid=self.template.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
            zoneid=self.zone.id
        )

        self.assertNotEqual(root_vm_new,
                            None,
                            "Verify that admin should create new VM")

        snap = Snapshot.create(
            self.apiclient,
            root_volume[0].id)

        self.assertNotEqual(snap,
                            None,
                            "Verify that admin should snashot")

        snapshots = list_snapshots(
            self.apiclient,
            volumeid=root_volume[0].id,
            listall=True)

        template_from_snapshot = Template.create_from_snapshot(
            self.apiclient,
            snapshots[0],
            self.testdata["privatetemplate"])

        self.assertNotEqual(
            template_from_snapshot,
            None,
            "Check if template gets created"
        )

        template_regis = Template.register(
            self.apiclient,
            self.testdata["privatetemplate"],
            zoneid=self.zone.id)

        self.assertNotEqual(
            template_regis,
            None,
            "Check if template gets created"
        )
        self.assertNotEqual(
            template_from_snapshot,
            None,
            "Check if template gets created"
        )

        data_volume = Volume.create(
            self.apiclient,
            self.testdata["volume"],
            zoneid=self.zone.id,
            account=self.account.name,
            domainid=self.account.domainid,
            diskofferingid=self.disk_offering.id
        )
        self.assertNotEqual(
            data_volume,
            None,
            "Check if volume gets created"
        )

        ISO = Iso.create(
            self.apiclient,
            self.testdata["iso2"],
            zoneid=self.zone.id,
            account=self.account.name,
            domainid=self.account.domainid,
        )

        self.assertNotEqual(
            ISO,
            None,
            "Check if volume gets created"
        )
        root_vm_new.delete(self.apiclient)
        # Non root user
        user_vm_new = VirtualMachine.create(
            self.userapiclient,
            self.testdata["small"],
            templateid=self.template.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
            zoneid=self.zone.id
        )

        self.assertNotEqual(user_vm_new,
                            None,
                            "Verify that admin should create new VM")

        snap = Snapshot.create(
            self.userapiclient,
            root_volume[0].id)

        self.assertNotEqual(snap,
                            None,
                            "Verify that admin should snashot")

        snapshots = list_snapshots(
            self.userapiclient,
            volumeid=root_volume[0].id,
            listall=True)

        template_regis = Template.register(
            self.userapiclient,
            self.testdata["privatetemplate"],
            zoneid=self.zone.id)

        self.assertNotEqual(
            template_regis,
            None,
            "Check if template gets created"
        )
        self.assertNotEqual(
            template_from_snapshot,
            None,
            "Check if template gets created"
        )

        data_volume = Volume.create(
            self.userapiclient,
            self.testdata["volume"],
            zoneid=self.zone.id,
            account=self.account.name,
            domainid=self.account.domainid,
            diskofferingid=self.disk_offering.id
        )
        self.assertNotEqual(
            data_volume,
            None,
            "Check if volume gets created"
        )

        ISO = Iso.create(
            self.userapiclient,
            self.testdata["iso2"],
            zoneid=self.zone.id,
            account=self.account.name,
            domainid=self.account.domainid,
        )

        self.assertNotEqual(
            ISO,
            None,
            "Check if volume gets created"
        )
        user_vm_new.delete(self.apiclient)

        # Step 3
        # Deletion of zone should fail if vm,volume is present on the zone
        with self.assertRaises(Exception):
            self.zone.delete(self.apiclient)

        return