def start_httperf_on_client(client_handles, vs_name, vs_port, uri, rate, num_conns, requests_per_session, **kwargs): """ Runs on the main interface of the client vm :param client_handles: :param vs_name: :param vs_port: :param uri: :param rate: :param num_conns: :param requests_per_session: :param kwargs: :return: """ method = kwargs.get('method', 'GET') client_handles = traffic_manager.get_client_handles_from_range(client_handles) vip = kwargs.get('vip', None) if not vip: vip = vs_lib.get_vip(vs_name) command = 'httperf ' # --timeout 0.5 command += '--hog --server %s --port %s --wsess %s,%s,0 --rate %s --uri "%s" --method %s --recv-buffer 1240000 --send-buffer 1240000 &> /tmp/httperf.txt &' % ( vip, vs_port, num_conns, requests_per_session, rate, uri, method) logger.info('start_httperf_on_client:'+command) for client_handle in client_handles: vm, ip = traffic_manager.get_client_by_handle(client_handle) vm.execute_command(command)
def simulate_ingress(handle, machine_type='client', **kwargs): client = machine_type.lower() == 'client' match1 = re.search('(.+\D+)(\d+)-(\d+)', handle) if match1: prefix = match1.group(1) start = match1.group(2) end = match1.group(3) for i in range(int(start), int(end) + 1): if client: vm, ip = traffic_manager.get_client_by_handle(prefix + str(i)) else: vm = ServerModel.get_server(prefix + str(i)).vm() vm.apply_net_emulation(prefix + str(i), machine_type, **kwargs) else: if client: vm, ip = traffic_manager.get_client_by_handle(handle) else: vm = ServerModel.get_server(handle).vm() vm.apply_net_emulation(handle, machine_type, **kwargs)
def stop_httperf_on_client(client_handles): """ :param client_handles: :return: """ client_handles = common.parse_handles(client_handles) for client_handle in client_handles: client_vm, ip = traffic_manager.get_client_by_handle(client_handle) client_vm.execute_command('pkill -9 -f httperf', log_error=False)
def stop_http_traffic(client_range, delete_httptest_files=1, log_file=''): clients = get_clients_from_range(client_range) vm, ip = traffic_manager.get_client_by_handle(clients[0]) if log_file != '': vm.execute_command('pkill -9 -f ' + log_file) else: vm.execute_command('pkill -9 -f httptest.py') if bool(delete_httptest_files): vm.execute_command('rm -rf /tmp/httptest_io_*') for vm in infra_utils.get_vm_of_type('server'): vm.execute_command('rm -rf /usr/share/nginx/www/uploads/*')
def stop_ab_on_client(client_handles): """ :param client_handles: :return: """ client_handles = traffic_manager.get_client_handles_from_range(client_handles) for client_handle in client_handles: client_vm, ip = traffic_manager.get_client_by_handle(client_handle) client_vm.execute_command('pkill -9 -f ab', log_error=False) client_vm.execute_command('pkill -9 -f run_ab.sh', log_error=False) client_vm.execute_command('rm -rf /tmp/ab.log')
def udp_client(client, vs_name, **kwargs): """ API Helps to start UDP from Client for given vs, addr_type, vip_idx, port Args: :param client: client handles to send UDP Traffic :type client: str :param vs_name: vs name on which we want to send UDP Traffic :type vs_name: str Kwargs: :param addr_type:VIP Address type, in case of Dual VIP :type addr_type: str, default 'V4' :param vip_id: VS VIP index value :type vip_id: int, default 0 Raises: KeyError """ addr_type = kwargs.get('addr_type', 'V4') vip_id = kwargs.get('vip_id', 0) port = kwargs.get('port', 8000) data = kwargs.get('data', 512) no_of_udp_req = kwargs.get('no_of_udp_req', 1) print_resp = kwargs.get('print_resp', 0) vip = get_vs_vip(vs_name, addr_type, vip_id) cmd = 'python /root/client/tools/udp_client.py --ip %s --p %s --data %s --n %s\ --print_resp %s &> /tmp/upd_out &' % (vip, port, data, no_of_udp_req, print_resp) logger.info("UDP client command: %s" % cmd) client_vm, client_ip = get_client_by_handle(client) client_vm.execute_command(cmd) sleep(1) out = client_vm.execute_command('cat /tmp/upd_out') logger.info("UDP Traffic CMD out: %s " % ''.join(out)) if not out: client_vm.execute_command(cmd) sleep(1) out = client_vm.execute_command('cat /tmp/upd_out') logger.info("UDP Traffic CMD out: %s " % ''.join(out)) out = ''.join(out).replace('\n', '-').split('-') return out
def scapy_client(client, command): """ API Helps to start scapy from Client by executing given scapy command Args: :param client: client handles to send scapy traffic :type client: str :param command: sacpy command to send :type command: str """ cmd = 'echo "%s\n">>/tmp/scapy_cmd && touch /tmp/scapy_cmd_done' % command logger.info("scapy_client command: %s" % cmd) client_vm, client_ip = get_client_by_handle(client) out = client_vm.execute_command(cmd) sleep(1) logger.info("Started scapy on client : %s" % out)
def is_there_IO_error(client_range, log_file='httptest_io_error*', raise_exception=False): """ While traffic genearation IO errors are generally logged at /tmp/httptest_<timestamp>.log. The function checks if the log file is present or not. """ if isinstance(log_file, basestring): logs = [log_file] else: logger_utils.fail( 'HttpTest failed. Error - Log file should be of type string, but got : %s' % log_file) for _log_file in logs: logger.info('is_there_IO_error: %s\n' % log_file) clients = get_clients_from_range(client_range) vm, ip = traffic_manager.get_client_by_handle(clients[0]) logger.debug('VM IP, NAME, CLIENT: %s, %s, %s' % (vm.ip, vm.name, ip)) cmd = 'tail -5 %s' % log_file resp = vm.execute_command(cmd) if len(resp) > 0 and raise_exception: error_msg = 'Get request failed\n' for error in resp: try: msg = json.loads(error) except Exception: # When httptest fails, it doesn't write error log in json # format. logger_utils.error('HttpTest failed. Error - %s' % error) error_msg += 'Client: %s\nValidation: %s\nExpected: %s\nActual: ' \ '%s\n\n' % (msg['client'], msg['error_code'], msg['expected'], msg['actual']) # Cleaning up before raising exception vm.execute_command('rm %s &> /tmp/httptest' % log_file) logger_utils.error(error_msg) else: if len(resp) == 0: return 'False' else: logger.info('Failures: %s' % resp) return 'True'
def stop_udp_clients_and_servers(client=None, servers=None, server_handle=None): """ API helps to stop udp on client and servers Args: :param client: client handles to send UDP Traffic :type client: str :param servers: list of server handles want to Listen on Server :type servers: List :param server_handle: server handles want to stop udp listen, if case want to stop on signle server :type server_handle: str Raises: KeyError """ kill_client_command = 'pkill -9 -f udp_client.py' if client: client_vm, client_ip = get_client_by_handle(client) client_vm.execute_command(kill_client_command, log_error=False) if not servers: servers = get_all_server_handle() elif isinstance(servers, basestring): servers = [servers] for server in servers: server_vm = get_server_by_handle(server).vm() if server_handle == server: pids = 'ps -aux |grep \"%s\" | grep -v grep |awk \"{print $2;}\"' % server pids = ' '.join(pids).replace('\n', '') kill_server_command = 'sudo kill -9 %s' % pids else: kill_server_command = 'pkill -9 -f udp_server.py' server_vm.execute_command(kill_server_command, log_error=False)
def stop_scapy_clients_and_servers(client, server): """ API helps to stop scapy on client and servers Args: :param client: client handles to stop Scapy Traffic :type client: str :param server: server handles to stop scapy Listen on Server :type server: str Raises: KeyError """ reset_iptables_command = 'iptables -F' kill_client_command = 'pkill -9 -f scapy' client_vm, client_ip = get_client_by_handle(client) client_vm.execute_command(kill_client_command, log_error=False) client_vm.execute_command(reset_iptables_command) kill_server_command = 'pkill -9 -f scapy' server_vm = get_server_by_handle(server).vm() server_vm.execute_command(kill_server_command, log_error=False) server_vm.execute_command(reset_iptables_command)
def run_ab_on_client(client_handles, vs_name, vs_port, path, c, n): """ Runs on the main interface of the client vm :param client_handles: :param vs_name: :param vs_port: :param path: :param c: :param n: :return: """ client_handles = traffic_manager.get_client_handles_from_range(client_handles) vip = vs_lib.get_vip(vs_name) vip_port = "%s:%s" % (vip, vs_port) kill_ab = "pkill -9 -f ab" run_ab = "ab -c %s -n %s http://%s/%s&> /tmp/ab.txt &" % \ (c, n, vip_port, path) logger.info('start_apache_bench run_ab:'+ run_ab) logger.info('vip_port'+ vip_port) for client_handle in client_handles: vm, ip = traffic_manager.get_client_by_handle(client_handle) vm.execute_command(kill_ab, log_error=False) vm.execute_command(run_ab)
def scapy_connect(clients, vs_name, port, **kwargs): """ API helps to start scapy connect from client for given vs and port Args: :param client: client handles to connect sacpy :type client: str :param vs_name: vs name to connect sacpy from client :type vs_name: str :param port: On which port Scapy start from client :type port: str Return: process grep of scapy Raises: KeyError """ out = [] params = [] vip = get_vs_vip(vs_name) # port = config.get_vport(service) for key in kwargs: found = re.match('(.*)_(delay|drop)', key) params.append('-' + found.group(1)) params.append(found.group(2)) if found.group(2) == 'delay': params.append(kwargs.get(key)) found = re.match('([^\d]+)([\d]+)-?([\d]+)?', clients) if found is None: fail('ERROR! Example client range format c1 or c1-10') client_prefix = found.group(1) client_start = int(found.group(2)) if found.group(3): client_end = int(found.group(3)) else: client_end = 1 client_vm = 0 tmp_args = '-client -H' eth_int = '' dst_mac = '' for i in range(client_start, client_end + 1): client_vm, client_ip = get_client_by_handle(client_prefix + str(i)) logger.debug('client_ip is: %s ' % client_ip) dst_mac = get_dst_mac(client_vm, client_ip, vip) tmp_args = tmp_args + ' ' + client_ip iptable_cmd = 'iptables -A OUTPUT -p tcp --tcp-flags RST RST -s ' + \ client_ip + ' -j DROP' client_vm.execute_command(iptable_cmd) eth_int = client_vm.get_eth_of_app_client(client_prefix + str(i)) tmp_args = tmp_args + ' -D ' + vip + ' -P ' + str(port) tmp_args = tmp_args + ' -F ' + dst_mac + \ ' -i ' + eth_int + ' ' + ' '.join(params) logger.info('/root/common/scapy/scapy_terminals.py %s >& /tmp/tmp &' % tmp_args) client_vm.execute_command_tcptest( '/root/common/scapy/scapy_terminals.py %s >& /tmp/tmp &' % tmp_args) tmp_out = client_vm.execute_command('pgrep scapy') proc_infos = tmp_out try: procId = proc_infos[0] except: logger.info('Cannot get process id for scapy client') procId = 'None' out.append(procId) return out