def delete_network(self, network, apiclient, expected=True):
     result = True
     try:
         Network.delete(
             network,
             apiclient,
         )
     except Exception as ex:
         result = False
         if expected:
             self.fail(
                 f"Failed to remove Shared network, but expected to succeed : {ex}"
             )
     if result and not expected:
         self.fail("network is removed successfully, but expected to fail")
示例#2
0
    def test_network_vcs(self):
        """Test Brocade Network and VM Creation
        """

        # Validate the following
        # 1. Deploy the first VM using a network from the above created
        #    Network offering.
        # 2. Deploy another VM.
        # 3. Delete The VMs and the Network

        # Creating network using the network offering created
        self.debug("Creating network with network offering: %s" %
                   self.network_offering.id)
        self.network = Network.create(
            self.apiclient,
            self.services["network"],
            accountid=self.account.name,
            domainid=self.account.domainid,
            networkofferingid=self.network_offering.id,
            zoneid=self.zone.id)
        self.debug("Created network with ID: %s" % self.network.id)

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

        # Spawn an instance in that network
        virtual_machine_1 = 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.debug("Deployed VM in network: %s" % self.network.id)
        list_vm_response = VirtualMachine.list(self.apiclient,
                                               id=virtual_machine_1.id)

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

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

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

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

        # Spawn an instance in that network
        virtual_machine_2 = 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.debug("Deployed VM in network: %s" % self.network.id)
        list_vm_response = VirtualMachine.list(self.apiclient,
                                               id=virtual_machine_2.id)

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

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

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

        # Deleting a single VM
        VirtualMachine.delete(virtual_machine_1, self.apiclient, expunge=True)

        # Deleting a single VM
        VirtualMachine.delete(virtual_machine_2, self.apiclient, expunge=True)

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

        return
示例#3
0
    def test_network_vsp(self):
        """Test nuage Network and VM Creation
        """

        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,
            gateway = "10.1.1.1",
            netmask = '255.255.255.0'
        )
        self.debug("Created network with ID: %s" % self.network.id)

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

        virtual_machine_1 = 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.debug("Deployed VM in network: %s" % self.network.id)
        list_vm_response = VirtualMachine.list(
            self.apiclient,
            id=virtual_machine_1.id
        )

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

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

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

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

        virtual_machine_2 = 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.debug("Deployed VM in network: %s" % self.network.id)
        list_vm_response = VirtualMachine.list(
            self.apiclient,
            id=virtual_machine_2.id
        )

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

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

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

        VirtualMachine.delete(virtual_machine_1, self.apiclient, expunge=True)

        # # Deleting a single VM
        VirtualMachine.delete(virtual_machine_2, self.apiclient, expunge=True)

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

        return
    def test_network_vsp(self):
        """Test nuage Network and VM Creation
        """

        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,
            gateway="10.1.1.1",
            netmask='255.255.255.0')
        self.debug("Created network with ID: %s" % self.network.id)

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

        virtual_machine_1 = 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.debug("Deployed VM in network: %s" % self.network.id)
        list_vm_response = VirtualMachine.list(self.apiclient,
                                               id=virtual_machine_1.id)

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

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

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

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

        virtual_machine_2 = 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.debug("Deployed VM in network: %s" % self.network.id)
        list_vm_response = VirtualMachine.list(self.apiclient,
                                               id=virtual_machine_2.id)

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

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

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

        VirtualMachine.delete(virtual_machine_1, self.apiclient, expunge=True)

        # # Deleting a single VM
        VirtualMachine.delete(virtual_machine_2, self.apiclient, expunge=True)

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

        return
示例#5
0
    def test_network_vcs(self):
        """Test Brocade Network and VM Creation
        """


        # Validate the following
        # 1. Deploy the first VM using a network from the above created
        #    Network offering.
        # 2. Deploy another VM.
        # 3. Delete The VMs and the Network

        # Creating network using the network offering created
        self.debug("Creating network with network offering: %s" %
                                                    self.network_offering.id)
        self.network = Network.create(
                                    self.apiclient,
                                    self.services["network"],
                                    accountid=self.account.name,
                                    domainid=self.account.domainid,
                                    networkofferingid=self.network_offering.id,
                                    zoneid=self.zone.id
                                    )
        self.debug("Created network with ID: %s" % self.network.id)

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

        # Spawn an instance in that network
        virtual_machine_1 = 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.debug("Deployed VM in network: %s" % self.network.id)
        list_vm_response = VirtualMachine.list(
                                        self.apiclient,
                                        id=virtual_machine_1.id
                                        )

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

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

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

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

        # Spawn an instance in that network
        virtual_machine_2 = 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.debug("Deployed VM in network: %s" % self.network.id)
        list_vm_response = VirtualMachine.list(
                                        self.apiclient,
                                        id=virtual_machine_2.id
                                        )

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

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

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

        # Deleting a single VM
        VirtualMachine.delete(virtual_machine_1, self.apiclient, expunge=True)


        # Deleting a single VM
        VirtualMachine.delete(virtual_machine_2, self.apiclient, expunge=True)


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        src_nat = src_nat_list[0]

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

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

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

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

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

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

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

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

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

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

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

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

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

        return