def note_mac_address_ip(context, device, index=None): if call("ip a s %s |grep -q ether" % device, shell=True) == 0: mac = command_output( context, "ip link show %s | grep 'link/ether' | awk '{print $2}'" % device).strip() if call("ip a s %s |grep -q infiniband" % device, shell=True) == 0: ip_out = command_output( context, "ip link show %s | grep 'link/inf' | awk '{print $2}'" % device).strip() mac = ip_out.split()[-1] client_id = "" mac_split = mac.split(":")[-8:] for i in mac_split: if i == mac_split[-1]: client_id += i else: client_id += i + ":" mac = client_id if index: if not hasattr(context, 'noted'): context.noted = {} context.noted[index] = mac else: if not hasattr(context, 'noted'): context.noted = {} context.noted['noted-value'] = mac print(mac)
def create_policy_based_routing_files(context, profile, dev, table): ips = command_output( context, "nmcli connection sh %s |grep IP4.ADDRESS |awk '{print $2}'" % profile) ip_slash_prefix = ips.split('\n')[0] ip = ip_slash_prefix.split('/')[0] gw = command_output( context, "nmcli connection sh %s |grep IP4.GATEWAY |awk '{print $2}'" % profile).strip() command_code( context, "echo '%s dev %s table %s' > /etc/sysconfig/network-scripts/route-%s" % (ip_slash_prefix, dev, table, profile)) command_code( context, "echo 'default via %s dev %s table %s' >> /etc/sysconfig/network-scripts/route-%s" % (gw, dev, table, profile)) command_code( context, "echo 'iif %s table %s' > /etc/sysconfig/network-scripts/rule-%s" % (dev, table, profile)) command_code( context, "echo 'from %s table %s' >> /etc/sysconfig/network-scripts/rule-%s" % (ip, table, profile)) sleep(3)
def note_mac_address(context, device): if not hasattr(context, 'noted'): context.noted = {} context.noted['noted-value'] = command_output( context, "ethtool -P %s |grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}'" % device).strip()
def add_secondary_addr_same_subnet(context, device): from netaddr import IPNetwork primary_ipn = IPNetwork(command_output(context, "ip -4 a s %s | awk '/inet .*dynamic/ {print $2}'" % device)) if str(primary_ipn.ip).split('.')[2] == str(primary_ipn.ip+1).split('.')[2]: secondary_ip = primary_ipn.ip+1 else: secondary_ip = primary_ipn.ip-1 assert command_code(context, 'ip addr add dev %s %s/%d' % (device, str(secondary_ip), primary_ipn.prefixlen)) == 0
def check_dns_domain(context, device, domain, kind="routing"): try: context.execute_steps( u'''* "Domain: \(%s\) %s\\r\\n" is not visible with command "prepare/%s %s"''' % (kind, re.escape(domain), context.dns_script, device)) except AssertionError: out = command_output(context, "prepare/%s %s" % (context.dns_script, device)).strip() raise AssertionError("Actual DNS configuration for %s is:\n%s\n" % (device, out))
def check_dns_domain(context, device, dns): try: context.execute_steps( '* "DNS: %s\\r\\n" is visible with command "prepare/%s %s"' % (re.escape(dns), context.dns_script, device)) except AssertionError: out = command_output(context, "prepare/%s %s" % (context.dns_script, device)).strip() raise AssertionError("Actual DNS configuration for %s is:\n%s\n" % (device, out))
def correct_lifetime(context, typ, valid_lft, pref_lft, device): if typ == 'IPv6': inet = "inet6" if typ == 'IPv4': inet = "inet" valid_cmd = "ip a s '%s' |grep -A 1 -w '%s'| grep -A 1 -w 'scope global' |grep valid_lft |awk '{print $2}'" % (device, inet) pref_cmd = "ip a s '%s' |grep -A 1 -w '%s'| grep -A 1 -w 'scope global' |grep valid_lft |awk '{print $4}'" % (device, inet) valid = command_output(context, valid_cmd).split()[0] pref = command_output(context, pref_cmd).split()[0] valid = valid.strip() valid = valid.replace('sec', '') pref = pref.strip() pref = pref.replace('sec', '') assert int(valid) < int(valid_lft) and int(valid) >= int(valid_lft)-50, "valid: %s, not close to: %s" % (valid, valid_lft) assert int(pref) < int(pref_lft) and int(pref) >= int(pref_lft)-50, "pref: %s, not close to : %s" % (pref, pref_lft)
def check_ipv6_connectivity_on_assumal(context, profile, device): context.nm_restarted = True address = command_output(context, "ip -6 a s %s | grep dynamic | awk '{print $2; exit}' | cut -d '/' -f1" % device) assert command_code(context, 'systemctl stop NetworkManager.service') == 0 assert command_code(context, "sed -i 's/UUID=/#UUID=/' /etc/sysconfig/network-scripts/ifcfg-%s" % profile) == 0 ping = pexpect.spawn('ping6 %s -i 0.2 -c 50' % address, logfile=context.log, encoding='utf-8') sleep(1) assert command_code(context, 'systemctl start NetworkManager.service') == 0 sleep(12) r = ping.expect(["0% packet loss", pexpect.EOF, pexpect.TIMEOUT]) if r != 0: raise Exception('Had packet loss on pinging the address!')
def check_solicitation(context, dev, file): #file = '/tmp/solicitation.txt' #dev = 'enp0s25' cmd = "ip a s %s |grep ff:ff|awk {'print $2'}" % dev mac = "" for line in command_output(context, cmd).split('\n'): if line.find(':') != -1: mac = line.strip() mac_last_4bits = mac.split(':')[-2] + mac.split(':')[-1] dump = open(file, 'r') assert mac_last_4bits not in dump.readlines( ), "Route solicitation from %s was found in tshark dump" % mac
def global_tem_address_check(context, dev): cmd = "ip a s %s" % dev mac = "" temp_ipv6 = "" ipv6 = "" for line in command_output(context, cmd).split('\n'): if line.find('brd ff:ff:ff:ff:ff:ff') != -1: mac = line.split()[1] if line.find('scope global temporary dynamic') != -1: temp_ipv6 = line.split()[1] if line.find('scope global dynamic') != -1: ipv6 = line.split()[1] assert temp_ipv6 != ipv6, 'IPV6 Address are similar!' temp_ipv6_end = temp_ipv6.split('/')[0].split(':')[-1] mac_end = mac.split(':')[-2] + mac.split(':')[-1] assert temp_ipv6_end != mac_end, 'Mac and tmp Ipv6 are similar in the end %s..%s'
def modify_connection(context, name, options): out = command_output(context, "nmcli connection modify %s %s" % (name, options)) if 'Error' in out: raise Exception('Got an Error while modifying %s options %s\n%s' % (name, options, out))
def note_the_output_of(context, command): if not hasattr(context, 'noted'): context.noted = {} context.noted['noted-value'] = command_output(context, command).strip()
def note_the_output_as(context, command, index): if not hasattr(context, 'noted'): context.noted = {} context.noted[index] = command_output(context, command + " 2>/dev/null").strip()
def force_renew_ipv6(context, device): mac = command_output(context, "ip a s %s |grep fe80 |awk '{print $2}'" % device).strip() command_code(context, "ip -6 addr flush dev %s" % (device)) command_code(context, "ip addr add %s dev %s" % (mac, device))