def setupAccounts(self, account_limit=2, domain_limit=2, project_limit=2):

        self.debug("Creating a domain under: %s" % self.domain.name)
        self.child_domain = Domain.create(self.apiclient,
            services=self.testdata["domain"],
            parentdomainid=self.domain.id)

        self.debug("domain crated with domain id %s" % self.child_domain.id)

        self.child_do_admin = Account.create(self.apiclient,
            self.testdata["account"],
            admin=True,
            domainid=self.child_domain.id)

        self.debug("domain admin created for domain id %s" %
                   self.child_do_admin.domainid)

        # Create project as a domain admin
        self.project = Project.create(self.apiclient,
            self.testdata["project"],
            account=self.child_do_admin.name,
            domainid=self.child_do_admin.domainid)
        # Cleanup created project at end of test
        self.cleanup.append(self.project)

        # Cleanup accounts created
        self.cleanup.append(self.child_do_admin)
        self.cleanup.append(self.child_domain)

        self.debug("Updating the CPU resource count for domain: %s" %
                   self.child_domain.name)
        # Update resource limits for account 1
        responses = Resources.updateLimit(self.apiclient,
            resourcetype=8,
            max=account_limit,
            account=self.child_do_admin.name,
            domainid=self.child_do_admin.domainid)

        self.debug("CPU Resource count for child domain admin account is now: %s" %
                   responses.max)

        self.debug("Updating the CPU limit for project")
        responses = Resources.updateLimit(self.apiclient,
            resourcetype=8,
            max=project_limit,
            projectid=self.project.id)

        self.debug("CPU Resource count for project is now")
        self.debug(responses.max)

        self.debug("Updating the CPU limit for domain only")
        responses = Resources.updateLimit(self.apiclient,
            resourcetype=8,
            max=domain_limit,
            domainid=self.child_domain.id)

        self.debug("CPU Resource count for domain %s with id %s is now %s" %
                   (responses.domain, responses.domainid, responses.max))

        return
    def setupAccounts(self):

        self.debug("Creating a sub-domain under: %s" % self.domain.name)

        self.child_domain = Domain.create(
            self.apiclient, services=self.services["domain"], parentdomainid=self.domain.id
        )
        self.child_do_admin = Account.create(
            self.apiclient, self.services["account"], admin=True, domainid=self.child_domain.id
        )
        # Cleanup the resources created at end of test
        self.cleanup.append(self.child_do_admin)
        self.cleanup.append(self.child_domain)

        Resources.updateLimit(
            self.apiclient,
            resourcetype=8,
            max=16,
            account=self.child_do_admin.name,
            domainid=self.child_do_admin.domainid,
        )

        self.domain = Domain.create(self.apiclient, services=self.services["domain"], parentdomainid=self.domain.id)

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

        # Cleanup the resources created at end of test
        self.cleanup.append(self.admin)
        self.cleanup.append(self.domain)

        Resources.updateLimit(
            self.apiclient, resourcetype=8, max=16, account=self.admin.name, domainid=self.admin.domainid
        )
        return
    def setupAccounts(self):

        self.debug("Creating a domain under: %s" % self.domain.name)
        self.parent_domain = Domain.create(
            self.apiclient, services=self.services["domain"], parentdomainid=self.domain.id
        )
        self.parentd_admin = Account.create(
            self.apiclient, self.services["account"], admin=True, domainid=self.domain.id
        )

        self.debug("Updating the Memory resource count for domain: %s" % self.domain.name)
        Resources.updateLimit(
            self.apiclient,
            resourcetype=9,
            max=4096,
            account=self.parentd_admin.name,
            domainid=self.parentd_admin.domainid,
        )
        self.debug("Creating a sub-domain under: %s" % self.parent_domain.name)
        self.cdomain_1 = Domain.create(
            self.apiclient, services=self.services["domain"], parentdomainid=self.parent_domain.id
        )

        self.debug("Creating a sub-domain under: %s" % self.parent_domain.name)
        self.cdomain_2 = Domain.create(
            self.apiclient, services=self.services["domain"], parentdomainid=self.parent_domain.id
        )

        self.cadmin_1 = Account.create(self.apiclient, self.services["account"], admin=True, domainid=self.cdomain_1.id)

        self.debug("Updating the Memory resource count for domain: %s" % self.cdomain_1.name)
        Resources.updateLimit(self.apiclient, resourcetype=9, max=2048, domainid=self.cadmin_1.domainid)

        self.debug("Updating the Memory resource count for account: %s" % self.cadmin_1.name)
        Resources.updateLimit(
            self.apiclient, resourcetype=9, max=2048, account=self.cadmin_1.name, domainid=self.cadmin_1.domainid
        )

        self.cadmin_2 = Account.create(self.apiclient, self.services["account"], admin=True, domainid=self.cdomain_2.id)

        self.debug("Updating the Memory resource count for domain: %s" % self.cdomain_2.name)
        Resources.updateLimit(self.apiclient, resourcetype=9, max=2048, domainid=self.cadmin_2.domainid)

        self.debug("Updating the Memory resource count for domain: %s" % self.cadmin_2.name)
        Resources.updateLimit(
            self.apiclient, resourcetype=9, max=2048, account=self.cadmin_2.name, domainid=self.cadmin_2.domainid
        )

        # Cleanup the resources created at end of test
        self.cleanup.append(self.cadmin_1)
        self.cleanup.append(self.cadmin_2)
        self.cleanup.append(self.cdomain_1)
        self.cleanup.append(self.cdomain_2)
        self.cleanup.append(self.parentd_admin)
        self.cleanup.append(self.parent_domain)

        users = {self.parent_domain: self.parentd_admin, self.cdomain_1: self.cadmin_1, self.cdomain_2: self.cadmin_2}
        return users
예제 #4
0
    def test_10_max_account_limit(self):
        """ Positive test for stopped VM test path - T12

        # 1.  Create an account in root domain and set the VM limit
        #     to max 2 VMs
        # 2.  Deploy two VMs in the account with startvm parameter
        #     as false
        # 3.  Deployment of both VMs should be successful
        # 4.  Try to deploy 3rd VM with startvm False, deployment should fail
        """

        # Create an account
        account = Account.create(self.apiclient,
                                 self.testdata["account"],
                                 domainid=self.domain.id)
        self.cleanup.append(account)

        Resources.updateLimit(self.apiclient,
                              resourcetype=0,
                              max=2,
                              account=account.name,
                              domainid=account.domainid)

        VirtualMachine.create(self.apiclient,
                              self.testdata["small"],
                              templateid=self.defaultTemplateId,
                              accountid=account.name,
                              domainid=account.domainid,
                              serviceofferingid=self.service_offering.id,
                              zoneid=self.zone.id,
                              startvm=False,
                              mode=self.zone.networktype)

        VirtualMachine.create(self.apiclient,
                              self.testdata["small"],
                              templateid=self.defaultTemplateId,
                              accountid=account.name,
                              domainid=account.domainid,
                              serviceofferingid=self.service_offering.id,
                              zoneid=self.zone.id,
                              startvm=False,
                              mode=self.zone.networktype)

        with self.assertRaises(Exception):
            VirtualMachine.create(self.apiclient,
                                  self.testdata["small"],
                                  templateid=self.defaultTemplateId,
                                  accountid=account.name,
                                  domainid=account.domainid,
                                  serviceofferingid=self.service_offering.id,
                                  zoneid=self.zone.id,
                                  startvm=False,
                                  mode=self.zone.networktype)
        return
예제 #5
0
    def test_10_max_account_limit(self):
        """ Positive test for stopped VM test path - T12

        # 1.  Create an account in root domain and set the VM limit
        #     to max 2 VMs
        # 2.  Deploy two VMs in the account with startvm parameter
        #     as false
        # 3.  Deployment of both VMs should be successful
        # 4.  Try to deploy 3rd VM with startvm False, deployment should fail
        """

        # Create an account
        account = Account.create(self.apiclient, self.testdata["account"], domainid=self.domain.id)
        self.cleanup.append(account)

        Resources.updateLimit(self.apiclient, resourcetype=0, max=2, account=account.name, domainid=account.domainid)

        VirtualMachine.create(
            self.apiclient,
            self.testdata["small"],
            templateid=self.defaultTemplateId,
            accountid=account.name,
            domainid=account.domainid,
            serviceofferingid=self.service_offering.id,
            zoneid=self.zone.id,
            startvm=False,
            mode=self.zone.networktype,
        )

        VirtualMachine.create(
            self.apiclient,
            self.testdata["small"],
            templateid=self.defaultTemplateId,
            accountid=account.name,
            domainid=account.domainid,
            serviceofferingid=self.service_offering.id,
            zoneid=self.zone.id,
            startvm=False,
            mode=self.zone.networktype,
        )

        with self.assertRaises(Exception):
            VirtualMachine.create(
                self.apiclient,
                self.testdata["small"],
                templateid=self.defaultTemplateId,
                accountid=account.name,
                domainid=account.domainid,
                serviceofferingid=self.service_offering.id,
                zoneid=self.zone.id,
                startvm=False,
                mode=self.zone.networktype,
            )
        return
예제 #6
0
    def update_account_resource_limitation(self, maxCpu, maxMemory):
        Resources.updateLimit(self.apiclient,
                              resourcetype=RESOURCE_CPU,
                              max=maxCpu,
                              domainid=self.account.domainid,
                              account=self.account.name)

        Resources.updateLimit(self.apiclient,
                              resourcetype=RESOURCE_MEMORY,
                              max=maxMemory,
                              domainid=self.account.domainid,
                              account=self.account.name)
예제 #7
0
    def updateResourceLimits(self, accountLimit=None, domainLimit=None):
        """Update primary storage limits of the parent domain and its
        child domains"""

        try:
            if domainLimit:
                #Update resource limit for domain
                Resources.updateLimit(self.apiclient, resourcetype=10,
                              max=domainLimit,
                              domainid=self.parent_domain.id)
            if accountLimit:
                #Update resource limit for domain
                Resources.updateLimit(self.apiclient, resourcetype=10,
                              max=accountLimit, account=self.parentd_admin.name,
                              domainid=self.parent_domain.id)
        except Exception as e:
            return [FAIL, e]
        return [PASS, None]
예제 #8
0
    def updateResourceLimits(self, accountLimit=None, domainLimit=None):
        """Update primary storage limits of the parent domain and its
        child domains"""

        try:
            if domainLimit:
                #Update resource limit for domain
                Resources.updateLimit(self.apiclient, resourcetype=10,
                              max=domainLimit,
                              domainid=self.parent_domain.id)
            if accountLimit:
                #Update resource limit for domain
                Resources.updateLimit(self.apiclient, resourcetype=10,
                              max=accountLimit, account=self.parentd_admin.name,
                              domainid=self.parent_domain.id)
        except Exception as e:
            return [FAIL, e]
        return [PASS, None]
    def setupAccounts(self):

        self.debug("Creating a sub-domain under: %s" % self.domain.name)
        self.child_domain_1 = Domain.create(self.apiclient,
                                            services=self.services["domain"],
                                            parentdomainid=self.domain.id)
        self.child_do_admin_1 = Account.create(
            self.apiclient,
            self.services["account"],
            admin=True,
            domainid=self.child_domain_1.id
        )
        # Cleanup the resources created at end of test
        self.cleanup.append(self.child_do_admin_1)
        self.cleanup.append(self.child_domain_1)

        Resources.updateLimit(self.apiclient,
                              resourcetype=9,
                              max=6144,
                              account=self.child_do_admin_1.name,
                              domainid=self.child_do_admin_1.domainid)

        self.child_domain_2 = Domain.create(self.apiclient,
                                            services=self.services["domain"],
                                            parentdomainid=self.domain.id)

        self.child_do_admin_2 = Account.create(
            self.apiclient,
            self.services["account"],
            admin=True,
            domainid=self.child_domain_2.id)

        # Cleanup the resources created at end of test
        self.cleanup.append(self.child_do_admin_2)
        self.cleanup.append(self.child_domain_2)

        Resources.updateLimit(self.apiclient,
                              resourcetype=9,
                              max=6144,
                              account=self.child_do_admin_2.name,
                              domainid=self.child_do_admin_2.domainid)
        return
예제 #10
0
    def updateSecondaryStorageLimits(self,
                                     accountLimit=None,
                                     domainLimit=None,
                                     projectLimit=None):

        try:
            # Update resource limits for account
            if accountLimit is not None:
                Resources.updateLimit(self.apiclient,
                                      resourcetype=11,
                                      max=int(accountLimit),
                                      account=self.child_do_admin.name,
                                      domainid=self.child_do_admin.domainid)

            if projectLimit is not None:
                Resources.updateLimit(self.apiclient,
                                      resourcetype=11,
                                      max=int(projectLimit),
                                      projectid=self.project.id)

            if domainLimit is not None:
                Resources.updateLimit(self.apiclient,
                                      resourcetype=11,
                                      max=int(domainLimit),
                                      domainid=self.child_domain.id)
        except Exception as e:
            return [FAIL, e]
        return [PASS, None]
예제 #11
0
    def updatePrimaryStorageLimits(self,
                                   accountLimit=None,
                                   domainLimit=None,
                                   projectLimit=None):

        try:
            # Update resource limits for account
            if accountLimit:
                Resources.updateLimit(self.apiclient,
                                      resourcetype=10,
                                      max=accountLimit,
                                      account=self.child_do_admin.name,
                                      domainid=self.child_do_admin.domainid)

            if projectLimit:
                Resources.updateLimit(self.apiclient,
                                      resourcetype=10,
                                      max=projectLimit,
                                      projectid=self.project.id)

            if domainLimit:
                Resources.updateLimit(self.apiclient,
                                      resourcetype=10,
                                      max=domainLimit,
                                      domainid=self.child_domain.id)
        except Exception as e:
            return [FAIL, e]
        return [PASS, None]
    def updateDomainResourceLimits(self, parentdomainlimit, subdomainlimit):
        """Update primary storage limits of the parent domain and its
        child domains"""

        try:
            # Update resource limit for domain
            Resources.updateLimit(
                self.apiclient, resourcetype=10, max=parentdomainlimit, domainid=self.parent_domain.id
            )

            # Update Resource limit for sub-domains
            Resources.updateLimit(self.apiclient, resourcetype=10, max=subdomainlimit, domainid=self.cadmin_1.domainid)

            Resources.updateLimit(self.apiclient, resourcetype=10, max=subdomainlimit, domainid=self.cadmin_2.domainid)
        except Exception as e:
            return [FAIL, e]
        return [PASS, None]
예제 #13
0
    def updateSecondaryStorageLimits(self, accountLimit=None, domainLimit=None, projectLimit=None):

        try:
            # Update resource limits for account
            if accountLimit:
                Resources.updateLimit(self.apiclient, resourcetype=11,
                                max=accountLimit, account=self.child_do_admin.name,
                                domainid=self.child_do_admin.domainid)

            if projectLimit:
                Resources.updateLimit(self.apiclient, resourcetype=11,
                                              max=projectLimit, projectid=self.project.id)

            if domainLimit:
                Resources.updateLimit(self.apiclient, resourcetype=11,
                                              max=domainLimit, domainid=self.child_domain.id)
        except Exception as e:
            return [FAIL, e]
        return [PASS, None]
예제 #14
0
    def updateDomainResourceLimits(self, parentdomainlimit, subdomainlimit):
        """Update secondary storage limits of the parent domain and its
        child domains"""

        try:
            #Update resource limit for domain
            Resources.updateLimit(self.apiclient, resourcetype=11,
                              max=parentdomainlimit,
                              domainid=self.parent_domain.id)

            # Update Resource limit for sub-domains
            Resources.updateLimit(self.apiclient, resourcetype=11,
                              max=subdomainlimit,
                              domainid=self.cadmin_1.domainid)

            Resources.updateLimit(self.apiclient, resourcetype=11,
                              max=subdomainlimit,
                              domainid=self.cadmin_2.domainid)
        except Exception as e:
            return [FAIL, e]
        return [PASS, None]
    def setupAccounts(self):

        self.debug("Creating a domain under: %s" % self.domain.name)
        self.parent_domain = Domain.create(self.apiclient,
                                           services=self.services["domain"],
                                           parentdomainid=self.domain.id)
        self.parentd_admin = Account.create(self.apiclient,
                                            self.services["account"],
                                            admin=True,
                                            domainid=self.domain.id)

        self.debug("Updating the Memory resource count for domain: %s" %
                   self.domain.name)
        Resources.updateLimit(self.apiclient,
                              resourcetype=9,
                              max=4096,
                              account=self.parentd_admin.name,
                              domainid=self.parentd_admin.domainid)
        self.debug("Creating a sub-domain under: %s" % self.parent_domain.name)
        self.cdomain_1 = Domain.create(self.apiclient,
                                       services=self.services["domain"],
                                       parentdomainid=self.parent_domain.id)

        self.debug("Creating a sub-domain under: %s" % self.parent_domain.name)
        self.cdomain_2 = Domain.create(self.apiclient,
                                       services=self.services["domain"],
                                       parentdomainid=self.parent_domain.id)

        self.cadmin_1 = Account.create(self.apiclient,
                                       self.services["account"],
                                       admin=True,
                                       domainid=self.cdomain_1.id)

        self.debug("Updating the Memory resource count for domain: %s" %
                   self.cdomain_1.name)
        Resources.updateLimit(self.apiclient,
                              resourcetype=9,
                              max=2048,
                              domainid=self.cadmin_1.domainid)

        self.debug("Updating the Memory resource count for account: %s" %
                   self.cadmin_1.name)
        Resources.updateLimit(self.apiclient,
                              resourcetype=9,
                              max=2048,
                              account=self.cadmin_1.name,
                              domainid=self.cadmin_1.domainid)

        self.cadmin_2 = Account.create(self.apiclient,
                                       self.services["account"],
                                       admin=True,
                                       domainid=self.cdomain_2.id)

        self.debug("Updating the Memory resource count for domain: %s" %
                   self.cdomain_2.name)
        Resources.updateLimit(self.apiclient,
                              resourcetype=9,
                              max=2048,
                              domainid=self.cadmin_2.domainid)

        self.debug("Updating the Memory resource count for domain: %s" %
                   self.cadmin_2.name)
        Resources.updateLimit(self.apiclient,
                              resourcetype=9,
                              max=2048,
                              account=self.cadmin_2.name,
                              domainid=self.cadmin_2.domainid)

        # Cleanup the resources created at end of test
        self.cleanup.append(self.cadmin_1)
        self.cleanup.append(self.cadmin_2)
        self.cleanup.append(self.cdomain_1)
        self.cleanup.append(self.cdomain_2)
        self.cleanup.append(self.parentd_admin)
        self.cleanup.append(self.parent_domain)

        users = {
            self.parent_domain: self.parentd_admin,
            self.cdomain_1: self.cadmin_1,
            self.cdomain_2: self.cadmin_2
        }
        return users
    def test_01_storage_snapshots_limits(self):
        """ Storage and Snapshot Limit
            1.   Create Snapshot of ROOT disk.
            2.   Verify the Secondary Storage value
                 is increased by the size of snapshot.
            3.   Delete Snaphshot.
            4.   Verify the Secondary
                 Storage value is decreased by the size of snapshot.
            5.   Set the Snapshot limit of Account.
            6.   Create Snasphots till limit is reached.
            7.   Create Snapshot of ROOT Volume.
                 Creation should fail.
            8.   Delete few Snapshots.
            9.   Create Snapshot again.
                 Creation should succeed.
        """

        # Get ROOT Volume
        root_volumes_list = Volume.list(self.userapiclient,
                                        virtualmachineid=self.vm.id,
                                        type='ROOT')

        status = validateList(root_volumes_list)
        self.assertEqual(status[0], PASS, "ROOT Volume List Validation Failed")

        root_volume = root_volumes_list[0]

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

        self.cleanup.append(self.data_volume_created)

        data_volumes_list = Volume.list(self.userapiclient,
                                        id=self.data_volume_created.id)

        status = validateList(data_volumes_list)
        self.assertEqual(status[0], PASS, "DATA Volume List Validation Failed")

        self.data_volume = data_volumes_list[0]

        self.vm.attach_volume(self.userapiclient, self.data_volume)

        # Get Secondary Storage Value from Database
        qryresult_before_snapshot = self.dbclient.execute(
            " select id, account_name, secondaryStorageTotal\
                    from account_view where account_name = '%s';" %
            self.account.name)

        status = validateList(qryresult_before_snapshot)
        self.assertEqual(
            status[0], PASS,
            "Check sql query to return SecondaryStorageTotal of account")

        secStorageBeforeSnapshot = qryresult_before_snapshot[0][2]

        # Step 1
        snapshot = Snapshot.create(self.userapiclient, root_volume.id)

        snapshots_list = Snapshot.list(self.userapiclient, id=snapshot.id)

        status = validateList(snapshots_list)
        self.assertEqual(status[0], PASS, "Snapshots List Validation Failed")

        # Verify Snapshot state
        self.assertEqual(
            snapshots_list[0].state.lower() in [
                BACKED_UP,
            ], True, "Snapshot state is not as expected. It is %s" %
            snapshots_list[0].state)

        # Step 2
        qryresult_after_snapshot = self.dbclient.execute(
            " select id, account_name, secondaryStorageTotal\
                        from account_view where account_name = '%s';" %
            self.account.name)

        status = validateList(qryresult_after_snapshot)
        self.assertEqual(
            status[0], PASS,
            "Check sql query to return SecondaryStorageTotal of account")

        secStorageAfterSnapshotCreated = qryresult_after_snapshot[0][2]

        snapshot_size = snapshots_list[0].physicalsize
        secStorageIncreased = secStorageBeforeSnapshot + \
            snapshot_size

        self.assertEqual(
            secStorageIncreased, secStorageAfterSnapshotCreated,
            "Secondary storage Total after Snapshot\
                        should be incremented by size of snapshot.")

        # Step 3
        snapshot.delete(self.apiclient)

        snapshots_list = Snapshot.list(self.userapiclient, id=snapshot.id)

        status = validateList(snapshots_list)
        self.assertEqual(status[0], FAIL, "Snapshots Not Deleted.")

        # Step 4
        qryresult_after_snapshot_deleted = self.dbclient.execute(
            " select id, account_name, secondaryStorageTotal\
                        from account_view where account_name = '%s';" %
            self.account.name)

        status = validateList(qryresult_after_snapshot_deleted)
        self.assertEqual(
            status[0], PASS,
            "Check sql query to return SecondaryStorageTotal of account")

        secStorageAfterSnapshotDeleted = qryresult_after_snapshot_deleted[0][2]

        secStorageDecreased = secStorageAfterSnapshotCreated - \
            snapshot_size

        self.assertEqual(
            secStorageDecreased, secStorageAfterSnapshotDeleted,
            "Secondary storage Total after Snapshot\
                        should be incremented by size of snapshot.")

        # Step 5
        # Set Snapshot Limit for account
        Resources.updateLimit(self.apiclient,
                              resourcetype=3,
                              max=1,
                              account=self.account.name,
                              domainid=self.account.domainid)

        # Step 6
        snapshot = Snapshot.create(self.userapiclient, root_volume.id)

        snapshots_list = Snapshot.list(self.userapiclient, id=snapshot.id)

        status = validateList(snapshots_list)
        self.assertEqual(status[0], PASS, "Snapshots List Validation Failed")

        # Verify Snapshot state
        self.assertEqual(
            snapshots_list[0].state.lower() in [
                BACKED_UP,
            ], True, "Snapshot state is not as expected. It is %s" %
            snapshots_list[0].state)

        # Step 7
        with self.assertRaises(Exception):
            Snapshot.create(self.userapiclient, self.data_volume.id)

        # Step 8
        snapshot.delete(self.userapiclient)

        snapshots_list = Snapshot.list(self.userapiclient, id=snapshot.id)

        status = validateList(snapshots_list)
        self.assertEqual(status[0], FAIL, "Snapshots Not Deleted.")

        # Step 9
        snapshot = Snapshot.create(self.userapiclient, root_volume.id)

        snapshots_list = Snapshot.list(self.userapiclient, id=snapshot.id)

        status = validateList(snapshots_list)
        self.assertEqual(status[0], PASS, "Snapshots List Validation Failed")

        # Verify Snapshot state
        self.assertEqual(
            snapshots_list[0].state.lower() in [
                BACKED_UP,
            ], True, "Snapshot state is not as expected. It is %s" %
            snapshots_list[0].state)

        return
    def test_01_storage_snapshots_limits(self):
        """ Storage and Snapshot Limit
            1.   Create Snapshot of ROOT disk.
            2.   Verify the Secondary Storage value
                 is increased by the size of snapshot.
            3.   Delete Snaphshot.
            4.   Verify the Secondary
                 Storage value is decreased by the size of snapshot.
            5.   Set the Snapshot limit of Account.
            6.   Create Snasphots till limit is reached.
            7.   Create Snapshot of ROOT Volume.
                 Creation should fail.
            8.   Delete few Snapshots.
            9.   Create Snapshot again.
                 Creation should succeed.
        """

        # Get ROOT Volume
        root_volumes_list = Volume.list(
            self.userapiclient,
            virtualmachineid=self.vm.id,
            type='ROOT'
        )

        status = validateList(root_volumes_list)
        self.assertEqual(status[0], PASS, "ROOT Volume List Validation Failed")

        root_volume = root_volumes_list[0]

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

        self.cleanup.append(self.data_volume_created)

        data_volumes_list = Volume.list(
            self.userapiclient,
            id=self.data_volume_created.id
        )

        status = validateList(data_volumes_list)
        self.assertEqual(status[0], PASS, "DATA Volume List Validation Failed")

        self.data_volume = data_volumes_list[0]

        self.vm.attach_volume(
            self.userapiclient,
            self.data_volume
        )

        # Get Secondary Storage Value from Database
        qryresult_before_snapshot = self.dbclient.execute(
            " select id, account_name, secondaryStorageTotal\
                    from account_view where account_name = '%s';" %
            self.account.name)

        status = validateList(qryresult_before_snapshot)
        self.assertEqual(
            status[0],
            PASS,
            "Check sql query to return SecondaryStorageTotal of account")

        secStorageBeforeSnapshot = qryresult_before_snapshot[0][2]

        # Step 1
        snapshot = Snapshot.create(
            self.userapiclient,
            root_volume.id)

        snapshots_list = Snapshot.list(self.userapiclient,
                                       id=snapshot.id)

        status = validateList(snapshots_list)
        self.assertEqual(status[0], PASS, "Snapshots List Validation Failed")

        # Verify Snapshot state
        self.assertEqual(
            snapshots_list[0].state.lower() in [
                BACKED_UP,
            ],
            True,
            "Snapshot state is not as expected. It is %s" %
            snapshots_list[0].state
        )

        # Step 2
        qryresult_after_snapshot = self.dbclient.execute(
            " select id, account_name, secondaryStorageTotal\
                        from account_view where account_name = '%s';" %
            self.account.name)

        status = validateList(qryresult_after_snapshot)
        self.assertEqual(
            status[0],
            PASS,
            "Check sql query to return SecondaryStorageTotal of account")

        secStorageAfterSnapshotCreated = qryresult_after_snapshot[0][2]

        snapshot_size = snapshots_list[0].physicalsize
        secStorageIncreased = secStorageBeforeSnapshot + \
            snapshot_size

        self.assertEqual(
            secStorageIncreased,
            secStorageAfterSnapshotCreated,
            "Secondary storage Total after Snapshot\
                        should be incremented by size of snapshot.")

        # Step 3
        snapshot.delete(self.apiclient)

        snapshots_list = Snapshot.list(self.userapiclient,
                                       id=snapshot.id)

        status = validateList(snapshots_list)
        self.assertEqual(status[0], FAIL, "Snapshots Not Deleted.")

        # Step 4
        qryresult_after_snapshot_deleted = self.dbclient.execute(
            " select id, account_name, secondaryStorageTotal\
                        from account_view where account_name = '%s';" %
            self.account.name)

        status = validateList(qryresult_after_snapshot_deleted)
        self.assertEqual(
            status[0],
            PASS,
            "Check sql query to return SecondaryStorageTotal of account")

        secStorageAfterSnapshotDeleted = qryresult_after_snapshot_deleted[0][2]

        secStorageDecreased = secStorageAfterSnapshotCreated - \
            snapshot_size

        self.assertEqual(
            secStorageDecreased,
            secStorageAfterSnapshotDeleted,
            "Secondary storage Total after Snapshot\
                        should be incremented by size of snapshot.")

        # Step 5
        # Set Snapshot Limit for account
        Resources.updateLimit(self.apiclient, resourcetype=3,
                              max=1, account=self.account.name,
                              domainid=self.account.domainid)

        # Step 6
        snapshot = Snapshot.create(
            self.userapiclient,
            root_volume.id)

        snapshots_list = Snapshot.list(self.userapiclient,
                                       id=snapshot.id)

        status = validateList(snapshots_list)
        self.assertEqual(status[0], PASS, "Snapshots List Validation Failed")

        # Verify Snapshot state
        self.assertEqual(
            snapshots_list[0].state.lower() in [
                BACKED_UP,
            ],
            True,
            "Snapshot state is not as expected. It is %s" %
            snapshots_list[0].state
        )

        # Step 7
        with self.assertRaises(Exception):
            Snapshot.create(
                self.userapiclient,
                self.data_volume.id)

        # Step 8
        snapshot.delete(self.userapiclient)

        snapshots_list = Snapshot.list(self.userapiclient,
                                       id=snapshot.id)

        status = validateList(snapshots_list)
        self.assertEqual(status[0], FAIL, "Snapshots Not Deleted.")

        # Step 9
        snapshot = Snapshot.create(
            self.userapiclient,
            root_volume.id)

        snapshots_list = Snapshot.list(self.userapiclient,
                                       id=snapshot.id)

        status = validateList(snapshots_list)
        self.assertEqual(status[0], PASS, "Snapshots List Validation Failed")

        # Verify Snapshot state
        self.assertEqual(
            snapshots_list[0].state.lower() in [
                BACKED_UP,
            ],
            True,
            "Snapshot state is not as expected. It is %s" %
            snapshots_list[0].state
        )

        return
예제 #18
0
    def test_02_negative_path(self):
        """
        negative test for volume life cycle
        # 1. Deploy a vm [vm1] with shared storage and  data disk
        #v1. Create VM2 with local storage offering disk offerings
        # 2.TBD
        # 3. Detach the data disk from VM1 and Download the volume
        # 4.TBD
        # 5. Attach volume with deviceid = 0
        # 6. Attach volume, specify a VM which is destroyed
        # 7.TBD
        # 8.TBD
        # 9.TBD
        # 10.TBD
        # 11.Upload the volume from T3 by providing the URL of the downloaded
             volume, but specify a wrong format (not supported by the
             hypervisor)
        # 12.Upload the same volume from T4 by providing a wrong URL
        # 13.Upload volume, provide wrong checksum
        # 14.Upload a volume when maximum limit for the account is reached
        # 15.TBD
        # 16.Upload volume with all correct parameters
             (covered in positive test path)
        # 17.TBD
        # 18.TBD
        # 19.Now attach the volume with all correct parameters
            (covered in positive test path)
        # 20.Destroy and expunge all VMs

        """

        # 1. Deploy a vm [vm1] with shared storage and data disk
        self.virtual_machine_1 = 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,
            diskofferingid=self.disk_offering_1.id,
            mode=self.testdata["mode"])
        verify_vm(self, self.virtual_machine_1.id)
        # List data volume for vm1
        list_volume = Volume.list(self.userapiclient,
                                  virtualmachineid=self.virtual_machine_1.id,
                                  type='DATADISK'
                                  )
        self.assertEqual(
            validateList(list_volume)[0],
            PASS,
            "Check List volume response for vm id  %s" %
            self.virtual_machine_1.id)
        list_data_volume_for_vm1 = list_volume[0]
        self.assertEqual(
            len(list_volume),
            1,
            "There is no data disk attached to vm id:%s" %
            self.virtual_machine_1.id)
        self.assertEqual(
            list_data_volume_for_vm1.virtualmachineid, str(
                self.virtual_machine_1.id),
            "Check if volume state (attached) is reflected")
        # Variance
        if self.zone.localstorageenabled:
            # V1.Create vm3 with local storage offering
            self.virtual_machine_local_2 = VirtualMachine.create(
                self.userapiclient,
                self.testdata["small"],
                templateid=self.template.id,
                accountid=self.account.name,
                domainid=self.account.domainid,
                serviceofferingid=self.service_offering_2.id,
                zoneid=self.zone.id,
                mode=self.testdata["mode"])
            verify_vm(self, self.virtual_machine_local_2.id)

        # 3. Detach the data disk from VM1 and Download the volume
        self.virtual_machine_1.detach_volume(self.userapiclient,
                                             volume=list_data_volume_for_vm1
                                             )
        verify_detach_volume(
            self,
            self.virtual_machine_1.id,
            list_data_volume_for_vm1.id)
        # download detached volume
        self.extract_volume = Volume.extract(
            self.userapiclient,
            volume_id=list_data_volume_for_vm1.id,
            zoneid=self.zone.id,
            mode='HTTP_DOWNLOAD')

        self.debug("extracted url is%s  :" % self.extract_volume.url)
        try:

            formatted_url = urllib.unquote_plus(self.extract_volume.url)
            self.debug(
                "Attempting to download volume at url %s" %
                formatted_url)
            response = urllib.urlopen(formatted_url)
            self.debug("response from volume url %s" % response.getcode())
            fd, path = tempfile.mkstemp()
            self.debug(
                "Saving volume %s to path %s" %
                (list_data_volume_for_vm1.id, path))
            os.close(fd)
            with open(path, 'wb') as fd:
                fd.write(response.read())
            self.debug("Saved volume successfully")
        except Exception:
            self.fail(
                "Extract Volume Failed with invalid URL %s (vol id: %s)" %
                (self.extract_volume, list_data_volume_for_vm1.id))

        # 6. Attach volume, specify a VM which is destroyed
        self.virtual_machine_2 = 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,
            mode=self.testdata["mode"])
        verify_vm(self, self.virtual_machine_2.id)
        try:
            self.virtual_machine_2.delete(self.apiclient)
        except Exception as e:
            raise Exception("Vm deletion failed with error %s" % e)
        # Create a new volume
        self.volume = Volume.create(self.userapiclient,
                                    services=self.testdata["volume"],
                                    diskofferingid=self.disk_offering_1.id,
                                    zoneid=self.zone.id
                                    )

        list_data_volume = Volume.list(self.userapiclient,
                                       id=self.volume.id
                                       )
        self.assertEqual(
            validateList(list_data_volume)[0],
            PASS,
            "Check List volume response for volume %s" %
            self.volume.id)
        self.assertEqual(
            list_data_volume[0].id,
            self.volume.id,
            "check list volume response for volume id:  %s" %
            self.volume.id)
        self.debug(
            "volume id %s got created successfully" %
            list_data_volume[0].id)
        # try  Attach volume to vm2
        try:
            self.virtual_machine_2.attach_volume(self.userapiclient,
                                                 self.volume
                                                 )
            self.fail("Volume got attached to a destroyed vm ")
        except Exception:
            self.debug("Volume cant not be attached to a destroyed vm ")

        # 11.Upload the volume  by providing the URL of the downloaded
        # volume, but specify a wrong format (not supported by the hypervisor)
        if "OVA" in self.extract_volume.url.upper():
            self.testdata["configurableData"]["upload_volume"]["format"] = "VHD"
        else:
            self.testdata["configurableData"]["upload_volume"]["format"] = "OVA"
        try:
            self.upload_response = Volume.upload(
                self.userapiclient,
                zoneid=self.zone.id,
                url=self.extract_volume.url,
                services=self.testdata["configurableData"]["upload_volume"])
            self.fail("Volume got uploaded with invalid format")
        except Exception as e:
            self.debug("upload volume failed due %s" % e)
        # 12. Upload the same volume from T4 by providing a wrong URL
        self.testdata["configurableData"]["upload_volume"]["format"] = "VHD"
        if "OVA" in self.extract_volume.url.upper():
            self.testdata["configurableData"]["upload_volume"]["format"] = "OVA"
        if "QCOW2" in self.extract_volume.url.upper():
            self.testdata["configurableData"]["upload_volume"]["format"] = "QCOW2"
        u1 = self.extract_volume.url.split('.')
        u1[-2] = "wrong"
        wrong_url = ".".join(u1)
        try:
            self.upload_response = Volume.upload(
                self.userapiclient,
                zoneid=self.zone.id,
                url=wrong_url,
                services=self.testdata["configurableData"]["upload_volume"])
            self.upload_response.wait_for_upload(self.userapiclient
                                                 )
            self.fail("volume got uploaded with wrong url")
        except Exception as e:
            self.debug("upload volume failed due to %s" % e)
        # 13.Upload volume, provide wrong checksum
        try:
            self.upload_response = Volume.upload(
                self.userapiclient,
                zoneid=self.zone.id,
                url=self.extract_volume.url,
                services=self.testdata["configurableData"]["upload_volume"],
                checksome="123456")
            self.upload_response.wait_for_upload(self.userapiclient
                                                 )
            self.fail("volume got uploaded with wrong checksome")
        except Exception as e:
            self.debug("upload volume failed due to %s" % e)

        # 14.Upload a volume when maximum limit for the account is reached
        account_update = Resources.updateLimit(self.apiclient,
                                               resourcetype=2,
                                               account=self.account.name,
                                               domainid=self.account.domainid,
                                               max=1
                                               )
        list_resource = Resources.list(self.apiclient,
                                       account=self.account.name,
                                       domainid=self.account.domainid,
                                       resourcetype=2
                                       )
        self.assertEqual(
            validateList(list_resource)[0],
            PASS,
            "Check List resource response for volume %s" %
            self.account.name)
        self.assertEqual(
            str(
                list_resource[0].max),
            '1',
            "check list List resource response for account id:  %s" %
            self.account.name)
        self.debug(
            "Max resources got updated successfully for account %s" %
            self.account.name)
        try:
            self.upload_response = Volume.upload(
                self.userapiclient,
                zoneid=self.zone.id,
                url=self.extract_volume.url,
                services=self.testdata["configurableData"]["upload_volume"])
            self.upload_response.wait_for_upload(self.userapiclient
                                                 )
            self.fail("volume got uploaded after account reached max limit for\
                      volumes ")
        except Exception as e:
            self.debug("upload volume failed due to %s" % e)
예제 #19
0
    def test_02_negative_path(self):
        """
        negative test for volume life cycle
        # 1. Deploy a vm [vm1] with shared storage and  data disk
        #v1. Create VM2 with local storage offering disk offerings
        # 2.TBD
        # 3. Detach the data disk from VM1 and Download the volume
        # 4.TBD
        # 5. Attach volume with deviceid = 0
        # 6. Attach volume, specify a VM which is destroyed
        # 7.TBD
        # 8.TBD
        # 9.TBD
        # 10.TBD
        # 11.Upload the volume from T3 by providing the URL of the downloaded
             volume, but specify a wrong format (not supported by the
             hypervisor)
        # 12.Upload the same volume from T4 by providing a wrong URL
        # 13.Upload volume, provide wrong checksum
        # 14.Upload a volume when maximum limit for the account is reached
        # 15.TBD
        # 16.Upload volume with all correct parameters
             (covered in positive test path)
        # 17.TBD
        # 18.TBD
        # 19.Now attach the volume with all correct parameters
            (covered in positive test path)
        # 20.Destroy and expunge all VMs

        """

        # 1. Deploy a vm [vm1] with shared storage and data disk
        self.virtual_machine_1 = 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,
            diskofferingid=self.disk_offering_1.id,
            mode=self.testdata["mode"])
        verify_vm(self, self.virtual_machine_1.id)
        # List data volume for vm1
        list_volume = Volume.list(self.userapiclient,
                                  virtualmachineid=self.virtual_machine_1.id,
                                  type='DATADISK')
        self.assertEqual(
            validateList(list_volume)[0], PASS,
            "Check List volume response for vm id  %s" %
            self.virtual_machine_1.id)
        list_data_volume_for_vm1 = list_volume[0]
        self.assertEqual(
            len(list_volume), 1, "There is no data disk attached to vm id:%s" %
            self.virtual_machine_1.id)
        self.assertEqual(list_data_volume_for_vm1.virtualmachineid,
                         str(self.virtual_machine_1.id),
                         "Check if volume state (attached) is reflected")
        # Variance
        if self.zone.localstorageenabled:
            # V1.Create vm3 with local storage offering
            self.virtual_machine_local_2 = VirtualMachine.create(
                self.userapiclient,
                self.testdata["small"],
                templateid=self.template.id,
                accountid=self.account.name,
                domainid=self.account.domainid,
                serviceofferingid=self.service_offering_2.id,
                zoneid=self.zone.id,
                mode=self.testdata["mode"])
            verify_vm(self, self.virtual_machine_local_2.id)

        # 3. Detach the data disk from VM1 and Download the volume
        self.virtual_machine_1.detach_volume(self.userapiclient,
                                             volume=list_data_volume_for_vm1)
        verify_detach_volume(self, self.virtual_machine_1.id,
                             list_data_volume_for_vm1.id)
        # download detached volume
        self.extract_volume = Volume.extract(
            self.userapiclient,
            volume_id=list_data_volume_for_vm1.id,
            zoneid=self.zone.id,
            mode='HTTP_DOWNLOAD')

        self.debug("extracted url is%s  :" % self.extract_volume.url)
        try:

            formatted_url = urllib.unquote_plus(self.extract_volume.url)
            self.debug("Attempting to download volume at url %s" %
                       formatted_url)
            response = urllib.urlopen(formatted_url)
            self.debug("response from volume url %s" % response.getcode())
            fd, path = tempfile.mkstemp()
            self.debug("Saving volume %s to path %s" %
                       (list_data_volume_for_vm1.id, path))
            os.close(fd)
            with open(path, 'wb') as fd:
                fd.write(response.read())
            self.debug("Saved volume successfully")
        except Exception:
            self.fail(
                "Extract Volume Failed with invalid URL %s (vol id: %s)" %
                (self.extract_volume, list_data_volume_for_vm1.id))

        # 6. Attach volume, specify a VM which is destroyed
        self.virtual_machine_2 = 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,
            mode=self.testdata["mode"])
        verify_vm(self, self.virtual_machine_2.id)
        try:
            self.virtual_machine_2.delete(self.apiclient)
        except Exception as e:
            raise Exception("Vm deletion failed with error %s" % e)
        # Create a new volume
        self.volume = Volume.create(self.userapiclient,
                                    services=self.testdata["volume"],
                                    diskofferingid=self.disk_offering_1.id,
                                    zoneid=self.zone.id)

        list_data_volume = Volume.list(self.userapiclient, id=self.volume.id)
        self.assertEqual(
            validateList(list_data_volume)[0], PASS,
            "Check List volume response for volume %s" % self.volume.id)
        self.assertEqual(
            list_data_volume[0].id, self.volume.id,
            "check list volume response for volume id:  %s" % self.volume.id)
        self.debug("volume id %s got created successfully" %
                   list_data_volume[0].id)
        # try  Attach volume to vm2
        try:
            self.virtual_machine_2.attach_volume(self.userapiclient,
                                                 self.volume)
            self.fail("Volume got attached to a destroyed vm ")
        except Exception:
            self.debug("Volume cant not be attached to a destroyed vm ")

        # 11.Upload the volume  by providing the URL of the downloaded
        # volume, but specify a wrong format (not supported by the hypervisor)
        if "OVA" in self.extract_volume.url.upper():
            self.testdata["upload_volume"]["format"] = "VHD"
        else:
            self.testdata["upload_volume"]["format"] = "OVA"
        try:
            self.upload_response = Volume.upload(
                self.userapiclient,
                zoneid=self.zone.id,
                url=self.extract_volume.url,
                services=self.testdata["upload_volume"])
            self.fail("Volume got uploaded with invalid format")
        except Exception as e:
            self.debug("upload volume failed due %s" % e)
        # 12. Upload the same volume from T4 by providing a wrong URL
        self.testdata["upload_volume"]["format"] = "VHD"
        if "OVA" in self.extract_volume.url.upper():
            self.testdata["upload_volume"]["format"] = "OVA"
        if "QCOW2" in self.extract_volume.url.upper():
            self.testdata["upload_volume"]["format"] = "QCOW2"
        u1 = self.extract_volume.url.split('.')
        u1[-2] = "wrong"
        wrong_url = ".".join(u1)
        try:
            self.upload_response = Volume.upload(
                self.userapiclient,
                zoneid=self.zone.id,
                url=wrong_url,
                services=self.testdata["upload_volume"])
            self.upload_response.wait_for_upload(self.userapiclient)
            self.fail("volume got uploaded with wrong url")
        except Exception as e:
            self.debug("upload volume failed due to %s" % e)
        # 13.Upload volume, provide wrong checksum
        try:
            self.upload_response = Volume.upload(
                self.userapiclient,
                zoneid=self.zone.id,
                url=self.extract_volume.url,
                services=self.testdata["upload_volume"],
                checksome="123456")
            self.upload_response.wait_for_upload(self.userapiclient)
            self.fail("volume got uploaded with wrong checksome")
        except Exception as e:
            self.debug("upload volume failed due to %s" % e)

        # 14.Upload a volume when maximum limit for the account is reached
        account_update = Resources.updateLimit(self.apiclient,
                                               resourcetype=2,
                                               account=self.account.name,
                                               domainid=self.account.domainid,
                                               max=1)
        list_resource = Resources.list(self.apiclient,
                                       account=self.account.name,
                                       domainid=self.account.domainid,
                                       resourcetype=2)
        self.assertEqual(
            validateList(list_resource)[0], PASS,
            "Check List resource response for volume %s" % self.account.name)
        self.assertEqual(
            str(list_resource[0].max), '1',
            "check list List resource response for account id:  %s" %
            self.account.name)
        self.debug("Max resources got updated successfully for account %s" %
                   self.account.name)
        try:
            self.upload_response = Volume.upload(
                self.userapiclient,
                zoneid=self.zone.id,
                url=self.extract_volume.url,
                services=self.testdata["upload_volume"])
            self.upload_response.wait_for_upload(self.userapiclient)
            self.fail("volume got uploaded after account reached max limit for\
                      volumes ")
        except Exception as e:
            self.debug("upload volume failed due to %s" % e)