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_04_create_template_snapshot(self):
        """Test create snapshot and templates from volume

        # Validate the following
        1. Create parent domain with two child sub-domains (and their admin accounts)
        Follow these steps for both the domains
        # 1. Create template from snapshot and verify secondary storage resource count
        # 2. Create Volume from Snapshot and verify primary storage resource count
        # 3. Attach volume to instance which was created from snapshot and
        #    verify primary storage resource count
        # 4. Detach volume from instance which was created from snapshot and
        #    verify the primary storage resource count
        # 5. Delete volume which was created from snapshot and verify primary storage
             resource count"""

        if self.hypervisor.lower() in ['hyperv']:
            self.skipTest("Snapshots feature is not supported on Hyper-V")

        result = self.setupAccounts()
        if result[0] == FAIL:
            self.fail("Failure while setting up accounts and domains: %s" %
                      result[1])
        users = result[2]

        for domain, admin in users.items():
            self.account = admin
            self.domain = domain

            try:
                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)

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

                templatesize = (self.template.size / (1024**3))

                initialResourceCount = expectedCount = templatesize + \
                    self.disk_offering.disksize
                result = isDomainResourceCountEqualToExpectedCount(
                    self.apiclient, self.domain.id, initialResourceCount,
                    RESOURCE_PRIMARY_STORAGE)
                self.assertFalse(result[0], result[1])
                self.assertTrue(result[2], "Resource count does not match")

                vm.stop(self.apiclient)

                response = createSnapshotFromVirtualMachineVolume(
                    apiclient, self.account, vm.id)
                self.assertEqual(response[0], PASS, response[1])
                snapshot = response[1]

                response = snapshot.validateState(apiclient,
                                                  Snapshot.BACKED_UP)
                self.assertEqual(response[0], PASS, response[1])

                self.services["volume"]["size"] = self.services[
                    "disk_offering"]["disksize"]
                volume = Volume.create_from_snapshot(
                    apiclient,
                    snapshot_id=snapshot.id,
                    services=self.services["volume"],
                    account=self.account.name,
                    domainid=self.account.domainid)
                volumeSize = (volume.size / (1024**3))
                vm.attach_volume(apiclient, volume)
                expectedCount = initialResourceCount + (volumeSize)
                result = isDomainResourceCountEqualToExpectedCount(
                    self.apiclient, self.domain.id, expectedCount,
                    RESOURCE_PRIMARY_STORAGE)
                self.assertFalse(result[0], result[1])
                self.assertTrue(result[2], "Resource count does not match")

                expectedCount -= volumeSize
                vm.detach_volume(apiclient, volume)
                result = isDomainResourceCountEqualToExpectedCount(
                    self.apiclient, self.domain.id, expectedCount,
                    RESOURCE_PRIMARY_STORAGE)
                self.assertFalse(result[0], result[1])
                self.assertTrue(result[2], "Resource count does not match")

                volume.delete(apiclient)
                result = isDomainResourceCountEqualToExpectedCount(
                    self.apiclient, self.domain.id, expectedCount,
                    RESOURCE_PRIMARY_STORAGE)
                self.assertFalse(result[0], result[1])
                self.assertTrue(result[2], "Resource count does not match")
            except Exception as e:
                self.fail("Failed with exception : %s" % e)
        return
Example #4
0
    def test_create_template_snapshot(self, value):
        """Test create snapshot and templates from volume

        # Validate the following
        # 1. Deploy VM with custoom disk offering and check the
        #    primary storage resource count
        # 2. Stop the VM and create Snapshot from VM's volume
        # 3. Create volume againt from this snapshto and attach to VM
        # 4. Verify that primary storage count increases by the volume size
        # 5. Detach and delete volume, verify primary storage count decreaes by volume size"""
        if self.hypervisor.lower() in ['hyperv']:
            self.skipTest("Snapshots feature is not supported on Hyper-V")
        response = self.setupAccount(value)
        self.debug(response[0])
        self.debug(response[1])
        self.assertEqual(response[0], PASS, response[1])

        apiclient = self.apiclient
        if value == CHILD_DOMAIN_ADMIN:
            apiclient = self.testClient.getUserApiClient(
                                        UserName=self.account.name,
                                        DomainName=self.account.domain
                                        )
            self.assertNotEqual(apiclient, FAIL, "Failure while getting api\
                    client of account: %s" % self.account.name)

        try:
            self.virtualMachine.stop(apiclient)
        except Exception as e:
            self.fail("Failed to stop instance: %s" % e)
        expectedCount = self.initialResourceCount
        response = matchResourceCount(
                        self.apiclient, expectedCount,
                        RESOURCE_PRIMARY_STORAGE,
                        accountid=self.account.id)
        self.assertEqual(response[0], PASS, response[1])

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

        try:
            self.services["volume"]["size"] = self.services["disk_offering"]["disksize"]
            volume = Volume.create_from_snapshot(apiclient,
                                        snapshot_id=snapshot.id,
                                        services=self.services["volume"],
                                        account=self.account.name,
                                        domainid=self.account.domainid)

            self.debug("Attaching the volume to vm: %s" % self.virtualMachine.name)
            self.virtualMachine.attach_volume(apiclient, volume)
        except Exception as e:
            self.fail("Failure in volume operation: %s" % e)

        expectedCount += int(self.services["volume"]["size"])
        response = matchResourceCount(
                        self.apiclient, expectedCount,
                        RESOURCE_PRIMARY_STORAGE,
                        accountid=self.account.id)
        self.assertEqual(response[0], PASS, response[1])

        try:
            self.virtualMachine.detach_volume(apiclient, volume)
        except Exception as e:
            self.fail("Failure in detach volume operation: %s" % e)

        try:
            self.debug("deleting the volume: %s" % volume.name)
            volume.delete(apiclient)
        except Exception as e:
            self.fail("Failure while deleting volume: %s" % e)

        expectedCount -= int(self.services["volume"]["size"])
        response = matchResourceCount(
                        self.apiclient, expectedCount,
                        RESOURCE_PRIMARY_STORAGE,
                        accountid=self.account.id)
        self.assertEqual(response[0], PASS, response[1])
        return
    def test_create_template_snapshot(self, value):
        """Test create snapshot and templates from volume

        # Validate the following
        # 1. Deploy VM with custoom disk offering and check the
        #    primary storage resource count
        # 2. Stop the VM and create Snapshot from VM's volume
        # 3. Create volume againt from this snapshto and attach to VM
        # 4. Verify that primary storage count increases by the volume size
        # 5. Detach and delete volume, verify primary storage count decreaes by volume size"""

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

        apiclient = self.apiclient
        if value == CHILD_DOMAIN_ADMIN:
            apiclient = self.testClient.getUserApiClient(
                UserName=self.account.name, DomainName=self.account.domain)
            self.assertNotEqual(
                apiclient, FAIL, "Failure while getting api\
                    client of account: %s" % self.account.name)

        try:
            self.virtualMachine.stop(apiclient)
        except Exception as e:
            self.fail("Failed to stop instance: %s" % e)
        expectedCount = self.initialResourceCount
        response = matchResourceCount(self.apiclient,
                                      expectedCount,
                                      RESOURCE_PRIMARY_STORAGE,
                                      accountid=self.account.id)
        self.assertEqual(response[0], PASS, response[1])

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

        try:
            self.services["volume"]["size"] = self.services["disk_offering"][
                "disksize"]
            volume = Volume.create_from_snapshot(
                apiclient,
                snapshot_id=snapshot.id,
                services=self.services["volume"],
                account=self.account.name,
                domainid=self.account.domainid)

            self.debug("Attaching the volume to vm: %s" %
                       self.virtualMachine.name)
            self.virtualMachine.attach_volume(apiclient, volume)
        except Exception as e:
            self.fail("Failure in volume operation: %s" % e)

        expectedCount += int(self.services["volume"]["size"])
        response = matchResourceCount(self.apiclient,
                                      expectedCount,
                                      RESOURCE_PRIMARY_STORAGE,
                                      accountid=self.account.id)
        self.assertEqual(response[0], PASS, response[1])

        try:
            self.virtualMachine.detach_volume(apiclient, volume)
        except Exception as e:
            self.fail("Failure in detach volume operation: %s" % e)

        response = matchResourceCount(self.apiclient,
                                      expectedCount,
                                      RESOURCE_PRIMARY_STORAGE,
                                      accountid=self.account.id)
        self.assertEqual(response[0], PASS, response[1])

        try:
            self.debug("deleting the volume: %s" % volume.name)
            volume.delete(apiclient)
        except Exception as e:
            self.fail("Failure while deleting volume: %s" % e)

        expectedCount -= int(self.services["volume"]["size"])
        response = matchResourceCount(self.apiclient,
                                      expectedCount,
                                      RESOURCE_PRIMARY_STORAGE,
                                      accountid=self.account.id)
        self.assertEqual(response[0], PASS, response[1])
        return
    def test_04_create_template_snapshot(self):
        """Test create snapshot and templates from volume

        # Validate the following
        1. Create parent domain with two child sub-domains (and their admin accounts)
        Follow these steps for both the domains
        # 1. Create template from snapshot and verify secondary storage resource count
        # 2. Create Volume from Snapshot and verify primary storage resource count
        # 3. Attach volume to instance which was created from snapshot and
        #    verify primary storage resource count
        # 4. Detach volume from instance which was created from snapshot and
        #    verify the primary storage resource count
        # 5. Delete volume which was created from snapshot and verify primary storage
             resource count"""

        result = self.setupAccounts()
        if result[0] == FAIL:
            self.fail(
                "Failure while setting up accounts and domains: %s" %
                result[1])
        users = result[2]

        for domain, admin in users.items():
            self.account = admin
            self.domain = domain

            try:
                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)

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

                templatesize = (self.template.size / (1024 ** 3))

                initialResourceCount = expectedCount = templatesize + \
                    self.disk_offering.disksize
                result = isDomainResourceCountEqualToExpectedCount(
                    self.apiclient, self.domain.id,
                    initialResourceCount, RESOURCE_PRIMARY_STORAGE)
                self.assertFalse(result[0], result[1])
                self.assertTrue(result[2], "Resource count does not match")

                vm.stop(self.apiclient)

                response = createSnapshotFromVirtualMachineVolume(
                    apiclient,
                    self.account,
                    vm.id)
                self.assertEqual(response[0], PASS, response[1])
                snapshot = response[1]

                response = snapshot.validateState(
                    apiclient,
                    Snapshot.BACKED_UP)
                self.assertEqual(response[0], PASS, response[1])

                self.services["volume"]["size"] = self.services[
                    "disk_offering"]["disksize"]
                volume = Volume.create_from_snapshot(
                    apiclient,
                    snapshot_id=snapshot.id,
                    services=self.services["volume"],
                    account=self.account.name,
                    domainid=self.account.domainid)
                volumeSize = (volume.size / (1024 ** 3))
                vm.attach_volume(apiclient, volume)
                expectedCount = initialResourceCount + (volumeSize)
                result = isDomainResourceCountEqualToExpectedCount(
                    self.apiclient, self.domain.id,
                    expectedCount, RESOURCE_PRIMARY_STORAGE)
                self.assertFalse(result[0], result[1])
                self.assertTrue(result[2], "Resource count does not match")

                expectedCount -= volumeSize
                vm.detach_volume(apiclient, volume)
                volume.delete(apiclient)
                result = isDomainResourceCountEqualToExpectedCount(
                    self.apiclient, self.domain.id,
                    expectedCount, RESOURCE_PRIMARY_STORAGE)
                self.assertFalse(result[0], result[1])
                self.assertTrue(result[2], "Resource count does not match")
            except Exception as e:
                self.fail("Failed with exception : %s" % e)
        return