Example #1
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
    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
    def setupAccounts(self):

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

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

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

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

        return
    def setupAccounts(self):

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

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

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

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

        return
    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.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.createUserApiClient(
                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
    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.createUserApiClient(
                            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
    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.createUserApiClient(
                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 = find_suitable_host(self.apiclient, vm)
            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
Example #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.createUserApiClient(
                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
    def test_03_delete_vm(self):
        """Test Deploy VM with 5 GB RAM & verify the usage"""

        # Validate the following
        # 1. Create compute offering with 5 GB 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.

        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
            self.debug("Creating an instance with service offering: %s" %
                       self.service_offering.name)

            api_client = self.testClient.createUserApiClient(
                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
    def setupAccounts(self):

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

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

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

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

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

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

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

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

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

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

        users = {self.parent_domain: self.parentd_admin, self.cdomain_1: self.cadmin_1, self.cdomain_2: self.cadmin_2}
        return users
    def test_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.createUserApiClient(
                            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
Example #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
Example #13
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.createUserApiClient(
                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
Example #14
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
Example #15
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.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.createUserApiClient(
            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")

        host = find_suitable_host(self.apiclient, vm)
        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
    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.createUserApiClient(
                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
    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.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.createUserApiClient(
            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")

        host = find_suitable_host(self.apiclient, vm)
        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
Example #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
    def test_03_delete_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 for the CPU 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.createUserApiClient(
            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"
        )

        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].cputotal
        self.assertEqual(resource_count, 0, "Resource count for %s should be 0"
                         % get_resource_type(resource_id=8))  #CPU
        return
    def setupAccounts(self):

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

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

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

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

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

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

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

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

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

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

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

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

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

        Resources.updateLimit(
            self.apiclient,
            resourcetype=8,
            max=16,
            account=self.admin.name,
            domainid=self.admin.domainid
        )
        return
    def 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
Example #23
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
Example #24
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
    def setUpClass(cls):
        cls.apiClient = super(TestDeployVmWithUserData, cls).getClsTestClient().getApiClient()
        cls.services = Services().services
        cls.zone = get_zone(cls.apiClient, cls.services)
        if cls.zone.localstorageenabled:
            #For devcloud since localstroage is enabled
            cls.services["service_offering"]["storagetype"] = "local"
        cls.service_offering = ServiceOffering.create(
            cls.apiClient,
            cls.services["service_offering"]
        )
        cls.account = Account.create(cls.apiClient, services=cls.services["account"])
        cls.cleanup = [cls.account]
        cls.template = get_template(
            cls.apiClient,
            cls.zone.id,
            cls.services["ostype"]
        )
        cls.debug("Successfully created account: %s, id: \
                   %s" % (cls.account.name,\
                          cls.account.id))


        # Generate userdata of 2500 bytes. This is larger than the 2048 bytes limit.
        # CS however allows for upto 4K bytes in the code. So this must succeed.
        # Overall, the query length must not exceed 4K, for then the json decoder
        # will fail this operation at the marvin client side itcls.
        user_data = ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(2500))
        cls.services["virtual_machine"]["userdata"] = user_data
    def setUpClass(cls):
        cls.api_client = super(TestSnapshotOnRootVolume,
                               cls).getClsTestClient().getApiClient()
        cls.services = Services().services
        cls.domain = get_domain(cls.api_client, cls.services)
        cls.zone = get_zone(cls.api_client, cls.services)
        cls.template = get_template(
                                    cls.api_client,
                                    cls.zone.id,
                                    cls.services["ostype"])
        cls.account = Account.create(cls.api_client,
                                     cls.services["account"],
                                     domainid=cls.domain.id)
        # pdb.set_trace()
        cls.service_offering = ServiceOffering.create(
                                            cls.api_client,
                                            cls.services["service_offering"])
        cls.disk_offering = DiskOffering.create(
                                    cls.api_client,
                                    cls.services["disk_offering"],
                                    domainid=cls.domain.id)
        cls.service_offering2 = ServiceOffering.create(
                                            cls.api_client,
                                            cls.services["service_offering2"])
        cls.disk_offering2 = DiskOffering.create(
                                    cls.api_client,
                                    cls.services["disk_offering2"],
                                    domainid=cls.domain.id)

        cls._cleanup = [cls.account,
                        cls.service_offering,
                        cls.disk_offering,
                        cls.service_offering2,
                        cls.disk_offering2]
Example #27
0
    def test_05_remove_used_range(self):
        """
        Test removing used vlan range
        """
        # 1. Use a vlan id from existing range by deploying an instance which
        #    will create a network with vlan id from this range
        # 4. Now try to remove this vlan range
        # 5. Vlan range should not get removed, should throw error

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

        self.debug("Deploying instance in the account: %s" % account.name)

        try:

            self.virtual_machine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"],
                                                     accountid=account.name,domainid=account.domainid,
                                                     serviceofferingid=self.service_offering.id,
                                                     mode=self.zone.networktype)
            self.debug("Deployed instance in account: %s" % account.name)
            self.debug("Trying to remove vlan range : %s , This should fail" % self.vlan["partial_range"][0])

            with self.assertRaises(Exception) as e:
                self.physicalnetwork.update(self.apiClient, id = self.physicalnetworkid, vlan = self.vlan["partial_range"][0])

            self.debug("operation failed with exception: %s" % e.exception)
            account.delete(self.apiclient)

        except Exception as e:
            self.fail("Exception in test case: %s" % e)

        return
Example #28
0
 def setUp(self):
     try:
         self.apiclient = self.testClient.getApiClient()
         self.dbclient = self.testClient.getDbConnection()
         self.account = Account.create(self.apiclient,
                                       self.services["account"],
                                       domainid=self.domain.id)
         self.cleanup = [
             self.account,
         ]
         self.virtual_machine = VirtualMachine.create(
             self.apiclient,
             self.services["virtual_machine"],
             templateid=self.template.id,
             accountid=self.account.name,
             domainid=self.account.domainid,
             serviceofferingid=self.service_offering.id)
         self.public_ip = PublicIPAddress.create(
             self.apiclient,
             accountid=self.virtual_machine.account,
             zoneid=self.virtual_machine.zoneid,
             domainid=self.virtual_machine.domainid,
             services=self.services["virtual_machine"])
         return
     except cloudstackAPIException as e:
         self.tearDown()
         raise e
Example #29
0
    def setupProjectAccounts(self):

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

        # Create project as a domain admin
        self.project = Project.create(self.apiclient,
                                      self.services["project"],
                                      account=self.admin.name,
                                      domainid=self.admin.domainid)
        # Cleanup created project at end of test
        self.cleanup.append(self.project)
        self.cleanup.append(self.admin)
        self.cleanup.append(self.domain)
        self.debug("Created project with domain admin with name: %s" %
                   self.project.name)

        projects = Project.list(self.apiclient,
                                id=self.project.id,
                                listall=True)

        self.assertEqual(isinstance(projects, list), True,
                         "Check for a valid list projects response")
        project = projects[0]
        self.assertEqual(project.name, self.project.name,
                         "Check project name from list response")
        return
    def setUp(self):
        self.testdata = TestData().testdata
        self.apiclient = self.testClient.getApiClient()

        # Get Zone, Domain and Default Built-in template
        self.domain = get_domain(self.apiclient, self.testdata)
        self.zone = get_zone(self.apiclient, self.testdata)
        self.testdata["mode"] = self.zone.networktype
        self.template = get_template(self.apiclient, self.zone.id, self.testdata["ostype"])
#       for testing with specific template
#        self.template = get_template(self.apiclient, self.zone.id, self.testdata["ostype"], templatetype='USER', services = {"template":'31f52a4d-5681-43f7-8651-ad4aaf823618'})
        

        #create a user account
        self.account = Account.create(
            self.apiclient,
            self.testdata["account"],
            domainid=self.domain.id
        )
        #create a service offering
        self.service_offering = ServiceOffering.create(
            self.apiclient,
            self.testdata["service_offering"]["small"]
        )
        #build cleanup list
        self.cleanup = [
            self.service_offering,
            self.account
        ]
    def setupAccounts(self, account_limit=2, domain_limit=2, project_limit=2):

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

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

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

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

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

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

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

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

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

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

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

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

        return
Example #32
0
    def setUpClass(cls):
        cls.api_client = super(TestSnapshotOnRootVolume,
                               cls).getClsTestClient().getApiClient()
        cls.services = Services().services
        cls.domain = get_domain(cls.api_client, cls.services)
        cls.zone = get_zone(cls.api_client, cls.services)
        cls.template = get_template(cls.api_client, cls.zone.id,
                                    cls.services["ostype"])
        cls.account = Account.create(cls.api_client,
                                     cls.services["account"],
                                     domainid=cls.domain.id)
        # pdb.set_trace()
        cls.service_offering = ServiceOffering.create(
            cls.api_client, cls.services["service_offering"])
        cls.disk_offering = DiskOffering.create(cls.api_client,
                                                cls.services["disk_offering"],
                                                domainid=cls.domain.id)
        cls.service_offering2 = ServiceOffering.create(
            cls.api_client, cls.services["service_offering2"])
        cls.disk_offering2 = DiskOffering.create(
            cls.api_client,
            cls.services["disk_offering2"],
            domainid=cls.domain.id)

        cls._cleanup = [
            cls.account, cls.service_offering, cls.disk_offering,
            cls.service_offering2, cls.disk_offering2
        ]
    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
Example #34
0
    def setUp(self):
        self.apiclient = self.testClient.getApiClient()
        self.dbclient = self.testClient.getDbConnection()
        self.account = Account.create(self.apiclient,
                                      self.services["account"],
                                      domainid=self.domain.id)
        self.virtual_machine = VirtualMachine.create(
            self.apiclient,
            self.services["virtual_machine"],
            templateid=self.template.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id)

        self.virtual_machine_2 = VirtualMachine.create(
            self.apiclient,
            self.services["virtual_machine"],
            templateid=self.template.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id)
        self.public_ip = PublicIPAddress.create(
            self.apiclient, self.virtual_machine.account,
            self.virtual_machine.zoneid, self.virtual_machine.domainid,
            self.services["virtual_machine"])

        NATRule.create(self.apiclient,
                       self.virtual_machine,
                       self.services["natrule"],
                       ipaddressid=self.public_ip.ipaddress.id)

        self.cleanup = [
            self.account,
        ]
        return
Example #35
0
 def setUp(self):
     try:
         self.apiclient = self.testClient.getApiClient()
         self.dbclient = self.testClient.getDbConnection()
         self.account = Account.create(
                             self.apiclient,
                             self.services["account"],
                             domainid=self.domain.id
                             )
         self.cleanup = [
                         self.account,
                         ]
         self.virtual_machine = VirtualMachine.create(
                                 self.apiclient,
                                 self.services["virtual_machine"],
                                 templateid=self.template.id,
                                 accountid=self.account.name,
                                 domainid=self.account.domainid,
                                 serviceofferingid=self.service_offering.id
                                 )
         self.public_ip = PublicIPAddress.create(
                                            self.apiclient,
                                            accountid=self.virtual_machine.account,
                                            zoneid=self.virtual_machine.zoneid,
                                            domainid=self.virtual_machine.domainid,
                                            services=self.services["virtual_machine"]
                                            )
         return
     except cloudstackAPIException as e:
             self.tearDown()
             raise e
Example #36
0
 def setUp(self):
     self.apiclient = self.testClient.getApiClient()
     self.dbclient = self.testClient.getDbConnection()
     self.account = Account.create(
                         self.apiclient,
                         self.services["account"],
                         domainid=self.domain.id
                         )
     self.virtual_machine = VirtualMachine.create(
                             self.apiclient,
                             self.services["virtual_machine"],
                             templateid=self.template.id,
                             accountid=self.account.name,
                             domainid=self.account.domainid,
                             serviceofferingid=self.service_offering.id
                             )
     self.public_ip = PublicIPAddress.create(
                                        self.apiclient,
                                        self.virtual_machine.account,
                                        self.virtual_machine.zoneid,
                                        self.virtual_machine.domainid,
                                        self.services["virtual_machine"]
                                        )
     self.cleanup = [
                     self.account,
                     ]
     return
    def setUp(self):
        self.apiclient = self.testClient.getApiClient()
        self.account = Account.create(
                                                self.apiclient,
                                                self.services["account"],
                                                admin=True,
                                                domainid=self.domain.id
                                                )
        self.cleanup = [self.account]
        self.debug("Creating a VPC offering..")
        self.vpc_off = VpcOffering.create(
                                                self.apiclient,
                                                self.services["vpc_offering"]
                                                )

        self.debug("Enabling the VPC offering created")
        self.vpc_off.update(self.apiclient, state='Enabled')

        self.debug("Creating a VPC network in the account: %s" % self.account.name)
        self.services["vpc"]["cidr"] = '10.1.1.1/16'
        self.vpc = VPC.create(
                                self.apiclient,
                                self.services["vpc"],
                                vpcofferingid=self.vpc_off.id,
                                zoneid=self.zone.id,
                                account=self.account.name,
                                domainid=self.account.domainid
                                )
        return
Example #38
0
 def setUpClass(cls):
     cls._cleanup = []
     cls.api_client = super(TestEgressFWRules,
                            cls).getClsTestClient().getApiClient()
     cls.services  = Services().services
     # Get Zone  Domain and create Domains and sub Domains.
     cls.domain           = get_domain(cls.api_client, cls.services)
     cls.zone             = get_zone(cls.api_client, cls.services)
     cls.services['mode'] = cls.zone.networktype
     # Get and set template id for VM creation.
     cls.template = get_template(cls.api_client,
                                 cls.zone.id,
                                 cls.services["ostype"])
     cls.services["virtual_machine"]["zoneid"] = cls.zone.id
     cls.services["virtual_machine"]["template"] = cls.template.id
     parentDomain = None
     cls.domain  =  Domain.create(cls.api_client,
                                  cls.services["domain"],
                                  parentdomainid=parentDomain.id if parentDomain else None)
     cls._cleanup.append(cls.domain)
     # Create an Account associated with domain
     cls.account = Account.create(cls.api_client,
                                  cls.services["account"],
                                  domainid=cls.domain.id)
     cls._cleanup.append(cls.account)
     # Create service offerings.
     cls.service_offering = ServiceOffering.create(cls.api_client,
                                                   cls.services["service_offering"])
     # Cleanup
     cls._cleanup.append(cls.service_offering)
    def setUpClass(cls):
        cls.apiclient = super(TestDeployVmWithVariedPlanners, cls).getClsTestClient().getApiClient()
        cls.services = Services().services
        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.apiclient, cls.services)
        cls.zone = get_zone(cls.apiclient, cls.services)
        cls.template = get_template(
            cls.apiclient,
            cls.zone.id,
            cls.services["ostype"]
        )
        cls.services["virtual_machine"]["zoneid"] = cls.zone.id
        cls.services["template"] = cls.template.id
        cls.services["zoneid"] = cls.zone.id

        cls.account = Account.create(
            cls.apiclient,
            cls.services["account"],
            domainid=cls.domain.id
        )
        cls.services["account"] = cls.account.name
        cls.hosts = Host.list(cls.apiclient, type='Routing')
        cls.clusters = Cluster.list(cls.apiclient)
        cls.cleanup = [
            cls.account
        ]
    def setupProjectAccounts(self):

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

        # Create project as a domain admin
        self.project = Project.create(self.apiclient,
                                 self.services["project"],
                                 account=self.admin.name,
                                 domainid=self.admin.domainid)
        # Cleanup created project at end of test
        self.cleanup.append(self.project)
        self.cleanup.append(self.admin)
        self.cleanup.append(self.domain)
        self.debug("Created project with domain admin with name: %s" %
                                                        self.project.name)

        projects = Project.list(self.apiclient, id=self.project.id,
                                listall=True)

        self.assertEqual(isinstance(projects, list), True,
                        "Check for a valid list projects response")
        project = projects[0]
        self.assertEqual(project.name, self.project.name,
                        "Check project name from list response")
        return
Example #41
0
 def create_domain_account_user(parentDomain=None):
     domain  =  Domain.create(cls.api_client,
                              cls.services["domain"],
                              parentdomainid=parentDomain.id if parentDomain else None)
     cls._cleanup.append(domain)
     # Create an Account associated with domain
     account = Account.create(cls.api_client,
                              cls.services["account"],
                              domainid=domain.id)
     cls._cleanup.append(account)
     # Create an User, Project, Volume associated with account
     user    = User.create(cls.api_client,
                           cls.services["user"],
                           account=account.name,
                           domainid=account.domainid)
     cls._cleanup.append(user)
     project = Project.create(cls.api_client,
                              cls.services["project"],
                              account=account.name,
                              domainid=account.domainid)
     cls._cleanup.append(project)
     volume  = Volume.create(cls.api_client,
                             cls.services["volume"],
                             zoneid=cls.zone.id,
                             account=account.name,
                             domainid=account.domainid,
                             diskofferingid=cls.disk_offering.id)
     cls._cleanup.append(volume)
     return {'domain':domain, 'account':account, 'user':user, 'project':project, 'volume':volume}
Example #42
0
    def setUp(self):
        self.apiclient = self.testClient.getApiClient()
        self.account = Account.create(self.apiclient,
                                      self.services["account"],
                                      admin=True,
                                      domainid=self.domain.id)
        self.cleanup = [self.account]
        self.debug("Creating a VPC offering..")
        self.vpc_off = VpcOffering.create(self.apiclient,
                                          self.services["vpc_offering"])

        self.cleanup.append(self.vpc_off)
        self.debug("Enabling the VPC offering created")
        self.vpc_off.update(self.apiclient, state='Enabled')

        self.debug("Creating a VPC network in the account: %s" %
                   self.account.name)
        self.services["vpc"]["cidr"] = '10.1.1.1/16'
        self.vpc = VPC.create(self.apiclient,
                              self.services["vpc"],
                              vpcofferingid=self.vpc_off.id,
                              zoneid=self.zone.id,
                              account=self.account.name,
                              domainid=self.account.domainid)
        return
Example #43
0
    def setUp(self):
        self.testdata = TestData().testdata
        self.apiclient = self.testClient.getApiClient()

        # Get Zone, Domain and Default Built-in template
        self.domain = get_domain(self.apiclient, self.testdata)
        self.zone = get_zone(self.apiclient, self.testdata)
        self.testdata["mode"] = self.zone.networktype
        self.template = get_template(self.apiclient, self.zone.id, self.testdata["ostype"])

        #create a user account
        self.account = Account.create(
            self.apiclient,
            self.testdata["account"],
            domainid=self.domain.id
        )
        #create a service offering
        self.service_offering = ServiceOffering.create(
            self.apiclient,
            self.testdata["service_offering"]["small"]
        )
        #build cleanup list
        self.cleanup = [
            self.service_offering,
            self.account
        ]
    def setUpClass(cls):
        cls.apiClient = super(TestDeployVmWithUserData,
                              cls).getClsTestClient().getApiClient()
        cls.services = Services().services
        cls.zone = get_zone(cls.apiClient, cls.services)
        if cls.zone.localstorageenabled:
            #For devcloud since localstroage is enabled
            cls.services["service_offering"]["storagetype"] = "local"
        cls.service_offering = ServiceOffering.create(
            cls.apiClient, cls.services["service_offering"])
        cls.account = Account.create(cls.apiClient,
                                     services=cls.services["account"])
        cls.cleanup = [cls.account]
        cls.template = get_template(cls.apiClient, cls.zone.id,
                                    cls.services["ostype"])
        cls.debug("Successfully created account: %s, id: \
                   %s"                       % (cls.account.name,\
                          cls.account.id))

        # Generate userdata of 2500 bytes. This is larger than the 2048 bytes limit.
        # CS however allows for upto 4K bytes in the code. So this must succeed.
        # Overall, the query length must not exceed 4K, for then the json decoder
        # will fail this operation at the marvin client side itcls.
        user_data = ''.join(
            random.choice(string.ascii_uppercase + string.digits)
            for x in range(2500))
        cls.services["virtual_machine"]["userdata"] = user_data
    def setUp(self):
        self.services = Services().services
        self.apiclient = self.testClient.getApiClient()

        # Get Zone, Domain and Default Built-in template
        self.domain = get_domain(self.apiclient, self.services)
        self.zone = get_zone(self.apiclient, self.services)
        self.services["mode"] = self.zone.networktype
        # Before running this test, register a windows template with ostype as 'Windows 7 (32-bit)'
        self.template = get_template(self.apiclient, self.zone.id, self.services["ostype"], templatetype='USER')

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

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

        self.services["vgpu140q"]["zoneid"] = self.zone.id
        self.services["vgpu140q"]["template"] = self.template.id
        #create a service offering
        self.service_offering = ServiceOffering.create(
                self.apiclient,
                self.services["service_offerings"]["vgpu260qwin"],
                serviceofferingdetails={'pciDevice': 'VGPU'}
        )
        #build cleanup list
        self.cleanup = [
            self.service_offering,
            self.account
        ]
    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
Example #47
0
    def test_operations_non_root_admin_api_client(self, value):
        """Test basic operations using non root admin apii client"""

        # Steps:
        # 1. Create Domain and Account in it
        # 2. Create network in it (isoalted/ shared/ vpc)
        # 3. Create User API client of this account
        # 4. Deploy a VM in this network and account
        # 5. Add secondary IP to the default nic of VM using non root admin api client
        # 6. List secondary IPs using non root admin api client
        # 7. Remove secondary IP using non root admin api client

        # Validations:
        # 1. All the operations should be successful

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

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

        apiclient = self.testClient.createUserApiClient(UserName=self.account.name, DomainName=self.account.domain)

        if(shouldTestBeSkipped(networkType=value, zoneType=self.mode)):
            self.skipTest("Skipping test as %s network is not supported in basic zone" % value)

        network = createNetwork(self, value)

        try:
            virtual_machine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"],
                                                    networkids=[network.id],serviceofferingid=self.service_offering.id,
                                                    accountid=self.account.name,domainid=self.account.domainid)
        except Exception as e:
            self.fail("vm creation failed: %s" % e)

        try:
            ipaddress_1 = NIC.addIp(apiclient, id=virtual_machine.nic[0].id)
        except Exception as e:
            self.fail("Failed while adding secondary IP to NIC of vm %s" % virtual_machine.id)

        try:
            NIC.list(apiclient, virtualmachineid=virtual_machine.id)
        except Exception as e:
            self.fail("Listing NICs for virtual machine %s failed with Exception %s" % (virtual_machine.id, e))

        try:
            NIC.list(apiclient, virtualmachineid=virtual_machine.id, nicid=virtual_machine.nic[0].id)
        except Exception as e:
            self.fail("Listing NICs for virtual machine %s and nic id %s failed with Exception %s" %
                    (virtual_machine.id, virtual_machine.nic[0].id, e))

        try:
            NIC.removeIp(apiclient, ipaddressid=ipaddress_1.id)
        except Exception as e:
            self.fail("Removing seondary IP %s from NIC failed as expected with Exception %s" % (ipaddress_1.id,e))

        return
Example #48
0
    def test_add_static_nat_rule(self, value):
        """ Add secondary IP to NIC of a VM"""

        # Steps:
        # 1. Create Account and create network in it (isoalted/ shared/ vpc)
        # 2. Deploy a VM in this network and account
        # 3. Add 2 secondary IPs to the default nic of VM
        # 4. Acquire public IP, open firewall for it, and
        #    create static NAT rule for this public IP to the 1st secondary IP
        # 5. Repeat step 4 for another public IP
        # 6. Repeat step 4 for 2nd secondary IP
        # 7. Repeat step 4 for invalid secondary IP
        # 8. Try to remove 1st secondary IP (with active static nat rule)

        # Validations:
        # 1. Step 4 should succeed
        # 2. Step 5 should succeed
        # 3. Step 6 should succeed
        # 4. Step 7 should fail
        # 5. Step 8 should succeed

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

        network = createNetwork(self, value)

        try:
            virtual_machine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"],
                                                    networkids=[network.id],serviceofferingid=self.service_offering.id,
                                                    accountid=self.account.name,domainid=self.account.domainid)
        except Exception as e:
            self.fail("vm creation failed: %s" % e)

        try:
            ipaddress_1 = NIC.addIp(self.apiclient, id=virtual_machine.nic[0].id)
        except Exception as e:
            self.fail("Failed while adding secondary IP to NIC of vm %s" % virtual_machine.id)

        try:
            ipaddress_2 = NIC.addIp(self.apiclient, id=virtual_machine.nic[0].id)
        except Exception as e:
            self.fail("Failed while adding secondary IP to NIC of vm %s" % virtual_machine.id)

        self.assertEqual(createNetworkRules(self, virtual_machine, network, ipaddress_1.ipaddress, value, ruletype="staticnat"),
                PASS, "Failure in creating NAT rule")
        self.assertEqual(createNetworkRules(self, virtual_machine, network, ipaddress_1.ipaddress, value, ruletype="staticnat"),
                FAIL, "Failure in creating NAT rule")
        self.assertEqual(createNetworkRules(self, virtual_machine, network, ipaddress_2.ipaddress, value, ruletype="staticnat"),
                PASS, "Failure in creating NAT rule")
        self.assertEqual(createNetworkRules(self, virtual_machine, network, "255.255.255.300", value, ruletype="staticnat"),
                FAIL, "Failure in NAT rule creation")

        try:
            NIC.removeIp(self.apiclient, ipaddress_1.id)
            self.fail("Ip address should not get removed when active static NAT rule is defined for it")
        except Exception as e:
            self.debug("Exception while removing secondary ip address as expected because static nat rule is present for it")
        return
 def setUp(self):
     self.apiclient = self.testClient.getApiClient()
     self.dbclient = self.testClient.getDbConnection()
     self.account = Account.create(self.apiclient,
                                   self.services["account"],
                                   admin=True,
                                   domainid=self.domain.id)
     self.cleanup = [self.account]
     return
Example #50
0
    def test_disable_static_nat(self, value):
        """ Add secondary IP to NIC of a VM"""

        # Steps:
        # 1. Create Account and create network in it (isoalted/ shared/ vpc)
        # 2. Deploy a VM in this network and account
        # 3. Add 2 secondary IPs to the default nic of VM
        # 4. Acquire public IP, open firewall for it, and
        #    enable static NAT rule for this public IP to the 1st secondary IP
        # 5. Disable the static nat rule and enable it again

        # Validations:
        # 1. Verify step 5 by listing seconday IP and checking the appropriate flag

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

        network = createNetwork(self, value)

        try:
            virtual_machine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"],
                                                    networkids=[network.id],serviceofferingid=self.service_offering.id,
                                                    accountid=self.account.name,domainid=self.account.domainid)
        except Exception as e:
            self.fail("vm creation failed: %s" % e)

        try:
            ipaddress_1 = NIC.addIp(self.apiclient, id=virtual_machine.nic[0].id)
        except Exception as e:
            self.fail("Failed while adding secondary IP to NIC of vm %s" % virtual_machine.id)

        public_ip = PublicIPAddress.create(self.api_client,accountid=self.account.name,
                                           zoneid=self.zone.id,domainid=self.account.domainid,
                                           networkid=network.id, vpcid = network.vpcid if value == VPC_NETWORK else None)

        if value != VPC_NETWORK:
            FireWallRule.create(self.apiclient,ipaddressid=public_ip.ipaddress.id,
                                      protocol='TCP', cidrlist=[self.services["fwrule"]["cidr"]],
                                      startport=self.services["fwrule"]["startport"],endport=self.services["fwrule"]["endport"])

        StaticNATRule.enable(self.apiclient, public_ip.ipaddress.id, virtual_machine.id,
                    network.id, vmguestip=ipaddress_1.ipaddress)

        self.VerifyStaticNatForPublicIp(public_ip.ipaddress.id, True)

        # Disabling static NAT
        StaticNATRule.disable(self.apiclient, public_ip.ipaddress.id)

        self.VerifyStaticNatForPublicIp(public_ip.ipaddress.id, False)

        StaticNATRule.enable(self.apiclient, public_ip.ipaddress.id, virtual_machine.id,
                    network.id, vmguestip=ipaddress_1.ipaddress)

        self.VerifyStaticNatForPublicIp(public_ip.ipaddress.id, True)

        public_ip.delete(self.apiclient)
        return
Example #51
0
    def test_add_ip_to_nic(self, value):
        """ Add secondary IP to NIC of a VM"""

        # Steps:
        # 1. Create Account and create network in it (isoalted/ shared/ vpc)
        # 2. Deploy a VM in this network and account
        # 3. Add secondary IP to the default nic of VM
        # 4. Try to add the same IP again
        # 5. Try to add secondary IP providing wrong virtual machine id
        # 6. Try to add secondary IP with correct virtual machine id but wrong IP address

        # Validations:
        # 1. Step 3 should succeed
        # 2. Step 4 should fail
        # 3. Step 5 should should fail
        # 4. Step 6 should fail

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

        if(shouldTestBeSkipped(networkType=value, zoneType=self.mode)):
            self.skipTest("Skipping test as %s network is not supported in basic zone" % value)

        network = createNetwork(self, value)

        try:
            virtual_machine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"],
                                                    networkids=[network.id],serviceofferingid=self.service_offering.id,
                                                    accountid=self.account.name,domainid=self.account.domainid)
        except Exception as e:
            self.fail("vm creation failed: %s" % e)

        try:
            ipaddress_1 = NIC.addIp(self.apiclient, id=virtual_machine.nic[0].id)
        except Exception as e:
            self.fail("Failed while adding secondary IP to NIC of vm %s" % virtual_machine.id)

        try:
            NIC.addIp(self.apiclient, id=virtual_machine.nic[0].id, ipaddress=ipaddress_1.ipaddress)
            self.debug("Adding already added secondary IP %s to NIC of vm %s succeeded, should have failed" %
                    (ipaddress_1.ipaddress, virtual_machine.id))
        except Exception as e:
            self.debug("Failed while adding already added secondary IP to NIC of vm %s" % virtual_machine.id)

        try:
            NIC.addIp(self.apiclient, id=(virtual_machine.nic[0].id + random_gen()))
            self.fail("Adding secondary IP with wrong NIC id succeded, it shoud have failed")
        except Exception as e:
            self.debug("Failed while adding secondary IP to wrong NIC")

        try:
            NIC.addIp(self.apiclient, id=virtual_machine.nic[0].id, ipaddress = "255.255.255.300")
            self.fail("Adding secondary IP with wrong ipaddress succeded, it should have failed")
        except Exception as e:
            self.debug("Failed while adding wrong secondary IP to NIC of VM %s" % virtual_machine.id)
        return
    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.createUserApiClient(
                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
Example #53
0
    def setUp(self):
        self.testdata = TestData().testdata
        self.apiclient = self.testClient.getApiClient()

        # Get Zone, Domain and Default Built-in template
        self.domain = get_domain(self.apiclient, self.testdata)
        self.zone = get_zone(self.apiclient, self.testdata)
        self.testdata["mode"] = self.zone.networktype
        self.template = get_template(self.apiclient, self.zone.id,
                                     self.testdata["ostype"])

        #create a user account
        self.account = Account.create(self.apiclient,
                                      self.testdata["account"],
                                      domainid=self.domain.id)
        #create a service offering
        self.service_offering = ServiceOffering.create(
            self.apiclient, self.testdata["service_offering"]["small"])
        #build cleanup list
        self.cleanup = [self.service_offering, self.account]

        # Validate the following:
        # 1. Virtual Machine is accessible via SSH
        # 2. listVirtualMachines returns accurate information

        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)

        list_vms = VirtualMachine.list(self.apiclient,
                                       id=self.virtual_machine.id)

        self.debug(
            "Verify listVirtualMachines response for virtual machine: %s"\
            % self.virtual_machine.id
        )

        self.assertEqual(isinstance(list_vms, list), True,
                         "List VM response was not a valid list")
        self.assertNotEqual(len(list_vms), 0, "List VM response was empty")

        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")
Example #54
0
    def setUp(self):
        self.apiclient = self.testClient.getApiClient()
        self.dbclient = self.testClient.getDbConnection()
        self.account = Account.create(self.apiclient,
                                      self.services["account"],
                                      admin=True)

        self.debug("Creating service offering with 5 GB RAM")

        self.cleanup = [
            self.account,
        ]
        return
Example #55
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
Example #56
0
    def test_disassociate_ip_mapped_to_secondary_ip_through_PF_rule(self, value):
        """ Add secondary IP to NIC of a VM"""

        ## Steps:
        # 1. Create Account and create network in it (isoalted/ shared/ vpc)
        # 2. Deploy a VM in this network and account
        # 3. Add secondary IP to the default nic of VM
        # 4. Acquire public IP, open firewall for it, and
        #    create NAT rule for this public IP to the 1st secondary IP
        # 5. Try to delete the public IP used for NAT rule

        # Validations:
        # 1. Step 5 should succeed

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

        network = createNetwork(self, value)

        try:
            virtual_machine = VirtualMachine.create(self.apiclient,self.services["virtual_machine"],
                                                    networkids=[network.id],serviceofferingid=self.service_offering.id,
                                                    accountid=self.account.name,domainid=self.account.domainid)
        except Exception as e:
            self.fail("vm creation failed: %s" % e)

        try:
            ipaddress_1 = NIC.addIp(self.apiclient, id=virtual_machine.nic[0].id)
        except Exception as e:
            self.fail("Failed while adding secondary IP to NIC of vm %s" % virtual_machine.id)

        public_ip = PublicIPAddress.create(self.api_client,accountid=self.account.name,
                                           zoneid=self.zone.id,domainid=self.account.domainid,
                                           networkid=network.id, vpcid = network.vpcid if value == VPC_NETWORK else None)

        if value != VPC_NETWORK:
            FireWallRule.create(self.apiclient,ipaddressid=public_ip.ipaddress.id,
                                      protocol='TCP', cidrlist=[self.services["fwrule"]["cidr"]],
                                      startport=self.services["fwrule"]["startport"],endport=self.services["fwrule"]["endport"])

        # Create NAT rule
        natrule = NATRule.create(self.api_client, virtual_machine,
                       self.services["natrule"],ipaddressid=public_ip.ipaddress.id,
                       networkid=network.id, vmguestip = ipaddress_1.ipaddress)

        try:
            public_ip.delete(self.apiclient)
        except Exception as e:
            self.fail("Exception while deleting nat rule %s: %s" % (natrule.id, e))
        return