示例#1
0
    def setUpClass(cls):
        cls.logger = MarvinLog('test').getLogger()

        test_client = super(TestVpcVpn, cls).getClsTestClient()
        cls.apiclient = test_client.getApiClient()
        cls.services = Services().services

        cls.zone = get_zone(cls.apiclient, test_client.getZoneForTests())
        cls.domain = get_domain(cls.apiclient)

        cls.compute_offering = ServiceOffering.create(
            cls.apiclient, cls.services["compute_offering"])

        cls.account = Account.create(cls.apiclient,
                                     services=cls.services["account"])
        cls.logger.debug("Successfully created account: %s, id: %s" %
                         (cls.account.name, cls.account.id))

        cls.hypervisor = test_client.getHypervisorInfo()

        cls._cleanup = [cls.account, cls.compute_offering]

        cls.template = get_template(cls.apiclient, cls.zone.id)

        cls.logger.debug("Retrieving default Network offering for VPCs")
        cls.network_offerings = NetworkOffering.list(
            cls.apiclient, name="DefaultIsolatedNetworkOfferingForVpcNetworks")
        if cls.network_offerings is None or len(cls.network_offerings) <= 0:
            raise Exception("No VPC based network offering")

        return
示例#2
0
 def validate_network_offering(self, net_offering, state=None):
     """Validates the Network offering"""
     self.debug("Check if the Network offering is created successfully ?")
     net_offs = NetworkOffering.list(self.api_client, id=net_offering.id)
     self.assertEqual(isinstance(net_offs, list), True,
                      "List Network offering should return a valid list")
     self.assertEqual(
         net_offering.name, net_offs[0].name,
         "Name of the Network offering should match with the returned list data"
     )
     if state:
         self.assertEqual(net_offs[0].state, state,
                          "Network offering state should be '%s'" % state)
     self.debug("Network offering creation successfully validated - %s" %
                net_offering.name)
示例#3
0
 def validate_NetworkOffering(self, net_offering, state=None):
     """Validates the Network offering"""
     self.debug("Check if the Network offering is created successfully ?")
     net_offs = NetworkOffering.list(self.api_client,
                                     id=net_offering.id
                                     )
     self.assertEqual(isinstance(net_offs, list), True,
                      "List Network offering should return a valid list"
                      )
     self.assertEqual(net_offering.name, net_offs[0].name,
                      "Name of the Network offering should match with the returned list data"
                      )
     if state:
         self.assertEqual(net_offs[0].state, state,
                          "Network offering state should be in state - %s" % state
                          )
     self.debug("Network offering creation successfully validated for %s" % net_offering.name)
示例#4
0
    def test_01_create_ipv6_network_offering(self):
        """Test to create network offering

        # Validate the following:
        # 1. createNetworkOffering should return valid info for new offering
        # 2. The Cloud Database contains the valid information
        """
        Configurations.update(self.apiclient,
            ipv6_offering_config_name,
            "true")
        ipv6_service = self.services["network_offering"]
        ipv6_service["internetprotocol"] = "dualstack"
        network_offering = NetworkOffering.create(
            self.apiclient,
            ipv6_service
        )
        self.cleanup.append(network_offering)

        self.debug("Created Network offering with ID: %s" % network_offering.id)

        list_network_off_response = NetworkOffering.list(self.apiclient,
            id=network_offering.id)
        self.assertEqual(
            isinstance(list_network_off_response, list),
            True,
            "Check list response returns a valid list"
        )
        self.assertNotEqual(
            len(list_network_off_response),
            0,
            "Check Network offering is created"
        )
        network_off_response = list_network_off_response[0]

        self.assertEqual(
            network_off_response.id,
            network_offering.id,
            "Check server id in listNetworkOfferings"
        )
        self.assertEqual(
            network_off_response.internetprotocol.lower(),
            ipv6_service["internetprotocol"].lower(),
            "Check internetprotocol in listNetworkOfferings"
        )
        return
示例#5
0
    def setUpClass(cls):
        cls.logger = logging.getLogger('TestVPCSite2SiteVPN')
        cls.stream_handler = logging.StreamHandler()
        cls.logger.setLevel(logging.DEBUG)
        cls.logger.addHandler(cls.stream_handler)

        testClient = super(TestVpcSite2SiteVpn, cls).getClsTestClient()
        cls.apiclient = testClient.getApiClient()
        cls.services = Services().services

        cls.zone = get_zone(cls.apiclient, testClient.getZoneForTests())
        cls.domain = get_domain(cls.apiclient)

        cls.compute_offering = ServiceOffering.create(
            cls.apiclient,
            cls.services["compute_offering"]
        )

        cls.account = Account.create(
            cls.apiclient, services=cls.services["account"])

        cls.hypervisor = testClient.getHypervisorInfo()

        cls.logger.debug("Downloading Template: %s from: %s" % (cls.services["template"][
                         cls.hypervisor.lower()], cls.services["template"][cls.hypervisor.lower()]["url"]))
        cls.template = Template.register(cls.apiclient, cls.services["template"][cls.hypervisor.lower(
        )], cls.zone.id, hypervisor=cls.hypervisor.lower(), account=cls.account.name, domainid=cls.domain.id)
        cls.template.download(cls.apiclient)

        if cls.template == FAILED:
            assert False, "get_template() failed to return template"

        cls.logger.debug("Successfully created account: %s, id: \
                   %s" % (cls.account.name,
                          cls.account.id))

        cls.networkoffering = NetworkOffering.list(
                cls.apiclient, name="DefaultIsolatedNetworkOfferingForVpcNetworks")
        assert cls.networkoffering is not None and len(
                cls.networkoffering) > 0, "No VPC based network offering"

        cls._cleanup = [cls.template, cls.account, cls.compute_offering]
        return
 def validate_NetworkOffering(self, net_offering, state=None):
     """Validates the Network offering"""
     self.debug("Validating the creation and state of Network offering - %s"
                % net_offering.name)
     net_offs = NetworkOffering.list(self.api_client,
                                     id=net_offering.id
                                     )
     self.assertEqual(isinstance(net_offs, list), True,
                      "List Network offering should return a valid list"
                      )
     self.assertEqual(net_offering.name, net_offs[0].name,
                      "Name of the Network offering should match with the "
                      "returned list data"
                      )
     if state:
         self.assertEqual(net_offs[0].state, state,
                          "Network offering state should be '%s'" % state
                          )
     self.debug("Successfully validated the creation and state of Network "
                "offering - %s" % net_offering.name)
    def test_15_restore_vm_with_template_id(self):
        """
        Test restoring Virtual Machine with template id
        """

        noffering = NetworkOffering.list(
            self.user_api_client,
            name="DefaultIsolatedNetworkOfferingWithSourceNatService")
        vm1network = Network.create(self.user_api_client,
                                    self.services["network"],
                                    accountid=self.account.name,
                                    domainid=self.account.domainid,
                                    networkofferingid=noffering[0].id,
                                    zoneid=self.zone.id)

        list_nw_response = Network.list(self.user_api_client, id=vm1network.id)
        self.assertEqual(isinstance(list_nw_response, list), True,
                         "Check list response returns a valid networks list")

        restorevm = VirtualMachine.create(
            self.user_api_client,
            self.services["small"],
            networkids=vm1network.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
            mode=self.services['mode'],
            startvm="true")

        time.sleep(600)

        list_vm_response = VirtualMachine.list(self.user_api_client,
                                               id=restorevm.id)
        self.assertEqual(list_vm_response[0].state, "Running",
                         "Check virtual machine is in running state")

        custom_disk_offering = DiskOffering.list(self.user_api_client,
                                                 name="custom")

        newvolume = Volume.create(self.user_api_client,
                                  self.services["volume"],
                                  zoneid=self.zone.id,
                                  account=self.account.name,
                                  domainid=self.domain.id,
                                  diskofferingid=custom_disk_offering[0].id,
                                  size=1)

        # Attach volume to VM
        cmd = attachVolume.attachVolumeCmd()
        cmd.id = newvolume.id
        cmd.virtualmachineid = restorevm.id
        cmd.deviceid = 1
        vol1 = self.user_api_client.attachVolume(cmd)

        cmd = restoreVirtualMachine.restoreVirtualMachineCmd()
        cmd.virtualmachineid = restorevm.id
        cmd.templateid = self.xtemplate.id
        self.user_api_client.restoreVirtualMachine(cmd)

        time.sleep(600)

        list_vm_response = VirtualMachine.list(self.user_api_client,
                                               id=restorevm.id)
        self.assertEqual(isinstance(list_vm_response, list), True,
                         "Check list response returns a valid list")

        self.assertNotEqual(len(list_vm_response), 0,
                            "Check VM available in List Virtual Machines")

        self.assertEqual(list_vm_response[0].state, "Running",
                         "Check virtual machine is in Stopped state")

        restorevm.delete(self.apiclient)

        vm1network.delete(self.user_api_client)

        return
    def test_01_create_delete_portforwarding_fornonvpc(self):
        """
        @summary: Test to list, create and delete Port Forwarding for
        IP Address associated to Non VPC network
        @Steps:
        Step1: Creating a Network for the user
        Step2: Associating an IP Addresses for Network
        Step3: Launching Virtual Machine in network created in step 2
        Step4: Listing Port Forwarding Rules for the IP Address associated
               in Step2
        Step5: Verifying that no Port Forwarding Rules are listed
        Step6: Creating a Port Forwarding Rule for IP Address associated in
               Step2
        Step7: Listing Port Forwarding Rules for the IP Address associated in
               Step2
        Step8: Verifying 1 Port Forwarding Rule is listed
        Step9: Deleting the Port Forwarding Rule created in Step6
        Step10: Listing Port Forwarding Rules for the IP Address associated in
               Step2
        Step11: Verifying that no Port Forwarding Rules are listed
        """
        # Listing all the Networks's for a user
        list_networks_before = Network.list(
            self.userapiclient,
            listall=self.services["listall"],
            type="Isolated"
        )
        # Verifying No Networks are listed
        self.assertIsNone(
            list_networks_before,
            "Networks listed for newly created User"
        )
        # Listing Network Offerings
        network_offerings_list = NetworkOffering.list(
            self.apiClient,
            forvpc="false",
            guestiptype="Isolated",
            state="Enabled",
            supportedservices="SourceNat,PortForwarding",
            zoneid=self.zone.id
        )
        status = validateList(network_offerings_list)
        self.assertEquals(
            PASS,
            status[0],
            "Isolated Network Offerings with sourceNat,\
                    PortForwarding enabled are not found"
        )
        # Creating a network
        network = Network.create(
            self.userapiclient,
            self.services["network"],
            accountid=self.account.name,
            domainid=self.domain.id,
            networkofferingid=network_offerings_list[0].id,
            zoneid=self.zone.id
        )
        self.assertIsNotNone(
            network,
            "Network creation failed"
        )
        # Listing all the IP Addresses for a user
        list_ipaddresses_before = PublicIPAddress.list(
            self.userapiclient,
            listall=self.services["listall"]
        )
        # Verifying no IP Addresses are listed
        self.assertIsNone(
            list_ipaddresses_before,
            "IP Addresses listed for newly created User"
        )
        # Associating an IP Addresses to Network created
        associated_ipaddress = PublicIPAddress.create(
            self.userapiclient,
            services=self.services["network"],
            networkid=network.id
        )
        self.assertIsNotNone(
            associated_ipaddress,
            "Failed to Associate IP Address"
        )
        # Listing all the IP Addresses for a user
        list_ipaddresses_after = PublicIPAddress.list(
            self.userapiclient,
            listall=self.services["listall"]
        )
        status = validateList(list_ipaddresses_after)
        self.assertEquals(
            PASS,
            status[0],
            "IP Addresses Association Failed"
        )
        # Verifying the length of the list is 1
        self.assertEqual(
            1,
            len(list_ipaddresses_after),
            "Number of IP Addresses associated are not matching expected"
        )
        # Launching a Virtual Machine with above created Network
        vm_created = VirtualMachine.create(
            self.userapiclient,
            self.services["virtual_machine"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            networkids=network.id,
            serviceofferingid=self.service_offering.id,
        )
        self.assertIsNotNone(
            vm_created,
            "Failed to launch a VM under network created"
        )
        self.cleanup.append(network)
        # Listing Virtual Machines in running state in above created network
        list_vms_running = VirtualMachine.list(
            self.userapiclient,
            listall=self.services["listall"],
            state="Running",
            networkid=network.id
        )
        status = validateList(list_vms_running)
        self.assertEquals(
            PASS,
            status[0],
            "VM Created is not in Running state"
        )
        # Verifying the length of the list is 1
        self.assertEqual(
            1,
            len(list_ipaddresses_after),
            "VM Created is not in Running state"
        )
        self.assertEquals(
            vm_created.id,
            list_vms_running[0].id,
            "VM Created is not in Running state"
        )
        # Listing Virtual Machines in stopped state in above created network
        list_vms_stopped = VirtualMachine.list(
            self.userapiclient,
            listall=self.services["listall"],
            state="Stopped",
            networkid=network.id
        )
        # Verifying no VMs are in stopped state
        self.assertIsNone(
            list_vms_stopped,
            "VM Created is in stopped state"
        )
        # Listing Port Forwarding Rules for the IP Address associated
        list_prtfwdrule_before = NATRule.list(
            self.userapiclient,
            listall=self.services["listall"],
            ipaddressid=associated_ipaddress.ipaddress.id
        )
        # Verifying no port forwarding rules are listed
        self.assertIsNone(
            list_prtfwdrule_before,
            "Port Forwarding Rules listed for newly associated IP Address"
        )
        # Creating a Port Forwarding rule
        portfwd_rule = NATRule.create(
            self.userapiclient,
            virtual_machine=vm_created,
            services=self.services["natrule"],
            ipaddressid=associated_ipaddress.ipaddress.id,
        )
        self.assertIsNotNone(
            portfwd_rule,
            "Failed to create Port Forwarding Rule"
        )
        # Verifying details of Sticky Policy created
        # Creating expected and actual values dictionaries
        expected_dict = {
            "ipaddressid": associated_ipaddress.ipaddress.id,
            "privateport": str(self.services["natrule"]["privateport"]),
            "publicport": str(self.services["natrule"]["publicport"]),
            "protocol": str(self.services["natrule"]["protocol"]).lower(),
        }
        actual_dict = {
            "ipaddressid": portfwd_rule.ipaddressid,
            "privateport": str(portfwd_rule.privateport),
            "publicport": str(portfwd_rule.publicport),
            "protocol": portfwd_rule.protocol,
        }
        portfwd_status = self.__verify_values(
            expected_dict,
            actual_dict
        )
        self.assertEqual(
            True,
            portfwd_status,
            "Created Port Forward Rule details are not as expected"
        )
        # Listing Port Forwarding Rules for the IP Address associated
        list_prtfwdrule_after = NATRule.list(
            self.userapiclient,
            listall=self.services["listall"],
            ipaddressid=associated_ipaddress.ipaddress.id
        )
        status = validateList(list_prtfwdrule_after)
        self.assertEquals(
            PASS,
            status[0],
            "Failed to create Port Forwarding Rule"
        )
        # Verifying the length of the list is 1
        self.assertEqual(
            1,
            len(list_prtfwdrule_after),
            "Failed to create Port Forwarding Rule"
        )
        # Deleting Port Forwarding Rule
        portfwd_rule.delete(self.userapiclient)


        # Creating a Port Forwarding rule with port range
        portfwd_rule = NATRule.create(
            self.userapiclient,
            virtual_machine=vm_created,
            services=self.services["natrulerange"],
            ipaddressid=associated_ipaddress.ipaddress.id,
            )
        self.assertIsNotNone(
            portfwd_rule,
            "Failed to create Port Forwarding Rule"
        )
        #update the private port for port forwarding rule
        updatefwd_rule = portfwd_rule.update(self.userapiclient,
                            portfwd_rule.id,
                            virtual_machine=vm_created,
                            services=self.services["updatenatrulerange"],
                            )

        # Verifying details of Sticky Policy created
        # Creating expected and actual values dictionaries
        expected_dict = {
            "privateport": str(self.services["updatenatrulerange"]["privateport"]),
            "privateendport": str(self.services["updatenatrulerange"]["privateendport"]),
            }
        actual_dict = {
            "privateport": str(updatefwd_rule.privateport),
            "privateendport": str(updatefwd_rule.privateendport),
            }
        portfwd_status = self.__verify_values(
            expected_dict,
            actual_dict
        )
        self.assertEqual(
            True,
            portfwd_status,
            "Updated Port Forward Rule details are not as expected"
        )
        # Deleting Port Forwarding Rule
        portfwd_rule.delete(self.userapiclient)
        # Listing Port Forwarding Rules for the IP Address associated
        list_prtfwdrule_after = NATRule.list(
            self.userapiclient,
            listall=self.services["listall"],
            ipaddressid=associated_ipaddress.ipaddress.id
        )
        # Verifying no port forwarding rules are listed
        self.assertIsNone(
            list_prtfwdrule_after,
            "Port Forwarding Rules listed after deletion"
        )
        # Destroying the VM Launched
        vm_created.delete(self.apiClient)
        self.cleanup.append(self.account)
        return
    def test_16_create_template_volume(self):
        """Test Create template from volume
        """

        noffering=NetworkOffering.list(
                     self.user_api_client,
                     name="DefaultIsolatedNetworkOfferingWithSourceNatService"
                     )
        vm2network=Network.create(
                                 self.user_api_client,
                                self.services["network"],
                                accountid=self.account.name,
                                domainid=self.account.domainid,
                                networkofferingid=noffering[0].id,
                                zoneid=self.zone.id
                                 )

        list_nw_response = Network.list(
                                            self.user_api_client,
                                            id=vm2network.id
                                            )
        self.assertEqual(
                            isinstance(list_nw_response, list),
                            True,
                            "Check list response returns a valid networks list"
                        )

        templatevm = VirtualMachine.create(
                                    self.user_api_client,
                                    self.services["small"],
                                    templateid=self.template.id,
                                    accountid=self.account.name,
                                    domainid=self.account.domainid,
                                    networkids=vm2network.id,
                                    serviceofferingid=self.service_offering.id,
                                    mode=self.services['mode'],
                                    startvm="true"
                                    )
        time.sleep(600)
        vm_response = VirtualMachine.list(
                            self.user_api_client,
                            id=templatevm.id)

        self.assertNotEqual(
                            len(vm_response),
                            0,
                            "Check VMs available in List VMs response"
                        )
        vm = vm_response[0]
        self.assertEqual(
                            vm.state,
                            'Running',
                            "Check the state of VM created from Template"
                        )

        templatevm.stop(self.user_api_client,forced="false")

        vm_response = VirtualMachine.list(
                            self.user_api_client,
                            id=templatevm.id)

        vm = vm_response[0]
        self.assertEqual(
                            vm.state,
                            'Stopped',
                            "Check the state of VM is in Stopped state before creating the Template"
                        )

        list_volume_response = Volume.list(
            self.user_api_client,
            virtualmachineid=vm.id,
            type="ROOT",
            listall=True
        )

        #Create template from Virtual machine and Volume ID
        roottemplate = Template.create(
                                self.user_api_client,
                                self.services["interop"]["template"],
                                volumeid=list_volume_response[0].id,
                                account=self.account.name,
                                domainid=self.domain.id,
                                )

        time.sleep(600)

        list_template_response = Template.list(
                                    self.user_api_client,
                                    templatefilter=\
                                    self.services["templatefilter"],
                                    id=roottemplate.id
                                    )

        self.assertEqual(
                            isinstance(list_template_response, list),
                            True,
                            "Check list response returns a valid list"
                        )
        #Verify template response to check whether template added successfully
        self.assertNotEqual(
                            len(list_template_response),
                            0,
                            "Check template available in List Templates"
                        )
        template_response = list_template_response[0]

        self.assertEqual(
                            template_response.displaytext,
                            self.services["interop"]["template"]["displaytext"],
                            "Check display text of newly created template"
                        )
        name = template_response.name
        self.assertEqual(
                            name.count(self.services["interop"]["template"]["name"]),
                            1,
                            "Check name of newly created template"
                        )


        templatevm.delete(self.apiclient)
        vm2network.delete(self.user_api_client)

        vm3network=Network.create(
                                 self.user_api_client,
                                self.services["network"],
                                accountid=self.account.name,
                                domainid=self.account.domainid,
                                networkofferingid=noffering[0].id,
                                zoneid=self.zone.id
                                 )

        list_nw_response = Network.list(
                                            self.user_api_client,
                                            id=vm3network.id
                                            )
        self.assertEqual(
                            isinstance(list_nw_response, list),
                            True,
                            "Check list response returns a valid networks list"
                        )


        templatevm = VirtualMachine.create(
                                    self.user_api_client,
                                    self.services["small"],
                                    templateid=roottemplate.id,
                                    networkids=vm3network.id,
                                    serviceofferingid=self.service_offering.id,
                                    accountid=self.account.name,
                                    domainid=self.account.domainid,
                                    mode=self.services['mode'],
                                    startvm="true"
                                    )
        time.sleep(600)
        vm_response = VirtualMachine.list(
                            self.user_api_client,
                            id=templatevm.id)

        self.assertNotEqual(
                            len(vm_response),
                            0,
                            "Check VMs available in List VMs response"
                        )
        vm = vm_response[0]
        self.assertEqual(
                            vm.state,
                            'Running',
                            "Check the state of VM created from Template"
                        )

        # Delete the template
        roottemplate.delete(self.user_api_client)

        list_template_response = Template.list(
                                    self.user_api_client,
                                    templatefilter=\
                                    self.services["template"]["templatefilter"],
                                    id=roottemplate.id,
                                    zoneid=self.zone.id
                                    )
        self.assertEqual(
                            list_template_response,
                            None,
                            "Check template available in List Templates"
                        )

        templatevm.delete(self.apiclient)

        vm3network.delete(self.user_api_client)
        return
    def test_15_restore_vm_with_template_id(self):

        """
        Test restoring Virtual Machine with template id
        """

        noffering=NetworkOffering.list(
                     self.user_api_client,
                     name="DefaultIsolatedNetworkOfferingWithSourceNatService"
                     )
        vm1network=Network.create(
                                 self.user_api_client,
                                self.services["network"],
                                accountid=self.account.name,
                                domainid=self.account.domainid,
                                networkofferingid=noffering[0].id,
                                zoneid=self.zone.id
                                 )

        list_nw_response = Network.list(
                                            self.user_api_client,
                                            id=vm1network.id
                                            )
        self.assertEqual(
                            isinstance(list_nw_response, list),
                            True,
                            "Check list response returns a valid networks list"
                        )

        restorevm = VirtualMachine.create(
            self.user_api_client,
            self.services["small"],
            networkids=vm1network.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
            mode=self.services['mode'],
            startvm="true"
        )


        time.sleep(600)

        list_vm_response = VirtualMachine.list(
                                            self.user_api_client,
                                            id=restorevm.id
                                            )
        self.assertEqual(
                            list_vm_response[0].state,
                            "Running",
                            "Check virtual machine is in running state"
                        )


        custom_disk_offering=DiskOffering.list(
                                self.user_api_client,
                                 name="custom"
                                 )

        newvolume = Volume.create(
            self.user_api_client,
            self.services["volume"],
            zoneid=self.zone.id,
            account=self.account.name,
            domainid=self.domain.id,
            diskofferingid=custom_disk_offering[0].id,
            size=1
        )

                # Attach volume to VM
        cmd = attachVolume.attachVolumeCmd()
        cmd.id = newvolume.id
        cmd.virtualmachineid = restorevm.id
        cmd.deviceid=1
        vol1=self.user_api_client.attachVolume(cmd)

        cmd = restoreVirtualMachine.restoreVirtualMachineCmd()
        cmd.virtualmachineid = restorevm.id
        cmd.templateid = self.xtemplate.id
        self.user_api_client.restoreVirtualMachine(cmd)

        time.sleep(600)

        list_vm_response = VirtualMachine.list(
                                            self.user_api_client,
                                            id=restorevm.id
                                            )
        self.assertEqual(
                            isinstance(list_vm_response, list),
                            True,
                            "Check list response returns a valid list"
                        )

        self.assertNotEqual(
                            len(list_vm_response),
                            0,
                            "Check VM available in List Virtual Machines"
                        )

        self.assertEqual(
                            list_vm_response[0].state,
                            "Running",
                            "Check virtual machine is in Stopped state"
                        )

        restorevm.delete(self.apiclient)

        vm1network.delete(self.user_api_client)

        return
    def test_19_template_tag(self):
        """ Test creation, listing and deletion tag on templates
        """

        try:
            
            noffering=NetworkOffering.list(
                     self.user_api_client,
                     name="DefaultIsolatedNetworkOfferingWithSourceNatService"
                     )
            vm4network=Network.create(
                                 self.user_api_client,
                                self.services["network"],
                                accountid=self.account.name,
                                domainid=self.account.domainid,
                                networkofferingid=noffering[0].id,
                                zoneid=self.zone.id
                                 )

            list_nw_response = Network.list(
                                            self.user_api_client,
                                            id=vm4network.id
                                            )
            self.assertEqual(
                            isinstance(list_nw_response, list),
                            True,
                            "Check list response returns a valid networks list"
                        )

            vm_1 = VirtualMachine.create(
                                    self.user_api_client,
                                    self.services["small"],
                                    templateid=self.template.id,
                                    networkids=vm4network.id,
                                    serviceofferingid=self.service_offering.id,
                                    accountid=self.account.name,
                                    domainid=self.account.domainid,
                                    mode=self.services['mode'],
                                    startvm="true"
                                    )
            time.sleep(600)
            self.debug("Stopping the virtual machine: %s" % vm_1.name)
            # Stop virtual machine
            vm_1.stop(self.user_api_client)
        except Exception as e:
            self.fail("Failed to stop VM: %s" % e)

        timeout = self.services["timeout"]
        while True:
            list_volume = Volume.list(
                self.user_api_client,
                virtualmachineid=vm_1.id,
                type='ROOT',
                listall=True
            )
            if isinstance(list_volume, list):
                break
            elif timeout == 0:
                raise Exception("List volumes failed.")

            time.sleep(5)
            timeout = timeout - 1

        self.volume = list_volume[0]

        self.debug("Creating template from ROOT disk of virtual machine: %s" %
                   vm_1.name)
        # Create template from volume
        template = Template.create(
            self.user_api_client,
            self.services["template"],
            self.volume.id
        )
        self.cleanup.append(template)
        self.debug("Created the template(%s). Now restarting the userVm: %s" %
                   (template.name, vm_1.name))
        vm_1.start(self.user_api_client)

        self.debug("Creating a tag for the template")
        tag = Tag.create(
            self.user_api_client,
            resourceIds=template.id,
            resourceType='Template',
            tags={'OS': 'windows8'}
        )
        self.debug("Tag created: %s" % tag.__dict__)

        tags = Tag.list(
            self.user_api_client,
            listall=True,
            resourceType='Template',
            key='OS',
            value='windows8'
        )
        self.assertEqual(
            isinstance(tags, list),
            True,
            "List tags should not return empty response"
        )
        self.assertEqual(
            tags[0].value,
            'windows8',
            'The tag should have original value'
        )

        Template.list(
            self.user_api_client,
            templatefilter=self.services["template"]["templatefilter"],
            listall=True,
            key='OS',
            value='windows8'
        )

        self.debug("Deleting the created tag..")
        try:
            tag.delete(
                self.user_api_client,
                resourceIds=template.id,
                resourceType='Template',
                tags={'OS': 'windows8'}
            )
        except Exception as e:
            self.fail("Failed to delete the tag - %s" % e)

        self.debug("Verifying if tag is actually deleted!")
        tags = Tag.list(
            self.user_api_client,
            listall=True,
            resourceType='Template',
            key='OS',
            value='windows8'
        )
        self.assertEqual(
            tags,
            None,
            "List tags should return empty response"
        )
        return
示例#12
0
    def test_01_redundant_vpc_site2site_vpn(self):
        """Test Site 2 Site VPN Across redundant VPCs"""
        self.logger.debug("Starting test: test_02_redundant_vpc_site2site_vpn")

        # 0) Get the default network offering for VPC
        networkOffering = NetworkOffering.list(
            self.apiclient, name="DefaultIsolatedNetworkOfferingForVpcNetworks")
        self.assert_(networkOffering is not None and len(
            networkOffering) > 0, "No VPC based network offering")

        # Create and enable redundant VPC offering
        redundant_vpc_offering = self._create_vpc_offering(
            'redundant_vpc_offering')
        self.assert_(redundant_vpc_offering is not None,
                     "Failed to create redundant VPC Offering")

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

        # Create VPC 1
        vpc1 = None
        try:
            vpc1 = VPC.create(
                apiclient=self.apiclient,
                services=self.services["vpc"],
                networkDomain="vpc1.vpn",
                vpcofferingid=redundant_vpc_offering.id,
                zoneid=self.zone.id,
                account=self.account.name,
                domainid=self.domain.id
            )
        except Exception as e:
            self.fail(e)
        finally:
            self.assert_(vpc1 is not None, "VPC1 creation failed")

        self.logger.debug("VPC1 %s created" % vpc1.id)

        # Create VPC 2
        vpc2 = None
        try:
            vpc2 = VPC.create(
                apiclient=self.apiclient,
                services=self.services["vpc2"],
                networkDomain="vpc2.vpn",
                vpcofferingid=redundant_vpc_offering.id,
                zoneid=self.zone.id,
                account=self.account.name,
                domainid=self.account.domainid
            )
        except Exception as e:
            self.fail(e)
        finally:
            self.assert_(vpc2 is not None, "VPC2 creation failed")

        self.logger.debug("VPC2 %s created" % vpc2.id)

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

        # Create network in VPC 1
        ntwk1 = None
        try:
            ntwk1 = Network.create(
                apiclient=self.apiclient,
                services=self.services["network_1"],
                accountid=self.account.name,
                domainid=self.account.domainid,
                networkofferingid=networkOffering[0].id,
                zoneid=self.zone.id,
                vpcid=vpc1.id,
                aclid=default_acl.id
            )
        except Exception as e:
            self.fail(e)
        finally:
            self.assertIsNotNone(ntwk1, "Network failed to create")

        self.logger.debug("Network %s created in VPC %s" % (ntwk1.id, vpc1.id))

        # Create network in VPC 2
        ntwk2 = None
        try:
            ntwk2 = Network.create(
                apiclient=self.apiclient,
                services=self.services["network_2"],
                accountid=self.account.name,
                domainid=self.account.domainid,
                networkofferingid=networkOffering[0].id,
                zoneid=self.zone.id,
                vpcid=vpc2.id,
                aclid=default_acl.id
            )
        except Exception as e:
            self.fail(e)
        finally:
            self.assertIsNotNone(ntwk2, "Network failed to create")

        self.logger.debug("Network %s created in VPC %s" % (ntwk2.id, vpc2.id))

        # Deploy a vm in network 2
        vm1 = None
        try:
            vm1 = 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.compute_offering.id,
                                        networkids=ntwk1.id,
                                        hypervisor=self.hypervisor
                                        )
        except Exception as e:
            self.fail(e)
        finally:
            self.assert_(vm1 is not None, "VM failed to deploy")
            self.assert_(vm1.state == 'Running', "VM is not running")

        self.logger.debug("VM %s deployed in VPC %s" % (vm1.id, vpc1.id))

        # Deploy a vm in network 2
        vm2 = None
        try:
            vm2 = 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.compute_offering.id,
                                        networkids=ntwk2.id,
                                        hypervisor=self.hypervisor
                                        )
        except Exception as e:
            self.fail(e)
        finally:
            self.assert_(vm2 is not None, "VM failed to deploy")
            self.assert_(vm2.state == 'Running', "VM is not running")

        self.debug("VM %s deployed in VPC %s" % (vm2.id, vpc2.id))

        # 4) Enable Site-to-Site VPN for VPC
        vpn1_response = Vpn.createVpnGateway(self.apiclient, vpc1.id)
        self.assert_(
            vpn1_response is not None, "Failed to enable VPN Gateway 1")
        self.logger.debug("VPN gateway for VPC %s enabled" % vpc1.id)

        vpn2_response = Vpn.createVpnGateway(self.apiclient, vpc2.id)
        self.assert_(
            vpn2_response is not None, "Failed to enable VPN Gateway 2")
        self.logger.debug("VPN gateway for VPC %s enabled" % vpc2.id)

        # 5) Add VPN Customer gateway info
        src_nat_list = PublicIPAddress.list(
            self.apiclient,
            account=self.account.name,
            domainid=self.account.domainid,
            listall=True,
            issourcenat=True,
            vpcid=vpc1.id
        )
        ip1 = src_nat_list[0]
        src_nat_list = PublicIPAddress.list(
            self.apiclient,
            account=self.account.name,
            domainid=self.account.domainid,
            listall=True,
            issourcenat=True,
            vpcid=vpc2.id
        )
        ip2 = src_nat_list[0]

        services = self.services["vpncustomergateway"]
        customer1_response = VpnCustomerGateway.create(
            self.apiclient, services, "Peer VPC1", ip1.ipaddress, vpc1.cidr, self.account.name, self.domain.id)
        self.debug("VPN customer gateway added for VPC %s enabled" % vpc1.id)
        self.logger.debug(vars(customer1_response))

        customer2_response = VpnCustomerGateway.create(
            self.apiclient, services, "Peer VPC2", ip2.ipaddress, vpc2.cidr, self.account.name, self.domain.id)
        self.debug("VPN customer gateway added for VPC %s enabled" % vpc2.id)
        self.logger.debug(vars(customer2_response))

        # 6) Connect two VPCs
        vpnconn1_response = Vpn.createVpnConnection(
            self.apiclient, customer1_response.id, vpn2_response['id'], True)
        self.debug("VPN passive connection created for VPC %s" % vpc2.id)

        vpnconn2_response = Vpn.createVpnConnection(
            self.apiclient, customer2_response.id, vpn1_response['id'])
        self.debug("VPN connection created for VPC %s" % vpc1.id)

        self.assertEqual(
            vpnconn2_response['state'], "Connected", "Failed to connect between VPCs!")

        # acquire an extra ip address to use to ssh into vm2
        try:
            vm2.public_ip = PublicIPAddress.create(
                apiclient=self.apiclient,
                accountid=self.account.name,
                zoneid=self.zone.id,
                domainid=self.account.domainid,
                services=self.services,
                networkid=ntwk2.id,
                vpcid=vpc2.id)
        except Exception as e:
            self.fail(e)
        finally:
            self.assert_(
                vm2.public_ip is not None, "Failed to aqcuire public ip for vm2")

        # Create port forward to be able to ssh into vm2
        natrule = None
        try:
            natrule = self._create_natrule(
                vpc2, vm2, 22, 22, vm2.public_ip, ntwk2)
        except Exception as e:
            self.fail(e)
        finally:
            self.assert_(
                natrule is not None, "Failed to create portforward for vm2")
            time.sleep(20)

        # setup ssh connection to vm2
        ssh_client = self._get_ssh_client(vm2, self.services, 10)

        if ssh_client:
            # run ping test
            packet_loss = ssh_client.execute(
                "/bin/ping -c 3 -t 10 " + vm1.nic[0].ipaddress + " |grep packet|cut -d ' ' -f 7| cut -f1 -d'%'")[0]
            self.assert_(int(packet_loss) == 0, "Ping did not succeed")
        else:
            self.fail("Failed to setup ssh connection to %s" % vm2.public_ip)
示例#13
0
    def test_01_vpc_remote_access_vpn(self):
        """Test Remote Access VPN in VPC"""

        self.logger.debug("Starting test: test_01_vpc_remote_access_vpn")

        # 0) Get the default network offering for VPC
        self.logger.debug("Retrieving default VPC offering")
        networkOffering = NetworkOffering.list(
            self.apiclient, name="DefaultIsolatedNetworkOfferingForVpcNetworks")
        self.assert_(networkOffering is not None and len(
            networkOffering) > 0, "No VPC based network offering")

        # 1) Create VPC
        vpcOffering = VpcOffering.list(self.apiclient, name="Default VPC offering")
        self.assert_(vpcOffering is not None and len(
            vpcOffering) > 0, "No VPC offerings found")

        vpc = None
        try:
            vpc = VPC.create(
                apiclient=self.apiclient,
                services=self.services["vpc"],
                networkDomain="vpc.vpn",
                vpcofferingid=vpcOffering[0].id,
                zoneid=self.zone.id,
                account=self.account.name,
                domainid=self.domain.id
            )
        except Exception as e:
            self.fail(e)
        finally:
            self.assert_(vpc is not None, "VPC creation failed")
            self.logger.debug("VPC %s created" % (vpc.id))

        try:
            # 2) Create network in VPC
            ntwk = Network.create(
                apiclient=self.apiclient,
                services=self.services["network_1"],
                accountid=self.account.name,
                domainid=self.domain.id,
                networkofferingid=networkOffering[0].id,
                zoneid=self.zone.id,
                vpcid=vpc.id
            )
        except Exception as e:
            self.fail(e)
        finally:
            self.assertIsNotNone(ntwk, "Network failed to create")
            self.logger.debug(
                "Network %s created in VPC %s" % (ntwk.id, vpc.id))

        try:
            # 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.compute_offering.id,
                                       networkids=ntwk.id,
                                       hypervisor=self.hypervisor
                                       )
            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))
        except Exception as e:
            self.fail(e)
        finally:
            self.logger.debug("Deployed virtual machine: OK")

        try:
            # 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]
        except Exception as e:
            self.fail(e)
        finally:
            self.logger.debug("Acquired public ip address: OK")

        try:
            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"]
                             )
        except Exception as e:
            self.fail(e)
        finally:
            self.assertIsNotNone(vpn, "Failed to create Remote Access VPN")
            self.logger.debug("Created Remote Access VPN: OK")

        vpnUser = None
        # 5) Add VPN user for VPC
        try:
            vpnUser = VpnUser.create(self.apiclient,
                                     account=self.account.name,
                                     domainid=self.account.domainid,
                                     username=self.services["vpn"]["vpn_user"],
                                     password=self.services["vpn"]["vpn_pass"]
                                     )
        except Exception as e:
            self.fail(e)
        finally:
            self.assertIsNotNone(
                vpnUser, "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

        try:
            # 9) Disable VPN for VPC
            vpn.delete(self.apiclient)
        except Exception as e:
            self.fail(e)
        finally:
            self.logger.debug("Deleted the Remote Access VPN: OK")
 def test_03_network_off_CS5332(self):
     """
     @Desc: Test Network offering with Custom system offering for VR
     @Steps:
     Step1: Create new system offering for domain router
     Step2: Verify the custom system offering creation for domain router
     Step3: Create new network offering with domain router system offering created in step1
     Step4: Verify the network offering creation with custom system offering for VR
     Step5: Enable the network offering created in step3
     Step5: Create isolated guest network using network offering created in step3
     Step6: Deploy guest vm in network created above
     """
     #create custom system offering for VR
     self.services["service_offering"]["name"] = "test_service_offering_for_router"
     self.services["service_offering"]["displaytext"] = "test_service_offering_for_router"
     self.services["service_offering"]["cpuspeed"] = 500
     self.services["service_offering"]["memory"] = 512
     self.services["service_offering"]["systemvmtype"] = "domainrouter"
     self.services["service_offering"]["storagetype"] = "shared"
     self.services["service_offering"]["issystem"] = "true"
     vr_sys_off = ServiceOffering.create(
                                         self.apiclient,
                                         self.services["service_offering"],
                                         )
     self.assertIsNotNone(
                          vr_sys_off,
                          "Failed to create custom system offering for VR"
                          )
     vr_sys_off_res = ServiceOffering.list(
                                           self.apiclient,
                                           id = vr_sys_off.id,
                                           issystem = "true"
                                           )
     status = validateList(vr_sys_off_res)
     self.assertEquals(
         PASS,
         status[0],
         "Listing of VR system offering failed"
     )
     self.assertEqual(
                      len(vr_sys_off_res),
                      1,
                      "Listing more than VR system offerings created"
     )
     self.debug("Created system offering with id %s" % vr_sys_off.id)
     # Create a network offering with all virtual router services enabled using custom system offering for VR
     self.debug(
         "Creating n/w offering with all services in VR & using custom system offering for VR"
     )
     self.network_offering = NetworkOffering.create(
                                               self.apiclient,
                                               self.services["network_offering"],
                                               conservemode=False,
                                               serviceofferingid=vr_sys_off.id
                                               )
     self.assertIsNotNone(
                          self.network_offering,
                          "Failed to create network offering with custom system offering for VR"
                          )
     network_off_res = NetworkOffering.list(
                                            self.apiclient,
                                            id=self.network_offering.id
                                            )
     status = validateList(network_off_res)
     self.assertEquals(
                       PASS,
                       status[0],
                       "Listing of network offerings failed"
     )
     self.assertEquals(
                       len(network_off_res),
                       1,
                       "More than one network offerings are created"
     )
     self.assertEquals(
                       network_off_res[0].serviceofferingid,
                       vr_sys_off.id,
                       "FAIL: Network offering has been created with default system offering"
     )
     self.cleanup.append(self.network_offering)
     self.cleanup.append(vr_sys_off)
     self.debug("Created n/w offering with ID: %s" % self.network_offering.id)
     # Enable Network offering
     self.network_offering.update(self.apiclient, state='Enabled')
     # 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.assertIsNotNone(self.network,"Failed to create network")
     self.debug("Created network with ID: %s" % self.network.id)
     self.debug("Deploying VM in account: %s" % self.account.name)
     # Spawn an instance in that network
     virtual_machine = VirtualMachine.create(
                                             self.apiclient,
                                             self.services["virtual_machine"],
                                             accountid=self.account.name,
                                             domainid=self.account.domainid,
                                             serviceofferingid=self.service_offering.id,
                                             networkids=[str(self.network.id)]
                                             )
     self.assertIsNotNone(
                          virtual_machine,
                          "VM creation failed with network %s" % self.network.id
                          )
     self.debug("Deployed VM in network: %s" % self.network.id)
     return
    def test_16_create_template_volume(self):
        """Test Create template from volume
        """

        noffering = NetworkOffering.list(
            self.user_api_client,
            name="DefaultIsolatedNetworkOfferingWithSourceNatService")
        vm2network = Network.create(self.user_api_client,
                                    self.services["network"],
                                    accountid=self.account.name,
                                    domainid=self.account.domainid,
                                    networkofferingid=noffering[0].id,
                                    zoneid=self.zone.id)

        list_nw_response = Network.list(self.user_api_client, id=vm2network.id)
        self.assertEqual(isinstance(list_nw_response, list), True,
                         "Check list response returns a valid networks list")

        templatevm = VirtualMachine.create(
            self.user_api_client,
            self.services["small"],
            templateid=self.template.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            networkids=vm2network.id,
            serviceofferingid=self.service_offering.id,
            mode=self.services['mode'],
            startvm="true")
        time.sleep(600)
        vm_response = VirtualMachine.list(self.user_api_client,
                                          id=templatevm.id)

        self.assertNotEqual(len(vm_response), 0,
                            "Check VMs available in List VMs response")
        vm = vm_response[0]
        self.assertEqual(vm.state, 'Running',
                         "Check the state of VM created from Template")

        templatevm.stop(self.user_api_client, forced="false")

        vm_response = VirtualMachine.list(self.user_api_client,
                                          id=templatevm.id)

        vm = vm_response[0]
        self.assertEqual(
            vm.state, 'Stopped',
            "Check the state of VM is in Stopped state before creating the Template"
        )

        list_volume_response = Volume.list(self.user_api_client,
                                           virtualmachineid=vm.id,
                                           type="ROOT",
                                           listall=True)

        #Create template from Virtual machine and Volume ID
        roottemplate = Template.create(
            self.user_api_client,
            self.services["interop"]["template"],
            volumeid=list_volume_response[0].id,
            account=self.account.name,
            domainid=self.domain.id,
        )

        time.sleep(600)

        list_template_response = Template.list(
                                    self.user_api_client,
                                    templatefilter=\
                                    self.services["templatefilter"],
                                    id=roottemplate.id
                                    )

        self.assertEqual(isinstance(list_template_response, list), True,
                         "Check list response returns a valid list")
        #Verify template response to check whether template added successfully
        self.assertNotEqual(len(list_template_response), 0,
                            "Check template available in List Templates")
        template_response = list_template_response[0]

        self.assertEqual(template_response.displaytext,
                         self.services["interop"]["template"]["displaytext"],
                         "Check display text of newly created template")
        name = template_response.name
        self.assertEqual(
            name.count(self.services["interop"]["template"]["name"]), 1,
            "Check name of newly created template")

        templatevm.delete(self.apiclient)
        vm2network.delete(self.user_api_client)

        vm3network = Network.create(self.user_api_client,
                                    self.services["network"],
                                    accountid=self.account.name,
                                    domainid=self.account.domainid,
                                    networkofferingid=noffering[0].id,
                                    zoneid=self.zone.id)

        list_nw_response = Network.list(self.user_api_client, id=vm3network.id)
        self.assertEqual(isinstance(list_nw_response, list), True,
                         "Check list response returns a valid networks list")

        templatevm = VirtualMachine.create(
            self.user_api_client,
            self.services["small"],
            templateid=roottemplate.id,
            networkids=vm3network.id,
            serviceofferingid=self.service_offering.id,
            accountid=self.account.name,
            domainid=self.account.domainid,
            mode=self.services['mode'],
            startvm="true")
        time.sleep(600)
        vm_response = VirtualMachine.list(self.user_api_client,
                                          id=templatevm.id)

        self.assertNotEqual(len(vm_response), 0,
                            "Check VMs available in List VMs response")
        vm = vm_response[0]
        self.assertEqual(vm.state, 'Running',
                         "Check the state of VM created from Template")

        # Delete the template
        roottemplate.delete(self.user_api_client)

        list_template_response = Template.list(
                                    self.user_api_client,
                                    templatefilter=\
                                    self.services["template"]["templatefilter"],
                                    id=roottemplate.id,
                                    zoneid=self.zone.id
                                    )
        self.assertEqual(list_template_response, None,
                         "Check template available in List Templates")

        templatevm.delete(self.apiclient)

        vm3network.delete(self.user_api_client)
        return
示例#16
0
    def test_downgradeRvR_to_VR(self):
        """Test downgrade redundant virtual router to virtual router
        """

        # Steps to validate
        # 1. create a network Offering that has redundant router enabled and
        #    all VR based services
        # 2. create a network with above offering
        # 3. deploy a VM in the above network and listRouters
        # 4. create a network Offering that has redundant router disabled and
        #    all VR based services
        # 5. updateNetwork - downgrade - created above to the offfering in 4.
        # 6. listRouters in the network
        # 7. delete account in which resources are created
        # Validate the following
        # 1. listNetworkOfferings should show craeted offering for RvR
        # 2. listNetworks should show the created network in allocated state
        # 3. VM should be deployed and in Running state and there should be
        #    two routers (MASTER and BACKUP) for this network
        # 4. listNetworkOfferings should show craeted offering for VR
        # 5. listNetworks shows the network still successfully implemented
        # 6. listRouters shows only one router for this network in Running

        # 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"],
                                 accountid=self.account.name,
                                 domainid=self.account.domainid,
                                 networkofferingid=self.network_offering.id,
                                 zoneid=self.zone.id)
        self.debug("Created network with ID: %s" % network.id)

        networks = Network.list(self.apiclient, id=network.id, listall=True)
        self.assertEqual(
            isinstance(networks, list), True,
            "List networks should return a valid response for created network")
        nw_response = networks[0]

        self.debug("Network state: %s" % nw_response.state)
        self.assertEqual(
            nw_response.state, "Allocated",
            "The network should be in allocated state after creation")

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

        # Spawn an instance in that network
        virtual_machine = VirtualMachine.create(
            self.apiclient,
            self.services["virtual_machine"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
            networkids=[str(network.id)])
        self.debug("Deployed VM in the account: %s" % self.account.name)

        vms = VirtualMachine.list(self.apiclient,
                                  id=virtual_machine.id,
                                  listall=True)
        self.assertEqual(isinstance(vms, list), True,
                         "List Vms should return a valid list")
        vm = vms[0]
        self.assertEqual(vm.state, "Running",
                         "Vm should be in running state after deployment")

        self.debug("Listing routers for account: %s" % self.account.name)
        routers = Router.list(self.apiclient,
                              account=self.account.name,
                              domainid=self.account.domainid,
                              listall=True)
        self.assertEqual(isinstance(routers, list), True,
                         "list router should return two routers")
        self.assertEqual(
            len(routers), 2,
            "Length of the list router should be 2 (MASTER & BACKUP)")

        network_offerings = NetworkOffering.list(
            self.apiclient,
            name='DefaultIsolatedNetworkOfferingWithSourceNatService',
            listall=True)
        self.assertEqual(
            isinstance(network_offerings, list), True,
            "List network offering should not return empty response")

        network_off_vr = network_offerings[0]

        self.debug("Upgrading the network to RVR network offering..")
        try:
            network.update(self.apiclient, networkofferingid=network_off_vr.id)
        except Exception as e:
            self.fail("Failed to upgrade the network from VR to RVR: %s" % e)

        self.debug("Listing routers for account: %s" % self.account.name)
        routers = Router.list(self.apiclient,
                              account=self.account.name,
                              domainid=self.account.domainid,
                              listall=True)
        self.assertEqual(isinstance(routers, list), True,
                         "list router should return only one router")
        self.assertEqual(len(routers), 1,
                         "Length of the list router should be 1")
        return
    def test_downgradeRvR_to_VR(self):
        """Test downgrade redundant virtual router to virtual router
        """

        # Steps to validate
        # 1. create a network Offering that has redundant router enabled and
        #    all VR based services
        # 2. create a network with above offering
        # 3. deploy a VM in the above network and listRouters
        # 4. create a network Offering that has redundant router disabled and
        #    all VR based services
        # 5. updateNetwork - downgrade - created above to the offfering in 4.
        # 6. listRouters in the network
        # 7. delete account in which resources are created
        # Validate the following
        # 1. listNetworkOfferings should show craeted offering for RvR
        # 2. listNetworks should show the created network in allocated state
        # 3. VM should be deployed and in Running state and there should be
        #    two routers (MASTER and BACKUP) for this network
        # 4. listNetworkOfferings should show craeted offering for VR
        # 5. listNetworks shows the network still successfully implemented
        # 6. listRouters shows only one router for this network in Running

        # 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"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            networkofferingid=self.network_offering.id,
            zoneid=self.zone.id
        )
        self.debug("Created network with ID: %s" % network.id)

        networks = Network.list(
            self.apiclient,
            id=network.id,
            listall=True
        )
        self.assertEqual(
            isinstance(networks, list),
            True,
            "List networks should return a valid response for created network"
        )
        nw_response = networks[0]

        self.debug("Network state: %s" % nw_response.state)
        self.assertEqual(
            nw_response.state,
            "Allocated",
            "The network should be in allocated state after creation"
        )

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

        # Spawn an instance in that network
        virtual_machine = VirtualMachine.create(
            self.apiclient,
            self.services["virtual_machine"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            serviceofferingid=self.service_offering.id,
            networkids=[str(network.id)]
        )
        self.debug("Deployed VM in the account: %s" %
                   self.account.name)

        vms = VirtualMachine.list(
            self.apiclient,
            id=virtual_machine.id,
            listall=True
        )
        self.assertEqual(
            isinstance(vms, list),
            True,
            "List Vms should return a valid list"
        )
        vm = vms[0]
        self.assertEqual(
            vm.state,
            "Running",
            "Vm should be in running state after deployment"
        )

        self.debug("Listing routers for account: %s" %
                   self.account.name)
        routers = Router.list(
            self.apiclient,
            account=self.account.name,
            domainid=self.account.domainid,
            listall=True
        )
        self.assertEqual(
            isinstance(routers, list),
            True,
            "list router should return two routers"
        )
        self.assertEqual(
            len(routers),
            2,
            "Length of the list router should be 2 (MASTER & BACKUP)"
        )

        network_offerings = NetworkOffering.list(
            self.apiclient,
            name='DefaultIsolatedNetworkOfferingWithSourceNatService',
            listall=True
        )
        self.assertEqual(
            isinstance(network_offerings, list),
            True,
            "List network offering should not return empty response"
        )

        network_off_vr = network_offerings[0]

        self.debug("Upgrading the network to RVR network offering..")
        try:
            network.update(
                self.apiclient,
                networkofferingid=network_off_vr.id
            )
        except Exception as e:
            self.fail("Failed to upgrade the network from VR to RVR: %s" % e)

        self.debug("Listing routers for account: %s" %
                   self.account.name)
        routers = Router.list(
            self.apiclient,
            account=self.account.name,
            domainid=self.account.domainid,
            listall=True
        )
        self.assertEqual(
            isinstance(routers, list),
            True,
            "list router should return only one router"
        )
        self.assertEqual(
            len(routers),
            1,
            "Length of the list router should be 1"
        )
        return
示例#18
0
    def test_vpc_remote_access_vpn(self):
        """Test Remote Access VPN in VPC"""

        # 0) Get the default network offering for VPC
        self.logger.debug("Retrieving default VPC offering")
        networkOffering = NetworkOffering.list(
            self.apiclient,
            name="DefaultIsolatedNetworkOfferingForVpcNetworks")
        self.assert_(networkOffering is not None and len(networkOffering) > 0,
                     "No VPC based network offering")

        # 1) Create VPC
        vpcOffering = VpcOffering.list(self.apiclient, isdefault=True)
        self.assert_(vpcOffering is not None and len(vpcOffering) > 0,
                     "No VPC offerings found")

        try:
            vpc = VPC.create(apiclient=self.apiclient,
                             services=self.services["vpc"],
                             networkDomain="vpc.vpn",
                             vpcofferingid=vpcOffering[0].id,
                             zoneid=self.zone.id,
                             account=self.account.name,
                             domainid=self.domain.id)
        except Exception as e:
            self.fail(e)
        finally:
            self.assert_(vpc is not None, "VPC creation failed")
            self.logger.debug("VPC %s created" % (vpc.id))

        try:
            # 2) Create network in VPC
            ntwk = Network.create(apiclient=self.apiclient,
                                  services=self.services["network_1"],
                                  accountid=self.account.name,
                                  domainid=self.domain.id,
                                  networkofferingid=networkOffering[0].id,
                                  zoneid=self.zone.id,
                                  vpcid=vpc.id)
        except Exception as e:
            self.fail(e)
        finally:
            self.assertIsNotNone(ntwk, "Network failed to create")
            self.logger.debug("Network %s created in VPC %s" %
                              (ntwk.id, vpc.id))

        try:
            # 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.compute_offering.id,
                networkids=ntwk.id,
                hypervisor=self.services["virtual_machine"]["hypervisor"])
            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))
        except Exception as e:
            self.fail(e)
        finally:
            self.logger.debug("Deployed virtual machine: OK")

        try:
            # 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]
        except Exception as e:
            self.fail(e)
        finally:
            self.logger.debug("Acquired public ip address: OK")

        try:
            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"])
        except Exception as e:
            self.fail(e)
        finally:
            self.assertIsNotNone(vpn, "Failed to create Remote Access VPN")
            self.logger.debug("Created Remote Access VPN: OK")

        vpnUser = None
        # 5) Add VPN user for VPC
        try:
            vpnUser = VpnUser.create(self.apiclient,
                                     account=self.account.name,
                                     domainid=self.account.domainid,
                                     username=self.services["vpn"]["vpn_user"],
                                     password=self.services["vpn"]["vpn_pass"])
        except Exception as e:
            self.fail(e)
        finally:
            self.assertIsNotNone(vpnUser,
                                 "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

        try:
            # 9) Disable VPN for VPC
            vpn.delete(self.apiclient)
        except Exceptio as e:
            self.fail(e)
        finally:
            self.logger.debug("Deleted the Remote Access VPN: OK")
示例#19
0
    def test_vpc_site2site_vpn(self):
        """Test VPN in VPC"""

        # 0) Get the default network offering for VPC
        networkOffering = NetworkOffering.list(
            self.apiclient,
            name="DefaultIsolatedNetworkOfferingForVpcNetworks")
        self.assert_(networkOffering is not None and len(networkOffering) > 0,
                     "No VPC based network offering")

        # 1) Create VPC offering
        vpcOffering = VpcOffering.list(self.apiclient, isdefault=True)
        self.assert_(vpcOffering is not None and len(vpcOffering) > 0,
                     "No VPC offerings found")

        # Create VPC 1
        try:
            vpc1 = VPC.create(apiclient=self.apiclient,
                              services=self.services["vpc"],
                              networkDomain="vpc1.vpn",
                              vpcofferingid=vpcOffering[0].id,
                              zoneid=self.zone.id,
                              account=self.account.name,
                              domainid=self.domain.id)
        except Exception as e:
            self.fail(e)
        finally:
            self.assert_(vpc1 is not None, "VPC1 creation failed")

        self.logger.debug("VPC1 %s created" % (vpc1.id))

        # Create VPC 2
        try:
            vpc2 = VPC.create(apiclient=self.apiclient,
                              services=self.services["vpc2"],
                              networkDomain="vpc2.vpn",
                              vpcofferingid=vpcOffering[0].id,
                              zoneid=self.zone.id,
                              account=self.account.name,
                              domainid=self.account.domainid)
        except Exception as e:
            self.fail(e)
        finally:
            self.assert_(vpc2 is not None, "VPC2 creation failed")

        self.logger.debug("VPC2 %s created" % (vpc2.id))

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

        # Create network in VPC 1
        try:
            ntwk1 = Network.create(apiclient=self.apiclient,
                                   services=self.services["network_1"],
                                   accountid=self.account.name,
                                   domainid=self.account.domainid,
                                   networkofferingid=networkOffering[0].id,
                                   zoneid=self.zone.id,
                                   vpcid=vpc1.id,
                                   aclid=default_acl.id)
        except Exception as e:
            self.fail(e)
        finally:
            self.assertIsNotNone(ntwk1, "Network failed to create")

        self.logger.debug("Network %s created in VPC %s" % (ntwk1.id, vpc1.id))

        # Create network in VPC 2
        try:
            ntwk2 = Network.create(apiclient=self.apiclient,
                                   services=self.services["network_2"],
                                   accountid=self.account.name,
                                   domainid=self.account.domainid,
                                   networkofferingid=networkOffering[0].id,
                                   zoneid=self.zone.id,
                                   vpcid=vpc2.id,
                                   aclid=default_acl.id)
        except Exception as e:
            self.fail(e)
        finally:
            self.assertIsNotNone(ntwk2, "Network failed to create")

        self.logger.debug("Network %s created in VPC %s" % (ntwk2.id, vpc2.id))

        # Deploy a vm in network 2
        try:
            vm1 = 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.service_offering.id,
                networkids=ntwk1.id,
                hypervisor=self.services["virtual_machine"]["hypervisor"])
        except Exception as e:
            self.fail(e)
        finally:
            self.assert_(vm1 is not None, "VM failed to deploy")
            self.assert_(vm1.state == 'Running', "VM is not running")

        self.logger.debug("VM %s deployed in VPC %s" % (vm1.id, vpc1.id))

        # Deploy a vm in network 2
        try:
            vm2 = 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.service_offering.id,
                networkids=ntwk2.id,
                hypervisor=self.services["virtual_machine"]["hypervisor"])
        except Exception as e:
            self.fail(e)
        finally:
            self.assert_(vm2 is not None, "VM failed to deploy")
            self.assert_(vm2.state == 'Running', "VM is not running")

        self.debug("VM %s deployed in VPC %s" % (vm2.id, vpc2.id))

        # 4) Enable Site-to-Site VPN for VPC
        vpn1_response = Vpn.createVpnGateway(self.apiclient, vpc1.id)
        self.assert_(vpn1_response is not None,
                     "Failed to enable VPN Gateway 1")
        self.logger.debug("VPN gateway for VPC %s enabled" % vpc1.id)

        vpn2_response = Vpn.createVpnGateway(self.apiclient, vpc2.id)
        self.assert_(vpn2_response is not None,
                     "Failed to enable VPN Gateway 2")
        self.logger.debug("VPN gateway for VPC %s enabled" % vpc2.id)

        # 5) Add VPN Customer gateway info
        src_nat_list = PublicIPAddress.list(self.apiclient,
                                            account=self.account.name,
                                            domainid=self.account.domainid,
                                            listall=True,
                                            issourcenat=True,
                                            vpcid=vpc1.id)
        ip1 = src_nat_list[0]
        src_nat_list = PublicIPAddress.list(self.apiclient,
                                            account=self.account.name,
                                            domainid=self.account.domainid,
                                            listall=True,
                                            issourcenat=True,
                                            vpcid=vpc2.id)
        ip2 = src_nat_list[0]

        services = self.services["vpncustomergateway"]
        customer1_response = VpnCustomerGateway.create(
            self.apiclient, services, "Peer VPC1", ip1.ipaddress, vpc1.cidr,
            self.account.name, self.domain.id)
        self.debug("VPN customer gateway added for VPC %s enabled" % vpc1.id)
        self.logger.debug(vars(customer1_response))

        customer2_response = VpnCustomerGateway.create(
            self.apiclient, services, "Peer VPC2", ip2.ipaddress, vpc2.cidr,
            self.account.name, self.domain.id)
        self.debug("VPN customer gateway added for VPC %s enabled" % vpc2.id)
        self.logger.debug(vars(customer2_response))

        # 6) Connect two VPCs
        vpnconn1_response = Vpn.createVpnConnection(self.apiclient,
                                                    customer1_response.id,
                                                    vpn2_response['id'], True)
        self.debug("VPN passive connection created for VPC %s" % vpc2.id)

        vpnconn2_response = Vpn.createVpnConnection(self.apiclient,
                                                    customer2_response.id,
                                                    vpn1_response['id'])
        self.debug("VPN connection created for VPC %s" % vpc1.id)

        self.assertEqual(vpnconn2_response['state'], "Connected",
                         "Failed to connect between VPCs!")

        # acquire an extra ip address to use to ssh into vm2
        try:
            vm2.public_ip = PublicIPAddress.create(
                apiclient=self.apiclient,
                accountid=self.account.name,
                zoneid=self.zone.id,
                domainid=self.account.domainid,
                services=self.services,
                networkid=ntwk2.id,
                vpcid=vpc2.id)
        except Exception as e:
            self.fail(e)
        finally:
            self.assert_(vm2.public_ip is not None,
                         "Failed to aqcuire public ip for vm2")

        # Create port forward to be able to ssh into vm2
        try:
            natrule = self.create_natrule(vpc2, vm2, 22, 22, vm2.public_ip,
                                          ntwk2)
        except Exception as e:
            self.fail(e)
        finally:
            self.assert_(natrule is not None,
                         "Failed to create portforward for vm2")
            time.sleep(10)

        # setup ssh connection to vm2
        ssh_client = self.get_ssh_client(vm2, self.services, 10)

        if ssh_client:
            # run ping test
            packet_loss = ssh_client.execute(
                "/bin/ping -c 3 -t 10 " + vm1.nic[0].ipaddress +
                " |grep packet|cut -d ' ' -f 7| cut -f1 -d'%'")[0]
            self.assert_(int(packet_loss) == 0, "Ping did not succeed")
        else:
            self.fail("Failed to setup ssh connection to %s" % vm2.public_ip)
    def test_19_template_tag(self):
        """ Test creation, listing and deletion tag on templates
        """

        if self.hypervisor.lower() in ['lxc']:
            self.skipTest(
                "template creation from volume feature is not supported on %s"
                % self.hypervisor.lower())

        try:

            noffering = NetworkOffering.list(
                self.user_api_client,
                name="DefaultIsolatedNetworkOfferingWithSourceNatService")
            vm4network = Network.create(self.user_api_client,
                                        self.services["network"],
                                        accountid=self.account.name,
                                        domainid=self.account.domainid,
                                        networkofferingid=noffering[0].id,
                                        zoneid=self.zone.id)

            list_nw_response = Network.list(self.user_api_client,
                                            id=vm4network.id)
            self.assertEqual(
                isinstance(list_nw_response, list), True,
                "Check list response returns a valid networks list")

            vm_1 = VirtualMachine.create(
                self.user_api_client,
                self.services["small"],
                templateid=self.template.id,
                networkids=vm4network.id,
                serviceofferingid=self.service_offering.id,
                accountid=self.account.name,
                domainid=self.account.domainid,
                mode=self.services['mode'],
                startvm="true")
            time.sleep(600)
            self.debug("Stopping the virtual machine: %s" % vm_1.name)
            # Stop virtual machine
            vm_1.stop(self.user_api_client)
        except Exception as e:
            self.fail("Failed to stop VM: %s" % e)

        timeout = self.services["timeout"]
        while True:
            list_volume = Volume.list(self.user_api_client,
                                      virtualmachineid=vm_1.id,
                                      type='ROOT',
                                      listall=True)
            if isinstance(list_volume, list):
                break
            elif timeout == 0:
                raise Exception("List volumes failed.")

            time.sleep(5)
            timeout = timeout - 1

        self.volume = list_volume[0]

        self.debug("Creating template from ROOT disk of virtual machine: %s" %
                   vm_1.name)
        # Create template from volume
        template = Template.create(self.user_api_client,
                                   self.services["template"], self.volume.id)
        self.cleanup.append(template)
        self.debug("Created the template(%s). Now restarting the userVm: %s" %
                   (template.name, vm_1.name))
        vm_1.start(self.user_api_client)

        self.debug("Creating a tag for the template")
        tag = Tag.create(self.user_api_client,
                         resourceIds=template.id,
                         resourceType='Template',
                         tags={'OS': 'windows8'})
        self.debug("Tag created: %s" % tag.__dict__)

        tags = Tag.list(self.user_api_client,
                        listall=True,
                        resourceType='Template',
                        key='OS',
                        value='windows8')
        self.assertEqual(isinstance(tags, list), True,
                         "List tags should not return empty response")
        self.assertEqual(tags[0].value, 'windows8',
                         'The tag should have original value')

        Template.list(
            self.user_api_client,
            templatefilter=self.services["template"]["templatefilter"],
            listall=True,
            key='OS',
            value='windows8')

        self.debug("Deleting the created tag..")
        try:
            tag.delete(self.user_api_client,
                       resourceIds=template.id,
                       resourceType='Template',
                       tags={'OS': 'windows8'})
        except Exception as e:
            self.fail("Failed to delete the tag - %s" % e)

        self.debug("Verifying if tag is actually deleted!")
        tags = Tag.list(self.user_api_client,
                        listall=True,
                        resourceType='Template',
                        key='OS',
                        value='windows8')
        self.assertEqual(tags, None, "List tags should return empty response")
        return
    def test_01_create_delete_portforwarding_fornonvpc(self):
        """
        @summary: Test to list, create and delete Port Forwarding for
        IP Address associated to Non VPC network
        @Steps:
        Step1: Creating a Network for the user
        Step2: Associating an IP Addresses for Network
        Step3: Launching Virtual Machine in network created in step 2
        Step4: Listing Port Forwarding Rules for the IP Address associated
               in Step2
        Step5: Verifying that no Port Forwarding Rules are listed
        Step6: Creating a Port Forwarding Rule for IP Address associated in
               Step2
        Step7: Listing Port Forwarding Rules for the IP Address associated in
               Step2
        Step8: Verifying 1 Port Forwarding Rule is listed
        Step9: Deleting the Port Forwarding Rule created in Step6
        Step10: Listing Port Forwarding Rules for the IP Address associated in
               Step2
        Step11: Verifying that no Port Forwarding Rules are listed
        """
        # Listing all the Networks's for a user
        list_networks_before = Network.list(
            self.userapiclient,
            listall=self.services["listall"],
            type="Isolated"
        )
        # Verifying No Networks are listed
        self.assertIsNone(
            list_networks_before,
            "Networks listed for newly created User"
        )
        # Listing Network Offerings
        network_offerings_list = NetworkOffering.list(
            self.apiClient,
            forvpc="false",
            guestiptype="Isolated",
            state="Enabled",
            supportedservices="SourceNat,PortForwarding",
            zoneid=self.zone.id
        )
        status = validateList(network_offerings_list)
        self.assertEqual(
            PASS,
            status[0],
            "Isolated Network Offerings with sourceNat,\
                    PortForwarding enabled are not found"
        )
        # Creating a network
        network = Network.create(
            self.userapiclient,
            self.services["network"],
            accountid=self.account.name,
            domainid=self.domain.id,
            networkofferingid=network_offerings_list[0].id,
            zoneid=self.zone.id
        )

        self.assertIsNotNone(
            network,
            "Network creation failed"
        )
        # Listing all the IP Addresses for a user
        list_ipaddresses_before = PublicIPAddress.list(
            self.userapiclient,
            listall=self.services["listall"]
        )
        # Verifying no IP Addresses are listed
        self.assertIsNone(
            list_ipaddresses_before,
            "IP Addresses listed for newly created User"
        )

        service_offering = ServiceOffering.create(
            self.apiClient,
            self.services["service_offerings"]["tiny"],
        )

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

        vm = VirtualMachine.create(
            self.userapiclient,
            self.services["virtual_machine"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            networkids=network.id,
            serviceofferingid=service_offering.id
        )

        VirtualMachine.delete(vm, self.apiClient, expunge=True)

        # Associating an IP Addresses to Network created
        associated_ipaddress = PublicIPAddress.create(
            self.userapiclient,
            services=self.services["network"],
            networkid=network.id
        )
        self.assertIsNotNone(
            associated_ipaddress,
            "Failed to Associate IP Address"
        )
        # Listing all the IP Addresses for a user
        list_ipaddresses_after = PublicIPAddress.list(
            self.userapiclient,
            listall=self.services["listall"]
        )
        status = validateList(list_ipaddresses_after)
        self.assertEqual(
            PASS,
            status[0],
            "IP Addresses Association Failed"
        )
        # Verifying the length of the list is 2
        self.assertEqual(
            2,
            len(list_ipaddresses_after),
            "Number of IP Addresses associated are not matching expected"
        )
        # Launching a Virtual Machine with above created Network
        vm_created = VirtualMachine.create(
            self.userapiclient,
            self.services["virtual_machine"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            networkids=network.id,
            serviceofferingid=self.service_offering.id,
        )
        self.assertIsNotNone(
            vm_created,
            "Failed to launch a VM under network created"
        )
        self.cleanup.append(network)
        # Listing Virtual Machines in running state in above created network
        list_vms_running = VirtualMachine.list(
            self.userapiclient,
            listall=self.services["listall"],
            state="Running",
            networkid=network.id
        )
        status = validateList(list_vms_running)
        self.assertEqual(
            PASS,
            status[0],
            "VM Created is not in Running state"
        )
        # Verifying the length of the list is 2
        self.assertEqual(
            2,
            len(list_ipaddresses_after),
            "VM Created is not in Running state"
        )
        self.assertEqual(
            vm_created.id,
            list_vms_running[0].id,
            "VM Created is not in Running state"
        )
        # Listing Virtual Machines in stopped state in above created network
        list_vms_stopped = VirtualMachine.list(
            self.userapiclient,
            listall=self.services["listall"],
            state="Stopped",
            networkid=network.id
        )
        # Verifying no VMs are in stopped state
        self.assertIsNone(
            list_vms_stopped,
            "VM Created is in stopped state"
        )
        # Listing Port Forwarding Rules for the IP Address associated
        list_prtfwdrule_before = NATRule.list(
            self.userapiclient,
            listall=self.services["listall"],
            ipaddressid=associated_ipaddress.ipaddress.id
        )
        # Verifying no port forwarding rules are listed
        self.assertIsNone(
            list_prtfwdrule_before,
            "Port Forwarding Rules listed for newly associated IP Address"
        )
        # Creating a Port Forwarding rule
        portfwd_rule = NATRule.create(
            self.userapiclient,
            virtual_machine=vm_created,
            services=self.services["natrule"],
            ipaddressid=associated_ipaddress.ipaddress.id,
        )
        self.assertIsNotNone(
            portfwd_rule,
            "Failed to create Port Forwarding Rule"
        )
        # Verifying details of Sticky Policy created
        # Creating expected and actual values dictionaries
        expected_dict = {
            "ipaddressid": associated_ipaddress.ipaddress.id,
            "privateport": str(self.services["natrule"]["privateport"]),
            "publicport": str(self.services["natrule"]["publicport"]),
            "protocol": str(self.services["natrule"]["protocol"]).lower(),
        }
        actual_dict = {
            "ipaddressid": portfwd_rule.ipaddressid,
            "privateport": str(portfwd_rule.privateport),
            "publicport": str(portfwd_rule.publicport),
            "protocol": portfwd_rule.protocol,
        }
        portfwd_status = self.__verify_values(
            expected_dict,
            actual_dict
        )
        self.assertEqual(
            True,
            portfwd_status,
            "Created Port Forward Rule details are not as expected"
        )
        # Listing Port Forwarding Rules for the IP Address associated
        list_prtfwdrule_after = NATRule.list(
            self.userapiclient,
            listall=self.services["listall"],
            ipaddressid=associated_ipaddress.ipaddress.id
        )
        status = validateList(list_prtfwdrule_after)
        self.assertEqual(
            PASS,
            status[0],
            "Failed to create Port Forwarding Rule"
        )
        # Verifying the length of the list is 1
        self.assertEqual(
            1,
            len(list_prtfwdrule_after),
            "Failed to create Port Forwarding Rule"
        )
        # Deleting Port Forwarding Rule
        portfwd_rule.delete(self.userapiclient)

        # Creating a Port Forwarding rule with port range
        portfwd_rule = NATRule.create(
            self.userapiclient,
            virtual_machine=vm_created,
            services=self.services["natrulerange"],
            ipaddressid=associated_ipaddress.ipaddress.id,
        )
        self.assertIsNotNone(
            portfwd_rule,
            "Failed to create Port Forwarding Rule"
        )
        # update the private port for port forwarding rule
        updatefwd_rule = portfwd_rule.update(self.userapiclient,
                                             portfwd_rule.id,
                                             virtual_machine=vm_created,
                                             services=self.services["updatenatrulerange"],
                                             )

        # Verifying details of Sticky Policy created
        # Creating expected and actual values dictionaries
        expected_dict = {
            "privateport": str(self.services["updatenatrulerange"]["privateport"]),
            "privateendport": str(self.services["updatenatrulerange"]["privateendport"]),
        }
        actual_dict = {
            "privateport": str(updatefwd_rule.privateport),
            "privateendport": str(updatefwd_rule.privateendport),
        }
        portfwd_status = self.__verify_values(
            expected_dict,
            actual_dict
        )
        self.assertEqual(
            True,
            portfwd_status,
            "Updated Port Forward Rule details are not as expected"
        )
        # Deleting Port Forwarding Rule
        portfwd_rule.delete(self.userapiclient)
        # Listing Port Forwarding Rules for the IP Address associated
        list_prtfwdrule_after = NATRule.list(
            self.userapiclient,
            listall=self.services["listall"],
            ipaddressid=associated_ipaddress.ipaddress.id
        )
        # Verifying no port forwarding rules are listed
        self.assertIsNone(
            list_prtfwdrule_after,
            "Port Forwarding Rules listed after deletion"
        )
        # Destroying the VM Launched
        vm_created.delete(self.apiClient)
        self.cleanup.append(self.account)
        return