Ejemplo n.º 1
0
    def test_02_create_vpc_wait_gc(self):
        """ Test VPC when host is in maintenance mode and wait till nw gc
        """

        # Validate the following
        # 1. Put the host in maintenance mode.
        # 2. Attempt to Create a VPC with cidr - 10.1.1.1/16
        # 3. Wait for the VPC GC thread to run.
        # 3. VPC will be created but will be in "Disabled" state and should
        #    get deleted

        self.debug("creating a VPC network in the account: %s" %
                   self.account.name)
        self.services["vpc"]["cidr"] = '10.1.1.1/16'
        vpc = VPC.create(self.apiclient,
                         self.services["vpc"],
                         vpcofferingid=self.vpc_off.id,
                         zoneid=self.zone.id,
                         account=self.account.name,
                         domainid=self.account.domainid,
                         start=False)
        self.validate_vpc_network(vpc, state='inactive')
        interval = list_configurations(self.apiclient,
                                       name='network.gc.interval')
        wait = list_configurations(self.apiclient, name='network.gc.wait')
        self.debug("Sleep till network gc thread runs..")
        # Sleep to ensure that all resources are deleted
        time.sleep(int(interval[0].value) + int(wait[0].value))
        vpcs = VPC.list(self.apiclient, id=vpc.id, listall=True)
        self.assertEqual(
            vpcs, None, "List VPC should not return anything after network gc")
        return
Ejemplo n.º 2
0
    def test_07_snapshot_to_template_bypass_secondary(self):
        ''' Create template from snapshot bypassing secondary storage
        '''
        ##cls.virtual_machine
        volume = list_volumes(self.apiclient,
                              virtualmachineid=self.virtual_machine.id)
        snapshot = Snapshot.create(self.apiclient, volume_id=volume[0].id)

        backup_config = list_configurations(self.apiclient,
                                            name="sp.bypass.secondary.storage")
        if (backup_config[0].value == "false"):
            backup_config = Configurations.update(
                self.apiclient,
                name="sp.bypass.secondary.storage",
                value="true")
        self.assertIsNotNone(snapshot, "Could not create snapshot")
        self.assertIsInstance(snapshot, Snapshot,
                              "Snapshot is not an instance of Snapshot")

        template = self.create_template_from_snapshot(self.apiclient,
                                                      self.services,
                                                      snapshotid=snapshot.id)
        virtual_machine = VirtualMachine.create(
            self.apiclient, {"name": "StorPool-%d" % random.randint(0, 100)},
            zoneid=self.zone.id,
            templateid=template.id,
            serviceofferingid=self.service_offering.id,
            hypervisor=self.hypervisor,
            rootdisksize=10)
        ssh_client = virtual_machine.get_ssh_client()
        self.assertIsNotNone(template, "Template is None")
        self.assertIsInstance(template, Template,
                              "Template is instance of template")
        self._cleanup.append(snapshot)
        self._cleanup.append(template)
    def test_02_create_vpc_wait_gc(self):
        """ Test VPC when host is in maintenance mode and wait till nw gc
        """

        # Validate the following
        # 1. Put the host in maintenance mode.
        # 2. Attempt to Create a VPC with cidr - 10.1.1.1/16
        # 3. Wait for the VPC GC thread to run.
        # 3. VPC will be created but will be in "Disabled" state and should
        #    get deleted

        self.debug("creating a VPC network in the account: %s" %
                   self.account.name)
        self.services["vpc"]["cidr"] = '10.1.1.1/16'
        vpc = VPC.create(
            self.apiclient,
            self.services["vpc"],
            vpcofferingid=self.vpc_off.id,
            zoneid=self.zone.id,
            account=self.account.name,
            domainid=self.account.domainid,
            start=False
        )
        self.validate_vpc_network(vpc, state='inactive')
        interval = list_configurations(
            self.apiclient,
            name='network.gc.interval'
        )
        wait = list_configurations(
            self.apiclient,
            name='network.gc.wait'
        )
        self.debug("Sleep till network gc thread runs..")
        # Sleep to ensure that all resources are deleted
        time.sleep(int(interval[0].value) + int(wait[0].value))
        vpcs = VPC.list(
            self.apiclient,
            id=vpc.id,
            listall=True
        )
        self.assertEqual(
            vpcs,
            None,
            "List VPC should not return anything after network gc"
        )
        return
Ejemplo n.º 4
0
 def tearDown(self):
     try:
         # Clean up, terminate the created network offerings
         cleanup_resources(self.apiclient, self.cleanup)
         self.account.delete(self.apiclient)
         interval = list_configurations(self.apiclient, name="account.cleanup.interval")
         # Sleep to ensure that all resources are deleted
         time.sleep(int(interval[0].value) * 2)
     except Exception as e:
         raise Exception("Warning: Exception during cleanup : %s" % e)
     return
Ejemplo n.º 5
0
 def get_remote_cluster(cls, apiclient, zoneid):
     storpool_clusterid = subprocess.check_output(
         ['storpool_confshow', 'CLUSTER_ID'])
     clusterid = storpool_clusterid.split("=")
     logging.debug(storpool_clusterid)
     clusters = list_clusters(apiclient, zoneid=zoneid)
     for c in clusters:
         configuration = list_configurations(apiclient, clusterid=c.id)
         for conf in configuration:
             if conf.name == 'sp.cluster.id' and (conf.value
                                                  not in clusterid[1]):
                 return c
Ejemplo n.º 6
0
 def bypass_secondary(cls, bypassed):
     if bypassed:
         backup_config = Configurations.update(cls.testClass.apiclient,
         name = "sp.bypass.secondary.storage",
         value = "true")
     else:
         backup_config = Configurations.update(cls.testClass.apiclient,
         name = "sp.bypass.secondary.storage",
         value = "false")
     cfg.logger.info(list_configurations(
         cls.testClass.apiclient,
         name = "sp.bypass.secondary.storage"))
Ejemplo n.º 7
0
 def get_local_cluster(self):
    storpool_clusterid = subprocess.check_output(['storpool_confshow', 'CLUSTER_ID'])
    clusterid = storpool_clusterid.split("=")
    clusters = list_clusters(self.testClass.apiclient)
    for c in clusters:
        configuration = list_configurations(
            self.testClass.apiclient,
            clusterid = c.id
            )
        for conf in configuration:
            if conf.name == 'sp.cluster.id'  and (conf.value in clusterid[1]):
                return c
Ejemplo n.º 8
0
 def tearDown(self):
     try:
         # Clean up, terminate the created network offerings
         cleanup_resources(self.apiclient, self.cleanup)
         self.account.delete(self.apiclient)
         interval = list_configurations(self.apiclient,
                                        name='account.cleanup.interval')
         # Sleep to ensure that all resources are deleted
         time.sleep(int(interval[0].value) * 2)
     except Exception as e:
         raise Exception("Warning: Exception during cleanup : %s" % e)
     return
Ejemplo n.º 9
0
    def test_delete_account(self):
        """Test for delete account"""

        # Validate the Following
        # 1. after account.cleanup.interval (global setting)
        #    time all the PF/LB rules should be deleted
        # 2. verify that list(LoadBalancer/PortForwarding)Rules
        #    API does not return any rules for the account
        # 3. The domR should have been expunged for this account

        self.account.delete(self.apiclient)
        interval = list_configurations(self.apiclient,
                                       name='account.cleanup.interval')
        self.assertEqual(isinstance(interval, list), True,
                         "Check if account.cleanup.interval config present")
        # Sleep to ensure that all resources are deleted
        time.sleep(int(interval[0].value))

        # ListLoadBalancerRules should not list
        # associated rules with deleted account
        # Unable to find account testuser1 in domain 1 : Exception
        try:
            list_lb_rules(self.apiclient,
                          account=self.account.name,
                          domainid=self.account.domainid)
        except CloudstackAPIException:
            self.debug("Port Forwarding Rule is deleted")

        # ListPortForwardingRules should not
        # list associated rules with deleted account
        try:
            list_nat_rules(self.apiclient,
                           account=self.account.name,
                           domainid=self.account.domainid)
        except CloudstackAPIException:
            self.debug("NATRule is deleted")

        # Retrieve router for the user account
        try:
            routers = list_routers(self.apiclient,
                                   account=self.account.name,
                                   domainid=self.account.domainid)
            self.assertEqual(routers, None,
                             "Check routers are properly deleted.")
        except CloudstackAPIException:
            self.debug("Router is deleted")

        except Exception as e:
            raise Exception(
                "Encountered %s raised while fetching routers for account: %s"
                % (e, self.account.name))
        return
    def test_06_snapshot_to_template_secondary_storage(self):
        ''' Create template from snapshot
        '''
        volume = Volume.list(self.apiclient,
                             virtualmachineid=self.virtual_machine.id,
                             type="ROOT",
                             listall=True)
        volume = volume[0]

        backup_config = list_configurations(self.apiclient,
                                            name="sp.bypass.secondary.storage")
        if (backup_config[0].value == "true"):
            backup_config = Configurations.update(
                self.apiclient,
                name="sp.bypass.secondary.storage",
                value="false")
        snapshot = Snapshot.create(self.apiclient,
                                   volume_id=volume.id,
                                   account=self.account.name,
                                   domainid=self.account.domainid)
        self.assertIsNotNone(snapshot, "Could not create snapshot")
        self.assertIsInstance(snapshot, Snapshot,
                              "Snapshot is not an instance of Snapshot")

        template = self.helper.create_template_from_snapshot(
            self.apiclient, self.services, snapshotid=snapshot.id)

        virtual_machine = VirtualMachine.create(
            self.apiclient, {"name": "StorPool-%s" % uuid.uuid4()},
            zoneid=self.zone.id,
            templateid=template.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
            hypervisor=self.hypervisor,
            rootdisksize=10)

        self.assertIsNotNone(template, "Template is None")
        self.assertIsInstance(template, Template,
                              "Template is instance of template")
        ssh_client = virtual_machine.get_ssh_client(reconnect=True)

        self._cleanup.append(template)
Ejemplo n.º 11
0
    def test_02_NetworkGarbageCollection(self):
        """Test network garbage collection
        """
        # Validate the following
        # 1. wait for router to start and guest network to be created
        #    a.listRouters account=user, domainid=1 (router state=Running)
        #    b.listNetworks account=user domainid=1 (network state=Implemented)
        #    c.listVirtualMachines account=user domainid=1 (VM states=Running)
        # 4. stopVirtualMachines (stop all VMs in this account)
        # 5. wait for VMs to stop-listVirtualMachines account=user, domainid=1
        #    (Both VM states = Stopped)
        # 6. wait for network.gc.interval*2 seconds (600s)
        # 7. listRouters account=user, domainid=1

        routers = list_routers(
            self.apiclient,
            account=self.account.name,
            domainid=self.account.domainid,
        )

        self.assertEqual(isinstance(routers, list), True,
                         "Check for list routers response return valid data")
        self.assertNotEqual(len(routers), 0, "Check list router response")
        # Router associated with account should be in running state
        timeout = 180
        router = routers[0]
        self.debug("Router ID: %s & Router state: %s" %
                   (router.id, router.state))
        self.debug("Wait for %s secs max for router to reach Running state" %
                   timeout)
        while timeout:
            time.sleep(60)
            routers = list_routers(self.apiclient,
                                   account=self.account.name,
                                   domainid=self.account.domainid,
                                   id=router.id)
            router = routers[0]
            if router.state == 'Running':
                break

            timeout = timeout - 60
            if timeout == 0:
                self.assertEqual(router.state, 'Running',
                                 "Router not in Running state")

        # Network state associated with account should be 'Implemented'
        networks = list_networks(self.apiclient,
                                 account=self.account.name,
                                 domainid=self.account.domainid,
                                 type='Isolated')
        self.assertEqual(isinstance(networks, list), True,
                         "Check for list networks response return valid data")
        self.assertNotEqual(len(networks), 0, "Check list networks response")
        # Check if network in 'Implemented' state
        for network in networks:
            self.debug("Network ID: %s & Network state: %s" %
                       (network.id, network.state))
            self.assertIn(network.state, ['Implemented', 'Allocated'],
                          "Check list network response for network state")

        # VM state associated with account should be 'Running'
        virtual_machines = list_virtual_machines(
            self.apiclient,
            account=self.account.name,
            domainid=self.account.domainid,
        )

        self.assertEqual(
            isinstance(virtual_machines, list), True,
            "Check for list virtual machines response return valid data")
        self.assertNotEqual(len(virtual_machines), 0,
                            "Check list virtual machines response")
        for virtual_machine in virtual_machines:
            self.debug("VM ID: %s & VM state: %s" %
                       (virtual_machine.id, virtual_machine.state))
            self.assertEqual(virtual_machine.state, 'Running',
                             "Check list VM response for Running state")

            # Stop virtual machine
            cmd = stopVirtualMachine.stopVirtualMachineCmd()
            cmd.id = virtual_machine.id
            self.apiclient.stopVirtualMachine(cmd)

        gcinterval = list_configurations(self.apiclient,
                                         name='network.gc.interval')
        self.assertEqual(
            isinstance(gcinterval, list), True,
            "Check for list intervals response return valid data")
        self.debug("network.gc.interval: %s" % gcinterval[0].value)

        gcwait = list_configurations(self.apiclient, name='network.gc.wait')
        self.assertEqual(
            isinstance(gcwait, list), True,
            "Check for list intervals response return valid data")
        self.debug("network.gc.wait: %s" % gcwait[0].value)

        total_wait = int(gcinterval[0].value) + int(gcwait[0].value)
        # Router is stopped after (network.gc.interval *2) time. Wait for
        # (network.gc.interval+network.gc.wait) * 2 for moving
        # router to 'Stopped'
        time.sleep(total_wait * 2)

        routers = list_routers(
            self.apiclient,
            account=self.account.name,
            domainid=self.account.domainid,
        )

        self.assertEqual(isinstance(routers, list), True,
                         "Check for list routers response return valid data")
        self.assertNotEqual(len(routers), 0, "Check list router response")
        for router in routers:
            self.debug("Router ID: %s & Router state: %s" %
                       (router.id, router.state))
            self.assertEqual(router.state, 'Stopped',
                             "Check list router response for router state")

        # Cleanup Vm_2 - Not required for further tests
        self.cleanup.append(self.vm_2)
        return
Ejemplo n.º 12
0
    def test_delete_account(self):
        """Test for delete account"""

        # Validate the Following
        # 1. after account.cleanup.interval (global setting)
        #    time all the PF/LB rules should be deleted
        # 2. verify that list(LoadBalancer/PortForwarding)Rules
        #    API does not return any rules for the account
        # 3. The domR should have been expunged for this account

        self.account.delete(self.apiclient)
        interval = list_configurations(
            self.apiclient,
            name='account.cleanup.interval'
        )
        self.assertEqual(
            isinstance(interval, list),
            True,
            "Check if account.cleanup.interval config present"
        )
        # Sleep to ensure that all resources are deleted
        time.sleep(int(interval[0].value))

        # ListLoadBalancerRules should not list
        # associated rules with deleted account
        # Unable to find account testuser1 in domain 1 : Exception
        try:
            list_lb_rules(
                self.apiclient,
                account=self.account.name,
                domainid=self.account.domainid
            )
        except CloudstackAPIException:
            self.debug("Port Forwarding Rule is deleted")

        # ListPortForwardingRules should not
        # list associated rules with deleted account
        try:
            list_nat_rules(
                self.apiclient,
                account=self.account.name,
                domainid=self.account.domainid
            )
        except CloudstackAPIException:
            self.debug("NATRule is deleted")

        # Retrieve router for the user account
        try:
            routers = list_routers(
                self.apiclient,
                account=self.account.name,
                domainid=self.account.domainid
            )
            self.assertEqual(
                routers,
                None,
                "Check routers are properly deleted."
            )
        except CloudstackAPIException:
            self.debug("Router is deleted")

        except Exception as e:
            raise Exception(
                "Encountered %s raised while fetching routers for account: %s" %
                (e, self.account.name))
        return
Ejemplo n.º 13
0
    def setUpClass(cls):
        cls.testClient = super(TestResizeVolume, cls).getClsTestClient()
        cls.api_client = cls.testClient.getApiClient()
        cls.hypervisor = (cls.testClient.getHypervisorInfo()).lower()
        cls.storageID = None
        # Fill services from the external config file
        cls.services = cls.testClient.getParsedTestDataConfig()
        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.api_client)
        cls.zone = get_zone(
            cls.api_client,
            cls.testClient.getZoneForTests())
        cls.services["mode"] = cls.zone.networktype
        cls._cleanup = []
        cls.unsupportedStorageType = False
        cls.unsupportedHypervisorType = False
        cls.updateclone = False
        if cls.hypervisor not in ['xenserver',"kvm","vmware"]:
            cls.unsupportedHypervisorType=True
            return
        cls.template = get_template(
            cls.api_client,
            cls.zone.id
        )
        cls.services["virtual_machine"]["zoneid"] = cls.zone.id
        cls.services["virtual_machine"]["template"] = cls.template.id
        cls.services["volume"]["zoneid"] = cls.zone.id
        try:
            cls.parent_domain = Domain.create(cls.api_client,
                                              services=cls.services[
                                                  "domain"],
                                              parentdomainid=cls.domain.id)
            cls.parentd_admin = Account.create(cls.api_client,
                                               cls.services["account"],
                                               admin=True,
                                               domainid=cls.parent_domain.id)
            cls._cleanup.append(cls.parentd_admin)
            cls._cleanup.append(cls.parent_domain)
            list_pool_resp = list_storage_pools(cls.api_client,
                                               account=cls.parentd_admin.name,domainid=cls.parent_domain.id)
            res = validateList(list_pool_resp)
            if res[2]== INVALID_INPUT:
                raise Exception("Failed to  list storage pool-no storagepools found ")
            #Identify the storage pool type  and set vmware fullclone to true if storage is VMFS
            if cls.hypervisor == 'vmware':
                for strpool in list_pool_resp:
                    if strpool.type.lower() == "vmfs" or strpool.type.lower()== "networkfilesystem":
                        list_config_storage_response = list_configurations(
                            cls.api_client
                            , name=
                            "vmware.create.full.clone",storageid=strpool.id)
                        res = validateList(list_config_storage_response)
                        if res[2]== INVALID_INPUT:
                         raise Exception("Failed to  list configurations ")
                        if list_config_storage_response[0].value == "false":
                            Configurations.update(cls.api_client,
                                                  "vmware.create.full.clone",
                                                  value="true",storageid=strpool.id)
                            cls.updateclone = True
                            StoragePool.update(cls.api_client,id=strpool.id,tags="scsi")
                            cls.storageID = strpool.id
                            cls.unsupportedStorageType = False
                            break
                    else:
                        cls.unsupportedStorageType = True
            # Creating service offering with normal config
            cls.service_offering = ServiceOffering.create(
                cls.api_client,
                cls.services["service_offering"])
            cls.services_offering_vmware=ServiceOffering.create(
                cls.api_client,cls.services["service_offering"],tags="scsi")
            cls._cleanup.extend([cls.service_offering,cls.services_offering_vmware])

        except Exception as e:
            cls.tearDownClass()
        return
Ejemplo n.º 14
0
    def setUpClass(cls):
        cls.cloudstacktestclient = super(TestDeployVmRootSize,
                                         cls).getClsTestClient()
        cls.api_client = cls.cloudstacktestclient.getApiClient()
        cls.hypervisor = cls.cloudstacktestclient.getHypervisorInfo().lower()
        cls.mgtSvrDetails = cls.config.__dict__["mgtSvr"][0].__dict__

        # Get Zone, Domain and Default Built-in template
        cls.domain = get_domain(cls.api_client)
        cls.zone = get_zone(cls.api_client,
                            cls.cloudstacktestclient.getZoneForTests())
        cls.services = cls.testClient.getParsedTestDataConfig()
        cls.services["mode"] = cls.zone.networktype
        cls._cleanup = []
        cls.updateclone = False
        cls.restartreq = False
        cls.defaultdiskcontroller = "ide"
        cls.template = get_template(cls.api_client, cls.zone.id)
        if cls.template == FAILED:
            assert False, "get_template() failed to return template "

        #create a user account
        cls.account = Account.create(cls.api_client,
                                     cls.services["account"],
                                     domainid=cls.domain.id,
                                     admin=True)
        cls._cleanup.append(cls.account)
        list_pool_resp = list_storage_pools(cls.api_client,
                                            account=cls.account.name,
                                            domainid=cls.domain.id)
        #Identify the storage pool type  and set vmware fullclone to
        # true if storage is VMFS
        if cls.hypervisor == 'vmware':
            # please make sure url of templateregister dictionary in
            # test_data.config pointing to .ova file

            list_config_storage_response = list_configurations(
                cls.api_client, name="vmware.root.disk.controller")
            cls.defaultdiskcontroller = list_config_storage_response[0].value
            if list_config_storage_response[0].value == "ide" or \
                            list_config_storage_response[0].value == \
                            "osdefault":
                Configurations.update(cls.api_client,
                                      "vmware.root.disk.controller",
                                      value="scsi")

                cls.updateclone = True
                cls.restartreq = True

            list_config_fullclone_global_response = list_configurations(
                cls.api_client, name="vmware.create.full.clone")
            if list_config_fullclone_global_response[0].value == "false":
                Configurations.update(cls.api_client,
                                      "vmware.create.full.clone",
                                      value="true")

                cls.updateclone = True
                cls.restartreq = True

            for strpool in list_pool_resp:
                if strpool.type.lower() == "vmfs" or strpool.type.lower(
                ) == "networkfilesystem":
                    list_config_storage_response = list_configurations(
                        cls.api_client,
                        name="vmware.create.full.clone",
                        storageid=strpool.id)
                    res = validateList(list_config_storage_response)
                    if res[2] == INVALID_INPUT:
                        raise Exception("Failed to  list configurations ")

                    if list_config_storage_response[0].value == "false":
                        Configurations.update(cls.api_client,
                                              "vmware.create.full.clone",
                                              value="true",
                                              storageid=strpool.id)
                        cls.updateclone = True
                        StoragePool.update(cls.api_client,
                                           id=strpool.id,
                                           tags="scsi")
                        cls.storageID = strpool.id
                        break
            if cls.restartreq:
                cls.restartServer()

                #Giving 30 seconds to management to warm-up,
                #Experienced failures when trying to deploy a VM exactly when management came up
                time.sleep(30)

        #create a service offering
        cls.service_offering = ServiceOffering.create(
            cls.api_client, cls.services["service_offering"])
        #build cleanup list
        cls.services_offering_vmware = ServiceOffering.create(
            cls.api_client, cls.services["service_offering"], tags="scsi")
        cls._cleanup.extend(
            [cls.service_offering, cls.services_offering_vmware])
    def setUpClass(cls):
        cls.cloudstacktestclient = super(TestDeployVmRootSize,
                                     cls).getClsTestClient()
        cls.api_client = cls.cloudstacktestclient.getApiClient()
        cls.hypervisor = cls.cloudstacktestclient.getHypervisorInfo().lower()
        cls.mgtSvrDetails = cls.config.__dict__["mgtSvr"][0].__dict__

        # Get Zone, Domain and Default Built-in template
        cls.domain = get_domain(cls.api_client)
        cls.zone = get_zone(cls.api_client,
                            cls.cloudstacktestclient.getZoneForTests())
        cls.services = cls.testClient.getParsedTestDataConfig()
        cls.services["mode"] = cls.zone.networktype
        cls._cleanup = []
        cls.updateclone = False
        cls.restartreq = False
        cls.defaultdiskcontroller = "ide"
        cls.template = get_template(cls.api_client, cls.zone.id)
        if cls.template == FAILED:
            assert False, "get_template() failed to return template "

        #create a user account
        cls.account = Account.create(
            cls.api_client,
            cls.services["account"],
            domainid=cls.domain.id,admin=True
        )
        cls._cleanup.append(cls.account)
        list_pool_resp = list_storage_pools(cls.api_client,
                                            account=cls.account.name,
                                            domainid=cls.domain.id)
        #Identify the storage pool type  and set vmware fullclone to
        # true if storage is VMFS
        if cls.hypervisor == 'vmware':
             # please make sure url of templateregister dictionary in
             # test_data.config pointing to .ova file

             list_config_storage_response = list_configurations(
                        cls.api_client
                        , name=
                        "vmware.root.disk.controller")
             cls.defaultdiskcontroller = list_config_storage_response[0].value
             if list_config_storage_response[0].value == "ide" or \
                             list_config_storage_response[0].value == \
                             "osdefault":
                        Configurations.update(cls.api_client,
                                              "vmware.root.disk.controller",
                                              value="scsi")

                        cls.updateclone = True
                        cls.restartreq = True

             list_config_fullclone_global_response = list_configurations(
                        cls.api_client
                        , name=
                        "vmware.create.full.clone")
             if list_config_fullclone_global_response[0].value=="false":
                        Configurations.update(cls.api_client,
                                              "vmware.create.full.clone",
                                              value="true")

                        cls.updateclone = True
                        cls.restartreq = True

             cls.tempobj = Template.register(cls.api_client,
                                    cls.services["templateregister"],
                                    hypervisor=cls.hypervisor,
                                    zoneid=cls.zone.id,
                                         account=cls.account.name,
                                         domainid=cls.domain.id
                                        )
             cls.tempobj.download(cls.api_client)

             for strpool in list_pool_resp:
                if strpool.type.lower() == "vmfs" or strpool.type.lower()== "networkfilesystem":
                    list_config_storage_response = list_configurations(
                        cls.api_client
                        , name=
                        "vmware.create.full.clone",storageid=strpool.id)
                    res = validateList(list_config_storage_response)
                    if res[2]== INVALID_INPUT:
                        raise Exception("Failed to  list configurations ")

                    if list_config_storage_response[0].value == "false":
                        Configurations.update(cls.api_client,
                                              "vmware.create.full.clone",
                                              value="true",
                                              storageid=strpool.id)
                        cls.updateclone = True
                        StoragePool.update(cls.api_client,id=strpool.id,
                                           tags="scsi")
                        cls.storageID = strpool.id
                        break
             if cls.restartreq:
                cls.restartServer()
        #create a service offering
        cls.service_offering = ServiceOffering.create(
            cls.api_client,
            cls.services["service_offering"]
        )
        #build cleanup list
        cls.services_offering_vmware=ServiceOffering.create(
                cls.api_client,cls.services["service_offering"],tags="scsi")
        cls._cleanup.extend([cls.service_offering,cls.services_offering_vmware])
Ejemplo n.º 16
0
    def test_02_NetworkGarbageCollection(self):
        """Test network garbage collection
        """
        # Validate the following
        # 1. wait for router to start and guest network to be created
        #    a.listRouters account=user, domainid=1 (router state=Running)
        #    b.listNetworks account=user domainid=1 (network state=Implemented)
        #    c.listVirtualMachines account=user domainid=1 (VM states=Running)
        # 4. stopVirtualMachines (stop all VMs in this account)
        # 5. wait for VMs to stop-listVirtualMachines account=user, domainid=1
        #    (Both VM states = Stopped)
        # 6. wait for network.gc.interval*2 seconds (600s)
        # 7. listRouters account=user, domainid=1

        routers = list_routers(
            self.apiclient,
            account=self.account.name,
            domainid=self.account.domainid,
        )

        self.assertEqual(
            isinstance(routers, list),
            True,
            "Check for list routers response return valid data"
        )
        self.assertNotEqual(
            len(routers),
            0,
            "Check list router response"
        )
        # Router associated with account should be in running state
        timeout = 180
        router = routers[0]
        self.debug("Router ID: %s & Router state: %s" % (
            router.id,
            router.state
        ))
        self.debug(
            "Wait for %s secs max for router to reach Running state" %
            timeout)
        while timeout:
            time.sleep(60)
            routers = list_routers(
                self.apiclient,
                account=self.account.name,
                domainid=self.account.domainid,
                id=router.id)
            router = routers[0]
            if router.state == 'Running':
                break

            timeout = timeout - 60
            if timeout == 0:
                self.assertEqual(
                    router.state,
                    'Running',
                    "Router not in Running state")

        # Network state associated with account should be 'Implemented'
        networks = list_networks(
            self.apiclient,
            account=self.account.name,
            domainid=self.account.domainid,
            type='Isolated'
        )
        self.assertEqual(
            isinstance(networks, list),
            True,
            "Check for list networks response return valid data"
        )
        self.assertNotEqual(
            len(networks),
            0,
            "Check list networks response"
        )
        # Check if network in 'Implemented' state
        for network in networks:
            self.debug("Network ID: %s & Network state: %s" % (
                network.id,
                network.state
            ))
            self.assertIn(
                network.state,
                ['Implemented', 'Allocated'],
                "Check list network response for network state"
            )

        # VM state associated with account should be 'Running'
        virtual_machines = list_virtual_machines(
            self.apiclient,
            account=self.account.name,
            domainid=self.account.domainid,
        )

        self.assertEqual(
            isinstance(virtual_machines, list),
            True,
            "Check for list virtual machines response return valid data"
        )
        self.assertNotEqual(
            len(virtual_machines),
            0,
            "Check list virtual machines response"
        )
        for virtual_machine in virtual_machines:
            self.debug("VM ID: %s & VM state: %s" % (
                virtual_machine.id,
                virtual_machine.state
            ))
            self.assertEqual(
                virtual_machine.state,
                'Running',
                "Check list VM response for Running state"
            )

            # Stop virtual machine
            cmd = stopVirtualMachine.stopVirtualMachineCmd()
            cmd.id = virtual_machine.id
            self.apiclient.stopVirtualMachine(cmd)

        gcinterval = list_configurations(
            self.apiclient,
            name='network.gc.interval'
        )
        self.assertEqual(
            isinstance(gcinterval, list),
            True,
            "Check for list intervals response return valid data"
        )
        self.debug("network.gc.interval: %s" % gcinterval[0].value)

        gcwait = list_configurations(
            self.apiclient,
            name='network.gc.wait'
        )
        self.assertEqual(
            isinstance(gcwait, list),
            True,
            "Check for list intervals response return valid data"
        )
        self.debug("network.gc.wait: %s" % gcwait[0].value)

        total_wait = int(gcinterval[0].value) + int(gcwait[0].value)
        # Router is stopped after (network.gc.interval *2) time. Wait for
        # (network.gc.interval+network.gc.wait) * 2 for moving
        # router to 'Stopped'
        time.sleep(total_wait * 2)

        routers = list_routers(
            self.apiclient,
            account=self.account.name,
            domainid=self.account.domainid,
        )

        self.assertEqual(
            isinstance(routers, list),
            True,
            "Check for list routers response return valid data"
        )
        self.assertNotEqual(
            len(routers),
            0,
            "Check list router response"
        )
        for router in routers:
            self.debug("Router ID: %s & Router state: %s" % (
                router.id,
                router.state
            ))
            self.assertEqual(
                router.state,
                'Stopped',
                "Check list router response for router state"
            )

        # Cleanup Vm_2 - Not required for further tests
        self.cleanup.append(self.vm_2)
        return
Ejemplo n.º 17
0
    def setUpClass(cls):
        cls.testClient = super(TestResizeVolume, cls).getClsTestClient()
        cls.api_client = cls.testClient.getApiClient()
        cls.hypervisor = (cls.testClient.getHypervisorInfo()).lower()
        cls.storageID = None
        # Fill services from the external config file
        cls.services = cls.testClient.getParsedTestDataConfig()
        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.api_client)
        cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests())
        cls.services["mode"] = cls.zone.networktype
        cls._cleanup = []
        cls.unsupportedStorageType = False
        cls.unsupportedHypervisorType = False
        cls.updateclone = False
        if cls.hypervisor not in ['xenserver', "kvm", "vmware"]:
            cls.unsupportedHypervisorType = True
            return
        cls.template = get_template(cls.api_client, cls.zone.id)
        cls.services["virtual_machine"]["zoneid"] = cls.zone.id
        cls.services["virtual_machine"]["template"] = cls.template.id
        cls.services["volume"]["zoneid"] = cls.zone.id
        try:
            cls.parent_domain = Domain.create(cls.api_client,
                                              services=cls.services["domain"],
                                              parentdomainid=cls.domain.id)
            cls.parentd_admin = Account.create(cls.api_client,
                                               cls.services["account"],
                                               admin=True,
                                               domainid=cls.parent_domain.id)
            cls._cleanup.append(cls.parentd_admin)
            cls._cleanup.append(cls.parent_domain)
            list_pool_resp = list_storage_pools(cls.api_client,
                                                account=cls.parentd_admin.name,
                                                domainid=cls.parent_domain.id)
            res = validateList(list_pool_resp)
            if res[2] == INVALID_INPUT:
                raise Exception(
                    "Failed to  list storage pool-no storagepools found ")
            #Identify the storage pool type  and set vmware fullclone to true if storage is VMFS
            if cls.hypervisor == 'vmware':
                for strpool in list_pool_resp:
                    if strpool.type.lower() == "vmfs" or strpool.type.lower(
                    ) == "networkfilesystem":
                        list_config_storage_response = list_configurations(
                            cls.api_client,
                            name="vmware.create.full.clone",
                            storageid=strpool.id)
                        res = validateList(list_config_storage_response)
                        if res[2] == INVALID_INPUT:
                            raise Exception("Failed to  list configurations ")
                        if list_config_storage_response[0].value == "false":
                            Configurations.update(cls.api_client,
                                                  "vmware.create.full.clone",
                                                  value="true",
                                                  storageid=strpool.id)
                            cls.updateclone = True
                            StoragePool.update(cls.api_client,
                                               id=strpool.id,
                                               tags="scsi")
                            cls.storageID = strpool.id
                            cls.unsupportedStorageType = False
                            break
                    else:
                        cls.unsupportedStorageType = True
            # Creating service offering with normal config
            cls.service_offering = ServiceOffering.create(
                cls.api_client, cls.services["service_offering"])
            cls.services_offering_vmware = ServiceOffering.create(
                cls.api_client, cls.services["service_offering"], tags="scsi")
            cls._cleanup.extend(
                [cls.service_offering, cls.services_offering_vmware])

        except Exception as e:
            cls.tearDownClass()
        return
    def test_04_try_delete_primary_with_template(self):
        virtual_machine = VirtualMachine.create(
            self.apiclient, {"name": "StorPool-%s" % uuid.uuid4()},
            zoneid=self.zone.id,
            templateid=self.template.id,
            serviceofferingid=self.serviceOfferings.id,
            hypervisor=self.hypervisor,
            rootdisksize=10)

        volume = list_volumes(self.apiclient,
                              virtualmachineid=virtual_machine.id,
                              type="ROOT",
                              listall=True)

        volume = volume[0]

        name = volume.path.split("/")[3]
        try:
            spvolume = self.spapi.volumeList(volumeName="~" + name)
            if spvolume[0].templateName != self.template_name:
                raise Exception(
                    "Storpool volume's template %s  is not with the same template %s"
                    % (spvolume[0].templateName, self.template_name))
        except spapi.ApiError as err:
            raise Exception(err)

        backup_config = list_configurations(self.apiclient,
                                            name="sp.bypass.secondary.storage")
        if (backup_config[0].value == "false"):
            backup_config = Configurations.update(
                self.apiclient,
                name="sp.bypass.secondary.storage",
                value="true")

        snapshot = Snapshot.create(
            self.apiclient,
            volume_id=volume.id,
        )
        self.debug("###################### %s" % snapshot)
        id = self.helper.get_snapshot_template_id(self.apiclient, snapshot,
                                                  self.storage_pool_id)
        if id is None:
            raise Exception("There isn't primary storgae id")
        virtual_machine.delete(self.apiclient, expunge=True)
        pool = list_storage_pools(self.apiclient, id=id)

        services = {
            "displaytext": "Template-1",
            "name": "Template-1-name",
            "ostypeid": self.template.ostypeid,
            "ispublic": "true"
        }
        template = Template.create_from_snapshot(self.apiclient,
                                                 snapshot=snapshot,
                                                 services=services)
        Snapshot.delete(snapshot, self.apiclient)

        try:
            StoragePool.delete(self.sp_primary_storage, self.apiclient)
        except Exception as err:
            StoragePool.cancelMaintenance(self.apiclient,
                                          id=self.sp_primary_storage.id)
            self.debug("Storge pool could not be delete due to %s" % err)

        Template.delete(template, self.apiclient)