2. Check if driver options(FCoE, RSS) are configured; configurations made accordingly 3. Check if size of ring buffers for physical NICs is set at required values; configurations made accordingly 4. Check if size of software TX queues is set at required values; configurations made accordingly 5. Check if Queue pairing is enabled; configurations made accordingly 6. Check if TX split mode is enabled; configurations made accordingly These checks are performed as per the values provided in the host.conf file. Tester can choose to go with the default configs of the ESXi host or to change some of them or to change them all. Command line switches are provided for the corresponding usecase. """ from src.core.host import Host from src.util import HostSession, LogUtil, ParserUtil from src.env_conf import settings logger = LogUtil.LogUtil() 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
import math, re from src.util import ParserUtil, LogUtil from src.env_conf import settings _LOGGER = LogUtil.LogUtil() class HostUtil: def __init__(self): pass def get_nics(self, client): """ Print the list of NICs and their settings. :param client: paramiko SSHClient object :return: <dict> NIC details """ stdin, stdout, stderr = client.exec_command('esxcfg-nics --list') a = stdout.read().decode() a = re.sub(' +', ' ', a).rstrip() a = a.split('\n') b = a[0].rstrip().split(' ') del b[8] q = dict() q[b[0]], q[b[1]], q[b[2]] = [], [], [] q[b[3]], q[b[4]], q[b[5]] = [], [], [] q[b[6]], q[b[7]], q[b[8]] = [], [], [] for nic in a[1:]: a1 = nic.split(' ') b1 = a1[8:] b1 = ' '.join(b1)
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}')
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()
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)