コード例 #1
0
    def test_02_migrate_instance(self):
        """Test Deploy VM with 4 core CPU & verify the usage"""

        # Validate the following
        # 1. Create compute offering with 4 core CPU & Deploy VM
        # 2. List Resource count
        # 3. Migrate instance to another host
        # 4. Resource count should list properly.
        self.hypervisor = self.testClient.getHypervisorInfo()
        if self.hypervisor.lower() in ['lxc']:
            self.skipTest("vm migrate is not supported in %s" %
                          self.hypervisor)

        self.debug("Setting up account and domain hierarchy")
        self.setupAccounts()
        users = {
            self.child_domain_1: self.child_do_admin_1,
            self.child_domain_2: self.child_do_admin_2
        }
        for domain, admin in users.items():
            self.account = admin
            self.domain = domain

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

        self.debug("Creating an instance with service offering: %s" %
                   self.service_offering.name)
        vm = self.createInstance(service_off=self.service_offering,
                                 api_client=api_client)

        account_list = Account.list(self.apiclient, id=self.account.id)
        self.assertIsInstance(account_list, list,
                              "List Accounts should return a valid response")
        resource_count = account_list[0].cputotal

        expected_resource_count = int(self.service_offering.cpunumber)

        self.assertEqual(
            resource_count, expected_resource_count,
            "Initial resource count should with the expected resource count")

        host = findSuitableHostForMigration(self.apiclient, vm.id)
        if host is None:
            self.skipTest(ERROR_NO_HOST_FOR_MIGRATION)
        self.debug("Migrating instance: %s to host: %s" % (vm.name, host.name))
        try:
            vm.migrate(self.apiclient, host.id)
        except Exception as e:
            self.fail("Failed to migrate instance: %s" % e)

        account_list = Account.list(self.apiclient, id=self.account.id)
        self.assertIsInstance(account_list, list,
                              "List Accounts should return a valid response")
        resource_count_after_migrate = account_list[0].cputotal

        self.assertEqual(
            resource_count, resource_count_after_migrate,
            "Resource count should be same after starting the instance")
        return
コード例 #2
0
    def test_02_multiple_core_vm_migrate_instance(self):
        """Test Deploy VM with 4 core CPU & verify the usage"""

        # Validate the following
        # 1. Create two domains and set specific resource (cpu) limit for them
        # 2. Create compute offering with 4 core CPU & deploy vm
        # 3. Update Resource count for the domains
        # 4. Migrate instance to new host and check resource count
        # 5. Resource count should list properly.
        self.hypervisor = self.testClient.getHypervisorInfo()

        self.debug("Setting up account and domain hierarchy")
        self.setupAccounts()
        users = {self.domain: self.admin,
                 self.child_domain: self.child_do_admin
                 }
        for domain, admin in users.items():
            self.account = admin
            self.domain = domain

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

            self.debug("Creating an instance with service offering: %s" %
                       self.service_offering.name)
            vm = self.createInstance(service_off=self.service_offering, api_client=api_client)

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(account_list,
                list,
                "List Accounts should return a valid response"
            )
            resource_count = account_list[0].cputotal

            expected_resource_count = int(self.services["service_offering"]["cpunumber"])

            self.assertEqual(resource_count, expected_resource_count,
                "Initial resource count should match with the expected resource count")

            host = findSuitableHostForMigration(self.apiclient, vm.id)
            if host is None:
                self.skipTest(ERROR_NO_HOST_FOR_MIGRATION)
            self.debug("Migrating instance: %s to host: %s" %
                       (vm.name, host.name))
            try:
                vm.migrate(self.apiclient, host.id)
            except Exception as e:
                self.fail("Failed to migrate instance: %s" % e)

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(account_list,
                list,
                "List Accounts should return a valid response"
            )
            resource_count_after_migrate = account_list[0].cputotal

            self.assertEqual(resource_count, resource_count_after_migrate,
                "Resource count should be same as before, after migrating the instance")
        return
コード例 #3
0
    def test_03_delete_instance(self):
        """Test Deploy VM with specified GB RAM & verify the usage"""

        # Validate the following
        # 1. Create compute offering with specified RAM & Deploy VM as root admin
        # 2. List Resource count for the root admin Memory usage
        # 3. Delete instance, resource count should be 0 after delete operation.

        account_list = Account.list(self.apiclient, id=self.account.id)
        self.assertIsInstance(account_list, list, "List Accounts should return a valid response")
        resource_count = account_list[0].memorytotal

        expected_resource_count = int(self.services["service_offering"]["memory"])

        self.assertEqual(
            resource_count, expected_resource_count, "Resource count should match with the expected resource count"
        )

        self.debug("Destroying instance: %s" % self.vm.name)
        try:
            self.vm.delete(self.apiclient)
        except Exception as e:
            self.fail("Failed to delete instance: %s" % e)

            # Wait for expunge interval to cleanup Memory
            wait_for_cleanup(self.apiclient, ["expunge.delay", "expunge.interval"])

        account_list = Account.list(self.apiclient, id=self.account.id)
        self.assertIsInstance(account_list, list, "List Accounts should return a valid response")
        resource_count_after_delete = account_list[0].memorytotal
        self.assertEqual(
            resource_count_after_delete, 0, "Resource count for %s should be 0" % get_resource_type(resource_id=9)
        )  # RAM
        return
コード例 #4
0
    def test_03_multiplecore_delete_instance(self):
        """Test Deploy VM with multiple core CPU & verify the usage"""

        # Validate the following
        # 1. Deploy VM with multiple core CPU & verify the usage
        # 2. Destroy VM & verify update resource count of Root Admin Account
        # 3. Resource count should list properly.

        account_list = Account.list(self.apiclient, id=self.account.id)
        self.assertIsInstance(account_list,
                              list,
                              "List Accounts should return a valid response"
                              )
        resource_count = account_list[0].cputotal

        expected_resource_count = int(self.services["service_offering"]["cpunumber"])

        self.assertEqual(resource_count, expected_resource_count,
                         "Resource count should match with the expected resource count")

        self.debug("Destroying instance: %s" % self.vm.name)
        try:
            self.vm.delete(self.apiclient)
        except Exception as e:
            self.fail("Failed to delete instance: %s" % e)

        account_list = Account.list(self.apiclient, id=self.account.id)
        self.assertIsInstance(account_list,
                              list,
                              "List Accounts should return a valid response"
                              )
        resource_count = account_list[0].cputotal
        self.assertEqual(resource_count, 0 , "Resource count for %s should be 0" % get_resource_type(resource_id=8))#CPU
        return
コード例 #5
0
    def test_02_migrate_vm(self):
        """Test Deploy VM with specified RAM & verify the usage"""

        # Validate the following
        # 1. Create compute offering with specified RAM & Deploy VM in the created domain
        # 2. List Resource count for the root admin Memory usage
        # 3. Migrate vm to another host, resource count should list properly.

        # Resetting memory count in service offering
        self.hypervisor = self.testClient.getHypervisorInfo()
        self.services["service_offering"]["memory"] = 2048

        self.debug("Setting up account and domain hierarchy")
        self.setupAccounts()
        users = {self.child_domain_1: self.child_do_admin_1,
                 self.child_domain_2: self.child_do_admin_2
                 }
        for domain, admin in users.items():
            self.account = admin
            self.domain = domain
            self.debug("Creating an instance with service offering: %s" %
                       self.service_offering.name)

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

            vm = self.createInstance(service_off=self.service_offering, api_client=api_client)

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(account_list,
                                  list,
                                  "List Accounts should return a valid response"
                                  )
            resource_count = account_list[0].memorytotal

            expected_resource_count = int(self.services["service_offering"]["memory"])

            self.assertEqual(resource_count, expected_resource_count,
                             "Resource count should match with the expected resource count")

            host = findSuitableHostForMigration(self.apiclient, vm.id)
            if host is None:
                self.skipTest(ERROR_NO_HOST_FOR_MIGRATION)
            self.debug("Migrating instance: %s to host: %s" %
                       (vm.name, host.name))
            try:
                vm.migrate(self.apiclient, host.id)
            except Exception as e:
                self.fail("Failed to migrate instance: %s" % e)
            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(account_list,
                                  list,
                                  "List Accounts should return a valid response"
                                  )
            resource_count_after_migrate = account_list[0].memorytotal

            self.assertTrue(resource_count_after_migrate == resource_count,
                            "Resource count should be same after migrating the instance")
        return
コード例 #6
0
    def test_03_multiplecore_delete_instance(self):
        """Test Deploy VM with multiple core CPU & verify the usage"""

        # Validate the following
        # 1. Deploy VM with multiple core CPU & verify the usage
        # 2. Destroy VM & verify update resource count of Root Admin Account
        # 3. Resource count should list properly.

        account_list = Account.list(self.apiclient, id=self.account.id)
        self.assertIsInstance(account_list, list,
                              "List Accounts should return a valid response")
        resource_count = account_list[0].cputotal

        expected_resource_count = int(self.service_offering.cpunumber)

        self.assertEqual(
            resource_count, expected_resource_count,
            "Resource count should match with the expected resource count")

        self.debug("Destroying instance: %s" % self.vm.name)
        try:
            self.vm.delete(self.apiclient)
        except Exception as e:
            self.fail("Failed to delete instance: %s" % e)

        account_list = Account.list(self.apiclient, id=self.account.id)
        self.assertIsInstance(account_list, list,
                              "List Accounts should return a valid response")
        resource_count = account_list[0].cputotal
        self.assertEqual(resource_count, 0,
                         "Resource count for %s should be 0" %
                         get_resource_type(resource_id=8))  #CPU
        return
コード例 #7
0
    def test_02_migrate_vm(self):
        """Test Deploy VM with specified RAM & verify the usage"""

        # Validate the following
        # 1. Create compute offering with specified RAM & Deploy VM in the created domain
        # 2. List Resource count for the root admin Memory usage
        # 3. Migrate vm to another host, resource count should list properly.

        #Resetting memory count in service offering
        self.services["service_offering"]["memory"] = 2048

        self.debug("Setting up account and domain hierarchy")
        self.setupAccounts()
        users =  { self.child_domain_1: self.child_do_admin_1,
                   self.child_domain_2: self.child_do_admin_2
                 }
        for domain, admin in users.items():
            self.account = admin
            self.domain = domain
            self.debug("Creating an instance with service offering: %s" %
                                                    self.service_offering.name)

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

            vm = self.createInstance(service_off=self.service_offering, api_client=api_client)

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(account_list,
                              list,
                              "List Accounts should return a valid response"
                              )
            resource_count = account_list[0].memorytotal

            expected_resource_count = int(self.services["service_offering"]["memory"])

            self.assertEqual(resource_count, expected_resource_count,
                         "Resource count should match with the expected resource count")

            host = findSuitableHostForMigration(self.apiclient, vm.id)
            if host is None:
                self.skipTest(ERROR_NO_HOST_FOR_MIGRATION)
            self.debug("Migrating instance: %s to host: %s" %
                                                        (vm.name, host.name))
            try:
                vm.migrate(self.apiclient, host.id)
            except Exception as e:
                self.fail("Failed to migrate instance: %s" % e)
            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(account_list,
                              list,
                              "List Accounts should return a valid response"
                              )
            resource_count_after_migrate = account_list[0].memorytotal

            self.assertTrue(resource_count_after_migrate == resource_count,
                            "Resource count should be same after migrating the instance")
        return
コード例 #8
0
    def test_03_multiple_core_vm_delete_instance(self):
        """Test Deploy VM with 4 core CPU & verify the usage"""

        # Validate the following
        # 1. Create two domains and set specific resource (cpu) limit for them
        # 2. Create compute offering with 4 core CPU & deploy vm
        # 3. Update Resource count for the domains
        # 4. delete instance and check resource count
        # 5. Resource count should list properly.

        self.debug("Setting up account and domain hierarchy")
        self.setupAccounts()
        users = {
            self.domain: self.admin,
            self.child_domain: self.child_do_admin
        }
        for domain, admin in users.items():
            self.account = admin
            self.domain = domain

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

            self.debug("Creating an instance with service offering: %s" %
                       self.service_offering.name)
            vm = self.createInstance(service_off=self.service_offering,
                                     api_client=api_client)

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(
                account_list, list,
                "List Accounts should return a valid response")
            resource_count = account_list[0].cputotal

            expected_resource_count = int(
                self.services["service_offering"]["cpunumber"])

            self.assertEqual(
                resource_count, expected_resource_count,
                "Initial resource count should with the expected resource count"
            )

            self.debug("Destroying instance: %s" % vm.name)
            try:
                vm.delete(self.apiclient)
            except Exception as e:
                self.fail("Failed to delete instance: %s" % e)

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(
                account_list, list,
                "List Accounts should return a valid response")
            resource_count_after_delete = account_list[0].cputotal

            self.assertEqual(resource_count_after_delete, 0,
                             "Resource count for %s should be 0" %
                             get_resource_type(resource_id=8))  #CPU
        return
コード例 #9
0
    def test_03_delete_vm(self):
        """Test Deploy VM with specified RAM & verify the usage"""

        # Validate the following
        # 1. Create compute offering with specified RAM & Deploy VM in the created domain
        # 2. List Resource count for the root admin Memory usage
        # 3. Delete vm, resource count should list as 0 after delete operation.

        # Resetting the memory count of service offering
        self.services["service_offering"]["memory"] = 2048

        self.debug("Setting up account and domain hierarchy")
        self.setupAccounts()
        users = {self.child_domain_1: self.child_do_admin_1,
                 self.child_domain_2: self.child_do_admin_2
                 }
        for domain, admin in users.items():
            self.account = admin
            self.domain = domain
            self.debug("Creating an instance with service offering: %s" %
                       self.service_offering.name)

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

            vm = self.createInstance(service_off=self.service_offering, api_client=api_client)

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(account_list,
                                  list,
                                  "List Accounts should return a valid response"
                                  )
            resource_count = account_list[0].memorytotal

            expected_resource_count = int(self.services["service_offering"]["memory"])

            self.assertEqual(resource_count, expected_resource_count,
                             "Resource count should match with the expected resource count")

            self.debug("Destroying instance: %s" % vm.name)
            try:
                vm.delete(self.apiclient)
            except Exception as e:
                self.fail("Failed to delete instance: %s" % e)

            # Wait for expunge interval to cleanup Memory
            wait_for_cleanup(self.apiclient, ["expunge.delay", "expunge.interval"])

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(account_list,
                                  list,
                                  "List Accounts should return a valid response"
                                  )
            resource_count_after_delete = account_list[0].memorytotal
            self.assertEqual(resource_count_after_delete, 0,
                             "Resource count for %s should be 0" % get_resource_type(resource_id=9))  # RAM
        return
コード例 #10
0
    def test_03_delete_vm(self):
        """Test Deploy VM with specified RAM & verify the usage"""

        # Validate the following
        # 1. Create compute offering with specified RAM & Deploy VM in the created domain
        # 2. List Resource count for the root admin Memory usage
        # 3. Delete vm, resource count should list as 0 after delete operation.

        # Resetting the memory count of service offering
        self.services["service_offering"]["memory"] = 2048

        self.debug("Setting up account and domain hierarchy")
        self.setupAccounts()
        users =  { self.child_domain_1: self.child_do_admin_1,
                   self.child_domain_2: self.child_do_admin_2
                 }
        for domain, admin in users.items():
            self.account = admin
            self.domain = domain
            self.debug("Creating an instance with service offering: %s" %
                                                    self.service_offering.name)

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

            vm = self.createInstance(service_off=self.service_offering, api_client=api_client)

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(account_list,
                              list,
                              "List Accounts should return a valid response"
                              )
            resource_count = account_list[0].memorytotal

            expected_resource_count = int(self.services["service_offering"]["memory"])

            self.assertEqual(resource_count, expected_resource_count,
                         "Resource count should match with the expected resource count")

            self.debug("Destroying instance: %s" % vm.name)
            try:
                vm.delete(self.apiclient)
            except Exception as e:
                self.fail("Failed to delete instance: %s" % e)

            # Wait for expunge interval to cleanup Memory
            wait_for_cleanup(self.apiclient, ["expunge.delay", "expunge.interval"])

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(account_list,
                              list,
                              "List Accounts should return a valid response"
                              )
            resource_count_after_delete = account_list[0].memorytotal
            self.assertEqual(resource_count_after_delete, 0 , "Resource count for %s should be 0" % get_resource_type(resource_id=9))#RAM
        return
コード例 #11
0
    def test_03_delete_instance(self):
        """Test Deploy VM with specified RAM & verify the usage"""

        # Validate the following
        # 1. Create compute offering with specified RAM in child domains of root domain & Deploy VM
        # 2. List Resource count for the Memory usage
        # 3. Delete instance
        # 4. Resource count should list as 0

        self.debug("Setting up account and domain hierarchy")
        self.setupAccounts()
        users = {
            self.child_domain_1: self.child_do_admin_1,
            self.child_domain_2: self.child_do_admin_2
        }
        for domain, admin in users.items():
            self.account = admin
            self.domain = domain

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

            self.debug("Creating an instance with service offering: %s" %
                       self.service_offering.name)
            vm = self.createInstance(service_off=self.service_offering,
                                     api_client=api_client)

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(
                account_list, list,
                "List Accounts should return a valid response")
            resource_count = account_list[0].memorytotal

            expected_resource_count = int(
                self.services["service_offering"]["memory"])

            self.assertEqual(
                resource_count, expected_resource_count,
                "Initial resource count should match with the expected resource count"
            )

            self.debug("Destroying instance: %s" % vm.name)
            try:
                vm.delete(self.apiclient)
            except Exception as e:
                self.fail("Failed to delete instance: %s" % e)

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(
                account_list, list,
                "List Accounts should return a valid response")
            resource_count = account_list[0].memorytotal
            self.assertEqual(resource_count, 0,
                             "Resource count for %s should be 0" %
                             get_resource_type(resource_id=9))  #RAM
        return
コード例 #12
0
    def test_04_deploy_multiple_vm(self):
        """Test Deploy multiple VM with specified RAM & verify the usage"""

        # Validate the following
        # 1. Create compute offering with specified RAM
        # 2. Deploy multiple VMs with this service offering
        # 3. List Resource count for the root admin Memory usage
        # 4. Memory usage should list properly

        account_list = Account.list(self.apiclient, id=self.account.id)
        self.assertIsInstance(account_list, list,
                              "List Accounts should return a valid response")
        resource_count = account_list[0].memorytotal

        expected_resource_count = int(
            self.services["service_offering"]["memory"])

        self.assertEqual(
            resource_count, expected_resource_count,
            "Resource count should match with the expected resource count")

        self.debug("Creating two instances with service offering: %s" %
                   self.service_offering.name)
        vm_1 = self.createInstance(service_off=self.service_offering)
        self.createInstance(service_off=self.service_offering)

        account_list = Account.list(self.apiclient, id=self.account.id)
        self.assertIsInstance(account_list, list,
                              "List Accounts should return a valid response")
        resource_count_new = account_list[0].memorytotal

        expected_resource_count = int(
            self.services["service_offering"]["memory"]) * 3  #Total 3 VMs

        self.assertEqual(
            resource_count_new, expected_resource_count,
            "Resource count should match with the expected resource count")

        self.debug("Destroying instance: %s" % vm_1.name)
        try:
            vm_1.delete(self.apiclient)
        except Exception as e:
            self.fail("Failed to delete instance: %s" % e)

        account_list = Account.list(self.apiclient, id=self.account.id)
        self.assertIsInstance(account_list, list,
                              "List Accounts should return a valid response")
        resource_count_after_delete = account_list[0].memorytotal

        expected_resource_count -= int(
            self.services["service_offering"]["memory"])

        self.assertEqual(
            resource_count_after_delete, expected_resource_count,
            "Resource count should match with the expected resource count")
        return
コード例 #13
0
    def test_04_deploy_multiple_vm(self):
        """Test Deploy multiple VM with specified RAM & verify the usage"""

        # Validate the following
        # 1. Create compute offering with specified RAM
        # 2. Deploy multiple VMs with this service offering
        # 3. List Resource count for the root admin Memory usage
        # 4. Memory usage should list properly

        account_list = Account.list(self.apiclient, id=self.account.id)
        self.assertIsInstance(account_list,
                              list,
                              "List Accounts should return a valid response"
                              )
        resource_count = account_list[0].memorytotal

        expected_resource_count = int(self.services["service_offering"]["memory"])

        self.assertEqual(resource_count, expected_resource_count,
                         "Resource count should match with the expected resource count")

        self.debug("Creating two instances with service offering: %s" %
                                                    self.service_offering.name)
        vm_1 = self.createInstance(service_off=self.service_offering)
        self.createInstance(service_off=self.service_offering)

        account_list = Account.list(self.apiclient, id=self.account.id)
        self.assertIsInstance(account_list,
                              list,
                              "List Accounts should return a valid response"
                              )
        resource_count_new = account_list[0].memorytotal

        expected_resource_count = int(self.services["service_offering"]["memory"]) * 3 #Total 3 VMs

        self.assertEqual(resource_count_new, expected_resource_count,
                         "Resource count should match with the expected resource count")

        self.debug("Destroying instance: %s" % vm_1.name)
        try:
            vm_1.delete(self.apiclient)
        except Exception as e:
            self.fail("Failed to delete instance: %s" % e)

        account_list = Account.list(self.apiclient, id=self.account.id)
        self.assertIsInstance(account_list,
                              list,
                              "List Accounts should return a valid response"
                              )
        resource_count_after_delete = account_list[0].memorytotal

        expected_resource_count -= int(self.services["service_offering"]["memory"])

        self.assertEqual(resource_count_after_delete, expected_resource_count,
                         "Resource count should match with the expected resource count")
        return
コード例 #14
0
    def test_02_migrate_instance(self):
        """Test Deploy VM with specified memory & verify the usage"""

        # Validate the following
        # 1. Create compute offering with specified memory in child domains of root domain & Deploy VM
        # 2. List Resource count
        # 3. Migrate instance to another host
        # 4. Resource count should list properly.
        self.hypervisor = self.testClient.getHypervisorInfo()
        if self.hypervisor.lower() in ["lxc"]:
            self.skipTest("vm migrate feature is not supported on %s" % self.hypervisor.lower())

        self.debug("Setting up account and domain hierarchy")
        self.setupAccounts()
        users = {self.child_domain_1: self.child_do_admin_1, self.child_domain_2: self.child_do_admin_2}
        for domain, admin in users.items():
            self.account = admin
            self.domain = domain

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

            self.debug("Creating an instance with service offering: %s" % self.service_offering.name)
            vm = self.createInstance(service_off=self.service_offering, api_client=api_client)

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(account_list, list, "List Accounts should return a valid response")
            resource_count = account_list[0].memorytotal

            expected_resource_count = int(self.services["service_offering"]["memory"])

            self.assertEqual(
                resource_count,
                expected_resource_count,
                "Initial resource count should with the expected resource count",
            )

            host = findSuitableHostForMigration(self.apiclient, vm.id)
            if host is None:
                self.skipTest(ERROR_NO_HOST_FOR_MIGRATION)
            self.debug("Migrating instance: %s to host: %s" % (vm.name, host.name))
            try:
                vm.migrate(self.apiclient, host.id)
            except Exception as e:
                self.fail("Failed to migrate instance: %s" % e)

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(account_list, list, "List Accounts should return a valid response")
            resource_count_after_migrate = account_list[0].memorytotal

            self.assertEqual(
                resource_count,
                resource_count_after_migrate,
                "Resource count should be same after starting the instance",
            )
        return
コード例 #15
0
    def test_03_multiple_core_vm_delete_instance(self):
        """Test Deploy VM with 4 core CPU & verify the usage"""

        # Validate the following
        # 1. Create two domains and set specific resource (cpu) limit for them
        # 2. Create compute offering with 4 core CPU & deploy vm
        # 3. Update Resource count for the domains
        # 4. delete instance and check resource count
        # 5. Resource count should list properly.

        self.debug("Setting up account and domain hierarchy")
        self.setupAccounts()
        users = {self.domain: self.admin,
                 self.child_domain: self.child_do_admin
                 }
        for domain, admin in users.items():
            self.account = admin
            self.domain = domain

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

            self.debug("Creating an instance with service offering: %s" %
                       self.service_offering.name)
            vm = self.createInstance(service_off=self.service_offering, api_client=api_client)

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(account_list,
                list,
                "List Accounts should return a valid response"
            )
            resource_count = account_list[0].cputotal

            expected_resource_count = int(self.services["service_offering"]["cpunumber"])

            self.assertEqual(resource_count, expected_resource_count,
                "Initial resource count should with the expected resource count")

            self.debug("Destroying instance: %s" % vm.name)
            try:
                vm.delete(self.apiclient)
            except Exception as e:
                self.fail("Failed to delete instance: %s" % e)

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(account_list,
                list,
                "List Accounts should return a valid response"
            )
            resource_count_after_delete = account_list[0].cputotal

            self.assertEqual(resource_count_after_delete, 0,
                "Resource count for %s should be 0" % get_resource_type(resource_id=8))#CPU
        return
コード例 #16
0
    def test_03_delete_instance(self):
        """Test Deploy VM with specified RAM & verify the usage"""

        # Validate the following
        # 1. Create compute offering with specified RAM in child domains of root domain & Deploy VM
        # 2. List Resource count for the Memory usage
        # 3. Delete instance
        # 4. Resource count should list as 0

        self.debug("Setting up account and domain hierarchy")
        self.setupAccounts()
        users = {self.child_domain_1: self.child_do_admin_1,
                 self.child_domain_2: self.child_do_admin_2
                 }
        for domain, admin in users.items():
            self.account = admin
            self.domain = domain

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

            self.debug("Creating an instance with service offering: %s" %
                       self.service_offering.name)
            vm = self.createInstance(service_off=self.service_offering, api_client=api_client)

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(account_list,
                                  list,
                                  "List Accounts should return a valid response"
                                  )
            resource_count = account_list[0].memorytotal

            expected_resource_count = int(self.services["service_offering"]["memory"])

            self.assertEqual(resource_count, expected_resource_count,
                             "Initial resource count should match with the expected resource count")

            self.debug("Destroying instance: %s" % vm.name)
            try:
                vm.delete(self.apiclient)
            except Exception as e:
                self.fail("Failed to delete instance: %s" % e)

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(account_list,
                                  list,
                                  "List Accounts should return a valid response"
                                  )
            resource_count = account_list[0].memorytotal
            self.assertEqual(resource_count, 0,
                             "Resource count for %s should be 0" % get_resource_type(resource_id=9))  # RAM
        return
コード例 #17
0
    def test_01_multiplecore_start_stop_instance(self):
        """Test Deploy VM with multiple core CPU & verify the usage"""

        # Validate the following
        # 1. Deploy VM with multiple core CPU & verify the usage
        # 2. Stop VM & verify the update resource count of Root Admin Account
        # 3. Start VM & verify the update resource count of Root Admin Account
        # 4. Resource count should list properly.

        account_list = Account.list(self.apiclient, id=self.account.id)
        self.assertIsInstance(account_list,
                              list,
                              "List Accounts should return a valid response"
                              )
        resource_count = account_list[0].cputotal

        expected_resource_count = int(self.services["service_offering"]["cpunumber"])

        self.assertEqual(resource_count, expected_resource_count,
                         "Resource count should match with the expected resource count")

        self.debug("Stopping instance: %s" % self.vm.name)
        try:
            self.vm.stop(self.apiclient)
        except Exception as e:
            self.fail("Failed to stop instance: %s" % e)

        account_list = Account.list(self.apiclient, id=self.account.id)
        self.assertIsInstance(account_list,
                              list,
                              "List Accounts should return a valid response"
                              )
        resource_count_after_stop = account_list[0].cputotal

        self.assertEqual(resource_count, resource_count_after_stop,
                         "Resource count should be same after stopping the instance")

        self.debug("Starting instance: %s" % self.vm.name)
        try:
            self.vm.start(self.apiclient)
        except Exception as e:
            self.fail("Failed to start instance: %s" % e)

        account_list = Account.list(self.apiclient, id=self.account.id)
        self.assertIsInstance(account_list,
                              list,
                              "List Accounts should return a valid response"
                              )
        resource_count_after_start = account_list[0].cputotal

        self.assertEqual(resource_count, resource_count_after_start,
                         "Resource count should be same after stopping the instance")
        return
コード例 #18
0
    def test_01_multiplecore_start_stop_instance(self):
        """Test Deploy VM with multiple core CPU & verify the usage"""

        # Validate the following
        # 1. Deploy VM with multiple core CPU & verify the usage
        # 2. Stop VM & verify the update resource count of Root Admin Account
        # 3. Start VM & verify the update resource count of Root Admin Account
        # 4. Resource count should list properly.

        account_list = Account.list(self.apiclient, id=self.account.id)
        self.assertIsInstance(account_list, list,
                              "List Accounts should return a valid response")
        resource_count = account_list[0].cputotal

        expected_resource_count = int(
            self.services["service_offering"]["cpunumber"])

        self.assertEqual(
            resource_count, expected_resource_count,
            "Resource count should match with the expected resource count")

        self.debug("Stopping instance: %s" % self.vm.name)
        try:
            self.vm.stop(self.apiclient)
        except Exception as e:
            self.fail("Failed to stop instance: %s" % e)

        account_list = Account.list(self.apiclient, id=self.account.id)
        self.assertIsInstance(account_list, list,
                              "List Accounts should return a valid response")
        resource_count_after_stop = account_list[0].cputotal

        self.assertEqual(
            resource_count, resource_count_after_stop,
            "Resource count should be same after stopping the instance")

        self.debug("Starting instance: %s" % self.vm.name)
        try:
            self.vm.start(self.apiclient)
        except Exception as e:
            self.fail("Failed to start instance: %s" % e)

        account_list = Account.list(self.apiclient, id=self.account.id)
        self.assertIsInstance(account_list, list,
                              "List Accounts should return a valid response")
        resource_count_after_start = account_list[0].cputotal

        self.assertEqual(
            resource_count, resource_count_after_start,
            "Resource count should be same after stopping the instance")
        return
コード例 #19
0
    def test_01_stop_start_instance(self):
        """Test Deploy VM with specified RAM & verify the usage"""

        # Validate the following
        # 1. Create compute offering with specified RAM & Deploy VM as root admin
        # 2 .List Resource count for the root admin Memory usage
        # 3. Stop and start instance, resource count should list properly.

        account_list = Account.list(self.apiclient, id=self.account.id)
        self.assertIsInstance(account_list,
                              list,
                              "List Accounts should return a valid response"
                              )
        resource_count = account_list[0].memorytotal

        expected_resource_count = int(self.services["service_offering"]["memory"])

        self.assertEqual(resource_count, expected_resource_count,
                         "Resource count should match with the expected resource count")

        self.debug("Stopping instance: %s" % self.vm.name)
        try:
            self.vm.stop(self.apiclient)
        except Exception as e:
            self.fail("Failed to stop instance: %s" % e)
        account_list = Account.list(self.apiclient, id=self.account.id)
        self.assertIsInstance(account_list,
                              list,
                              "List Accounts should return a valid response"
                              )
        resource_count_after_stop = account_list[0].memorytotal

        self.assertEqual(resource_count, resource_count_after_stop,
                         "Resource count should be same after stopping the instance")

        self.debug("Starting instance: %s" % self.vm.name)
        try:
            self.vm.start(self.apiclient)
        except Exception as e:
            self.fail("Failed to start instance: %s" % e)
        account_list = Account.list(self.apiclient, id=self.account.id)
        self.assertIsInstance(account_list,
                              list,
                              "List Accounts should return a valid response"
                              )
        resource_count_after_start = account_list[0].memorytotal

        self.assertEqual(resource_count, resource_count_after_start,
                         "Resource count should be same after stopping the instance")
        return
コード例 #20
0
    def test_01_stop_start_instance(self):
        """Test Deploy VM with specified RAM & verify the usage"""

        # Validate the following
        # 1. Create compute offering with specified RAM & Deploy VM as root admin
        # 2 .List Resource count for the root admin Memory usage
        # 3. Stop and start instance, resource count should list properly.

        account_list = Account.list(self.apiclient, id=self.account.id)
        self.assertIsInstance(account_list,
                              list,
                              "List Accounts should return a valid response"
                              )
        resource_count = account_list[0].memorytotal

        expected_resource_count = int(self.services["service_offering"]["memory"])

        self.assertEqual(resource_count, expected_resource_count,
                         "Resource count should match with the expected resource count")

        self.debug("Stopping instance: %s" % self.vm.name)
        try:
            self.vm.stop(self.apiclient)
        except Exception as e:
            self.fail("Failed to stop instance: %s" % e)
        account_list = Account.list(self.apiclient, id=self.account.id)
        self.assertIsInstance(account_list,
                              list,
                              "List Accounts should return a valid response"
                              )
        resource_count_after_stop = account_list[0].memorytotal

        self.assertEqual(resource_count, resource_count_after_stop,
                         "Resource count should be same after stopping the instance")

        self.debug("Starting instance: %s" % self.vm.name)
        try:
            self.vm.start(self.apiclient)
        except Exception as e:
            self.fail("Failed to start instance: %s" % e)
        account_list = Account.list(self.apiclient, id=self.account.id)
        self.assertIsInstance(account_list,
                              list,
                              "List Accounts should return a valid response"
                              )
        resource_count_after_start = account_list[0].memorytotal

        self.assertEqual(resource_count, resource_count_after_start,
                         "Resource count should be same after stopping the instance")
        return
コード例 #21
0
def matchResourceCount(apiclient, expectedCount, resourceType,
                              accountid=None, projectid=None):
    """Match the resource count of account/project with the expected
    resource count"""
    try:
        resourceholderlist = None
        if accountid:
            resourceholderlist = Account.list(apiclient, id=accountid)
        elif projectid:
            resourceholderlist = Project.list(apiclient, id=projectid, listall=True)
        validationresult = validateList(resourceholderlist)
        assert validationresult[0] == PASS,\
               "accounts list validation failed"
        if resourceType == RESOURCE_PRIMARY_STORAGE:
            resourceCount = resourceholderlist[0].primarystoragetotal
        elif resourceType == RESOURCE_SECONDARY_STORAGE:
            resourceCount = resourceholderlist[0].secondarystoragetotal
        elif resourceType == RESOURCE_CPU:
            resourceCount = resourceholderlist[0].cputotal
        elif resourceType == RESOURCE_MEMORY:
            resourceCount = resourceholderlist[0].memorytotal
        assert str(resourceCount) == str(expectedCount),\
                "Resource count %s should match with the expected resource count %s" %\
                (resourceCount, expectedCount)
    except Exception as e:
        return [FAIL, e]
    return [PASS, None]
コード例 #22
0
    def setupNormalAccount(self):
        """Setup the account required for the test"""

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

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

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

            accounts = Account.list(self.apiclient, id=self.account.id)

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

            self.initialResourceCount = int(accounts[0].primarystoragetotal)

            primarystoragelimit = self.initialResourceCount
            update_resource_limit(self.api_client, RESOURCE_PRIMARY_STORAGE, account=self.account.name, domainid=self.account.domainid, max=primarystoragelimit)

        except Exception as e:
            return [FAIL, e]
        return [PASS, None]
コード例 #23
0
    def test_01_manual(self):
        '''
        test if an account can be imported

        prerequisite
        a ldap host is configured
        a domain is linked to cloudstack
        '''
        cmd = listLdapUsers.listLdapUsersCmd()
        cmd.domainid = self.manualDomain.id
        cmd.userfilter = "LocalDomain"
        response = self.apiclient.listLdapUsers(cmd)
        self.logger.info("users found for linked domain %s" % response)
        self.assertEqual(len(response), len(self.testdata.testdata[LdapTestData.users]), "unexpected number (%d) of ldap users" % len(self.testdata.testdata[LdapTestData.users]))

        cmd = ldapCreateAccount.ldapCreateAccountCmd()
        cmd.domainid = self.manualDomain.id
        cmd.accounttype = 0
        cmd.username = self.test_user[1]
        create_response = self.apiclient.ldapCreateAccount(cmd)

        # cleanup
        # last results id should be the account
        list_response = Account.list(self.apiclient, id=create_response.id)
        account_created = Account(list_response[0].__dict__)
        self.cleanup.append(account_created)

        self.assertEqual(len(create_response.user), 1, "only one user %s should be present" % self.test_user[1])

        self.assertEqual(len(list_response),
                         1,
                         "only one account (for user %s) should be present" % self.test_user[1])

        return
コード例 #24
0
    def deploy_account(self, account_data, domain):
        self.logger.debug('>>>  ACCOUNT  =>  Creating "%s"...', account_data['username'])
        account = None
        if not self.randomizeNames:
            account_list = Account.list(api_client=self.api_client, name=account_data['username'], listall=True)
            if isinstance(account_list, list) and len(account_list) >= 1:
                if account_list[0].name == account_data['username']:
                    account = account_list[0]
                    self.logger.debug('>>>  ACCOUNT  =>  Loaded from (pre) existing account,  ID: %s', account.id)
                    return

        if not account:
            account = Account.create(
                api_client=self.api_client,
                services=account_data,
                domainid=domain.uuid,
                randomizeID=self.randomizeNames
            )
        self.resources_to_cleanup.append(account)
        self.dynamic_names['accounts'][account_data['username']] = account.name

        self.logger.debug('>>>  ACCOUNT  =>  ID: %s  =>  Name: %s  =>  State: %s  =>  Domain: %s', account.id,
                          account.name, account.state, account.domainid)

        self.deploy_vpcs(account_data['vpcs'], account)
        self.deploy_isolatednetworks(account_data['isolatednetworks'], account)
        self.deploy_vms(account_data['virtualmachines'], account)
        self.deploy_vpcs_publicipaddresses(account_data['vpcs'], account_data['virtualmachines'])
        self.deploy_isolatednetworks_publicipaddresses(account_data['isolatednetworks'], account_data['virtualmachines'])
        self.deploy_privatenetworks(account_data['privatenetworks'], account, domain)
        self.deploy_vpcs_privategateways(account_data['vpcs'])
        self.enable_vpcs_localvpngateway(account_data['vpcs'])
        self.deploy_vpcs_remotevpngateways(account_data['vpcs'], account)
コード例 #25
0
ファイル: common.py プロジェクト: rafaelthedevops/cloudstack
def matchResourceCount(apiclient, expectedCount, resourceType, accountid=None, projectid=None):
    """Match the resource count of account/project with the expected
    resource count"""
    try:
        resourceholderlist = None
        if accountid:
            resourceholderlist = Account.list(apiclient, id=accountid)
        elif projectid:
            resourceholderlist = Project.list(apiclient, id=projectid, listall=True)
        validationresult = validateList(resourceholderlist)
        assert validationresult[0] == PASS, "accounts list validation failed"
        if resourceType == RESOURCE_PRIMARY_STORAGE:
            resourceCount = resourceholderlist[0].primarystoragetotal
        elif resourceType == RESOURCE_SECONDARY_STORAGE:
            resourceCount = resourceholderlist[0].secondarystoragetotal
        elif resourceType == RESOURCE_CPU:
            resourceCount = resourceholderlist[0].cputotal
        elif resourceType == RESOURCE_MEMORY:
            resourceCount = resourceholderlist[0].memorytotal
        assert str(resourceCount) == str(
            expectedCount
        ), "Resource count %s should match with the expected resource count %s" % (resourceCount, expectedCount)
    except Exception as e:
        return [FAIL, e]
    return [PASS, None]
コード例 #26
0
    def test_02_import(self):
        '''
        test if components are synced

        prerequisite
        a ldap host is configured
        a domain is linked to cloudstack
        '''
        domainid = self.importDomain.id

        cmd = importLdapUsers.importLdapUsersCmd()
        cmd.domainid = domainid
        cmd.accounttype = 0
        import_response = self.apiclient.importLdapUsers(cmd)

        # this is needed purely for cleanup:
        # cleanup
        list_response = Account.list(self.apiclient, domainid=domainid)
        for account in list_response:
            account_created = Account(account.__dict__)
            self.logger.debug("account to clean: %s (id: %s)" %
                              (account_created.name, account_created.id))
            self.cleanup.append(account_created)

        self.assertEqual(len(import_response),
                         len(self.testdata.testdata[LdapTestData.users]),
                         "unexpected number of ldap users")

        self.assertEqual(
            len(list_response),
            len(self.testdata.testdata[LdapTestData.users]),
            "only one account (for user %s) should be present" %
            self.test_user[1])

        return
コード例 #27
0
    def setupAccount(self, accountType):
        """Setup the account required for the test"""

        try:
            if accountType == CHILD_DOMAIN_ADMIN:
                self.domain = Domain.create(self.apiclient,
                                        services=self.services["domain"],
                                        parentdomainid=self.domain.id)

            self.account = Account.create(self.apiclient, self.services["account"],
                                      domainid=self.domain.id, admin=True)
            self.cleanup.append(self.account)
            if accountType == CHILD_DOMAIN_ADMIN:
                self.cleanup.append(self.domain)

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

            accounts = Account.list(self.apiclient, id=self.account.id)

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

            self.initialResourceCount = int(accounts[0].primarystoragetotal)
        except Exception as e:
            return [FAIL, e]
        return [PASS, None]
コード例 #28
0
    def test_04_deploy_multiple_vm_with_multiple_cpus(self):
        """Test Deploy multiple VM with 4 core CPU & verify the usage"""

        # Validate the following
        # 1. Create compute offering with 4 core CPU
        # 2. Deploy multiple VMs with this service offering
        # 3. List Resource count for the root admin CPU usage
        # 4. CPU usage should list properly
        # 5. Destroy one VM among multiple VM's and verify the resource count
        # 6. Migrate VM from & verify resource updates
        # 7. List resource count for Root Admin
        # 8. Failed to deploy VM and verify the resource usage

        self.debug("Creating service offering with 4 CPU cores")
        self.service_offering = ServiceOffering.create(
            self.apiclient, self.testdata["service_offering_multiple_cores"])
        # Adding to cleanup list after execution
        self.cleanup.append(self.service_offering)

        self.debug("Creating an instance with service offering: %s" %
                   self.service_offering.name)
        vm_1 = self.createInstance(service_off=self.service_offering)
        vm_2 = self.createInstance(service_off=self.service_offering)
        self.createInstance(service_off=self.service_offering)

        account_list = Account.list(self.apiclient, id=self.account.id)
        self.assertIsInstance(account_list, list,
                              "List Accounts should return a valid response")
        resource_count = account_list[0].cputotal

        expected_resource_count = int(
            self.service_offering.cpunumber) * 4  #Total 4 Vms
        self.assertTrue(resource_count == expected_resource_count,
                        "Resource count does not match the expected vavlue")
        return
コード例 #29
0
    def setupAccount(self, accountType):
        """Setup the account required for the test"""

        try:
            if accountType == CHILD_DOMAIN_ADMIN:
                self.domain = Domain.create(self.apiclient,
                                            services=self.services["domain"],
                                            parentdomainid=self.domain.id)

            self.account = Account.create(self.apiclient,
                                          self.services["account"],
                                          domainid=self.domain.id,
                                          admin=True)
            self.cleanup.append(self.account)
            if accountType == CHILD_DOMAIN_ADMIN:
                self.cleanup.append(self.domain)

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

            accounts = Account.list(self.apiclient, id=self.account.id)

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

            self.initialResourceCount = int(accounts[0].primarystoragetotal)
        except Exception as e:
            return [FAIL, e]
        return [PASS, None]
コード例 #30
0
    def setUp(self):
        self.user = self.services["configurableData"]["link_ldap_details"]["linkLdapUsername"]
        self.password = self.services["configurableData"]["link_ldap_details"]["linkLdapPassword"]
        self.delflag1 = 0
        self.delflag2 = 0
        self.delflag3 = 0
        self.delflag4 = 0

        self.apiclient = self.testClient.getApiClient()
        self.dbclient = self.testClient.getDbConnection()
        self.cleanup = []

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

        self.ldaplink = linkDomainToLdap.linkDomainToLdapCmd()
        self.ldaplink.domainid = self.parent_domain.id
        self.ldaplink.accounttype = self.services[
            "configurableData"]["link_ldap_details"]["accounttype"]
        self.ldaplink.name = self.services[
            "configurableData"]["link_ldap_details"]["name"]
        self.ldaplink.type = self.services[
            "configurableData"]["link_ldap_details"]["type"]
        if self.services["configurableData"][
            "link_ldap_details"]["admin"] is not None:
            self.ldaplink.admin = self.services[
                "configurableData"]["link_ldap_details"]["admin"]

        if self.ldaplink.domainid == "" or self.ldaplink.accounttype == "" \
                or self.ldaplink.name == "" \
                or self.ldaplink.type == "":
            self.debug(
                "Please rerun the test by providing "
                "values in link_ldap configuration user details")
            self.skipTest(
                "Please rerun the test by providing "
                "proper values in configuration file(link ldap)")
        else:
            self.delflag1 = 1
            self.ldaplinkRes = self.apiClient.linkDomainToLdap(self.ldaplink)
        self.assertEquals(
            self.delflag1,
            1,
            "Linking LDAP failed,please check the configuration")
        loginRes = checklogin(self,
                              self.user, self.password,
                              self.parent_domain.name,
                              method="POST")
        self.debug(loginRes)
        self.assertEquals(loginRes, 1, self.reason)

        lsap_user = Account.list(self.api_client,
                                 domainid=self.parent_domain.id,
                                 name=self.user
                                 )
        self.ldapacctID = lsap_user[0].id
コード例 #31
0
    def test_04_deploy_multiple_vm(self):
        """Test Deploy multiple VM with specified RAM & verify the usage"""

        # Validate the following
        # 1. Create compute offering with specified RAM
        # 2. Deploy multiple VMs with this service offering
        # 3. List Resource count for the root admin Memory usage
        # 4. Memory usage should list properly

        # Resetting the memory count of service offering
        self.services["service_offering"]["memory"] = 2048

        self.debug("Setting up account and domain hierarchy")
        self.setupAccounts()
        users = {
            self.child_domain_1: self.child_do_admin_1,
            self.child_domain_2: self.child_do_admin_2
        }
        for domain, admin in users.items():
            self.account = admin
            self.domain = domain
            self.debug("Creating an instance with service offering: %s" %
                       self.service_offering.name)

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

            vm_1 = self.createInstance(service_off=self.service_offering,
                                       api_client=api_client)
            vm_2 = self.createInstance(service_off=self.service_offering,
                                       api_client=api_client)
            vm_3 = self.createInstance(service_off=self.service_offering,
                                       api_client=api_client)

            self.debug(
                "Deploying instance - Memory capacity is fully utilized")
            with self.assertRaises(Exception):
                self.createInstance(service_off=self.service_offering,
                                    api_client=api_client)

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(
                account_list, list,
                "List Accounts should return a valid response")
            resource_count = account_list[0].memorytotal

            expected_resource_count = int(
                self.services["service_offering"]["memory"]) * 3  #Total 3 VMs

            self.assertEqual(
                resource_count, expected_resource_count,
                "Resource count should match with the expected resource count")

            vm_2.delete(self.apiclient)
            vm_3.delete(self.apiclient)
        return
コード例 #32
0
    def test_02_migrate_instance(self):
        """Test Deploy VM with specified RAM & verify the usage"""

        # Validate the following
        # 1. Create compute offering with specified RAM & Deploy VM as root admin
        # 2. List Resource count for the root admin Memory usage
        # 3. Migrate vm, resource count should list properly.
        self.hypervisor = self.testClient.getHypervisorInfo()
        if self.hypervisor.lower() in ['lxc']:
            self.skipTest("vm migrate feature is not supported on %s" %
                          self.hypervisor.lower())

        account_list = Account.list(self.apiclient, id=self.account.id)
        self.assertIsInstance(account_list, list,
                              "List Accounts should return a valid response")
        resource_count = account_list[0].memorytotal

        expected_resource_count = int(
            self.services["service_offering"]["memory"])

        self.assertEqual(
            resource_count, expected_resource_count,
            "Resource count should match with the expected resource count")

        host = findSuitableHostForMigration(self.apiclient, self.vm.id)
        if host is None:
            self.skipTest(ERROR_NO_HOST_FOR_MIGRATION)
        self.debug("Migrating instance: %s to host: %s" %
                   (self.vm.name, host.name))
        try:
            self.vm.migrate(self.apiclient, host.id)
        except Exception as e:
            self.fail("Failed to migrate instance: %s" % e)

        account_list = Account.list(self.apiclient, id=self.account.id)
        self.assertIsInstance(account_list, list,
                              "List Accounts should return a valid response")
        resource_count_after_migrate = account_list[0].memorytotal

        self.assertEqual(
            resource_count, resource_count_after_migrate,
            "Resource count should be same after stopping the instance")
        return
コード例 #33
0
    def test_02_multiplecore_migrate_instance(self):
        """Test Deploy VM with multiple core CPU & verify the usage"""

        # Validate the following
        # 1. Deploy VM with multiple core CPU & verify the usage
        # 2. Migrate VM & verify updated resource count of Root Admin Account
        # 3. Resource count should list properly.
        self.hypervisor = self.testClient.getHypervisorInfo()
        if self.hypervisor.lower() in ['lxc']:
            self.skipTest("vm migrate is not supported in %s" %
                          self.hypervisor)

        account_list = Account.list(self.apiclient, id=self.account.id)
        self.assertIsInstance(account_list, list,
                              "List Accounts should return a valid response")
        resource_count = account_list[0].cputotal

        expected_resource_count = int(
            self.services["service_offering"]["cpunumber"])

        self.assertEqual(
            resource_count, expected_resource_count,
            "Resource count should match with the expected resource count")

        host = findSuitableHostForMigration(self.apiclient, self.vm.id)
        if host is None:
            self.skipTest(ERROR_NO_HOST_FOR_MIGRATION)
        self.debug("Migrating instance: %s to host: %s" %
                   (self.vm.name, host.name))
        try:
            self.vm.migrate(self.apiclient, host.id)
        except Exception as e:
            self.fail("Failed to migrate instance: %s" % e)

        account_list = Account.list(self.apiclient, id=self.account.id)
        self.assertIsInstance(account_list, list,
                              "List Accounts should return a valid response")
        resource_count_after_migrate = account_list[0].cputotal

        self.assertEqual(
            resource_count, resource_count_after_migrate,
            "Resource count should be same after migrating the instance")
        return
コード例 #34
0
    def test_02_multiplecore_migrate_instance(self):
        """Test Deploy VM with multiple core CPU & verify the usage"""

        # Validate the following
        # 1. Deploy VM with multiple core CPU & verify the usage
        # 2. Migrate VM & verify updated resource count of Root Admin Account
        # 3. Resource count should list properly.
        self.hypervisor = self.testClient.getHypervisorInfo()
        if self.hypervisor.lower() in ['lxc']:
            self.skipTest("vm migrate is not supported in %s" % self.hypervisor)

        account_list = Account.list(self.apiclient, id=self.account.id)
        self.assertIsInstance(account_list,
                              list,
                              "List Accounts should return a valid response"
                              )
        resource_count = account_list[0].cputotal

        expected_resource_count = int(self.services["service_offering"]["cpunumber"])

        self.assertEqual(resource_count, expected_resource_count,
                         "Resource count should match with the expected resource count")

        host = findSuitableHostForMigration(self.apiclient, self.vm.id)
        if host is None:
            self.skipTest(ERROR_NO_HOST_FOR_MIGRATION)
        self.debug("Migrating instance: %s to host: %s" % (self.vm.name, host.name))
        try:
            self.vm.migrate(self.apiclient, host.id)
        except Exception as e:
            self.fail("Failed to migrate instance: %s" % e)

        account_list = Account.list(self.apiclient, id=self.account.id)
        self.assertIsInstance(account_list,
                              list,
                              "List Accounts should return a valid response"
                              )
        resource_count_after_migrate = account_list[0].cputotal

        self.assertEqual(resource_count, resource_count_after_migrate,
                         "Resource count should be same after migrating the instance")
        return
コード例 #35
0
    def test_02_migrate_instance(self):
        """Test Deploy VM with specified RAM & verify the usage"""

        # Validate the following
        # 1. Create compute offering with specified RAM & Deploy VM as root admin
        # 2. List Resource count for the root admin Memory usage
        # 3. Migrate vm, resource count should list properly.
        self.hypervisor = self.testClient.getHypervisorInfo()

        account_list = Account.list(self.apiclient, id=self.account.id)
        self.assertIsInstance(account_list,
                              list,
                              "List Accounts should return a valid response"
                              )
        resource_count = account_list[0].memorytotal

        expected_resource_count = int(self.services["service_offering"]["memory"])

        self.assertEqual(resource_count, expected_resource_count,
                         "Resource count should match with the expected resource count")

        host = findSuitableHostForMigration(self.apiclient, self.vm.id)
        if host is None:
            self.skipTest(ERROR_NO_HOST_FOR_MIGRATION)
        self.debug("Migrating instance: %s to host: %s" % (self.vm.name, host.name))
        try:
            self.vm.migrate(self.apiclient, host.id)
        except Exception as e:
            self.fail("Failed to migrate instance: %s" % e)

        account_list = Account.list(self.apiclient, id=self.account.id)
        self.assertIsInstance(account_list,
                              list,
                              "List Accounts should return a valid response"
                              )
        resource_count_after_migrate = account_list[0].memorytotal

        self.assertEqual(resource_count, resource_count_after_migrate,
                         "Resource count should be same after stopping the instance")
        return
コード例 #36
0
    def test_01_deploy_vm_domain_limit_reached(self):
        """Test Try to deploy VM with admin account where account has not used
            the resources but @ domain they are not available

        # Validate the following
        # 1. Try to deploy VM with admin account where account has not used the
        #    resources but @ domain they are not available
        # 2. Deploy VM should error out saying  ResourceAllocationException
        #    with "resource limit exceeds"""

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

        accounts = Account.list(self.apiclient, id=self.child_do_admin.id)
        self.assertEqual(
            validateList(accounts)[0], PASS, "accounts list validation failed")

        self.initialResourceCount = int(accounts[0].primarystoragetotal)
        domainLimit = self.initialResourceCount + 3

        self.debug("Setting up account and domain hierarchy")
        response = self.updatePrimaryStorageLimits(domainLimit=domainLimit)
        self.assertEqual(response[0], PASS, response[1])

        self.services["volume"]["size"] = self.services["disk_offering"][
            "disksize"] = 2

        try:
            disk_offering = DiskOffering.create(
                self.apiclient, services=self.services["disk_offering"])
            self.cleanup.append(disk_offering)
            Volume.create(self.apiclient,
                          self.services["volume"],
                          zoneid=self.zone.id,
                          account=self.child_do_admin.name,
                          domainid=self.child_do_admin.domainid,
                          diskofferingid=disk_offering.id)
        except Exception as e:
            self.fail("Exception occurred: %s" % e)

        with self.assertRaises(Exception):
            Volume.create(self.apiclient,
                          self.services["volume"],
                          zoneid=self.zone.id,
                          account=self.child_do_admin.name,
                          domainid=self.child_do_admin.domainid,
                          diskofferingid=disk_offering.id)
        return
コード例 #37
0
    def test_03_delete_instance(self):
        """Test Deploy VM with specified GB RAM & verify the usage"""

        # Validate the following
        # 1. Create compute offering with specified RAM & Deploy VM as root admin
        # 2. List Resource count for the root admin Memory usage
        # 3. Delete instance, resource count should be 0 after delete operation.

        account_list = Account.list(self.apiclient, id=self.account.id)
        self.assertIsInstance(account_list, list,
                              "List Accounts should return a valid response")
        resource_count = account_list[0].memorytotal

        expected_resource_count = int(
            self.services["service_offering"]["memory"])

        self.assertEqual(
            resource_count, expected_resource_count,
            "Resource count should match with the expected resource count")

        self.debug("Destroying instance: %s" % self.vm.name)
        try:
            self.vm.delete(self.apiclient)
        except Exception as e:
            self.fail("Failed to delete instance: %s" % e)

            # Wait for expunge interval to cleanup Memory
            wait_for_cleanup(self.apiclient,
                             ["expunge.delay", "expunge.interval"])

        account_list = Account.list(self.apiclient, id=self.account.id)
        self.assertIsInstance(account_list, list,
                              "List Accounts should return a valid response")
        resource_count_after_delete = account_list[0].memorytotal
        self.assertEqual(resource_count_after_delete, 0,
                         "Resource count for %s should be 0" %
                         get_resource_type(resource_id=9))  #RAM
        return
コード例 #38
0
    def test_04_deploy_multiple_vm(self):
        """Test Deploy multiple VM with specified RAM & verify the usage"""

        # Validate the following
        # 1. Create compute offering with specified RAM
        # 2. Deploy multiple VMs with this service offering
        # 3. List Resource count for the root admin Memory usage
        # 4. Memory usage should list properly

        # Resetting the memory count of service offering
        self.services["service_offering"]["memory"] = 2048

        self.debug("Setting up account and domain hierarchy")
        self.setupAccounts()
        users =  { self.child_domain_1: self.child_do_admin_1,
                   self.child_domain_2: self.child_do_admin_2
                 }
        for domain, admin in users.items():
            self.account = admin
            self.domain = domain
            self.debug("Creating an instance with service offering: %s" %
                                                    self.service_offering.name)

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

            vm_1 = self.createInstance(service_off=self.service_offering, api_client=api_client)
            vm_2 = self.createInstance(service_off=self.service_offering, api_client=api_client)
            vm_3 = self.createInstance(service_off=self.service_offering, api_client=api_client)

            self.debug("Deploying instance - Memory capacity is fully utilized")
            with self.assertRaises(Exception):
                self.createInstance(service_off=self.service_offering, api_client=api_client)

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(account_list,
                              list,
                              "List Accounts should return a valid response"
                              )
            resource_count = account_list[0].memorytotal

            expected_resource_count = int(self.services["service_offering"]["memory"]) * 3 #Total 3 VMs

            self.assertEqual(resource_count, expected_resource_count,
                         "Resource count should match with the expected resource count")

            vm_2.delete(self.apiclient)
            vm_3.delete(self.apiclient)
        return
コード例 #39
0
    def test_01_deploy_vm_domain_limit_reached(self):
        """Test Try to deploy VM with admin account where account has not used
            the resources but @ domain they are not available

        # Validate the following
        # 1. Try to deploy VM with admin account where account has not used the
        #    resources but @ domain they are not available
        # 2. Deploy VM should error out saying  ResourceAllocationException
        #    with "resource limit exceeds"""

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

        accounts = Account.list(self.apiclient, id=self.child_do_admin.id)
        self.assertEqual(validateList(accounts)[0], PASS,
            "accounts list validation failed")

        self.initialResourceCount = int(accounts[0].primarystoragetotal)
        domainLimit = self.initialResourceCount + 3

        self.debug("Setting up account and domain hierarchy")
        response = self.updatePrimaryStorageLimits(domainLimit=domainLimit)
        self.assertEqual(response[0], PASS, response[1])

        self.services["volume"]["size"] = self.services["disk_offering"]["disksize"] = 2

        try:
            disk_offering = DiskOffering.create(self.apiclient,
                                    services=self.services["disk_offering"])
            self.cleanup.append(disk_offering)
            Volume.create(self.apiclient,
                                   self.services["volume"],
                                   zoneid=self.zone.id,
                                   account=self.child_do_admin.name,
                                   domainid=self.child_do_admin.domainid,
                                   diskofferingid=disk_offering.id)
        except Exception as e:
            self.fail("Exception occured: %s" % e)

        with self.assertRaises(Exception):
            Volume.create(self.apiclient,
                                   self.services["volume"],
                                   zoneid=self.zone.id,
                                   account=self.child_do_admin.name,
                                   domainid=self.child_do_admin.domainid,
                                   diskofferingid=disk_offering.id)
        return
コード例 #40
0
    def test_02_deploy_vm_account_limit_reached(self):
        """Test Try to deploy VM with admin account where account has used
            the resources but @ domain they are available"""

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

        accounts = Account.list(self.apiclient, id=self.child_do_admin.id)
        self.assertEqual(
            validateList(accounts)[0], PASS, "accounts list validation failed")

        self.initialResourceCount = int(accounts[0].primarystoragetotal)
        accountLimit = self.initialResourceCount + 3

        self.debug("Setting up account and domain hierarchy")
        response = self.updatePrimaryStorageLimits(accountLimit=accountLimit)
        self.assertEqual(response[0], PASS, response[1])

        self.services["volume"]["size"] = self.services["disk_offering"][
            "disksize"] = 2

        try:
            disk_offering = DiskOffering.create(
                self.apiclient, services=self.services["disk_offering"])
            self.cleanup.append(disk_offering)
            Volume.create(self.apiclient,
                          self.services["volume"],
                          zoneid=self.zone.id,
                          account=self.child_do_admin.name,
                          domainid=self.child_do_admin.domainid,
                          diskofferingid=disk_offering.id)
        except Exception as e:
            self.fail("failed to create volume: %s" % e)

        with self.assertRaises(Exception):
            Volume.create(self.apiclient,
                          self.services["volume"],
                          zoneid=self.zone.id,
                          account=self.child_do_admin.name,
                          domainid=self.child_do_admin.domainid,
                          diskofferingid=disk_offering.id)
        return
コード例 #41
0
    def bind_account_to_ldap(cls, account, ldapdomain, type="Group", accounttype=0):
        cmd = linkAccountToLdap.linkAccountToLdapCmd()

        cmd.domainid = cls.syncDomain.id
        cmd.account = account
        cmd.ldapdomain = ldapdomain
        cmd.type = type
        cmd.accounttype = accounttype

        response = cls.apiclient.linkAccountToLdap(cmd)
        cls.logger.info("account linked to ladp %s" % response)

        # this is needed purely for cleanup:
        response = Account.list(cls.apiclient, id=response.accountid)
        account_created = Account(response[0].__dict__)
        cls._cleanup.append(account_created)
        return account_created
コード例 #42
0
    def test_02_deploy_vm_account_limit_reached(self):
        """Test Try to deploy VM with admin account where account has used
            the resources but @ domain they are available"""

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

        accounts = Account.list(self.apiclient, id=self.child_do_admin.id)
        self.assertEqual(validateList(accounts)[0], PASS,
            "accounts list validation failed")

        self.initialResourceCount = int(accounts[0].primarystoragetotal)
        accountLimit = self.initialResourceCount + 3

        self.debug("Setting up account and domain hierarchy")
        response = self.updatePrimaryStorageLimits(accountLimit=accountLimit)
        self.assertEqual(response[0], PASS, response[1])

        self.services["volume"]["size"] = self.services["disk_offering"]["disksize"] = 2

        try:
            disk_offering = DiskOffering.create(self.apiclient,
                                    services=self.services["disk_offering"])
            self.cleanup.append(disk_offering)
            Volume.create(self.apiclient,
                                   self.services["volume"],
                                   zoneid=self.zone.id,
                                   account=self.child_do_admin.name,
                                   domainid=self.child_do_admin.domainid,
                                   diskofferingid=disk_offering.id)
        except Exception as e:
            self.fail("failed to create volume: %s" % e)

        with self.assertRaises(Exception):
            Volume.create(self.apiclient,
                                   self.services["volume"],
                                   zoneid=self.zone.id,
                                   account=self.child_do_admin.name,
                                   domainid=self.child_do_admin.domainid,
                                   diskofferingid=disk_offering.id)
        return
コード例 #43
0
    def deploy_account(self, account_data, domain):
        self.logger.debug('>>>  ACCOUNT  =>  Creating "%s"...',
                          account_data['username'])
        account = None
        if not self.randomizeNames:
            account_list = Account.list(api_client=self.api_client,
                                        name=account_data['username'],
                                        listall=True)
            if isinstance(account_list, list) and len(account_list) >= 1:
                if account_list[0].name == account_data['username']:
                    account = account_list[0]
                    self.logger.debug(
                        '>>>  ACCOUNT  =>  Loaded from (pre) existing account,  ID: %s',
                        account.id)
                    return

        if not account:
            account = Account.create(api_client=self.api_client,
                                     services=account_data,
                                     domainid=domain.uuid,
                                     randomizeID=self.randomizeNames)
        self.resources_to_cleanup.append(account)
        self.dynamic_names['accounts'][account_data['username']] = account.name

        self.logger.debug(
            '>>>  ACCOUNT  =>  ID: %s  =>  Name: %s  =>  State: %s  =>  Domain: %s',
            account.id, account.name, account.state, account.domainid)

        self.deploy_vpcs(account_data['vpcs'], account)
        self.deploy_isolatednetworks(account_data['isolatednetworks'], account)
        self.deploy_vms(account_data['virtualmachines'], account)
        self.deploy_vpcs_publicipaddresses(account_data['vpcs'],
                                           account_data['virtualmachines'])
        self.deploy_isolatednetworks_publicipaddresses(
            account_data['isolatednetworks'], account_data['virtualmachines'])
        self.deploy_privatenetworks(account_data['privatenetworks'], account,
                                    domain)
        self.deploy_vpcs_privategateways(account_data['vpcs'])
        self.enable_vpcs_localvpngateway(account_data['vpcs'])
        self.deploy_vpcs_remotevpngateways(account_data['vpcs'], account)
コード例 #44
0
    def setupNormalAccount(self):
        """Setup the account required for the test"""

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

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

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

            accounts = Account.list(self.apiclient, id=self.account.id)

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

            self.initialResourceCount = int(accounts[0].primarystoragetotal)

            primarystoragelimit = self.initialResourceCount
            update_resource_limit(
                self.api_client,
                RESOURCE_PRIMARY_STORAGE,
                account=self.account.name,
                domainid=self.account.domainid,
                max=primarystoragelimit,
            )

        except Exception as e:
            return [FAIL, e]
        return [PASS, None]
コード例 #45
0
    def test_04_deploy_multiple_vm_with_multiple_cpus(self):
        """Test Deploy multiple VM with 4 core CPU & verify the usage"""

        # Validate the following
        # 1. Create compute offering with 4 core CPU
        # 2. Deploy multiple VMs with this service offering
        # 3. List Resource count for the root admin CPU usage
        # 4. CPU usage should list properly
        # 5. Destroy one VM among multiple VM's and verify the resource count
        # 6. Migrate VM from & verify resource updates
        # 7. List resource count for Root Admin
        # 8. Failed to deploy VM and verify the resource usage

        self.debug("Creating service offering with 4 CPU cores")
        self.service_offering = ServiceOffering.create(
                                            self.apiclient,
                                            self.services["service_offering"]
                                            )
        # Adding to cleanup list after execution
        self.cleanup.append(self.service_offering)

        self.debug("Creating an instance with service offering: %s" %
                                                    self.service_offering.name)
        vm_1 = self.createInstance(service_off=self.service_offering)
        vm_2 = self.createInstance(service_off=self.service_offering)
        self.createInstance(service_off=self.service_offering)

        account_list = Account.list(self.apiclient, id=self.account.id)
        self.assertIsInstance(account_list,
                              list,
                              "List Accounts should return a valid response"
                              )
        resource_count = account_list[0].cputotal

        expected_resource_count = int(self.services["service_offering"]["cpunumber"]) * 4 #Total 4 Vms
        self.assertTrue(resource_count == expected_resource_count,
                         "Resource count does not match the expected vavlue")
        return
コード例 #46
0
    def test_02_test_settings_for_account(self):
        """
        1. Get the default value for the setting in account scope
        2. Change the default value to new value
        3. Make sure updated value is same as new value
        4. Reset the config value
        5. Make sure that current value is same as default value
        :return:
        """
        accounts = Account.list(
            self.apiclient,
            domainid=self.domain.id,
            listall=True
        )

        self.assertIsNotNone(accounts[0],
                             "There should be atleast 1 account in the zone")

        config_name = "enable.additional.vm.configuration"
        #1. Get the default value
        configs = Configurations.list(
            self.apiclient,
            name=config_name
        )
        self.assertIsNotNone(configs, "Fail to get account setting %s " % config_name)

        orig_value = str(configs[0].value)
        new_value = "true"

        Configurations.update(
            self.apiclient,
            name=config_name,
            value=new_value,
            accountid=accounts[0].id
        )

        configs = Configurations.list(
            self.apiclient,
            name=config_name,
            accountid=accounts[0].id
        )
        self.assertIsNotNone(configs, "Fail to get account setting %s " % config_name)

        self.assertEqual(new_value,
                         str(configs[0].value),
                         "Failed to set new config value")

        Configurations.reset(
            self.apiclient,
            name=config_name,
            accountid=accounts[0].id
        )

        configs = Configurations.list(
            self.apiclient,
            name=config_name,
            accountid=accounts[0].id
        )
        self.assertIsNotNone(configs, "Fail to get account setting %s " % config_name)

        self.assertEqual(orig_value,
                         str(configs[0].value),
                         "Failed to reset the value")
コード例 #47
0
    def test_00_deploy_vm_root_resize(self):
        """Test deploy virtual machine with root resize

        # Validate the following:
        # 1. listVirtualMachines returns accurate information
        # 2. root disk has new size per listVolumes
        # 3. Rejects non-supported hypervisor types
        """

        newrootsize = (self.template.size >> 30) + 2
        if (self.hypervisor.lower() == 'kvm'
                or self.hypervisor.lower() == 'xenserver'
                or self.hypervisor.lower() == 'vmware'
                or self.hypervisor.lower() == 'simulator'):

            accounts = Account.list(self.apiclient, id=self.account.id)
            self.assertEqual(
                validateList(accounts)[0], PASS,
                "accounts list validation failed")
            initialResourceCount = int(accounts[0].primarystoragetotal)

            if self.hypervisor == "vmware":
                self.virtual_machine = VirtualMachine.create(
                    self.apiclient,
                    self.services["virtual_machine"],
                    zoneid=self.zone.id,
                    accountid=self.account.name,
                    domainid=self.domain.id,
                    serviceofferingid=self.services_offering_vmware.id,
                    templateid=self.template.id,
                    rootdisksize=newrootsize)
            else:
                self.virtual_machine = VirtualMachine.create(
                    self.apiclient,
                    self.services["virtual_machine"],
                    zoneid=self.zone.id,
                    accountid=self.account.name,
                    domainid=self.domain.id,
                    serviceofferingid=self.service_offering.id,
                    templateid=self.template.id,
                    rootdisksize=newrootsize)

            list_vms = VirtualMachine.list(self.apiclient,
                                           id=self.virtual_machine.id)
            self.debug(
                "Verify listVirtualMachines response for virtual machine: %s" \
                % self.virtual_machine.id
            )

            res = validateList(list_vms)
            self.assertNotEqual(res[2], INVALID_INPUT, "Invalid list VM "
                                "response")
            self.cleanup.append(self.virtual_machine)

            vm = list_vms[0]
            self.assertEqual(vm.id, self.virtual_machine.id,
                             "Virtual Machine ids do not match")
            self.assertEqual(vm.name, self.virtual_machine.name,
                             "Virtual Machine names do not match")
            self.assertEqual(vm.state,
                             "Running",
                             msg="VM is not in Running state")

            # get root vol from created vm, verify it is correct size
            list_volume_response = list_volumes(
                self.apiclient,
                virtualmachineid=self.virtual_machine.id,
                type='ROOT',
                listall=True)
            res = validateList(list_volume_response)
            self.assertNotEqual(res[2], INVALID_INPUT, "Invalid list VM "
                                "response")
            rootvolume = list_volume_response[0]
            success = False
            if rootvolume is not None and rootvolume.size == (
                    newrootsize << 30):
                success = True

            self.assertEqual(success, True,
                             "Check if the root volume resized appropriately")

            response = matchResourceCount(self.apiclient,
                                          (initialResourceCount + newrootsize),
                                          RESOURCE_PRIMARY_STORAGE,
                                          accountid=self.account.id)
            self.assertEqual(response[0], PASS, response[1])
        else:
            self.debug(
                "hypervisor %s unsupported for test 00, verifying it errors properly"
                % self.hypervisor)
            newrootsize = (self.template.size >> 30) + 2
            success = False
            try:
                self.virtual_machine = VirtualMachine.create(
                    self.apiclient,
                    self.testdata["virtual_machine"],
                    accountid=self.account.name,
                    zoneid=self.zone.id,
                    domainid=self.account.domainid,
                    serviceofferingid=self.service_offering.id,
                    templateid=self.template.id,
                    rootdisksize=newrootsize)
            except Exception as ex:
                if re.search(
                        "Hypervisor \S+ does not support rootdisksize override",
                        str(ex)):
                    success = True
                else:
                    self.debug(
                        "Virtual machine create did not fail appropriately. Error was actually : "
                        + str(ex))

            self.assertEqual(
                success, True,
                "Check if unsupported hypervisor %s fails appropriately" %
                self.hypervisor)
    def test_01_snapshot_root_disk(self):
        """Test Snapshot Root Disk
        """

        # Validate the following
        # 1. Account List should list the accounts that was existed.
        # 2. List Volumes
        # 3. Create Snapshot From the volume[0] from volume list
        # 4. List Snapshots
        # 5. Create Volume V1,V2,V3 from Snapshot List[0]
        # 6. Verify that Async Job id's status
        # 7. List all the volumes
        # 8. Add Volumes V1,V2,V3 to cleanup
        # 9. Check list response returns a valid list
        # 10. Check if result exists in list item call

        # 1. Account List should list the accounts that was existed.
        account_list = Account.list(
            self.apiclient,
            listAll = True,
            roleType ='Admin'
            );

        # 2. List Volumes
        volumes = list_volumes(
            self.apiclient,
            virtualmachineid=self.virtual_machine_with_disk.id,
            type='ROOT',
            listall=True
        )

        # 3. Create Snapshot From the volume[0] from volume list
        snapshot = Snapshot.create(
            self.apiclient,
            volumes[0].id,
            account=self.account.name,
            domainid=self.account.domainid
        )
        #self._cleanup.append(snapshot)
        self.debug("Snapshot created: ID - %s" % snapshot.id)

        # 4. List Snapshots
        snapshots = list_snapshots(
            self.apiclient,listall=True
            )

        # 5. Create Volume V1,V2,V3 from Snapshot List[0]
        services = {"diskname": "Vol", "zoneid": self.zone.id, "size": 10, "ispublic": True}
        vol1_jobId = self.create_from_snapshot(
             self.apiclient,snapshots[0].id,
            services,

            account_list[0].name,
            account_list[0].domainid
         );

        vol2_jobId = self.create_from_snapshot(
            self.apiclient, snapshots[0].id,
            services,

            account_list[0].name,
            account_list[0].domainid
        );

        vol3_jobId = self.create_from_snapshot(
             self.apiclient, snapshots[0].id,
             services,

             account_list[0].name,
             account_list[0].domainid
         );

        # 6. Verify that Async Job id's status
        self.query_async_job(self.apiclient, vol1_jobId.jobid)
        self.query_async_job(self.apiclient, vol2_jobId.jobid)
        self.query_async_job(self.apiclient, vol3_jobId.jobid)

        # 7. List all the volumes
        list_volume_response = Volume.list(
            self.apiclient,
            type="DATADISK",
            account=account_list[0].name,
            domainid=account_list[0].domainid
        )

        # 8. Add Volumes V1,V2,V3 to cleanup
        self.cleanup.append(list_volume_response[0]);
        self.cleanup.append(list_volume_response[1]);
        self.cleanup.append(list_volume_response[2]);

        # 9. Check list response returns a valid list
        self.assertEqual(
            isinstance(list_volume_response, list),
            True,
            "Check list response returns a valid list"
        )


        # 10.Check if result exists in list item call
        self.assertNotEqual(
            list_volume_response,
            None,
            "Check if result exists in list item call"
        )

        self.assertIsNotNone(snapshots[0].zoneid,
                             "Zone id is not none in listSnapshots")
        self.assertEqual(
            snapshots[0].zoneid,
            self.zone.id,
            "Check zone id in the list snapshots"
        )

        return
コード例 #49
0
    def test_04_deploy_multiple_vm_with_multiple_core(self):
        """Test Deploy multiple VM with 4 core CPU & verify the usage"""

        # Validate the following
        # 1. Create compute offering with 4 core CPU
        # 2. Deploy multiple VMs within domain with this service offering
        # 3. Update Resource count for the domain
        # 4. CPU usage should list properly

        self.debug("Creating service offering with 4 CPU cores")
        self.service_offering = ServiceOffering.create(
                                            self.apiclient,
                                            self.services["service_offering"]
                                            )
        # Adding to cleanup list after execution
        self.cleanup.append(self.service_offering)

        self.debug("Setting up account and domain hierarchy")
        self.setupAccounts()
        users = {self.domain: self.admin,
                 self.child_domain: self.child_do_admin
                 }
        for domain, admin in users.items():
            self.account = admin
            self.domain = domain

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

            self.debug("Creating an instance with service offering: %s" %
                       self.service_offering.name)
            vm_1 = self.createInstance(service_off=self.service_offering, api_client=api_client)
            vm_2 = self.createInstance(service_off=self.service_offering, api_client=api_client)
            self.createInstance(service_off=self.service_offering, api_client=api_client)
            self.createInstance(service_off=self.service_offering, api_client=api_client)

            self.debug("Deploying instance - CPU capacity is fully utilized")
            with self.assertRaises(Exception):
                self.createInstance(service_off=self.service_offering, api_client=api_client)

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(account_list,
                list,
                "List Accounts should return a valid response"
            )
            resource_count = account_list[0].cputotal

            expected_resource_count = int(self.services["service_offering"]["cpunumber"]) * 4 #Total 4 VMs

            self.assertEqual(resource_count, expected_resource_count,
                "Initial resource count should be 4")

            self.debug("Destroying instance: %s" % vm_1.name)
            try:
                vm_1.delete(self.apiclient)
            except Exception as e:
                self.fail("Failed to delete instance: %s" % e)

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(account_list,
                list,
                "List Accounts should return a valid response"
            )
            resource_count_after_delete = account_list[0].cputotal

            expected_resource_count -= int(self.services["service_offering"]["cpunumber"])

            self.assertEqual(resource_count_after_delete, expected_resource_count,
                "Resource count should match with the expected count")
            host = findSuitableHostForMigration(self.apiclient, vm_2.id)
            if host is None:
                self.skipTest(ERROR_NO_HOST_FOR_MIGRATION)
            self.debug("Migrating instance: %s to host: %s" % (vm_2.name,
                                                               host.name))
            try:
                vm_2.migrate(self.apiclient, host.id)
            except Exception as e:
                self.fail("Failed to migrate instance: %s" % e)

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(account_list,
                list,
                "List Accounts should return a valid response"
            )
            resource_count_after_migrate = account_list[0].cputotal

            self.assertEqual(resource_count_after_migrate, resource_count_after_delete,
                "Resource count should not change after migrating the instance")
        return
コード例 #50
0
    def test_01_multiple_child_domains(self):
        """Test memory limits with multiple child domains"""

        # Validate the following
        # 1. Create Domain1 with 4 GB RAM and 2 child domains with 2 GB
        #    each.
        # 2. Deploy VM's by Domain1 admin1/user1/ Domain2 user1/Admin1 account
        #    and verify the resource updates
        # 3. Deploy VM by admin account after reaching max parent domain limit
        # 4. Deploy VM with child account after reaching max child domain limit
        # 5. Delete user account and verify the resource updates
        # 6. Destroy user/admin account VM's and verify the child & Parent
        #    domain resource updates

        self.debug("Creating service offering with 2 GB RAM")
        self.services["service_offering"]["memory"] = 2048
        self.service_offering = ServiceOffering.create(
            self.apiclient, self.services["service_offering"])
        # Adding to cleanup list after execution
        self.cleanup.append(self.service_offering)

        self.debug("Setting up account and domain hierarchy")
        self.setupAccounts()

        api_client_cadmin_1 = self.testClient.getUserApiClient(
            UserName=self.cadmin_1.name, DomainName=self.cadmin_1.domain)

        api_client_cadmin_2 = self.testClient.getUserApiClient(
            UserName=self.cadmin_2.name, DomainName=self.cadmin_2.domain)

        self.debug("Creating an instance with service offering: %s" %
                   self.service_offering.name)
        vm_1 = self.createInstance(account=self.cadmin_1,
                                   service_off=self.service_offering,
                                   api_client=api_client_cadmin_1)

        vm_2 = self.createInstance(account=self.cadmin_2,
                                   service_off=self.service_offering,
                                   api_client=api_client_cadmin_2)

        account_list = Account.list(self.apiclient, id=self.cadmin_1.id)
        self.assertIsInstance(account_list, list,
                              "List Accounts should return a valid response")
        resource_count_cadmin_1 = account_list[0].memorytotal
        self.debug(resource_count_cadmin_1)

        account_list = Account.list(self.apiclient, id=self.cadmin_2.id)
        self.assertIsInstance(account_list, list,
                              "List Accounts should return a valid response")
        resource_count_cadmin_2 = account_list[0].memorytotal
        self.debug(resource_count_cadmin_2)

        self.debug(
            "Creating instance when Memory limit is fully used in parent domain"
        )
        with self.assertRaises(Exception):
            self.createInstance(account=self.cadmin_1,
                                service_off=self.service_offering,
                                api_client=api_client_cadmin_1)

        self.debug(
            "Creating instance when Memory limit is fully used in child domain"
        )
        with self.assertRaises(Exception):
            self.createInstance(account=self.cadmin_2,
                                service_off=self.service_offering,
                                api_client=api_client_cadmin_2)
        self.debug("Destroying instances: %s, %s" % (vm_1.name, vm_2.name))
        try:
            vm_1.delete(self.apiclient)
            vm_2.delete(self.apiclient)
        except Exception as e:
            self.fail("Failed to delete instance: %s" % e)

        self.debug("Checking resource count for account: %s" %
                   self.cadmin_1.name)

        account_list = Account.list(self.apiclient, id=self.cadmin_1.id)
        self.assertIsInstance(account_list, list,
                              "List Accounts should return a valid response")
        resource_count_cadmin_1 = account_list[0].memorytotal

        self.assertEqual(resource_count_cadmin_1, 0,
                         "Resource count for %s should be 0" %
                         get_resource_type(resource_id=9))  #RAM

        self.debug("Checking resource count for account: %s" %
                   self.cadmin_2.name)

        account_list = Account.list(self.apiclient, id=self.cadmin_1.id)
        self.assertIsInstance(account_list, list,
                              "List Accounts should return a valid response")
        resource_count_cadmin_2 = account_list[0].memorytotal

        self.assertEqual(resource_count_cadmin_2, 0,
                         "Resource count for %s should be 0" %
                         get_resource_type(resource_id=9))  #RAM
        return
コード例 #51
0
    def test_04_deploy_multiple_vm_with_multiple_core(self):
        """Test Deploy multiple VM with 4 core CPU & verify the usage"""

        # Validate the following
        # 1. Create compute offering with 4 core CPU
        # 2. Deploy multiple VMs within domain with this service offering
        # 3. Update Resource count for the domain
        # 4. CPU usage should list properly

        self.debug("Creating service offering with 4 CPU cores")
        self.service_offering = ServiceOffering.create(
            self.apiclient, self.services["service_offering"])
        # Adding to cleanup list after execution
        self.cleanup.append(self.service_offering)

        self.debug("Setting up account and domain hierarchy")
        self.setupAccounts()
        users = {
            self.domain: self.admin,
            self.child_domain: self.child_do_admin
        }
        for domain, admin in users.items():
            self.account = admin
            self.domain = domain

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

            self.debug("Creating an instance with service offering: %s" %
                       self.service_offering.name)
            vm_1 = self.createInstance(service_off=self.service_offering,
                                       api_client=api_client)
            vm_2 = self.createInstance(service_off=self.service_offering,
                                       api_client=api_client)
            self.createInstance(service_off=self.service_offering,
                                api_client=api_client)
            self.createInstance(service_off=self.service_offering,
                                api_client=api_client)

            self.debug("Deploying instance - CPU capacity is fully utilized")
            with self.assertRaises(Exception):
                self.createInstance(service_off=self.service_offering,
                                    api_client=api_client)

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(
                account_list, list,
                "List Accounts should return a valid response")
            resource_count = account_list[0].cputotal

            expected_resource_count = int(self.services["service_offering"]
                                          ["cpunumber"]) * 4  #Total 4 VMs

            self.assertEqual(resource_count, expected_resource_count,
                             "Initial resource count should be 4")

            self.debug("Destroying instance: %s" % vm_1.name)
            try:
                vm_1.delete(self.apiclient)
            except Exception as e:
                self.fail("Failed to delete instance: %s" % e)

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(
                account_list, list,
                "List Accounts should return a valid response")
            resource_count_after_delete = account_list[0].cputotal

            expected_resource_count -= int(
                self.services["service_offering"]["cpunumber"])

            self.assertEqual(
                resource_count_after_delete, expected_resource_count,
                "Resource count should match with the expected count")
            #vm migration is not supported in LXC. So don't need to execute below vm migration code
            if self.hypervisor.lower() in ['lxc']:
                continue
            host = findSuitableHostForMigration(self.apiclient, vm_2.id)
            if host is None:
                self.skipTest(ERROR_NO_HOST_FOR_MIGRATION)
            self.debug("Migrating instance: %s to host: %s" %
                       (vm_2.name, host.name))
            try:
                vm_2.migrate(self.apiclient, host.id)
            except Exception as e:
                self.fail("Failed to migrate instance: %s" % e)

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(
                account_list, list,
                "List Accounts should return a valid response")
            resource_count_after_migrate = account_list[0].cputotal

            self.assertEqual(
                resource_count_after_migrate, resource_count_after_delete,
                "Resource count should not change after migrating the instance"
            )
        return
コード例 #52
0
    def test_01_change_service_offering(self):
        """Test Deploy VM with specified RAM & verify the usage"""

        # Validate the following
        # 1. Create compute offering with specified RAM & Deploy VM in the created domain
        # 2. List Resource count for the root admin Memory usage
        # 3. Upgrade and downgrade service offering
        # 4. Resource count should list properly for the domain

        self.debug("Setting up account and domain hierarchy")
        self.setupAccounts()
        users = {
            self.child_domain_1: self.child_do_admin_1,
            self.child_domain_2: self.child_do_admin_2
        }
        for domain, admin in users.items():
            self.account = admin
            self.domain = domain

            #Resetting memory count in service offering
            self.services["service_offering"]["memory"] = 2048

            self.debug("Creating an instance with service offering: %s" %
                       self.service_offering.name)

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

            vm = self.createInstance(service_off=self.service_offering,
                                     api_client=api_client)

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(
                account_list, list,
                "List Accounts should return a valid response")
            resource_count = account_list[0].memorytotal

            expected_resource_count = int(
                self.services["service_offering"]["memory"])

            self.assertEqual(
                resource_count, expected_resource_count,
                "Resource count should match with the expected resource count")

            self.debug("Stopping instance: %s" % vm.name)
            try:
                vm.stop(self.apiclient)
            except Exception as e:
                self.fail("Failed to stop instance: %s" % e)
            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(
                account_list, list,
                "List Accounts should return a valid response")
            resource_count_after_stop = account_list[0].memorytotal

            self.assertEqual(
                resource_count_after_stop, expected_resource_count,
                "Resource count should be same after stopping the instance")

            self.debug("Creating service offering with 5 GB RAM")
            self.services["service_offering"]["memory"] = 5120
            self.service_offering_5gb = ServiceOffering.create(
                self.apiclient, self.services["service_offering"])
            # Adding to cleanup list after execution
            self.cleanup.append(self.service_offering_5gb)

            self.debug(
                "Upgrade service offering of instance %s from %s to %s" %
                (vm.name, self.service_offering.name,
                 self.service_offering_5gb.name))

            try:
                vm.change_service_offering(
                    self.apiclient,
                    serviceOfferingId=self.service_offering_5gb.id)
            except Exception as e:
                self.fail("Failed to change service offering of vm %s - %s" %
                          (vm.name, e))

            update_resource_count(self.apiclient,
                                  domainid=self.domain.id,
                                  rtype=9)  #RAM

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(
                account_list, list,
                "List Accounts should return a valid response")
            resource_count_after_upgrade = account_list[0].memorytotal

            self.debug(resource_count_after_upgrade)

            self.assertTrue(
                resource_count_after_upgrade > resource_count_after_stop,
                "Resource count should be more than before, after upgrading service offering"
            )

            self.debug(
                "Down grade service offering of instance %s from %s to %s" %
                (vm.name, self.service_offering_5gb.name,
                 self.service_offering.name))

            try:
                vm.change_service_offering(
                    self.apiclient, serviceOfferingId=self.service_offering.id)
            except Exception as e:
                self.fail("Failed to change service offering of vm %s - %s" %
                          (vm.name, e))

            update_resource_count(self.apiclient,
                                  domainid=self.domain.id,
                                  rtype=9)  #RAM

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(
                account_list, list,
                "List Accounts should return a valid response")

            resource_count_after_downgrade = account_list[0].memorytotal

            self.debug(resource_count_after_downgrade)

            self.assertTrue(
                resource_count_after_downgrade < resource_count_after_upgrade,
                "Resource count should be less than before, after downgrading service offering"
            )

            self.debug("Starting instance: %s" % vm.name)
            try:
                vm.start(self.apiclient)
            except Exception as e:
                self.fail("Failed to start instance: %s" % e)
            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(
                account_list, list,
                "List Accounts should return a valid response")
            resource_count_after_start = account_list[0].memorytotal

            self.assertTrue(
                resource_count_after_start == resource_count_after_downgrade,
                "Resource count should be same after starting the instance")

        return
コード例 #53
0
    def test_04_deploy_multiple_vm(self):
        """Test Deploy multiple VM with 2 GB memory & verify the usage"""
        #keep the configuration value - max.account.memory = 8192 (maximum 4 instances per account with 2 GB RAM)

        # Validate the following
        # 1. Create compute offering with 2 GB RAM
        # 2. Deploy multiple VMs with this service offering in child domains of root domain
        # 3. List Resource count for the root admin Memory usage
        # 4. Memory usage should list properly

        self.debug("Creating service offering with 2 GB RAM")
        self.service_offering = ServiceOffering.create(
            self.apiclient, self.services["service_offering"])
        # Adding to cleanup list after execution
        self.cleanup.append(self.service_offering)

        self.debug("Setting up account and domain hierarchy")
        self.setupAccounts()
        users = {
            self.child_domain_1: self.child_do_admin_1,
            self.child_domain_2: self.child_do_admin_2
        }
        for domain, admin in users.items():
            self.account = admin
            self.domain = domain

            memory_account_gc = Resources.list(
                self.apiclient,
                resourcetype=9,  #Memory
                account=self.account.name,
                domainid=self.domain.id)

            if memory_account_gc[0].max != 8192:
                self.skipTest(
                    "This test case requires configuration value max.account.memory to be 8192"
                )

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

            self.debug("Creating an instance with service offering: %s" %
                       self.service_offering.name)
            vm_1 = self.createInstance(service_off=self.service_offering,
                                       api_client=api_client)
            vm_2 = self.createInstance(service_off=self.service_offering,
                                       api_client=api_client)
            self.createInstance(service_off=self.service_offering,
                                api_client=api_client)
            self.createInstance(service_off=self.service_offering,
                                api_client=api_client)

            self.debug(
                "Deploying instance - memory capacity is fully utilized")
            with self.assertRaises(Exception):
                self.createInstance(service_off=self.service_offering,
                                    api_client=api_client)

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(
                account_list, list,
                "List Accounts should return a valid response")
            resource_count = account_list[0].memorytotal

            expected_resource_count = int(
                self.services["service_offering"]["memory"]) * 4  #Total 4 vms

            self.assertEqual(
                resource_count, expected_resource_count,
                "Initial resource count should with the expected resource count"
            )

            self.debug("Destroying instance: %s" % vm_1.name)
            try:
                vm_1.delete(self.apiclient)
            except Exception as e:
                self.fail("Failed to delete instance: %s" % e)

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(
                account_list, list,
                "List Accounts should return a valid response")
            resource_count_after_delete = account_list[0].memorytotal

            expected_resource_count -= int(
                self.services["service_offering"]["memory"])

            self.assertEqual(
                resource_count_after_delete, expected_resource_count,
                "Resource count should match with the expected resource count")

            host = findSuitableHostForMigration(self.apiclient, vm_2.id)
            if host is None:
                self.skipTest(ERROR_NO_HOST_FOR_MIGRATION)
            self.debug("Migrating instance: %s to host: %s" %
                       (vm_2.name, host.name))
            try:
                vm_2.migrate(self.apiclient, host.id)
            except Exception as e:
                self.fail("Failed to migrate instance: %s" % e)

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(
                account_list, list,
                "List Accounts should return a valid response")
            resource_count_after_migrate = account_list[0].memorytotal

            self.debug(resource_count_after_migrate)
            self.assertEqual(
                resource_count_after_delete, resource_count_after_migrate,
                "Resource count should be same after migrating the instance")
        return
コード例 #54
0
    def test_LoginApiDomain(self):
        """Test login API with domain
        """

        # Steps for test scenario
        # 1. create a domain
        # 2. create user in the domain
        # 3. login to the user account above using UUID domain/user
        # 4. delete the user account
        # Validate the following
        # 1. listDomains returns created domain
        # 2. listAccounts returns created user
        # 3. loginResponse should have UUID only in responses
        #    Login also succeeds with non NULL sessionId in response

        self.debug("Creating a domain for login with API domain test")
        domain = Domain.create(
                                self.apiclient,
                                self.services["domain"],
                                parentdomainid=self.domain.id
                                )
        self.debug("Domain: %s is created succesfully." % domain.name)
        self.debug(
            "Checking if the created domain is listed in list domains API")
        domains = Domain.list(self.apiclient, id=domain.id, listall=True)

        self.assertEqual(
                         isinstance(domains, list),
                         True,
                         "List domains shall return a valid response"
                         )
        self.debug("Creating an user account in domain: %s" % domain.name)
        self.account = Account.create(
                                     self.apiclient,
                                     self.services["account"],
                                     domainid=domain.id
                                     )
        self._cleanup.append(self.account)

        accounts = Account.list(
                                self.apiclient,
                                name=self.account.name,
                                domainid=self.account.domainid,
                                listall=True
                                )

        self.assertEqual(
                         isinstance(accounts, list),
                         True,
                         "List accounts should return a valid response"
                         )

        self.debug("Logging into the cloudstack with login API")
        respose = User.login(
                             self.apiclient,
                             username=self.account.name,
                             password=self.services["account"]["password"],
                             domainid=domain.id)
        self.debug("Login API response: %s" % respose)

        self.assertNotEqual(
                            respose.sessionkey,
                            None,
                            "Login to the CloudStack should be successful" +
                            "response shall have non Null key"
                            )
        return
コード例 #55
0
    def test_01_stop_start_instance(self):
        """Test Deploy VM with 5 GB memory & verify the usage"""

        # Validate the following
        # 1. Create compute offering with 5 GB memory in child domains of root domain & Deploy VM
        # 2. List Resource count memory usage
        # 3. Stop and Start instance, check resource count.
        # 4. Resource count should list properly.

        self.debug("Setting up account and domain hierarchy")
        self.setupAccounts()
        users = {self.child_domain_1: self.child_do_admin_1,
                 self.child_domain_2: self.child_do_admin_2
                 }
        for domain, admin in users.items():
            self.account = admin
            self.domain = domain

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

            self.debug("Creating an instance with service offering: %s" %
                                                    self.service_offering.name)
            vm = self.createInstance(service_off=self.service_offering, api_client=api_client)

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(account_list,
                                  list,
                                  "List Accounts should return a valid response"
                                  )
            resource_count = account_list[0].memorytotal

            expected_resource_count = int(self.services["service_offering"]["memory"])

            self.assertEqual(resource_count, expected_resource_count,
                         "Initial resource count should match with the expected resource count")

            self.debug("Stopping instance: %s" % vm.name)
            try:
                vm.stop(self.apiclient)
            except Exception as e:
                self.fail("Failed to stop instance: %s" % e)

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(account_list,
                                  list,
                                  "List Accounts should return a valid response"
                                  )
            resource_count_after_stop = account_list[0].memorytotal

            self.assertEqual(resource_count, resource_count_after_stop,
                         "Resource count should be same after stopping the instance")

            self.debug("Starting instance: %s" % vm.name)
            try:
                vm.start(self.apiclient)
            except Exception as e:
                self.fail("Failed to start instance: %s" % e)

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(account_list,
                                  list,
                                  "List Accounts should return a valid response"
                                  )
            resource_count_after_start = account_list[0].memorytotal

            self.assertEqual(resource_count_after_stop, resource_count_after_start,
                         "Resource count should be same after starting the instance")
        return
コード例 #56
0
    def test_01_change_service_offering(self):
        """Test Deploy VM with specified RAM & verify the usage"""

        # Validate the following
        # 1. Create compute offering with specified RAM & Deploy VM in the created domain
        # 2. List Resource count for the root admin Memory usage
        # 3. Upgrade and downgrade service offering
        # 4. Resource count should list properly for the domain

        self.debug("Setting up account and domain hierarchy")
        self.setupAccounts()
        users =  { self.child_domain_1: self.child_do_admin_1,
                   self.child_domain_2: self.child_do_admin_2
                 }
        for domain, admin in users.items():
            self.account = admin
            self.domain = domain

            #Resetting memory count in service offering
            self.services["service_offering"]["memory"] = 2048

            self.debug("Creating an instance with service offering: %s" %
                                                    self.service_offering.name)

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

            vm = self.createInstance(service_off=self.service_offering, api_client=api_client)

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(account_list,
                                  list,
                                  "List Accounts should return a valid response"
                                  )
            resource_count = account_list[0].memorytotal

            expected_resource_count = int(self.services["service_offering"]["memory"])

            self.assertEqual(resource_count, expected_resource_count,
                         "Resource count should match with the expected resource count")

            self.debug("Stopping instance: %s" % vm.name)
            try:
                vm.stop(self.apiclient)
            except Exception as e:
                self.fail("Failed to stop instance: %s" % e)
            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(account_list,
                              list,
                              "List Accounts should return a valid response"
                              )
            resource_count_after_stop = account_list[0].memorytotal

            self.assertEqual(resource_count_after_stop, expected_resource_count,
                         "Resource count should be same after stopping the instance")

            self.debug("Creating service offering with 5 GB RAM")
            self.services["service_offering"]["memory"] = 5120
            self.service_offering_5gb = ServiceOffering.create(
                                            self.apiclient,
                                            self.services["service_offering"]
                                            )
            # Adding to cleanup list after execution
            self.cleanup.append(self.service_offering_5gb)

            self.debug(
                "Upgrade service offering of instance %s from %s to %s" %
                                            (vm.name,
                                             self.service_offering.name,
                                             self.service_offering_5gb.name))

            try:
                vm.change_service_offering(self.apiclient,
                                serviceOfferingId=self.service_offering_5gb.id)
            except Exception as e:
                self.fail("Failed to change service offering of vm %s - %s" %
                                                                (vm.name, e))

            update_resource_count(self.apiclient, domainid=self.domain.id, rtype=9) #RAM

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(account_list,
                              list,
                              "List Accounts should return a valid response"
                              )
            resource_count_after_upgrade = account_list[0].memorytotal

            self.debug(resource_count_after_upgrade)

            self.assertTrue(resource_count_after_upgrade > resource_count_after_stop,
                            "Resource count should be more than before, after upgrading service offering")

            self.debug(
                "Down grade service offering of instance %s from %s to %s" %
                                            (vm.name,
                                             self.service_offering_5gb.name,
                                             self.service_offering.name))

            try:
                vm.change_service_offering(self.apiclient,
                                serviceOfferingId=self.service_offering.id)
            except Exception as e:
                self.fail("Failed to change service offering of vm %s - %s" %
                                                                (vm.name, e))

            update_resource_count(self.apiclient, domainid=self.domain.id, rtype=9) #RAM

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(account_list,
                              list,
                              "List Accounts should return a valid response"
                              )

            resource_count_after_downgrade = account_list[0].memorytotal

            self.debug(resource_count_after_downgrade)

            self.assertTrue(resource_count_after_downgrade < resource_count_after_upgrade,
                            "Resource count should be less than before, after downgrading service offering")

            self.debug("Starting instance: %s" % vm.name)
            try:
                vm.start(self.apiclient)
            except Exception as e:
                self.fail("Failed to start instance: %s" % e)
            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(account_list,
                              list,
                              "List Accounts should return a valid response"
                              )
            resource_count_after_start = account_list[0].memorytotal

            self.assertTrue(resource_count_after_start == resource_count_after_downgrade,
                            "Resource count should be same after starting the instance")

        return
コード例 #57
0
    def test_01_multiple_child_domains(self):
        """Test CPU limits with multiple child domains"""

        # Validate the following
        # 1. Create Domain1 with 10 core CPU and 2 child domains with 4 core
        #    each.Assign 2 cores for Domain1 admin1 & Domain1 User1 .Assign 2
        #    cores for Domain2 admin1 & Domain2 User1
        # 2. Deploy VM's by Domain1 admin1/user1/ Domain2 user1/Admin1 account
        #    and verify the resource updates
        # 3. Deploy VM by admin account after reaching max parent domain limit
        # 4. Deploy VM with child account after reaching max child domain limit
        # 5. Destroy user/admin account VM's and verify the child & Parent
        #    domain resource updates

        self.debug("Creating service offering with 2 CPU cores")
        self.services["service_offering"]["cpunumber"] = 2
        self.service_offering = ServiceOffering.create(
                                            self.apiclient,
                                            self.services["service_offering"]
                                            )
        # Adding to cleanup list after execution
        self.cleanup.append(self.service_offering)

        self.debug("Setting up account and domain hierarchy")
        self.setupAccounts()

        api_client_cadmin_1 = self.testClient.getUserApiClient(
            UserName=self.cadmin_1.name,
            DomainName=self.cadmin_1.domain)

        api_client_cadmin_2 = self.testClient.getUserApiClient(
            UserName=self.cadmin_2.name,
            DomainName=self.cadmin_2.domain)

        self.debug("Creating an instance with service offering: %s" %
                   self.service_offering.name)
        vm_1 = self.createInstance(account=self.cadmin_1,
            service_off=self.service_offering, api_client=api_client_cadmin_1)

        vm_2 = self.createInstance(account=self.cadmin_2,
            service_off=self.service_offering, api_client=api_client_cadmin_2)

        self.debug("Checking resource count for account: %s" % self.cadmin_1.name)

        account_list = Account.list(self.apiclient, id=self.cadmin_1.id)
        self.assertIsInstance(account_list,
            list,
            "List Accounts should return a valid response"
        )
        resource_count_cadmin_1 = account_list[0].cputotal

        self.debug(resource_count_cadmin_1)

        self.debug("Checking resource count for account: %s" % self.cadmin_2.name)
        account_list = Account.list(self.apiclient, id=self.cadmin_2.id)
        self.assertIsInstance(account_list,
            list,
            "List Accounts should return a valid response"
        )
        resource_count_cadmin_2 = account_list[0].cputotal

        self.debug(resource_count_cadmin_2)

        self.debug(
            "Creating instance when CPU limit is fully used in child domain 1")
        with self.assertRaises(Exception):
            self.createInstance(account=self.cadmin_1,
                service_off=self.service_offering, api_client=api_client_cadmin_1)

        self.debug(
            "Creating instance when CPU limit is fully used in child domain 2")
        with self.assertRaises(Exception):
            self.createInstance(account=self.cadmin_2,
                service_off=self.service_offering, api_client=api_client_cadmin_2)
        self.debug("Destroying instances: %s, %s" % (vm_1.name, vm_2.name))
        try:
            vm_1.delete(self.apiclient)
            vm_2.delete(self.apiclient)
        except Exception as e:
            self.fail("Failed to delete instance: %s" % e)

        self.debug("Checking resource count for account: %s" % self.cadmin_1.name)

        account_list = Account.list(self.apiclient, id=self.cadmin_1.id)
        self.assertIsInstance(account_list,
            list,
            "List Accounts should return a valid response"
        )
        resource_count_cadmin_1 = account_list[0].cputotal

        self.debug(resource_count_cadmin_1)
        self.assertEqual(resource_count_cadmin_1, 0, "Resource count for %s should be 0" % get_resource_type(resource_id=8))#CPU

        self.debug("Checking resource count for account: %s" % self.cadmin_2.name)
        account_list = Account.list(self.apiclient, id=self.cadmin_2.id)
        self.assertIsInstance(account_list,
            list,
            "List Accounts should return a valid response"
        )
        resource_count_cadmin_2 = account_list[0].cputotal

        self.debug(resource_count_cadmin_2)
        self.assertEqual(resource_count_cadmin_2, 0, "Resource count for %s should be 0" % get_resource_type(resource_id=8))#CPU
        return
コード例 #58
0
    def test_04_deploy_multiple_vm(self):
        """Test Deploy multiple VM with 2 GB memory & verify the usage"""
	    #keep the configuration value - max.account.memory = 8192 (maximum 4 instances per account with 2 GB RAM)

        # Validate the following
        # 1. Create compute offering with 2 GB RAM
        # 2. Deploy multiple VMs with this service offering in child domains of root domain
        # 3. List Resource count for the root admin Memory usage
        # 4. Memory usage should list properly

        self.debug("Creating service offering with 2 GB RAM")
        self.service_offering = ServiceOffering.create(
                                            self.apiclient,
                                            self.services["service_offering"]
                                            )
        # Adding to cleanup list after execution
        self.cleanup.append(self.service_offering)

        self.debug("Setting up account and domain hierarchy")
        self.setupAccounts()
        users = {self.child_domain_1: self.child_do_admin_1,
                 self.child_domain_2: self.child_do_admin_2
                 }
        for domain, admin in users.items():
            self.account = admin
            self.domain = domain

            memory_account_gc = Resources.list(self.apiclient,
                                resourcetype = 9, #Memory
                                account = self.account.name,
                                domainid = self.domain.id
                                )

            if memory_account_gc[0].max != 8192:
                self.skipTest("This test case requires configuration value max.account.memory to be 8192")

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

            self.debug("Creating an instance with service offering: %s" %
                                                    self.service_offering.name)
            vm_1 = self.createInstance(service_off=self.service_offering, api_client=api_client)
            vm_2 = self.createInstance(service_off=self.service_offering, api_client=api_client)
            self.createInstance(service_off=self.service_offering, api_client=api_client)
            self.createInstance(service_off=self.service_offering, api_client=api_client)

            self.debug("Deploying instance - memory capacity is fully utilized")
            with self.assertRaises(Exception):
                self.createInstance(service_off=self.service_offering, api_client=api_client)

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(account_list,
                                  list,
                                  "List Accounts should return a valid response"
                                  )
            resource_count = account_list[0].memorytotal

            expected_resource_count = int(self.services["service_offering"]["memory"]) * 4 #Total 4 vms

            self.assertEqual(resource_count, expected_resource_count,
                         "Initial resource count should with the expected resource count")

            self.debug("Destroying instance: %s" % vm_1.name)
            try:
                vm_1.delete(self.apiclient)
            except Exception as e:
                self.fail("Failed to delete instance: %s" % e)

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(account_list,
                                  list,
                                  "List Accounts should return a valid response"
                                  )
            resource_count_after_delete = account_list[0].memorytotal

            expected_resource_count -= int(self.services["service_offering"]["memory"])

            self.assertEqual(resource_count_after_delete, expected_resource_count,
                         "Resource count should match with the expected resource count")

            host = findSuitableHostForMigration(self.apiclient, vm_2.id)
            if host is None:
                self.skipTest(ERROR_NO_HOST_FOR_MIGRATION)
            self.debug("Migrating instance: %s to host: %s" % (vm_2.name,
                                                               host.name))
            try:
                vm_2.migrate(self.apiclient, host.id)
            except Exception as e:
                self.fail("Failed to migrate instance: %s" % e)

            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(account_list,
                                  list,
                                  "List Accounts should return a valid response"
                                  )
            resource_count_after_migrate = account_list[0].memorytotal

            self.debug(resource_count_after_migrate)
            self.assertEqual(resource_count_after_delete, resource_count_after_migrate,
                         "Resource count should be same after migrating the instance")
        return
コード例 #59
0
    def test_forceDeleteDomain(self):
        """ Test delete domain with force option"""

        # Steps for validations
        # 1. create a domain DOM
        # 2. create 2 users under this domain
        # 3. deploy 1 VM into each of these user accounts
        # 4. create PF / FW rules for port 22 on these VMs for their
        #    respective accounts
        # 5. delete the domain with force=true option
        # Validate the following
        # 1. listDomains should list the created domain
        # 2. listAccounts should list the created accounts
        # 3. listvirtualmachines should show the Running VMs
        # 4. PF and FW rules should be shown in listFirewallRules
        # 5. domain should delete successfully and above three list calls
        #    should show all the resources now deleted. listRouters should
        #    not return any routers in the deleted accounts/domains

        self.debug("Creating a domain for login with API domain test")
        domain = Domain.create(
                                self.apiclient,
                                self.services["domain"],
                                parentdomainid=self.domain.id
                                )
        self.debug("Domain is created succesfully.")
        self.debug(
            "Checking if the created domain is listed in list domains API")
        domains = Domain.list(self.apiclient, id=domain.id, listall=True)

        self.assertEqual(
                         isinstance(domains, list),
                         True,
                         "List domains shall return a valid response"
                         )
        self.debug("Creating 2 user accounts in domain: %s" % domain.name)
        self.account_1 = Account.create(
                                     self.apiclient,
                                     self.services["account"],
                                     domainid=domain.id
                                     )

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

        try:
            self.debug("Creating a tiny service offering for VM deployment")
            self.service_offering = ServiceOffering.create(
                                    self.apiclient,
                                    self.services["service_offering"],
                                    domainid=self.domain.id
                                    )

            self.debug("Deploying virtual machine in account 1: %s" %
                                                self.account_1.name)
            vm_1 = VirtualMachine.create(
                                    self.apiclient,
                                    self.services["virtual_machine"],
                                    templateid=self.template.id,
                                    accountid=self.account_1.name,
                                    domainid=self.account_1.domainid,
                                    serviceofferingid=self.service_offering.id
                                    )

            self.debug("Deploying virtual machine in account 2: %s" %
                                                self.account_2.name)
            VirtualMachine.create(
                                    self.apiclient,
                                    self.services["virtual_machine"],
                                    templateid=self.template.id,
                                    accountid=self.account_2.name,
                                    domainid=self.account_2.domainid,
                                    serviceofferingid=self.service_offering.id
                                    )

            networks = Network.list(
                                self.apiclient,
                                account=self.account_1.name,
                                domainid=self.account_1.domainid,
                                listall=True
                                )
            self.assertEqual(
                         isinstance(networks, list),
                         True,
                         "List networks should return a valid response"
                         )
            network_1 = networks[0]
            self.debug("Default network in account 1: %s is %s" % (
                                                self.account_1.name,
                                                network_1.name))
            src_nat_list = PublicIPAddress.list(
                                    self.apiclient,
                                    associatednetworkid=network_1.id,
                                    account=self.account_1.name,
                                    domainid=self.account_1.domainid,
                                    listall=True,
                                    issourcenat=True,
                                    )
            self.assertEqual(
                         isinstance(src_nat_list, list),
                         True,
                         "List Public IP should return a valid source NAT"
                         )
            self.assertNotEqual(
                    len(src_nat_list),
                    0,
                    "Length of response from listPublicIp should not be 0"
                    )

            src_nat = src_nat_list[0]

            self.debug(
                      "Trying to create a port forwarding rule in source NAT: %s" %
                                                            src_nat.ipaddress)
            #Create NAT rule
            nat_rule = NATRule.create(
                                  self.apiclient,
                                  vm_1,
                                  self.services["natrule"],
                                  ipaddressid=src_nat.id
                           )
            self.debug("Created PF rule on source NAT: %s" % src_nat.ipaddress)

            nat_rules = NATRule.list(self.apiclient, id=nat_rule.id)

            self.assertEqual(
                         isinstance(nat_rules, list),
                         True,
                         "List NAT should return a valid port forwarding rules"
                         )

            self.assertNotEqual(
                    len(nat_rules),
                    0,
                    "Length of response from listLbRules should not be 0"
                    )
        except Exception as e:
            self._cleanup.append(self.account_1)
            self._cleanup.append(self.account_2)
            self.fail(e)

        self.debug("Deleting domain with force option")
        try:
            domain.delete(self.apiclient, cleanup=True)
        except Exception as e:
            self.debug("Waiting for account.cleanup.interval" +
                " to cleanup any remaining resouces")
            # Sleep 3*account.gc to ensure that all resources are deleted
            wait_for_cleanup(self.apiclient, ["account.cleanup.interval"]*3)
            with self.assertRaises(CloudstackAPIException):
                Domain.list(
                        self.apiclient,
                        id=domain.id,
                        listall=True
                        )

        self.debug("Checking if the resources in domain are deleted")
        with self.assertRaises(CloudstackAPIException):
            Account.list(
                        self.apiclient,
                        name=self.account_1.name,
                        domainid=self.account_1.domainid,
                        listall=True
                        )
        return