コード例 #1
0
ファイル: test.py プロジェクト: 18782967131/test
    def va_get_switch(self, hv_uniq_id):
        """
        Generates a list of switchs
        Returns:
            :list of switchs:

        Example:
            :va_get_switch('hvisor_1')
        """

        vswitches = []
        inventory_file = self._top_params.get('inventory_file')
        inv_params = load_yaml(inventory_file)
        hvs = inv_params.get('hypervisor')

        #get all switch of all hypervisor
        for hv in hvs :
            if hv['uniq_id'] == hv_uniq_id :
                current_hv = hv
                break

        vswitches = hv['vswitches'].split(' ')

        #delete empty value if exist
        for key in vswitches :
            if ' ' in vswitches:
                vswitches.remove(' ')

        if len(vswitches) == 0 :
            self._log.warn("Not found any switchs of hv {}".format(hv['mgmt_ip']))
        else :
            self._log.info("Succeed to get all switchs of hv {}".format(hv['mgmt_ip']))
            self._log.info("Switchs information is {}".format(str(vswitches)))

        return vswitches
コード例 #2
0
    def __init__(self, test_param_yaml, topo_yaml, image=None, **kwargs):
        """
        Initializes the device/pc object and data from topo and test_param yaml file

        Kwargs:
            test_param_yaml    : data of test parametes.
                                 onttrol information and  user_params
            topo_yaml          : data of topo,
                    for exampe: inventory file. devices information, connections information.
            image: string, url of image, for example: https://10.123.0.8/image.tar

        Examples:
            vatpobj = VaTopo(test_param_file, topo_file)
            vatpobj.setup()
            vatpobj.cleanup()

        """
        #check if need to add varmour_no_cli user
        test_params = load_yaml(test_param_yaml)  #返回字典
        self.add_nocli_user = False
        if 'add_nocli_user' in test_params.get('control') and \
                        test_params.get('control').get('add_nocli_user').upper() == 'Y':
            self.add_nocli_user = True

        self.testdata = VaTestInfo(test_param_yaml,
                                   topo_yaml,
                                   add_nocli_user=self.add_nocli_user)
        self.link_info = self.testdata.va_get_links()
        self.ints_info = self.testdata.va_get_interfaces()
        self.route_info = self.testdata.va_get_routes()
        self.vmsobj = self.testdata.va_get_test_vms()
        self.swobjs = {}
        self.get_vsw_obj()  #get vswitch object
        self.control_data = self.testdata.va_get_control()
        self.image = image
        builtins.__dict__['testdata'] = self.testdata
        builtins.__dict__['dirs'] = []
        builtins.__dict__['cps'] = []
        builtins.__dict__['epis'] = []
        for dev_name in self.vmsobj.keys():
            dev_type = self.vmsobj.get(dev_name).get_nodetype()
            if (dev_type == 'esxi'):
                continue

            dev_obj = self.testdata.va_get_by_uniq_id(dev_name)
            builtins.__dict__['%s' % dev_name] = dev_obj
            if (dev_type == 'dir'):
                builtins.__dict__['dirs'].append(dev_obj)
            elif (dev_type == 'cp'):
                builtins.__dict__['cps'].append(dev_obj)
            elif (dev_type == 'epi'):
                builtins.__dict__['epis'].append(dev_obj)
            else:
                pass

        for hv_id in self.swobjs.keys():
            hv_obj = self.swobjs.get(hv_id)
            builtins.__dict__['%s' % hv_id] = hv_obj
コード例 #3
0
ファイル: test.py プロジェクト: 18782967131/test
    def __init__(self, test_yaml=None, topology_yaml=None, add_nocli_user=False):
        """
        Initializes the VaTestInfo object
        """
        if not test_yaml:
            raise TestInfoError()
        self.test_yaml = test_yaml
        self.topology_yaml = topology_yaml
        self._test_params = load_yaml(test_yaml)
        self._top_params = load_yaml(topology_yaml)
        self._inventory = self._top_params.get('inventory_file') 
        self._log = logger
        self._user_params = self._test_params.get('user_params') 
        self._control = self._test_params.get('control')
        self.inventory_file = self._inventory

        self.va_load_inventory()
        self.va_lookup_inventory(add_nocli_user=add_nocli_user)
コード例 #4
0
    def revert_links(self):
        """
         revert link according to inventory file

         Kwargs:
                 None
         Return:
                 True   :   Succeed to revert link according to inventory file.
                 False :    Failed to revert link according to inventory file.
         Examples:
             vatpobj = VaTopo(test_param_file, topo_file)
             vatpobj.revert_links()
        """
        inventory_tb_data = load_yaml(self.testdata.inventory_file)
        swobjs = {}

        for dev_key in inventory_tb_data.keys():
            for dev in inventory_tb_data[dev_key]:
                if not 'interfaces' in dev or len(dev['interfaces']) == 0:
                    continue
                else:
                    vswitches = dev['hvisor']['vswitches']
                    vswitches_l = vswitches.split(' ')

                    for int in dev['interfaces']:
                        logger.debug(
                            'Check switch {} if it is in hv {}'.format(
                                int['vswitch'], dev['hvisor']['mgmt_ip']))
                        tag = 0
                        for vswname in vswitches_l:
                            if vswname == int['vswitch']:
                                logger.debug('check vswitch on hv.done')
                                tag = 1
                                break

                        if tag == 0:
                            logger.error('vswitch {} is not in hv {}' . format (int['vswitch'], \
                                                                                dev['hvisor']['mgmt_ip']))
                            return False

                        #update vlan for each interface
                        logger.info('Clean access vlan {} for {}:{}'\
                                    .format(int['vlan'],dev['uniq_id'],int['phy_name']))
                        hv_uqid = dev['hvisor']['uniq_id']
                        vswobj = self.swobjs[hv_uqid][int['vswitch']]
                        if not vswobj.update_vlan(int['port_group'],
                                                  int['vlan']):
                            return False

        logger.info("Completed to revert links")
        return True
コード例 #5
0
    def get_vsw_obj(self):
        """
         Instance all vswitch object

         Kwargs:
                  None
         Return:
                  vswitch object   :  dict
                 for example :
                {'hvisor_1':
                    {
                        'hvobj': <vautils.resource.Esxi object at 0x0000000003EA91D0>,
                        'vSwitch1': <vautils.resource.network.esxvswitch.EsxVswitch object at 0x000000000413E0B8>,
                        'vSwitch3': <vautils.resource.network.esxvswitch.EsxVswitch object at 0x000000000413E0F0>,
                        'vSwitch2': <vautils.resource.network.esxvswitch.EsxVswitch object at 0x000000000413E208>
                    }
                }

         Examples:
             vatpobj = VaTopo(test_param_file, topo_file)
             vatpobj.setup()
         """
        inventory_tb_data = load_yaml(self.testdata.inventory_file)
        self.swobjs = {}

        for dev_key in inventory_tb_data.keys():
            if dev_key == 'network':
                continue
            for dev in inventory_tb_data[dev_key]:
                if 'type' in dev and dev['type'] == 'esxi':
                    continue

                hvid = dev['hvisor']['uniq_id']
                if not hvid in self.swobjs:
                    self.swobjs[hvid] = {}

                if not 'hvobj' in self.swobjs[hvid]:
                    self.swobjs[hvid][
                        'hvobj'] = self.testdata.va_get_by_uniq_id(
                            hvid, False)
                    self.swobjs[hvid]['hvobj'].setup_vswitch(
                        self.swobjs[hvid]['hvobj'].get_shell())

                if 'interfaces' in dev:
                    for int in dev['interfaces']:
                        sw_name = int['vswitch']
                        if not sw_name in self.swobjs[hvid]:
                            self.swobjs[hvid][sw_name] = self.swobjs[hvid][
                                'hvobj'].get_vswitch(sw_name)
        logger.info(self.swobjs)
        return self.swobjs
コード例 #6
0
ファイル: test_xliu.py プロジェクト: 18782967131/test
    def va_load_inventory(self, inventory_yaml=None):
        """
        Loads the lab information provided as a yaml file that contains
        the vm resource information.

        Kwargs:
            :inventory_yaml (str): representation of the inventory info

        Raises:
            :LabInfoError:
        """
        inventory_yaml = self._inventory
        if not inventory_yaml:
            raise LabInfoError()

        self._inventory = VaInventory(**load_yaml(inventory_yaml))