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]
Exemplo n.º 2
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 setUpClass(cls):
        cls.api_client = super(TestServiceOfferings, cls).getClsTestClient().getApiClient()
        cls.services = Services().services
        domain = get_domain(cls.api_client, cls.services)
        cls.zone = get_zone(cls.api_client, cls.services)
        cls.services['mode'] = cls.zone.networktype

        cls.service_offering_1 = ServiceOffering.create(
            cls.api_client,
            cls.services["off"]
        )
        cls.service_offering_2 = ServiceOffering.create(
            cls.api_client,
            cls.services["off"]
        )
        template = get_template(
                            cls.api_client,
                            cls.zone.id,
                            cls.services["ostype"]
                            )
        # Set Zones and disk offerings
        cls.services["small"]["zoneid"] = cls.zone.id
        cls.services["small"]["template"] = template.id

        cls.services["medium"]["zoneid"] = cls.zone.id
        cls.services["medium"]["template"] = template.id

        # Create VMs, NAT Rules etc
        cls.account = Account.create(
                            cls.api_client,
                            cls.services["account"],
                            domainid=domain.id
                            )

        cls.small_offering = ServiceOffering.create(
                                    cls.api_client,
                                    cls.services["service_offerings"]["small"]
                                    )

        cls.medium_offering = ServiceOffering.create(
                                    cls.api_client,
                                    cls.services["service_offerings"]["medium"]
                                    )
        cls.medium_virtual_machine = VirtualMachine.create(
                                       cls.api_client,
                                       cls.services["medium"],
                                       accountid=cls.account.name,
                                       domainid=cls.account.domainid,
                                       serviceofferingid=cls.medium_offering.id,
                                       mode=cls.services["mode"]
                                    )
        cls._cleanup = [
                        cls.small_offering,
                        cls.medium_offering,
                        cls.account
                        ]
        return
    def setUpClass(cls):
        cls.api_client = super(TestBaseImageUpdate,
                               cls).getClsTestClient().getApiClient()
        cls.services = Services().services
        # Get Zone, Domain and templates
        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.services["virtual_machine"]["zoneid"] = cls.zone.id
        cls.services["virtual_machine"]["template"] = cls.template.id

        cls.service_offering_with_reset = ServiceOffering.create(
            cls.api_client, cls.services["service_offering_with_reset"])

        cls.service_offering_without_reset = ServiceOffering.create(
            cls.api_client, cls.services["service_offering_without_reset"])

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

        cls.vm_with_reset = VirtualMachine.create(
            cls.api_client,
            cls.services["virtual_machine"],
            accountid=cls.account.name,
            domainid=cls.account.domainid,
            serviceofferingid=cls.service_offering_with_reset.id,
        )
        cls.vm_with_reset_root_disk_id = cls.get_root_device_uuid_for_vm(
            cls.vm_with_reset.id, cls.vm_with_reset.rootdeviceid)

        cls.vm_without_reset = VirtualMachine.create(
            cls.api_client,
            cls.services["virtual_machine"],
            accountid=cls.account.name,
            domainid=cls.account.domainid,
            serviceofferingid=cls.service_offering_without_reset.id,
        )
        cls.vm_without_reset_root_disk_id = cls.get_root_device_uuid_for_vm(
            cls.vm_without_reset.id, cls.vm_without_reset.rootdeviceid)

        cls._cleanup = [
            cls.account,
            cls.service_offering_with_reset,
            cls.service_offering_without_reset,
        ]
        return
Exemplo n.º 5
0
    def setUpClass(cls):
        # We want to fail quicker if it's failure
        socket.setdefaulttimeout(60)

        cls.api_client = super(
                                        TestVPCNetworkPFRules,
                                        cls
                                        ).getClsTestClient().getApiClient()
        cls.services = Services().services
        # Get Zone, Domain and templates
        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.services["virtual_machine"]["zoneid"] = cls.zone.id
        cls.services["virtual_machine"]["template"] = cls.template.id

        cls.service_offering = ServiceOffering.create(
                                                        cls.api_client,
                                                        cls.services["service_offering"]
                                                        )
        cls._cleanup = [cls.service_offering]
        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 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
Exemplo n.º 8
0
    def setUpClass(cls):
        cls.api_client = super(TestMemoryLimits,
                               cls).getClsTestClient().getApiClient()
        cls.services = Services().services
        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.api_client, cls.services)
        cls.zone = get_zone(cls.api_client, cls.services)

        cls.services["mode"] = cls.zone.networktype

        cls.template = get_template(
                            cls.api_client,
                            cls.zone.id,
                            cls.services["ostype"]
                            )

        cls.services["virtual_machine"]["zoneid"] = cls.zone.id

        cls.service_offering = ServiceOffering.create(
                                            cls.api_client,
                                            cls.services["service_offering"]
                                            )

        cls._cleanup = [cls.service_offering, ]
        return
    def test_deployvm_firstfit(self):
        """Test to deploy vm with a first fit offering
        """
        # FIXME: How do we know that first fit actually happened?
        self.service_offering_firstfit = ServiceOffering.create(
            self.apiclient, self.services["service_offering"], deploymentplanner="FirstFitPlanner"
        )

        self.virtual_machine = VirtualMachine.create(
            self.apiclient,
            self.services["virtual_machine"],
            accountid=self.account.name,
            zoneid=self.zone.id,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering_firstfit.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.state, "Running", msg="VM is not in Running state")
Exemplo n.º 10
0
    def setUpClass(cls):
        cls.api_client = super(TestNonContiguousVLANRanges, cls).getClsTestClient().getApiClient()
        cls.services = Services().services
        # Get Zone, pod, domain
        cls.zone = get_zone(cls.api_client, cls.services)
        cls.pod = get_pod(cls.api_client, cls.zone.id, cls.services)
        cls.domain = get_domain(cls.api_client, cls.services)

        cls.service_offering = ServiceOffering.create(
                                    cls.api_client,
                                    cls.services["service_offering"]
                                    )

        cls.template = get_template(
                            cls.api_client,
                            cls.zone.id,
                            cls.services["ostype"]
                            )

        cls.services["virtual_machine"]["template"] = cls.template.id
        cls.services["virtual_machine"]["zoneid"] = cls.zone.id

        cls._cleanup = [cls.service_offering]

        return
    def test_deployvm_firstfit(self):
        """Test to deploy vm with a first fit offering
        """
        #FIXME: How do we know that first fit actually happened?
        self.service_offering_firstfit = ServiceOffering.create(
            self.apiclient,
            self.services["service_offering"],
            deploymentplanner='FirstFitPlanner')

        self.virtual_machine = VirtualMachine.create(
            self.apiclient,
            self.services["virtual_machine"],
            accountid=self.account.name,
            zoneid=self.zone.id,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering_firstfit.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.state, "Running", msg="VM is not in Running state")
Exemplo n.º 12
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
        ]
Exemplo n.º 13
0
    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 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
Exemplo n.º 15
0
    def setUpClass(cls):
        # We want to fail quicker if it's failure
        socket.setdefaulttimeout(60)

        cls.api_client = super(
                                        TestVPCNetworkPFRules,
                                        cls
                                        ).getClsTestClient().getApiClient()
        cls.services = Services().services
        # Get Zone, Domain and templates
        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.services["virtual_machine"]["zoneid"] = cls.zone.id
        cls.services["virtual_machine"]["template"] = cls.template.id

        cls.service_offering = ServiceOffering.create(
                                                        cls.api_client,
                                                        cls.services["service_offering"]
                                                        )
        cls._cleanup = [cls.service_offering]
        return
Exemplo n.º 16
0
    def test_03_deploy_vm_project_limit_reached(self):
        """Test TTry to deploy VM with admin account where account has not used
        the resources but @ project they are not available"""

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

        self.debug("Creating service offering with 3 CPU cores")

        self.services["service_offering"]["cpunumber"] = 3
        self.service_offering = ServiceOffering.create(
            self.apiclient, self.services["service_offering"])
        # Adding to cleanup list after execution
        self.cleanup.append(self.service_offering)

        self.debug("Setting up account and domain hierarchy")
        self.setupAccounts(account_limit=4, domain_limit=4, project_limit=2)

        api_client_admin = self.testClient.createUserApiClient(
            UserName=self.child_do_admin.name,
            DomainName=self.child_do_admin.domain)

        self.debug("Deploying instance in account 2 when CPU limit is reached")

        with self.assertRaises(Exception):
            self.createInstance(project=self.project,
                                service_off=self.service_offering,
                                api_client=api_client_admin)
        return
Exemplo n.º 17
0
    def test_04_deploy_multiple_vm_with_multiple_cpus(self):
        """Test Deploy multiple VM with 4 core CPU & verify the usage"""

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

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

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

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

        expected_resource_count = int(
            self.services["service_offering"]["cpunumber"]) * 4  #Total 4 Vms
        self.assertTrue(resource_count == expected_resource_count,
                        "Resource count does not match the expected vavlue")
        return
Exemplo n.º 18
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 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
    def setUpClass(cls):
        cls.api_client = super(
                               TestCreateSnapshot,
                               cls).getClsTestClient().getApiClient()
        cls.services = Services().services
        # Get Zone, Domain and templates
        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.services["virtual_machine"]["zoneid"] = cls.zone.id

        # Create VMs, NAT Rules etc
        cls.service_offering = ServiceOffering.create(
                                            cls.api_client,
                                            cls.services["service_offering"]
                                            )
        cls._cleanup = [
                        cls.service_offering,
                        ]
        return
Exemplo n.º 21
0
    def test_03_deploy_vm_project_limit_reached(self):
        """Test TTry to deploy VM with admin account where account has not used
        the resources but @ project they are not available"""

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

        self.debug("Creating service offering with 3 CPU cores")

        self.services["service_offering"]["cpunumber"] = 3
        self.service_offering = ServiceOffering.create(
            self.apiclient,
            self.services["service_offering"]
        )
        # Adding to cleanup list after execution
        self.cleanup.append(self.service_offering)

        self.debug("Setting up account and domain hierarchy")
        self.setupAccounts(account_limit=4, domain_limit=4, project_limit=2)

        api_client_admin = self.testClient.createUserApiClient(
            UserName=self.child_do_admin.name,
            DomainName=self.child_do_admin.domain)

        self.debug("Deploying instance in account 2 when CPU limit is reached")

        with self.assertRaises(Exception):
            self.createInstance(project=self.project,
                service_off=self.service_offering, api_client=api_client_admin)
        return
Exemplo n.º 22
0
    def test_01_create_service_offering(self):
        """Test to create service offering"""

        # Validate the following:
        # 1. createServiceOfferings should return a valid information for newly created offering
        # 2. The Cloud Database contains the valid information

        service_offering = ServiceOffering.create(
            self.apiclient,
            self.services["off"]
        )
        self.cleanup.append(service_offering)

        self.debug("Created service offering with ID: %s" % service_offering.id)

        list_service_response = list_service_offering(
            self.apiclient,
            id=service_offering.id
        )
        self.assertEqual(
            isinstance(list_service_response, list),
            True,
            "Check list response returns a valid list"
        )

        self.assertNotEqual(
            len(list_service_response),
            0,
            "Check Service offering is created"
        )
        service_response = list_service_response[0]

        self.assertEqual(
            list_service_response[0].cpunumber,
            self.services["off"]["cpunumber"],
            "Check server id in createServiceOffering"
        )
        self.assertEqual(
            list_service_response[0].cpuspeed,
            self.services["off"]["cpuspeed"],
            "Check cpuspeed in createServiceOffering"
        )
        self.assertEqual(
            list_service_response[0].displaytext,
            self.services["off"]["displaytext"],
            "Check server displaytext in createServiceOfferings"
        )
        self.assertEqual(
            list_service_response[0].memory,
            self.services["off"]["memory"],
            "Check memory in createServiceOffering"
        )
        self.assertEqual(
            list_service_response[0].name,
            self.services["off"]["name"],
            "Check name in createServiceOffering"
        )
        return
    def test_deployvm_userdispersing(self):
        """Test deploy VMs using user dispersion planner
        """
        self.service_offering_userdispersing = ServiceOffering.create(
            self.apiclient,
            self.services["service_offering"],
            deploymentplanner='UserDispersingPlanner'
        )

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

        list_vm_1 = VirtualMachine.list(self.apiclient, id=self.virtual_machine_1.id)
        list_vm_2 = VirtualMachine.list(self.apiclient, id=self.virtual_machine_2.id)
        self.assertEqual(
            isinstance(list_vm_1, list),
            True,
            "List VM response was not a valid list"
        )
        self.assertEqual(
            isinstance(list_vm_2, list),
            True,
            "List VM response was not a valid list"
        )
        vm1 = list_vm_1[0]
        vm2 = list_vm_2[0]
        self.assertEqual(
            vm1.state,
            "Running",
            msg="VM is not in Running state"
        )
        self.assertEqual(
            vm2.state,
            "Running",
            msg="VM is not in Running state"
        )
        vm1clusterid = filter(lambda c: c.id == vm1.hostid, self.hosts)[0].clusterid
        vm2clusterid = filter(lambda c: c.id == vm2.hostid, self.hosts)[0].clusterid
        if vm1clusterid == vm2clusterid:
            self.debug("VMs (%s, %s) meant to be dispersed are deployed in the same cluster %s" % (
            vm1.id, vm2.id, vm1clusterid))
    def test_deployvm_userconcentrated(self):
        """Test deploy VMs using user concentrated planner
        """
        self.service_offering_userconcentrated = ServiceOffering.create(
            self.apiclient,
            self.services["service_offering"],
            deploymentplanner='UserConcentratedPodPlanner'
        )

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

        list_vm_1 = VirtualMachine.list(self.apiclient, id=self.virtual_machine_1.id)
        list_vm_2 = VirtualMachine.list(self.apiclient, id=self.virtual_machine_2.id)
        self.assertEqual(
            isinstance(list_vm_1, list),
            True,
            "List VM response was not a valid list"
        )
        self.assertEqual(
            isinstance(list_vm_2, list),
            True,
            "List VM response was not a valid list"
        )
        vm1 = list_vm_1[0]
        vm2 = list_vm_2[0]
        self.assertEqual(
            vm1.state,
            "Running",
            msg="VM is not in Running state"
        )
        self.assertEqual(
            vm2.state,
            "Running",
            msg="VM is not in Running state"
        )
        self.assertNotEqual(
            vm1.hostid,
            vm2.hostid,
            msg="VMs meant to be concentrated are deployed on the different hosts"
        )
    def setUpClass(cls):
        cls.api_client = super(TestBaseImageUpdate, cls).getClsTestClient().getApiClient()
        cls.services = Services().services
        # Get Zone, Domain and templates
        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.services["virtual_machine"]["zoneid"] = cls.zone.id
        cls.services["virtual_machine"]["template"] = cls.template.id

        cls.service_offering_with_reset = ServiceOffering.create(
            cls.api_client, cls.services["service_offering_with_reset"]
        )

        cls.service_offering_without_reset = ServiceOffering.create(
            cls.api_client, cls.services["service_offering_without_reset"]
        )

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

        cls.vm_with_reset = VirtualMachine.create(
            cls.api_client,
            cls.services["virtual_machine"],
            accountid=cls.account.name,
            domainid=cls.account.domainid,
            serviceofferingid=cls.service_offering_with_reset.id,
        )
        cls.vm_with_reset_root_disk_id = cls.get_root_device_uuid_for_vm(
            cls.vm_with_reset.id, cls.vm_with_reset.rootdeviceid
        )

        cls.vm_without_reset = VirtualMachine.create(
            cls.api_client,
            cls.services["virtual_machine"],
            accountid=cls.account.name,
            domainid=cls.account.domainid,
            serviceofferingid=cls.service_offering_without_reset.id,
        )
        cls.vm_without_reset_root_disk_id = cls.get_root_device_uuid_for_vm(
            cls.vm_without_reset.id, cls.vm_without_reset.rootdeviceid
        )

        cls._cleanup = [cls.account, cls.service_offering_with_reset, cls.service_offering_without_reset]
        return
    def test_deployvm_userconcentrated(self):
        """Test deploy VMs using user concentrated planner
        """
        self.service_offering_userconcentrated = ServiceOffering.create(
            self.apiclient,
            self.services["service_offering"],
            deploymentplanner='UserConcentratedPodPlanner')

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

        list_vm_1 = VirtualMachine.list(self.apiclient,
                                        id=self.virtual_machine_1.id)
        list_vm_2 = VirtualMachine.list(self.apiclient,
                                        id=self.virtual_machine_2.id)
        self.assertEqual(isinstance(list_vm_1, list), True,
                         "List VM response was not a valid list")
        self.assertEqual(isinstance(list_vm_2, list), True,
                         "List VM response was not a valid list")
        vm1 = list_vm_1[0]
        vm2 = list_vm_2[0]
        self.assertEqual(vm1.state,
                         "Running",
                         msg="VM is not in Running state")
        self.assertEqual(vm2.state,
                         "Running",
                         msg="VM is not in Running state")
        vm1clusterid = filter(lambda c: c.id == vm1.hostid,
                              self.hosts)[0].clusterid
        vm2clusterid = filter(lambda c: c.id == vm2.hostid,
                              self.hosts)[0].clusterid

        vm1podid = filter(lambda p: p.id == vm1clusterid,
                          self.clusters)[0].podid
        vm2podid = filter(lambda p: p.id == vm2clusterid,
                          self.clusters)[0].podid
        self.assertEqual(
            vm1podid,
            vm2podid,
            msg=
            "VMs (%s, %s) meant to be pod concentrated are deployed on different pods (%s, %s)"
            % (vm1.id, vm2.id, vm1clusterid, vm2clusterid))
    def test_deploy_virtual_machines_static_offering(self, value):
        """Test deploy VM with static offering"""

        # Steps:
        # 1. Create admin/user account and create its user api client
        # 2. Create a static compute offering
        # 3. Deploy a VM with account api client and static service offering
        # 4. Repeat step 3 but also pass custom values for cpu number, cpu speed and memory
        #    while deploying VM

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

        isadmin=True
        if value == USER_ACCOUNT:
            isadmin=False

        # Create Account
        self.account = Account.create(self.apiclient,self.services["account"],domainid=self.domain.id, admin=isadmin)
        apiclient = self.testClient.createUserApiClient(
                                    UserName=self.account.name,
                                    DomainName=self.account.domain)
        self.cleanup.append(self.account)

        # Create service offering
        self.services["service_offering"]["cpunumber"] = 2
        self.services["service_offering"]["cpuspeed"] = 256
        self.services["service_offering"]["memory"] = 128

        serviceOffering = ServiceOffering.create(self.apiclient,
                                                 self.services["service_offering"])

        self.cleanup_co.append(serviceOffering)

        # Deploy VM with static service offering
        try:
            VirtualMachine.create(apiclient,self.services["virtual_machine"],
                                                    serviceofferingid=serviceOffering.id,
                                                    accountid=self.account.name,domainid=self.account.domainid)
        except Exception as e:
            self.fail("vm creation failed: %s" % e)

        # Deploy VM with static service offering, also with custom values
        try:
            VirtualMachine.create(apiclient,self.services["virtual_machine"],
                serviceofferingid=serviceOffering.id,
                customcpunumber=4,
                customcpuspeed=512,
                custommemory=256,
                accountid=self.account.name,domainid=self.account.domainid)
            self.fail("VM creation should have failed, it succeeded")
        except Exception as e:
            self.debug("vm creation failed as expected: %s" % e)
        return
Exemplo n.º 28
0
    def setUpClass(cls):
        cls.services = Services().services
        cls.apiclient = super(TestDeployVM, cls).getClsTestClient().getApiClient()
        # Get Zone, Domain and templates
        domain = get_domain(cls.apiclient, cls.services)
        cls.zone = get_zone(cls.apiclient, cls.services)
        cls.services['mode'] = cls.zone.networktype

        #If local storage is enabled, alter the offerings to use localstorage
        #this step is needed for devcloud
        if cls.zone.localstorageenabled == True:
            cls.services["service_offerings"]["tiny"]["storagetype"] = 'local'
            cls.services["service_offerings"]["small"]["storagetype"] = 'local'
            cls.services["service_offerings"]["medium"]["storagetype"] = 'local'

        template = get_template(
            cls.apiclient,
            cls.zone.id,
            cls.services["ostype"]
        )
        # Set Zones and disk offerings
        cls.services["small"]["zoneid"] = cls.zone.id
        cls.services["small"]["template"] = template.id

        cls.services["medium"]["zoneid"] = cls.zone.id
        cls.services["medium"]["template"] = template.id
        cls.services["iso"]["zoneid"] = cls.zone.id

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

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

        cls.virtual_machine = VirtualMachine.create(
            cls.apiclient,
            cls.services["small"],
            accountid=cls.account.name,
            domainid=cls.account.domainid,
            serviceofferingid=cls.service_offering.id,
            mode=cls.services['mode']
        )

        cls.cleanup = [
            cls.service_offering,
            cls.account
        ]
Exemplo n.º 29
0
    def setUpClass(cls):
        cls.api_client = super(TestServiceOfferings,
                               cls).getClsTestClient().getApiClient()
        cls.services = Services().services
        domain = get_domain(cls.api_client, cls.services)
        cls.zone = get_zone(cls.api_client, cls.services)
        cls.services['mode'] = cls.zone.networktype

        cls.service_offering_1 = ServiceOffering.create(
            cls.api_client, cls.services["off"])
        cls.service_offering_2 = ServiceOffering.create(
            cls.api_client, cls.services["off"])
        template = get_template(cls.api_client, cls.zone.id,
                                cls.services["ostype"])
        # Set Zones and disk offerings
        cls.services["small"]["zoneid"] = cls.zone.id
        cls.services["small"]["template"] = template.id

        cls.services["medium"]["zoneid"] = cls.zone.id
        cls.services["medium"]["template"] = template.id

        # Create VMs, NAT Rules etc
        cls.account = Account.create(cls.api_client,
                                     cls.services["account"],
                                     domainid=domain.id)

        cls.small_offering = ServiceOffering.create(
            cls.api_client, cls.services["service_offerings"]["small"])

        cls.medium_offering = ServiceOffering.create(
            cls.api_client, cls.services["service_offerings"]["medium"])
        cls.medium_virtual_machine = VirtualMachine.create(
            cls.api_client,
            cls.services["medium"],
            accountid=cls.account.name,
            domainid=cls.account.domainid,
            serviceofferingid=cls.medium_offering.id,
            mode=cls.services["mode"])
        cls._cleanup = [cls.small_offering, cls.medium_offering, cls.account]
        return
Exemplo n.º 30
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")
    def test_deployvm_userdispersing(self):
        """Test deploy VMs using user dispersion planner
        """
        self.service_offering_userdispersing = ServiceOffering.create(
            self.apiclient,
            self.services["service_offering"],
            deploymentplanner='UserDispersingPlanner')

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

        list_vm_1 = VirtualMachine.list(self.apiclient,
                                        id=self.virtual_machine_1.id)
        list_vm_2 = VirtualMachine.list(self.apiclient,
                                        id=self.virtual_machine_2.id)
        self.assertEqual(isinstance(list_vm_1, list), True,
                         "List VM response was not a valid list")
        self.assertEqual(isinstance(list_vm_2, list), True,
                         "List VM response was not a valid list")
        vm1 = list_vm_1[0]
        vm2 = list_vm_2[0]
        self.assertEqual(vm1.state,
                         "Running",
                         msg="VM is not in Running state")
        self.assertEqual(vm2.state,
                         "Running",
                         msg="VM is not in Running state")
        vm1clusterid = filter(lambda c: c.id == vm1.hostid,
                              self.hosts)[0].clusterid
        vm2clusterid = filter(lambda c: c.id == vm2.hostid,
                              self.hosts)[0].clusterid
        if vm1clusterid == vm2clusterid:
            self.debug(
                "VMs (%s, %s) meant to be dispersed are deployed in the same cluster %s"
                % (vm1.id, vm2.id, vm1clusterid))
Exemplo n.º 32
0
    def setUpClass(cls):

        cls.api_client = super(TestVMPlacement, cls).getClsTestClient().getApiClient()
        cls.services = Services().services
        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.api_client, cls.services)
        cls.zone = get_zone(cls.api_client, cls.services)
        cls.pod = get_pod(cls.api_client, zoneid=cls.zone.id, services=cls.services)
        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

        cls.service_offering = ServiceOffering.create(cls.api_client, cls.services["service_offering"], offerha=True)
        cls._cleanup = [cls.service_offering]
        return
Exemplo n.º 33
0
    def setUpClass(cls):
        cls.api_client = super(TestVPCNetworkLBRules,
                               cls).getClsTestClient().getApiClient()
        cls.services = Services().services
        # Get Zone, Domain and templates
        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.services["virtual_machine"]["zoneid"] = cls.zone.id
        cls.services["virtual_machine"]["template"] = cls.template.id

        cls.service_offering = ServiceOffering.create(
            cls.api_client, cls.services["service_offering"])
        cls._cleanup = [cls.service_offering]
        return
Exemplo n.º 34
0
    def setUpClass(cls):

        cls.api_client = super(TestAntiAffinityRules, cls).getClsTestClient().getApiClient()
        cls.services = Services().services
        # Get Zone, Domain and templates
        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.services["virtual_machine"]["zoneid"] = cls.zone.id
        cls.services["virtual_machine"]["template"] = cls.template.id

        cls.service_offering = ServiceOffering.create(cls.api_client, cls.services["service_offering"], offerha=True)

        cls.account = Account.create(cls.api_client, cls.services["account"], domainid=cls.domain.id)
        cls._cleanup = [cls.account]
        return
Exemplo n.º 35
0
    def setUpClass(cls):
        cls.services = Services().services
        cls.apiclient = super(TestDeployVM,
                              cls).getClsTestClient().getApiClient()
        # Get Zone, Domain and templates
        domain = get_domain(cls.apiclient, cls.services)
        cls.zone = get_zone(cls.apiclient, cls.services)
        cls.services['mode'] = cls.zone.networktype

        #If local storage is enabled, alter the offerings to use localstorage
        #this step is needed for devcloud
        if cls.zone.localstorageenabled == True:
            cls.services["service_offerings"]["tiny"]["storagetype"] = 'local'
            cls.services["service_offerings"]["small"]["storagetype"] = 'local'
            cls.services["service_offerings"]["medium"][
                "storagetype"] = 'local'

        template = get_template(cls.apiclient, cls.zone.id,
                                cls.services["ostype"])
        # Set Zones and disk offerings
        cls.services["small"]["zoneid"] = cls.zone.id
        cls.services["small"]["template"] = template.id

        cls.services["medium"]["zoneid"] = cls.zone.id
        cls.services["medium"]["template"] = template.id
        cls.services["iso"]["zoneid"] = cls.zone.id

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

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

        cls.virtual_machine = VirtualMachine.create(
            cls.apiclient,
            cls.services["small"],
            accountid=cls.account.name,
            domainid=cls.account.domainid,
            serviceofferingid=cls.service_offering.id,
            mode=cls.services['mode'])

        cls.cleanup = [cls.service_offering, cls.account]
    def test_create_dynamic_compute_offering_no_memory(self):
        """ Create dynamic compute offering with only memory unspecified"""

        # Validations:
        # 1. Compute offering creation should fail

        self.services["service_offering"]["cpunumber"] = 2
        self.services["service_offering"]["cpuspeed"] = 256
        self.services["service_offering"]["memory"] = ""

        try:
            serviceOffering = ServiceOffering.create(self.api_client,
                                                 self.services["service_offering"]
                                                 )
            self.cleanup_co.append(serviceOffering)
            self.fail("Compute Offering creation succeded, it should have failed")
        except Exception:
            self.debug("Compute Offering Creation failed as expected")
        return
    def setUpClass(cls):
        cls.api_client = super(TestDomainCPULimitsConfiguration,
                               cls).getClsTestClient().getApiClient()
        cls.services = Services().services
        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.api_client, cls.services)
        cls.zone = get_zone(cls.api_client, cls.services)
        cls.services["mode"] = cls.zone.networktype
        cls.template = get_template(cls.api_client, cls.zone.id,
                                    cls.services["ostype"])

        cls.service_offering = ServiceOffering.create(
            cls.api_client, cls.services["service_offering"])

        cls.services["virtual_machine"]["zoneid"] = cls.zone.id

        cls._cleanup = [
            cls.service_offering,
        ]
        return
Exemplo n.º 38
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]
Exemplo n.º 39
0
    def setUpClass(cls):
        cloudstackTestClient = super(TestBasicOperations,cls).getClsTestClient()
        cls.api_client = cloudstackTestClient.getApiClient()

        # Fill services from the external config file
        cls.services = cloudstackTestClient.getConfigParser().parsedDict

        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.api_client, cls.services)
        cls.zone = get_zone(cls.api_client, cls.services)
        cls.mode = str(cls.zone.networktype).lower()
        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
        cls.service_offering = ServiceOffering.create(
                                            cls.api_client,
                                            cls.services["service_offering"]
                                            )
        cls._cleanup = [cls.service_offering]
        cls.services["shared_network_offering"]["specifyVlan"] = "True"
        cls.services["shared_network_offering"]["specifyIpRanges"] = "True"

        cls.shared_network_offering = CreateEnabledNetworkOffering(cls.api_client,
                                                                      cls.services["shared_network_offering"])
        cls._cleanup.append(cls.shared_network_offering)

        if cls.mode == "advanced":
            cls.isolated_network_offering = CreateEnabledNetworkOffering(cls.api_client,
                                                                      cls.services["isolated_network_offering"])
            cls._cleanup.append(cls.isolated_network_offering)
            cls.isolated_network_offering_vpc = CreateEnabledNetworkOffering(cls.api_client,
                                                    cls.services["nw_offering_isolated_vpc"])
            cls._cleanup.append(cls.isolated_network_offering_vpc)
            cls.vpc_off = VpcOffering.create(cls.api_client, cls.services["vpc_offering"])
            cls.vpc_off.update(cls.api_client, state='Enabled')
            cls._cleanup.append(cls.vpc_off)
        return
    def setUpClass(cls):

        cls.api_client = super(TestAntiAffinityRules,
                               cls).getClsTestClient().getApiClient()
        cls.services = Services().services
        # Get Zone, Domain and templates
        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.services["virtual_machine"]["zoneid"] = cls.zone.id
        cls.services["virtual_machine"]["template"] = cls.template.id

        cls.service_offering = ServiceOffering.create(
            cls.api_client, cls.services["service_offering"], offerha=True)

        cls.account = Account.create(cls.api_client,
                                     cls.services["account"],
                                     domainid=cls.domain.id)
        cls._cleanup = [cls.account]
        return
    def setUpClass(cls):

        cls.api_client = super(TestVMPlacement,
                               cls).getClsTestClient().getApiClient()
        cls.services = Services().services
        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.api_client, cls.services)
        cls.zone = get_zone(cls.api_client, cls.services)
        cls.pod = get_pod(cls.api_client,
                          zoneid=cls.zone.id,
                          services=cls.services)
        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

        cls.service_offering = ServiceOffering.create(
            cls.api_client, cls.services["service_offering"], offerha=True)
        cls._cleanup = [
            cls.service_offering,
        ]
        return
Exemplo n.º 42
0
    def test_01_create_service_offering(self):
        """Test to create service offering"""

        # Validate the following:
        # 1. createServiceOfferings should return a valid information for newly created offering
        # 2. The Cloud Database contains the valid information

        service_offering = ServiceOffering.create(self.apiclient,
                                                  self.services["off"])
        self.cleanup.append(service_offering)

        self.debug("Created service offering with ID: %s" %
                   service_offering.id)

        list_service_response = list_service_offering(self.apiclient,
                                                      id=service_offering.id)
        self.assertEqual(isinstance(list_service_response, list), True,
                         "Check list response returns a valid list")

        self.assertNotEqual(len(list_service_response), 0,
                            "Check Service offering is created")
        service_response = list_service_response[0]

        self.assertEqual(list_service_response[0].cpunumber,
                         self.services["off"]["cpunumber"],
                         "Check server id in createServiceOffering")
        self.assertEqual(list_service_response[0].cpuspeed,
                         self.services["off"]["cpuspeed"],
                         "Check cpuspeed in createServiceOffering")
        self.assertEqual(list_service_response[0].displaytext,
                         self.services["off"]["displaytext"],
                         "Check server displaytext in createServiceOfferings")
        self.assertEqual(list_service_response[0].memory,
                         self.services["off"]["memory"],
                         "Check memory in createServiceOffering")
        self.assertEqual(list_service_response[0].name,
                         self.services["off"]["name"],
                         "Check name in createServiceOffering")
        return
    def test_create_dynamic_compute_offering(self):
        """ Create dynamic compute offering with cpunumber, cpuspeed and memory
            not specified"""

        # Steps:
        # 1. Create dynamic compute offering with values for cpu number,
        #    cpu speed, memory not specified

        # Validations:
        # 1. Compute offering should be created

        self.services["service_offering"]["cpunumber"] = ""
        self.services["service_offering"]["cpuspeed"] = ""
        self.services["service_offering"]["memory"] = ""

        serviceOffering = ServiceOffering.create(self.api_client,
                                                 self.services["service_offering"]
                                                 )
        self.assertEqual(verifyComputeOfferingCreation(self.apiclient, serviceOffering.id),
                         PASS, "Compute Offering verification failed")

        self.cleanup_co.append(serviceOffering)
        return
    def test_create_normal_compute_offering(self):
        """ Create normal compute offering with non zero values for cpu,
            cpu number and memory"""

        # Steps:
        # 1. Create normal compute offering with non zero values for cpu number,
        #    cpu speed, memory

        # Validations:
        # 1. Compute offering should be created

        self.services["service_offering"]["cpunumber"] = 2
        self.services["service_offering"]["cpuspeed"] = 256
        self.services["service_offering"]["memory"] = 128

        serviceOffering = ServiceOffering.create(self.api_client,
                                                 self.services["service_offering"]
                                                 )
        self.assertEqual(verifyComputeOfferingCreation(self.apiclient, serviceOffering.id),
                         PASS, "Compute Offering verification failed")

        self.cleanup_co.append(serviceOffering)
        return
Exemplo n.º 45
0
    def test_01_multiple_child_domains(self):
        """Test CPU limits with multiple child domains"""

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

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

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

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

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

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

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

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

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

        self.debug(resource_count_cadmin_1)

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

        self.debug(resource_count_cadmin_2)

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

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

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

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

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

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

        self.debug(resource_count_cadmin_2)
        self.assertEqual(resource_count_cadmin_2, 0, "Resource count for %s should be 0" % get_resource_type(resource_id=8))#CPU
        return
Exemplo n.º 46
0
    def setUpClass(cls):
        cls._cleanup = []
        cls.api_client = super(TestVMOwnership,
                               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

        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}

        # Create disk offerings.
        try:
            cls.disk_offering = DiskOffering.create(cls.api_client,
                                                    cls.services["disk_offering"])
            # Create service offerings.
            cls.service_offering = ServiceOffering.create(cls.api_client,
                                                          cls.services["service_offering"])
            # Cleanup
            cls._cleanup = [cls.service_offering]
            # Create domain, account, user, project and volumes.
            cls.domain_account_user1   = create_domain_account_user()
            cls.domain_account_user2   = create_domain_account_user()
            cls.sdomain_account_user1  = create_domain_account_user(cls.domain_account_user1['domain'])
            cls.sdomain_account_user2  = create_domain_account_user(cls.domain_account_user2['domain'])
            cls.ssdomain_account_user2 = create_domain_account_user(cls.sdomain_account_user2['domain'])
        except Exception as e:
          raise e
        return
Exemplo n.º 47
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"])

        self.hosts = []
        suitablecluster = None
        clusters = Cluster.list(self.apiclient)
        self.assertTrue(isinstance(clusters, list) and len(clusters) > 0, msg = "No clusters found")
        for cluster in clusters:
            self.hosts = Host.list(self.apiclient, clusterid=cluster.id, type='Routing')
            if isinstance(self.hosts, list) and len(self.hosts) >= 2:
                suitablecluster = cluster
                break
        self.assertTrue(isinstance(self.hosts, list) and len(self.hosts) >= 2, msg = "Atleast 2 hosts required in cluster for VM HA test")
        #update host tags
        for host in self.hosts:
            Host.update(self.apiclient, id=host.id, hosttags=self.testdata["service_offering"]["hasmall"]["hosttags"])

        #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"]["hasmall"]
        )
        #deploy ha vm
        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.assertTrue(isinstance(list_vms, list) and len(list_vms) == 1, msg = "List VM response was empty")
        self.virtual_machine = list_vms[0]

        self.mock_checkhealth = SimulatorMock.create(
            apiclient=self.apiclient,
            command="CheckHealthCommand",
            zoneid=suitablecluster.zoneid,
            podid=suitablecluster.podid,
            clusterid=suitablecluster.id,
            hostid=self.virtual_machine.hostid,
            value="result:fail")
        self.mock_ping = SimulatorMock.create(
            apiclient=self.apiclient,
            command="PingCommand",
            zoneid=suitablecluster.zoneid,
            podid=suitablecluster.podid,
            clusterid=suitablecluster.id,
            hostid=self.virtual_machine.hostid,
            value="result:fail")
        self.mock_checkvirtualmachine = SimulatorMock.create(
            apiclient=self.apiclient,
            command="CheckVirtualMachineCommand",
            zoneid=suitablecluster.zoneid,
            podid=suitablecluster.podid,
            clusterid=suitablecluster.id,
            hostid=self.virtual_machine.hostid,
            value="result:fail")
        self.mock_pingtest = SimulatorMock.create(
            apiclient=self.apiclient,
            command="PingTestCommand",
            zoneid=suitablecluster.zoneid,
            podid=suitablecluster.podid,
            value="result:fail")
        self.mock_checkonhost_list = []
        for host in self.hosts:
            if host.id != self.virtual_machine.hostid:
                self.mock_checkonhost_list.append(SimulatorMock.create(
                    apiclient=self.apiclient,
                    command="CheckOnHostCommand",
                    zoneid=suitablecluster.zoneid,
                    podid=suitablecluster.podid,
                    clusterid=suitablecluster.id,
                    hostid=host.id,
                    value="result:fail"))
        #build cleanup list
        self.cleanup = [
            self.service_offering,
            self.account,
            self.mock_checkhealth,
            self.mock_ping,
            self.mock_checkvirtualmachine,
            self.mock_pingtest
        ]
        self.cleanup = self.cleanup + self.mock_checkonhost_list
Exemplo n.º 48
0
    def test_04_deploy_multiple_vm_with_multiple_core(self):
        """Test Deploy multiple VM with 4 core CPU & verify the usage"""

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            self.assertEqual(resource_count_after_migrate, resource_count_after_delete,
                "Resource count should not change after migrating the instance")
        return
Exemplo n.º 49
0
    def test_01_change_service_offering(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. Upgrade and downgrade service offering
        # 4. Resource count should list properly for the domain

        self.debug("Setting up account and domain hierarchy")
        self.setupAccounts()
        users =  { self.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("Stopping instance: %s" % vm.name)
            try:
                vm.stop(self.apiclient)
            except Exception as e:
                self.fail("Failed to stop instance: %s" % e)
            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(account_list,
                              list,
                              "List Accounts should return a valid response"
                              )
            resource_count_after_stop = account_list[0].memorytotal

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

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

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

            try:
                vm.change_service_offering(self.apiclient,
                                serviceOfferingId=self.service_offering_7gb.id)
            except Exception as e:
                self.fail("Failed to change service offering of vm %s - %s" %
                                                                (vm.name, 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_upgrade = account_list[0].memorytotal

            self.debug(resource_count_after_upgrade)

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

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

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

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

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

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

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

        return
Exemplo n.º 50
0
    def test_01_change_service_offering(self):
        """Test Deploy VM with specified RAM & verify the usage"""

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

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

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

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

            api_client = self.testClient.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("Stopping instance: %s" % vm.name)
            try:
                vm.stop(self.apiclient)
            except Exception as e:
                self.fail("Failed to stop instance: %s" % e)
            account_list = Account.list(self.apiclient, id=self.account.id)
            self.assertIsInstance(
                account_list, list,
                "List Accounts should return a valid response")
            resource_count_after_stop = account_list[0].memorytotal

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

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

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

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

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

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

            self.debug(resource_count_after_upgrade)

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

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

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

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

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

            resource_count_after_downgrade = account_list[0].memorytotal

            self.debug(resource_count_after_downgrade)

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

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

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

        return
    def test_vm_creation_in_fully_automated_mode(self):
        """ Test VM Creation in  automation mode = Fully automated
            This test requires following preconditions:
                - DRS Cluster is configured in "Fully automated" mode
        """
        # Validate the following
        # 1. Create a new VM in a host which is almost fully utilized
        # 2 Automatically places VM on the other host
        # 3. VM state is running after deployment

        hosts = Host.list(self.apiclient,
                          zoneid=self.zone.id,
                          resourcestate='Enabled',
                          type='Routing')
        self.assertEqual(isinstance(hosts, list), True,
                         "List hosts should return valid host response")
        self.assertGreaterEqual(
            len(hosts), 2, "There must be two hosts present in a cluster")

        host_1 = hosts[0]

        #Convert available memory( Keep some margin) into MBs and assign to service offering
        self.services["service_offering_max_memory"]["memory"] = int(
            (int(hosts[0].memorytotal) - int(hosts[0].memoryused)) / 1048576 -
            1024)

        self.debug("max memory: %s" %
                   self.services["service_offering_max_memory"]["memory"])

        service_offering_max_memory = ServiceOffering.create(
            self.apiclient, self.services["service_offering_max_memory"])

        VirtualMachine.create(self.apiclient,
                              self.services["virtual_machine"],
                              accountid=self.account.name,
                              domainid=self.account.domainid,
                              serviceofferingid=service_offering_max_memory.id,
                              hostid=host_1.id)

        # Host 1 has only 1024 MB memory available now after deploying the instance
        # We are trying to deploy an instance with 2048 MB memory, this should automatically
        # get deployed on other host which has the enough capacity

        self.debug(
            "Trying to deploy instance with memory requirement more than that is available on\
                     the first host")

        self.debug("Deploying VM in account: %s" % self.account.name)
        # Spawn an instance in that network
        virtual_machine = VirtualMachine.create(
            self.apiclient,
            self.services["virtual_machine"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id)
        vms = VirtualMachine.list(self.apiclient,
                                  id=virtual_machine.id,
                                  listall=True)
        self.assertEqual(
            isinstance(vms, list), True,
            "List VMs should return valid response for deployed VM")
        self.assertNotEqual(
            len(vms), 0,
            "List VMs should return valid response for deployed VM")
        vm = vms[0]
        self.assertEqual(vm.state, "Running",
                         "Deployed VM should be in RUnning state")
        self.assertNotEqual(
            vm.hostid, host_1.id,
            "Host Ids of two should not match as one host is full")

        self.debug(
            "The host ids of two virtual machines are different as expected\
                    they are %s and %s" % (vm.hostid, host_1.id))
        return
Exemplo n.º 52
0
    def setUpClass(cls):
        cls._cleanup = []
        cls.api_client = super(TestVMOwnership,
                               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

        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
            }

        # Create disk offerings.
        try:
            cls.disk_offering = DiskOffering.create(
                cls.api_client, cls.services["disk_offering"])
            # Create service offerings.
            cls.service_offering = ServiceOffering.create(
                cls.api_client, cls.services["service_offering"])
            # Cleanup
            cls._cleanup.append(cls.service_offering)
            # Create domain, account, user, project and volumes.
            cls.domain_account_user1 = create_domain_account_user()
            cls.domain_account_user2 = create_domain_account_user()
            cls.sdomain_account_user1 = create_domain_account_user(
                cls.domain_account_user1['domain'])
            cls.sdomain_account_user2 = create_domain_account_user(
                cls.domain_account_user2['domain'])
            cls.ssdomain_account_user2 = create_domain_account_user(
                cls.sdomain_account_user2['domain'])
        except Exception as e:
            raise e
        return
Exemplo n.º 53
0
    def test_04_deploy_multiple_vm_with_multiple_core(self):
        """Test Deploy multiple VM with 4 core CPU & verify the usage"""

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

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

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

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

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

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

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

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

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

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

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

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

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

            host = find_suitable_host(self.apiclient, vm_2)
            self.debug("Migrating instance: %s to host: %s" %
                       (vm_2.name, host.name))
            try:
                vm_2.migrate(self.apiclient, host.id)
            except Exception as e:
                self.fail("Failed to migrate instance: %s" % e)

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

            self.assertEqual(
                resource_count_after_migrate, resource_count_after_delete,
                "Resource count should not change after migrating the instance"
            )
        return
Exemplo n.º 54
0
    def test_01_multiple_child_domains(self):
        """Test CPU limits with multiple child domains"""

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

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

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

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

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

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

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

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

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

        self.debug(resource_count_cadmin_1)

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

        self.debug(resource_count_cadmin_2)

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

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

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

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

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

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

        self.debug(resource_count_cadmin_2)
        self.assertEqual(resource_count_cadmin_2, 0,
                         "Resource count for %s should be 0" %
                         get_resource_type(resource_id=8))  #CPU
        return
    def test_04_deploy_multiple_vm_with_multiple_cpus(self):
        """Test Deploy multiple VM with 4 core CPU & verify the usage"""
        #keep the configuration value - max.account.cpus number = 16
        # 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

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

        self.debug("Setting up account and domain hierarchy")
        self.setupAccounts()
        users = {
            self.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

            cpu_account_gc = Resources.list(
                self.apiclient,
                resourcetype=8,  #CPU
                account=self.account.name,
                domainid=self.domain.id)

            if cpu_account_gc[0].max != 16:
                self.skipTest(
                    "This test case requires configuration value max.account.cpus to be 16"
                )

            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_1 = self.createInstance(service_off=self.service_offering,
                                       api_client=api_client)
            vm_2 = self.createInstance(service_off=self.service_offering,
                                       api_client=api_client)
            self.createInstance(service_off=self.service_offering,
                                api_client=api_client)
            self.createInstance(service_off=self.service_offering,
                                api_client=api_client)

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

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

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

            self.assertEqual(
                resource_count, expected_resource_count,
                "Initial resource count should 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].cputotal

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

            self.assertEqual(
                resource_count_after_delete, expected_resource_count,
                "Resource count should be less than before after deleting the instance"
            )

            host = find_suitable_host(self.apiclient, vm_2)
            self.debug("Migrating instance: %s to host: %s" %
                       (vm_2.name, host.name))
            try:
                vm_2.migrate(self.apiclient, host.id)
            except Exception as e:
                self.fail("Failed to migrate instance: %s" % e)

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

            self.debug(resource_count_after_migrate)
            self.assertEqual(
                resource_count_after_delete, resource_count_after_migrate,
                "Resource count should be same after migrating the instance")