def test_06_volumes_per_project(self):
        """Test Volumes limit per project
        """
        # Validate the following
        # 1. set max no of volume per project to 1.
        # 2. Create 1 VM in this project
        # 4. Try to Create another VM in the project. It should give the user
        #    an appropriate error that Volume limit is exhausted and an alert
        #    should be generated.

        if self.hypervisor.lower() == 'lxc':
            if not find_storage_pool_type(self.apiclient, storagetype='rbd'):
                self.skipTest(
                    "RBD storage type is required for data volumes for LXC")
        self.project_1 = Project.create(self.api_client,
                                        self.services["project"],
                                        account=self.account.name,
                                        domainid=self.account.domainid)
        self.cleanup.append(self.project_1)

        self.debug("Updating volume resource limits for project: %s" %
                   self.project_1.id)
        # Set usage_vm=1 for Account 1
        update_resource_limit(
            self.apiclient,
            2,  # Volume
            max=1,
            projectid=self.project_1.id)

        self.debug("Deploying VM for project: %s" % self.project_1.id)
        virtual_machine_1 = VirtualMachine.create(
            self.apiclient,
            self.services["server"],
            templateid=self.template.id,
            serviceofferingid=self.service_offering.id,
            projectid=self.project_1.id)
        # Verify VM state
        self.assertEqual(virtual_machine_1.state, 'Running',
                         "Check VM state is Running or not")
        self.cleanup.append(virtual_machine_1)
        networks = Network.list(self.apiclient,
                                projectid=self.project_1.id,
                                listall=True)
        for network in networks:
            self.cleanup.insert(1, Network(network.__dict__))

        # Exception should be raised for second volume
        with self.assertRaises(Exception):
            Volume.create(self.apiclient,
                          self.services["volume"],
                          zoneid=self.zone.id,
                          diskofferingid=self.disk_offering.id,
                          projectid=self.project_1.id)
        return
    def test_01_nuage_Domain_Template_selection_per_VPC(self):
        """Test Nuage VSP Domain Template selection per VPC
        """

        # 1. Associate an invalid/non-existing Nuage VSP domain template to a
        #    VPC; verify that the association fails.
        # 2. Associate a valid/existing pre-configured Nuage VSP domain
        #    template to a VPC; verify that the association is successful, VPC
        #    networks (domains) are instantiated from the associated domain
        #    template in VSD.
        # 3. Verify that the state of such VPC networks (domains) in VSD is not
        #    affected with their restarts in CloudStack with and without
        #    cleanup.
        # 4. Verify that multiple associations (update) of domain templates to
        #    a VPC goes through till the creation of its first VPC network
        #    (tier).
        # 5. Verify that the VPC networks (domains) creation fails in VSD when
        #    the associated domain templates to their corresponding VPCs have
        #    been deleted in VSD.
        # 6. Verify that the VPC networks (domains) creation fails in VSD when
        #    an acl list is associated with them after their corresponding VPCs
        #    have been associated with a pre-configured Nuage VSP domain
        #    template.
        # 7. Delete all the created objects (cleanup).

        # Creating VPC
        vpc_1 = self.create_vpc(self.vpc_offering, cidr='10.1.0.0/16')

        # Associating pre-configured Nuage VSP Domain Template to VPC
        with self.assertRaises(Exception):
            self.validate_NuageVspDomainTemplate("invalid_domain_template")
        self.debug("There is no domain template with name "
                   "invalid_domain_template in VSD")
        with self.assertRaises(Exception):
            self.associate_NuageVspDomainTemplate("invalid_domain_template",
                                                  vpc_1)
        self.debug("Association fails as there is no domain template with "
                   "name invalid_domain_template in VSD")
        self.associate_NuageVspDomainTemplate(self.domain_template_list[0],
                                              vpc_1)

        # Creating VPC networks (tiers)
        vpc_1_tier_1 = self.create_Network(self.network_offering,
                                           gateway='10.1.3.1',
                                           vpc=vpc_1)
        vpc_1_tier_2 = self.create_Network(self.network_offering,
                                           gateway='10.1.4.1',
                                           vpc=vpc_1)

        # VSD verification
        self.verify_vsd_network(
            self.account.domainid,
            vpc_1_tier_1,
            vpc_1,
            domain_template_name=self.domain_template_list[0])
        self.verify_vsd_network(
            self.account.domainid,
            vpc_1_tier_2,
            vpc_1,
            domain_template_name=self.domain_template_list[0])

        # Restart VPC networks (tiers) without cleanup
        Network.restart(vpc_1_tier_1, self.api_client, cleanup=False)
        Network.restart(vpc_1_tier_2, self.api_client, cleanup=False)

        # VSD verification
        self.verify_vsd_network(
            self.account.domainid,
            vpc_1_tier_1,
            vpc_1,
            domain_template_name=self.domain_template_list[0])
        self.verify_vsd_network(
            self.account.domainid,
            vpc_1_tier_2,
            vpc_1,
            domain_template_name=self.domain_template_list[0])

        # Restart VPC networks (tiers) with cleanup
        Network.restart(vpc_1_tier_1, self.api_client, cleanup=True)
        Network.restart(vpc_1_tier_2, self.api_client, cleanup=True)

        # VSD verification
        self.verify_vsd_network(
            self.account.domainid,
            vpc_1_tier_1,
            vpc_1,
            domain_template_name=self.domain_template_list[0])
        self.verify_vsd_network(
            self.account.domainid,
            vpc_1_tier_2,
            vpc_1,
            domain_template_name=self.domain_template_list[0])

        # Restart VPC without cleanup
        self.restart_Vpc(vpc_1, cleanup=False)

        # VSD verification
        self.verify_vsd_network(
            self.account.domainid,
            vpc_1_tier_1,
            vpc_1,
            domain_template_name=self.domain_template_list[0])
        self.verify_vsd_network(
            self.account.domainid,
            vpc_1_tier_2,
            vpc_1,
            domain_template_name=self.domain_template_list[0])

        # Restart VPC with cleanup
        self.restart_Vpc(vpc_1, cleanup=True)

        # VSD verification
        self.verify_vsd_network(
            self.account.domainid,
            vpc_1_tier_1,
            vpc_1,
            domain_template_name=self.domain_template_list[0])
        self.verify_vsd_network(
            self.account.domainid,
            vpc_1_tier_2,
            vpc_1,
            domain_template_name=self.domain_template_list[0])

        # Creating VPC
        vpc_2 = self.create_vpc(self.vpc_offering, cidr='10.1.0.0/16')

        # Associating pre-configured Nuage VSP Domain Template to VPC
        self.validate_NuageVspDomainTemplate(self.domain_template_list[0])
        self.associate_NuageVspDomainTemplate(self.domain_template_list[0],
                                              vpc_2)
        self.validate_NuageVspDomainTemplate(self.domain_template_list[1])
        self.associate_NuageVspDomainTemplate(self.domain_template_list[1],
                                              vpc_2)

        # Deleting the associated pre-configured Nuage VSP domain template
        enterprise = self._session.user.enterprises.get_first(
            filter="externalID BEGINSWITH '%s'" % self.account.domainid)
        domain_template = enterprise.domain_templates.get_first(
            filter="name is '%s'" % self.domain_template_list[1])
        domain_template.delete()

        # Creating VPC networks (tiers)
        with self.assertRaises(Exception):
            self.create_Network(self.network_offering,
                                gateway='10.1.1.1',
                                vpc=vpc_2)
        self.debug("Corresponding domain creation in VSD fails, but VPC "
                   "(tier) network gets created on CloudStack as the "
                   "associated pre-configured Nuage VSP domain template is no "
                   "longer existing in VSD")
        for vpc_2_tier in Network.list(self.api_client, vpcid=vpc_2.id):
            Network(vpc_2_tier.__dict__).delete(self.api_client)

        # Re-creating the associated pre-configured Nuage VSP domain template
        new_domain_template = self.vsdk.NUDomainTemplate(
            name=self.domain_template_list[1],
            description=self.domain_template_list[1])
        enterprise = self._session.user.enterprises.get_first(
            filter="externalID BEGINSWITH '%s'" % self.account.domainid)
        enterprise.create_child(new_domain_template)
        self.cleanup_domain_templates.append(
            enterprise.domain_templates.get_first(
                filter="name is '%s'" % self.domain_template_list[1]))

        vpc_2_tier_1 = self.create_Network(self.network_offering,
                                           gateway='10.1.2.1',
                                           vpc=vpc_2)
        vpc_2_tier_2 = self.create_Network(self.network_offering,
                                           gateway='10.1.3.1',
                                           vpc=vpc_2)

        # VSD verification
        self.verify_vsd_network(
            self.account.domainid,
            vpc_2_tier_1,
            vpc_2,
            domain_template_name=self.domain_template_list[1])
        self.verify_vsd_network(
            self.account.domainid,
            vpc_2_tier_2,
            vpc_2,
            domain_template_name=self.domain_template_list[1])

        # Creating VPC
        vpc_3 = self.create_vpc(self.vpc_offering, cidr='10.1.0.0/16')

        # Associating pre-configured Nuage VSP Domain Template to VPC
        self.validate_NuageVspDomainTemplate(self.domain_template_list[0])
        self.associate_NuageVspDomainTemplate(self.domain_template_list[0],
                                              vpc_3)

        # Creating an ACL list and an ACL item
        acl_list = self.create_NetworkAclList(name="acl",
                                              description="acl",
                                              vpc=vpc_3)
        self.create_NetworkAclRule(self.test_data["ingress_rule"],
                                   acl_list=acl_list)

        # Creating VPC networks (tiers)
        with self.assertRaises(Exception):
            self.create_Network(self.network_offering,
                                gateway='10.1.1.1',
                                vpc=vpc_3,
                                acl_list=acl_list)
        self.debug("Corresponding domain creation in VSD fails, but VPC "
                   "(tier) network gets created on CloudStack as creation of "
                   "Network ACLs from CloudStack is not supported when the "
                   "VPC is associated with a Nuage VSP pre-configured domain "
                   "template")
        for vpc_3_tier in Network.list(self.api_client, vpcid=vpc_3.id):
            Network(vpc_3_tier.__dict__).delete(self.api_client)

        vpc_3_tier_1 = self.create_Network(self.network_offering,
                                           gateway='10.1.2.1',
                                           vpc=vpc_3)
        vpc_3_tier_2 = self.create_Network(self.network_offering,
                                           gateway='10.1.3.1',
                                           vpc=vpc_3)

        # VSD verification
        self.verify_vsd_network(
            self.account.domainid,
            vpc_3_tier_1,
            vpc_3,
            domain_template_name=self.domain_template_list[0])
        self.verify_vsd_network(
            self.account.domainid,
            vpc_3_tier_2,
            vpc_3,
            domain_template_name=self.domain_template_list[0])

        # Creating VPC and VPC network (tier)
        vpc = self.create_vpc(self.vpc_offering, cidr='10.1.0.0/16')
        vpc_tier = self.create_Network(self.network_offering, vpc=vpc)

        # VSD verification
        self.verify_vsd_network(self.account.domainid, vpc_tier, vpc)

        # Associating pre-configured Nuage VSP Domain Template to VPC
        self.validate_NuageVspDomainTemplate(self.domain_template_list[0])
        with self.assertRaises(Exception):
            self.associate_NuageVspDomainTemplate(self.domain_template_list[0],
                                                  vpc)
        self.debug("Association fails as the corresponding domain and domain "
                   "templates are already created in VSD for the VPC vpc")
示例#3
0
 def get_network(self, name=None, id=None):
     return Network(
         get_network(api_client=self.api_client, name=name, id=id).__dict__)
    def test_07_templates_per_project(self):
        """Test Templates limit per project
        """
        # 1. set max no of templates per project to 1.
        # 2. Create a template in this project. Both template should be in
        #    ready state
        # 3. Try create 2nd template in the project. It should give the user
        #    appropriate error and an alert should be generated.

        # Reset the volume limits
        update_resource_limit(
            self.apiclient,
            2,  # Volume
            max=5,
            projectid=self.project.id)
        self.debug("Updating template resource limits for domain: %s" %
                   self.account.domainid)
        # Set usage_vm=1 for Account 1
        update_resource_limit(
            self.apiclient,
            4,  # Template
            max=1,
            projectid=self.project.id)

        # Register the First Template in the project
        self.debug("Register the First Template in the project")
        builtin_info = get_builtin_template_info(self.apiclient, self.zone.id)
        self.services["template"]["url"] = builtin_info[0]
        self.services["template"]["hypervisor"] = builtin_info[1]
        self.services["template"]["format"] = builtin_info[2]

        # Register new template
        template = Template.register(self.userapiclient,
                                     self.services["template"],
                                     zoneid=self.zone.id,
                                     projectid=self.project.id)
        self.debug("Registered a template of format: %s with ID: %s" %
                   (self.services["template"]["format"], template.id))
        self.cleanup.append(template)

        # Wait for template status to be changed across
        time.sleep(self.services["sleep"])
        timeout = self.services["timeout"]
        while True:
            list_template_response = Template.list(
                self.apiclient,
                templatefilter='all',
                id=template.id,
                zoneid=self.zone.id,
                projectid=self.project.id,
            )
            if list_template_response[0].isready is True:
                break
            elif timeout == 0:
                raise Exception("Template state is not ready, it is %s" %
                                list_template_response[0].isready)

            time.sleep(self.services["sleep"])
            timeout = timeout - 1

        #Verify template response to check whether template added successfully
        self.assertEqual(isinstance(list_template_response, list), True,
                         "Check for list template response return valid data")

        self.assertNotEqual(len(list_template_response), 0,
                            "Check template available in List Templates")

        template_response = list_template_response[0]
        self.assertEqual(
            template_response.isready, True,
            "Template state is not ready, it is %s" %
            template_response.isready)

        # Exception should be raised for second template
        with self.assertRaises(Exception):
            Template.register(self.userapiclient,
                              self.services["template"],
                              zoneid=self.zone.id,
                              projectid=self.project.id)
        networks = Network.list(self.apiclient,
                                projectid=self.project.id,
                                listall=True)
        for network in networks:
            self.cleanup.append(Network(network.__dict__))

        return