def test_deployvm_multinic(self):
        """Test userdata update when non default nic is without userdata for deploy and update
        """

        self.userdata = base64.b64encode(self.userdata)

        network1 = Network.create(
            self.apiclient,
            self.test_data["isolated_network"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            networkofferingid=self.network_offering_all.id,
            zoneid=self.zone.id,
        )

        self.test_data["network_without_acl"]["netmask"] = "255.255.255.128"

        network2 = Network.create(
            self.apiclient,
            self.test_data["network_without_acl"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            networkofferingid=self.network_offering_nouserdata.id,
            gateway="10.2.1.1",
            zoneid=self.zone.id,
        )

        deployVmResponse = VirtualMachine.create(
            self.apiclient,
            services=self.test_data["virtual_machine_userdata"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
            networkids=[str(network1.id), str(network2.id)],
            templateid=self.template.id,
            zoneid=self.zone.id,
        )

        vms = list_virtual_machines(
            self.apiclient, account=self.account.name, domainid=self.account.domainid, id=deployVmResponse.id
        )
        self.assert_(len(vms) > 0, "There are no Vms deployed in the account %s" % self.account.name)
        vm = vms[0]
        self.assert_(vm.id == str(deployVmResponse.id), "Vm deployed is different from the test")
        self.assert_(vm.state == "Running", "VM is not in Running state")

        try:
            updateresponse = deployVmResponse.update(self.apiclient, userdata=self.userdata)
        except Exception as e:
            self.fail("Failed to update userdata: %s" % e)

        self.debug("virtual machine update response is: %s" % updateresponse)
    def create_network(self, net_offerring, vpc_id, gateway='10.1.1.1'):
        try:
            self.logger.debug('Create NetworkOffering')
            net_offerring["name"] = "NET_OFF-" + str(gateway)
            nw_off = NetworkOffering.create(
                self.apiclient,
                net_offerring,
                conservemode=False)

            nw_off.update(self.apiclient, state='Enabled')
            self.logger.debug('Created and Enabled NetworkOffering')

            self.services["network"]["name"] = "NETWORK-" + str(gateway)
            self.logger.debug('Adding Network=%s to VPC ID %s' % (self.services["network"], vpc_id))
            obj_network = Network.create(
                self.apiclient,
                self.services["network"],
                accountid=self.account.name,
                domainid=self.account.domainid,
                networkofferingid=nw_off.id,
                zoneid=self.zone.id,
                gateway=gateway,
                vpcid=vpc_id)

            self.logger.debug("Created network with ID: %s" % obj_network.id)
        except Exception, e:
            raise Exception('Unable to create a Network with offering=%s because of %s ' % (net_offerring, e))
    def test_02_dedicated_another_network(self):
        # Create network
        self.network = Network.create(
            self.apiclient,
            self.services["network"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            networkofferingid=self.network_offering.id,
            zoneid=self.zone.id
        )
        self.debug("Created network: %s" % self.network.id)

        self.debug("Trying VM deploy with network created on account: %s" % self.account.name)

        with self.assertRaises(Exception):
            self.virtual_machine = VirtualMachine.create(
            self.apiclient,
            self.services["small"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            networkids=self.network.id,
            zoneid=self.zone.id,
            serviceofferingid=self.service_offering.id
            )
        return
    def create_network(self, net_offerring, gateway='10.1.1.1',vpc=None):
        try:
                self.debug('Create NetworkOffering')
                net_offerring["name"] = "NET_OFF-" + str(gateway)
                nw_off = NetworkOffering.create(self.apiclient,
                                                        net_offerring,
                                                        conservemode=False
                                                        )
                # Enable Network offering
                nw_off.update(self.apiclient, state='Enabled')
                self._cleanup.append(nw_off)
                self.debug('Created and Enabled NetworkOffering')

                self.services["network"]["name"] = "NETWORK-" + str(gateway)
                self.debug('Adding Network=%s' % self.services["network"])
                obj_network = Network.create(self.apiclient,
                                                self.services["network"],
                                                accountid=self.account.name,
                                                domainid=self.account.domainid,
                                                networkofferingid=nw_off.id,
                                                zoneid=self.zone.id,
                                                gateway=gateway,
                                                vpcid=vpc.id if vpc else self.vpc.id
                                                )
                self.debug("Created network with ID: %s" % obj_network.id)
                return obj_network
        except Exception, e:
                self.fail('Unable to create a Network with offering=%s because of %s ' % (net_offerring, e))
    def test_vm_nic_adapter_vmxnet3(self):
        """

        # 1. Register a template for VMware with nicAdapter vmxnet3
        # 2. Deploy a VM using this template
        # 3. Create an isolated network
        # 4. Add network to VM
        # 5. Verify that the NIC adapter for VM for both the nics
        #    is vmxnet3
        """

        if self.hypervisor.lower() not in ["vmware"]:
            self.skipTest("This test case is written specifically\
                    for Vmware hypervisor")

        # Register a private template in the account with nic adapter vmxnet3
        template = Template.register(
            self.userapiclient,
            self.testdata["configurableData"]["vmxnet3template"],
            zoneid=self.zone.id,
            account=self.account.name,
            domainid=self.account.domainid,
            details=[{"nicAdapter": self.testdata["configurableData"]["vmxnet3template"]["nicadapter"]}]
        )
        self.cleanup.append(template)
        template.download(self.apiclient)

        templates = Template.list(
            self.userapiclient,
            listall=True,
            id=template.id,
            templatefilter="self")

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

        self.testdata["virtual_machine"]["zoneid"] = self.zone.id
        self.testdata["virtual_machine"]["template"] = template.id

        virtual_machine = VirtualMachine.create(
            self.apiclient,
            self.testdata["virtual_machine"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id)

        isolated_network = Network.create(
            self.apiclient,
            self.testdata["isolated_network"],
            self.account.name,
            self.account.domainid,
            networkofferingid=self.isolated_network_offering.id)

        virtual_machine.add_nic(self.apiclient, isolated_network.id)

        # TODO: Add steps to check the Nic Adapter type in VCenter
        # using VCenter APIs
        return
Пример #6
0
    def create_network_tier(self, name, vpcid, gateway, network_offering):
        self.services["network"]["name"] = name
        self.services["network"]["displaytext"] = name

        default_acl = NetworkACLList.list(self.apiclient, name="default_allow")[0]

        try:
            network = Network.create(
                apiclient=self.apiclient,
                services=self.services["network"],
                accountid=self.account.name,
                domainid=self.domain.id,
                networkofferingid=network_offering.id,
                zoneid=self.zone.id,
                vpcid=vpcid,
                gateway=gateway,
                netmask=self.services["network"]["netmask"],
                aclid=default_acl.id
            )

            self.assertIsNotNone(network, "Network failed to create")
            self.logger.debug(
                "Created network %s in VPC %s" % (network.id, vpcid))

            self.cleanup.insert(0, network)
            return network

        except Exception as e:
            raise Exception("Create network failed: %s" % e)
Пример #7
0
    def test_03_supported_policies_by_network(self):
        """Test listnetworks response to check supported stickiness policies"""

        # Validate the following
        # 1. List networks for the account in advance network mode
        # 2. List of supported sticky methods should be present under
        #    SupportedStickinessMethods tag

        self.debug("List networks for account: %s" % self.account.name)
        networks = Network.list(self.apiclient, account=self.account.name, domainid=self.account.domainid, listall=True)

        self.assertIsInstance(networks, list, "List network should return a valid response")
        network = networks[0]
        self.debug("Network: %s" % network)
        self.assertEqual(
            hasattr(network, "SupportedStickinessMethods"), True, "Network should have SupportedStickinessMethods param"
        )

        self.assertEqual(hasattr(network, "LbCookie"), True, "Network should have LbCookie LB method param")

        self.assertEqual(hasattr(network, "AppCookie"), True, "Network should have AppCookie LB method param")

        self.assertEqual(hasattr(network, "SourceBased"), True, "Network should have SourceBased LB method param")

        return
Пример #8
0
    def create_network(self, net_offerring, gateway='10.1.1.1', vpc=None, nr_vms=2, mark_net_cleanup=True):
        if not nr_vms or nr_vms <= 0:
            self.fail("At least 1 VM has to be created. You informed nr_vms < 1")
        try:
            self.logger.debug('Create NetworkOffering')
            net_offerring["name"] = "NET_OFF-" + str(gateway)
            nw_off = NetworkOffering.create(
                self.apiclient,
                net_offerring,
                conservemode=False)

            nw_off.update(self.apiclient, state='Enabled')

            self.logger.debug('Created and Enabled NetworkOffering')

            self.services["network"]["name"] = "NETWORK-" + str(gateway)
            self.logger.debug('Adding Network=%s' % self.services["network"])
            obj_network = Network.create(
                self.apiclient,
                self.services["network"],
                accountid=self.account.name,
                domainid=self.account.domainid,
                networkofferingid=nw_off.id,
                zoneid=self.zone.id,
                gateway=gateway,
                vpcid=vpc.id if vpc else self.vpc.id
            )

            self.logger.debug("Created network with ID: %s" % obj_network.id)
        except Exception, e:
            self.fail('Unable to create a Network with offering=%s because of %s ' % (net_offerring, e))
    def create_vm(self, pfrule=False, egress_policy=True, RR=False):
        self.create_network_offering(egress_policy, RR)
        # Creating network using the network offering created
        self.debug("Creating network with network offering: %s" % self.network_offering.id)
        self.network = Network.create(
            self.apiclient,
            self.services["network"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            networkofferingid=self.network_offering.id,
            zoneid=self.zone.id,
        )
        self.debug("Created network with ID: %s" % self.network.id)
        self.debug("Deploying instance in the account: %s" % self.account.name)

        project = None
        self.virtual_machine = VirtualMachine.create(
            self.apiclient,
            self.services["virtual_machine"],
            accountid=self.account.name,
            domainid=self.domain.id,
            serviceofferingid=self.service_offering.id,
            mode=self.zone.networktype if pfrule else "basic",
            networkids=[str(self.network.id)],
            projectid=project.id if project else None,
        )
        self.debug("Deployed instance %s in account: %s" % (self.virtual_machine.id, self.account.name))

        # Checking if VM is running or not, in case it is deployed in error state, test case fails
        self.vm_list = list_virtual_machines(self.apiclient, id=self.virtual_machine.id)

        self.assertEqual(validateList(self.vm_list)[0], PASS, "vm list validation failed, vm list is %s" % self.vm_list)
        self.assertEqual(
            str(self.vm_list[0].state).lower(),
            "running",
            "VM state should be running, it is %s" % self.vm_list[0].state,
        )

        self.public_ip = PublicIPAddress.create(
            self.apiclient,
            accountid=self.account.name,
            zoneid=self.zone.id,
            domainid=self.account.domainid,
            networkid=self.network.id,
        )

        # Open up firewall port for SSH
        FireWallRule.create(
            self.apiclient,
            ipaddressid=self.public_ip.ipaddress.id,
            protocol=self.services["natrule"]["protocol"],
            cidrlist=["0.0.0.0/0"],
            startport=self.services["natrule"]["publicport"],
            endport=self.services["natrule"]["publicport"],
        )

        self.debug("Creating NAT rule for VM ID: %s" % self.virtual_machine.id)
        # Create NAT rule
        NATRule.create(self.apiclient, self.virtual_machine, self.services["natrule"], self.public_ip.ipaddress.id)
        return
Пример #10
0
    def test_maxAccountNetworks(self):
        """Test Limit number of guest account specific networks
        """

        # Steps for validation
        # 1. Fetch max.account.networks from configurations
        # 2. Create an account. Create account more that max.accout.network
        # 3. Create network should fail

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

        config = Configurations.list(self.apiclient, name="max.project.networks", listall=True)
        self.assertEqual(isinstance(config, list), True, "List configurations hsould have max.project.networks")

        config_value = int(config[0].value)
        self.debug("max.project.networks: %s" % config_value)

        for ctr in range(config_value):
            # Creating network using the network offering created
            self.debug("Creating network with network offering: %s" % self.network_offering.id)
            network = Network.create(
                self.apiclient,
                self.services["network"],
                projectid=project.id,
                networkofferingid=self.network_offering.id,
                zoneid=self.zone.id,
            )
            self.debug("Created network with ID: %s" % network.id)
        self.debug("Creating network in account already having networks : %s" % config_value)

        with self.assertRaises(Exception):
            Network.create(
                self.apiclient,
                self.services["network"],
                projectid=project.id,
                networkofferingid=self.network_offering.id,
                zoneid=self.zone.id,
            )
        self.debug("Create network failed (as expected)")
        return
Пример #11
0
    def test_01_native_to_native_network_migration(self):
        """
        Verify Migration for an isolated network nativeOnly
        1. create native non-persistent isolated network
        2. migrate to other non-persistent isolated network
        3. migrate back to first native non-persistent network
        4. deploy VM in non-persistent isolated network
        5. migrate to native persistent isolated network
        6. migrate back to native non-persistent network
        """

        isolated_network = Network.create(
                self.apiclient,
                self.test_data["isolated_network"],
                accountid=self.account.name,
                domainid=self.account.domainid,
                networkofferingid=self.network_offering_all.id,
                zoneid=self.zone.id
        )

        self.migrate_network(
                self.network_offering_nouserdata,
                isolated_network, resume=False)

        self.migrate_network(
                self.network_offering_all,
                isolated_network, resume=False)

        deployVmResponse = VirtualMachine.create(
                self.apiclient,
                services=self.test_data["virtual_machine_userdata"],
                accountid=self.account.name,
                domainid=self.account.domainid,
                serviceofferingid=self.service_offering.id,
                networkids=[str(isolated_network.id)],
                templateid=self.template.id,
                zoneid=self.zone.id
        )
        vms = list_virtual_machines(
                self.apiclient,
                account=self.account.name,
                domainid=self.account.domainid,
                id=deployVmResponse.id
        )
        self.assert_(len(vms) > 0, "There are no Vms deployed in the account"
                                   " %s" % self.account.name)
        vm = vms[0]
        self.assert_(vm.id == str(deployVmResponse.id),
                     "Vm deployed is different from the test")
        self.assert_(vm.state == "Running", "VM is not in Running state")

        self.migrate_network(
                self.network_offering_nouserdata,
                isolated_network, resume=False)

        self.migrate_network(
                self.network_offering_all,
                isolated_network, resume=False)
    def test_02_nicira_controller_redirect(self):
        """
            Nicira clusters will redirect clients (in this case ACS) to the master node.
            This test assumes that a Nicira cluster is present and configured properly, and
            that it has at least two controller nodes. The test will check that ASC follows
            redirects by:
                - adding a Nicira Nvp device that points to one of the cluster's slave controllers,
                - create a VM in a Nicira backed network
            If all is well, no matter what controller is specified (slaves or master), the vm (and respective router VM)
            should be created without issues.
        """
        nicira_slave = self.determine_slave_conroller(self.nicira_hosts, self.nicira_master_controller)
        self.debug("Nicira slave controller is: %s " % nicira_slave)

        nicira_device = NiciraNvp.add(
            self.api_client,
            None,
            self.physical_network_id,
            hostname=nicira_slave,
            username=self.nicira_credentials['username'],
            password=self.nicira_credentials['password'],
            transportzoneuuid=self.transport_zone_uuid)
        self.test_cleanup.append(nicira_device)

        network_services = {
            'name'            : 'nicira_enabled_network',
            'displaytext'     : 'nicira_enabled_network',
            'zoneid'          : self.zone.id,
            'networkoffering' : self.network_offering.id
        }
        network = Network.create(
            self.api_client,
            network_services,
            accountid='admin',
            domainid=self.domain.id,
        )
        self.test_cleanup.append(network)

        virtual_machine = VirtualMachine.create(
            self.api_client,
            self.vm_services['small'],
            accountid='admin',
            domainid=self.domain.id,
            serviceofferingid=self.service_offering.id,
            networkids=[network.id],
            mode=self.vm_services['mode']
        )
        self.test_cleanup.append(virtual_machine)

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

        self.assertEqual(isinstance(list_vm_response, list), True, 'Response did not return a valid list')
        self.assertNotEqual(len(list_vm_response), 0, 'List of VMs is empty')

        vm_response = list_vm_response[0]
        self.assertEqual(vm_response.id, virtual_machine.id, 'Virtual machine in response does not match request')
        self.assertEqual(vm_response.state, 'Running', 'VM is not in Running state')
    def setUpClass(cls):
        cls.logger = MarvinLog(MarvinLog.LOGGER_TEST).get_logger()

        # We want to fail quicker if it's failure
        socket.setdefaulttimeout(60)

        cls.testClient = super(TestRouterIpTablesPolicies, cls).getClsTestClient()
        cls.apiclient = cls.testClient.getApiClient()

        cls.services = cls.testClient.getParsedTestDataConfig()
        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.apiclient)
        cls.zone = get_zone(cls.apiclient, cls.testClient.getZoneForTests())
        cls.template = get_template(
            cls.apiclient,
            cls.zone.id
        )
        cls.services["vpc"]["cidr"] = '10.1.1.1/16'
        cls.services["virtual_machine"]["zoneid"] = cls.zone.id
        cls.services["virtual_machine"]["template"] = cls.template.id
        cls.vpc_offering = get_default_vpc_offering(cls.apiclient)
        cls.logger.debug("VPC Offering '%s' selected", cls.vpc_offering.name)

        cls.network_offering = get_default_network_offering(cls.apiclient)
        cls.logger.debug("Network Offering '%s' selected", cls.network_offering.name)

        cls.default_allow_acl = get_network_acl(cls.apiclient, 'default_allow')
        cls.logger.debug("ACL '%s' selected", cls.default_allow_acl.name)

        cls.account = Account.create(
            cls.apiclient,
            cls.services["account"],
            admin=True,
            domainid=cls.domain.id)
        cls.vpc1 = VPC.create(cls.apiclient,
                               cls.services['vpcs']['vpc1'],
                               vpcofferingid=cls.vpc_offering.id,
                               zoneid=cls.zone.id,
                               domainid=cls.domain.id,
                               account=cls.account.name)
        cls.logger.debug("VPC '%s' created, CIDR: %s", cls.vpc1.name, cls.vpc1.cidr)

        cls.network1 = Network.create(cls.apiclient,
                                       cls.services['networks']['network1'],
                                       networkofferingid=cls.network_offering.id,
                                       aclid=cls.default_allow_acl.id,
                                       vpcid=cls.vpc1.id,
                                       zoneid=cls.zone.id,
                                       domainid=cls.domain.id,
                                       accountid=cls.account.name)
        cls.logger.debug("Network '%s' created, CIDR: %s, Gateway: %s", cls.network1.name, cls.network1.cidr, cls.network1.gateway)

        cls.service_offering = get_default_virtual_machine_offering(cls.apiclient)

        cls.entity_manager = EntityManager(cls.apiclient, cls.services, cls.service_offering, cls.account, cls.zone, cls.network1, cls.logger)

        cls._cleanup = [cls.account]
        return
Пример #14
0
    def test_04_publicip_per_project(self):
        """Test Public IP limit per project
        """
        # Validate the following
        # 1. set max no of IPs per project to 2.
        # 2. Create an account in this domain
        # 3. Create 1 VM in this domain
        # 4. Acquire 1 IP in the domain. IP should be successfully acquired
        # 5. Try to acquire 3rd IP in this domain. It should give the user an
        #    appropriate error and an alert should be generated.

        self.debug("Updating public IP resource limits for project: %s" % self.project.id)
        # Set usage_vm=1 for Account 1
        update_resource_limit(self.apiclient, 1, max=2, projectid=self.project.id)  # Public Ip

        self.debug("Deploying VM for Project: %s" % self.project.id)
        virtual_machine_1 = VirtualMachine.create(
            self.apiclient,
            self.services["server"],
            templateid=self.template.id,
            serviceofferingid=self.service_offering.id,
            projectid=self.project.id,
        )
        self.cleanup.append(virtual_machine_1)
        # Verify VM state
        self.assertEqual(virtual_machine_1.state, "Running", "Check VM state is Running or not")
        networks = Network.list(self.apiclient, projectid=self.project.id, listall=True)
        self.assertEqual(isinstance(networks, list), True, "Check list networks response returns a valid response")
        self.assertNotEqual(len(networks), 0, "Check list networks response returns a valid network")
        network = networks[0]
        self.debug("Associating public IP for project: %s" % self.project.id)
        public_ip_1 = PublicIPAddress.create(
            self.apiclient,
            zoneid=virtual_machine_1.zoneid,
            services=self.services["server"],
            networkid=network.id,
            projectid=self.project.id,
        )
        self.cleanup.append(public_ip_1)
        # Verify Public IP state
        self.assertEqual(
            public_ip_1.ipaddress.state in ["Allocated", "Allocating"],
            True,
            "Check Public IP state is allocated or not",
        )

        # Exception should be raised for second Public IP
        with self.assertRaises(Exception):
            PublicIPAddress.create(
                self.apiclient,
                zoneid=virtual_machine_1.zoneid,
                services=self.services["server"],
                networkid=network.id,
                projectid=self.project.id,
            )
        return
    def test_03_Update_Network_with_Domain(self):
        """ Verify update NetworkDomain for InternalDns on Isolated Network
        """

        # Validate the following
        # 1. Create an Isolated network - network1 (10.1.1.1/24) by using DNS
        #    network offering.
        # 2. Deploy vm1 in network1.
        # 3. Verify dhcp option 06 and 0f for subnet
        # 4. Verify dhcp option 06,15 and 0f for vm Interface.
        # 5. Update Network domain and verify it is properly updated

        # update Network Domain at zone level
        cmd = updateZone.updateZoneCmd()
        cmd.id = self.zone.id
        cmd.domain = "isolated.com"
        self.apiclient.updateZone(cmd)

        self.debug("Creating and enabling Nuage Vsp Isolated Network "
                   "offering...")
        network_offering = self.create_NetworkOffering(
            self.dnsdata["isolated_network_offering"])
        self.validate_NetworkOffering(network_offering, state="Enabled")

        network_1 = self.create_Network(network_offering)
        vm_1 = self.create_VM(network_1)

        # VSD verification
        self.verify_vsd_network(self.domain.id, network_1)
        self.verify_vsd_vm(vm_1)

        # Internal DNS check point on VSD
        self.verify_vsd_dhcp_option(self.DNS, "10.1.1.2", network_1)
        self.verify_vsd_dhcp_option(self.DOMAINNAME, "isolated.com", network_1)
        for nic in vm_1.nic:
            self.verify_vsd_dhcp_option(self.DNS, "10.1.1.2", nic, True)
            self.verify_vsd_dhcp_option(
                self.DOMAINNAME, "isolated.com", nic, True)
            self.verify_vsd_dhcp_option(self.HOSTNAME, "vm1", nic, True)

        update_response = Network.update(
            network_1, self.apiclient, id=network_1.id,
            networkdomain="update.com", changecidr=False)
        completeoutput = str(update_response).strip('[]')
        self.debug("network update response is " + completeoutput)
        self.assertEqual("update.com", update_response.networkdomain,
                         "Network Domain is not updated as expected"
                         )
        self.verify_vsd_dhcp_option(self.DNS, "10.1.1.2", network_1)
        self.verify_vsd_dhcp_option(self.DOMAINNAME, "update.com", network_1)
        for nic in vm_1.nic:
            self.verify_vsd_dhcp_option(self.DNS, "10.1.1.2", nic, True)
            self.verify_vsd_dhcp_option(
                self.DOMAINNAME, "update.com", nic, True)
            self.verify_vsd_dhcp_option(self.HOSTNAME, "vm1", nic, True)
    def test_vpcnetwork_nuage(self):
        """Test network VPC for Nuage"""

        # 1) Create VPC with Nuage VPC offering
        vpcOffering = VpcOffering.list(self.apiclient,name="Nuage VSP VPC offering")
        self.assert_(vpcOffering is not None and len(vpcOffering)>0, "Nuage VPC offering not found")
        vpc = VPC.create(
                apiclient=self.apiclient,
                services=self.services["vpc"],
                networkDomain="vpc.networkacl",
                vpcofferingid=vpcOffering[0].id,
                zoneid=self.zone.id,
                account=self.account.name,
                domainid=self.account.domainid
        )
        self.assert_(vpc is not None, "VPC creation failed")

        # 2) Create ACL
        aclgroup = NetworkACLList.create(apiclient=self.apiclient, services={}, name="acl", description="acl", vpcid=vpc.id)
        self.assertIsNotNone(aclgroup, "Failed to create NetworkACL list")
        self.debug("Created a network ACL list %s" % aclgroup.name)

        # 3) Create ACL Item
        aclitem = NetworkACL.create(apiclient=self.apiclient, services={},
            protocol="TCP", number="10", action="Deny", aclid=aclgroup.id, cidrlist=["0.0.0.0/0"])
        self.assertIsNotNone(aclitem, "Network failed to aclItem")
        self.debug("Added a network ACL %s to ACL list %s" % (aclitem.id, aclgroup.name))

        # 4) Create network with ACL
        nwNuage = Network.create(
            self.apiclient,
            self.services["vpcnetwork"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            networkofferingid=self.network_offering.id,
            zoneid=self.zone.id,
            vpcid=vpc.id,
            aclid=aclgroup.id,
            gateway='10.1.0.1'
        )
        self.debug("Network %s created in VPC %s" %(nwNuage.id, vpc.id))

        # 5) Deploy a vm
        vm = VirtualMachine.create(
            self.apiclient,
            self.services["virtual_machine"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
            networkids=[str(nwNuage.id)]
        )
        self.assert_(vm is not None, "VM failed to deploy")
        self.assert_(vm.state == 'Running', "VM is not running")
        self.debug("VM %s deployed in VPC %s" %(vm.id, vpc.id))
Пример #17
0
 def createNetwork(idx):
     offering["name"] = "Test Network%s" % idx
     network = Network.create(
         self.apiclient,
         offering,
         self.account.name,
         self.account.domainid,
         zoneid=self.services["network"]["zoneid"]
     )
     networks.append(network)
     self.cleanup.insert(0, network)
Пример #18
0
    def setUp(self):
        self.apiclient = self.testClient.getApiClient()
        self.services["network"]["networkoffering"] = self.network_offering.id

        self.l2_network = Network.create(
            self.apiclient,
            self.services["l2-network"],
            zoneid=self.zone.id,
            networkofferingid=self.network_offering.id
        )
        self.cleanup = [
            self.l2_network]
Пример #19
0
def isNetworkDeleted(apiclient, networkid, timeout=600):
    """ List the network and check that the list is empty or not"""
    networkDeleted = False
    while timeout >= 0:
        networks = Network.list(apiclient, id=networkid)
        if networks is None:
            networkDeleted = True
            break
        timeout -= 60
        time.sleep(60)
    #end while
    return networkDeleted
Пример #20
0
    def setUpClass(cls):

        cls.testClient = super(TestIsolatedNetworks, cls).getClsTestClient()
        cls.api_client = cls.testClient.getApiClient()

        cls.services = cls.testClient.getParsedTestDataConfig()
        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.api_client)
        cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests())
        cls.services["mode"] = cls.zone.networktype
        template = get_template(cls.api_client, cls.zone.id, cls.services["ostype"])
        cls.services["virtual_machine"]["zoneid"] = cls.zone.id

        # Create an account, network, VM and IP addresses
        cls.account = Account.create(cls.api_client, cls.services["account"], admin=True, domainid=cls.domain.id)
        cls.service_offering = ServiceOffering.create(cls.api_client, cls.services["service_offering"])

        cls.services["network_offering"]["egress_policy"] = "true"

        cls.network_offering = NetworkOffering.create(
            cls.api_client, cls.services["network_offering"], conservemode=True
        )

        cls.network_offering.update(cls.api_client, state="Enabled")

        cls.network = Network.create(
            cls.api_client,
            cls.services["network"],
            accountid=cls.account.name,
            domainid=cls.account.domainid,
            networkofferingid=cls.network_offering.id,
            zoneid=cls.zone.id,
        )

        cls.vm_1 = VirtualMachine.create(
            cls.api_client,
            cls.services["virtual_machine"],
            templateid=template.id,
            accountid=cls.account.name,
            domainid=cls.domain.id,
            serviceofferingid=cls.service_offering.id,
            networkids=[str(cls.network.id)],
        )

        cls._cleanup = [cls.vm_1, cls.network, cls.network_offering, cls.service_offering, cls.account]

        cls.logger = logging.getLogger("TestIsolatedNetworks")
        cls.stream_handler = logging.StreamHandler()
        cls.logger.setLevel(logging.DEBUG)
        cls.logger.addHandler(cls.stream_handler)

        return
Пример #21
0
    def get_Network(self, account):
        """Returns a network for account"""

        networks = Network.list(
                                self.apiclient,
                                account=account.name,
                                domainid=account.domainid,
                                listall=True
                                )
        self.assertIsInstance(networks,
                              list,
                              "List networks should return a valid response")
        return networks[0]
 def test_04_network_without_domain_CS19303(self):
     """
     @Desc: Errors editing a network without a network domain specified
     @Steps:
     Step1: Create a network offering with SourceNAT,staticNAT and dhcp services
     Step2: Verify the network offering creation
     Step3: Create an isolated network with the offering created in step1 and without a network domain specified
     Step4: Verify the network creation
     Step5: Edit the network and verify that updating network should not error out
     """
     self.debug(
         "Creating n/w offering with SourceNat,StaticNat and DHCP services in VR & conserve mode:off"
     )
     self.network_offering = NetworkOffering.create(
         self.api_client,
         self.services["network_offering_withoutDNS"],
         conservemode=False
     )
     self.assertIsNotNone(
         self.network_offering,
         "Failed to create NO with Sourcenat,staticnat and dhcp only services"
     )
     self.cleanup.append(self.network_offering)
     self.debug("Created n/w offering with ID: %s" % self.network_offering.id)
     # Enable Network offering
     self.network_offering.update(self.apiclient, state='Enabled')
     self.debug("Creating nw without dns service using no id: %s" % self.network_offering.id)
     self.network = Network.create(
         self.apiclient,
         self.services["network"],
         accountid=self.account.name,
         domainid=self.account.domainid,
         networkofferingid=self.network_offering.id,
         zoneid=self.zone.id
     )
     self.assertIsNotNone(
         self.network,
         "Failed to create network without DNS service and network domain"
     )
     self.debug("Created network with NO: %s" % self.network_offering.id)
     try:
         self.network_update = self.network.update(
             self.apiclient,
             name="NW without nw domain"
         )
         self.debug("Success:Network update has been successful without network domain")
     except Exception as e:
         self.fail("Error editing a network without network domain specified: %s" % e)
     return
 def deploy_isolatednetwork(self, isolatednetwork_data, account):
     self.logger.debug('>>>  ISOLATED NETWORK  =>  Creating "%s"...', isolatednetwork_data['name'])
     isolatednetwork = Network.create(
         self.api_client,
         data=isolatednetwork_data,
         account=account,
         zone=self.zone
     )
     self.logger.debug('>>>  ISOLATED NETWORK   =>  ID: %s  =>  Name: %s  =>  CIDR: %s  '
                       '=>  Gateway: %s  =>  Type: %s  =>  Traffic Type: %s  =>  State: %s  '
                       '=>  Offering: %s  =>  Physical Network: %s  =>  Domain: %s',
                       isolatednetwork.id, isolatednetwork.name, isolatednetwork.cidr,
                       isolatednetwork.gateway, isolatednetwork.type, isolatednetwork.traffictype,
                       isolatednetwork.state, isolatednetwork.networkofferingid,
                       isolatednetwork.physicalnetworkid, isolatednetwork.domainid)
 def create_guest_network(self):
     network_services = {
         'name'            : 'nicira_enabled_network',
         'displaytext'     : 'nicira_enabled_network',
         'zoneid'          : self.zone.id,
         'networkoffering' : self.network_offering.id
     }
     network = Network.create(
         self.api_client,
         network_services,
         accountid='admin',
         domainid=self.domain.id,
     )
     self.test_cleanup.append(network)
     return network
Пример #25
0
    def test_isolated_nw_invalid_gw(self):

        self.debug("Trying to create a network with Gateway as 192.168.3.0. This should fail")
        with self.assertRaises(Exception):
            Network.create(
                self.apiclient,
                self.services["network"],
                self.account.name,
                self.account.domainid,
                gateway="192.168.3.0",
                netmask="255.255.255.0",
            )

        self.debug("Trying to create a network with Gateway as 192.168.3.255")
        with self.assertRaises(Exception):
            Network.create(
                self.apiclient,
                self.services["network"],
                self.account.name,
                self.account.domainid,
                gateway="192.168.3.255",
                netmask="255.255.255.0"
            )

        self.debug("Trying to create a network with Gateway as 192.168.3.0 and Subnet mask as 255.0.255.0")
        with self.assertRaises(Exception):
            Network.create(
                self.apiclient,
                self.services["network"],
                self.account.name,
                self.account.domainid,
                gateway="192.168.3.0",
                netmask="255.0.255.0",
            )

        self.debug("Trying to create a network with Subnet mask as 255.0.255.0")
        with self.assertRaises(Exception):
            Network.create(
                self.apiclient,
                self.services["network"],
                self.account.name,
                self.account.domainid,
                gateway="192.168.3.1",
                netmask="255.0.255.0",
            )
        return
Пример #26
0
 def create_Network(self, nw_off, gateway="10.1.1.1", netmask="255.255.255.0", vpc=None, acl_list=None):
     self.debug("Creating a network in the account - %s" % self.account.name)
     self.test_data["network"]["netmask"] = netmask
     network = Network.create(self.api_client,
                              self.test_data["network"],
                              accountid=self.account.name,
                              domainid=self.account.domainid,
                              networkofferingid=nw_off.id,
                              zoneid=self.zone.id,
                              gateway=gateway,
                              vpcid=vpc.id if vpc else self.vpc.id if hasattr(self, "vpc") else None,
                              aclid=acl_list.id if acl_list else None
                              )
     self.debug("Created network with ID - %s" % network.id)
     self.cleanup.append(network)
     return network
    def create_network(self, network_offering, vpc_id, gateway='10.1.1.1'):
        try:
            self.services["network"]["name"] = "NETWORK-" + str(gateway)
            self.logger.debug('Adding Network=%s to VPC ID %s' % (self.services["network"], vpc_id))
            obj_network = Network.create(
                self.apiclient,
                self.services["network"],
                accountid=self.account.name,
                domainid=self.account.domainid,
                networkofferingid=network_offering.id,
                zoneid=self.zone.id,
                gateway=gateway,
                vpcid=vpc_id)

            self.logger.debug("Created network with ID: %s" % obj_network.id)
        except Exception, e:
            raise Exception('Unable to create a Network with offering=%s because of %s ' % (network_offering.id, e))
Пример #28
0
 def validate_Network(self, network, state=None):
     """Validates the Network"""
     self.debug("Check if the network is created successfully ?")
     networks = Network.list(self.api_client,
                             id=network.id
                             )
     self.assertEqual(isinstance(networks, list), True,
                      "List network should return a valid list"
                      )
     self.assertEqual(network.name, networks[0].name,
                      "Name of the network should match with with the returned list data"
                      )
     if state:
         self.assertEqual(networks[0].state, state,
                          "Network state should be in state - %s" % state
                          )
     self.debug("Network creation successfully validated for %s" % network.name)
Пример #29
0
 def validate_Network(self, network, state=None):
     """Validates the network"""
     self.debug("Validating the creation and state of Network - %s" % network.name)
     networks = Network.list(self.api_client,
                             id=network.id
                             )
     self.assertEqual(isinstance(networks, list), True,
                      "List network should return a valid list"
                      )
     self.assertEqual(network.name, networks[0].name,
                      "Name of the network should match with with the returned list data"
                      )
     if state:
         self.assertEqual(networks[0].state, state,
                          "Network state should be '%s'" % state
                          )
     self.debug("Successfully validated the creation and state of Network - %s" % network.name)
    def test_01_nicira_controller(self):
        nicira_device = NiciraNvp.add(
            self.api_client,
            None,
            self.physical_network_id,
            hostname=self.nicira_master_controller,
            username=self.nicira_credentials['username'],
            password=self.nicira_credentials['password'],
            transportzoneuuid=self.transport_zone_uuid)
        self.test_cleanup.append(nicira_device)

        network_services = {
            'name'            : 'nicira_enabled_network',
            'displaytext'     : 'nicira_enabled_network',
            'zoneid'          : self.zone.id,
            'networkoffering' : self.network_offering.id
        }
        network = Network.create(
            self.api_client,
            network_services,
            accountid='admin',
            domainid=self.domain.id,
        )
        self.test_cleanup.append(network)

        virtual_machine = VirtualMachine.create(
            self.api_client,
            self.vm_services['small'],
            accountid='admin',
            domainid=self.domain.id,
            serviceofferingid=self.service_offering.id,
            networkids=[network.id],
            mode=self.vm_services['mode']
        )
        self.test_cleanup.append(virtual_machine)

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

        self.assertEqual(isinstance(list_vm_response, list), True, 'Response did not return a valid list')
        self.assertNotEqual(len(list_vm_response), 0, 'List of VMs is empty')

        vm_response = list_vm_response[0]
        self.assertEqual(vm_response.id, virtual_machine.id, 'Virtual machine in response does not match request')
        self.assertEqual(vm_response.state, 'Running', 'VM is not in Running state')
Пример #31
0
    def setUpClass(cls):
        cls._cleanup = []
        cls.testClient = super(TestLbStickyPolicy, cls).getClsTestClient()
        cls.api_client = cls.testClient.getApiClient()

        # Fill testdata from the external config file
        cls.testdata = cls.testClient.getParsedTestDataConfig()
        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.api_client)
        cls.zone = get_zone(cls.api_client, cls.testClient.getZoneForTests())
        cls.template = get_template(cls.api_client, cls.zone.id,
                                    cls.testdata["ostype"])

        cls.testdata["configurableData"]["netscaler"][
            "lbdevicededicated"] = False

        try:
            cls.netscaler = add_netscaler(
                cls.api_client, cls.zone.id,
                cls.testdata["configurableData"]["netscaler"])
            cls._cleanup.append(cls.netscaler)
            cls.network_offering = NetworkOffering.create(
                cls.api_client,
                cls.testdata["nw_off_isolated_netscaler"],
                conservemode=True)
            # Enable Network offering
            cls.network_offering.update(cls.api_client, state='Enabled')
            cls.testdata["small"]["zoneid"] = cls.zone.id
            cls.testdata["small"]["template"] = cls.template.id

            cls.service_offering = ServiceOffering.create(
                cls.api_client, cls.testdata["service_offering"])
            cls.account = Account.create(cls.api_client,
                                         cls.testdata["account"],
                                         admin=True,
                                         domainid=cls.domain.id)
            cls._cleanup.insert(0, cls.account)
            # Creating network using the network offering created
            cls.network = Network.create(
                cls.api_client,
                cls.testdata["network"],
                accountid=cls.account.name,
                domainid=cls.account.domainid,
                networkofferingid=cls.network_offering.id,
                zoneid=cls.zone.id)

            # Spawn an instance in that network
            cls.virtual_machine = VirtualMachine.create(
                cls.api_client,
                cls.testdata["small"],
                accountid=cls.account.name,
                domainid=cls.account.domainid,
                serviceofferingid=cls.service_offering.id,
                networkids=[str(cls.network.id)])
            cls.public_ip = PublicIPAddress.create(
                cls.api_client,
                accountid=cls.account.name,
                zoneid=cls.zone.id,
                domainid=cls.account.domainid,
                networkid=cls.network.id)
        except Exception as e:
            cls.tearDownClass()
            raise Exception("Warning: Exception in setUpClass: %s" % e)
        return
Пример #32
0
    def create_vm(self, pfrule=False, egress_policy=True, RR=False):
        self.create_network_offering(egress_policy, RR)
        # Creating network using the network offering created
        self.debug("Creating network with network offering: %s" %
                   self.network_offering.id)
        self.network = Network.create(
            self.apiclient,
            self.services["network"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            networkofferingid=self.network_offering.id,
            zoneid=self.zone.id)
        self.cleanup_networks.append(self.network)
        self.debug("Created network with ID: %s" % self.network.id)
        self.debug("Deploying instance in the account: %s" % self.account.name)

        project = None
        try:
            self.virtual_machine = VirtualMachine.create(
                self.apiclient,
                self.services["virtual_machine"],
                accountid=self.account.name,
                domainid=self.domain.id,
                serviceofferingid=self.service_offering.id,
                mode=self.zone.networktype if pfrule else 'basic',
                networkids=[str(self.network.id)],
                projectid=project.id if project else None)
            self.cleanup_vms.append(self.virtual_machine)
        except Exception as e:
            self.fail("Virtual machine deployment failed with exception: %s" %
                      e)
        self.debug("Deployed instance %s in account: %s" %
                   (self.virtual_machine.id, self.account.name))

        # Checking if VM is running or not, in case it is deployed in error state, test case fails
        self.vm_list = list_virtual_machines(self.apiclient,
                                             id=self.virtual_machine.id)

        self.assertEqual(
            validateList(self.vm_list)[0], PASS,
            "vm list validation failed, vm list is %s" % self.vm_list)
        self.assertEqual(
            str(self.vm_list[0].state).lower(), 'running',
            "VM state should be running, it is %s" % self.vm_list[0].state)

        self.public_ip = PublicIPAddress.create(self.apiclient,
                                                accountid=self.account.name,
                                                zoneid=self.zone.id,
                                                domainid=self.account.domainid,
                                                networkid=self.network.id)

        # Open up firewall port for SSH
        FireWallRule.create(self.apiclient,
                            ipaddressid=self.public_ip.ipaddress.id,
                            protocol=self.services["natrule"]["protocol"],
                            cidrlist=['0.0.0.0/0'],
                            startport=self.services["natrule"]["publicport"],
                            endport=self.services["natrule"]["publicport"])

        self.debug("Creating NAT rule for VM ID: %s" % self.virtual_machine.id)
        #Create NAT rule
        NATRule.create(self.apiclient, self.virtual_machine,
                       self.services["natrule"], self.public_ip.ipaddress.id)
        return
Пример #33
0
    def setUp(self):
        self.cleanup = []
        self.logger = logging.getLogger('TestNIC')
        self.stream_handler = logging.StreamHandler()
        self.logger.setLevel(logging.DEBUG)
        self.logger.addHandler(self.stream_handler)

        def signal_handler(signal, frame):
            self.tearDown()
            sys.exit(0)

        # assign the signal handler immediately
        signal.signal(signal.SIGINT, signal_handler)

        self.hypervisor = self.testClient.getHypervisorInfo()
        if self.hypervisor.lower() == "hyperv":
            self.skipTest("Not supported on Hyper-V")

        try:
            self.apiclient = self.testClient.getApiClient()
            self.dbclient = self.testClient.getDbConnection()
            self.services = self.testClient.getParsedTestDataConfig()

            # Get Zone, Domain and templates
            domain = get_domain(self.apiclient)
            self.zone = get_zone(self.apiclient,
                                 self.testClient.getZoneForTests())

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

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

            self.services["iso1"]["zoneid"] = self.zone.id
            self.services["network"]["zoneid"] = self.zone.id

            # Create Account, VMs, NAT Rules etc
            self.account = Account.create(self.apiclient,
                                          self.services["account"],
                                          domainid=domain.id)
            self.cleanup.insert(0, self.account)

            self.service_offering = ServiceOffering.create(
                self.apiclient, self.services["service_offerings"]["tiny"])
            self.cleanup.insert(0, self.service_offering)

            ####################
            # Network offering
            self.network_offering = NetworkOffering.create(
                self.apiclient,
                self.services["network_offering"],
            )
            self.cleanup.insert(0, self.network_offering)
            self.network_offering.update(
                self.apiclient, state='Enabled')  # Enable Network offering
            self.services["network"][
                "networkoffering"] = self.network_offering.id

            self.network_offering_shared = NetworkOffering.create(
                self.apiclient,
                self.services["network_offering_shared"],
            )
            self.cleanup.insert(0, self.network_offering_shared)
            self.network_offering_shared.update(
                self.apiclient, state='Enabled')  # Enable Network offering
            self.services["network2"][
                "networkoffering"] = self.network_offering_shared.id

            ################
            # Test Network
            self.test_network = Network.create(
                self.apiclient,
                self.services["network"],
                self.account.name,
                self.account.domainid,
            )
            self.cleanup.insert(0, self.test_network)
            self.test_network2 = Network.create(
                self.apiclient,
                self.services["network2"],
                self.account.name,
                self.account.domainid,
                zoneid=self.services["network"]["zoneid"])
            self.cleanup.insert(0, self.test_network2)
        except Exception as ex:
            self.debug("Exception during NIC test SETUP!: " + str(ex))
Пример #34
0
    def test_vm_nic_adapter_vmxnet3(self):
        """

        # 1. Register a template for VMware with nicAdapter vmxnet3
        # 2. Deploy a VM using this template
        # 3. Create an isolated network
        # 4. Add network to VM
        # 5. Verify that the NIC adapter for VM for both the nics
        #    is vmxnet3
        """

        if self.hypervisor.lower() not in ["vmware"]:
            raise unittest.SkipTest("This test case is written specifically\
                    for Vmware hypervisor")

        # Register a private template in the account with nic adapter vmxnet3
        template = Template.register(
            self.userapiclient,
            self.testdata["configurableData"]["vmxnet3template"],
            zoneid=self.zone.id,
            account=self.account.name,
            domainid=self.account.domainid,
            details=[{
                "nicAdapter":
                self.testdata["configurableData"]["vmxnet3template"]
                ["nicadapter"]
            }])
        self.cleanup.append(template)
        template.download(self.apiclient)

        templates = Template.list(self.userapiclient,
                                  listall=True,
                                  id=template.id,
                                  templatefilter="self")

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

        self.testdata["virtual_machine"]["zoneid"] = self.zone.id
        self.testdata["virtual_machine"]["template"] = template.id

        virtual_machine = VirtualMachine.create(
            self.apiclient,
            self.testdata["virtual_machine"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id)

        isolated_network = Network.create(
            self.apiclient,
            self.testdata["isolated_network"],
            self.account.name,
            self.account.domainid,
            networkofferingid=self.isolated_network_offering.id)

        virtual_machine.add_nic(self.apiclient, isolated_network.id)

        # TODO: Add steps to check the Nic Adapter type in VCenter
        # using VCenter APIs
        return
Пример #35
0
    def _test_vpc_site2site_vpn(self, vpc_offering, num_VPCs=3):
        # Number of VPNs (to test) is number_of_VPCs - 1
        # By default test setting up 2 VPNs from VPC0, requiring total of 3 VPCs

        maxnumVM = num_VPCs - 1
        # Create VPC i
        vpc_list = []
        for i in range(num_VPCs):
            # Generate VPC (mostly subnet) info
            vpcservice_n = copy.deepcopy(self.services["vpcN"])
            for key in vpcservice_n.keys():
                vpcservice_n[key] = vpcservice_n[key].format(N=` i `)

            vpc_n = VPC.create(api_client=self.apiclient,
                               services=vpcservice_n,
                               networkDomain="vpc%d.vpn" % i,
                               vpcofferingid=vpc_offering.id,
                               zoneid=self.zone.id,
                               account=self.account.name,
                               domainid=self.domain.id)
            self.assertIsNotNone(vpc_n, "VPC%d creation failed" % i)
            vpc_list.append(vpc_n)
            self.cleanup.append(vpc_n)
            self.logger.debug("VPC%d %s created" % (i, vpc_list[i].id))

        default_acl = NetworkACLList.list(self.apiclient,
                                          name="default_allow")[0]

        # Create network in VPC i
        ntwk_list = []
        for i in range(num_VPCs):
            # Generate network (mostly subnet) info
            ntwk_info_n = copy.deepcopy(self.services["network_N"])
            for key in ntwk_info_n.keys():
                ntwk_info_n[key] = ntwk_info_n[key].format(N=` i `)

            ntwk_n = Network.create(api_client=self.apiclient,
                                    services=ntwk_info_n,
                                    accountid=self.account.name,
                                    domainid=self.account.domainid,
                                    networkofferingid=self.network_offering.id,
                                    zoneid=self.zone.id,
                                    vpcid=vpc_list[i].id,
                                    aclid=default_acl.id)
            self.assertIsNotNone(ntwk_n, "Network%d failed to create" % i)
            self.cleanup.append(ntwk_n)
            ntwk_list.append(ntwk_n)
            self.logger.debug("Network%d %s created in VPC %s" %
                              (i, ntwk_list[i].id, vpc_list[i].id))

        # Deploy a vm in network i
        vm_list = []
        vm_n = None

        for i in range(num_VPCs):
            vm_n = VirtualMachine.create(
                self.apiclient,
                services=self.services["virtual_machine"],
                templateid=self.template.id,
                zoneid=self.zone.id,
                accountid=self.account.name,
                domainid=self.account.domainid,
                serviceofferingid=self.virtual_machine_offering.id,
                networkids=[ntwk_list[i].id],
                hypervisor=self.hypervisor,
                mode='advanced' if (i == 0) or (i == maxnumVM) else 'default')
            self.assertIsNotNone(vm_n, "VM%d failed to deploy" % i)
            self.cleanup.append(vm_n)
            vm_list.append(vm_n)
            self.logger.debug("VM%d %s deployed in VPC %s" %
                              (i, vm_list[i].id, vpc_list[i].id))
            self.assertEquals(vm_n.state, 'Running', "VM%d is not running" % i)

        # 4) Enable Site-to-Site VPN for VPC
        vpn_response_list = []
        for i in range(num_VPCs):
            vpn_response = Vpn.createVpnGateway(self.apiclient, vpc_list[i].id)
            self.assertIsNotNone(vpn_response,
                                 "Failed to enable VPN Gateway %d" % i)
            vpn_response_list.append(vpn_response)
            self.logger.debug("VPN gateway for VPC%d %s enabled" %
                              (i, vpc_list[i].id))

        # 5) Add VPN Customer gateway info
        vpn_cust_gw_list = []
        services = self.services["vpncustomergateway"]
        for i in range(num_VPCs):
            src_nat_list = PublicIPAddress.list(self.apiclient,
                                                account=self.account.name,
                                                domainid=self.account.domainid,
                                                listall=True,
                                                issourcenat=True,
                                                vpcid=vpc_list[i].id)
            ip = src_nat_list[0]

            customer_response = VpnCustomerGateway.create(
                self.apiclient, services, "Peer VPC" + ` i `, ip.ipaddress,
                vpc_list[i].cidr, self.account.name, self.domain.id)
            self.cleanup.insert(
                0, customer_response
            )  # this has to be cleaned up after the VPCs have been destroyed (due to client connectionsonections)
            vpn_cust_gw_list.append(customer_response)
            self.logger.debug(
                "VPN customer gateway added for VPC%d %s enabled" %
                (i, vpc_list[i].id))

        # Before the next step ensure the last VPC is up and running
        # Routers in the right state?
        self.assertEqual(
            self.routers_in_right_state(vpcid=vpc_list[maxnumVM].id), True,
            "Check whether the routers are in the right state.")

        # 6) Connect VPCi with VPC0
        for i in range(num_VPCs)[1:]:
            passiveVpn = Vpn.createVpnConnection(self.apiclient,
                                                 vpn_cust_gw_list[0].id,
                                                 vpn_response_list[i]['id'],
                                                 True)
            self.logger.debug("VPN passive connection created for VPC%d %s" %
                              (i, vpc_list[i].id))

            vpnconn2_response = Vpn.createVpnConnection(
                self.apiclient, vpn_cust_gw_list[i].id,
                vpn_response_list[0]['id'])
            self.logger.debug("VPN connection created for VPC%d %s" %
                              (0, vpc_list[0].id))

            self.assertEqual(vpnconn2_response['state'], "Connected",
                             "Failed to connect between VPCs 0 and %d!" % i)
            self.logger.debug("VPN connected between VPC0 and VPC%d" % i)

            time.sleep(15)
            self.logger.debug("Resetting VPN connection with id %s" %
                              (passiveVpn['id']))
            Vpn.resetVpnConnection(self.apiclient, passiveVpn['id'])

            # Ping to put tunnel up
            ssh_client = vm_list[0].get_ssh_client(retries=10)
            self.assertIsNotNone(ssh_client, "Failed to setup SSH to VM0")
            if ssh_client:
                # run ping test
                for i in range(num_VPCs)[1:]:
                    packet_loss = ssh_client.execute(
                        "/bin/ping -c 3 -t 10 " +
                        vm_list[i].nic[0].ipaddress)[0]
                    self.logger.debug(
                        "Ping from vm0 to vm%d to make sure tunnel is up." % i)
            else:
                self.fail("Failed to setup ssh connection to %s" %
                          vm_list[0].public_ip)

            self.logger.debug("Waiting for the VPN with id %s to connect" %
                              (passiveVpn['id']))
            max_retries = 30
            retries = 0
            while retries < max_retries:
                vpnconn2_response = Vpn.listVpnConnection(self.apiclient,
                                                          listall=True,
                                                          id=passiveVpn['id'])
                if len(vpnconn2_response) > 0 and vpnconn2_response[
                        0].state.lower() == 'connected':
                    break
                retries += 1
                time.sleep(2)
            self.assertLess(
                retries, max_retries,
                "Failed to reconnect VPN with id %s" % (passiveVpn['id']))

        # First the last VM
        # setup ssh connection to vm maxnumVM
        self.logger.debug(
            "Setup SSH connection to last VM created (%d) to ensure availability for ping tests"
            % maxnumVM)
        ssh_max_client = vm_list[maxnumVM].get_ssh_client(retries=20)
        self.assertIsNotNone(
            ssh_max_client,
            "Failed to setup SSH to last VM created (%d)" % maxnumVM)

        self.logger.debug(
            "Setup SSH connection to first VM created (0) to ensure availability for ping tests"
        )
        ssh_client = vm_list[0].get_ssh_client(retries=10)
        self.assertIsNotNone(ssh_client, "Failed to setup SSH to VM0")

        if ssh_client:
            # run ping test
            for i in range(num_VPCs)[1:]:
                packet_loss = ssh_client.execute(
                    "/bin/ping -c 3 -t 10 " + vm_list[i].nic[0].ipaddress +
                    " |grep packet|cut -d ' ' -f 7| cut -f1 -d'%'")[0]
                self.assertEquals(
                    int(packet_loss), 0,
                    " Ping towards vm" + ` i ` + " did not succeed")
                self.logger.debug("SUCCESS! Ping from vm0 to vm%d succeeded." %
                                  i)
        else:
            self.fail("Failed to setup ssh connection to %s" %
                      vm_list[0].public_ip)

        return
Пример #36
0
    def test_01_vpc_remote_access_vpn(self):
        """Test Remote Access VPN in VPC"""
        # 1) Create VPC
        vpc = VPC.create(api_client=self.apiclient,
                         services=self.services["vpc"],
                         networkDomain="vpc.vpn",
                         vpcofferingid=self.vpc_offering.id,
                         zoneid=self.zone.id,
                         account=self.account.name,
                         domainid=self.domain.id)

        self.assertIsNotNone(vpc, "VPC creation failed")
        self.logger.debug("VPC %s created" % (vpc.id))

        self.cleanup.append(vpc)

        # 2) Create network in VPC
        ntwk = Network.create(api_client=self.apiclient,
                              services=self.services["network_1"],
                              accountid=self.account.name,
                              domainid=self.domain.id,
                              networkofferingid=self.network_offering.id,
                              zoneid=self.zone.id,
                              vpcid=vpc.id)

        self.assertIsNotNone(ntwk, "Network failed to create")
        self.logger.debug("Network %s created in VPC %s" % (ntwk.id, vpc.id))

        self.cleanup.append(ntwk)

        # 3) Deploy a vm
        vm = VirtualMachine.create(
            self.apiclient,
            services=self.services["virtual_machine"],
            templateid=self.template.id,
            zoneid=self.zone.id,
            accountid=self.account.name,
            domainid=self.domain.id,
            serviceofferingid=self.virtual_machine_offering.id,
            networkids=ntwk.id,
            hypervisor=self.hypervisor)
        self.assertIsNotNone(vm, "VM failed to deploy")
        self.assertEquals(vm.state, 'Running', "VM is not running")
        self.debug("VM %s deployed in VPC %s" % (vm.id, vpc.id))

        self.logger.debug("Deployed virtual machine: OK")
        self.cleanup.append(vm)

        # 4) Enable VPN for VPC
        src_nat_list = PublicIPAddress.list(self.apiclient,
                                            account=self.account.name,
                                            domainid=self.account.domainid,
                                            listall=True,
                                            issourcenat=True,
                                            vpcid=vpc.id)
        ip = src_nat_list[0]

        self.logger.debug("Acquired public ip address: OK")

        vpn = Vpn.create(self.apiclient,
                         publicipid=ip.id,
                         account=self.account.name,
                         domainid=self.account.domainid,
                         iprange=self.services["vpn"]["iprange"],
                         fordisplay=self.services["vpn"]["fordisplay"])

        self.assertIsNotNone(vpn, "Failed to create Remote Access VPN")
        self.logger.debug("Created Remote Access VPN: OK")

        vpn_user = None
        # 5) Add VPN user for VPC
        vpn_user = VpnUser.create(self.apiclient,
                                  account=self.account.name,
                                  domainid=self.account.domainid,
                                  username=self.services["vpn"]["vpn_user"],
                                  password=self.services["vpn"]["vpn_pass"])

        self.assertIsNotNone(vpn_user,
                             "Failed to create Remote Access VPN User")
        self.logger.debug("Created VPN User: OK")

        # TODO: Add an actual remote vpn connection test from a remote vpc

        # 9) Disable VPN for VPC
        vpn.delete(self.apiclient)

        self.logger.debug("Deleted the Remote Access VPN: OK")
Пример #37
0
    def test_01_restart_network_cleanup(self):
        """TS_BUG_008-Test restart network
        """


        # Validate the following
        # 1. When cleanup = true, router is destroyed and a new one created
        # 2. New router will have new publicIp and linkLocalIp and
        #    all it's services should resume

        # Find router associated with user account
        list_router_response = list_routers(
                                    self.apiclient,
                                    account=self.account.name,
                                    domainid=self.account.domainid
                                    )
        self.assertEqual(
                            isinstance(list_router_response, list),
                            True,
                            "Check list response returns a valid list"
                        )
        router = list_router_response[0]

        #Store old values before restart
        old_linklocalip = router.linklocalip

        timeout = 10
        # Network should be in Implemented or Setup stage before restart
        while True:
            networks = Network.list(
                                 self.apiclient,
                                 account=self.account.name,
                                 domainid=self.account.domainid
                                 )
            network = networks[0]
            if network.state in ["Implemented", "Setup"]:
                break
            elif timeout == 0:
                break
            else:
                time.sleep(60)
                timeout = timeout - 1

        self.debug("Restarting network: %s" % network.id)
        cmd = restartNetwork.restartNetworkCmd()
        cmd.id = network.id
        cmd.cleanup = True
        self.apiclient.restartNetwork(cmd)

        # Get router details after restart
        list_router_response = list_routers(
                                    self.apiclient,
                                    account=self.account.name,
                                    domainid=self.account.domainid
                                    )
        self.assertEqual(
                            isinstance(list_router_response, list),
                            True,
                            "Check list response returns a valid list"
                        )
        router = list_router_response[0]

        self.assertNotEqual(
                            router.linklocalip,
                            old_linklocalip,
                            "Check link-local IP after restart"
                        )
        return
Пример #38
0
    def test_vpc_network_bcf(self):
        """Test VPC workflow with BigSwitch BCF plugin
           1. Create a VPC with three networks
           2. Create one VM on each of the three networks
           3. Add firewall rule to make virtual router pingable
           4. Test ping to virtual router public IP
           5. Add static NAT to vm_1, with firewall rule to allow ssh
           6. Add NAT rule to allow ping between net1 and net2
           7. Ssh to vm_1, ping vm_2 private address, should succeed
           8. continue ... ping vm_3 private address, should fail
           9. continue ... ping Internet, should succeed
        """

        self.debug("STEP 1: Creating VPC with VPC offering: %s" %
                            self.vpc_offering.id)
        vpc = VPC.create(
                         self.apiclient,
                         self.services["vpc"],
                         accountid=self.account.name,
                         domainid=self.account.domainid,
                         vpcofferingid=self.vpc_offering.id,
                         zoneid=self.zone.id
                        )
        self.debug("Created VPC with ID: %s" % self.vpc.id)

        # Creating network using the vpc network offering created
        self.debug("Creating networks with vpc network offering: %s" %
                    self.vpc_network_offering.id)
        net1 = Network.create(
                              self.apiclient,
                              self.services["vpc_network"],
                              accountid=self.account.name,
                              domainid=self.account.domainid,
                              networkofferingid=self.vpc_network_offering.id,
                              zoneid=self.zone.id,
                              gateway="10.0.100.1",
                              vpcid=vpc.id
                             )
        self.debug("Created network with ID: %s" % net1.id)

        net2 = Network.create(
                              self.apiclient,
                              self.services["vpc_network"],
                              accountid=self.account.name,
                              domainid=self.account.domainid,
                              networkofferingid=self.vpc_network_offering.id,
                              zoneid=self.zone.id,
                              gateway="10.0.101.1",
                              vpcid=vpc.id
                             )
        self.debug("Created network with ID: %s" % net2.id)

        net3 = Network.create(
                              self.apiclient,
                              self.services["vpc_network"],
                              accountid=self.account.name,
                              domainid=self.account.domainid,
                              networkofferingid=self.vpc_network_offering.id,
                              zoneid=self.zone.id,
                              gateway="10.0.102.0",
                              vpcid=vpc.id
                             )
        self.debug("Created network with ID: %s" % net3.id)

        self.debug("STEP 2: Deploying VMs in networks")

        vm_1 = VirtualMachine.create(
                                     self.apiclient,
                                     self.services["virtual_machine"],
                                     accountid=self.account.name,
                                     domainid=self.account.domainid,
                                     serviceofferingid=self.service_offering.id,
                                     networkids=[ str(net1.id), ]
                                    )
        self.debug("Deployed VM in network: %s" % net1.id)
        list_vm_response = VirtualMachine.list(
                                               self.apiclient,
                                               id=vm_1.id
                                              )
        self.debug(
                   "Verify listVirtualMachines response for virtual machine: %s" \
                   % vm_1.id
                  )
        self.assertEqual(
                         isinstance(list_vm_response, list),
                         True,
                         "Check list response returns a valid list"
                        )
        vm_response = list_vm_response[0]

        self.assertEqual(
                         vm_response.state,
                         "Running",
                         "VM state should be running after deployment"
                        )

        vm_2 = VirtualMachine.create(
                                     self.apiclient,
                                     self.services["virtual_machine"],
                                     accountid=self.account.name,
                                     domainid=self.account.domainid,
                                     serviceofferingid=self.service_offering.id,
                                     networkids=[ str(net2.id), ]
                                    )
        self.debug("Deployed VM in network: %s" % net2.id)
        list_vm_response = VirtualMachine.list(
                                               self.apiclient,
                                               id=vm_2.id
                                              )

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

        self.assertEqual(
                         isinstance(list_vm_response, list),
                         True,
                         "Check list response returns a valid list"
                        )
        vm_response = list_vm_response[0]

        self.assertEqual(
                            vm_response.state,
                            "Running",
                            "VM state should be running after deployment"
                        )

        vm_3 = VirtualMachine.create(
                                     self.apiclient,
                                     self.services["virtual_machine"],
                                     accountid=self.account.name,
                                     domainid=self.account.domainid,
                                     serviceofferingid=self.service_offering.id,
                                     networkids=[ str(net3.id), ]
                                    )
        self.debug("Deployed VM in network: %s" % net3.id)
        list_vm_response = VirtualMachine.list(
                                               self.apiclient,
                                               id=vm_3.id
                                              )
        self.debug(
                   "Verify listVirtualMachines response for virtual machine: %s" \
                   % vm_3.id
                  )
        self.assertEqual(
                         isinstance(list_vm_response, list),
                         True,
                         "Check list response returns a valid list"
                        )
        vm_response = list_vm_response[0]

        self.assertEqual(
                         vm_response.state,
                         "Running",
                         "VM state should be running after deployment"
                        )

        self.debug("STEP 3: Add FW rule to allow source nat ping")
        src_nat_list = PublicIPAddress.list(
                                        self.apiclient,
                                        account=self.account.name,
                                        domainid=self.account.domainid,
                                        listall=True,
                                        issourcenat=True,
                                        vpcid=vpc.id
                                        )
        self.assertEqual(
                         isinstance(src_nat_list, list),
                         True,
                         "List Public IP should return a valid source NAT"
                         )
        self.assertNotEqual(
                    len(src_nat_list),
                    0,
                    "Length of response from listPublicIp should not be 0"
                    )

        src_nat = src_nat_list[0]

        #Create Firewall rules on source NAT
        fw_rule_icmp = FireWallRule.create(
                            self.apiclient,
                            ipaddressid=src_nat.id,
                            protocol='ICMP',
                            cidrlist=["0.0.0.0/0",]
                            )
        self.debug("Created firewall rule: %s" % fw_rule_icmp.id)

        self.debug("STEP 4: Trying to ping source NAT %s" % src_nat.ipaddress)
        # User should be able to ping router via source nat ip
        try:
            self.debug("Trying to ping source NAT %s" % src_nat.ipaddress)
            result = subprocess.call(
                ['ping', '-c 1', src_nat.ipaddress])

            self.debug("Ping result: %s" % result)
            # if ping successful, then result should be 0
            self.assertEqual(
                             result,
                             0,
                             "Check if ping is successful or not"
                            )
        except Exception as e:
            self.fail("Ping failed for source NAT %s (%s)"
                      % (src_nat.ipaddress, e))

        self.debug("STEP 5: Add static NAT to vm_1 with FW rule to allow SSH")
        floating_ip_1 = PublicIPAddress.create(
                                               self.apiclient,
                                               accountid=self.account.name,
                                               zoneid=self.zone.id,
                                               domainid=self.account.domainid,
                                               networkid=net1.id,
                                               vpcid=vpc.id
                                              )
        self.debug("Associated %s with network %s" % (
                                                      floating_ip_1.ipaddress,
                                                      net1.id
                                                     )
                  )
        NATRule.create(
                                  self.apiclient,
                                  vm_1,
                                  self.services["natrule"],
                                  ipaddressid=floating_ip_1.ipaddress.id,
                                  openfirewall=False,
                                  networkid=net1.id,
                                  vpcid=vpc.id
                                  )

        # Should be able to SSH vm_1 via static nat, then ping vm_2 & Internet
        try:
            self.debug("STEP 6: SSH into vm_1: %s" % floating_ip_1)

            ssh = vm_1.get_ssh_client(
                                  ipaddress=floating_ip_1.ipaddress.ipaddress
                                  )
#            self.debug("Ping vm_2 at %s" % vm_2.ipaddress)
            # Ping to outsite world
#            res_1 = ssh.execute("ping -c 1 %s" % vm_2.ipaddress)

#            self.debug("Ping to google.com from VM")
            # Ping to outsite world
#            res_2 = ssh.execute("ping -c 1 www.google.com")

            # res = 64 bytes from maa03s17-in-f20.1e100.net (74.125.236.212):
            # icmp_req=1 ttl=57 time=25.9 ms
            # --- www.l.google.com ping statistics ---
            # 1 packets transmitted, 1 received, 0% packet loss, time 0ms
            # rtt min/avg/max/mdev = 25.970/25.970/25.970/0.000 ms
        except Exception as e:
            self.fail("SSH Access failed: %s" % e)

#        self.debug("ping result1: %s" % res_1);
#        self.debug("ping result2: %s" % res_2);

#        result1 = str(res_1)
#        self.assertEqual(
#                         result1.count("1 received"),
#                         1,
#                         "Ping vm_2 from vm_1 should be successful"
#                         )

#        result2 = str(res_2)
#        self.assertEqual(
#                         result2.count("1 received"),
#                         1,
#                         "Ping Internet from vm_1 should be successful"
#                         )

        # Deleting two test VMs
        VirtualMachine.delete(vm_1, self.apiclient, expunge=True)
        VirtualMachine.delete(vm_2, self.apiclient, expunge=True)

        # Delete Network
        Network.delete(self.network, self.apiclient)

        return
Пример #39
0
    def test_maxAccountNetworks(self):
        """Test Limit number of guest account specific networks
        """

        # Steps for validation
        # 1. Fetch max.account.networks from configurations
        # 2. Create an account. Create account more that max.accout.network
        # 3. Create network should fail

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

        config = Configurations.list(
                                    self.apiclient,
                                    name='max.project.networks',
                                    listall=True
                                    )
        self.assertEqual(
                isinstance(config, list),
                True,
                "List configurations hsould have max.project.networks"
                )

        config_value = int(config[0].value)
        self.debug("max.project.networks: %s" % config_value)

        for ctr in range(config_value):
            # Creating network using the network offering created
            self.debug("Creating network with network offering: %s" %
                                                    self.network_offering.id)
            network = Network.create(
                                    self.apiclient,
                                    self.services["network"],
                                    projectid=project.id,
                                    networkofferingid=self.network_offering.id,
                                    zoneid=self.zone.id
                                    )
            self.debug("Created network with ID: %s" % network.id)
        self.debug(
            "Creating network in account already having networks : %s" %
                                                            config_value)

        with self.assertRaises(Exception):
            Network.create(
                                    self.apiclient,
                                    self.services["network"],
                                    projectid=project.id,
                                    networkofferingid=self.network_offering.id,
                                    zoneid=self.zone.id
                                    )
        self.debug('Create network failed (as expected)')
        return
Пример #40
0
    def test_04_publicip_per_project(self):
        """Test Public IP limit per project
        """
        # Validate the following
        # 1. set max no of IPs per project to 2.
        # 2. Create an account in this domain
        # 3. Create 1 VM in this domain
        # 4. Acquire 1 IP in the domain. IP should be successfully acquired
        # 5. Try to acquire 3rd IP in this domain. It should give the user an
        #    appropriate error and an alert should be generated.

        self.debug(
            "Updating public IP resource limits for project: %s" %
                                                            self.project.id)
        # Set usage_vm=1 for Account 1
        update_resource_limit(
                              self.apiclient,
                              1, # Public Ip
                              max=2,
                              projectid=self.project.id
                              )

        self.debug("Deploying VM for Project: %s" % self.project.id)
        virtual_machine_1 = VirtualMachine.create(
                                self.apiclient,
                                self.services["server"],
                                templateid=self.template.id,
                                serviceofferingid=self.service_offering.id,
                                projectid=self.project.id
                                )
        self.cleanup.append(virtual_machine_1)
        # Verify VM state
        self.assertEqual(
                            virtual_machine_1.state,
                            'Running',
                            "Check VM state is Running or not"
                        )
        networks = Network.list(
                                self.apiclient,
                                projectid=self.project.id,
                                listall=True
                                )
        self.assertEqual(
                    isinstance(networks, list),
                    True,
                    "Check list networks response returns a valid response"
                    )
        self.assertNotEqual(
                    len(networks),
                    0,
                    "Check list networks response returns a valid network"
                    )
        network = networks[0]
        self.debug("Associating public IP for project: %s" %
                                                            self.project.id)
        public_ip_1 = PublicIPAddress.create(
                                           self.apiclient,
                                           zoneid=virtual_machine_1.zoneid,
                                           services=self.services["server"],
                                           networkid=network.id,
                                           projectid=self.project.id
                                           )
        self.cleanup.append(public_ip_1)
        # Verify Public IP state
        self.assertEqual(
                            public_ip_1.ipaddress.state in [
                                                 'Allocated',
                                                 'Allocating'
                                                 ],
                            True,
                            "Check Public IP state is allocated or not"
                        )

        # Exception should be raised for second Public IP
        with self.assertRaises(Exception):
            PublicIPAddress.create(
                                           self.apiclient,
                                           zoneid=virtual_machine_1.zoneid,
                                           services=self.services["server"],
                                           networkid=network.id,
                                           projectid=self.project.id
                                           )
        return