def find_public_gateway(self):
        networks = list_networks(self.apiclient,
                                 zoneid=self.zone.id,
                                 listall=True,
                                 issystem=True,
                                 traffictype="Public")
        self.logger.debug('::: Public Networks ::: ==> %s' % networks)

        self.assertTrue(
            len(networks) == 1,
            "Test expects only 1 Public network but found -> '%s'" %
            len(networks))

        ip_ranges = list_vlan_ipranges(self.apiclient,
                                       zoneid=self.zone.id,
                                       networkid=networks[0].id)
        self.logger.debug('::: IP Ranges ::: ==> %s' % ip_ranges)

        self.assertTrue(
            len(ip_ranges) == 1,
            "Test expects only 1 VLAN IP Range network but found -> '%s'" %
            len(ip_ranges))
        self.assertIsNotNone(
            ip_ranges[0].gateway,
            "The network with id -> '%s' returned an IP Range with a None gateway. Please check your Datacenter settings."
            % networks[0].id)

        return ip_ranges[0].gateway
    def test_01_netmask_value_check(self):
        """ Check Netmask value in database
            1. Check if netmask attribute in nics table
                stores correct value.
        """

        # Step 1
        # Get the netmask from ipv4 address of the VM
        qryresult_netmask = self.dbclient.execute(" select id, uuid, netmask\
                    from nics where ip4_address='%s';" %
                                                  self.vm.nic[0].ipaddress)

        self.assertNotEqual(
            len(qryresult_netmask), 0,
            "Check if netmask attribute in nics table \
            stores correct value")

        # Step 2
        netmask_id = qryresult_netmask[0][2]
        netlist = list_networks(self.apiclient,
                                account=self.account.name,
                                domainid=self.account.domainid)

        self.assertNotEqual(len(netlist), 0,
                            "Check if list networks returned an empty list.")

        cidr = netlist[0].cidr.split("/")[1]
        # Get netmask from CIDR
        netmask = ipv4_cidr_to_netmask(int(cidr))

        # Validate the netmask
        self.assertEqual(netmask_id, netmask,
                         "Check if the netmask is from guest CIDR")
        return
Пример #3
0
    def test_03_restart_network_cleanup(self):
        """Test restart network
        """

        # Validate the following
        # 1. When cleanup = true, router is destroyed and a new one created
        # 2. New router should have the same public IP

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

        # Store old values before restart
        old_publicip = router.publicip

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

        self.debug("Restarting network with ID: %s, Network state: %s" %
                   (network.id, network.state))
        cmd = restartNetwork.restartNetworkCmd()
        cmd.id = network.id
        cmd.cleanup = True
        self.apiclient.restartNetwork(cmd)

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

        self.assertEqual(
            router.publicip, old_publicip,
            "Public IP of the router should remain same after network restart")
        return
Пример #4
0
    def find_public_gateway(self):
        networks = list_networks(self.apiclient,
                                  zoneid = self.zone.id,
                                  listall = True,
                                  issystem = True,
                                  traffictype = "Public")
        self.logger.debug('::: Public Networks ::: ==> %s' % networks)

        self.assertTrue(len(networks) == 1, "Test expects only 1 Public network but found -> '%s'" % len(networks))
        
        ip_ranges = list_vlan_ipranges(self.apiclient,
                                       zoneid = self.zone.id,
                                       networkid = networks[0].id)
        self.logger.debug('::: IP Ranges ::: ==> %s' % ip_ranges)

        self.assertTrue(len(ip_ranges) == 1, "Test expects only 1 VLAN IP Range network but found -> '%s'" % len(ip_ranges))
        self.assertIsNotNone(ip_ranges[0].gateway, "The network with id -> '%s' returned an IP Range with a None gateway. Please check your Datacenter settings." % networks[0].id)

        return ip_ranges[0].gateway
Пример #5
0
 def test_08_move_across_subdomain_network_create(self):
     """Test as root, stop a VM from subdomain1 and attempt to move it to subdomain2, network should get craeted
     """
     # Validate the following:
     # 1. deploy VM in sub subdomain1
     # 2. stop VM in sub subdomain1
     # 3. assignVirtualMachine to subdomain2 network should get created
     self.create_vm(self.sdomain_account_user1['account'], self.sdomain_account_user1['domain'])
     self.virtual_machine.assign_virtual_machine(self.apiclient, self.sdomain_account_user2['account'].name ,self.sdomain_account_user2['domain'].id)
     self.check_vm_is_moved_in_account_domainid(self.sdomain_account_user2['account'])
     networks = list_networks(self.apiclient,
                              account=self.sdomain_account_user2['account'].name,
                              domainid=self.sdomain_account_user2['domain'].id)
     self.assertEqual(isinstance(networks, list),
                      True,
                      "Check for list networks response return valid data")
     self.assertNotEqual(len(networks),
                         0,
                         "Check list networks response")
Пример #6
0
 def test_08_move_across_subdomain_network_create(self):
     """Test as root, stop a VM from subdomain1 and attempt to move it to subdomain2, network should get craeted
     """
     # Validate the following:
     # 1. deploy VM in sub subdomain1
     # 2. stop VM in sub subdomain1
     # 3. assignVirtualMachine to subdomain2 network should get created
     self.create_vm(self.sdomain_account_user1['account'], self.sdomain_account_user1['domain'])
     self.virtual_machine.assign_virtual_machine(self.apiclient, self.sdomain_account_user2['account'].name ,self.sdomain_account_user2['domain'].id)
     self.check_vm_is_moved_in_account_domainid(self.sdomain_account_user2['account'])
     networks = list_networks(self.apiclient,
                              account=self.sdomain_account_user2['account'].name,
                              domainid=self.sdomain_account_user2['domain'].id)
     self.assertEqual(isinstance(networks, list),
                      True,
                      "Check for list networks response return valid data")
     self.assertNotEqual(len(networks),
                         0,
                         "Check list networks response")
Пример #7
0
    def test_02_NetworkGarbageCollection(self):
        """Test network garbage collection
        """
        # Validate the following
        # 1. wait for router to start and guest network to be created
        #    a.listRouters account=user, domainid=1 (router state=Running)
        #    b.listNetworks account=user domainid=1 (network state=Implemented)
        #    c.listVirtualMachines account=user domainid=1 (VM states=Running)
        # 4. stopVirtualMachines (stop all VMs in this account)
        # 5. wait for VMs to stop-listVirtualMachines account=user, domainid=1
        #    (Both VM states = Stopped)
        # 6. wait for network.gc.interval*2 seconds (600s)
        # 7. listRouters account=user, domainid=1

        routers = list_routers(
            self.apiclient,
            account=self.account.name,
            domainid=self.account.domainid,
        )

        self.assertEqual(isinstance(routers, list), True,
                         "Check for list routers response return valid data")
        self.assertNotEqual(len(routers), 0, "Check list router response")
        # Router associated with account should be in running state
        timeout = 180
        router = routers[0]
        self.debug("Router ID: %s & Router state: %s" %
                   (router.id, router.state))
        self.debug("Wait for %s secs max for router to reach Running state" %
                   timeout)
        while timeout:
            time.sleep(60)
            routers = list_routers(self.apiclient,
                                   account=self.account.name,
                                   domainid=self.account.domainid,
                                   id=router.id)
            router = routers[0]
            if router.state == 'Running':
                break

            timeout = timeout - 60
            if timeout == 0:
                self.assertEqual(router.state, 'Running',
                                 "Router not in Running state")

        # Network state associated with account should be 'Implemented'
        networks = list_networks(self.apiclient,
                                 account=self.account.name,
                                 domainid=self.account.domainid,
                                 type='Isolated')
        self.assertEqual(isinstance(networks, list), True,
                         "Check for list networks response return valid data")
        self.assertNotEqual(len(networks), 0, "Check list networks response")
        # Check if network in 'Implemented' state
        for network in networks:
            self.debug("Network ID: %s & Network state: %s" %
                       (network.id, network.state))
            self.assertIn(network.state, ['Implemented', 'Allocated'],
                          "Check list network response for network state")

        # VM state associated with account should be 'Running'
        virtual_machines = list_virtual_machines(
            self.apiclient,
            account=self.account.name,
            domainid=self.account.domainid,
        )

        self.assertEqual(
            isinstance(virtual_machines, list), True,
            "Check for list virtual machines response return valid data")
        self.assertNotEqual(len(virtual_machines), 0,
                            "Check list virtual machines response")
        for virtual_machine in virtual_machines:
            self.debug("VM ID: %s & VM state: %s" %
                       (virtual_machine.id, virtual_machine.state))
            self.assertEqual(virtual_machine.state, 'Running',
                             "Check list VM response for Running state")

            # Stop virtual machine
            cmd = stopVirtualMachine.stopVirtualMachineCmd()
            cmd.id = virtual_machine.id
            self.apiclient.stopVirtualMachine(cmd)

        gcinterval = list_configurations(self.apiclient,
                                         name='network.gc.interval')
        self.assertEqual(
            isinstance(gcinterval, list), True,
            "Check for list intervals response return valid data")
        self.debug("network.gc.interval: %s" % gcinterval[0].value)

        gcwait = list_configurations(self.apiclient, name='network.gc.wait')
        self.assertEqual(
            isinstance(gcwait, list), True,
            "Check for list intervals response return valid data")
        self.debug("network.gc.wait: %s" % gcwait[0].value)

        total_wait = int(gcinterval[0].value) + int(gcwait[0].value)
        # Router is stopped after (network.gc.interval *2) time. Wait for
        # (network.gc.interval+network.gc.wait) * 2 for moving
        # router to 'Stopped'
        time.sleep(total_wait * 2)

        routers = list_routers(
            self.apiclient,
            account=self.account.name,
            domainid=self.account.domainid,
        )

        self.assertEqual(isinstance(routers, list), True,
                         "Check for list routers response return valid data")
        self.assertNotEqual(len(routers), 0, "Check list router response")
        for router in routers:
            self.debug("Router ID: %s & Router state: %s" %
                       (router.id, router.state))
            self.assertEqual(router.state, 'Stopped',
                             "Check list router response for router state")

        # Cleanup Vm_2 - Not required for further tests
        self.cleanup.append(self.vm_2)
        return
Пример #8
0
    def test_01_AdvancedZoneRouterServices(self):
        """Test advanced zone router services
        """
        # Validate the following:
        # 1. Verify that list of services provided by this network are running
        #    a. DNS
        #    b. DHCP
        #    c. Gateway
        #    d. Firewall
        #    e. LB
        #    f. VPN
        #    g. userdata
        # 2. wait for router to start and guest network to be created
        #    a. listRouters account=user, domainid=1 (router state=Running)
        #    b. listNetworks account=user domainid=1
        #       (network state=Implemented)
        #    c. listVirtualMachines account=user domainid=1 (VM state=Running)
        # 3. listNetwork

        routers = list_routers(
            self.apiclient,
            account=self.account.name,
            domainid=self.account.domainid,
        )

        self.assertEqual(isinstance(routers, list), True,
                         "Check for list routers response return valid data")
        self.assertNotEqual(len(routers), 0, "Check list router response")
        for router in routers:
            self.debug("Router ID: %s & Router state: %s" %
                       (router.id, router.state))
            self.assertEqual(
                router.state, 'Running',
                "Router state is not running but is  %s" % router.state)

        # Network state associated with account should be 'Implemented'
        networks = list_networks(self.apiclient,
                                 account=self.account.name,
                                 domainid=self.account.domainid,
                                 type='Isolated')
        self.assertEqual(isinstance(networks, list), True,
                         "Check for list networks response return valid data")

        self.assertNotEqual(len(networks), 0, "Check list networks response")
        for network in networks:
            self.debug("Network ID: %s & Network state: %s" %
                       (network.id, network.state))
            self.assertIn(network.state, ['Implemented', 'Allocated'],
                          "Check list network response for network state")

        # VM state associated with account should be 'Running'
        virtual_machines = list_virtual_machines(
            self.apiclient,
            account=self.account.name,
            domainid=self.account.domainid)

        self.assertEqual(
            isinstance(virtual_machines, list), True,
            "Check for list virtual machines response return valid data")
        self.assertNotEqual(len(virtual_machines), 0,
                            "Check list virtual machines response")
        for virtual_machine in virtual_machines:
            self.assertEqual(virtual_machine.state, 'Running',
                             "Check list VM response for Running state")
            self.debug("VM ID: %s & VM state: %s" %
                       (virtual_machine.id, virtual_machine.state))

        # Check status of DNS, DHCP, FIrewall, LB VPN processes
        networks = list_networks(self.apiclient,
                                 account=self.account.name,
                                 domainid=self.account.domainid,
                                 type='Isolated')
        self.assertEqual(isinstance(networks, list), True,
                         "Check for list networks response return valid data")
        self.assertNotEqual(len(networks), 0, "Check list networks response")
        # Load Balancer, Userdata, VPN, Firewall, Gateway, DNS processes should
        # be running
        for network in networks:
            self.assertEqual('Lb' in str(network.service), True,
                             "Check Load balancing process in list networks")
            self.assertEqual('UserData' in str(network.service), True,
                             "Check UserData service in list networks")
            self.assertEqual('Vpn' in str(network.service), True,
                             "Check Vpn service in list networks")
            self.assertEqual('Firewall' in str(network.service), True,
                             "Check Firewall service in list networks")
            self.assertEqual('Dns' in str(network.service), True,
                             "Check Dns service in list networks")
        return
Пример #9
0
    def test_04_restart_network_wo_cleanup(self):
        """Test restart network without cleanup
        """

        # Validate the following
        # 1. When cleanup = false, router is restarted and
        #    all services inside the router are restarted
        # 2. check 'uptime' to see if the actual restart happened

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

        self.debug(
            "Restarting network with ID: %s, Network state: %s" % (
                network.id,
                network.state
            ))
        cmd = restartNetwork.restartNetworkCmd()
        cmd.id = network.id
        cmd.cleanup = False
        self.apiclient.restartNetwork(cmd)

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

        hosts = list_hosts(
            self.apiclient,
            zoneid=router.zoneid,
            type='Routing',
            state='Up',
            id=router.hostid
        )
        self.assertEqual(
            isinstance(hosts, list),
            True,
            "Check list response returns a valid list"
        )
        host = hosts[0]

        if self.hypervisor.lower() in ('vmware', 'hyperv'):
            res = get_process_status(
                self.apiclient.connection.mgtSvr,
                22,
                self.apiclient.connection.user,
                self.apiclient.connection.passwd,
                router.linklocalip,
                "uptime",
                hypervisor=self.hypervisor
            )
        else:
            try:
                host.user, host.passwd = get_host_credentials(
                    self.config, host.ipaddress)
                res = get_process_status(
                    host.ipaddress,
                    22,
                    host.user,
                    host.passwd,
                    router.linklocalip,
                    "uptime"
                )
            except KeyError:
                self.skipTest(
                    "Marvin configuration has no host credentials\
                            to check router services")
        # res = 12:37:14 up 1 min,  0 users,  load average: 0.61, 0.22, 0.08
        # Split result to check the uptime
        result = res[0].split()
        self.debug("Router Uptime: %s" % result)
        self.assertEqual(
            str(result[1]),
            'up',
            "Check router is running or not"
        )
        if str(result[3]) == "min,":
            self.assertEqual(
                (int(result[2]) < 3),
                True,
                "Check uptime is less than 3 mins or not"
            )
        else:
            self.assertEqual(
                str(result[3]),
                'sec,',
                "Check uptime is in seconds"
            )
        return
Пример #10
0
    def test_03_restart_network_cleanup(self):
        """Test restart network
        """

        # Validate the following
        # 1. When cleanup = true, router is destroyed and a new one created
        # 2. New router should have the same public IP

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

        # Store old values before restart
        old_publicip = router.publicip

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

        self.debug(
            "Restarting network with ID: %s, Network state: %s" % (
                network.id,
                network.state
            ))
        cmd = restartNetwork.restartNetworkCmd()
        cmd.id = network.id
        cmd.cleanup = True
        self.apiclient.restartNetwork(cmd)

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

        self.assertEqual(
            router.publicip,
            old_publicip,
            "Public IP of the router should remain same after network restart"
        )
        return
Пример #11
0
    def test_04_restart_network_wo_cleanup(self):
        """Test restart network without cleanup
        """

        # Validate the following
        # 1. When cleanup = false, router is restarted and
        #    all services inside the router are restarted
        # 2. check 'uptime' to see if the actual restart happened

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

        self.debug(
            "Restarting network with ID: %s, Network state: %s" % (
                network.id,
                network.state
            ))
        cmd = restartNetwork.restartNetworkCmd()
        cmd.id = network.id
        cmd.cleanup = False
        self.apiclient.restartNetwork(cmd)

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

        hosts = list_hosts(
            self.apiclient,
            zoneid=router.zoneid,
            type='Routing',
            state='Up',
            id=router.hostid
        )
        self.assertEqual(
            isinstance(hosts, list),
            True,
            "Check list response returns a valid list"
        )
        host = hosts[0]

        if self.hypervisor.lower() in ('vmware', 'hyperv'):
            res = get_process_status(
                self.apiclient.connection.mgtSvr,
                22,
                self.apiclient.connection.user,
                self.apiclient.connection.passwd,
                router.linklocalip,
                "uptime",
                hypervisor=self.hypervisor
            )
        else:
            try:
                host.user, host.passwd = get_host_credentials(
                    self.config, host.ipaddress)
                res = get_process_status(
                    host.ipaddress,
                    22,
                    host.user,
                    host.passwd,
                    router.linklocalip,
                    "uptime"
                )
            except KeyError:
                self.skipTest(
                    "Marvin configuration has no host credentials\
                            to check router services")
        # res = 12:37:14 up 1 min,  0 users,  load average: 0.61, 0.22, 0.08
        # Split result to check the uptime
        result = res[0].split()
        self.debug("Router Uptime: %s" % result)
        self.assertEqual(
            str(result[1]),
            'up',
            "Check router is running or not"
        )
        if str(result[3]) == "min,":
            self.assertEqual(
                (int(result[2]) < 3),
                True,
                "Check uptime is less than 3 mins or not"
            )
        else:
            self.assertEqual(
                str(result[3]),
                'sec,',
                "Check uptime is in seconds"
            )
        return
Пример #12
0
    def test_02_NetworkGarbageCollection(self):
        """Test network garbage collection
        """
        # Validate the following
        # 1. wait for router to start and guest network to be created
        #    a.listRouters account=user, domainid=1 (router state=Running)
        #    b.listNetworks account=user domainid=1 (network state=Implemented)
        #    c.listVirtualMachines account=user domainid=1 (VM states=Running)
        # 4. stopVirtualMachines (stop all VMs in this account)
        # 5. wait for VMs to stop-listVirtualMachines account=user, domainid=1
        #    (Both VM states = Stopped)
        # 6. wait for network.gc.interval*2 seconds (600s)
        # 7. listRouters account=user, domainid=1

        routers = list_routers(
            self.apiclient,
            account=self.account.name,
            domainid=self.account.domainid,
        )

        self.assertEqual(
            isinstance(routers, list),
            True,
            "Check for list routers response return valid data"
        )
        self.assertNotEqual(
            len(routers),
            0,
            "Check list router response"
        )
        # Router associated with account should be in running state
        timeout = 180
        router = routers[0]
        self.debug("Router ID: %s & Router state: %s" % (
            router.id,
            router.state
        ))
        self.debug(
            "Wait for %s secs max for router to reach Running state" %
            timeout)
        while timeout:
            time.sleep(60)
            routers = list_routers(
                self.apiclient,
                account=self.account.name,
                domainid=self.account.domainid,
                id=router.id)
            router = routers[0]
            if router.state == 'Running':
                break

            timeout = timeout - 60
            if timeout == 0:
                self.assertEqual(
                    router.state,
                    'Running',
                    "Router not in Running state")

        # Network state associated with account should be 'Implemented'
        networks = list_networks(
            self.apiclient,
            account=self.account.name,
            domainid=self.account.domainid,
            type='Isolated'
        )
        self.assertEqual(
            isinstance(networks, list),
            True,
            "Check for list networks response return valid data"
        )
        self.assertNotEqual(
            len(networks),
            0,
            "Check list networks response"
        )
        # Check if network in 'Implemented' state
        for network in networks:
            self.debug("Network ID: %s & Network state: %s" % (
                network.id,
                network.state
            ))
            self.assertIn(
                network.state,
                ['Implemented', 'Allocated'],
                "Check list network response for network state"
            )

        # VM state associated with account should be 'Running'
        virtual_machines = list_virtual_machines(
            self.apiclient,
            account=self.account.name,
            domainid=self.account.domainid,
        )

        self.assertEqual(
            isinstance(virtual_machines, list),
            True,
            "Check for list virtual machines response return valid data"
        )
        self.assertNotEqual(
            len(virtual_machines),
            0,
            "Check list virtual machines response"
        )
        for virtual_machine in virtual_machines:
            self.debug("VM ID: %s & VM state: %s" % (
                virtual_machine.id,
                virtual_machine.state
            ))
            self.assertEqual(
                virtual_machine.state,
                'Running',
                "Check list VM response for Running state"
            )

            # Stop virtual machine
            cmd = stopVirtualMachine.stopVirtualMachineCmd()
            cmd.id = virtual_machine.id
            self.apiclient.stopVirtualMachine(cmd)

        gcinterval = list_configurations(
            self.apiclient,
            name='network.gc.interval'
        )
        self.assertEqual(
            isinstance(gcinterval, list),
            True,
            "Check for list intervals response return valid data"
        )
        self.debug("network.gc.interval: %s" % gcinterval[0].value)

        gcwait = list_configurations(
            self.apiclient,
            name='network.gc.wait'
        )
        self.assertEqual(
            isinstance(gcwait, list),
            True,
            "Check for list intervals response return valid data"
        )
        self.debug("network.gc.wait: %s" % gcwait[0].value)

        total_wait = int(gcinterval[0].value) + int(gcwait[0].value)
        # Router is stopped after (network.gc.interval *2) time. Wait for
        # (network.gc.interval+network.gc.wait) * 2 for moving
        # router to 'Stopped'
        time.sleep(total_wait * 2)

        routers = list_routers(
            self.apiclient,
            account=self.account.name,
            domainid=self.account.domainid,
        )

        self.assertEqual(
            isinstance(routers, list),
            True,
            "Check for list routers response return valid data"
        )
        self.assertNotEqual(
            len(routers),
            0,
            "Check list router response"
        )
        for router in routers:
            self.debug("Router ID: %s & Router state: %s" % (
                router.id,
                router.state
            ))
            self.assertEqual(
                router.state,
                'Stopped',
                "Check list router response for router state"
            )

        # Cleanup Vm_2 - Not required for further tests
        self.cleanup.append(self.vm_2)
        return
Пример #13
0
    def test_01_AdvancedZoneRouterServices(self):
        """Test advanced zone router services
        """
        # Validate the following:
        # 1. Verify that list of services provided by this network are running
        #    a. DNS
        #    b. DHCP
        #    c. Gateway
        #    d. Firewall
        #    e. LB
        #    f. VPN
        #    g. userdata
        # 2. wait for router to start and guest network to be created
        #    a. listRouters account=user, domainid=1 (router state=Running)
        #    b. listNetworks account=user domainid=1
        #       (network state=Implemented)
        #    c. listVirtualMachines account=user domainid=1 (VM state=Running)
        # 3. listNetwork

        routers = list_routers(
            self.apiclient,
            account=self.account.name,
            domainid=self.account.domainid,
        )

        self.assertEqual(
            isinstance(routers, list),
            True,
            "Check for list routers response return valid data"
        )
        self.assertNotEqual(
            len(routers),
            0,
            "Check list router response"
        )
        for router in routers:
            self.debug("Router ID: %s & Router state: %s" % (
                router.id,
                router.state
            ))
            self.assertEqual(
                router.state,
                'Running',
                "Router state is not running but is  %s" % router.state
            )

        # Network state associated with account should be 'Implemented'
        networks = list_networks(
            self.apiclient,
            account=self.account.name,
            domainid=self.account.domainid,
            type='Isolated'
        )
        self.assertEqual(
            isinstance(networks, list),
            True,
            "Check for list networks response return valid data"
        )

        self.assertNotEqual(
            len(networks),
            0,
            "Check list networks response"
        )
        for network in networks:
            self.debug("Network ID: %s & Network state: %s" % (
                network.id,
                network.state
            ))
            self.assertIn(
                network.state,
                ['Implemented', 'Allocated'],
                "Check list network response for network state"
            )

        # VM state associated with account should be 'Running'
        virtual_machines = list_virtual_machines(
            self.apiclient,
            account=self.account.name,
            domainid=self.account.domainid
        )

        self.assertEqual(
            isinstance(virtual_machines, list),
            True,
            "Check for list virtual machines response return valid data"
        )
        self.assertNotEqual(
            len(virtual_machines),
            0,
            "Check list virtual machines response"
        )
        for virtual_machine in virtual_machines:
            self.assertEqual(
                virtual_machine.state,
                'Running',
                "Check list VM response for Running state"
            )
            self.debug("VM ID: %s & VM state: %s" % (
                virtual_machine.id,
                virtual_machine.state
            ))

        # Check status of DNS, DHCP, FIrewall, LB VPN processes
        networks = list_networks(
            self.apiclient,
            account=self.account.name,
            domainid=self.account.domainid,
            type='Isolated'
        )
        self.assertEqual(
            isinstance(networks, list),
            True,
            "Check for list networks response return valid data"
        )
        self.assertNotEqual(
            len(networks),
            0,
            "Check list networks response"
        )
        # Load Balancer, Userdata, VPN, Firewall, Gateway, DNS processes should
        # be running
        for network in networks:
            self.assertEqual(
                'Lb' in str(network.service),
                True,
                "Check Load balancing process in list networks"
            )
            self.assertEqual(
                'UserData' in str(network.service),
                True,
                "Check UserData service in list networks"
            )
            self.assertEqual(
                'Vpn' in str(network.service),
                True,
                "Check Vpn service in list networks"
            )
            self.assertEqual(
                'Firewall' in str(network.service),
                True,
                "Check Firewall service in list networks"
            )
            self.assertEqual(
                'Dns' in str(network.service),
                True,
                "Check Dns service in list networks"
            )
        return
    def setUpClass(cls):
                    
        
        cloudstackTestClient = super(
                                     TestMultipleVPNAccessonVPC,
                                     cls
                                    ).getClsTestClient()
        
        cls.debug("Obtain the Admin's API Client")                                
        cls.api_client = cloudstackTestClient.getApiClient()
        cls.debug("Get the dictionary information that will be used during CCP tests, from test_data.py present on the Client")
        cls.services = cloudstackTestClient.getParsedTestDataConfig()
        
        if cls.services is None:
            cls.debug("Services Object is None")
            raise Exception("Services Object is None")
        
        cls.debug("Procure the CloudStack Setup configuration Information")
        with open(cls.services["config_path"], 'rb') as fp:
            cls.pullconfig = json.load(fp)
        
        cls.debug("Update 'remote.access.vpn.client.iprange','remote.access.vpn.user.limit','max.account.primary.storage','max.account.public.ips','max.account.user.vms','max.account.volumes','max.account.cpus', Global Configuration Parameters")
        
        update_vpn_client_iprange = Configurations.update(
            cls.api_client, 
            name="remote.access.vpn.client.iprange", 
            value="10.1.2.1-10.1.2.120")
        
        cls.debug("'remote.access.vpn.client.iprange' Global Configuration Parameter Updated Successfully")
        
        update_vpn_user_limit = Configurations.update(
            cls.api_client,
            name="remote.access.vpn.user.limit", 
            value=str(int(cls.services["vpnclient_count"]*2))
        )    
        
        cls.debug("'remote.access.vpn.user.limit' Global Configuration Parameter Updated Successfully")

        update_max_account_primary_stg_limit = Configurations.update(
            cls.api_client,
            name="max.account.primary.storage", 
            value=str(int(cls.services["vpnclient_count"]*20 + 100))
        )
        cls.debug("'max.account.primary.storage' Global Configuration Parameter Updated Successfully")

        update_max_account_public_ips_limit = Configurations.update(
            cls.api_client,
            name="max.account.public.ips", 
            value=str(int(cls.services["vpnclient_count"]*2 + 10))
        )
        cls.debug("'max.account.public.ips' Global Configuration Parameter Updated Successfully")
        
        update_max_account_user_vms_limit = Configurations.update(
            cls.api_client,
            name="max.account.user.vms", 
            value=str(int(cls.services["vpnclient_count"]*2))
        )
        cls.debug("'max.account.user.vms' Global Configuration Parameter Updated Successfully")
        
        update_max_account_volumes_limit = Configurations.update(
            cls.api_client,
            name="max.account.volumes", 
            value=str(int(cls.services["vpnclient_count"]*2))
        )
        cls.debug("'max.account.volumes' Global Configuration Parameter Updated Successfully")

        update_max_account_cpus_limit = Configurations.update(
            cls.api_client,
            name="max.account.cpus", 
            value=str(int(cls.services["vpnclient_count"]*2))
        )
        cls.debug("'max.account.cpus' Global Configuration Parameter Updated Successfully")
        
        cls.debug("Restart the Management Server")
        TestMultipleVPNAccessonVPC.restart_mgmt_server(cls.services["config_path"])
        cls.debug("Completed restarting the Management Server")
        
        cls.debug("Wait for 120 seconds...")
        time.sleep(120)
        cls.debug("End of 120 seconds wait time....")
        
        # Get Zone, Domain and templates
        cls.domain = get_domain(cls.api_client)
        cls.zone = get_zone(
            cls.api_client,
            zone_name = cls.services["zone_vpn"]["name"])
        
        cls.debug("Use an Existing 'Tiny Instance' Service Offering on the Setup")
        list_service_offerings = []
        list_service_offerings = list_service_offering(
            cls.api_client,
            keyword="Tiny Instance",
        )
        
        cls._cleanup = []
            
        if list_service_offerings is not None:
            cls.debug("Found an Existing 'Tiny Instance' Service Offering on the Setup")
            cls.service_offering = list_service_offerings[0]
            
        else:
            cls.debug("Create a service offering which will be used for VM deployments in this test")
            cls.service_offering = ServiceOffering.create(
                cls.api_client,
                cls.services["service_offering"]
            )
            
            cls.debug("Add the created service offering to the _cleanup queue")
            cls._cleanup.append(cls.service_offering)
        
        try:
            cls.debug("Create or Use Existing Account to own the VPN Clients, which is used to test Remote VPN Access to VPC")
            cls.api_client_vpn_client_reg_user = cloudstackTestClient.getUserApiClient(
                UserName="******",
                DomainName="ROOT"
            )

            list_vpn_client_regular_user = User.list(
                cls.api_client,
                username="******"
            )
            
            cls.debug("Procure the Account Name and DomainID Information of the Regular Account")
            cls.vpn_client_reg_acct_name = list_vpn_client_regular_user[0].account
            cls.vpn_client_reg_domain_id = list_vpn_client_regular_user[0].domainid
            
            list_vpn_client_regular_user_acct = Account.list(
                cls.api_client,
                name = cls.vpn_client_reg_acct_name,
                listall = True
            )
            
            cls._cleanup.append(Account(list_vpn_client_regular_user_acct[0].__dict__))
            
            # Register a Template that already has VPN client installed on it. The template registered here
            # has extra scripts to facilitate automated operations to execute Test Cases.
            # Template has pre-configured configuration files required for the VPN Client operations.
            # The following files are present on the registered template. The location of the files are locations
            # on a VM deployed from this template
            #            1. "/tmp/ipsec.conf"
            #            2. "/tmp/ipsec.secrets"
            #            3. "/tmp/options.xl2tpd.client"
            #            4. "/tmp/xl2tpd.conf"
            #            5  "/tmp/vpnclient_services.sh"
            #            6. "/tmp/firstconn_expectscript.exp"
            #            7. "/tmp/secondconn_expectscript.exp"
            
            cls.debug("Use an Existing VPN Client Template on the Setup")
            list_vpn_client_templates = list_templates(
                cls.api_client_vpn_client_reg_user,
                keyword="VPNClient",
                templatefilter="featured",
                zoneid = cls.zone.id
            )
            
            if list_vpn_client_templates is not None:
                cls.debug("Found an Existing VPN Client Template on the Setup")
                cls.template = list_vpn_client_templates[0]
            
            else:
                cls.debug("Register a Template that already has VPN client installed on it")
                cls.template = Template.register(
                    cls.api_client, 
                    cls.services["vpn_template"], 
                    zoneid=cls.zone.id,
                    hypervisor='XenServer' 
                )

                cls._cleanup.append(cls.template)

                cls.debug("Sleep for {0} seconds specified in the dictionary before checking for Template's Availability".format(cls.services["sleep"]))
                time.sleep(cls.services["sleep"])
                
            cls.debug("Procure Timeout Value from the dictionary")
            timeout = cls.services["timeout"]
            
            while True:
                list_template_response = list_templates(
                    cls.api_client_vpn_client_reg_user,
                    templatefilter='featured',
                    id=cls.template.id,
                )
            
                if isinstance(list_template_response, list):
                    break
                elif timeout == 0:
                    raise Exception("List template failed!")

                time.sleep(5)
                timeout = timeout - 1
            
            cls.debug("Verify template response to check whether template is present")
            
            if list_template_response is None: 
                raise Exception("Check whether the VPN Client Template is available")
            template_response = list_template_response[0]
            if template_response.isready == False: 
                raise Exception("Template state is not ready, it is %r" % template_response.isready)
            
            # Queue that holds all the VPN Client VMs Information
            cls.vpnclientvms = []
            
            cls.debug("Deploy {0} VPN Clients in the account".format(int(cls.services["vpnclient_count"])))
            
            for vm in xrange(0,int(cls.services["vpnclient_count"])):
                
                cls.debug("Deploy a new VM {0} in first account. This VM which will be configured as VPN Client".format(int(vm)))
                new_vpnclient_vm = VirtualMachine.create(
                    cls.api_client_vpn_client_reg_user,
                    cls.services["virtual_machine"],
                    zoneid=cls.zone.id,
                    serviceofferingid=cls.service_offering.id,
                    templateid=cls.template.id,
                )
                
                cls.debug("Add new VM {0} to the vpnclientvms Queue".format(int(vm)))
                cls.vpnclientvms.append(new_vpnclient_vm)                

                cls.debug("Allow SSH Access to the new VPN Client VM {0}".format(int(vm)))
                new_vpnclient_vm.access_ssh_over_nat(
                    cls.api_client_vpn_client_reg_user, 
                    cls.services, 
                    new_vpnclient_vm, 
                    allow_egress=True
                )
                cls.debug("VM for VPNClient Access Got Created with Public IP Address %s" % new_vpnclient_vm.public_ip)
            
            cls.debug("Create or Use existing Account in which we deploy VPCs and test remote access to them from the First Account's VMs present on isolated Network")          
            cls.api_client_vpn_server_reg_user = cloudstackTestClient.getUserApiClient(
                UserName="******",
                DomainName="ROOT"
            )

            list_vpn_server_regular_user = User.list(
                cls.api_client,
                username="******"
            )
            
            cls.debug("Procure the Account Name and DomainID Information of the Regular Account")
            cls.vpn_server_reg_acct_name = list_vpn_server_regular_user[0].account
            cls.vpn_server_reg_domain_id = list_vpn_server_regular_user[0].domainid
        
            list_vpn_server_regular_user_acct = Account.list(
                cls.api_client,
                name = cls.vpn_server_reg_acct_name,
                listall = True
            )
            
            cls._cleanup.append(Account(list_vpn_server_regular_user_acct[0].__dict__))        
        
            cls.debug("Use an Existing 'VPC off-' Service Offering on the Setup")
            list_available_vpc_offerings = list_vpc_offerings(
                cls.api_client,
                keyword="VPC off-",
            )
            
            if list_available_vpc_offerings is not None:
                cls.debug("Found an Existing 'VPC off-' Service Offering on the Setup")
                cls.vpc_offering = VpcOffering(list_available_vpc_offerings[0].__dict__)
            
            else:
                cls.debug("Creating a VPC offering..")
                cls.vpc_offering = VpcOffering.create(
                    cls.api_client,
                    cls.services["vpc_offering"]
                )

                # Add the created VPC Offering to __cleanup queue
                cls._cleanup.append(cls.vpc_offering)

            # Enable to created VPC Offering inorder to deploy VPCs with it       
            cls.debug("Enabling the VPC offering created")
            cls.vpc_offering.update(cls.api_client, state='Enabled')
            cls.debug("Enabled the VPC Offering")

            # Create a VPC for the second account
            cls.debug("Creating a VPC in the account: %s" % cls.vpn_server_reg_acct_name)
            cls.firstvpc = VPC.create(
                cls.api_client_vpn_server_reg_user,
                cls.services["vpc_remote_vpn"],
                vpcofferingid=cls.vpc_offering.id,
                zoneid=cls.zone.id
            )        
        
            cls.debug("Use an Existing 'NET_OFF-RemoteAccessVPNTest-' Network Offering on the Setup")
            list_available_network_offerings = list_network_offerings(
                cls.api_client,
                keyword="NET_OFF-RemoteAccessVPNTest-",
            )
            
            if list_available_network_offerings is not None:
                cls.debug("Found an Existing 'NET_OFF-RemoteAccessVPNTest-' Network Offering on the Setup")
                cls.network_off = NetworkOffering(list_available_network_offerings[0].__dict__)
            
            else:
                cls.debug('Create NetworkOffering for Networks in VPC')
                cls.services["vpc_network_offering"]["name"] = "NET_OFF-RemoteAccessVPNTest-"+ random_gen()
                cls.network_off = NetworkOffering.create(
                    cls.api_client,
                    cls.services["vpc_network_offering"],
                    conservemode=False
                )

                # Add the created Network Offering to __cleanup queue
                cls._cleanup.append(cls.network_off)
        
            # Enable Network offering
            cls.network_off.update(cls.api_client, state='Enabled')
                    
            cls.debug('Created and Enabled NetworkOffering')
            cls.services["network"]["name"] = "NETWORK-" + random_gen()
            
            # Create First Network Tier in the First VPC created for second account using the network offering created above.    
            cls.debug('Adding Network=%s' % cls.services["network"])
            cls.firstnetworktier = Network.create(
                cls.api_client_vpn_server_reg_user,
                cls.services["network"],
                networkofferingid=cls.network_off.id,
                zoneid=cls.zone.id,
                gateway=cls.services["firstnetwork_tier"]["gateway"],
                netmask=cls.services["firstnetwork_tier"]["netmask"],
                vpcid=cls.firstvpc.id 
            )
        
            cls.debug("Created network with ID: %s" % cls.firstnetworktier.id)
        
            # Create Ingress and Egress NetworkACL rules for First Network Tier in the First VPC created for second account.
            cls.debug("Adding NetworkACL rules to make Network accessible for all Protocols and all CIDRs ")
            NetworkACL.create(
                cls.api_client_vpn_server_reg_user,
                cls.services["all_rule"],
                networkid=cls.firstnetworktier.id,
                traffictype='Ingress'
            )
        
            NetworkACL.create(
                cls.api_client_vpn_server_reg_user,
                cls.services["all_rule"],
                networkid=cls.firstnetworktier.id,
                traffictype='Egress'
            )
         
            listFirstVPC = VPC.list(
                cls.api_client_vpn_server_reg_user,
                id=cls.firstvpc.id
            )
            
            cls.debug("Information about the VPC: {0}".format(str(listFirstVPC)))
        
            cls.debug("Obtain the source nat IP Address of the first VPC.")
            cls.listFirstVPCPublicIpAddress = list_publicIP(
                cls.api_client_vpn_server_reg_user,
                issourcenat="true",
                vpcid=listFirstVPC[0].id,
                listall="true"
            )
            cls.debug("Information about the VPC's Source NAT IP Address: {0}".format(str(cls.listFirstVPCPublicIpAddress)))
        
            cls.debug("Enable Remote Access VPN on the source nat Public IP Address of the first VPC")
            cls.FirstVPNonFirstVPC = Vpn.create(
                cls.api_client_vpn_server_reg_user,
                cls.listFirstVPCPublicIpAddress[0].id
            )

            cls.debug("Successfully Created First VPN on VPC with preshared key:"+ cls.FirstVPNonFirstVPC.presharedkey)
            cls.listfirstNetworkTier = list_networks(
                cls.api_client_vpn_server_reg_user,
                id=cls.firstnetworktier.id,
                listall=True
            )


            cls.debug("Create a VM using the default template on the First Network Tier in the First VPC of the Second Account")
            cls.vm1 = VirtualMachine.create(
                cls.api_client_vpn_server_reg_user,
                cls.services["virtual_machine"],
                zoneid=cls.zone.id,
                serviceofferingid=cls.service_offering.id,
                templateid=cls.template.id,
                networkids=[str(cls.firstnetworktier.id)]
            )
        
            cls.debug("First VM deployed in the first Network Tier")
        
        except Exception as e:
            cleanup_resources(cls.api_client, cls._cleanup)
            printex = traceback.format_exc()
            cls.debug("Exception Occurred : {0}".format(printex))
            raise Exception("Warning: Exception during Setting Up the Test Suite Configuration : %s" % e)
        
        return