Beispiel #1
0
    def test_listtemplate(self):

        # Register template under one domain admin(root/domain1->account 1)

        template_register = Template.register(self.apiclient,
                                              self.testdata["privatetemplate"],
                                              zoneid=self.zone.id,
                                              hypervisor=self.hypervisor,
                                              account=self.account1.name,
                                              domainid=self.domain1.id)

        template_register.download(self.apiclient)
        # self.cleanup.append(self.template_register)

        time.sleep(self.testdata["sleep"])
        timeout = self.testdata["timeout"]
        while True:
            listTemplateResponse = Template.list(self.apiclient,
                                                 templatefilter="all",
                                                 id=template_register.id,
                                                 account=self.account1.name,
                                                 domainid=self.domain1.id)
            status = validateList(listTemplateResponse)
            self.assertEquals(PASS, status[0], "Template creation failed")

        listtemplate = Template.list(self.apiclient,
                                     zoneid=self.zone.id,
                                     hypervisor=self.hypervisor,
                                     account=self.account2.name,
                                     domainid=self.account2.domainid,
                                     templatefilter="all")

        self.assertEqual(listtemplate, None, "Check templates are not listed")
        return
Beispiel #2
0
    def test_03_delete_template(self):
        """Test Delete template
        """

        # Validate the following:
        # 1. Create a template and verify it is shown in list templates response
        # 2. Delete the created template and again verify list template response

        # Verify template response for updated attributes
        list_template_response = Template.list(
                                    self.apiclient,
                                    templatefilter=\
                                    self.services["template"]["templatefilter"],
                                    id=self.template.id,
                                    zoneid=self.zone.id)
        self.assertEqual(
                        isinstance(list_template_response, list),
                        True,
                        "Check for list template response return valid list"
                        )

        self.assertNotEqual(
                            len(list_template_response),
                            0,
                            "Check template available in List Templates"
                        )
        template_response = list_template_response[0]

        self.assertEqual(
                            template_response.id,
                            self.template.id,
                            "Template id %s in the list is not matching with created template id %s" %
                            (template_response.id, self.template.id)
                        )

        self.debug("Deleting template: %s" % self.template)
        # Delete the template
        self.template.delete(self.apiclient)
        self.debug("Delete template: %s successful" % self.template)

        list_template_response = Template.list(
                                    self.apiclient,
                                    templatefilter=\
                                    self.services["template"]["templatefilter"],
                                    id=self.template.id,
                                    zoneid=self.zone.id
                                    )
        self.assertEqual(
                            list_template_response,
                            None,
                            "Check template available in List Templates"
                        )
        return
    def test_listtemplate(self):

        # Register template under one domain admin(root/domain1->account 1)

        template_register = Template.register(
            self.apiclient,
            self.testdata["privatetemplate"],
            zoneid=self.zone.id,
            hypervisor=self.hypervisor,
            account=self.account1.name,
            domainid=self.domain1.id)

        template_register.download(self.apiclient)

        self.download(self.apiclient, template_register.id)

        listtemplate = Template.list(
            self.apiclient,
            zoneid=self.zone.id,
            hypervisor=self.hypervisor,
            account=self.account2.name,
            domainid=self.account2.domainid,
            templatefilter="executable")

        self.assertEqual(
            listtemplate,
            None,
            "Check templates are not listed - CLOUDSTACK-10149"
        )
        return
    def test_vm_nic_adapter_vmxnet3(self):
        """

        # 1. Register a template for VMware with nicAdapter vmxnet3
        # 2. Deploy a VM using this template
        # 3. Create an isolated network
        # 4. Add network to VM
        # 5. Verify that the NIC adapter for VM for both the nics
        #    is vmxnet3
        """

        if self.hypervisor.lower() not in ["vmware"]:
            self.skipTest("This test case is written specifically\
                    for Vmware hypervisor")

        # Register a private template in the account with nic adapter vmxnet3
        template = Template.register(
            self.userapiclient,
            self.testdata["configurableData"]["vmxnet3template"],
            zoneid=self.zone.id,
            account=self.account.name,
            domainid=self.account.domainid,
            details=[{"nicAdapter": self.testdata["configurableData"]["vmxnet3template"]["nicadapter"]}]
        )
        self.cleanup.append(template)
        template.download(self.apiclient)

        templates = Template.list(
            self.userapiclient,
            listall=True,
            id=template.id,
            templatefilter="self")

        self.assertEqual(
            validateList(templates)[0],
            PASS,
            "Templates list validation failed")

        self.testdata["virtual_machine"]["zoneid"] = self.zone.id
        self.testdata["virtual_machine"]["template"] = template.id

        virtual_machine = VirtualMachine.create(
            self.apiclient,
            self.testdata["virtual_machine"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id)

        isolated_network = Network.create(
            self.apiclient,
            self.testdata["isolated_network"],
            self.account.name,
            self.account.domainid,
            networkofferingid=self.isolated_network_offering.id)

        virtual_machine.add_nic(self.apiclient, isolated_network.id)

        # TODO: Add steps to check the Nic Adapter type in VCenter
        # using VCenter APIs
        return
    def test_03_delete_template(self):
        """Test delete template
        """

        # Validate the following:
        # 1. UI should not show the deleted template
        # 2. database (vm_template table) should not contain deleted template

        self.debug("Deleting Template ID: %s" % self.template_1.id)

        self.template_1.delete(self.apiclient)

        list_template_response = Template.list(
                                    self.apiclient,
                                    templatefilter=\
                                    self.services["templatefilter"],
                                    id=self.template_1.id,
                                    account=self.account.name,
                                    domainid=self.account.domainid
                                    )
        # Verify template is deleted properly using ListTemplates
        self.assertEqual(
                         list_template_response,
                         None,
                         "Check if template exists in List Templates"
                         )
        return
    def test_08_list_system_templates(self):
        """Test System templates are not visible to normal user"""

        # Validate the following
        # 1. ListTemplates should not show 'SYSTEM' templates for normal user

        list_template_response = Template.list(
                                    self.apiclient,
                                    templatefilter='featured',
                                    account=self.user.name,
                                    domainid=self.user.domainid
                                    )
        self.assertEqual(
                            isinstance(list_template_response, list),
                            True,
                            "Check list response returns a valid list"
                        )

        self.assertNotEqual(
                            len(list_template_response),
                            0,
                            "Check template available in List Templates"
                        )

        for template in list_template_response:
            self.assertNotEqual(
                        template.templatetype,
                        'SYSTEM',
                        "ListTemplates should not list any system templates"
                        )
        return
    def test_07_list_public_templates(self):
        """Test only public templates are visible to normal user"""

        # Validate the following
        # 1. ListTemplates should show only 'public' templates for normal user

        list_template_response = Template.list(
                                    self.apiclient,
                                    templatefilter='featured',
                                    account=self.user.name,
                                    domainid=self.user.domainid
                                    )
        self.assertEqual(
                            isinstance(list_template_response, list),
                            True,
                            "Check list response returns a valid list"
                        )
        self.assertNotEqual(
                            len(list_template_response),
                            0,
                            "Check template available in List Templates"
                        )
        #Template response should list all 'public' templates
        for template in list_template_response:
            self.assertEqual(
                            template.ispublic,
                            True,
                            "ListTemplates should list only public templates"
                        )
        return
    def test_08_list_system_templates(self):
        """Test System templates are not visible to normal user"""

        # Validate the following
        # 1. ListTemplates should not show 'SYSTEM' templates for normal user

        list_template_response = Template.list(
                                    self.apiclient,
                                    templatefilter='featured',
                                    account=self.user.name,
                                    domainid=self.user.domainid
                                    )
        self.assertEqual(
                            isinstance(list_template_response, list),
                            True,
                            "Check list response returns a valid list"
                        )

        self.assertNotEqual(
                            len(list_template_response),
                            0,
                            "Check template available in List Templates"
                        )

        for template in list_template_response:
            self.assertNotEqual(
                        template.templatetype,
                        'SYSTEM',
                        "ListTemplates should not list any system templates"
                        )
        return
    def test_listtemplate(self):

        # Register template under one domain admin(root/domain1->account 1)

        template_register = Template.register(self.apiclient,
                                              self.testdata["privatetemplate"],
                                              zoneid=self.zone.id,
                                              hypervisor=self.hypervisor,
                                              account=self.account1.name,
                                              domainid=self.domain1.id)

        template_register.download(self.apiclient)

        self.download(self.apiclient, template_register.id)

        listtemplate = Template.list(self.apiclient,
                                     zoneid=self.zone.id,
                                     hypervisor=self.hypervisor,
                                     account=self.account2.name,
                                     domainid=self.account2.domainid,
                                     templatefilter="executable")

        self.assertEqual(listtemplate, None,
                         "Check templates are not listed - CLOUDSTACK-10149")
        return
    def registerTemplate(self, inProject=False):
        """Register and download template by default in the account/domain,
        in project if stated so"""

        try:
            builtin_info = get_builtin_template_info(self.apiclient, self.zone.id)
            self.services["template_2"]["url"] = builtin_info[0]
            self.services["template_2"]["hypervisor"] = builtin_info[1]
            self.services["template_2"]["format"] = builtin_info[2]

            template = Template.register(self.apiclient,
                                     self.services["template_2"],
                                     zoneid=self.zone.id,
                                     account=self.child_do_admin.name if not inProject else None,
                                     domainid=self.child_do_admin.domainid if not inProject else None,
                                     projectid=self.project.id if inProject else None)

            template.download(self.apiclient)

            templates = Template.list(self.apiclient,
                                      templatefilter=\
                                      self.services["template_2"]["templatefilter"],
                                      id=template.id)
            self.assertEqual(validateList(templates)[0], PASS,\
                             "templates list validation failed")

            self.templateSize = (templates[0].size / (1024**3))
        except Exception as e:
            return [FAIL, e]
        return [PASS, None]
    def test_07_list_public_templates(self):
        """Test only public templates are visible to normal user"""

        # Validate the following
        # 1. ListTemplates should show only 'public' templates for normal user

        list_template_response = Template.list(
                                    self.apiclient,
                                    templatefilter='featured',
                                    account=self.user.name,
                                    domainid=self.user.domainid
                                    )
        self.assertEqual(
                            isinstance(list_template_response, list),
                            True,
                            "Check list response returns a valid list"
                        )
        self.assertNotEqual(
                            len(list_template_response),
                            0,
                            "Check template available in List Templates"
                        )
        #Template response should list all 'public' templates
        for template in list_template_response:
            self.assertEqual(
                            template.ispublic,
                            True,
                            "ListTemplates should list only public templates"
                        )
        return
    def test_03_delete_template(self):
        """Test delete template
        """

        # Validate the following:
        # 1. UI should not show the deleted template
        # 2. database (vm_template table) should not contain deleted template

        self.debug("Deleting Template ID: %s" % self.template_1.id)

        self.template_1.delete(self.apiclient)

        list_template_response = Template.list(
                                    self.apiclient,
                                    templatefilter=\
                                    self.services["templatefilter"],
                                    id=self.template_1.id,
                                    account=self.account.name,
                                    domainid=self.account.domainid
                                    )
        # Verify template is deleted properly using ListTemplates
        self.assertEqual(
                         list_template_response,
                         None,
                         "Check if template exists in List Templates"
                         )
        return
    def test_02_create_template_snapshot(self, value):
        """Test create snapshot and templates from volume

        # Validate the following
        1. Create root domain/child domain admin account
        2. Deploy VM in the account
        3. Create snapshot from the virtual machine root volume
        4. Create template from the snapshot
        5. Verify that the secondary storage count of the account equals
           the size of the template"""

        response = self.setupAccount(value)
        self.assertEqual(response[0], PASS, response[1])

        self.virtualMachine = VirtualMachine.create(
            self.api_client,
            self.services["virtual_machine"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
        )

        self.assertNotEqual(self.virtualMachine, FAILED, "VM deployment failed")

        apiclient = self.testClient.getUserApiClient(UserName=self.account.name, DomainName=self.account.domain)
        self.assertNotEqual(apiclient, FAILED, "Failed to create api client for account: %s" % self.account.name)

        try:
            self.virtualMachine.stop(apiclient)
        except Exception as e:
            self.fail("Failed to stop instance: %s" % e)

        self.debug("Creating snapshot from ROOT volume: %s" % self.virtualMachine.name)
        response = createSnapshotFromVirtualMachineVolume(apiclient, self.account, self.virtualMachine.id)
        self.assertEqual(response[0], PASS, response[1])
        snapshot = response[1]

        snapshotSize = snapshot.physicalsize / (1024 ** 3)

        try:
            template = Template.create_from_snapshot(apiclient, snapshot=snapshot, services=self.services["template_2"])
        except Exception as e:
            self.fail("Failed to create template: %s" % e)

        templates = Template.list(
            apiclient, templatefilter=self.services["template_2"]["templatefilter"], id=template.id
        )
        self.assertEqual(validateList(templates)[0], PASS, "templates list validation failed")

        templateSize = templates[0].size / (1024 ** 3)

        expectedSecondaryStorageCount = int(templateSize + snapshotSize)
        response = matchResourceCount(
            self.apiclient,
            expectedSecondaryStorageCount,
            resourceType=RESOURCE_SECONDARY_STORAGE,
            accountid=self.account.id,
        )
        self.assertEqual(response[0], PASS, response[1])
        return
    def test_02_create_template_snapshot(self, value):
        """Test create snapshot and templates from volume

        # Validate the following
        1. Create root domain/child domain admin account
        2. Deploy VM in the account
        3. Create snapshot from the virtual machine root volume
        4. Create template from the snapshot
        5. Verify that the secondary storage count of the account equals
           the size of the template"""

        response = self.setupAccount(value)
        self.assertEqual(response[0], PASS, response[1])

        self.virtualMachine = VirtualMachine.create(self.api_client, self.services["virtual_machine"],
                            accountid=self.account.name, domainid=self.account.domainid,
                            serviceofferingid=self.service_offering.id)

        self.assertNotEqual(self.virtualMachine, FAILED, "VM deployment failed")

        apiclient = self.testClient.getUserApiClient(
                                UserName=self.account.name,
                                DomainName=self.account.domain)
        self.assertNotEqual(apiclient, FAILED,\
            "Failed to create api client for account: %s" % self.account.name)

        try:
            self.virtualMachine.stop(apiclient)
        except Exception as e:
            self.fail("Failed to stop instance: %s" % e)

        self.debug("Creating snapshot from ROOT volume: %s" % self.virtualMachine.name)
        response = createSnapshotFromVirtualMachineVolume(apiclient, self.account, self.virtualMachine.id)
        self.assertEqual(response[0], PASS, response[1])
        snapshot = response[1]

        snapshotSize = (snapshot.physicalsize / (1024 ** 3))

        try:
            template = Template.create_from_snapshot(apiclient,
                                        snapshot=snapshot,
                                        services=self.services["template_2"])
        except Exception as e:
            self.fail("Failed to create template: %s" % e)

        templates = Template.list(apiclient,
                                  templatefilter=\
                                  self.services["template_2"]["templatefilter"],
                                  id=template.id)
        self.assertEqual(validateList(templates)[0],PASS,\
                        "templates list validation failed")

        templateSize = (templates[0].size / (1024**3))

        expectedSecondaryStorageCount = int(templateSize + snapshotSize)
        response = matchResourceCount(self.apiclient, expectedSecondaryStorageCount,
                                      resourceType=RESOURCE_SECONDARY_STORAGE,
                                      accountid=self.account.id)
        self.assertEqual(response[0], PASS, response[1])
        return
    def test_01_create_template(self):
        """Test create public & private template
        """

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

        #Create template from Virtual machine and Volume ID
        template = Template.create(
                                self.apiclient,
                                self.services["template"],
                                self.volume.id,
                                account=self.account.name,
                                domainid=self.account.domainid
                                )
        self.cleanup.append(template)

        self.debug("Created template with ID: %s" % template.id)

        list_template_response = Template.list(
                                    self.apiclient,
                                    templatefilter=\
                                    self.services["templatefilter"],
                                    id=template.id
                                    )

        self.assertEqual(
                            isinstance(list_template_response, list),
                            True,
                            "Check list response returns a valid list"
                        )
        #Verify template response to check whether template added successfully
        self.assertNotEqual(
                            len(list_template_response),
                            0,
                            "Check template available in List Templates"
                        )
        template_response = list_template_response[0]

        self.assertEqual(
                            template_response.displaytext,
                            self.services["template"]["displaytext"],
                            "Check display text of newly created template"
                        )
        name = template_response.name
        self.assertEqual(
                            name.count(self.services["template"]["name"]),
                            1,
                            "Check name of newly created template"
                        )
        self.assertEqual(
                            template_response.ostypeid,
                            self.services["template"]["ostypeid"],
                            "Check osTypeID of newly created template"
                        )
        return
    def test_01_create_template(self):
        """Test create public & private template
        """

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

        #Create template from Virtual machine and Volume ID
        template = Template.create(
                                self.apiclient,
                                self.services["template"],
                                self.volume.id,
                                account=self.account.name,
                                domainid=self.account.domainid
                                )
        self.cleanup.append(template)

        self.debug("Created template with ID: %s" % template.id)

        list_template_response = Template.list(
                                    self.apiclient,
                                    templatefilter=\
                                    self.services["templatefilter"],
                                    id=template.id
                                    )

        self.assertEqual(
                            isinstance(list_template_response, list),
                            True,
                            "Check list response returns a valid list"
                        )
        #Verify template response to check whether template added successfully
        self.assertNotEqual(
                            len(list_template_response),
                            0,
                            "Check template available in List Templates"
                        )
        template_response = list_template_response[0]

        self.assertEqual(
                            template_response.displaytext,
                            self.services["template"]["displaytext"],
                            "Check display text of newly created template"
                        )
        name = template_response.name
        self.assertEqual(
                            name.count(self.services["template"]["name"]),
                            1,
                            "Check name of newly created template"
                        )
        self.assertEqual(
                            template_response.ostypeid,
                            self.services["template"]["ostypeid"],
                            "Check osTypeID of newly created template"
                        )
        return
Beispiel #17
0
    def test_01_register_template(self, value):
        """Test register template
        # Validate the following:
        1. Create a root domain admin/ child domain admin account
        2. Register and download a template according to hypervisor type
        3. Verify that the template is listed
        4. Verify that the secondary storage count for the account equals the size
           of the template
        5. Delete the template
        6. Verify that the secondary storage resource count of the account equals 0
       """
        response = self.setupAccount(value)
        self.assertEqual(response[0], PASS, response[1])

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

        try:
            template = Template.register(self.apiclient,
                                     self.services["template_2"],
                                     zoneid=self.zone.id,
                                     account=self.account.name,
                                     domainid=self.account.domainid,
                                     hypervisor=self.hypervisor)

            template.download(self.apiclient)
        except Exception as e:
            self.fail("Failed to register template: %s" % e)

        templates = Template.list(self.apiclient,
                                      templatefilter=\
                                      self.services["template_2"]["templatefilter"],
                                      id=template.id)
        self.assertEqual(validateList(templates)[0],PASS,\
                        "templates list validation failed")

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

        try:
            template.delete(self.apiclient)
        except Exception as e:
            self.fail("Failed to delete template: %s" % e)

        expectedCount = 0
        response = matchResourceCount(
                        self.apiclient, expectedCount,
                        RESOURCE_SECONDARY_STORAGE,
                        accountid=self.account.id)
        self.assertEqual(response[0], PASS, response[1])
        return
    def test_03_concurrent_snapshots_create_template(self):
        """Test while parent concurrent snapshot job in progress,create
            template from completed snapshot

            1.Configure the concurrent.snapshots.threshold.perhost=3
            2.Deploy a Linux VM using default CentOS template, use small
            service offering, disk offering
            3.Perform snapshot on root disk of this newly created VMs(10 vms)
            4.while parent concurrent snapshot job in progress,create template
            from completed snapshot"""

        # Validate the following
        # a.Able to create Template from snapshots
        # b.check all snapshots jobs are running concurrently on back grounds
        # c.listSnapshots should list this newly created snapshot.

        self.debug("Create virtual machine and snapshot on ROOT disk")
        self.create_Snapshot_VM()

        self.debug("Verify whether snapshots were created properly or not?")
        self.verify_Snapshots()

        self.debug("Fetch the list of snapshots belong to account: %s" %
                                                    self.account.name)
        snapshots = self.get_Snapshots_For_Account(
                                                self.account.name,
                                                self.account.domainid)
        jobs = []
        for snapshot in snapshots:
            self.debug("Create a template from snapshot: %s" % snapshot.name)
            jobs.append(self.create_Template_from_Snapshot(snapshot))


        userapiclient = self.testClient.getUserApiClient(
                                UserName=self.account.name,
                                DomainName=self.account.domain)

        # Verify IO usage by submitting the concurrent jobs
        self.testClient.submitCmdsAndWait(jobs, apiclient=userapiclient)

        self.debug("Verifying if templates are created properly or not?")
        templates = Template.list(
                            self.apiclient,
                            templatefilter=self.services["template"]["templatefilter"],
                            account=self.account.name,
                            domainid=self.account.domainid,
                            listall=True)
        self.assertNotEqual(templates,
                            None,
                            "Check if result exists in list item call")
        for template in templates:
            self.assertEqual(template.isready,
                         True,
                        "Check new template state in list templates call")

        self.debug("Test completed successfully.")
        return
Beispiel #19
0
    def test_02_list_templates_with_templatefilter_all_domain_admin(self):
        """
            Test list templates with templatefilter=all is not permitted for domain admin
        """

        domain_user_api_client = self.testClient.getUserApiClient(
                                    UserName=self.newdomain_account.name,
                                    DomainName=self.newdomain_account.domain)
        try:
            list_template_response = Template.list(domain_user_api_client, templatefilter='all')
        except Exception as e:
            self.fail("Domain admin should be able to use templatefilter='all' in listTemplates API call")
Beispiel #20
0
def get_builtin_template_info(apiclient, zoneid):
    """Returns hypervisor specific infor for templates"""

    list_template_response = Template.list(apiclient, templatefilter="featured", zoneid=zoneid)

    for b_template in list_template_response:
        if b_template.templatetype == "BUILTIN":
            break

    extract_response = Template.extract(apiclient, b_template.id, "HTTP_DOWNLOAD", zoneid)

    return extract_response.url, b_template.hypervisor, b_template.format
    def test_listtemplate(self):

        # Register template under one domain admin(root/domain1->account 1)

        template_register = Template.register(
            self.apiclient,
            self.testdata["privatetemplate"],
            zoneid=self.zone.id,
            hypervisor=self.hypervisor,
            account=self.account1.name,
            domainid=self.domain1.id,
        )

        template_register.download(self.apiclient)
        # self.cleanup.append(self.template_register)

        time.sleep(self.testdata["sleep"])
        timeout = self.testdata["timeout"]
        while True:
            listTemplateResponse = Template.list(
                self.apiclient,
                templatefilter="all",
                id=template_register.id,
                account=self.account1.name,
                domainid=self.domain1.id,
            )
            status = validateList(listTemplateResponse)
            self.assertEquals(PASS, status[0], "Template creation failed")

        listtemplate = Template.list(
            self.apiclient,
            zoneid=self.zone.id,
            hypervisor=self.hypervisor,
            account=self.account2.name,
            domainid=self.account2.domainid,
            templatefilter=self.testdata["templatefilter"],
        )

        self.assertEqual(listtemplate, None, "Check templates are not listed")
        return
Beispiel #22
0
    def test_01_list_templates_with_templatefilter_all_normal_user(self):
        """
            Test list templates with templatefilter=all is not permitted for normal user
        """

        user_api_client = self.testClient.getUserApiClient(
                                    UserName=self.account.name,
                                    DomainName=self.account.domain)
        try:
            list_template_response = Template.list(self.user_api_client, templatefilter='all')
            self.fail("Regular User is able to use templatefilter='all' in listTemplates API call")
        except Exception as e:
            self.debug("ListTemplates API with templatefilter='all' is not permitted for normal user")
    def test_01_positive_tests_vm_deploy_shared_nw(self):
        """ Positive tests for VMLC test path - Advanced Zone in Shared Network

        # 1.  List created service offering in setUpClass by name
        # 2.  List registered template with name
        # 3.  Create VM in account
        """

        # List created service offering in setUpClass by name
        listServiceOfferings = ServiceOffering.list(
            self.apiclient, name=self.service_offering_1.name, listall=True)
        self.assertEqual(
            validateList(listServiceOfferings)[0], PASS,
            "List validation failed for service offerings list")

        self.assertEqual(
            listServiceOfferings[0].name, self.service_offering_1.name,
            "Names of created service offering\
                         and listed service offering not matching")

        # List registered template with name
        listTemplates = Template.list(self.userapiclient,
                                      templatefilter="self",
                                      name=self.template.name,
                                      listall=True,
                                      zone=self.zone.id)
        self.assertEqual(
            validateList(listTemplates)[0], PASS,
            "List validation failed for templates list")

        self.assertEqual(
            listTemplates[0].name, self.template.name,
            "Names of created template and listed template\
                         not matching")

        network = CreateNetwork(self, SHARED_NETWORK)

        # Create VM in account
        self.virtual_machine = VirtualMachine.create(
            self.userapiclient,
            self.testdata["small"],
            templateid=self.template.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering_1.id,
            networkids=[
                network.id,
            ],
            zoneid=self.zone.id)
        self.cleanup.append(self.virtual_machine)
        return
Beispiel #24
0
    def test_01_positive_tests_vm_deploy_shared_nw(self):
        """ Positive tests for VMLC test path - Advanced Zone in Shared Network

        # 1.  List created service offering in setUpClass by name
        # 2.  List registered template with name
        # 3.  Create VM in account
        """

        # List created service offering in setUpClass by name
        listServiceOfferings = ServiceOffering.list(
            self.apiclient,
            name=self.service_offering_1.name,
            listall=True
        )
        self.assertEqual(validateList(listServiceOfferings)[0], PASS,
                         "List validation failed for service offerings list")

        self.assertEqual(listServiceOfferings[0].name,
                         self.service_offering_1.name,
                         "Names of created service offering\
                         and listed service offering not matching")

        # List registered template with name
        listTemplates = Template.list(
            self.userapiclient,
            templatefilter="self",
            name=self.template.name,
            listall=True,
            zone=self.zone.id)
        self.assertEqual(validateList(listTemplates)[0], PASS,
                         "List validation failed for templates list")

        self.assertEqual(listTemplates[0].name, self.template.name,
                         "Names of created template and listed template\
                         not matching")

        network = CreateNetwork(self, SHARED_NETWORK)

        # Create VM in account
        self.virtual_machine = VirtualMachine.create(
            self.userapiclient,
            self.testdata["small"],
            templateid=self.template.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering_1.id,
            networkids=[network.id, ],
            zoneid=self.zone.id
        )
        self.cleanup.append(self.virtual_machine)
        return
    def test_04_template_from_snapshot(self):
        """Create Template from snapshot
        """

        # Validate the following
        # 2. Snapshot the Root disk
        # 3. Create Template from snapshot
        # 4. Deploy Virtual machine using this template
        # 5. VM should be in running state

        userapiclient = self.testClient.getUserApiClient(UserName=self.account.name, DomainName=self.account.domain)

        volumes = Volume.list(userapiclient, virtualmachineid=self.virtual_machine.id, type="ROOT", listall=True)
        volume = volumes[0]

        self.debug("Creating a snapshot from volume: %s" % volume.id)
        # Create a snapshot of volume
        snapshot = Snapshot.create(userapiclient, volume.id, account=self.account.name, domainid=self.account.domainid)
        self.debug("Creating a template from snapshot: %s" % snapshot.id)
        # Generate template from the snapshot
        template = Template.create_from_snapshot(userapiclient, snapshot, self.services["template"])
        self.cleanup.append(template)
        # Verify created template
        templates = Template.list(
            userapiclient, templatefilter=self.services["template"]["templatefilter"], id=template.id
        )
        self.assertNotEqual(templates, None, "Check if result exists in list item call")

        self.assertEqual(templates[0].id, template.id, "Check new template id in list resources call")
        self.debug("Deploying a VM from template: %s" % template.id)
        # Deploy new virtual machine using template
        virtual_machine = VirtualMachine.create(
            userapiclient,
            self.services["virtual_machine"],
            templateid=template.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
        )
        self.cleanup.append(virtual_machine)

        vm_response = VirtualMachine.list(
            userapiclient, id=virtual_machine.id, account=self.account.name, domainid=self.account.domainid
        )
        self.assertEqual(isinstance(vm_response, list), True, "Check for list VM response return valid list")

        # Verify VM response to check whether VM deployment was successful
        self.assertNotEqual(len(vm_response), 0, "Check VMs available in List VMs response")
        vm = vm_response[0]
        self.assertEqual(vm.state, "Running", "Check the state of VM created from Template")
        return
Beispiel #26
0
    def test_05_template_permissions(self):
        """Update & Test for template permissions"""

        # Validate the following
        # 1. listTemplatePermissions returns valid
        #    permissions set for template
        # 2. permission changes should be reflected in vm_template
        #    table in database

        self.debug("Updating Template permissions ID:%s" % self.template_2.id)

        cmd = updateTemplatePermissions.updateTemplatePermissionsCmd()
        # Update template permissions
        cmd.id = self.template_2.id
        cmd.isfeatured = self.services["isfeatured"]
        cmd.ispublic = self.services["ispublic"]
        cmd.isextractable = self.services["isextractable"]
        self.apiclient.updateTemplatePermissions(cmd)

        list_template_response = Template.list(
                                    self.apiclient,
                                    templatefilter='featured',
                                    id=self.template_2.id,
                                    account=self.account.name,
                                    domainid=self.account.domainid
                                    )
        self.assertEqual(
                            isinstance(list_template_response, list),
                            True,
                            "Check list response returns a valid list"
                        )
        # Verify template response for updated permissions for normal user
        template_response = list_template_response[0]

        self.assertEqual(
                            template_response.id,
                            self.template_2.id,
                            "Check template ID"
                        )
        self.assertEqual(
                            template_response.ispublic,
                            int(True),
                            "Check ispublic permission of template"
                        )

        self.assertNotEqual(
                        template_response.templatetype,
                        'SYSTEM',
                        "ListTemplates should not list any system templates"
                        )
        return
    def test_05_template_permissions(self):
        """Update & Test for template permissions"""

        # Validate the following
        # 1. listTemplatePermissions returns valid
        #    permissions set for template
        # 2. permission changes should be reflected in vm_template
        #    table in database

        self.debug("Updating Template permissions ID:%s" % self.template_2.id)

        cmd = updateTemplatePermissions.updateTemplatePermissionsCmd()
        # Update template permissions
        cmd.id = self.template_2.id
        cmd.isfeatured = self.services["isfeatured"]
        cmd.ispublic = self.services["ispublic"]
        cmd.isextractable = self.services["isextractable"]
        self.apiclient.updateTemplatePermissions(cmd)

        list_template_response = Template.list(
                                    self.apiclient,
                                    templatefilter='featured',
                                    id=self.template_2.id,
                                    account=self.account.name,
                                    domainid=self.account.domainid
                                    )
        self.assertEqual(
                            isinstance(list_template_response, list),
                            True,
                            "Check list response returns a valid list"
                        )
        # Verify template response for updated permissions for normal user
        template_response = list_template_response[0]

        self.assertEqual(
                            template_response.id,
                            self.template_2.id,
                            "Check template ID"
                        )
        self.assertEqual(
                            template_response.ispublic,
                            int(True),
                            "Check ispublic permission of template"
                        )

        self.assertNotEqual(
                        template_response.templatetype,
                        'SYSTEM',
                        "ListTemplates should not list any system templates"
                        )
        return
    def test_02_check_size_snapshotTemplate(self):
        """TS_BUG_010-Test check size of snapshot and template
        """

        # Validate the following
        # 1. Deploy VM using default template, small service offering
        #    and small data disk offering.
        # 2. Perform snapshot on the root disk of this VM.
        # 3. Create a template from snapshot.
        # 4. Check the size of snapshot and template

        # Create a snapshot from the ROOTDISK
        snapshot = Snapshot.create(self.apiclient,
                                   self.volume.id,
                                   account=self.account.name,
                                   domainid=self.account.domainid)
        self.debug("Created snapshot with ID: %s" % snapshot.id)
        snapshots = Snapshot.list(self.apiclient, id=snapshot.id)
        self.assertEqual(isinstance(snapshots, list), True,
                         "Check list response returns a valid list")
        self.assertNotEqual(snapshots, None,
                            "Check if result exists in list snapshots call")
        self.assertEqual(snapshots[0].id, snapshot.id,
                         "Check snapshot id in list resources call")

        # Generate template from the snapshot
        template = Template.create_from_snapshot(self.apiclient, snapshot,
                                                 self.services["template"])
        self.cleanup.append(template)

        self.debug("Created template from snapshot with ID: %s" % template.id)
        templates = Template.list(
                                self.apiclient,
                                templatefilter=\
                                self.services["template"]["templatefilter"],
                                id=template.id
                                )
        self.assertEqual(isinstance(templates, list), True,
                         "Check list response returns a valid list")
        self.assertNotEqual(templates, None,
                            "Check if result exists in list item call")

        self.assertEqual(templates[0].isready, True,
                         "Check new template state in list templates call")
        # check size of template with that of snapshot
        self.assertEqual(
            templates[0].size, self.volume.size,
            "Derived template size (%s) does not match snapshot size (%s)" %
            (templates[0].size, self.volume.size))
        return
Beispiel #29
0
    def test_02_list_templates_with_templatefilter_all_domain_admin(self):
        """
            Test list templates with templatefilter=all is not permitted for domain admin
        """

        domain_user_api_client = self.testClient.getUserApiClient(
            UserName=self.newdomain_account.name,
            DomainName=self.newdomain_account.domain)
        try:
            list_template_response = Template.list(domain_user_api_client,
                                                   templatefilter='all')
        except Exception as e:
            self.fail(
                "Domain admin should be able to use templatefilter='all' in listTemplates API call"
            )
Beispiel #30
0
 def test_02_list_templates(self):
     """Test listing Templates using 'ids' parameter
     """
     list_template_response = Template.list(
         self.apiclient,
         templatefilter='all',
         ids=[self.template_1.id, self.template_2.id, self.template_3.id],
         account=self.account.name,
         domainid=self.account.domainid,
         listAll=True)
     self.assertEqual(isinstance(list_template_response, list), True,
                      "ListTemplates response was not a valid list")
     self.assertEqual(
         len(list_template_response), 3,
         "ListTemplates response expected 3 Templates, received %s" %
         len(list_template_response))
Beispiel #31
0
    def test_01_list_templates_with_templatefilter_all_normal_user(self):
        """
            Test list templates with templatefilter=all is not permitted for normal user
        """

        user_api_client = self.testClient.getUserApiClient(
            UserName=self.account.name, DomainName=self.account.domain)
        try:
            list_template_response = Template.list(user_api_client,
                                                   templatefilter='all')
            self.fail(
                "Regular User is able to use templatefilter='all' in listTemplates API call"
            )
        except Exception as e:
            self.debug(
                "ListTemplates API with templatefilter='all' is not permitted for normal user"
            )
Beispiel #32
0
def get_builtin_template_info(apiclient, zoneid):
    """Returns hypervisor specific infor for templates"""

    list_template_response = Template.list(
        apiclient,
        templatefilter='featured',
        zoneid=zoneid,
    )

    for b_template in list_template_response:
        if b_template.templatetype == 'BUILTIN':
            break

    extract_response = Template.extract(apiclient, b_template.id,
                                        'HTTP_DOWNLOAD', zoneid)

    return extract_response.url, b_template.hypervisor, b_template.format
Beispiel #33
0
    def download(self, apiclient, template_id, retries=12, interval=5):
        """Check if template download will finish in 1 minute"""
        while retries > -1:
            time.sleep(interval)
            template_response = Template.list(
                apiclient,
                id=template_id,
                zoneid=self.zone.id,
                templatefilter='self'
            )

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

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

                elif template.status == 'Download Complete' and template.isready:
                    return

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

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

            else:
                retries = retries - 1
        raise Exception("Template download failed exception.")
    def download(self, apiclient, template_id, retries=12, interval=5):
        """Check if template download will finish in 1 minute"""
        while retries > -1:
            time.sleep(interval)
            template_response = Template.list(apiclient,
                                              id=template_id,
                                              zoneid=self.zone.id,
                                              templatefilter='self')

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

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

                elif template.status == 'Download Complete' and template.isready:
                    return

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

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

            else:
                retries = retries - 1
        raise Exception("Template download failed exception.")
 def test_02_list_templates(self):
     """Test listing Templates using 'ids' parameter
     """
     list_template_response = Template.list(
                                 self.apiclient,
                                 templatefilter='all',
                                 ids=[self.template_1.id, self.template_2.id, self.template_3.id],
                                 account=self.account.name,
                                 domainid=self.account.domainid,
                                 listAll=True
                                 )
     self.assertEqual(
         isinstance(list_template_response, list),
         True,
         "ListTemplates response was not a valid list"
     )
     self.assertEqual(
         len(list_template_response),
         3,
         "ListTemplates response expected 3 Templates, received %s" % len(list_template_response)
     )
Beispiel #36
0
    def waitForTemplateReadyState(cls, template_id, retries=30, interval=60):
        """Check if template download will finish"""
        while retries > 0:
            time.sleep(interval)
            template_response = Template.list(
                cls.apiclient,
                id=template_id,
                zoneid=cls.zone.id,
                templatefilter='self'
            )

            if isinstance(template_response, list):
                template = template_response[0]
                if not hasattr(template, 'status') or not template or not template.status:
                    retries = retries - 1
                    continue
                if 'Failed' == template.status:
                    raise Exception("Failed to download template: status - %s" % template.status)
                elif template.status == 'Download Complete' and template.isready:
                    return
            retries = retries - 1
        raise Exception("Template download timed out")
    def test_04_copy_template(self, value):
        """Test copy template between zones

        Steps and validations:
        This test requires at least two zones present in the setup
        1. Create a root domain/child domain admin account
        2. Register and download a template in the account
        3. Verify the secondary storage resource count of the account
           equals the size of the template
        4. Copy this template to other zone
        5. Verify that the secondary storage resource count is now doubled
           as there are two templates now in two zones under the admin account
        """

        zones = list_zones(self.apiclient)
        self.assertEqual(validateList(zones)[0], PASS, "zones list validation faield")

        if len(zones) < 2:
            self.skipTest("At least 2 zones should be present for this test case")

        response = self.setupAccount(value)
        self.assertEqual(response[0], PASS, response[1])

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

        try:
            template = Template.register(
                self.apiclient,
                self.services["template_2"],
                zoneid=self.zone.id,
                account=self.account.name,
                domainid=self.account.domainid,
                hypervisor=self.hypervisor,
            )

            template.download(self.apiclient)
        except Exception as e:
            self.fail("Failed to register template: %s" % e)

        templates = Template.list(
            self.apiclient, templatefilter=self.services["template_2"]["templatefilter"], id=template.id
        )
        self.assertEqual(validateList(templates)[0], PASS, "templates list validation failed")

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

        templateDestinationZoneId = None
        for zone in zones:
            if template.zoneid != zone.id:
                templateDestinationZoneId = zone.id
                break

        template.copy(self.apiclient, destzoneid=templateDestinationZoneId, sourcezoneid=template.zoneid)

        expectedCount = templateSize * 2
        response = matchResourceCount(
            self.apiclient, expectedCount, RESOURCE_SECONDARY_STORAGE, accountid=self.account.id
        )
        self.assertEqual(response[0], PASS, response[1])
        return
    def setUpClass(cls):
        testClient = super(TestXDCCPInterop, cls).getClsTestClient()
        cls.apiclient = testClient.getApiClient()
        cls.services = testClient.getParsedTestDataConfig()
        cls.hypervisor = cls.testClient.getHypervisorInfo()
        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.apiclient)
        cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())
        cls.services['mode'] = cls.zone.networktype

        hosts = list_hosts(
               cls.apiclient,
               type="Routing"
           )
   
        if hosts is None:
               raise unittest.SkipTest(
                   "There are no hypervisor's available.Check list hosts response")
        for hypervisorhost in hosts :
                    if hypervisorhost.hypervisor == "XenServer":
                        cls.uploadtemplateformat="VHD"
                        break
                    elif hypervisorhost.hypervisor== "VMware":
                        cls.uploadtemplateformat="OVA"
                        break
                    elif hypervisorhost.hypervisor== "KVM":
                       cls.uploadtemplateformat="KVM"
                    break

        if cls.uploadtemplateformat=="KVM":
            assert False, "Interop is not supported on KVM"

        cls.uploadurl=cls.services["interop"][cls.uploadtemplateformat]["url"]
  
        cls.xtemplate = get_template(
            cls.apiclient,
            cls.zone.id,
            cls.services["ostype"]
        )
        if cls.xtemplate == FAILED:
            assert False, "get_template() failed to return template with description %s" % cls.services["ostype"]

        cls.account = Account.create(
            cls.apiclient,
            cls.services["account"],
            domainid=cls.domain.id,
            admin=False
        )
        cls.debug(cls.account.id)

        cls.service_offering = ServiceOffering.create(
            cls.apiclient,
            cls.services["service_offerings"]["large"]
        )

        cls.template = get_windows_template(
            cls.apiclient,
            cls.zone.id,
            ostype_desc="Windows 8 (64-bit)")
        #cls.template = get_windows_template(cls.apiclient, cls.zone.id ,ostype_desc="Windows Server 2012 (64-bit)")

        if cls.template == FAILED:
            if "http://pleaseupdateURL/" in cls.uploadurl:
                raise unittest.SkipTest(
                    "Check Test Data file if it has the valid template URL")
            cls.template = Template.register(
                cls.apiclient,
                cls.services["interop"][cls.uploadtemplateformat],
                zoneid=cls.zone.id,
                domainid=cls.account.domainid,
                account=cls.account.name
            )
            timeout = cls.services["vgpu"]["timeout"]

            while True:
                time.sleep(cls.services["vgpu"]["sleep"]) 
                list_template_response = Template.list(
                    cls.apiclient,
                    templatefilter=cls.services["templatefilter"],
                    id=cls.template.id
                )
                if (isinstance(list_template_response, list)) is not True:
                    raise unittest.SkipTest(
                        "Check list template api response returns a valid list")

                if len(list_template_response) is None:
                    raise unittest.SkipTest(
                        "Check template registered is in List Templates")

                template_response = list_template_response[0]
                if template_response.isready:
                    break

                if timeout == 0:
                    raise unittest.SkipTest(
                        "Failed to download template(ID: %s). " %
                        template_response.id)

                timeout = timeout - 1
        cls.volume=[]

        # Set Zones and disk offerings
        cls.services["small"]["zoneid"] = cls.zone.id
        cls.services["small"]["template"] = cls.template.id

        user_data = ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(2500))
        cls.services["virtual_machine"]["userdata"] = user_data


#        cls.services["large"]["zoneid"] = cls.zone.id
#        cls.services["large"]["template"] = cls.template.id

        cls.virtual_machine = VirtualMachine.create(
            cls.apiclient,
            cls.services["small"],
            accountid=cls.account.name,
            domainid=cls.account.domainid,
            serviceofferingid=cls.service_offering.id,  
            mode=cls.services['mode'],
            startvm="false"
        )
        cls.user_api_client = cls.testClient.getUserApiClient(
            UserName=cls.account.name,
            DomainName=cls.account.domain
        )


        cls.cleanup = [
            cls.service_offering,
            cls.account
        ]
    def test_19_template_tag(self):
        """ Test creation, listing and deletion tag on templates
        """

        if self.hypervisor.lower() in ['lxc']:
            self.skipTest(
                "template creation from volume feature is not supported on %s"
                % self.hypervisor.lower())

        try:

            noffering = NetworkOffering.list(
                self.user_api_client,
                name="DefaultIsolatedNetworkOfferingWithSourceNatService")
            vm4network = Network.create(self.user_api_client,
                                        self.services["network"],
                                        accountid=self.account.name,
                                        domainid=self.account.domainid,
                                        networkofferingid=noffering[0].id,
                                        zoneid=self.zone.id)

            list_nw_response = Network.list(self.user_api_client,
                                            id=vm4network.id)
            self.assertEqual(
                isinstance(list_nw_response, list), True,
                "Check list response returns a valid networks list")

            vm_1 = VirtualMachine.create(
                self.user_api_client,
                self.services["small"],
                templateid=self.template.id,
                networkids=vm4network.id,
                serviceofferingid=self.service_offering.id,
                accountid=self.account.name,
                domainid=self.account.domainid,
                mode=self.services['mode'],
                startvm="true")
            time.sleep(600)
            self.debug("Stopping the virtual machine: %s" % vm_1.name)
            # Stop virtual machine
            vm_1.stop(self.user_api_client)
        except Exception as e:
            self.fail("Failed to stop VM: %s" % e)

        timeout = self.services["timeout"]
        while True:
            list_volume = Volume.list(self.user_api_client,
                                      virtualmachineid=vm_1.id,
                                      type='ROOT',
                                      listall=True)
            if isinstance(list_volume, list):
                break
            elif timeout == 0:
                raise Exception("List volumes failed.")

            time.sleep(5)
            timeout = timeout - 1

        self.volume = list_volume[0]

        self.debug("Creating template from ROOT disk of virtual machine: %s" %
                   vm_1.name)
        # Create template from volume
        template = Template.create(self.user_api_client,
                                   self.services["template"], self.volume.id)
        self.cleanup.append(template)
        self.debug("Created the template(%s). Now restarting the userVm: %s" %
                   (template.name, vm_1.name))
        vm_1.start(self.user_api_client)

        self.debug("Creating a tag for the template")
        tag = Tag.create(self.user_api_client,
                         resourceIds=template.id,
                         resourceType='Template',
                         tags={'OS': 'windows8'})
        self.debug("Tag created: %s" % tag.__dict__)

        tags = Tag.list(self.user_api_client,
                        listall=True,
                        resourceType='Template',
                        key='OS',
                        value='windows8')
        self.assertEqual(isinstance(tags, list), True,
                         "List tags should not return empty response")
        self.assertEqual(tags[0].value, 'windows8',
                         'The tag should have original value')

        Template.list(
            self.user_api_client,
            templatefilter=self.services["template"]["templatefilter"],
            listall=True,
            key='OS',
            value='windows8')

        self.debug("Deleting the created tag..")
        try:
            tag.delete(self.user_api_client,
                       resourceIds=template.id,
                       resourceType='Template',
                       tags={'OS': 'windows8'})
        except Exception as e:
            self.fail("Failed to delete the tag - %s" % e)

        self.debug("Verifying if tag is actually deleted!")
        tags = Tag.list(self.user_api_client,
                        listall=True,
                        resourceType='Template',
                        key='OS',
                        value='windows8')
        self.assertEqual(tags, None, "List tags should return empty response")
        return
    def setUpClass(cls):
        testClient = super(TestXDCCPInterop, cls).getClsTestClient()
        cls.apiclient = testClient.getApiClient()
        cls.services = testClient.getParsedTestDataConfig()
        cls.hypervisor = cls.testClient.getHypervisorInfo()
        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.apiclient)
        cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())
        cls.services['mode'] = cls.zone.networktype

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

        if hosts is None:
            raise unittest.SkipTest(
                "There are no hypervisor's available.Check list hosts response"
            )
        for hypervisorhost in hosts:
            if hypervisorhost.hypervisor == "XenServer":
                cls.uploadtemplateformat = "VHD"
                break
            elif hypervisorhost.hypervisor == "VMware":
                cls.uploadtemplateformat = "OVA"
                break
            elif hypervisorhost.hypervisor == "KVM":
                cls.uploadtemplateformat = "KVM"
            break

        if cls.uploadtemplateformat == "KVM":
            raise unittest.SkipTest("Interop is not supported on KVM")

        cls.uploadurl = cls.services["interop"][
            cls.uploadtemplateformat]["url"]

        cls.xtemplate = get_template(cls.apiclient, cls.zone.id,
                                     cls.services["ostype"])
        if cls.xtemplate == FAILED:
            assert False, "get_template() failed to return template with description %s" % cls.services[
                "ostype"]

        cls.account = Account.create(cls.apiclient,
                                     cls.services["account"],
                                     domainid=cls.domain.id,
                                     admin=False)
        cls.debug(cls.account.id)

        cls.service_offering = ServiceOffering.create(
            cls.apiclient, cls.services["service_offerings"]["large"])

        cls.template = get_windows_template(cls.apiclient,
                                            cls.zone.id,
                                            ostype_desc="Windows 8 (64-bit)")
        #cls.template = get_windows_template(cls.apiclient, cls.zone.id ,ostype_desc="Windows Server 2012 (64-bit)")

        if cls.template == FAILED:
            if "http://pleaseupdateURL/" in cls.uploadurl:
                raise unittest.SkipTest(
                    "Check Test Data file if it has the valid template URL")
            cls.template = Template.register(
                cls.apiclient,
                cls.services["interop"][cls.uploadtemplateformat],
                zoneid=cls.zone.id,
                domainid=cls.account.domainid,
                account=cls.account.name)
            timeout = cls.services["vgpu"]["timeout"]

            while True:
                time.sleep(cls.services["vgpu"]["sleep"])
                list_template_response = Template.list(
                    cls.apiclient,
                    templatefilter=cls.services["templatefilter"],
                    id=cls.template.id)
                if (isinstance(list_template_response, list)) is not True:
                    raise unittest.SkipTest(
                        "Check list template api response returns a valid list"
                    )

                if len(list_template_response) is None:
                    raise unittest.SkipTest(
                        "Check template registered is in List Templates")

                template_response = list_template_response[0]
                if template_response.isready:
                    break

                if timeout == 0:
                    raise unittest.SkipTest(
                        "Failed to download template(ID: %s). " %
                        template_response.id)

                timeout = timeout - 1
        cls.volume = []

        # Set Zones and disk offerings
        cls.services["small"]["zoneid"] = cls.zone.id
        cls.services["small"]["template"] = cls.template.id

        user_data = ''.join(
            random.choice(string.ascii_uppercase + string.digits)
            for x in range(2500))
        cls.services["virtual_machine"]["userdata"] = user_data

        #        cls.services["large"]["zoneid"] = cls.zone.id
        #        cls.services["large"]["template"] = cls.template.id

        cls.virtual_machine = VirtualMachine.create(
            cls.apiclient,
            cls.services["small"],
            accountid=cls.account.name,
            domainid=cls.account.domainid,
            serviceofferingid=cls.service_offering.id,
            mode=cls.services['mode'],
            startvm="false")
        cls.user_api_client = cls.testClient.getUserApiClient(
            UserName=cls.account.name, DomainName=cls.account.domain)

        cls.cleanup = [cls.service_offering, cls.account]
Beispiel #41
0
    def test_04_copy_template(self, value):
        """Test copy template between zones

        Steps and validations:
        This test requires at least two zones present in the setup
        1. Create a root domain/child domain admin account
        2. Register and download a template in the account
        3. Verify the secondary storage resource count of the account
           equals the size of the template
        4. Copy this template to other zone
        5. Verify that the secondary storage resource count is now doubled
           as there are two templates now in two zones under the admin account
        """

        zones = list_zones(self.apiclient)
        self.assertEqual(
            validateList(zones)[0], PASS, "zones list validation faield")

        if len(zones) < 2:
            self.skipTest(
                "At least 2 zones should be present for this test case")

        response = self.setupAccount(value)
        self.assertEqual(response[0], PASS, response[1])

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

        try:
            template = Template.register(self.apiclient,
                                         self.services["template_2"],
                                         zoneid=self.zone.id,
                                         account=self.account.name,
                                         domainid=self.account.domainid,
                                         hypervisor=self.hypervisor)

            template.download(self.apiclient)
        except Exception as e:
            self.fail("Failed to register template: %s" % e)

        templates = Template.list(self.apiclient,
                                      templatefilter=\
                                      self.services["template_2"]["templatefilter"],
                                      id=template.id)
        self.assertEqual(validateList(templates)[0],PASS,\
                         "templates list validation failed")

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

        templateDestinationZoneId = None
        for zone in zones:
            if template.zoneid != zone.id:
                templateDestinationZoneId = zone.id
                break

        template.copy(self.apiclient,
                      destzoneid=templateDestinationZoneId,
                      sourcezoneid=template.zoneid)

        expectedCount = (templateSize * 2)
        response = matchResourceCount(self.apiclient,
                                      expectedCount,
                                      RESOURCE_SECONDARY_STORAGE,
                                      accountid=self.account.id)
        self.assertEqual(response[0], PASS, response[1])
        return
Beispiel #42
0
    def test_09_copy_delete_template(self):
        cmd = listZones.listZonesCmd()
        zones = self.apiclient.listZones(cmd)
        if not isinstance(zones, list):
            raise Exception("Failed to find zones.")
        if len(zones) < 2:
            self.skipTest(
                "Skipping test due to there are less than two zones.")
        return

        self.sourceZone = zones[0]
        self.destZone = zones[1]

        template = Template.create(self.apiclient,
                                   self.services["template"],
                                   self.volume.id,
                                   account=self.account.name,
                                   domainid=self.account.domainid)
        self.cleanup.append(template)

        self.debug("Created template with ID: %s" % template.id)

        list_template_response = Template.list(
                                    self.apiclient,
                                    templatefilter=\
                                    self.services["templatefilter"],
                                    id=template.id
                                    )

        self.assertEqual(isinstance(list_template_response, list), True,
                         "Check list response returns a valid list")
        #Verify template response to check whether template added successfully
        self.assertNotEqual(len(list_template_response), 0,
                            "Check template available in List Templates")
        #Copy template from zone1 to zone2
        copytemplate = Template.copy(cls.apiclient,
                                     zoneid=cls.sourceZone.id,
                                     destzoneid=cls.destZone.id)
        cls._cleanup.append(cls.copytemplate)

        list_template_response = Template.list(
            self.apiclient,
            templatefilter=self.services["template"]["templatefilter"],
            id=self.template.id,
            zoneid=self.destZone.id)
        self.assertEqual(list_template_response, None,
                         "Check template available in List Templates")

        self.deltemplate = list_template_response[0]

        self.debug("Deleting template: %s" % self.deltemplate)
        # Delete the template
        self.deltemplate.delete(self.apiclient)
        self.debug("Delete template: %s successful" % self.deltemplate)

        copytemplate = Template.copy(self.apiclient,
                                     zoneid=self.sourceZone.id,
                                     destzoneid=self.destZone.id)

        removed = cls.dbclient.execute(
            "select removed from template_zone_ref where zone_id='%s' and template_id='%s';"
            % self.destZone.id, self.template.id)

        self.assertEqual(removed, NULL, "Removed state is not correct.")
        return
Beispiel #43
0
    def test_01_positive_tests_vm_operations_basic_zone(self):
        """ Positive tests for VMLC test path - Basic Zone

        # 1.  List created service offering in setUpClass by name
        # 2.  List registered template with name
        # 3.  Create VM in account
        # 4.  Enable networking for reaching to VM thorugh SSH
        # 5.  Check VM accessibility through SSH
        # 6.  Stop vm and verify vm is not accessible
        # 7.  Start vm and verify vm is not accessible
        # 8.  Reboot vm and verify vm is not accessible
        # 9.  Destroy and recover VM
        # 10. Change service offering of VM to a different service offering
        # 11. Verify that the cpuspeed, cpunumber and memory of VM matches to
        #     as specified in new service offering
            # 12. Start VM and verify VM accessibility
        # 13. Find suitable host for VM to migrate and migrate the VM
        # 14. Verify VM accessibility on new host
        """

        # List created service offering in setUpClass by name
        listServiceOfferings = ServiceOffering.list(
            self.apiclient,
            name=self.service_offering_1.name,
            listall=True
        )
        self.assertEqual(validateList(listServiceOfferings)[0], PASS,
                         "List validation failed for service offerings list")
        self.assertEqual(listServiceOfferings[0].name,
                         self.service_offering_1.name,
                         "Names of created service offering and\
                         listed service offering not matching")

        # List registered template with name
        listTemplates = Template.list(self.userapiclient,
                                      templatefilter="self",
                                      name=self.template.name,
                                      listall=True,
                                      zone=self.zone.id
                                      )

        self.assertEqual(validateList(listTemplates)[0], PASS,
                         "List validation failed for\
                         templates list")

        self.assertEqual(listTemplates[0].name, self.template.name,
                         "Names of created template and listed template\
                         not matching")

        # Enable networking for reaching to VM thorugh SSH
        security_group = SecurityGroup.create(
            self.apiclient,
            self.testdata["security_group"],
            account=self.account.name,
            domainid=self.account.domainid
        )
        self.cleanup.append(security_group)
        # Authorize Security group to SSH to VM
        security_group.authorize(
            self.apiclient,
            self.testdata["ingress_rule"],
            account=self.account.name,
            domainid=self.account.domainid
        )

        # Create VM in account
        self.virtual_machine = VirtualMachine.create(
            self.userapiclient,
            self.testdata["small"],
            templateid=self.template.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering_1.id,
            zoneid=self.zone.id,
            securitygroupids=[security_group.id, ]
        )
        self.cleanup.append(self.virtual_machine)
        # Check VM accessibility
        try:
            SshClient(host=self.virtual_machine.ssh_ip,
                      port=22,
                      user=self.virtual_machine.username,
                      passwd=self.virtual_machine.password)
        except Exception as e:
            self.fail("Exception while SSHing to VM: %s" % e)

        # Stop VM and verify VM is not accessible
        self.virtual_machine.stop(self.userapiclient)

        with self.assertRaises(Exception):
            SshClient(host=self.virtual_machine.ssh_ip,
                      port=22,
                      user=self.virtual_machine.username,
                      passwd=self.virtual_machine.password,
                      retries=0
                      )

        # Start VM and verify that it is accessible
        self.virtual_machine.start(self.userapiclient)

        try:
            SshClient(host=self.virtual_machine.ssh_ip,
                      port=22,
                      user=self.virtual_machine.username,
                      passwd=self.virtual_machine.password)
        except Exception as e:
            self.fail("Exception while SSHing to VM: %s" % e)

        # Reboot VM and verify that it is accessible
        self.virtual_machine.reboot(self.userapiclient)

        try:
            SshClient(host=self.virtual_machine.ssh_ip,
                      port=22,
                      user=self.virtual_machine.username,
                      passwd=self.virtual_machine.password)
        except Exception as e:
            self.fail("Exception while SSHing to VM: %s" % e)

        # Destroy and recover VM
        self.virtual_machine.delete(self.userapiclient, expunge=False)
        self.virtual_machine.recover(self.apiclient)

        # Change service offering of VM and verify that it is changed
        self.virtual_machine.change_service_offering(
            self.userapiclient,
            serviceOfferingId=self.service_offering_2.id
        )

        VerifyChangeInServiceOffering(self,
                                      self.virtual_machine,
                                      self.service_offering_2)

        # Start VM and verify that it is accessible
        self.virtual_machine.start(self.userapiclient)

        try:
            SshClient(host=self.virtual_machine.ssh_ip,
                      port=22,
                      user=self.virtual_machine.username,
                      passwd=self.virtual_machine.password)
        except Exception as e:
            self.fail("Exception while SSHing to VM: %s" % e)

        return
Beispiel #44
0
    def test_01_positive_tests_vm_operations_advanced_zone(self, value):
        """ Positive tests for VMLC test path - Advanced Zone

        # 1.  List created service offering in setUpClass by name
        # 2.  List registered template with name
        # 3.  Create VM in account
        # 4.  Enable networking for reaching to VM thorugh SSH
        # 5.  Check VM accessibility through SSH
        # 6.  Stop vm and verify vm is not accessible
        # 7.  Start vm and verify vm is not accessible
        # 8.  Reboot vm and verify vm is not accessible
        # 9.  Destroy and recover VM
        # 10. Change service offering of VM to a different service offering
        # 11. Verify that the cpuspeed, cpunumber and memory of VM matches to
        #     as specified in new service offering
        # 12. Start VM and verify VM accessibility
        # 13. Find suitable host for VM to migrate and migrate the VM
        # 14. Verify VM accessibility on new host
        """
        # List created service offering in setUpClass by name
        listServiceOfferings = ServiceOffering.list(
            self.apiclient,
            name=self.service_offering_1.name,
            listall=True
        )
        self.assertEqual(validateList(listServiceOfferings)[0], PASS,
                         "List validation failed for service offerings list")

        self.assertEqual(listServiceOfferings[0].name,
                         self.service_offering_1.name,
                         "Names of created service offering\
                         and listed service offering not matching")

        # List registered template with name
        listTemplates = Template.list(
            self.userapiclient,
            templatefilter="self",
            name=self.template.name,
            listall=True,
            zone=self.zone.id)
        self.assertEqual(validateList(listTemplates)[0], PASS,
                         "List validation failed for templates list")

        self.assertEqual(listTemplates[0].name, self.template.name,
                         "Names of created template and listed template\
                         not matching")

        network = CreateNetwork(self, value)

        # Create VM in account
        self.virtual_machine = VirtualMachine.create(
            self.userapiclient,
            self.testdata["small"],
            templateid=self.template.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering_1.id,
            networkids=[network.id, ],
            zoneid=self.zone.id
        )
        self.cleanup.append(self.virtual_machine)
        publicip = PublicIPAddress.create(
            self.userapiclient, accountid=self.account.name,
            zoneid=self.zone.id, domainid=self.account.domainid,
            networkid=network.id, vpcid=self.vpcid
        )

        if value == VPC_NETWORK:
            lb_rule = LoadBalancerRule.create(
                self.apiclient,
                self.testdata["vpclbrule"],
                ipaddressid=publicip.ipaddress.id,
                accountid=self.account.name,
                domainid=self.account.domainid,
                networkid=network.id,
                vpcid=self.vpcid
            )
            lb_rule.assign(self.apiclient, [self.virtual_machine])

            # Opening up the ports in VPC
            NetworkACL.create(
                self.apiclient,
                networkid=network.id,
                services=self.testdata["natrule"],
                traffictype='Ingress'
            )
        elif value == ISOLATED_NETWORK:
            FireWallRule.create(
                self.userapiclient,
                ipaddressid=publicip.ipaddress.id,
                protocol='TCP',
                cidrlist=[self.testdata["fwrule"]["cidr"]],
                startport=self.testdata["fwrule"]["startport"],
                endport=self.testdata["fwrule"]["endport"]
            )

            NATRule.create(
                self.userapiclient,
                self.virtual_machine,
                self.testdata["natrule"],
                ipaddressid=publicip.ipaddress.id,
                networkid=network.id
            )

        # Check VM accessibility
        try:
            SshClient(host=publicip.ipaddress.ipaddress,
                      port=22,
                      user=self.virtual_machine.username,
                      passwd=self.virtual_machine.password)
        except Exception as e:
            self.fail("Exception while SSHing to VM: %s" % e)

        # Stop VM and verify VM is not accessible
        self.virtual_machine.stop(self.userapiclient)

        with self.assertRaises(Exception):
            SshClient(host=publicip.ipaddress.ipaddress,
                      port=22,
                      user=self.virtual_machine.username,
                      passwd=self.virtual_machine.password,
                      retries=0)

        # Start VM and verify that it is accessible
        self.virtual_machine.start(self.userapiclient)

        try:
            SshClient(host=publicip.ipaddress.ipaddress,
                      port=22,
                      user=self.virtual_machine.username,
                      passwd=self.virtual_machine.password)
        except Exception as e:
            self.fail("Exception while SSHing to VM: %s" % e)

        # Reboot VM and verify that it is accessible
        self.virtual_machine.reboot(self.userapiclient)

        try:
            SshClient(host=publicip.ipaddress.ipaddress,
                      port=22,
                      user=self.virtual_machine.username,
                      passwd=self.virtual_machine.password)
        except Exception as e:
            self.fail("Exception while SSHing to VM: %s" % e)

        # Destroy and recover VM
        self.virtual_machine.delete(self.apiclient, expunge=False)
        self.virtual_machine.recover(self.apiclient)

        # Change service offering of VM and verify that it is changed
        self.virtual_machine.change_service_offering(
            self.userapiclient,
            serviceOfferingId=self.service_offering_2.id
        )

        VerifyChangeInServiceOffering(self,
                                      self.virtual_machine,
                                      self.service_offering_2)

        # Start VM and verify that it is accessible
        self.virtual_machine.start(self.userapiclient)

        try:
            SshClient(host=publicip.ipaddress.ipaddress,
                      port=22,
                      user=self.virtual_machine.username,
                      passwd=self.virtual_machine.password)
        except Exception as e:
            self.fail("Exception while SSHing to VM: %s" % e)

        return
    def test_03_reuse_template_name(self):
        """TS_BUG_011-Test Reusing deleted template name
        """


        # Validate the following
        # 1. Deploy VM using default template, small service offering
        #    and small data disk offering.
        # 2. Perform snapshot on the root disk of this VM.
        # 3. Create a template from snapshot.
        # 4. Delete the template and create a new template with same name
        # 5. Template should be created succesfully

        # Create a snapshot from the ROOTDISK
        snapshot = Snapshot.create(
                                   self.apiclient,
                                   self.volume.id,
                                   account=self.account.name,
                                   domainid=self.account.domainid
                                   )
        self.debug("Created snapshot with ID: %s" % snapshot.id)
        snapshots = Snapshot.list(
                                   self.apiclient,
                                   id=snapshot.id
                                   )
        self.assertEqual(
                            isinstance(snapshots, list),
                            True,
                            "Check list response returns a valid list"
                        )
        self.assertNotEqual(
                            snapshots,
                            None,
                            "Check if result exists in list snapshots call"
                            )
        self.assertEqual(
                            snapshots[0].id,
                            snapshot.id,
                            "Check snapshot id in list resources call"
                        )

        # Generate template from the snapshot
        template = Template.create_from_snapshot(
                                    self.apiclient,
                                    snapshot,
                                    self.services["template"],
                                    random_name=False
                                    )
        self.debug("Created template from snapshot: %s" % template.id)
        templates = Template.list(
                                self.apiclient,
                                templatefilter=\
                                self.services["template"]["templatefilter"],
                                id=template.id
                                )
        self.assertEqual(
                            isinstance(templates, list),
                            True,
                            "Check list response returns a valid list"
                        )
        self.assertNotEqual(
                            templates,
                            None,
                            "Check if result exists in list item call"
                            )

        self.assertEqual(
                            templates[0].isready,
                            True,
                            "Check new template state in list templates call"
                        )

        self.debug("Deleting template: %s" % template.id)
        template.delete(self.apiclient)

        # Wait for some time to ensure template state is reflected in other calls
        time.sleep(self.services["sleep"])

        # Generate template from the snapshot
        self.debug("Creating template from snapshot: %s with same name" %
                                                                template.id)
        template = Template.create_from_snapshot(
                                    self.apiclient,
                                    snapshot,
                                    self.services["template"],
                                    random_name=False
                                    )

        templates = Template.list(
                                self.apiclient,
                                templatefilter=\
                                self.services["template"]["templatefilter"],
                                id=template.id
                                )
        self.assertEqual(
                            isinstance(templates, list),
                            True,
                            "Check list response returns a valid list"
                        )
        self.assertNotEqual(
                            templates,
                            None,
                            "Check if result exists in list item call"
                            )

        self.assertEqual(
                            templates[0].name,
                            self.services["template"]["name"],
                            "Check the name of the template"
                        )
        return
    def test_16_create_template_volume(self):
        """Test Create template from volume
        """

        noffering=NetworkOffering.list(
                     self.user_api_client,
                     name="DefaultIsolatedNetworkOfferingWithSourceNatService"
                     )
        vm2network=Network.create(
                                 self.user_api_client,
                                self.services["network"],
                                accountid=self.account.name,
                                domainid=self.account.domainid,
                                networkofferingid=noffering[0].id,
                                zoneid=self.zone.id
                                 )

        list_nw_response = Network.list(
                                            self.user_api_client,
                                            id=vm2network.id
                                            )
        self.assertEqual(
                            isinstance(list_nw_response, list),
                            True,
                            "Check list response returns a valid networks list"
                        )

        templatevm = VirtualMachine.create(
                                    self.user_api_client,
                                    self.services["small"],
                                    templateid=self.template.id,
                                    accountid=self.account.name,
                                    domainid=self.account.domainid,
                                    networkids=vm2network.id,
                                    serviceofferingid=self.service_offering.id,
                                    mode=self.services['mode'],
                                    startvm="true"
                                    )
        time.sleep(600)
        vm_response = VirtualMachine.list(
                            self.user_api_client,
                            id=templatevm.id)

        self.assertNotEqual(
                            len(vm_response),
                            0,
                            "Check VMs available in List VMs response"
                        )
        vm = vm_response[0]
        self.assertEqual(
                            vm.state,
                            'Running',
                            "Check the state of VM created from Template"
                        )

        templatevm.stop(self.user_api_client,forced="false")

        vm_response = VirtualMachine.list(
                            self.user_api_client,
                            id=templatevm.id)

        vm = vm_response[0]
        self.assertEqual(
                            vm.state,
                            'Stopped',
                            "Check the state of VM is in Stopped state before creating the Template"
                        )

        list_volume_response = Volume.list(
            self.user_api_client,
            virtualmachineid=vm.id,
            type="ROOT",
            listall=True
        )

        #Create template from Virtual machine and Volume ID
        roottemplate = Template.create(
                                self.user_api_client,
                                self.services["interop"]["template"],
                                volumeid=list_volume_response[0].id,
                                account=self.account.name,
                                domainid=self.domain.id,
                                )

        time.sleep(600)

        list_template_response = Template.list(
                                    self.user_api_client,
                                    templatefilter=\
                                    self.services["templatefilter"],
                                    id=roottemplate.id
                                    )

        self.assertEqual(
                            isinstance(list_template_response, list),
                            True,
                            "Check list response returns a valid list"
                        )
        #Verify template response to check whether template added successfully
        self.assertNotEqual(
                            len(list_template_response),
                            0,
                            "Check template available in List Templates"
                        )
        template_response = list_template_response[0]

        self.assertEqual(
                            template_response.displaytext,
                            self.services["interop"]["template"]["displaytext"],
                            "Check display text of newly created template"
                        )
        name = template_response.name
        self.assertEqual(
                            name.count(self.services["interop"]["template"]["name"]),
                            1,
                            "Check name of newly created template"
                        )


        templatevm.delete(self.apiclient)
        vm2network.delete(self.user_api_client)

        vm3network=Network.create(
                                 self.user_api_client,
                                self.services["network"],
                                accountid=self.account.name,
                                domainid=self.account.domainid,
                                networkofferingid=noffering[0].id,
                                zoneid=self.zone.id
                                 )

        list_nw_response = Network.list(
                                            self.user_api_client,
                                            id=vm3network.id
                                            )
        self.assertEqual(
                            isinstance(list_nw_response, list),
                            True,
                            "Check list response returns a valid networks list"
                        )


        templatevm = VirtualMachine.create(
                                    self.user_api_client,
                                    self.services["small"],
                                    templateid=roottemplate.id,
                                    networkids=vm3network.id,
                                    serviceofferingid=self.service_offering.id,
                                    accountid=self.account.name,
                                    domainid=self.account.domainid,
                                    mode=self.services['mode'],
                                    startvm="true"
                                    )
        time.sleep(600)
        vm_response = VirtualMachine.list(
                            self.user_api_client,
                            id=templatevm.id)

        self.assertNotEqual(
                            len(vm_response),
                            0,
                            "Check VMs available in List VMs response"
                        )
        vm = vm_response[0]
        self.assertEqual(
                            vm.state,
                            'Running',
                            "Check the state of VM created from Template"
                        )

        # Delete the template
        roottemplate.delete(self.user_api_client)

        list_template_response = Template.list(
                                    self.user_api_client,
                                    templatefilter=\
                                    self.services["template"]["templatefilter"],
                                    id=roottemplate.id,
                                    zoneid=self.zone.id
                                    )
        self.assertEqual(
                            list_template_response,
                            None,
                            "Check template available in List Templates"
                        )

        templatevm.delete(self.apiclient)

        vm3network.delete(self.user_api_client)
        return
Beispiel #47
0
    def test_01_create_template(self):
        """Test create public & private template
        """
        # Validate the following:
        # 1. Upload a templates in raw img format. Create a Vm instances from
        #    raw img template.
        # 2. Upload a templates in  zip file format. Create a Vm instances from
        #    zip template.
        # 3. Upload a templates in tar format.Create a Vm instances from tar
        #    template.
        # 4. Upload a templates in tar gzip format.Create a Vm instances from
        #    tar gzip template.
        # 5. Upload a templates in  tar bzip format. Create a Vm instances from
        #    tar bzip template.
        # 6. Verify VMs & Templates is up and in ready state

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

        # Register new template
        template = Template.register(self.apiclient,
                                     self.services["templates"][0],
                                     zoneid=self.zone.id,
                                     account=self.account.name,
                                     domainid=self.account.domainid,
                                     hypervisor=self.hypervisor)
        self.debug("Registered a template of format: %s with ID: %s" %
                   (self.services["templates"][0]["format"], template.id))
        # Wait for template to download
        template.download(self.apiclient)
        self.cleanup.append(template)

        # Wait for template status to be changed across
        time.sleep(self.services["sleep"])
        timeout = self.services["timeout"]
        while True:
            list_template_response = Template.list(
                self.apiclient,
                templatefilter='all',
                id=template.id,
                zoneid=self.zone.id,
                account=self.account.name,
                domainid=self.account.domainid)
            if isinstance(list_template_response, list):
                break
            elif timeout == 0:
                raise Exception("List template failed!")

            time.sleep(5)
            timeout = timeout - 1
        #Verify template response to check whether template added successfully
        self.assertEqual(isinstance(list_template_response, list), True,
                         "Check for list template response return valid data")

        self.assertNotEqual(len(list_template_response), 0,
                            "Check template available in List Templates")

        template_response = list_template_response[0]
        self.assertEqual(
            template_response.isready, True,
            "Template state is not ready, it is %s" %
            template_response.isready)

        # Deploy new virtual machine using template
        virtual_machine = VirtualMachine.create(
            self.apiclient,
            self.services["virtual_machine"],
            templateid=template.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
            mode=self.services["mode"])
        self.debug("creating an instance with template ID: %s" % template.id)
        vm_response = VirtualMachine.list(self.apiclient,
                                          id=virtual_machine.id,
                                          account=self.account.name,
                                          domainid=self.account.domainid)
        self.assertEqual(isinstance(vm_response, list), True,
                         "Check for list VMs response after VM deployment")
        #Verify VM response to check whether VM deployment was successful
        self.assertNotEqual(len(vm_response), 0,
                            "Check VMs available in List VMs response")
        vm = vm_response[0]
        self.assertEqual(vm.state, 'Running',
                         "Check the state of VM created from Template")
        return
Beispiel #48
0
    def test_01_create_template(self):
        """Test create public & private template
        """
        # Validate the following:
        # 1. Upload a templates in raw img format. Create a Vm instances from
        #    raw img template.
        # 2. Upload a templates in  zip file format. Create a Vm instances from
        #    zip template.
        # 3. Upload a templates in tar format.Create a Vm instances from tar
        #    template.
        # 4. Upload a templates in tar gzip format.Create a Vm instances from
        #    tar gzip template.
        # 5. Upload a templates in  tar bzip format. Create a Vm instances from
        #    tar bzip template.
        # 6. Verify VMs & Templates is up and in ready state

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

        # Register new template
        template = Template.register(
            self.apiclient,
            self.services["templates"][0],
            zoneid=self.zone.id,
            account=self.account.name,
            domainid=self.account.domainid,
            hypervisor=self.hypervisor
        )
        self.debug(
            "Registered a template of format: %s with ID: %s" % (
                self.services["templates"][0]["format"],
                template.id
            ))
        # Wait for template to download
        template.download(self.apiclient)
        self.cleanup.append(template)

        # Wait for template status to be changed across
        time.sleep(self.services["sleep"])
        timeout = self.services["timeout"]
        while True:
            list_template_response = Template.list(
                self.apiclient,
                templatefilter='all',
                id=template.id,
                zoneid=self.zone.id,
                account=self.account.name,
                domainid=self.account.domainid)
            if isinstance(list_template_response, list):
                break
            elif timeout == 0:
                raise Exception("List template failed!")

            time.sleep(5)
            timeout = timeout - 1
        # Verify template response to check whether template added successfully
        self.assertEqual(
            isinstance(list_template_response, list),
            True,
            "Check for list template response return valid data"
        )

        self.assertNotEqual(
            len(list_template_response),
            0,
            "Check template available in List Templates"
        )

        template_response = list_template_response[0]
        self.assertEqual(
            template_response.isready,
            True,
            "Template state is not ready, it is %s" % template_response.isready
        )

        # Deploy new virtual machine using template
        virtual_machine = VirtualMachine.create(
            self.apiclient,
            self.services["virtual_machine"],
            templateid=template.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
            mode=self.services["mode"]
        )
        self.debug("creating an instance with template ID: %s" % template.id)
        vm_response = VirtualMachine.list(self.apiclient,
                                          id=virtual_machine.id,
                                          account=self.account.name,
                                          domainid=self.account.domainid)
        self.assertEqual(
            isinstance(vm_response, list),
            True,
            "Check for list VMs response after VM deployment"
        )
        # Verify VM response to check whether VM deployment was successful
        self.assertNotEqual(
            len(vm_response),
            0,
            "Check VMs available in List VMs response"
        )
        vm = vm_response[0]
        self.assertEqual(
            vm.state,
            'Running',
            "Check the state of VM created from Template"
        )
        return
Beispiel #49
0
    def test_04_template_from_snapshot(self):
        """Create Template from snapshot
        """

        # Validate the following
        # 2. Snapshot the Root disk
        # 3. Create Template from snapshot
        # 4. Deploy Virtual machine using this template
        # 5. VM should be in running state

        volumes = Volume.list(self.apiclient,
                              virtualmachineid=self.virtual_machine.id,
                              type='ROOT',
                              listall=True)
        volume = volumes[0]

        self.debug("Creating a snapshot from volume: %s" % volume.id)
        #Create a snapshot of volume
        snapshot = Snapshot.create(self.apiclient,
                                   volume.id,
                                   account=self.account.name,
                                   domainid=self.account.domainid)
        self.debug("Creating a template from snapshot: %s" % snapshot.id)
        # Generate template from the snapshot
        template = Template.create_from_snapshot(self.apiclient, snapshot,
                                                 self.services["template"])
        self.cleanup.append(template)
        # Verify created template
        templates = Template.list(
                                self.apiclient,
                                templatefilter=\
                                self.services["template"]["templatefilter"],
                                id=template.id
                                )
        self.assertNotEqual(templates, None,
                            "Check if result exists in list item call")

        self.assertEqual(templates[0].id, template.id,
                         "Check new template id in list resources call")
        self.debug("Deploying a VM from template: %s" % template.id)
        # Deploy new virtual machine using template
        virtual_machine = VirtualMachine.create(
            self.apiclient,
            self.services["virtual_machine"],
            templateid=template.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
        )
        self.cleanup.append(virtual_machine)

        vm_response = VirtualMachine.list(self.apiclient,
                                          id=virtual_machine.id,
                                          account=self.account.name,
                                          domainid=self.account.domainid)
        self.assertEqual(isinstance(vm_response, list), True,
                         "Check for list VM response return valid list")

        #Verify VM response to check whether VM deployment was successful
        self.assertNotEqual(len(vm_response), 0,
                            "Check VMs available in List VMs response")
        vm = vm_response[0]
        self.assertEqual(vm.state, 'Running',
                         "Check the state of VM created from Template")
        return
Beispiel #50
0
    def test_02_edit_template(self):
        """Test Edit template
        """

        # Validate the following:
        # 1. UI should show the edited values for template
        # 2. database (vm_template table) should have updated values

        new_displayText = random_gen()
        new_name = random_gen()

        cmd = updateTemplate.updateTemplateCmd()
        # Update template attributes
        cmd.id = self.template_1.id
        cmd.displaytext = new_displayText
        cmd.name = new_name
        cmd.bootable = self.services["bootable"]
        cmd.passwordenabled = self.services["passwordenabled"]

        self.apiclient.updateTemplate(cmd)

        self.debug("Edited template with new name: %s" % new_name)

        # Sleep to ensure update reflected across all the calls
        time.sleep(self.services["sleep"])

        timeout = self.services["timeout"]
        while True:
            # Verify template response for updated attributes
            list_template_response = Template.list(
                                    self.apiclient,
                                    templatefilter=\
                                    self.services["templatefilter"],
                                    id=self.template_1.id,
                                    account=self.account.name,
                                    domainid=self.account.domainid
                                    )
            if isinstance(list_template_response, list):
                break
            elif timeout == 0:
                raise Exception("List Template failed!")

            time.sleep(10)
            timeout = timeout - 1

        self.assertEqual(isinstance(list_template_response, list), True,
                         "Check list response returns a valid list")
        self.assertNotEqual(len(list_template_response), 0,
                            "Check template available in List Templates")
        template_response = list_template_response[0]

        self.debug("New Name: %s" % new_displayText)
        self.debug("Name in Template response: %s" %
                   template_response.displaytext)
        self.assertEqual(template_response.displaytext, new_displayText,
                         "Check display text of updated template")
        self.assertEqual(template_response.name, new_name,
                         "Check name of updated template")
        self.assertEqual(
            str(template_response.passwordenabled).lower(),
            str(self.services["passwordenabled"]).lower(),
            "Check passwordenabled field of updated template")
        self.assertEqual(template_response.ostypeid, self.services["ostypeid"],
                         "Check OSTypeID of updated template")
        return
    def test_16_create_template_volume(self):
        """Test Create template from volume
        """

        noffering = NetworkOffering.list(
            self.user_api_client,
            name="DefaultIsolatedNetworkOfferingWithSourceNatService")
        vm2network = Network.create(self.user_api_client,
                                    self.services["network"],
                                    accountid=self.account.name,
                                    domainid=self.account.domainid,
                                    networkofferingid=noffering[0].id,
                                    zoneid=self.zone.id)

        list_nw_response = Network.list(self.user_api_client, id=vm2network.id)
        self.assertEqual(isinstance(list_nw_response, list), True,
                         "Check list response returns a valid networks list")

        templatevm = VirtualMachine.create(
            self.user_api_client,
            self.services["small"],
            templateid=self.template.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            networkids=vm2network.id,
            serviceofferingid=self.service_offering.id,
            mode=self.services['mode'],
            startvm="true")
        time.sleep(600)
        vm_response = VirtualMachine.list(self.user_api_client,
                                          id=templatevm.id)

        self.assertNotEqual(len(vm_response), 0,
                            "Check VMs available in List VMs response")
        vm = vm_response[0]
        self.assertEqual(vm.state, 'Running',
                         "Check the state of VM created from Template")

        templatevm.stop(self.user_api_client, forced="false")

        vm_response = VirtualMachine.list(self.user_api_client,
                                          id=templatevm.id)

        vm = vm_response[0]
        self.assertEqual(
            vm.state, 'Stopped',
            "Check the state of VM is in Stopped state before creating the Template"
        )

        list_volume_response = Volume.list(self.user_api_client,
                                           virtualmachineid=vm.id,
                                           type="ROOT",
                                           listall=True)

        #Create template from Virtual machine and Volume ID
        roottemplate = Template.create(
            self.user_api_client,
            self.services["interop"]["template"],
            volumeid=list_volume_response[0].id,
            account=self.account.name,
            domainid=self.domain.id,
        )

        time.sleep(600)

        list_template_response = Template.list(
                                    self.user_api_client,
                                    templatefilter=\
                                    self.services["templatefilter"],
                                    id=roottemplate.id
                                    )

        self.assertEqual(isinstance(list_template_response, list), True,
                         "Check list response returns a valid list")
        #Verify template response to check whether template added successfully
        self.assertNotEqual(len(list_template_response), 0,
                            "Check template available in List Templates")
        template_response = list_template_response[0]

        self.assertEqual(template_response.displaytext,
                         self.services["interop"]["template"]["displaytext"],
                         "Check display text of newly created template")
        name = template_response.name
        self.assertEqual(
            name.count(self.services["interop"]["template"]["name"]), 1,
            "Check name of newly created template")

        templatevm.delete(self.apiclient)
        vm2network.delete(self.user_api_client)

        vm3network = Network.create(self.user_api_client,
                                    self.services["network"],
                                    accountid=self.account.name,
                                    domainid=self.account.domainid,
                                    networkofferingid=noffering[0].id,
                                    zoneid=self.zone.id)

        list_nw_response = Network.list(self.user_api_client, id=vm3network.id)
        self.assertEqual(isinstance(list_nw_response, list), True,
                         "Check list response returns a valid networks list")

        templatevm = VirtualMachine.create(
            self.user_api_client,
            self.services["small"],
            templateid=roottemplate.id,
            networkids=vm3network.id,
            serviceofferingid=self.service_offering.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            mode=self.services['mode'],
            startvm="true")
        time.sleep(600)
        vm_response = VirtualMachine.list(self.user_api_client,
                                          id=templatevm.id)

        self.assertNotEqual(len(vm_response), 0,
                            "Check VMs available in List VMs response")
        vm = vm_response[0]
        self.assertEqual(vm.state, 'Running',
                         "Check the state of VM created from Template")

        # Delete the template
        roottemplate.delete(self.user_api_client)

        list_template_response = Template.list(
                                    self.user_api_client,
                                    templatefilter=\
                                    self.services["template"]["templatefilter"],
                                    id=roottemplate.id,
                                    zoneid=self.zone.id
                                    )
        self.assertEqual(list_template_response, None,
                         "Check template available in List Templates")

        templatevm.delete(self.apiclient)

        vm3network.delete(self.user_api_client)
        return
Beispiel #52
0
    def test_3d_gpu_support(self):
        """

        # 1. Register a template for VMware with nicAdapter vmxnet3 and 3D GPU details
        # 2. Deploy a VM using this template
        # 3. Create an isolated network
        # 4. Add network to VM
        # 5. Verify vm details for 3D GPU details
        """

        if self.hypervisor.lower() not in ["vmware"]:
            self.skipTest("This test case is written specifically\
                    for Vmware hypervisor")

        # Register a private template in the account with nic adapter vmxnet3
        # Also add required 3D GPU details for enabling it
        template = Template.register(
            self.userapiclient,
            self.testdata["configurableData"]["vmxnet3template"],
            zoneid=self.zone.id,
            account=self.account.name,
            domainid=self.account.domainid,
            details=[{
                "mks.enable3d": "true",
                "mks.use3dRenderer": "automatic",
                "svga.autodetect": "false",
                "svga.vramSize": "131072"
            }])
        self.cleanup.append(template)
        template.download(self.apiclient)

        templates = Template.list(self.userapiclient,
                                  listall=True,
                                  id=template.id,
                                  templatefilter="self")

        self.assertEqual(
            validateList(templates)[0], PASS,
            "Templates list validation failed")

        self.testdata["virtual_machine"]["zoneid"] = self.zone.id
        self.testdata["virtual_machine"]["template"] = template.id

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

        isolated_network = Network.create(
            self.apiclient,
            self.testdata["isolated_network"],
            self.account.name,
            self.account.domainid,
            networkofferingid=self.isolated_network_offering.id)

        virtual_machine.add_nic(self.apiclient, isolated_network.id)

        qresultset = self.dbclient.execute(
            "select id from vm_instance where uuid = '%s';" %
            virtual_machine.id)
        vm_id = qresultset[0]
        qresultset = self.dbclient.execute(
            "select name, value from user_vm_details where vm_id = '%d';" %
            vm_id)
        detailKeys = [x[0] for x in qresultset]

        self.assertTrue(
            'mks.enable3d' in detailKeys and 'mks.use3dRenderer' in detailKeys
            and 'svga.autodetect' in detailKeys
            and 'svga.vramSize' in detailKeys,
            "VM details do not contain 3D GPU details")

        self.assertEquals('true',
                          qresultset[detailKeys.index('mks.enable3d')][1],
                          "Expected detail 'mks.enable3d'='true'")

        self.assertEquals('automatic',
                          qresultset[detailKeys.index('mks.use3dRenderer')][1],
                          "Expected detail 'mks.use3dRenderer'='automatic'")

        self.assertEquals('false',
                          qresultset[detailKeys.index('svga.autodetect')][1],
                          "Expected detail 'svga.autodetect'='false'")

        self.assertEquals('131072',
                          qresultset[detailKeys.index('svga.vramSize')][1],
                          "Expected detail 'svga.vramSize'='131072'")
    def test_02_check_size_snapshotTemplate(self):
        """TS_BUG_010-Test check size of snapshot and template
        """


        # Validate the following
        # 1. Deploy VM using default template, small service offering
        #    and small data disk offering.
        # 2. Perform snapshot on the root disk of this VM.
        # 3. Create a template from snapshot.
        # 4. Check the size of snapshot and template

        # Create a snapshot from the ROOTDISK
        snapshot = Snapshot.create(
                                   self.apiclient,
                                   self.volume.id,
                                   account=self.account.name,
                                   domainid=self.account.domainid
                                   )
        self.debug("Created snapshot with ID: %s" % snapshot.id)
        snapshots = Snapshot.list(
                                   self.apiclient,
                                   id=snapshot.id
                                   )
        self.assertEqual(
                            isinstance(snapshots, list),
                            True,
                            "Check list response returns a valid list"
                        )
        self.assertNotEqual(
                            snapshots,
                            None,
                            "Check if result exists in list snapshots call"
                            )
        self.assertEqual(
                            snapshots[0].id,
                            snapshot.id,
                            "Check snapshot id in list resources call"
                        )

        # Generate template from the snapshot
        template = Template.create_from_snapshot(
                                    self.apiclient,
                                    snapshot,
                                    self.services["template"]
                                    )
        self.cleanup.append(template)

        self.debug("Created template from snapshot with ID: %s" % template.id)
        templates = Template.list(
                                self.apiclient,
                                templatefilter=\
                                self.services["template"]["templatefilter"],
                                id=template.id
                                )
        self.assertEqual(
                            isinstance(templates, list),
                            True,
                            "Check list response returns a valid list"
                        )
        self.assertNotEqual(
                            templates,
                            None,
                            "Check if result exists in list item call"
                            )

        self.assertEqual(
                            templates[0].isready,
                            True,
                            "Check new template state in list templates call"
                        )
        # check size of template with that of snapshot
        self.assertEqual(
                            templates[0].size,
                            self.volume.size,
                            "Derived template size (%s) does not match snapshot size (%s)" % (templates[0].size, self.volume.size)
                        )
        return
    def test_19_template_tag(self):
        """ Test creation, listing and deletion tag on templates
        """

        try:
            
            noffering=NetworkOffering.list(
                     self.user_api_client,
                     name="DefaultIsolatedNetworkOfferingWithSourceNatService"
                     )
            vm4network=Network.create(
                                 self.user_api_client,
                                self.services["network"],
                                accountid=self.account.name,
                                domainid=self.account.domainid,
                                networkofferingid=noffering[0].id,
                                zoneid=self.zone.id
                                 )

            list_nw_response = Network.list(
                                            self.user_api_client,
                                            id=vm4network.id
                                            )
            self.assertEqual(
                            isinstance(list_nw_response, list),
                            True,
                            "Check list response returns a valid networks list"
                        )

            vm_1 = VirtualMachine.create(
                                    self.user_api_client,
                                    self.services["small"],
                                    templateid=self.template.id,
                                    networkids=vm4network.id,
                                    serviceofferingid=self.service_offering.id,
                                    accountid=self.account.name,
                                    domainid=self.account.domainid,
                                    mode=self.services['mode'],
                                    startvm="true"
                                    )
            time.sleep(600)
            self.debug("Stopping the virtual machine: %s" % vm_1.name)
            # Stop virtual machine
            vm_1.stop(self.user_api_client)
        except Exception as e:
            self.fail("Failed to stop VM: %s" % e)

        timeout = self.services["timeout"]
        while True:
            list_volume = Volume.list(
                self.user_api_client,
                virtualmachineid=vm_1.id,
                type='ROOT',
                listall=True
            )
            if isinstance(list_volume, list):
                break
            elif timeout == 0:
                raise Exception("List volumes failed.")

            time.sleep(5)
            timeout = timeout - 1

        self.volume = list_volume[0]

        self.debug("Creating template from ROOT disk of virtual machine: %s" %
                   vm_1.name)
        # Create template from volume
        template = Template.create(
            self.user_api_client,
            self.services["template"],
            self.volume.id
        )
        self.cleanup.append(template)
        self.debug("Created the template(%s). Now restarting the userVm: %s" %
                   (template.name, vm_1.name))
        vm_1.start(self.user_api_client)

        self.debug("Creating a tag for the template")
        tag = Tag.create(
            self.user_api_client,
            resourceIds=template.id,
            resourceType='Template',
            tags={'OS': 'windows8'}
        )
        self.debug("Tag created: %s" % tag.__dict__)

        tags = Tag.list(
            self.user_api_client,
            listall=True,
            resourceType='Template',
            key='OS',
            value='windows8'
        )
        self.assertEqual(
            isinstance(tags, list),
            True,
            "List tags should not return empty response"
        )
        self.assertEqual(
            tags[0].value,
            'windows8',
            'The tag should have original value'
        )

        Template.list(
            self.user_api_client,
            templatefilter=self.services["template"]["templatefilter"],
            listall=True,
            key='OS',
            value='windows8'
        )

        self.debug("Deleting the created tag..")
        try:
            tag.delete(
                self.user_api_client,
                resourceIds=template.id,
                resourceType='Template',
                tags={'OS': 'windows8'}
            )
        except Exception as e:
            self.fail("Failed to delete the tag - %s" % e)

        self.debug("Verifying if tag is actually deleted!")
        tags = Tag.list(
            self.user_api_client,
            listall=True,
            resourceType='Template',
            key='OS',
            value='windows8'
        )
        self.assertEqual(
            tags,
            None,
            "List tags should return empty response"
        )
        return
Beispiel #55
0
    def test_06_copy_template(self):
        """Test for copy template from one zone to another"""

        # Validate the following
        # 1. copy template should be successful and
        #    secondary storage should contain new copied template.

        if len(self.zones) <= 1:
            self.skipTest(
                "Not enough zones available to perform copy template")

        self.services["destzoneid"] = filter(
            lambda z: z.id != self.services["sourcezoneid"], self.zones)[0].id

        self.debug(
            "Copy template from Zone: %s to %s" %
            (self.services["sourcezoneid"], self.services["destzoneid"]))
        cmd = copyTemplate.copyTemplateCmd()
        cmd.id = self.template_2.id
        cmd.destzoneid = self.services["destzoneid"]
        cmd.sourcezoneid = self.services["sourcezoneid"]
        self.apiclient.copyTemplate(cmd)

        # Verify template is copied to another zone using ListTemplates
        list_template_response = Template.list(
                                    self.apiclient,
                                    templatefilter=\
                                    self.services["templatefilter"],
                                    id=self.template_2.id,
                                    zoneid=self.services["destzoneid"]
                                    )
        self.assertEqual(isinstance(list_template_response, list), True,
                         "Check list response returns a valid list")
        self.assertNotEqual(len(list_template_response), 0,
                            "Check template extracted in List Templates")

        template_response = list_template_response[0]
        self.assertEqual(template_response.id, self.template_2.id,
                         "Check ID of the downloaded template")
        self.assertEqual(template_response.zoneid, self.services["destzoneid"],
                         "Check zone ID of the copied template")

        # Cleanup- Delete the copied template
        timeout = self.services["timeout"]
        while True:
            time.sleep(self.services["sleep"])
            list_template_response = Template.list(
                                        self.apiclient,
                                        templatefilter=\
                                        self.services["templatefilter"],
                                        id=self.template_2.id,
                                        zoneid=self.services["destzoneid"]
                                        )
            self.assertEqual(isinstance(list_template_response, list), True,
                             "Check list response returns a valid list")
            self.assertNotEqual(len(list_template_response), 0,
                                "Check template extracted in List Templates")

            template_response = list_template_response[0]
            if template_response.isready == True:
                break

            if timeout == 0:
                raise Exception("Failed to download copied template(ID: %s)" %
                                template_response.id)

            timeout = timeout - 1
        cmd = deleteTemplate.deleteTemplateCmd()
        cmd.id = template_response.id
        cmd.zoneid = self.services["destzoneid"]
        self.apiclient.deleteTemplate(cmd)
        return
    def test_01_create_template(self):
        """TS_BUG_002-Test to create and deploy VM using password enabled template
        """


        # Validate the following:
        #1. Create a password enabled template
        #2. Deploy VM using this template
        #3. Deploy VM should return password set in template.

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

        self.debug("Registering a new template")

        # Register new template
        template = Template.register(
                                        self.apiclient,
                                        self.services["template"],
                                        zoneid=self.zone.id,
                                        account=self.account.name,
                                        domainid=self.account.domainid,
                                        hypervisor=self.hypervisor
                                        )
        self.debug(
                "Registered a template of format: %s with ID: %s" % (
                                                                self.services["template"]["format"],
                                                                template.id
                                                                ))
        try:
            # Wait for template to download
            template.download(self.apiclient)
        except Exception as e:
            self.fail("Exception while downloading template %s: %s"\
                      % (template.id, e))

        self.cleanup.append(template)

        # Wait for template status to be changed across
        time.sleep(self.services["sleep"])

        list_template_response = Template.list(
                                            self.apiclient,
                                            templatefilter=\
                                            self.services["template"]["templatefilter"],
                                            id=template.id,
                                            zoneid=self.zone.id
                                            )

        self.assertEqual(
                            isinstance(list_template_response, list),
                            True,
                            "Check list response returns a valid list"
                        )
        #Verify template response to check whether template added successfully
        self.assertNotEqual(
                            len(list_template_response),
                            0,
                            "Check template available in List Templates"
                        )
        template_response = list_template_response[0]

        self.assertEqual(
                            template_response.isready,
                            True,
                            "Template state is not ready, it is %s" % template_response.isready
                        )

        # Deploy new virtual machine using template
        virtual_machine = VirtualMachine.create(
                                 self.apiclient,
                                 self.services["virtual_machine"],
                                 templateid=template.id,
                                 accountid=self.account.name,
                                 domainid=self.account.domainid,
                                 serviceofferingid=self.service_offering.id,
                                 )
        self.debug("Deployed VM with ID: %s " % virtual_machine.id)
        self.assertEqual(
                         hasattr(virtual_machine, "password"),
                         True,
                         "Check if the deployed VM returned a password"
                        )
        return