コード例 #1
0
ファイル: test_iso.py プロジェクト: slavkap/cloudstack
    def setUpClass(cls):
        testClient = super(TestISO, cls).getClsTestClient()
        cls.apiclient = testClient.getApiClient()
        cls.services = testClient.getParsedTestDataConfig()
        cls._cleanup = []
        cls.unsupportedHypervisor = False
        cls.hypervisor = get_hypervisor_type(cls.apiclient)
        if cls.hypervisor.lower() in ["simulator", "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["domainid"] = cls.domain.id
        cls.services["iso1"]["zoneid"] = cls.zone.id
        cls.services["iso2"]["zoneid"] = cls.zone.id
        cls.services["sourcezoneid"] = cls.zone.id
        # populate second zone id for iso copy
        cmd = listZones.listZonesCmd()
        cls.zones = cls.apiclient.listZones(cmd)
        if not isinstance(cls.zones, list):
            raise Exception("Failed to find zones.")

        # Create an account, ISOs etc.
        cls.account = Account.create(cls.apiclient,
                                     cls.services["account"],
                                     domainid=cls.domain.id)
        cls._cleanup.append(cls.account)
        # Finding the OsTypeId from Ostype
        ostypes = list_os_types(cls.apiclient,
                                description=cls.services["ostype"])
        if not isinstance(ostypes, list):
            raise unittest.SkipTest("OSTypeId for given description not found")

        cls.services["iso1"]["ostypeid"] = ostypes[0].id
        cls.services["iso2"]["ostypeid"] = ostypes[0].id
        cls.services["ostypeid"] = ostypes[0].id

        cls.iso_1 = Iso.create(cls.apiclient,
                               cls.services["iso1"],
                               account=cls.account.name,
                               domainid=cls.account.domainid)
        try:
            cls.iso_1.download(cls.apiclient)
        except Exception as e:
            raise Exception("Exception while downloading ISO %s: %s" %
                            (cls.iso_1.id, e))

        cls.iso_2 = Iso.create(cls.apiclient,
                               cls.services["iso2"],
                               account=cls.account.name,
                               domainid=cls.account.domainid)
        try:
            cls.iso_2.download(cls.apiclient)
        except Exception as e:
            raise Exception("Exception while downloading ISO %s: %s" %
                            (cls.iso_2.id, e))
        return
コード例 #2
0
    def test_03_register_iso(self, value):
        """Test register iso
        Steps and validations:
        1. Create a root domain/child domain admin account
        2. Register a test iso in the account
        3. Wait till the iso is downloaded and is in ready state
        3. Verify that secondary storage resource count of the account equals the
           iso size
        4. Delete the iso
        5. Verify that the secondary storage count of the account equals 0
        """
        response = self.setupAccount(value)
        self.assertEqual(response[0], PASS, response[1])

        self.services["iso"]["zoneid"] = self.zone.id
        try:
            iso = Iso.create(
                         self.apiclient,
                         self.services["iso"],
                         account=self.account.name,
                         domainid=self.account.domainid
                         )
        except Exception as e:
            self.fail("Failed to create Iso: %s" % e)

        timeout = 600
        isoList = None
        while timeout >= 0:
            isoList = Iso.list(self.apiclient,
                                      isofilter="self",
                                      id=iso.id)
            self.assertEqual(validateList(isoList)[0],PASS,\
                            "iso list validation failed")
            if isoList[0].isready:
                break
            time.sleep(60)
            timeout -= 60

        self.assertNotEqual(timeout, 0,\
                "template not downloaded completely")

        isoSize = (isoList[0].size / (1024**3))
        expectedCount = isoSize
        response = matchResourceCount(self.apiclient, expectedCount,
                                      resourceType=RESOURCE_SECONDARY_STORAGE,
                                      accountid=self.account.id)
        self.assertEqual(response[0], PASS, response[1])

        try:
            iso.delete(self.apiclient)
        except Exception as e:
            self.fail("Failed to delete Iso")

        expectedCount = 0
        response = matchResourceCount(self.apiclient, expectedCount,
                                      resourceType=RESOURCE_SECONDARY_STORAGE,
                                      accountid=self.account.id)
        self.assertEqual(response[0], PASS, response[1])
        return
コード例 #3
0
    def test_02_deploy_ha_vm_from_iso(self):
        """Test Deploy HA enabled Virtual Machine from ISO
        """

        # Validate the following:
        # 1. deployHA enabled Vm using ISO with the startvm parameter=true
        # 2. listVM command should return the deployed VM. State of this VM
        #    should be "Running".

        self.iso = Iso.create(
            self.apiclient, self.services["iso"], account=self.account.name, domainid=self.account.domainid
        )
        try:
            # Download the ISO
            self.iso.download(self.apiclient)

        except Exception as e:
            raise Exception("Exception while downloading ISO %s: %s" % (self.iso.id, e))

        self.debug("Registered ISO: %s" % self.iso.name)
        self.debug("Deploying instance in the account: %s" % self.account.name)
        self.virtual_machine = VirtualMachine.create(
            self.apiclient,
            self.services["virtual_machine"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            templateid=self.iso.id,
            serviceofferingid=self.service_offering.id,
            diskofferingid=self.disk_offering.id,
            startvm=True,
        )

        response = self.virtual_machine.getState(self.apiclient, VirtualMachine.RUNNING)
        self.assertEqual(response[0], PASS, response[1])
        return
コード例 #4
0
ファイル: test_iso.py プロジェクト: urvies/cloudstack
    def test_01_create_iso(self):
        """Test create public & private ISO
        """

        # Validate the following:
        # 1. database (vm_template table) should be
        #    updated with newly created ISO
        # 2. UI should show the newly added ISO
        # 3. listIsos API should show the newly added ISO

        iso = Iso.create(self.apiclient,
                         self.services["iso2"],
                         account=self.account.name,
                         domainid=self.account.domainid)
        self.debug("ISO created with ID: %s" % iso.id)

        try:
            iso.download(self.apiclient)
        except Exception as e:
            self.fail("Exception while downloading ISO %s: %s" % (iso.id, e))

        list_iso_response = list_isos(self.apiclient, id=iso.id)
        self.assertEqual(isinstance(list_iso_response, list), True,
                         "Check list response returns a valid list")

        self.assertNotEqual(len(list_iso_response), 0,
                            "Check template available in List ISOs")
        iso_response = list_iso_response[0]

        self.assertEqual(iso_response.displaytext,
                         self.services["iso2"]["displaytext"],
                         "Check display text of newly created ISO")
        self.assertEqual(iso_response.zoneid, self.services["iso2"]["zoneid"],
                         "Check zone ID of newly created ISO")
        return
コード例 #5
0
    def test_06_pt_startvm_false_attach_iso(self):
        """ Positive test for stopped VM test path - T5

        # 1.  Deploy VM in the network with specifying startvm parameter
        #     as False
        # 2.  List VMs and verify that VM is in stopped state
        # 3.  Register an ISO and attach it to the VM
        # 4.  Verify that ISO is attached to the VM
        """

        # Create VM in account
        virtual_machine = VirtualMachine.create(
            self.userapiclient,
            self.testdata["small"],
            templateid=self.defaultTemplateId,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
            networkids=[self.networkid, ] if self.networkid else None,
            zoneid=self.zone.id,
            startvm=False,
            mode=self.zone.networktype
        )
        self.cleanup.append(virtual_machine)

        response = virtual_machine.getState(
            self.apiclient,
            VirtualMachine.STOPPED)
        self.assertEqual(response[0], PASS, response[1])

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

        iso.download(self.userapiclient)
        virtual_machine.attach_iso(self.userapiclient, iso)

        vms = VirtualMachine.list(
            self.userapiclient,
            id=virtual_machine.id,
            listall=True
        )
        self.assertEqual(
            validateList(vms)[0],
            PASS,
            "List vms should return a valid list"
        )
        vm = vms[0]
        self.assertEqual(
            vm.isoid,
            iso.id,
            "The ISO status should be reflected in list Vm call"
        )
        return
コード例 #6
0
    def test_07_pt_startvm_false_attach_iso_running_vm(self):
        """ Positive test for stopped VM test path - T5 variant

        # 1.  Deploy VM in the network with specifying startvm parameter
        #     as False
        # 2.  List VMs and verify that VM is in stopped state
        # 3.  Start the VM and verify that it is in running state
        # 3.  Register an ISO and attach it to the VM
        # 4.  Verify that ISO is attached to the VM
        """

        # Create VM in account
        virtual_machine = VirtualMachine.create(
            self.userapiclient,
            self.testdata["small"],
            templateid=self.defaultTemplateId,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
            networkids=[
                self.networkid,
            ] if self.networkid else None,
            zoneid=self.zone.id,
            startvm=False,
            mode=self.zone.networktype)
        self.cleanup.append(virtual_machine)

        response = virtual_machine.getState(self.apiclient,
                                            VirtualMachine.STOPPED)
        self.assertEqual(response[0], PASS, response[1])

        virtual_machine.start(self.userapiclient)

        response = virtual_machine.getState(self.apiclient,
                                            VirtualMachine.RUNNING)
        self.assertEqual(response[0], PASS, response[1])

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

        iso.download(self.userapiclient)
        virtual_machine.attach_iso(self.userapiclient, iso)

        vms = VirtualMachine.list(self.userapiclient,
                                  id=virtual_machine.id,
                                  listall=True)
        self.assertEqual(
            validateList(vms)[0], PASS, "List vms should return a valid list")
        vm = vms[0]
        self.assertEqual(vm.isoid, iso.id,
                         "The ISO status should be reflected in list Vm call")
        return
コード例 #7
0
ファイル: test_iso.py プロジェクト: K0zka/cloudstack
    def test_01_create_iso(self):
        """Test create public & private ISO
        """

        # Validate the following:
        # 1. database (vm_template table) should be
        #    updated with newly created ISO
        # 2. UI should show the newly added ISO
        # 3. listIsos API should show the newly added ISO

        iso = Iso.create(
            self.apiclient,
            self.services["iso2"],
            account=self.account.name,
            domainid=self.account.domainid
        )
        self.debug("ISO created with ID: %s" % iso.id)

        try:
            iso.download(self.apiclient)
        except Exception as e:
            self.fail("Exception while downloading ISO %s: %s"
                      % (iso.id, e))

        list_iso_response = list_isos(
            self.apiclient,
            id=iso.id
        )
        self.assertEqual(
            isinstance(list_iso_response, list),
            True,
            "Check list response returns a valid list"
        )

        self.assertNotEqual(
            len(list_iso_response),
            0,
            "Check template available in List ISOs"
        )
        iso_response = list_iso_response[0]

        self.assertEqual(
            iso_response.displaytext,
            self.services["iso2"]["displaytext"],
            "Check display text of newly created ISO"
        )
        self.assertEqual(
            iso_response.zoneid,
            self.services["iso2"]["zoneid"],
            "Check zone ID of newly created ISO"
        )
        return
コード例 #8
0
    def test_deploy_vm_from_iso(self):
        """Test Deploy Virtual Machine from ISO
        """

        # Validate the following:
        # 1. deploy VM using ISO
        # 2. listVM command should return the deployed VM. State of this VM
        #    should be "Running".
        self.hypervisor = self.testClient.getHypervisorInfo()
        if self.hypervisor.lower() in ['lxc']:
            self.skipTest(
                "vm deploy from ISO feature is not supported on %s" %
                self.hypervisor.lower())

        self.iso = Iso.create(
            self.apiclient,
            self.testdata["configurableData"]["bootableIso"],
            account=self.account.name,
            domainid=self.account.domainid,
            zoneid=self.zone.id
        )
        try:
            # Download the ISO
            self.iso.download(self.apiclient)

        except Exception as e:
            raise Exception("Exception while downloading ISO %s: %s"
                            % (self.iso.id, e))

        self.debug("Registered ISO: %s" % self.iso.name)
        self.debug("Deploying instance in the account: %s" %
                   self.account.name)
        self.virtual_machine = VirtualMachine.create(
            self.apiclient,
            self.testdata["virtual_machine"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            templateid=self.iso.id,
            serviceofferingid=self.service_offering.id,
            diskofferingid=self.disk_offering.id,
            hypervisor=self.hypervisor
        )

        response = self.virtual_machine.getState(
            self.apiclient,
            VirtualMachine.RUNNING)
        self.assertEqual(response[0], PASS, response[1])
        return
コード例 #9
0
    def test_07_deploy_startvm_attach_iso(self):
        """Test Deploy Virtual Machine with startVM=false and attach ISO
        """

        # Validate the following:
        # 1. deploy Vm  with the startvm=false. Attach volume to the instance
        # 2. listVM command should return the deployed VM.State of this VM
        #    should be "Stopped".
        # 3. Attach ISO to the instance. Attach ISO should be successful

        self.debug("Deploying instance in the account: %s" % self.account.name)
        self.virtual_machine = VirtualMachine.create(
            self.apiclient,
            self.services["virtual_machine"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
            startvm=False,
            diskofferingid=self.disk_offering.id,
        )

        response = self.virtual_machine.getState(self.apiclient, VirtualMachine.STOPPED)
        self.assertEqual(response[0], PASS, response[1])
        self.debug("Registering a ISO in account: %s" % self.account.name)
        iso = Iso.create(
            self.apiclient, self.services["iso"], account=self.account.name, domainid=self.account.domainid
        )

        self.debug("Successfully created ISO with ID: %s" % iso.id)
        try:
            iso.download(self.apiclient)

        except Exception as e:
            self.fail("Exception while downloading ISO %s: %s" % (iso.id, e))

        self.debug("Attach ISO with ID: %s to VM ID: %s" % (iso.id, self.virtual_machine.id))
        try:
            self.virtual_machine.attach_iso(self.apiclient, iso)
        except Exception as e:
            self.fail("Attach ISO failed!")

        vms = VirtualMachine.list(self.apiclient, id=self.virtual_machine.id, listall=True)
        self.assertEqual(isinstance(vms, list), True, "List vms should return a valid list")
        vm = vms[0]
        self.assertEqual(vm.isoid, iso.id, "The ISO status should be reflected in list Vm call")
        return
コード例 #10
0
ファイル: test_iso.py プロジェクト: slavkap/cloudstack
    def download(self, apiclient, iso_id, retries=12, interval=5):
        """Check if template download will finish in 1 minute"""
        while retries > -1:
            time.sleep(interval)
            iso_response = Iso.list(apiclient, id=iso_id)

            if isinstance(iso_response, list):
                iso = iso_response[0]
                if not hasattr(iso, 'status') or not iso or not iso.status:
                    retries = retries - 1
                    continue

                # If iso is ready,
                # iso.status = Download Complete
                # Downloading - x% Downloaded
                # if Failed
                # Error - Any other string
                if 'Failed' in iso.status:
                    raise Exception("Failed to download iso: status - %s" %
                                    iso.status)

                elif iso.status == 'Successfully Installed' and iso.isready:
                    return

                elif 'Downloaded' in iso.status:
                    retries = retries - 1
                    continue

                elif 'Installing' not in iso.status:
                    if retries >= 0:
                        retries = retries - 1
                        continue
                    raise Exception("Error in downloading iso: status - %s" %
                                    iso.status)

            else:
                retries = retries - 1
        raise Exception("Template download failed exception.")
コード例 #11
0
    def setUp(self):

        if self.testClient.getHypervisorInfo().lower() != "vmware":
            raise unittest.SkipTest(
                "VMWare tests only valid on VMWare hypervisor")

        self.services = self.testClient.getParsedTestDataConfig()
        self.apiclient = self.testClient.getApiClient()
        self.dbclient = self.testClient.getDbConnection()
        self.zone = get_zone(self.apiclient, self.testClient.getZoneForTests())
        self.domain = get_domain(self.apiclient)
        self.services['mode'] = self.zone.networktype
        self.hypervisor = self.hypervisor = self.testClient.getHypervisorInfo()

        template = get_suitable_test_template(self.apiclient, self.zone.id,
                                              self.services["ostype"],
                                              self.hypervisor)

        if template == FAILED:
            assert False, "get_suitable_test_template() failed to return template with description %s" % self.services[
                "ostype"]

        self.account = Account.create(self.apiclient,
                                      self.services["account"],
                                      domainid=self.domain.id)

        self.services["small"]["zoneid"] = self.zone.id
        self.services["small"]["template"] = template.id

        self.services["iso1"]["zoneid"] = self.zone.id

        iso = Iso.create(self.apiclient,
                         self.services["iso1"],
                         account=self.account.name,
                         domainid=self.account.domainid)

        self.cleanup = [self.account]
コード例 #12
0
ファイル: test_iso.py プロジェクト: K0zka/cloudstack
    def setUpClass(cls):
        testClient = super(TestISO, cls).getClsTestClient()
        cls.apiclient = testClient.getApiClient()
        cls.services = testClient.getParsedTestDataConfig()

        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.apiclient)
        cls.zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests())

        cls.services["domainid"] = cls.domain.id
        cls.services["iso1"]["zoneid"] = cls.zone.id
        cls.services["iso2"]["zoneid"] = cls.zone.id
        cls.services["sourcezoneid"] = cls.zone.id
        # populate second zone id for iso copy
        cmd = listZones.listZonesCmd()
        cls.zones = cls.apiclient.listZones(cmd)
        if not isinstance(cls.zones, list):
            raise Exception("Failed to find zones.")

        # Create an account, ISOs etc.
        cls.account = Account.create(
            cls.apiclient,
            cls.services["account"],
            domainid=cls.domain.id
        )
        # Finding the OsTypeId from Ostype
        ostypes = list_os_types(
            cls.apiclient,
            description=cls.services["ostype"]
        )
        if not isinstance(ostypes, list):
            raise unittest.SkipTest("OSTypeId for given description not found")

        cls.services["iso1"]["ostypeid"] = ostypes[0].id
        cls.services["iso2"]["ostypeid"] = ostypes[0].id
        cls.services["ostypeid"] = ostypes[0].id

        cls.iso_1 = Iso.create(
            cls.apiclient,
            cls.services["iso1"],
            account=cls.account.name,
            domainid=cls.account.domainid
        )
        try:
            cls.iso_1.download(cls.apiclient)
        except Exception as e:
            raise Exception("Exception while downloading ISO %s: %s"
                            % (cls.iso_1.id, e))

        cls.iso_2 = Iso.create(
            cls.apiclient,
            cls.services["iso2"],
            account=cls.account.name,
            domainid=cls.account.domainid
        )
        try:
            cls.iso_2.download(cls.apiclient)
        except Exception as e:
            raise Exception("Exception while downloading ISO %s: %s"
                            % (cls.iso_2.id, e))

        cls._cleanup = [cls.account]
        return
コード例 #13
0
    def test_01_volume_iso_attach(self):
        """Test Volumes and ISO attach
        """

        # Validate the following
        # 1. Create and attach 5 data volumes to VM
        # 2. Create an ISO. Attach it to VM instance
        # 3. Verify that attach ISO is successful

        # Create 5 volumes and attach to VM
        if self.hypervisor.lower() in ["lxc"]:
            self.skipTest("attach ISO is not supported on LXC")
        for i in range(self.max_data_volumes):
            volume = Volume.create(
                self.apiclient,
                self.services["volume"],
                zoneid=self.zone.id,
                account=self.account.name,
                domainid=self.account.domainid,
                diskofferingid=self.disk_offering.id
            )
            self.debug("Created volume: %s for account: %s" % (
                volume.id,
                self.account.name
            ))
            # Check List Volume response for newly created volume
            list_volume_response = Volume.list(
                self.apiclient,
                id=volume.id
            )
            self.assertNotEqual(
                list_volume_response,
                None,
                "Check if volume exists in ListVolumes"
            )
            self.assertEqual(
                isinstance(list_volume_response, list),
                True,
                "Check list volumes response for valid list"
            )
            # Attach volume to VM
            self.virtual_machine.attach_volume(
                self.apiclient,
                volume
            )

        # Check all volumes attached to same VM
        list_volume_response = Volume.list(
            self.apiclient,
            virtualmachineid=self.virtual_machine.id,
            type='DATADISK',
            listall=True
        )
        self.assertNotEqual(
            list_volume_response,
            None,
            "Check if volume exists in ListVolumes"
        )
        self.assertEqual(
            isinstance(list_volume_response, list),
            True,
            "Check list volumes response for valid list"
        )
        self.assertEqual(
            len(list_volume_response),
            self.max_data_volumes,
            "Volumes attached to the VM %s. Expected %s" %
            (len(list_volume_response),
             self.max_data_volumes))
        # Create an ISO and attach it to VM
        iso = Iso.create(
            self.apiclient,
            self.services["iso"],
            account=self.account.name,
            domainid=self.account.domainid,
        )
        self.debug("Created ISO with ID: %s for account: %s" % (
            iso.id,
            self.account.name
        ))

        try:
            self.debug("Downloading ISO with ID: %s" % iso.id)
            iso.download(self.apiclient)
        except Exception as e:
            self.fail("Exception while downloading ISO %s: %s"
                      % (iso.id, e))

        # Attach ISO to virtual machine
        self.debug("Attach ISO ID: %s to VM: %s" % (
            iso.id,
            self.virtual_machine.id
        ))
        cmd = attachIso.attachIsoCmd()
        cmd.id = iso.id
        cmd.virtualmachineid = self.virtual_machine.id
        self.apiclient.attachIso(cmd)

        # Verify ISO is attached to VM
        vm_response = VirtualMachine.list(
            self.apiclient,
            id=self.virtual_machine.id,
        )
        # Verify VM response to check whether VM deployment was successful
        self.assertEqual(
            isinstance(vm_response, list),
            True,
            "Check list VM response for valid list"
        )

        self.assertNotEqual(
            len(vm_response),
            0,
            "Check VMs available in List VMs response"
        )
        vm = vm_response[0]
        self.assertEqual(
            vm.isoid,
            iso.id,
            "Check ISO is attached to VM or not"
        )
        return
    def test_01_disable_enable_cluster(self):
        """disable enable cluster
            1. Disable cluster and verify following things:
                For admin user:
                     --Should be able to create new vm, snapshot,
                     volume,template,iso in the same cluster
                For Non-admin user:
                     --Should not be able create new vm, snapshot,
                     volume,template,iso in the same cluster
            2. Enable the above disabled cluster and verify that:
                -All users should be create to deploy new vm, snapshot,
                volume,template,iso in the same cluster
            3. Disable the managestate of the cluster and verify that:
                --Host in the cluster should get disconnected
                --VM's in the cluster are ping-able and ssh to
                --Creation of new VM in the cluster should fail
            4. Enable the managestate of the cluster and verify that:
                --Hosts in the cluster get connected
                --VM's in the cluster are accessible
            5. Try to delete the cluster and it should fail with error message:
                -"The cluster is not deletable because there are
                servers running in this cluster"

        """
        # 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,
            mode=self.zone.networktype,
        )

        self.vm_list.append(vm_user)

        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,
            mode=self.zone.networktype,
        )

        self.vm_list.append(vm_root)

        cmd = updateCluster.updateClusterCmd()
        cmd.id = self.cluster.id
        cmd.allocationstate = DISABLED
        self.apiclient.updateCluster(cmd)
        clusterList = Cluster.list(self.apiclient, id=self.cluster.id)

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

        # Verify the existing vms should 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 root vm is running")

        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,
        )

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

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

        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]

        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-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,
                mode=self.zone.networktype,
            )

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

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

        if self.snapshotSupported:
            Snapshot.create(self.userapiclient, 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 2
        cmd.allocationstate = ENABLED
        self.apiclient.updateCluster(cmd)
        clusterList = Cluster.list(self.apiclient, id=self.cluster.id)
        self.assertEqual(clusterList[0].allocationstate, ENABLED, "Check if the cluster is in disabled state")

        # After enabling the zone all users should be able to add new VM,
        # volume, templatee 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)

        # 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)

        # Step 3

        cmd = updateCluster.updateClusterCmd()
        cmd.id = self.cluster.id
        cmd.managedstate = "Unmanaged"
        self.apiclient.updateCluster(cmd)
        clusterList = Cluster.list(self.apiclient, id=self.cluster.id)

        self.assertEqual(
            clusterList[0].managedstate.lower(), "unmanaged", "Check if the cluster is in unmanaged  state"
        )
        # Hosts in the cluster takes some time to go into disconnected state
        time.sleep(60)
        hostList = Host.list(self.apiclient, clusterid=self.cluster.id)

        for host in hostList:
            self.assertEqual(host.state.lower(), "disconnected", "Check if host in the cluster gets disconnected")
        exception_list = []
        for vm in self.vm_list:
            try:
                SshClient(vm.ssh_ip, vm.ssh_port, vm.username, vm.password)

            except Exception as e:
                exception_list.append(e)

        self.assertEqual(len(exception_list), 0, "Check if vm's are accesible")

        # 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,
                mode=self.zone.networktype,
            )

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

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

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

        # Step 4
        cmd.managedstate = "Managed"
        self.apiclient.updateCluster(cmd)
        # After changing the cluster's managestate to Managed hosts in the
        # cluster takes some time to come back to Up state
        time.sleep(120)
        hostList = Host.list(self.apiclient, clusterid=self.cluster.id)
        for host in hostList:
            self.assertEqual(host.state.lower(), "up", "Check if host in the cluster gets up")

        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 should stop")

        self.assertEqual(user_state, "Stopped", "verify that vm should stop")

        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")

        # Step 5
        # Deletion of zone should fail if resources are running on the zone
        with self.assertRaises(Exception):
            self.pod.delete(self.apiclient)

        return
コード例 #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
    def test_01_disable_enable_pod(self):
        """disable enable Pod
            1. Disable pod and verify following things:
                For admin user:
                    -- Should be able to create new vm, snapshot,
                            volume,template,iso in the same pod
                For Non-admin user:
                    -- Should not be able to create new vm, snapshot,
                            volume,template,iso in the same pod
            2. Enable the above disabled pod and verify that:
                -All users should be able to create new vm, snapshot,
                volume,template,iso in the same pod
            3. Try to delete the pod and it should fail with error message:
                - "The pod is not deletable because there are servers
                running in this pod"

        """
        # 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 = updatePod.updatePodCmd()
        cmd.id = self.pod.id
        cmd.allocationstate = DISABLED
        self.apiclient.updatePod(cmd)
        podList = Pod.list(self.apiclient, id=self.pod.id)

        self.assertEqual(podList[0].allocationstate, DISABLED, "Check if the pod is in disabled state")
        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")

        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,
        )

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

        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]

        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,
        )

        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 volume id %s" % vm_user.id)
        if self.snapshotSupported:
            Snapshot.create(self.userapiclient, 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 2
        cmd.allocationstate = ENABLED
        self.apiclient.updatePod(cmd)
        podList = Pod.list(self.apiclient, id=self.pod.id)

        self.assertEqual(podList[0].allocationstate, ENABLED, "Check if the pod is in enabled state")

        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 be able \
                                    to 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,
        )

        user_vm_new.delete(self.apiclient)
        # Step 3
        # Deletion of zone should fail if resources are running on the zone
        with self.assertRaises(Exception):
            self.pod.delete(self.apiclient)

        return
コード例 #17
0
    def test_01_volume_iso_attach(self):
        """Test Volumes and ISO attach
        """

        # Validate the following
        # 1. Create and attach 5 data volumes to VM
        # 2. Create an ISO. Attach it to VM instance
        # 3. Verify that attach ISO is successful

        # Create 5 volumes and attach to VM
        for i in range(self.max_data_volumes):
            volume = Volume.create(
                self.apiclient,
                self.services["volume"],
                zoneid=self.zone.id,
                account=self.account.name,
                domainid=self.account.domainid,
                diskofferingid=self.disk_offering.id
            )
            self.debug("Created volume: %s for account: %s" % (
                volume.id,
                self.account.name
            ))
            # Check List Volume response for newly created volume
            list_volume_response = Volume.list(
                self.apiclient,
                id=volume.id
            )
            self.assertNotEqual(
                list_volume_response,
                None,
                "Check if volume exists in ListVolumes"
            )
            self.assertEqual(
                isinstance(list_volume_response, list),
                True,
                "Check list volumes response for valid list"
            )
            # Attach volume to VM
            self.virtual_machine.attach_volume(
                self.apiclient,
                volume
            )

        # Check all volumes attached to same VM
        list_volume_response = Volume.list(
            self.apiclient,
            virtualmachineid=self.virtual_machine.id,
            type='DATADISK',
            listall=True
        )
        self.assertNotEqual(
            list_volume_response,
            None,
            "Check if volume exists in ListVolumes"
        )
        self.assertEqual(
            isinstance(list_volume_response, list),
            True,
            "Check list volumes response for valid list"
        )
        self.assertEqual(
            len(list_volume_response),
            self.max_data_volumes,
            "Volumes attached to the VM %s. Expected %s" %
            (len(list_volume_response),
             self.max_data_volumes))
        # Create an ISO and attach it to VM
        iso = Iso.create(
            self.apiclient,
            self.services["iso"],
            account=self.account.name,
            domainid=self.account.domainid,
        )
        self.debug("Created ISO with ID: %s for account: %s" % (
            iso.id,
            self.account.name
        ))

        try:
            self.debug("Downloading ISO with ID: %s" % iso.id)
            iso.download(self.apiclient)
        except Exception as e:
            self.fail("Exception while downloading ISO %s: %s"
                      % (iso.id, e))

        # Attach ISO to virtual machine
        self.debug("Attach ISO ID: %s to VM: %s" % (
            iso.id,
            self.virtual_machine.id
        ))
        cmd = attachIso.attachIsoCmd()
        cmd.id = iso.id
        cmd.virtualmachineid = self.virtual_machine.id
        self.apiclient.attachIso(cmd)

        # Verify ISO is attached to VM
        vm_response = VirtualMachine.list(
            self.apiclient,
            id=self.virtual_machine.id,
        )
        # Verify VM response to check whether VM deployment was successful
        self.assertEqual(
            isinstance(vm_response, list),
            True,
            "Check list VM response for valid list"
        )

        self.assertNotEqual(
            len(vm_response),
            0,
            "Check VMs available in List VMs response"
        )
        vm = vm_response[0]
        self.assertEqual(
            vm.isoid,
            iso.id,
            "Check ISO is attached to VM or not"
        )
        return
コード例 #18
0
    def setUpClass(cls):
        cls.testClient = super(TestDeployVMFromISOWithUefi,
                               cls).getClsTestClient()
        cls.apiclient = cls.testClient.getApiClient()

        cls.hypervisor = cls.testClient.getHypervisorInfo()

        if cls.hypervisor != 'kvm':
            raise unittest.SkipTest(
                "Those tests can be run only for KVM hypervisor")

        cls.testdata = cls.testClient.getParsedTestDataConfig()
        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.apiclient)
        cls.zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests())

        hosts = list_hosts(cls.apiclient, zoneid=cls.zone.id, type="Routing")

        if not cls.isUefiEnabledOnAtLeastOnHost(hosts):
            raise unittest.SkipTest("At least one host should support UEFI")

        cls.hostConfig = cls.config.__dict__["zones"][0].__dict__["pods"][
            0].__dict__["clusters"][0].__dict__["hosts"][0].__dict__

        # Create service, disk offerings  etc
        cls.service_offering = ServiceOffering.create(
            cls.apiclient, cls.testdata["service_offering"])

        cls.disk_offering = DiskOffering.create(cls.apiclient,
                                                cls.testdata["disk_offering"])

        cls.testdata["virtual_machine"]["zoneid"] = cls.zone.id
        cls.testdata["iso1"]["zoneid"] = cls.zone.id
        cls.testdata["iso3"]["zoneid"] = cls.zone.id
        cls.account = Account.create(cls.apiclient,
                                     cls.testdata["account"],
                                     domainid=cls.domain.id)
        cls._cleanup = [cls.account, cls.service_offering, cls.disk_offering]

        cls.centos_iso = Iso.create(cls.apiclient,
                                    cls.testdata["iso1"],
                                    account=cls.account.name,
                                    domainid=cls.account.domainid,
                                    zoneid=cls.zone.id)
        try:
            # Download the ISO
            cls.centos_iso.download(cls.apiclient)
        except Exception as e:
            raise Exception("Exception while downloading ISO %s: %s" %
                            (cls.centos_iso.id, e))

        cls.windows_iso = Iso.create(cls.apiclient,
                                     cls.testdata["iso3"],
                                     account=cls.account.name,
                                     domainid=cls.account.domainid,
                                     zoneid=cls.zone.id)
        try:
            # Download the ISO
            cls.windows_iso.download(cls.apiclient)
        except Exception as e:
            raise Exception("Exception while downloading ISO %s: %s" %
                            (cls.windows_iso.id, e))

        return
コード例 #19
0
    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
コード例 #20
0
                    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
                    tmp_dict = {}
                    if options.upload_tmpl is not None:
                        my_templ = Template(tmp_dict)
                        if my_templ.register(apiClient, services) == FAILED:
                            print "Uploading template failed"
                            tc_run_logger.debug(
                                "\n=== Uploading template failed ===")
                            exit(1)
                    if options.upload_iso is not None:
                        my_templ = Iso(tmp_dict)
                        if my_templ.create(apiClient, services) == FAILED:
                            print "Uploading template failed"
                            tc_run_logger.debug(
                                "\n=== Uploading template failed ===")
                            exit(1)
                else:
                    print "Zone is not ready"
        else:
            print "No zones"
    exit(0)
コード例 #21
0
    def test_01_list_isos_pagination(self):
        """
        @Desc: Test to List ISO's pagination
        @steps:
        Step1: Listing all the ISO's for a user
        Step2: Verifying that no ISO's are listed
        Step3: Creating (page size + 1) number of ISO's
        Step4: Listing all the ISO's again for a user
        Step5: Verifying that list size is (page size + 1)
        Step6: Listing all the ISO's in page1
        Step7: Verifying that list size is (page size)
        Step8: Listing all the ISO's in page2
        Step9: Verifying that list size is 1
        Step10: Listing the ISO's by Id
        Step11: Verifying if the ISO is downloaded and ready.
                If yes the continuing
                If not waiting and checking for iso to be ready till timeout
        Step12: Deleting the ISO present in page 2
        Step13: Listing all the ISO's in page2
        Step14: Verifying that no ISO's are listed
        """
        # Listing all the ISO's for a User
        list_iso_before = Iso.list(
                                   self.userapiclient,
                                   listall=self.services["listall"],
                                   isofilter=self.services["templatefilter"]
                                   )
        # Verifying that no ISOs are listed
        self.assertIsNone(
                          list_iso_before,
                          "ISOs listed for newly created User"
                          )
        self.services["iso"]["zoneid"] = self.zone.id
        # Creating pagesize + 1 number of ISO's
        for i in range(0, (self.services["pagesize"] + 1)):
            iso_created = Iso.create(
                                     self.userapiclient,
                                     self.services["iso"]
                                     )
            self.assertIsNotNone(
                                 iso_created,
                                 "ISO creation failed"
                                 )
            if(i < self.services["pagesize"]):
                self.cleanup.append(iso_created)

        # Listing all the ISO's for a User
        list_iso_after = Iso.list(
                                  self.userapiclient,
                                  listall=self.services["listall"],
                                  isofilter=self.services["templatefilter"]
                                  )
        status = validateList(list_iso_after)
        self.assertEquals(
                          PASS,
                          status[0],
                          "ISO's creation failed"
                          )
        # Verifying that list size is pagesize + 1
        self.assertEquals(
                          self.services["pagesize"] + 1,
                          len(list_iso_after),
                          "Failed to create pagesize + 1 number of ISO's"
                          )
        # Listing all the ISO's in page 1
        list_iso_page1 = Iso.list(
                                  self.userapiclient,
                                  listall=self.services["listall"],
                                  isofilter=self.services["templatefilter"],
                                  page=1,
                                  pagesize=self.services["pagesize"]
                                  )
        status = validateList(list_iso_page1)
        self.assertEquals(
                          PASS,
                          status[0],
                          "Failed to list ISO's in page 1"
                          )
        # Verifying the list size to be equal to pagesize
        self.assertEquals(
                          self.services["pagesize"],
                          len(list_iso_page1),
                          "Size of ISO's in page 1 is not matching"
                          )
        # Listing all the Templates in page 2
        list_iso_page2 = Iso.list(
                                  self.userapiclient,
                                  listall=self.services["listall"],
                                  isofilter=self.services["templatefilter"],
                                  page=2,
                                  pagesize=self.services["pagesize"]
                                  )
        status = validateList(list_iso_page2)
        self.assertEquals(
                          PASS,
                          status[0],
                          "Failed to list ISo's in page 2"
                          )
        # Verifying the list size to be equal to 1
        self.assertEquals(
                          1,
                          len(list_iso_page2),
                          "Size of ISO's in page 2 is not matching"
                          )
        # Verifying the state of the ISO to be ready. If not waiting for state to become ready
        iso_ready = False
        count = 0
        while iso_ready is False:
            list_iso = Iso.list(
                                self.userapiclient,
                                listall=self.services["listall"],
                                isofilter=self.services["templatefilter"],
                                id=iso_created.id
                                )
            status = validateList(list_iso)
            self.assertEquals(
                              PASS,
                              status[0],
                              "Failed to list ISO by Id"
                              )
            if list_iso[0].isready is True:
                iso_ready = True
            elif (str(list_iso[0].status) == "Error"):
                self.fail("Created ISO is in Errored state")
                break
            elif count > 10:
                self.fail("Timed out before ISO came into ready state")
                break
            else:
                time.sleep(self.services["sleep"])
                count = count + 1

        # Deleting the ISO present in page 2
        Iso.delete(
                   iso_created,
                   self.userapiclient
                   )
        # Listing all the ISO's in page 2 again
        list_iso_page2 = Iso.list(
                                  self.userapiclient,
                                  listall=self.services["listall"],
                                  isofilter=self.services["templatefilter"],
                                  page=2,
                                  pagesize=self.services["pagesize"]
                                  )
        # Verifying that there are no ISO's listed
        self.assertIsNone(
                          list_iso_page2,
                          "ISO's not deleted from page 2"
                          )
        del self.services["iso"]["zoneid"]
        return
コード例 #22
0
    def test_02_download_iso(self):
        """
        @Desc: Test to Download ISO
        @steps:
        Step1: Listing all the ISO's for a user
        Step2: Verifying that no ISO's are listed
        Step3: Creating an ISO
        Step4: Listing all the ISO's again for a user
        Step5: Verifying that list size is 1
        Step6: Verifying if the ISO is in ready state.
                If yes the continuing
                If not waiting and checking for template to be ready till timeout
        Step7: Downloading the ISO (Extract)
        Step8: Verifying the details of downloaded ISO
        """
        # Listing all the ISO's for a User
        list_iso_before = Iso.list(
                                   self.userapiclient,
                                   listall=self.services["listall"],
                                   isofilter=self.services["templatefilter"]
                                   )
        # Verifying that no ISOs are listed
        self.assertIsNone(
                          list_iso_before,
                          "ISOs listed for newly created User"
                          )
        self.services["iso"]["zoneid"] = self.zone.id
        self.services["iso"]["isextractable"] = True
        # Creating an ISO's
        iso_created = Iso.create(
                                 self.userapiclient,
                                 self.services["iso"]
                                 )
        self.assertIsNotNone(
                             iso_created,
                             "ISO creation failed"
                             )
        self.cleanup.append(iso_created)
        # Listing all the ISO's for a User
        list_iso_after = Iso.list(
                                  self.userapiclient,
                                  listall=self.services["listall"],
                                  isofilter=self.services["templatefilter"]
                                  )
        status = validateList(list_iso_after)
        self.assertEquals(
                          PASS,
                          status[0],
                          "ISO's creation failed"
                          )
        # Verifying that list size is 1
        self.assertEquals(
                          1,
                          len(list_iso_after),
                          "Failed to create an ISO's"
                          )
        # Verifying the state of the ISO to be ready. If not waiting for state to become ready
        iso_ready = False
        count = 0
        while iso_ready is False:
            list_iso = Iso.list(
                                self.userapiclient,
                                listall=self.services["listall"],
                                isofilter=self.services["templatefilter"],
                                id=iso_created.id
                                )
            status = validateList(list_iso)
            self.assertEquals(
                              PASS,
                              status[0],
                              "Failed to list ISO by Id"
                              )
            if list_iso[0].isready is True:
                iso_ready = True
            elif (str(list_iso[0].status) == "Error"):
                self.fail("Created ISO is in Errored state")
                break
            elif count > 10:
                self.fail("Timed out before ISO came into ready state")
                break
            else:
                time.sleep(self.services["sleep"])
                count = count + 1

        # Downloading the ISO
        download_iso = Iso.extract(
                                   self.userapiclient,
                                   iso_created.id,
                                   mode="HTTP_DOWNLOAD",
                                   zoneid=self.zone.id
                                   )
        self.assertIsNotNone(
                             download_iso,
                             "Download ISO failed"
                             )
         # Verifying the details of downloaded ISO
        self.assertEquals(
                          "DOWNLOAD_URL_CREATED",
                          download_iso.state,
                          "Download URL not created for ISO"
                          )
        self.assertIsNotNone(
                             download_iso.url,
                             "Download URL not created for ISO"
                             )
        self.assertEquals(
                          iso_created.id,
                          download_iso.id,
                          "Download ISO details are not same as ISO created"
                          )
        del self.services["iso"]["zoneid"]
        del self.services["iso"]["isextractable"]
        return
コード例 #23
0
    def test_10_attachAndDetach_iso(self):
        """Test for attach and detach ISO to virtual machine"""

        # Validate the following
        # 1. Create ISO
        # 2. Attach ISO to VM
        # 3. Log in to the VM.
        # 4. The device should be available for use
        # 5. Detach ISO
        # 6. Check the device is properly detached by logging into VM

        iso = Iso.create(
                         self.apiclient,
                         self.services["iso1"],
                         account=self.account.name,
                         domainid=self.account.domainid
                         )

        self.debug("Successfully created ISO with ID: %s" % iso.id)
        try:
            iso.download(self.apiclient)
        except Exception as e:
            self.fail("Exception while downloading ISO %s: %s"\
                      % (iso.id, e))

        self.debug("Attach ISO with ID: %s to VM ID: %s" % (
                                                    iso.id,
                                                    self.virtual_machine.id
                                                    ))
        #Attach ISO to virtual machine
        cmd = attachIso.attachIsoCmd()
        cmd.id = iso.id
        cmd.virtualmachineid = self.virtual_machine.id
        self.apiclient.attachIso(cmd)

        try:
            ssh_client = self.virtual_machine.get_ssh_client()
        except Exception as e:
            self.fail("SSH failed for virtual machine: %s - %s" %
                                (self.virtual_machine.ipaddress, e))

        mount_dir = "/mnt/tmp"
        cmds = "mkdir -p %s" % mount_dir
        self.assert_(ssh_client.execute(cmds) == [], "mkdir failed within guest")

        for diskdevice in self.services["diskdevice"]:
            res = ssh_client.execute("mount -rt iso9660 {} {}".format(diskdevice, mount_dir))
            if res == []:
                self.services["mount"] = diskdevice
                break
        else:
            self.fail("No mount points matched. Mount was unsuccessful")

        c = "mount |grep %s|head -1" % self.services["mount"]
        res = ssh_client.execute(c)
        size = ssh_client.execute("du %s | tail -1" % self.services["mount"])
        self.debug("Found a mount point at %s with size %s" % (res, size))

        # Get ISO size
        iso_response = Iso.list(
                                 self.apiclient,
                                 id=iso.id
                                 )
        self.assertEqual(
                            isinstance(iso_response, list),
                            True,
                            "Check list response returns a valid list"
                        )

        try:
            #Unmount ISO
            command = "umount %s" % mount_dir
            ssh_client.execute(command)
        except Exception as e:
            self.fail("SSH failed for virtual machine: %s - %s" %
                                (self.virtual_machine.ipaddress, e))

        #Detach from VM
        cmd = detachIso.detachIsoCmd()
        cmd.virtualmachineid = self.virtual_machine.id
        self.apiclient.detachIso(cmd)

        try:
            res = ssh_client.execute(c)
        except Exception as e:
            self.fail("SSH failed for virtual machine: %s - %s" %
                                (self.virtual_machine.ipaddress, e))

        # Check if ISO is properly detached from VM (using fdisk)
        result = self.services["mount"] in str(res)

        self.assertEqual(
                         result,
                         False,
                         "Check if ISO is detached from virtual machine"
                         )
        return
コード例 #24
0
    def test_03_edit_iso_details(self):
        """
        @Desc: Test to Edit ISO name, displaytext, OSType
        @steps:
        Step1: Listing all the ISO's for a user
        Step2: Verifying that no ISO's are listed
        Step3: Creating an ISO
        Step4: Listing all the ISO's again for a user
        Step5: Verifying that list size is 1
        Step6: Verifying if the ISO is in ready state.
                If yes the continuing
                If not waiting and checking for template to be ready till timeout
        Step7: Editing the ISO's name, displaytext
        Step8: Verifying that ISO name and displaytext are edited
        Step9: Editing the ISO name, displaytext, ostypeid
        Step10: Verifying that ISO name, displaytext and ostypeid are edited
        """
        # Listing all the ISO's for a User
        list_iso_before = Iso.list(
                                   self.userapiclient,
                                   listall=self.services["listall"],
                                   isofilter=self.services["templatefilter"]
                                   )
        # Verifying that no ISOs are listed
        self.assertIsNone(
                          list_iso_before,
                          "ISOs listed for newly created User"
                          )
        self.services["iso"]["zoneid"] = self.zone.id
        # Creating an ISO's
        iso_created = Iso.create(
                                 self.userapiclient,
                                 self.services["iso"]
                                 )
        self.assertIsNotNone(
                             iso_created,
                             "ISO creation failed"
                             )
        self.cleanup.append(iso_created)
        # Listing all the ISO's for a User
        list_iso_after = Iso.list(
                                  self.userapiclient,
                                  listall=self.services["listall"],
                                  isofilter=self.services["templatefilter"]
                                  )
        status = validateList(list_iso_after)
        self.assertEquals(
                          PASS,
                          status[0],
                          "ISO's creation failed"
                          )
        # Verifying that list size is 1
        self.assertEquals(
                          1,
                          len(list_iso_after),
                          "Failed to create an ISO's"
                          )
        # Verifying the state of the ISO to be ready. If not waiting for state to become ready
        iso_ready = False
        count = 0
        while iso_ready is False:
            list_iso = Iso.list(
                                self.userapiclient,
                                listall=self.services["listall"],
                                isofilter=self.services["templatefilter"],
                                id=iso_created.id
                                )
            status = validateList(list_iso)
            self.assertEquals(
                              PASS,
                              status[0],
                              "Failed to list ISO by Id"
                              )
            if list_iso[0].isready is True:
                iso_ready = True
            elif (str(list_iso[0].status) == "Error"):
                self.fail("Created ISO is in Errored state")
                break
            elif count > 10:
                self.fail("Timed out before ISO came into ready state")
                break
            else:
                time.sleep(self.services["sleep"])
                count = count + 1

        # Editing the ISO name, displaytext
        edited_iso = Iso.update(
                                iso_created,
                                self.userapiclient,
                                name="NewISOName",
                                displaytext="NewISODisplayText"
                                )
        self.assertIsNotNone(
                             edited_iso,
                             "Editing ISO failed"
                             )
         # Verifying the details of edited template
        expected_dict = {
                         "id":iso_created.id,
                         "name":"NewISOName",
                         "displaytest":"NewISODisplayText",
                         "account":iso_created.account,
                         "domainid":iso_created.domainid,
                         "isfeatured":iso_created.isfeatured,
                         "ostypeid":iso_created.ostypeid,
                         "ispublic":iso_created.ispublic,
                         }
        actual_dict = {
                       "id":edited_iso.id,
                       "name":edited_iso.name,
                       "displaytest":edited_iso.displaytext,
                       "account":edited_iso.account,
                       "domainid":edited_iso.domainid,
                       "isfeatured":edited_iso.isfeatured,
                       "ostypeid":edited_iso.ostypeid,
                       "ispublic":edited_iso.ispublic,
                       }
        edit_iso_status = self.__verify_values(
                                               expected_dict,
                                               actual_dict
                                               )
        self.assertEqual(
                         True,
                         edit_iso_status,
                         "Edited ISO details are not as expected"
                         )
        # Editing the ISO name, displaytext, ostypeid
        ostype_list = list_os_types(self.userapiclient)
        status = validateList(ostype_list)
        self.assertEquals(
                          PASS,
                          status[0],
                          "Failed to list OS Types"
                          )
        for i in range(0, len(ostype_list)):
            if ostype_list[i].id != iso_created.ostypeid:
                newostypeid = ostype_list[i].id
                break

        edited_iso = Iso.update(
                                iso_created,
                                self.userapiclient,
                                name=iso_created.name,
                                displaytext=iso_created.displaytext,
                                ostypeid=newostypeid
                                )
        self.assertIsNotNone(
                             edited_iso,
                             "Editing ISO failed"
                             )
        # Verifying the details of edited template
        expected_dict = {
                         "id":iso_created.id,
                         "name":iso_created.name,
                         "displaytest":iso_created.displaytext,
                         "account":iso_created.account,
                         "domainid":iso_created.domainid,
                         "isfeatured":iso_created.isfeatured,
                         "ostypeid":newostypeid,
                         "ispublic":iso_created.ispublic,
                         }
        actual_dict = {
                       "id":edited_iso.id,
                       "name":edited_iso.name,
                       "displaytest":edited_iso.displaytext,
                       "account":edited_iso.account,
                       "domainid":edited_iso.domainid,
                       "isfeatured":edited_iso.isfeatured,
                       "ostypeid":edited_iso.ostypeid,
                       "ispublic":edited_iso.ispublic,
                       }
        edit_iso_status = self.__verify_values(
                                               expected_dict,
                                               actual_dict
                                               )
        self.assertEqual(
                         True,
                         edit_iso_status,
                         "Edited ISO details are not as expected"
                         )
        del self.services["iso"]["zoneid"]
        return
コード例 #25
0
    def test_10_attachAndDetach_iso(self):
        """Test for attach and detach ISO to virtual machine"""

        # Validate the following
        # 1. Create ISO
        # 2. Attach ISO to VM
        # 3. Log in to the VM.
        # 4. The device should be available for use
        # 5. Detach ISO
        # 6. Check the device is properly detached by logging into VM

        iso = Iso.create(self.apiclient,
                         self.services["iso1"],
                         account=self.account.name,
                         domainid=self.account.domainid)

        self.debug("Successfully created ISO with ID: %s" % iso.id)
        try:
            iso.download(self.apiclient)
        except Exception as e:
            self.fail("Exception while downloading ISO %s: %s"\
                      % (iso.id, e))

        self.debug("Attach ISO with ID: %s to VM ID: %s" %
                   (iso.id, self.virtual_machine.id))
        #Attach ISO to virtual machine
        cmd = attachIso.attachIsoCmd()
        cmd.id = iso.id
        cmd.virtualmachineid = self.virtual_machine.id
        self.apiclient.attachIso(cmd)

        try:
            ssh_client = self.virtual_machine.get_ssh_client()
        except Exception as e:
            self.fail("SSH failed for virtual machine: %s - %s" %
                      (self.virtual_machine.ipaddress, e))

        mount_dir = "/mnt/tmp"
        cmds = "mkdir -p %s" % mount_dir
        self.assert_(
            ssh_client.execute(cmds) == [], "mkdir failed within guest")

        for diskdevice in self.services["diskdevice"]:
            res = ssh_client.execute("mount -rt iso9660 {} {}".format(
                diskdevice, mount_dir))
            if res == []:
                self.services["mount"] = diskdevice
                break
        else:
            self.fail("No mount points matched. Mount was unsuccessful")

        c = "mount |grep %s|head -1" % self.services["mount"]
        res = ssh_client.execute(c)
        size = ssh_client.execute("du %s | tail -1" % self.services["mount"])
        self.debug("Found a mount point at %s with size %s" % (res, size))

        # Get ISO size
        iso_response = Iso.list(self.apiclient, id=iso.id)
        self.assertEqual(isinstance(iso_response, list), True,
                         "Check list response returns a valid list")

        try:
            #Unmount ISO
            command = "umount %s" % mount_dir
            ssh_client.execute(command)
        except Exception as e:
            self.fail("SSH failed for virtual machine: %s - %s" %
                      (self.virtual_machine.ipaddress, e))

        #Detach from VM
        cmd = detachIso.detachIsoCmd()
        cmd.virtualmachineid = self.virtual_machine.id
        self.apiclient.detachIso(cmd)

        try:
            res = ssh_client.execute(c)
        except Exception as e:
            self.fail("SSH failed for virtual machine: %s - %s" %
                      (self.virtual_machine.ipaddress, e))

        # Check if ISO is properly detached from VM (using fdisk)
        result = self.services["mount"] in str(res)

        self.assertEqual(result, False,
                         "Check if ISO is detached from virtual machine")
        return
    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