Beispiel #1
0
def dpdk_init():
    """
    Configure appropriate mac addresses in startL3fwd.sh files and initiate the script on each of the dpdk VMs.
    :return:
    """
    deploy_settings = settings.getValue('VM_TOPOLOGY')
    tgen_mac = ''
    if deploy_settings['TOPOLOGY_TYPE'] == 'PVP':
        client = HostSession.HostSession().connect(
            deploy_settings['VM_DETAILS'][0]['IP'], deploy_settings['VM_USER'],
            deploy_settings['VM_PASSWORD'], False)
        vm_mac = get_vm_macs(client)
        pattern = '[0-9A-Za-z][0-9A-Za-z]:[0-9A-Za-z][0-9A-Za-z]:[0-9A-Za-z][0-9A-Za-z]:[0-9A-Za-z][0-9A-Za-z]:' \
                  '[0-9A-Za-z][0-9A-Za-z]:[0-9A-Za-z][0-9A-Za-z]'
        stdin, stdout, stderr = client.exec_command('cat startL3fwd.sh')
        dpdk_file_data = stdout.read().decode()
        pattern1 = '--eth-dest=0,' + pattern
        pattern2 = '--eth-dest=1,' + pattern
        dpdk_file_data = re.sub(pattern1, f'--eth-dest=0,{vm_mac[1]}',
                                dpdk_file_data)
        dpdk_file_data = re.sub(pattern2, f'--eth-dest=1,{tgen_mac}',
                                dpdk_file_data)
        client.exec_command(f'echo "{dpdk_file_data}" > startL3fwd.sh')
        client.exec_command(r'sudo ./startL3fwd.sh')
        HostSession.HostSession().disconnect(client)
    elif deploy_settings['TOPOLOGY_TYPE'] == 'PVVP':
        client = []
        for vm in deploy_settings['VM_DETAILS']:
            client.append(HostSession.HostSession().connect(
                vm['IP'], deploy_settings['VM_USER'],
                deploy_settings['VM_PASSWORD'], False))
        pattern = '[0-9A-Za-z][0-9A-Za-z]:[0-9A-Za-z][0-9A-Za-z]:[0-9A-Za-z][0-9A-Za-z]:[0-9A-Za-z][0-9A-Za-z]:' \
                  '[0-9A-Za-z][0-9A-Za-z]:[0-9A-Za-z][0-9A-Za-z]'
        vm_mac = []
        pattern1 = '--eth-dest=0,' + pattern
        pattern2 = '--eth-dest=1,' + pattern
        for i in range(len(client)):
            vm_mac.append(get_vm_macs(client[i]))
        for i in range(len(client)):
            stdin, stdout, stderr = client[i].exec_command('cat startL3fwd.sh')
            dpdk_file_data = stdout.read().decode()
            dpdk_file_data = re.sub(pattern1, f'--eth-dest=0,{vm_mac[i][1]}',
                                    dpdk_file_data)
            if i == len(client) - 1:
                dpdk_file_data = re.sub(pattern2, f'--eth-dest=1,{tgen_mac}',
                                        dpdk_file_data)
            else:
                dpdk_file_data = re.sub(pattern2,
                                        f'--eth-dest=1,{vm_mac[1][i]}',
                                        dpdk_file_data)
            client[i].exec_command(f'echo "{dpdk_file_data}" > startL3fwd.sh')
            client[i].exec_command(r'sudo ./startL3fwd.sh')
        for i in range(len(client)):
            HostSession.HostSession().disconnect(client[i])
Beispiel #2
0
 def list_env_detail_compact(self, client):
     parse = ParserUtil.Parser()
     path = settings.getValue('LOG_DIR') + "\env_details_compact.txt"
     print(f'saving the text file in {path}')
     _LOGGER.info(f'saving the text file in {path}')
     f = open(path, "a+")
     a = self.hardware_detail_compact(client)
     c = parse.dict_to_table(a, 'Hardware Details', False)
     print(c)
     f.write(str(c))
     c = parse.dict_to_table(self.get_server_details(client),
                             'Servers Information', False)
     print(c)
     f.write('\n')
     f.write(str(c))
     f.close()
Beispiel #3
0
def get_host_config(header='Host Optimization Status'):
    parse = ParserUtil.Parser()
    hosts = settings.getValue('HOST_DETAILS')
    # Create object of HostConfig() to access functions
    config_host = Host.HostConfig()
    for host in hosts:
        client = HostSession.HostSession().connect(host['HOST'], host['USER'],
                                                   host['PASSWORD'], False)
        _NICS = host['NICS'].split(',')
        logger.info(f'Getting ESXi version details')
        ver = config_host.get_host_version(client)
        b = dict()
        b['Host Version'] = ''
        b['NICS'] = _NICS
        b['Driver module'] = list()
        b['RX Ring Size'] = list()
        b['TX Ring Size'] = list()
        b['txMode'] = list()
        if ver.find('6.5') > -1:
            b['Host Version'] = ver
            config = Host.HostConfig()
            for nic in _NICS:
                a = config.get_nic_ring_size(client, nic)
                # print(a)
                b['RX Ring Size'].append(a['RX'])
                b['TX Ring Size'].append(a['TX'])
            for nic in _NICS:
                a = config.get_split_tx_status(client, nic)
                b['txMode'].append(a['txMode'])
            a = config.get_rss(client, 'ixgben')
            b['RSS'] = a['options']
            for nic in _NICS:
                a = config.get_nic_driver(client, nic)
                b['Driver module'].append(a['module'])
            a = config.get_queue_pairing_status(client)
            b['Queue paring status '] = a['queue_pairing_enabled']
            a = config.get_sw_tx_queue_size(client)
            b['Software TX queue size'] = a['sw_tx_queue_size']
            print(parse.dict_to_table(b, header, False))
            print('\n')
        HostSession.HostSession().disconnect(client)
    pass
Beispiel #4
0
 def get_ova_networks(self, ova_path):
     ostype = sys.platform
     folder_name = str()
     if ostype.startswith('win32'):
         folder_name = 'win32'
     elif ostype.startswith('linux'):
         folder_name = 'lin64'
     dir_name = settings.getValue('OVF_TOOL_DIR')
     ovftool_path = os.path.join(dir_name, folder_name, 'ovftool')
     cmd = [ovftool_path, '--machineOutput', ova_path]
     ova_details = subprocess.run(cmd,
                                  stdout=subprocess.PIPE).stdout.decode()
     ova_details = re.sub('\+', '', ova_details)
     xml_data = et.fromstring(
         ova_details[ova_details.index('<probeResult>'):ova_details.
                     index('</probeResult>') + len('</probeResult>')])
     networks = []
     for network in xml_data.find('networks'):
         networks.append(network.find('name').text.strip())
     return networks
Beispiel #5
0
def host_config(keep_defaults=False, splittx=False, splitrx=False, rss=False):
    """
    Apply host optimizations with values specified in host.json(BIOS optimizations not supported)
    Steps involved:
    1. Login to hosts using SSH client
    2. Perform optimizations
    3. Logout from ssh session
    :param keep_defaults: (bool) if True, skips the configuration of host and just gets the values of default settings on host
    :return: (bool) True If all optimizations are applied successfully else False.
    """
    print(f'''\n{'-'*60}\n\t\t\t\tHost Optimization\n{'-'*60}\n''')
    hosts = settings.getValue('HOST_DETAILS')
    # Create object of HostConfig() to access functions
    config_host = Host.HostConfig()
    for host in hosts:
        print(f' - Getting the Host current Status')
        get_host_config(header=f"Current Host Status ({host['HOST']})")
        client = HostSession.HostSession().connect(host['HOST'], host['USER'],
                                                   host['PASSWORD'], False)
        _NICS = host['NICS'].split(',')
        logger.info(f'Getting ESXi version details')
        ver = config_host.get_host_version(client)
        logger.info(f'{ver}')
        logger.info(
            'Start applying optimizations for the specific Esxi version')
        print(f' - Getting configuration settings from host.json')
        print(f' - Applying the host Optimization.')
        if ver.find('6.5') > -1:
            logger.info('Getting configuration settings from host.json')
            params = settings.getValue('ESXI65')
            logger.info(
                f'Configuring NICS {_NICS} for driver module: {params["NIC_DRIVER"]}'
            )
            for nic in _NICS:
                logger.info(f'Configuring {nic}')
                success, message = config_host.config_nic_driver(
                    client, nic, params['NIC_DRIVER']['NAME'])
                if eval(success):
                    logger.info(
                        f'{nic} driver configuration success: {eval(success)}')
                else:
                    logger.error(
                        f'{nic} driver configuration success: {eval(success)}')
                    logger.info(f'host output: {message}')
                    HostSession.HostSession().disconnect(client)
                    return False
            if rss:
                logger.info(f'RSS to be enabled: {params["ENABLE_RSS"]}')
                logger.info('Configuring RSS')
                success, message = config_host.config_rss(
                    client,
                    params["NIC_DRIVER"]['NAME'],
                    enable=params["ENABLE_RSS"])
                if eval(success):
                    logger.info(f'RSS configuration success : {eval(success)}')
                else:
                    logger.info(f'RSS configuration success : {eval(success)}')
                    logger.info(f'host output: {message}')
                    HostSession.HostSession().disconnect(client)
                    return False
            else:
                success, message = config_host.config_rss(
                    client, params["NIC_DRIVER"]['NAME'], enable=False)
                if eval(success):
                    logger.info(f'RSS configuration success : {eval(success)}')
                else:
                    logger.info(f'RSS configuration success : {eval(success)}')
                    logger.info(f'host output: {message}')
                    HostSession.HostSession().disconnect(client)
                    return False

            for nic in _NICS:
                logger.info(
                    f'Configuring Physical NIC Ring Size as {params["NIC_BUFFER_SIZE"]} on {nic}'
                )
                success, message = config_host.config_nic_ring_size(
                    client, nic, params["NIC_BUFFER_SIZE"]["RX"],
                    params["NIC_BUFFER_SIZE"]["TX"])
                if eval(success):
                    logger.info(
                        f'{nic} ring size configuration success: {eval(success)}'
                    )
                else:
                    logger.error(
                        f'{nic} ring size configuration success: {eval(success)}'
                    )
                    logger.info(f'host output: {message}')
                    HostSession.HostSession().disconnect(client)
                    return False

            logger.info(
                f'Configuring SW TX queue length as {params["SW_TX_QUEUE"]}')
            success, message = config_host.config_sw_tx_queue_size(
                client, params["SW_TX_QUEUE"])
            if eval(success):
                logger.info(
                    f'Software TX queue configuration success: {eval(success)}'
                )
            else:
                logger.error(
                    f'Software TX queue configuration success: {eval(success)}'
                )
                logger.info(f'host output: {message}')
                HostSession.HostSession().disconnect(client)
                return False

            logger.info(
                f'Queue Pairing to be enabled: {params["ENABLE_QUEUE_PAIRING"]}'
            )
            success, message = config_host.config_queue_pairing(
                client, enable=params["ENABLE_QUEUE_PAIRING"])
            if eval(success):
                logger.info(
                    f'Queue Pairing configuration success: {eval(success)}')
            else:
                logger.info(
                    f'Queue Pairing configuration success: {eval(success)}')
                logger.info(f'host output: {message}')
                HostSession.HostSession().disconnect(client)
                return False
            if splittx:
                logger.info(
                    f'Split TX mode to be enabled: {params["ENABLE_TX_SPLIT"]}'
                )
                for nic in _NICS:
                    logger.info(f'Configuring Split TX on {nic}')
                    success, message = config_host.config_tx_split(
                        client, nic, enable=params["ENABLE_TX_SPLIT"])
                    if eval(success):
                        logger.info(
                            f'Split TX configuration success: {eval(success)}')
                    else:
                        logger.error(
                            f'Split TX configuration success: {eval(success)}')
                        logger.info(f'host output: {message}')
                        HostSession.HostSession().disconnect(client)
                        return False
        else:
            logger.info('Getting configuration settings from host.json')
            params = settings.getValue('ESXI60U2')
            logger.info(ver)
            logger.info(
                f'Hyper threading enabled: {config_host.is_hyperthreading_enabled(client)}'
            )
            logger.info(
                f'Configure Hyper threading: enable={params["ENABLE_HYPERTHREADING"]} config success={config_host.config_hyperthreading(client, enable=params["ENABLE_HYPERTHREADING"])}'
            )

            logger.info(f'NICS {_NICS}')
            logger.info(f'Configuring {params["NIC_DRIVER"]}')
            for nic in _NICS:
                logger.info("{} : config={}".format(
                    nic,
                    config_host.config_nic_driver(
                        client, nic, params['NIC_DRIVER']['NAME'])))
            if rss:
                logger.info(
                    f'RSS enabled: {config_host.verify_rss(client, params["NIC_DRIVER"])}'
                )
                logger.info(
                    f'Configuring RSS: enable = {params["ENABLE_RSS"]} success=\
                {config_host.config_rss(client, params["NIC_DRIVER"]["NAME"], enable=params["ENABLE_RSS"])}'
                )
            else:
                success, message = config_host.config_rss(
                    client, params["NIC_DRIVER"]['NAME'], enable=False)
                if eval(success):
                    logger.info(f'RSS configuration success : {eval(success)}')
                else:
                    logger.info(f'RSS configuration success : {eval(success)}')
                    logger.info(f'host output: {message}')
                    HostSession.HostSession().disconnect(client)
                    return False

            for nic in _NICS:
                logger.info(
                    f'Configuring Physical NIC Ring Size as {params["NIC_BUFFER_SIZE"]} on {nic} : \
                             isSet = {config_host.verify_nic_ring_size(client, nic, params["NIC_BUFFER_SIZE"]["RX"], params["NIC_BUFFER_SIZE"]["TX"])} : \
                             config success={config_host.config_nic_ring_size(client, nic, params["NIC_BUFFER_SIZE"]["RX"], params["NIC_BUFFER_SIZE"]["TX"])} '
                )

            logger.info(
                f'Configuring SW TX queue length as {params["SW_TX_QUEUE"]}: isSet={config_host.verify_sw_tx_queue_size(client, params["SW_TX_QUEUE"])} \
                         : config success = {config_host.config_sw_tx_queue_size(client, params["SW_TX_QUEUE"])}'
            )

            logger.info(
                f'Configuring Queue Pairing enabled ={params["ENABLE_QUEUE_PAIRING"]}: isEnabled={config_host.is_queue_pairing_enabled(client)} \
                                     : config success = {config_host.config_queue_pairing(client, enable=params["ENABLE_QUEUE_PAIRING"])}'
            )
            if splittx:
                for nic in _NICS:
                    logger.info(
                        f'Configuring Split TX mode  ={params["ENABLE_TX_SPLIT"]}: isEnabled={config_host.is_tx_split_enabled(client, nic)}\
                                                     : config success = {config_host.config_tx_split(client, nic, enable=params["ENABLE_TX_SPLIT"])}'
                    )
        print(f' - Getting the Host Status after Optimizations')
        get_host_config(header=f"Post Host Optimization ({host['HOST']})")
        HostSession.HostSession().disconnect(client)
        return True
Beispiel #6
0
 def list_env_details(self, client):
     parse = ParserUtil.Parser()
     path = settings.getValue('LOG_DIR') + "\env_details.txt"
     print(f'saving the text file in {path}')
     _LOGGER.info(f'saving the text file in {path}')
     f = open(path, "a+")
     b = {}
     a = parse.dict_to_table(self.get_platform_details(client), '', False)
     b['platform Details'] = a
     c = parse.dict_to_table(b, 'Hardware Details', False)
     f.write(str(c))
     f.write('\n')
     b = {}
     a = self.get_cpu_info(client)
     a = parse.dict_to_table(a, '', False)
     b['CPU'] = a
     c = parse.dict_to_table(b, 'CPU Details', False)
     print(c)
     f.write(str(c))
     f.write('\n')
     b = {}
     a = parse.dict_to_table(self.get_hw_memory(client), '', False)
     b['Hardware Memory'] = a
     c = parse.dict_to_table(b, 'Hardware Memory Details', False)
     print(c)
     f.write(str(c))
     f.write('\n')
     b = {}
     # a = parse.dict_to_table(self.get_physical_adapter(client),'')
     # b['Physical adapter Details'] = a
     # a = dict_to_table(self.get_vflash(client),'',False)
     # b['vFlash Details'] = a
     a = parse.dict_to_table(self.get_filesystem(client), "fileSystem")
     b['File System'] = a
     # a = parse.dict_to_table(self.get_logical_device_details(client),'')
     # b['Logical device'] = a
     c = parse.dict_to_table(b, 'Storage Details', False)
     print(c)
     f.write(str(c))
     f.write('\n')
     b = {}
     a = parse.dict_to_table(self.get_nics(client), '')
     b['NIC Details'] = a
     # a= parse.dict_to_table(self.get_host_ip(client),'VMkernal details')
     # b['VMKernal Details'] = a
     a = parse.dict_to_table(self.get_vswitch(client), '')
     b['vswitch Detail'] = a
     a = parse.dict_to_table(self.get_pg_name(client), '')
     b['Port group name'] = a
     #a = parse.dict_to_table(self.get_dvs_name(client), '')
     #b['DVS details'] = a
     a = parse.dict_to_table(self.get_dvport_id(client), '')
     b['DVport ID'] = a
     a = parse.dict_to_table(self.get_vm_details(client), '')
     b['Virtual Machine'] = a
     c = parse.dict_to_table(b, 'Network Details', False)
     print(c)
     f.write(str(c))
     f.write('\n')
     b = {}
     a = parse.dict_to_table(self.get_current_powerstatus(client), '',
                             False)
     b['Current Power Policy'] = a
     a = parse.dict_to_table(self.get_hoststats(client), '', False)
     b['Host status'] = a
     a = parse.dict_to_table(self.get_pcpu_power_mgmt_states(client), '',
                             False)
     b['PCPU power management states'] = a
     c = parse.dict_to_table(b, 'System State', False)
     print(c)
     f.write(str(c))
     f.write('\n')
     f.close()
Beispiel #7
0
 def deploy_vm(self):
     print(f'''\n{'-'*60}\n\t\t\tInitiating VM Deployment\n{'-'*60}\n''')
     deploy_settings = settings.getValue('VM_TOPOLOGY')
     vms = deploy_settings['VM_DETAILS']
     ova_path = deploy_settings["OVA_FILE_PATH"]
     source_networks = self.get_ova_networks(ova_path)
     datastore = deploy_settings['DATASTORE']
     target_switch = str()
     success = True
     if deploy_settings['DEPLOYMENT_TARGET'] == "VCENTER" or deploy_settings[
             'DEPLOYMENT_TARGET'] == "NSX-V":
         target_ip = settings.getValue('VCENTER_DETAILS')['IP']
         target_user = settings.getValue('VCENTER_DETAILS')['USER']
         target_password = settings.getValue('VCENTER_DETAILS')['PASSWORD']
         host_ip = settings.getValue('HOST_DETAILS')[0]['HOST']
         target_user = re.sub('@', '%40', target_user)
         target_password = re.sub('@', '%40', target_password)
         target_switch = f'"vi://{target_user}:{target_password}@{target_ip}/?ip={host_ip}"'
     elif deploy_settings['DEPLOYMENT_TARGET'] == "ESXI":
         target_ip = settings.getValue('HOST_DETAILS')[0]['HOST']
         target_user = settings.getValue('HOST_DETAILS')[0]['USER']
         target_password = settings.getValue('HOST_DETAILS')[0]['PASSWORD']
         target_user = re.sub('@', '%40', target_user)
         target_password = re.sub('@', '%40', target_password)
         target_switch = f'"vi://{target_user}:{target_password}@{target_ip}"'
     for vm in vms:
         vm_name = vm['VM_NAME']
         target_networks = vm['NETWORKS']
         ip = vm['IP_ADDRESS']
         netmask = vm['NETMASK']
         gateway = vm['GATEWAY']
         ostype = sys.platform
         if ostype.startswith('win32'):
             folder_name = 'win32'
             dir_name = settings.getValue('OVF_TOOL_DIR')
             tool_path = os.path.join(dir_name, folder_name, 'ovftool.exe')
             _LOGGER.debug(f'opening {tool_path} ')
             command_switches = [
                 '--acceptAllEulas', '--powerOn', '--allowExtraConfig',
                 '--noSSLVerify', '--sourceType=OVA'
             ]
             cmd = [tool_path] + command_switches
             cmd += [
                 f'--datastore="{datastore}"', f'--name="{vm_name}"',
                 f'--net:"{source_networks[0]}"="{target_networks[0]}"',
                 f'--net:"{source_networks[1]}"="{target_networks[1]}"',
                 f'--net:"{source_networks[2]}"="{target_networks[2]}"',
                 f'--prop:"ipAddress"="{ip}"',
                 f'--prop:"netmask"="{netmask}"',
                 f'--prop:"gateway"="{gateway}"',
                 f'--prop:"dns"="192.168.11.2"', f'"{ova_path}"',
                 target_switch
             ]
             print(" ".join(cmd))
             _LOGGER.debug(f'Executing command: {" ".join(cmd)}')
             _LOGGER.info('Deploying vm. This might take a few minutes...')
             result = os.system(" ".join(cmd))
             print(result)
         elif ostype.startswith('linux'):
             folder_name = 'lin64'
             dir_name = settings.getValue('OVF_TOOL_DIR')
             tool_path = os.path.join(dir_name, folder_name, 'ovftool')
             _LOGGER.debug(f'opening {tool_path} ')
             command_switches = [
                 '--acceptAllEulas', '--powerOn', '--allowExtraConfig',
                 '--noSSLVerify', '--sourceType=OVA'
             ]
             cmd = [tool_path] + command_switches
             cmd += [
                 f'--datastore="{datastore}"', f'--name="{vm_name}"',
                 f'--net:"{source_networks[0]}"="{target_networks[0]}"',
                 f'--net:"{source_networks[1]}"="{target_networks[1]}"',
                 f'--net:"{source_networks[2]}"="{target_networks[2]}"',
                 f'--prop:"ipAddress"="{ip}"',
                 f'--prop:"netmask"="{netmask}"',
                 f'--prop:"gateway"="{gateway}"',
                 f'--prop:"dns"="192.168.11.2"', f'"{ova_path}"',
                 target_switch
             ]
             print(" ".join(cmd))
             _LOGGER.debug(f'Executing command: {" ".join(cmd)}')
             _LOGGER.info('Deploying vm. This might take a few minutes...')
             result = os.system(" ".join(cmd))
             print(result)
         # TODO for mac deployment
     return success
Beispiel #8
0
def vm_config(keep_defaults=False):
    hosts = settings.getValue('HOST_DETAILS')
    print(f'''\n{'-'*60}\n\t\t\tInitiating VM Optimizations\n{'-'*60}\n''')
    for host in hosts:
        client = HostSession.HostSession().connect(host['HOST'], host['USER'],
                                                   host['PASSWORD'], False)
        temp_vms = settings.getValue('VM_TOPOLOGY')['VM_DETAILS']
        ver = conf_host.get_host_version(client)
        _NICS = host['NICS'].split(',')
        _LOGGER.info('Verifying optimization on virtual machine')
        print('- Verifying optimization on virtual machine')
        for vm in temp_vms:
            # for vm in vms:
            if ver.find('6.5') > -1:
                # ESXI 6.5
                param = settings.getValue('ESXI_65')
                _LOGGER.info(f'HOST VERSION : ESXI 6.5 ')
                print(
                    f'- Getting the current configuration of virtual machine :{vm["VM_NAME"]}'
                )
                print(
                    parser.dict_to_table(
                        get_env_data(client, vm["VM_NAME"]),
                        f'Current configuration of Virtual Machine - {vm["VM_NAME"]}',
                        False))
                _LOGGER.info(f'virtual machine : {vm["VM_NAME"]}')
                print(f'- Optimization verification has been started.')
                vm_util.power_off_vm(client, vm["VM_NAME"])
                _LOGGER.info(
                    f'checking Latency sensitivity is set to "high":{vm_tune.verify_latency_sensitivity(client,vm["VM_NAME"])}'
                )
                status = vm_tune.config_latency_sensitivity(
                    client, vm["VM_NAME"])
                if status:
                    _LOGGER.info(
                        f'Setting latency sensitivity to high : {status}')
                else:
                    _LOGGER.error(
                        f'Setting latency sensitivity to high :{status}')

                _LOGGER.info(
                    f'checking CPU reservation : {vm_tune.verify_cpu_reservation(client,vm["VM_NAME"])}'
                )
                status = vm_tune.config_cpu_reservation(client, vm["VM_NAME"])
                if status:
                    _LOGGER.info(f'changing CPU reservation :{status}')
                else:
                    _LOGGER.error(f'CPU reservation status :{status}')

                _LOGGER.info(
                    f'checking CPU share :{vm_tune.verify_cpu_share(client, vm["VM_NAME"])}'
                )
                status = vm_tune.config_cpu_share(client, vm["VM_NAME"])
                if status:
                    _LOGGER.info(f'changing CPU share : {status}')
                else:
                    _LOGGER.error(f'changing CPU share : {status}')

                _LOGGER.info(
                    f'checking Memory reservation : {vm_tune.verify_mem_reservation(client,vm["VM_NAME"])}'
                )
                status = vm_tune.config_mem_reservation(client, vm["VM_NAME"])
                if status:
                    _LOGGER.info(f'changing Memory reservation :{status}')
                else:
                    _LOGGER.error(f'changing Memory reservation :{status}')

                _LOGGER.info(
                    f'checking Memory share :{vm_tune.verify_mem_share(client, vm["VM_NAME"])}'
                )
                status = vm_tune.config_mem_share(client, vm["VM_NAME"])
                if status:
                    _LOGGER.info(f'changing Memory share : {status}')
                else:
                    _LOGGER.error(f'chaging Memory share : {status}')

                for vnic in set(vm_util.get_vnic_no(client, vm["VM_NAME"])):
                    _LOGGER.info(
                        f'checking the vNIC adapter type : {vm_tune.verify_nic_adapter_type(client, vm["VM_NAME"], param["ADAPTER_TYPE"],vnic)}'
                    )
                    status = vm_tune.config_nic_adapter_type(
                        client, vm["VM_NAME"], param["ADAPTER_TYPE"], vnic)
                    if status:
                        _LOGGER.info(
                            f'changing the vNIC adapter type  to {param["ADAPTER_TYPE"]}:{status}'
                        )
                    else:
                        _LOGGER.error(
                            f'changing the vNIC adapter type  to {param["ADAPTER_TYPE"]}:{status}'
                        )

                    _LOGGER.info(
                        f'checking the TX thread Allocation for vnic{vnic}: {vm_tune.verify_tx_thread_allocation(client, vm["VM_NAME"], vnic)}'
                    )
                    status = vm_tune.config_tx_thread_allocation(
                        client, vm["VM_NAME"], vnic)
                    if status:
                        _LOGGER.info(
                            f'changing the TX thread allocation for vnic{vnic}: {status}'
                        )
                    else:
                        _LOGGER.error(
                            f'changing the TX thread allocation  for vnic{vnic}: {status}'
                        )

                _LOGGER.info(
                    f'Checking the SysContext : {vm_tune.verify_sys_context(client, vm["VM_NAME"], vm_tune.get_syscontext_value(client, vm["VM_NAME"], True))}'
                )
                status = vm_tune.config_sys_context(
                    client, vm["VM_NAME"],
                    vm_tune.get_syscontext_value(client, vm["VM_NAME"], True))
                if status:
                    _LOGGER.info(
                        f'changing SysContext value to {vm_tune.get_syscontext_value(client, vm["VM_NAME"], True)} : {status}'
                    )
                else:
                    _LOGGER.error(
                        f'changing SysContext value to {vm_tune.get_syscontext_value(client, vm["VM_NAME"], True)} : {status}'
                    )

                for nic in _NICS:
                    _LOGGER.info(
                        f'Checking the NUMA affinity value for {nic} : {vm_tune.verify_numa_affinity(client,vm["VM_NAME"], nic)}'
                    )
                    status = vm_tune.config_numa_affinity(
                        client, vm["VM_NAME"], nic)
                    if status:
                        _LOGGER.info(f'changing NUMA value for {nic}:{status}')
                    else:
                        _LOGGER.error(
                            f'changing NUMA value for {nic}:{status}')
            else:
                """
                    ESXI VERSION 6.0 U2
                """
                param = settings.getValue('ESXI_60U2')
                _LOGGER.info(f'HOST VETSION : ESXI 6.0 U2')
                _LOGGER.info('Verifying optimization on virtual machine')
                vm_util.power_off_vm(client, vm["VM_NAME"])
                print(
                    f' - Getting the current configuration of virtual machine :{vm["VM_NAME"]}'
                )
                print(
                    parser.dict_to_table(
                        get_env_data(client, vm["VM_NAME"]),
                        f'Current configuration of Virtual Machine :{vm["VM_NAME"]}',
                        False))
                _LOGGER.info(
                    f'checking Latency sensitivity is set to "high":{vm_tune.verify_latency_sensitivity()}'
                )
                status = vm_tune.config_latency_sensitivity(
                    client, vm["VM_NAME"])
                if status:
                    _LOGGER.info(
                        f'Setting latency sensitivity to high : {status}')
                else:
                    _LOGGER.error(
                        f'Setting latency sensitivity to high :{status}')
                    return False
                _LOGGER.info(
                    f'checking CPU reservation : {vm_tune.verify_cpu_reservation(client,vm["VM_NAME"])}'
                )
                status = vm_tune.config_cpu_reservation(client, vm["VM_NAME"])
                if status:
                    _LOGGER.info(f'changing CPU reservation :{status}')
                else:
                    _LOGGER.error(f'changing CPU reservation :{status}')

                _LOGGER.info(
                    f'checking CPU share :{vm_tune.verify_cpu_share(client, vm["VM_NAME"])}'
                )
                status = vm_tune.config_cpu_share(client, vm["VM_NAME"])
                if status:
                    _LOGGER.info(f'changing CPU share : {status}')
                else:
                    _LOGGER.error(f'chaging CPU share : {status}')

                _LOGGER.info(
                    f'checking Memory reservation : {vm_tune.verify_mem_reservation(client,vm["VM_NAME"])}'
                )
                status = vm_tune.config_mem_reservation(client, vm["VM_NAME"])
                if status:
                    _LOGGER.info(f'changing Memory reservation :{status}')
                else:
                    _LOGGER.error(f'changing Memory reservation :{status}')

                _LOGGER.info(
                    f'checking Memory share :{vm_tune.verify_mem_share(client, vm["VM_NAME"])}'
                )
                status = vm_tune.config_mem_share(client, vm["VM_NAME"])
                if status:
                    _LOGGER.info(f'changing Memory share : {status}')
                else:
                    _LOGGER.error(f'chaging Memory share : {status}')

                for vnic in set(vm_util.get_vnic_no(client, vm["VM_NAME"])):
                    _LOGGER.info(
                        f'checking the TX thread Allocation for vnic{vnic}: {vm_tune.verify_tx_thread_allocation(client, vm["VM_NAME"],vnic)}'
                    )
                    status = vm_tune.config_tx_thread_allocation(
                        client, vm["VM_NAME"], vnic)
                    if status:
                        _LOGGER.info(
                            f'changing the TX thread allocation for vnic{vnic}: {status}'
                        )
                    else:
                        _LOGGER.error(
                            f'changing the TX thread allocation  for vnic{vnic}:: {status}'
                        )

                    _LOGGER.info(
                        f'checking the vNIC adapter type : {vm_tune.verify_nic_adapter_type(client, vm["VM_NAME"], vm_tune.get_syscontext_value(client, vm["VM_NAME"], False))}'
                    )
                    status = vm_tune.config_nic_adapter_type(
                        client, vm["VM_NAME"],
                        vm_tune.get_syscontext_value(client, vm["VM_NAME"],
                                                     False))
                    if status:
                        _LOGGER.info(
                            f'changing the vNIC adapter type  to {vm_tune.get_syscontext_value(client, vm["VM_NAME"], False)}:{status}'
                        )
                    else:
                        _LOGGER.error(
                            f'changing the vNIC adapter type  to {vm_tune.get_syscontext_value(client, vm["VM_NAME"], False)}:{status}'
                        )

                _LOGGER.info(
                    f'Checking the SysContext : {vm_tune.verify_sys_context(client,vm["VM_NAME"],param["VM_SYSCONTEXT"])}'
                )
                status = vm_tune.config_sys_context(client, vm["VM_NAME"],
                                                    param["VM_SYSCONTEXT"])
                if status:
                    _LOGGER.info(
                        f'changing SysContext value to {param["VM_SYSCONTEXT"]} : {status}'
                    )
                else:
                    _LOGGER.error(
                        f'changing SysContext value to {param["VM_SYSCONTEXT"]} : {status}'
                    )

                for nic in _NICS:
                    _LOGGER.info(
                        f'Checking the NUMA affinity value for {nic} : {vm_tune.verify_numa_affinity(client,vm["VM_NAME"], nic)}'
                    )
                    status = vm_tune.config_numa_affinity(
                        client, vm["VM_NAME"], nic)
                    if status:
                        _LOGGER.info(f'changing NUMA value for {nic}:{status}')
                    else:
                        _LOGGER.error(
                            f'changing NUMA value for {nic}:{status}')
            vm_tune.clean_file(client, vm["VM_NAME"])
            vm_util.power_on_vm(client, vm["VM_NAME"])
            print(f'- Virtual machine Verification are done.')
            print(
                f'- Getting the current configuration of virtual machine(post Optimization) :{vm["VM_NAME"]}'
            )
            print(
                parser.dict_to_table(
                    get_env_data(client, vm["VM_NAME"]),
                    f'Post configuration VM Status- {vm["VM_NAME"]}', False))
        HostSession.HostSession().disconnect(client)
Beispiel #9
0
def main():
    """
    Main Script that controls the framework execution; This is the starting point of the framework.
    """
    args = ParserUtil.Parser(__file__).parse_cmd_args()
    logger1 = logging.getLogger()

    #print(host_config.__doc__)
    # configure settings
    print("Loading configuration file values in current session...")
    settings.load_from_dir(
        os.path.join(os.path.dirname(os.path.realpath(__file__)), 'src',
                     'env_conf'))
    print("Done.")

    # load command line parameters first in case there are settings files
    # to be used
    #settings.load_from_dict(args)

    # reload command line parameters since these should take higher priority
    # than both a settings file and environment variables
    #settings.load_from_dict(args)

    # if required, handle list-* operations
    print("Scanning for command line arguments...")
    ParserUtil.Parser().process_cmd_switches(args)
    print("Done.")
    if args['collect_tech_support']:
        print(args['collect_tech_support'])
    if args['verbose']:
        LogUtil.LogUtil().configure_logging(logger1, 'debug')
    else:
        LogUtil.LogUtil().configure_logging(logger1,
                                            settings.getValue('VERBOSITY'))

    logger = LogUtil.LogUtil()
    # Check if there are any specific operations to perform, otherwise continue the normal framework execution.
    if args['collect_tech_support']:
        tech_support.TechSupport().generate_tech_support(
            'host', args['collect_tech_support'])
    if args['perform']:
        # Apply host optimizations
        if args['perform'] == 'host_config':
            logger.info('Pre optimization status')
            host_optimizations.get_host_config()
            logger.info('Initiating host optimizations.')
            if host_optimizations.host_config() == False:
                logger.error('Unable to configure host optimizations.')
                sys.exit(0)
            else:
                logger.info('Post optimization status')
                host_optimizations.get_host_config()
                logger.info('Host optimizations successful.')

        # Deploy vnfs based on the vnf.json file
        if args['perform'] == 'vm_deploy':
            logger.info('Initiating VM deployment on host')
            if vm_deploy.VMDeploy().deploy_vm() == False:
                logger.error('Unable to deploy VM.')
                sys.exit(0)
            else:
                logger.info('VM Deployment complete')
        # Apply VM optimizations
        if args['perform'] == 'vm_config':
            logger.info('Initiating VM optimization')
            vm_optimizations.vm_config()
            logger.info('VM optimization complete')

        # Run traffic from traffic generator
        if args['perform'] == 'run_traffic':
            trex = Trex.Trex()
            trex.trafficGen()
        # trex_automated.main()

        if args['perform'] == 'tech_support':
            tech_support.TechSupport().generate_tech_support('Host')

        if args['perform'] == 'monitoring':
            pass

        if args['perform'] == 'reporting':
            reporting.Report().get_excel()
            pass
    if args['host_optimization_type']:
        if args['host_optimization_type'] == 'standard+splittx':
            if not host_optimizations.host_config(splittx=True):
                logger.error('Unable to configure host optimizations.')
                sys.exit(0)
        if args['host_optimization_type'] == 'standard+splitrx':
            print(args['host_optimization_type'])
        if args['host_optimization_type'] == 'standard+splittx+splitrx':
            print(args['host_optimization_type'])
        if args['host_optimization_type'] == 'standard+splittx+rss':
            if not host_optimizations.host_config(splittx=True, rss=True):
                logger.error('Unable to configure host optimizations.')
                sys.exit(0)
            print(args['host_optimization_type'])
        if args['host_optimization_type'] == 'standard+rss':
            if not host_optimizations.host_config(rss=True):
                logger.error('Unable to configure host optimizations.')
                sys.exit(0)
            print(args['host_optimization_type'])

    if args['testcase']:
        print(args['testcase'])
        tcase = settings.getValue('TESTCASES')
        for tc in tcase:
            if args['testcase'] in tc['NAME']:
                logger.info('Initiating host optimizations.')
                if host_optimizations.host_config() == False:
                    logger.error('Unable to configure host optimizations.')
                    sys.exit(0)
                else:
                    logger.info('Host optimizations successful.')
                logger.info('Initiating VM deployment on host')
                for vm in tc['VM_NAME']:
                    if vm_deploy.VMDeploy().deploy_vm(vm) == False:
                        logger.error('Unable to deploy VM.')
                        sys.exit(0)
                else:
                    logger.info('VM Deployment complete')
                logger.info('Initiating VM optimization')
                vm_optimizations.vm_config()
                logger.info('VM optimization complete')
                trex = Trex.Trex()
                trex.trafficGen()
                sys.exit(0)
        logger.info('Initiating host optimizations.')
        if host_optimizations.host_config() == False:
            logger.error('Unable to configure host optimizations.')
            sys.exit(0)
        else:
            logger.info('Host optimizations successful.')
        logger.info('Initiating VM deployment on host')
        if vm_deploy.VMDeploy().deploy_vm() == False:
            logger.error('Unable to deploy VM.')
            sys.exit(0)
        else:
            logger.info('VM Deployment complete')
        logger.info('Initiating VM optimization')
        vm_optimizations.vm_config()
        logger.info('VM optimization complete')
        trex = Trex.Trex()
        trex.trafficGen()
Beispiel #10
0
    def process_cmd_switches(self, args):
        """ Process --list cli arguments if needed

        :param args: A dictionary with all CLI arguments
        """
        if args['list_settings']:
            print(str(settings))
            sys.exit(0)
        if args['list_testcases']:
            print(args['list_testcases'])
            if len(settings.getValue('TESTCASES')) > 0:
                #if args['list_testcase'] == 'all':
                for a in settings.getValue('TESTCASES'):
                    print(self.dict_to_table(a, a['NAME'], False))
                    print('\n')
                """
                if args['list_testcase'] == 'single':
                    for a in settings.getValue('TESTCASES'):
                        if a['FLOWTYPE'] == 'single':
                            print(self.dict_to_table(a, a['NAME'], False))
                            print('\n')
                if args['list_testcase'] == 'multiple':
                    for a in settings.getValue('TESTCASES'):
                        if a['FLOWTYPE'] == 'multiple':
                            print(self.dict_to_table(a, a['NAME'], False))
                            print('\n')
                """
            else:
                print("No defined testcases found")
            sys.exit(0)
        if args['get_testcase']:
            data = args['get_testcase'].strip().split('=')
            flag = True
            #for a in settings.getValue('TESTCASES'):
            if len(data) > 1:
                if data[0] == 'flow':
                    if data[1] == 'single':
                        print(f'Searching Testcase with {data[1]} flow')
                        for a in settings.getValue('TESTCASES'):
                            if a['FLOWTYPE'] == 'single':
                                print(self.dict_to_table(a, a['NAME'], False))
                                print('\n')
                                flag = False
                    if data[1] == 'multiple':
                        print(f'Searching Testcase with {data[1]} flow')
                        for a in settings.getValue('TESTCASES'):
                            if a['FLOWTYPE'] == 'multiple':
                                print(self.dict_to_table(a, a['NAME'], False))
                                print('\n')
                                flag = False
                if data[0] == 'vm':
                    print(f'Searching Testcase with {data[1]} virtual machines')
                    for a in settings.getValue('TESTCASES'):
                        if len(a['VM_NAME']) == int(data[1]):
                            print(self.dict_to_table(a, a['NAME'], False))
                            print('\n')
                            flag= False
            else:
                print(f'Searching Testcase with Name : {args["get_testcase"]}')
                for a in settings.getValue('TESTCASES'):
                    if a['NAME'] == args['get_testcase']:
                        print(self.dict_to_table(a, a['NAME'], False))
                        print('\n')
                        flag = False
            if flag:
                print("No defined testcase found.")
            sys.exit(0)

        if args['list_operations']:
            self.get_usecases(os.path.dirname(os.path.dirname(__file__)))
            sys.exit(0)

        if args['list_host_optimizations']:
            print(self.dict_to_table(settings.getValue('ESXI65'), 'HOST optimization settings', False))
            sys.exit(0)
        if args['list_env_details'] == 'all':
            hosts = settings.getValue('HOST_DETAILS')
            print('Environment Details')
            for host in hosts:
                client = HostSession.HostSession().connect(host['HOST'], host['USER'], host['PASSWORD'], False)
                HostUtil.HostUtil().list_env_details(client)
            sys.exit(0)

        if args['list_env_details'] == 'compact':
            hosts = settings.getValue('HOST_DETAILS')
            print('Environment Details compact')
            for host in hosts:
                client = HostSession.HostSession().connect(host['HOST'], host['USER'], host['PASSWORD'], False)
                HostUtil.HostUtil().list_env_detail_compact(client)
            sys.exit(0)

        if args['dependency_install']:
            print(f'pip install -r {os.path.dirname(os.path.abspath(__file__))}/dependency.txt')
            if self.get_os() == 'linux':
                os.system(f'pip install -r {os.path.dirname(os.path.abspath(__file__))}/dependency.txt')
            elif self.get_os() == 'darwin':
                os.system(f'pip install -r {os.path.dirname(os.path.abspath(__file__))}/dependency.txt')
            else:
                # print(self.get_os())
                os.system(f'pip install -r {os.path.dirname(os.path.abspath(__file__))}/dependency.txt')
            sys.exit(0)
Beispiel #11
0
    def trafficGen(self):
        monitor = monitoring.Monitor()
        _LOGGER.info('Initating tRex...')
        #trafficGen = json.load(open(r'env_conf\trafficGen.json'))

        #host = json.load(open(r'env_conf\host.json'))
        trafficGen = settings.getValue('TREX')
        #host = host['HOST_DETAILS']
        #print(host)
        client = HostSession.HostSession().connect(trafficGen['IP'], trafficGen['USERNAME'], trafficGen['PASSWORD'], False)
        testc = settings.getValue('TESTCASES')
        t_file = settings.getValue('TESTER-CONF')
        tc = ''
        """
        for tc in testc:
            print('first inside')
            if tc['FLOWTYPE'] == 'multiple':
                print('flow type is multiple')
                for tf in t_file:
                    print(tf['name'])
                    if len(tf['flows']) > 1:
                        print(f'Executing Test case :{tc}')
                        tc = 'tc-1.2'
                        self.monitorTest(client, test_case=tc)
            if tc['FLOWTYPE'] =='single':
                for tf in t_file:
                    if len(tf['flows'])==1:
                        print(f'Executing Test case :{tc}')
                        tc = 'tc-1.1'
                        self.monitorTest(client, test_case=tc)
        """
        file_data = self.get_data_dict(monitor.get_traffic(client, 'tc-1.1.txt'))
        # print(Monitoring.getTraffic(client, '/home/trex/Results/tc-1.1.txt'))
        _LOGGER.info(f'{file_data}')
        hosts = settings.getValue('HOST_DETAILS')
        for host in hosts:
            client2 = HostSession.HostSession().connect(host['HOST'], host['USER'], host['PASSWORD'], False)
            client3 = HostSession.HostSession().connect(host['HOST'], host['USER'], host['PASSWORD'], False)
            for frame in self.result_data['framesizes']:
                _LOGGER.info(f'Running traffic with Frame Size : {frame}')
                self.monitorTest(client, frame)
                t1 = threading.Thread(target=monitor.monitor_netstats, args=(client2, 5, 'server_netstats.logs'))
                t2 = threading.Thread(target=monitor.monitor_schedstats, args=(client3, 'server_schedstats.logs'))
                t3 = threading.Thread(target=self.monitorTest, args=(client, frame, tc))
                _LOGGER.info(f'creating the thread for Running traffic with {frame} frame size')
                t3.start()
                _LOGGER.info(f'creating the thread for net-stats -i <duration> -t WicQv -A  > server_netstats.logs')
                t1.start()
                _LOGGER.info(f'creating the thread for sched-stats -t pcpu-stats > server_schedstats.logs')
                t2.start()
                t3.join()
                t1.join()
                t2.join()
                netstats = eval(monitor.get_netstats(client2, 'server_netstats.logs'))
                # print(netstats)
                self.get_rx_thread(netstats)
                schedstats = monitor.get_schedstats(client3, 'server_schedstats.logs')
                if len(self.result_data['rx']) == 0:
                    self.result_data['rx'] = [0]*len(self.result_data['framesizes'])
                if len(self.result_data['tx']) == 0:
                    self.result_data['tx'] = [0]*len(self.result_data['framesizes'])
                _LOGGER.info(f'Result Data for Graph : {self.result_data}')
                # print(ParserUtil.Parser.dict_to_table(self.result_data,'Result', False))


        """
Beispiel #12
0
    def generate_tech_support(self, client, extra_commands=None):
        logger = LogUtil.LogUtil()
        timestamp = re.sub(":", "", LogUtil.LogUtil().get_host_time())
        dirpath = os.path.join(settings.getValue('TECH_SUPPORT_DIR'),
                               f'tech_support_{timestamp}')
        os.makedirs(dirpath)
        filename = os.path.join(dirpath, f'Command_Line_support.txt')
        logger.info('Creating command line support file...')
        print(f' - Creating command line support file...')
        try:
            with open(filename, 'w') as f:
                if client.lower() == 'host':
                    target_list = settings.getValue('HOST_DETAILS')
                    for target in target_list:
                        target_client = HostSession.HostSession().connect(
                            target['HOST'], target['USER'], target['PASSWORD'])
                        f.write(f'Host: {target["HOST"]}\n')
                        command_list = settings.getValue('ESXI_COMMANDS')
                        if extra_commands:
                            for x in extra_commands[0].split(','):
                                command_list.append(x)
                        for command in command_list:
                            stdin, stdout, stderr = target_client.exec_command(
                                command)
                            f.write(f'Executed Command: {command}\n')
                            f.write(f'Output: \n{stdout.read().decode()}')
                            errors = stderr.read().decode()
                            if len(errors):
                                f.write(f'Error: \n{errors}')
                        HostSession.HostSession().disconnect(target_client)
            logger.info(f'Command Line support file created: {filename}')
            print(f' - Command Line support file created: {filename}')

            logger.info('Collecting Net stats....')
            filename = os.path.join(dirpath, f'netstats.log')
            with open(filename, 'w') as f:
                if client.lower() == 'host':
                    target_list = settings.getValue('HOST_DETAILS')
                    for target in target_list:
                        target_client = HostSession.HostSession().connect(
                            target['HOST'], target['USER'], target['PASSWORD'])
                        f.write(f'Host: {target["HOST"]}\n')
                        command = f'net-stats -i 20 -t WicQv -A'
                        stdin, stdout, stderr = target_client.exec_command(
                            command)
                        f.write(stdout.read().decode())
                        errors = stderr.read().decode()
                        if len(errors):
                            f.write(f'Error: \n{errors}')
                        HostSession.HostSession().disconnect(target_client)
            logger.info('Collecting Sched stats...')
            filename = os.path.join(dirpath, f'schedstats.log')
            with open(filename, 'w') as f:
                if client.lower() == 'host':
                    target_list = settings.getValue('HOST_DETAILS')
                    for target in target_list:
                        target_client = HostSession.HostSession().connect(
                            target['HOST'], target['USER'], target['PASSWORD'])
                        f.write(f'Host: {target["HOST"]}\n')
                        command = f'sched-stats -t pcpu-stats'
                        stdin, stdout, stderr = target_client.exec_command(
                            command)
                        f.write(stdout.read().decode())
                        errors = stderr.read().decode()
                        if len(errors):
                            f.write(f'Error: \n{errors}')
                        logger.info('Collecting environment details...')
                        filename = os.path.join(dirpath, f'env_details.txt')
                        HostUtil.HostUtil().list_env_details(target_client,
                                                             print_flag=False)
                        HostSession.HostSession().disconnect(target_client)
            print(f' - Creating Compressed Tech support file')
            if sys.platform.startswith('win'):
                filename = shutil.make_archive(
                    dirpath, 'zip', settings.getValue('TECH_SUPPORT_DIR'))
                logger.info(f'Compressed Tech support file created {filename}')
                print(f' - Compressed Tech support file created {filename}')
                # shutil.rmtree(dirpath)
            elif sys.platform.startswith('lin'):
                filename = shutil.make_archive(
                    dirpath, 'tar', settings.getValue('TECH_SUPPORT_DIR'))
                logger.info(f'Compressed Tech support file created {filename}')
                print(f' - Compressed Tech support file created {filename}')
                shutil.rmtree(dirpath)
        except FileNotFoundError as fex:
            print(
                f'FileNotFoundError: {fex.filename} {fex.args}\nCheck TECH_SUPPORT_DIR value in common.json'
            )
        except NotImplementedError as ex:
            print(f'NotImplementedError: {ex.args}')
        except Exception as ex:
            print(f'Exception: {ex.args}')
Beispiel #13
0
def main():
    """
    Main Script that controls the framework execution; This is the starting point of the framework.
    """
    args = ParserUtil.Parser(__file__).parse_cmd_args()
    logger1 = logging.getLogger()

    # configure settings
    print("Loading configuration file values in current session...")
    settings.load_from_dir(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'src', 'env_conf'))
    print("Done.")

    # if required, handle list-* operations
    print("Scanning for command line arguments...")
    ParserUtil.Parser().process_cmd_switches(args)
    print("Done.")
    if args['generate_support_bundle']:
        print(args['generate_support_bundle'])
    if args['verbose']:
        LogUtil.LogUtil().configure_logging(logger1, 'debug')
    else:
        LogUtil.LogUtil().configure_logging(logger1, settings.getValue('VERBOSITY'))

    logger = LogUtil.LogUtil()
    # Check if there are any specific operations to perform, otherwise continue the normal framework execution.
    if args['generate_support_bundle']:
        tech_support.TechSupport().generate_tech_support('host', args['generate_support_bundle'])
    if args['perform']:
        # Apply host optimizations based on host.json file.
        if args['perform'] == 'host_optimization':
            logger.info('Initiating host optimizations.')
            splittx = False
            splitrx = False
            rss = False
            if args['host_optimization_type']:
                splittx = 'splittx' in args['host_optimization_type']
                splitrx = 'splitrx' in args['host_optimization_type']
                rss = 'rss' in args['host_optimization_type']
            if host_optimizations.host_config(splitrx = splitrx, splittx = splittx, rss = rss) == False:
                logger.error('Unable to configure host optimizations.')
                print('Unable to configure host optimizations. See logs for more details.')
            else:
                logger.info('Host optimizations successful.')
                print('Host optimizations successful.')
            sys.exit(0)

        # Deploy vnfs based on the vnf.json file.
        if args['perform'] == 'vm_deploy':
            logger.info('Initiating VM deployment on host')
            if vm_deploy.VMDeploy().deploy_vm() == False:
                logger.error('Unable to deploy VM.')
                print('Unable to deploy VM. See logs for more details.')
                sys.exit(0)
            else:
                logger.info('VM Deployment complete')
        
        # Apply VM optimizations based on vm.json file.
        if args['perform'] == 'vm_optimization':
            logger.info('Initiating VM optimization')
            vm_optimizations.vm_config()
            logger.info('VM optimization complete')

        # Run traffic from traffic generator based on traffic_config.json file.
        if 'traffic_run' in args['perform']:
            logger.info('Setting up DPDK application on VM(s)')
            logger.info('Setting up traffic profile and initiating traffic run.')
            print('Initiating traffic from spirent')
            traffic_config.test_run(testcase=args['perform'].split()[1], restart = True)
            """result = Spirent.spirent_util(tc=args['perform'].split()[1], rfc=True, restart = True)
            config = {}
            client = HostSession.HostSession().connect('192.168.11.4', 'root', 'ca$hc0w', False)
            config['host'] = host_optimizations.get_host_config(printdata=False)
            config['vm'] = vm_optimizations.get_env_data(client, settings.getValue('VM_TOPOLOGY')['VM_DETAILS'][0]['VM_NAME'])
            HostSession.HostSession().disconnect(client)
            print(DbUtil.db_util(result['data'], config))"""

        # Generate support bundle.
        if args['perform'] == 'generate_support_bundle':
            logger.info('Generating support bundle')
            tech_support.TechSupport().generate_tech_support('Host')
            sys.exit(0)

        # Perform Monitoring.
        if args['perform'] == 'monitoring':
            Trex.Trex().specify_dest_mac()
            sys.exit(0)

        # Perform Reporting.
        if args['perform'] == 'reporting':
            reporting.Report().get_excel()
            sys.exit(0)

    if args['testcase']:
        print(args['testcase'])
        tcase = settings.getValue('TRAFFIC_PROFILE')
        for tc in tcase:
            if args['testcase'] in tc['TESTCASE']:
                # Host Config
                logger.info('Initiating host optimizations.')
                splittx = False
                splitrx = False
                rss = False
                if args['host_optimization_type']:
                    splittx = 'splittx' in args['host_optimization_type']
                    splitrx = 'splitrx' in args['host_optimization_type']
                    rss = 'rss' in args['host_optimization_type']
                if host_optimizations.host_config(splitrx = splitrx, splittx = splittx, rss = rss) == False:
                    logger.error('Unable to configure host optimizations.')
                    print('Unable to configure host optimizations. See logs for more details.')
                    sys.exit(0)
                else:
                    logger.info('Host optimizations successful.')
                    print('Host optimizations successful.')
                # VM deploy
                logger.info('Initiating VM deployment on host')
                if vm_deploy.VMDeploy().deploy_vm() == False:
                    logger.error('Unable to deploy VM.')
                    print('Unable to deploy VM. See logs for more details.')
                    sys.exit(0)
                else:
                    logger.info('VM Deployment complete. Waiting for IP configurations to take place...')
                    time.sleep(60)
                logger.info('Initiating VM optimization')
                vm_optimizations.vm_config()
                logger.info('VM optimization complete')
                Spirent.stc_util()
                #trex = Trex.Trex()
                #trex.trafficGen()
                sys.exit(0)