def bash_get_intf_mac(self, node, intf): ''' return mac address of a host interface ''' t = test.Test() n = t.node(node) output = n.sudo("ifconfig %s | grep --color=never HWaddr" % (intf))['content'] return_stat = n.sudo('echo $?')['content'] return_stat = helpers.strip_cli_output(return_stat) helpers.log("return_stat: %s" % return_stat) if int(return_stat) == 1: # helpers.log("I am here") return '' else: # helpers.log("I am there") # helpers.log("output: %s" % output) output = helpers.strip_cli_output(output) result = re.search('HWaddr (.*)', output) mac_addr = result.group(1) helpers.log("output: %s" % output) helpers.log("result: %s" % result) # mac = mac_addr.replace("\r", "") mac = mac_addr.strip(' \t\n\r') helpers.log("mac_addr: %s" % mac_addr) return mac
def bash_get_blocked_thread(self, node): ''' do df in debug bash ouput: index: directory with all the field ''' t = test.Test() n = t.node(node) content = n.bash('sudo jps -l')['content'] lines = helpers.strip_cli_output(content, to_list=True) helpers.log("lines: %s" % lines) for line in lines: line = line.lstrip() helpers.log(" line is - %s" % line) if (re.match(r'(\d+) org.projectfloodlight.core.Main', line)): match = re.match(r'(\d+) .*projectfloodlight.*', line) pid = match.group(1) helpers.log("INFO: ***floodlight pid is \n %s" % pid) break string = 'sudo jstack -F -l ' + pid + ' > /tmp/jstack.log' content = n.bash(string, timeout=3600)['content'] content = n.bash('cat /tmp/jstack.log | grep BLOCKED | wc -l' )['content'] temp = helpers.strip_cli_output(content) temp = helpers.str_to_list(temp) helpers.log("*****Output list is :\n%s" % temp) temp.pop(0) for line in temp: line = line.lstrip() helpers.log(" line is - %s" % line) if (re.match(r'(\d+).*', line)): helpers.log("INFO:blocked threads are \n %s" % match.group(1)) return match.group(1) break return True
def cli_show_endpoint_pattern(self,pattern): ''' ''' helpers.test_log("Entering ==> cli_show_endpoint_filter: %s" % pattern) t = test.Test() c = t.controller('master') cli= 'show endpoint | grep ' + pattern + ' | wc -l' content = c.cli(cli)['content'] temp = helpers.strip_cli_output(content) return temp
def bash_run_command(self, node, cmd): t = test.Test() n = t.node(node) try: content = n.bash("%s " % cmd)['content'] str_list = helpers.strip_cli_output(content, to_list=True) except: helpers.test_error("Bash run command failed", soft_error=True) str_list = "Bash Run Command Failed" return str_list
def bash_ls(self, node, path): """ Execute 'ls -l --time-style=+%Y-%m-%d <path>' on a device. Inputs: | node | reference to switch/controller/host as defined in .topo file | | path | directory to get listing for | Example: - bash ls master /home/admin - bash ls h1 /etc/passwd Return Value: - Dictionary with file name as key. Value contains list of fields, where - fields[0] = file/dir - fields[1] = no of links - fields[2] = user - fields[3] = group - fields[4] = size - fields[5] = datetime """ t = test.Test() n = t.node(node) content = n.bash('ls -l --time-style=+%%Y-%%m-%%d %s' % path)['content'] lines = helpers.strip_cli_output(content, to_list=True) # Output: # total 691740 # -rw-r--r-- 1 root root 708335092 2014-03-03 13:08 controller-upgrade-bvs-2.0.5-SNAPSHOT.pkg # -rw-r--r-- 1 bsn bsn 0 2014-03-12 10:05 blah blah.txt # Strip first line ('total <nnnnn>') lines = lines[1:] # helpers.log("lines: %s" % helpers.prettify(lines)) files = {} for line in lines: fields = line.split() helpers.log("fields: %s" % fields) # fields[6]+ contains filename (may have spaces in name) filename = ' '.join(fields[6:]) # If file is a symlink, remove the symlink (leave just the name) # E.g., 'blkid.tab -> /dev/.blkid.tab' filename = re.sub('-> .*$', '', filename) files[filename] = fields[0:6] helpers.log("files:\n%s" % helpers.prettify(files)) return files
def bash_get_interface_ipv4(self, node, intf): t = test.Test() n = t.node(node) output = n.sudo("ifconfig %s | grep --color=never -i 'inet addr'" % intf)['content'] return_stat = n.sudo('echo $?')['content'] return_stat = helpers.strip_cli_output(return_stat) helpers.log("output: %s" % output) helpers.log("return_stat: %s" % return_stat) if int(return_stat) == 1: return '' else: result = re.search('inet addr:(.*)\sBcast', output) return result.group(1)
def bash_release_dhcpv4_address(self, node, intf): t = test.Test() n = t.node(node) n.sudo("dhclient -r %s" % intf) return True n.sudo("ifconfig %s | grep --color=never -i 'inet addr'" % intf)['content'] return_stat = n.sudo('echo $?')['content'] return_stat = helpers.strip_cli_output(return_stat) helpers.log("return_stat: %s" % return_stat) if int(return_stat) == 1: return True else: return False
def get_L2_table_count(self, node): t = test.Test() s = t.switch(node) string = 'debug ofad "brcmdriver3 flow-stats"' content = s.enable(string)['content'] temp = helpers.strip_cli_output(content, to_list=True) helpers.log("***temp is: %s \n" % temp) for line in temp: helpers.log("***line is: %s \n" % line) line = line.lstrip() match = re.match(r'L2 (\d+)\s+(\d+).*', line) if match: helpers.log("INFO: Total L2 table size is %s, and current allocation is: %s" % (match.group(1), match.group(2))) return match.group(2) return 0
def bash_renew_dhcpv4_address(self, node, intf): ''' attempt to obtain an IPv4 address via dhcp. timeout is set to 10 seconds in /etc/dhcp/dhclient.conf file for ubuntu host ''' t = test.Test() n = t.node(node) n.sudo("dhclient -v -4 %s" % intf) output = n.sudo("ifconfig %s | grep --color=never -i 'inet addr'" % intf)['content'] return_stat = n.sudo('echo $?')['content'] return_stat = helpers.strip_cli_output(return_stat) helpers.log("return_stat: %s" % return_stat) if int(return_stat) == 1: return '' else: result = re.search('inet addr:(.*)\sBcast', output) return result.group(1).strip()
def cli_get_links_nodes(self,node1, node2): ''' ''' helpers.test_log("Entering ==> cli_get_links_nodes: %s - %s" %( node1, node2) ) t = test.Test() c = t.controller('master') cli= 'show link | grep ' + node1 + ' | grep ' + node2 content = c.cli(cli)['content'] temp = helpers.strip_cli_output(content, to_list=True) helpers.log("INFO: *** output *** \n %s" %temp) linkinfo = {} linkinfo[node1]={} linkinfo[node2]={} for line in temp: line = line.lstrip() fields = line.split() helpers.log("fields: %s" % fields) N1 = fields[1] N2 = fields[3] match = re.match(r'.*-(.*)',fields[2]) intf1= match.group(1) match = re.match(r'.*-(.*)',fields[4]) intf2= match.group(1) linkinfo[N1][intf1]= {} linkinfo[N1][intf1]['name']= intf1 linkinfo[N1][intf1]['nbr']= N2 linkinfo[N1][intf1]['nbr-intf']= intf2 linkinfo[N2][intf2]= {} linkinfo[N2][intf2]['name']= intf2 linkinfo[N2][intf2]['nbr']= N1 linkinfo[N2][intf2]['nbr-intf']= intf1 helpers.log("INFO: *** link info *** \n %s" % helpers.prettify(linkinfo)) return linkinfo
def verify_logs_numbers(self, node): """ Check if number of logs stored in elasticsarch matches number of lines in floodlight.log, syslog and switch syslogs. Inputs: | node | reference to controller as defined in .topo file | Return Value: - True if numbers are matching, False otherwise """ t = test.Test() c = t.controller(node) total_logs = 0 tmp_flag = False helpers.log("Checking how many logs" " are present on node %s" % node) c.bash("sudo iptables -A INPUT -p tcp --dport 9200 -j ACCEPT") c.bash("sudo ls -alt /var/log/floodlight/floodlight.log*") output = c.cli_content() output = helpers.strip_cli_output(output) output = helpers.str_to_list(output) if len(output) > 1: c.bash("sudo cp /var/log/floodlight/floodlight.log.* /tmp/") c.bash("sudo gunzip /tmp/floodlight.log*") c.bash("grep $(date +'20%y-%m-%d'') /tmp/" "floodlight.log* > /tmp/floodlight_date") tmp_flag = True else: c.bash("grep $(date +'20%y-%m-%d') /var/log/floodlight/" "floodlight.log > /tmp/floodlight_date") c.bash("sudo wc -l /tmp/floodlight_date") output = c.cli_content() output = helpers.strip_cli_output(output) output = helpers.str_to_list(output) number = output[len(output) - 1].split()[0] helpers.log("There are %s lines in floodlight.log" % number) total_logs = total_logs + int(number) if (tmp_flag == True): c.bash("sudo rm /tmp/floodlight.log*") c.bash("sudo rm /tmp/floodlight_date") c.bash("sudo wc -l /var/log/syslog*") output = c.cli_content() output = helpers.strip_cli_output(output) output = helpers.str_to_list(output) number = output[len(output) - 1].split()[0] helpers.log("There are %s lines in syslog" % number) total_logs = total_logs + int(number) c.bash("sudo wc -l /var/log/switch/*") output = c.cli_content() output = helpers.strip_cli_output(output) output = helpers.str_to_list(output) if "No such file or directory" in output[0]: number = 0 else: number = output[len(output) - 1].split()[0] helpers.log("There are %s lines in switch syslogs" % number) total_logs = total_logs + int(number) c.bash("grep $(date +'20%y-%m-%d') /var/log/vsphere-extension/" "vsphere-extension.log* > /tmp/vsphere_date") c.bash("sudo wc -l /tmp/vsphere_date*") output = c.cli_content() output = helpers.strip_cli_output(output) output = helpers.str_to_list(output) number = output[len(output) - 1].split()[0] helpers.log("There are %s lines in vsphere-extension.log" % number) total_logs = total_logs + int(number) c.bash("sudo rm /tmp/vsphere_date") helpers.log("There are %s lines in controller logs" % total_logs) helpers.log("Checking how many entries are reported by Elasticsearch") c.bash("curl -XGET 'http://localhost:9200/_search'; echo") output = c.cli_content() output = helpers.strip_cli_output(output) data = json.loads(output) total_elastic = int(data['hits']['total']) helpers.log("There are %s entries in Elasticsearch" % total_elastic) helpers.log("Controller: %s, Elastic: %s" % (total_logs, total_elastic)) tolerance = total_logs / 50 helpers.log("Allowed discrepancy in logs is 2%%, i.e. %s" % tolerance) discrepancy = abs(total_logs - total_elastic) helpers.log("Actual discrepancy is %s" % discrepancy) if (discrepancy < tolerance): return True else: helpers.log("The discrepancy in log numbers is too big") return False