コード例 #1
0
def network_dropped_two(context, state, device):
    if state == "is":
        assert command_code(context,
                            'ping -c 2 -I %s -W 1 8.8.8.8' % device) != 0
    if state == "is not":
        assert command_code(context,
                            'ping -c 2 -I %s -W 1 8.8.8.8' % device) == 0
コード例 #2
0
def start_pppoe_server(context, name, ip, dev):
    command_code(context, "ip link set dev %s up" % dev)
    Popen(
        "kill -9 $(pidof pppoe-server); pppoe-server -S %s -C %s -L %s -p /etc/ppp/allip -I %s"
        % (name, name, ip, dev),
        shell=True)
    sleep(0.5)
コード例 #3
0
def execute_multiple_times(context, command, number):
    orig_nm_pid = check_output('pidof NetworkManager', shell=True).decode('utf-8', 'ignore')

    i = 0
    while i < int(number):
        command_code(context, command)
        curr_nm_pid = check_output('pidof NetworkManager', shell=True).decode('utf-8', 'ignore')
        assert curr_nm_pid == orig_nm_pid, 'NM crashed as original pid was %s but now is %s' %(orig_nm_pid, curr_nm_pid)
        i += 1
コード例 #4
0
ファイル: device.py プロジェクト: pemensik/NetworkManager-ci
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!')
コード例 #5
0
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)
コード例 #6
0
def prepare_sriov_config(context, conf, device, vfs):
    conf_path = "/etc/NetworkManager/conf.d/" + conf
    command_code(context, "echo '[device-%s]' > %s" % (device, conf_path))
    command_code(
        context,
        "echo 'match-device=interface-name:%s' >> %s" % (device, conf_path))
    command_code(context,
                 "echo 'sriov-num-vfs=%d' >> %s" % (int(vfs), conf_path))
    command_code(context, 'systemctl reload NetworkManager')
コード例 #7
0
def write_dispatcher_file(context, path, params=None):
    if path.startswith("/"):
        disp_file = path
        dir = os.path.dirname(disp_file)
        if not os.path.exists(dir):
            os.makedirs(dir)
    else:
        disp_file = '/etc/NetworkManager/dispatcher.d/%s' % path
    f = open(disp_file, 'w')
    f.write('#!/bin/bash\n')
    if params:
        f.write(params)
    f.write('\necho $2 >> /tmp/dispatcher.txt\n')
    f.close()
    command_code(context, 'chmod +x %s' % disp_file)
    command_code(context, "> /tmp/dispatcher.txt")
    sleep(8)
コード例 #8
0
ファイル: device.py プロジェクト: pemensik/NetworkManager-ci
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
コード例 #9
0
def hostname_visible(context, log, seconds=1):
    seconds = int(seconds)
    orig_seconds = seconds
    cmd = "grep $(hostname -s) '%s'" %log
    while seconds > 0:
        if command_code(context, cmd) != 0:
            return True
        seconds = seconds - 1
        sleep(1)
    raise Exception('Hostname visible in log after %d seconds' % (orig_seconds - seconds))
コード例 #10
0
def check_slave_in_team_is_up(context, slave, team, state):
    #sleep(2)
    r = command_code(context,
                     'sudo teamdctl %s port present %s' % (team, slave))
    if state == "up":
        if r != 0:
            sleep(1)
            r = command_code(
                context, 'sudo teamdctl %s port present %s' % (team, slave))
            if r != 0:
                raise Exception('Device %s was not found in dump of team %s' %
                                (slave, team))

    if state == "down":
        if r == 0:
            sleep(1)
            r = command_code(
                context, 'sudo teamdctl %s port present %s' % (team, slave))
            if r == 0:
                raise Exception('Device %s was found in dump of team %s' %
                                (slave, team))
コード例 #11
0
def prepare_pppoe_server(context, user, passwd, ip, auth):
    command_code(
        context,
        "echo -e 'require-%s\nlogin\nlcp-echo-interval 10\nlcp-echo-failure 2\nms-dns 8.8.8.8\nms-dns 8.8.4.4\nnetmask 255.255.255.0\ndefaultroute\nnoipdefault\nusepeerdns' > /etc/ppp/pppoe-server-options"
        % auth)
    command_code(
        context,
        "echo '%s * %s %s' > /etc/ppp/%s-secrets" % (user, passwd, ip, auth))
    command_code(context, "echo '%s-253' > /etc/ppp/allip" % ip)
コード例 #12
0
def restart_dhcp_server(context, device, ipv4, ipv6):
    command_code(context,
                 'kill $(cat /tmp/{device}_ns.pid)'.format(device=device))
    command_code(
        context,
        "ip netns exec {device}_ns ip addr flush dev {device}_bridge".format(
            device=device))
    command_code(
        context,
        "ip netns exec {device}_ns ip addr add {ip}.1/24 dev {device}_bridge".
        format(device=device, ip=ipv4))
    command_code(
        context,
        "ip netns exec {device}_ns ip -6 addr add {ip}::1/64 dev {device}_bridge"
        .format(device=device, ip=ipv6))
    command_code(
        context, "ip netns exec {device}_ns dnsmasq \
                                        --pid-file=/tmp/{device}_ns.pid \
                                        --dhcp-leasefile=/tmp/{device}_ns.lease \
                                        --dhcp-range={ipv4}.10,{ipv4}.15,2m \
                                        --dhcp-range={ipv6}::100,{ipv6}::fff,slaac,64,2m \
                                        --enable-ra --interface={device}_bridge \
                                        --bind-interfaces".format(
            device=device, ipv4=ipv4, ipv6=ipv6))
コード例 #13
0
def start_stop_connection(context, action, name):
    if action == "down":
        if command_code(context, "nmcli connection show --active |grep %s" %name) != 0:
            print ("Warning: Connection is down no need to down it again")
            return

    cli = pexpect.spawn('nmcli connection %s id %s' % (action, name), logfile=context.log,  timeout=180, encoding='utf-8')

    r = cli.expect(['Error', 'Timeout', pexpect.TIMEOUT, pexpect.EOF])
    if r == 0:
        raise Exception('Got an Error while %sing connection %s\n%s%s' % (action, name, cli.after, cli.buffer))
    elif r == 1:
        raise Exception('nmcli connection %s %s timed out (90s)' % (action, name))
    elif r == 2:
        raise Exception('nmcli connection %s %s timed out (180s)' % (action, name))
コード例 #14
0
def do_device_stuff(context, action, what):
    command_code(
        context,
        "for dev in $(nmcli device status | grep '%s' | awk {'print $1'}); do nmcli device %s $dev; done"
        % (what, action))
コード例 #15
0
def execute_command(context, command):
    command_code(context, command)
    sleep(0.3)
コード例 #16
0
def restore_hostname(context):
    command_code('nmcli g hostname %s' % context.noted['noted-value'])
    sleep(0.5)
コード例 #17
0
def network_dropped(context, state):
    if state == "is":
        assert command_code(context, 'ping -c 1 -W 1 boston.com') != 0
    if state == "is not":
        assert command_code(context, 'ping -c 1 -W 1 boston.com') == 0
コード例 #18
0
def delete_device(context, old_device, new_device):
    command_code(context, "ip link set dev %s down" % old_device)
    command_code(context, "ip link set %s name %s" % (old_device, new_device))
    command_code(context, "ip link set dev %s ip" % old_device)
コード例 #19
0
def wait_for_process(context, command):
    assert command_code(context, command) != 0
    sleep(0.1)
コード例 #20
0
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))
コード例 #21
0
def prepare_dhcpd_simdev(context, device, server_id):
    ipv4 = "192.168.99"
    command_code(context, "ip netns add {device}_ns".format(device=device))
    command_code(
        context, "ip link add {device} type veth peer name {device}p".format(
            device=device))
    command_code(
        context,
        "ip link set {device}p netns {device}_ns".format(device=device))
    command_code(context, "ip link set {device} up".format(device=device))
    command_code(
        context, "ip netns exec {device}_ns ip link set {device}p up".format(
            device=device))
    command_code(
        context,
        "ip netns exec {device}_ns ip addr add {ip}.1/24 dev {device}p".format(
            device=device, ip=ipv4))
    command_code(
        context,
        "echo '127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4' > /etc/hosts"
    )
    command_code(
        context,
        "echo '::1         localhost localhost.localdomain localhost6 localhost6.localdomain6' >> /etc/hosts"
    )
    command_code(context,
                 "echo '192.168.99.10 ip-192-168-99-10' >> /etc/hosts")
    command_code(context,
                 "echo '192.168.99.11 ip-192-168-99-11' >> /etc/hosts")
    command_code(context,
                 "echo '192.168.99.12 ip-192-168-99-12' >> /etc/hosts")
    command_code(context,
                 "echo '192.168.99.13 ip-192-168-99-13' >> /etc/hosts")
    command_code(context,
                 "echo '192.168.99.14 ip-192-168-99-14' >> /etc/hosts")
    command_code(context,
                 "echo '192.168.99.15 ip-192-168-99-15' >> /etc/hosts")

    config = []
    if server_id is not None:
        config.append(
            "server-identifier {server_id};".format(server_id=server_id))
    config.append("max-lease-time 150;")
    config.append("default-lease-time 120;")
    config.append("subnet {ip}.0 netmask 255.255.255.0 {{".format(ip=ipv4))
    config.append("  range {ip}.10 {ip}.15;".format(ip=ipv4))
    config.append("}}".format(ip=ipv4))

    f = open('/tmp/dhcpd.conf', 'w')
    for line in config:
        f.write(line + '\n')
    f.close()

    command_code(
        context,
        "ip netns exec {device}_ns dhcpd -4 -cf /tmp/dhcpd.conf -pf /tmp/{device}_ns.pid"
        .format(device=device))
    if not hasattr(context, 'testvethns'):
        context.testvethns = []
    context.testvethns.append("%s_ns" % device)
コード例 #22
0
def prepare_simdev(context, device):
    if not hasattr(context, 'testvethns'):
        os.system(
            '''echo 'ENV{ID_NET_DRIVER}=="veth", ENV{INTERFACE}=="test*", ENV{NM_UNMANAGED}="0"' >/etc/udev/rules.d/88-lr.rules'''
        )
        command_code(context, "udevadm control --reload-rules")
        command_code(context, "udevadm settle --timeout=5")
        command_code(context, "sleep 1")
    #         +-------testX_ns--------+ +--testX2_ns--+
    # testX <-|-> testXp     testX2 <-|-|-> testX2p   |
    #         |  fd01::1     fd02::1  | |   fd02::2   |
    # mtu 1500|   1500        1400    | |    1500     |
    #         +-----------------------+ +-------------+
    command_code(context, "ip netns add {device}_ns".format(device=device))
    command_code(context, "ip netns add {device}2_ns".format(device=device))
    command_code(
        context, "ip link add {device} type veth peer name {device}p".format(
            device=device))
    command_code(
        context, "ip link add {device}2 type veth peer name {device}2p".format(
            device=device))
    command_code(
        context,
        "ip link set {device}p netns {device}_ns".format(device=device))
    command_code(
        context,
        "ip link set {device}2 netns {device}_ns".format(device=device))
    command_code(
        context,
        "ip link set {device}2p netns {device}2_ns".format(device=device))
    # Bring up devices
    command_code(context, "ip link set {device} up".format(device=device))
    command_code(
        context, "ip netns exec {device}_ns ip link set {device}p up".format(
            device=device))
    command_code(
        context, "ip netns exec {device}_ns ip link set {device}2 up".format(
            device=device))
    command_code(
        context, "ip netns exec {device}2_ns ip link set {device}2p up".format(
            device=device))
    # Set addresses
    command_code(
        context,
        "ip netns exec {device}_ns ip addr add dev {device}p fd01::1/64".
        format(device=device))
    command_code(
        context,
        "ip netns exec {device}_ns ip addr add dev {device}2 fd02::1/64".
        format(device=device))
    command_code(
        context,
        "ip netns exec {device}2_ns ip addr add dev {device}2p fd02::2/64".
        format(device=device))
    # Set MTU
    command_code(
        context,
        "ip netns exec {device}_ns ip link set {device}p mtu 1500".format(
            device=device))
    command_code(
        context,
        "ip netns exec {device}_ns ip link set {device}2 mtu 1400".format(
            device=device))
    command_code(
        context,
        "ip netns exec {device}2_ns ip link set {device}2p mtu 1500".format(
            device=device))
    # Set up router (testX_ns)
    command_code(
        context,
        "ip netns exec {device}_ns sh -c 'echo 1 > /proc/sys/net/ipv6/conf/all/forwarding'"
        .format(device=device))
    command_code(
        context, "ip netns exec {device}_ns dnsmasq \
                                         --no-resolv \
                                         --pid-file=/tmp/{device}_ns.pid \
                                         --bind-interfaces -i {device}p \
                                         --enable-ra \
                                         --dhcp-range=::1,::400,constructor:{device}p,ra-only,64,15s"
        .format(device=device))
    # Add route
    command_code(
        context,
        "ip netns exec {device}2_ns ip route add fd01::/64 via fd02::1 dev {device}2p"
        .format(device=device))
    # Run netcat server to receive some data
    Popen("ip netns exec {device}2_ns nc -6 -l -p 8080 > /dev/null".format(
        device=device),
          shell=True)

    if not hasattr(context, 'testvethns'):
        context.testvethns = []
    context.testvethns.append("%s_ns" % device)
    context.testvethns.append("%s2_ns" % device)
コード例 #23
0
def prepare_simdev_no_carrier(context, device):
    ipv4 = "192.168.99"
    ipv6 = "2620:dead:beaf"
    if not hasattr(context, 'testvethns'):
        os.system(
            '''echo 'ENV{ID_NET_DRIVER}=="veth", ENV{INTERFACE}=="test*", ENV{NM_UNMANAGED}="0"' >/etc/udev/rules.d/88-lr.rules'''
        )
        command_code(context, "udevadm control --reload-rules")
        command_code(context, "udevadm settle --timeout=5")
        command_code(context, "sleep 1")
    command_code(context, "ip netns add {device}_ns".format(device=device))
    command_code(
        context,
        "ip netns exec {device}_ns ip link add {device} type veth peer name {device}p"
        .format(device=device))
    command_code(
        context, "ip netns exec {device}_ns ip link set {device}p up".format(
            device=device))
    command_code(
        context, "ip netns exec {device}_ns ip link set {device} up".format(
            device=device))
    command_code(
        context,
        "ip netns exec {device}_ns ip link add name {device}_bridge type bridge"
        .format(device=device))
    command_code(
        context,
        "ip netns exec {device}_ns ip link set {device}p master {device}_bridge"
        .format(device=device))
    command_code(
        context,
        "ip netns exec {device}_ns ip addr add {ip}.1/24 dev {device}_bridge".
        format(device=device, ip=ipv4))
    command_code(
        context,
        "ip netns exec {device}_ns ip -6 addr add {ip}::1/64 dev {device}_bridge"
        .format(device=device, ip=ipv6))
    command_code(
        context,
        "ip netns exec {device}_ns ip link set {device}_bridge up".format(
            device=device))
    command_code(
        context, "ip netns exec {device}_ns ip link set {device}p down".format(
            device=device))
    command_code(
        context, "ip netns exec {device}_ns dnsmasq \
                                            --pid-file=/tmp/{device}_ns.pid \
                                            --dhcp-leasefile=/tmp/{device}_ns.lease \
                                            --dhcp-range={ipv4}.10,{ipv4}.15,2m \
                                            --dhcp-range={ipv6}::100,{ipv6}::1ff,slaac,64,2m \
                                            --enable-ra --interface={device}_bridge \
                                            --bind-interfaces".format(
            device=device, ipv4=ipv4, ipv6=ipv6))
    command_code(
        context,
        "ip netns exec {device}_ns ip link set {device} netns 1".format(
            device=device))
    if not hasattr(context, 'testvethns'):
        context.testvethns = []
    context.testvethns.append("%s_ns" % device)
コード例 #24
0
def prepare_simdev_no_dhcp(context, device):
    if not hasattr(context, 'testvethns'):
        os.system(
            '''echo 'ENV{ID_NET_DRIVER}=="veth", ENV{INTERFACE}=="test*", ENV{NM_UNMANAGED}="0"' >/etc/udev/rules.d/88-lr.rules'''
        )
        command_code(context, "udevadm control --reload-rules")
        command_code(context, "udevadm settle --timeout=5")
        command_code(context, "sleep 1")
    command_code(context, "ip netns add {device}_ns".format(device=device))
    command_code(
        context, "ip link add {device} type veth peer name {device}p".format(
            device=device))
    command_code(
        context,
        "ip link set {device}p netns {device}_ns".format(device=device))
    # Bring up devices
    command_code(context, "ip link set {device} up".format(device=device))
    command_code(
        context, "ip netns exec {device}_ns ip link set {device}p up".format(
            device=device))
    if not hasattr(context, 'testvethns'):
        context.testvethns = []
    context.testvethns.append("%s_ns" % device)
コード例 #25
0
def prepare_simdev(context, device):
    if not hasattr(context, 'testvethns'):
        os.system(
            '''echo 'ENV{ID_NET_DRIVER}=="veth", ENV{INTERFACE}=="test*", ENV{NM_UNMANAGED}="0"' >/etc/udev/rules.d/88-lr.rules'''
        )
        command_code(context, "udevadm control --reload-rules")
        command_code(context, "udevadm settle --timeout=5")
        command_code(context, "sleep 1")
    #         +-------testX_ns--------+ +--testX2_ns--+
    # testX <-|-> testXp     testX2 <-|-|-> testX2p   |
    # (DHCP   | 172.16.0.1  10.0.0.2  | |  10.0.0.1   |
    # client) |(dhcrelay + forwarding)| | (DHCP serv) |
    #         +-----------------------+ +-------------+
    command_code(context, "ip netns add {device}_ns".format(device=device))
    command_code(context, "ip netns add {device}2_ns".format(device=device))
    command_code(
        context, "ip link add {device} type veth peer name {device}p".format(
            device=device))
    command_code(
        context, "ip link add {device}2 type veth peer name {device}2p".format(
            device=device))
    command_code(
        context,
        "ip link set {device}p netns {device}_ns".format(device=device))
    command_code(
        context,
        "ip link set {device}2 netns {device}_ns".format(device=device))
    command_code(
        context,
        "ip link set {device}2p netns {device}2_ns".format(device=device))
    # Bring up devices
    command_code(context, "ip link set {device} up".format(device=device))
    command_code(
        context, "ip netns exec {device}_ns ip link set {device}p up".format(
            device=device))
    command_code(
        context, "ip netns exec {device}_ns ip link set {device}2 up".format(
            device=device))
    command_code(
        context, "ip netns exec {device}2_ns ip link set {device}2p up".format(
            device=device))
    # Set addresses
    command_code(
        context,
        "ip netns exec {device}_ns ip addr add dev {device}p 172.16.0.1/24".
        format(device=device))
    command_code(
        context,
        "ip netns exec {device}_ns ip addr add dev {device}2 10.0.0.2/24".
        format(device=device))
    command_code(
        context,
        "ip netns exec {device}2_ns ip addr add dev {device}2p 10.0.0.1/24".
        format(device=device))
    # Enable forwarding and DHCP relay in first namespace
    command_code(
        context,
        "ip netns exec {device}_ns sh -c 'echo 1 > /proc/sys/net/ipv4/ip_forward'"
        .format(device=device))
    command_code(
        context,
        "ip netns exec {device}_ns dhcrelay -4 10.0.0.1 -pf /tmp/dhcrelay.pid".
        format(device=device))
    # Start DHCP server in second namespace
    # Push a default route and a route to reach the DHCP server
    command_code(
        context, "ip netns exec {device}2_ns dnsmasq \
                                         --pid-file=/tmp/{device}_ns.pid \
                                         --bind-interfaces -i {device}2p \
                                         --dhcp-range=172.16.0.100,172.16.0.200,255.255.255.0,1m \
                                         --dhcp-option=3,172.16.0.50 \
                                         --dhcp-option=121,10.0.0.0/24,172.16.0.1"
        .format(device=device))
    if not hasattr(context, 'testvethns'):
        context.testvethns = []
    context.testvethns.append("%s_ns" % device)
    context.testvethns.append("%s2_ns" % device)
コード例 #26
0
def prepare_veths(context, pairs_array, bridge):
    os.system(
        '''echo 'ENV{ID_NET_DRIVER}=="veth", ENV{INTERFACE}=="test*", ENV{NM_UNMANAGED}="0"' >/etc/udev/rules.d/88-lr.rules'''
    )
    command_code(context, "udevadm control --reload-rules")
    command_code(context, "udevadm settle --timeout=5")
    command_code(context, "sleep 1")

    pairs = []
    for pair in pairs_array.split(','):
        pairs.append(pair.strip())

    command_code(context, "sudo ip link add name %s type bridge" % bridge)
    command_code(context, "sudo ip link set dev %s up" % bridge)
    for pair in pairs:
        command_code(context,
                     "ip link add %s type veth peer name %sp" % (pair, pair))
        command_code(context, "ip link set %sp master %s" % (pair, bridge))
        command_code(context, "ip link set dev %s up" % pair)
        command_code(context, "ip link set dev %sp up" % pair)
コード例 #27
0
def reload_connections(context):
    command_code(context, "nmcli con reload")
    sleep(0.5)
コード例 #28
0
def setup_macsec_psk(context, cak, ckn):
    command_code(context, "modprobe macsec")
    command_code(context, "ip netns add macsec_ns")
    command_code(context,
                 "ip link add macsec_veth type veth peer name macsec_vethp")
    command_code(context, "ip link set macsec_vethp netns macsec_ns")
    command_code(context, "ip link set macsec_veth up")
    command_code(context,
                 "ip netns exec macsec_ns ip link set macsec_vethp up")
    command_code(context, "echo 'eapol_version=3' > /tmp/wpa_supplicant.conf")
    command_code(context, "echo 'ap_scan=0' >> /tmp/wpa_supplicant.conf")
    command_code(context, "echo 'network={' >> /tmp/wpa_supplicant.conf")
    command_code(context, "echo '  key_mgmt=NONE' >> /tmp/wpa_supplicant.conf")
    command_code(context, "echo '  eapol_flags=0' >> /tmp/wpa_supplicant.conf")
    command_code(context,
                 "echo '  macsec_policy=1' >> /tmp/wpa_supplicant.conf")
    command_code(
        context,
        "echo '  mka_cak={cak}' >> /tmp/wpa_supplicant.conf".format(cak=cak))
    command_code(
        context,
        "echo '  mka_ckn={ckn}' >> /tmp/wpa_supplicant.conf".format(ckn=ckn))
    command_code(context, "echo '}' >> /tmp/wpa_supplicant.conf")

    command_code(
        context, "ip netns exec macsec_ns wpa_supplicant \
                                         -c /tmp/wpa_supplicant.conf \
                                         -i macsec_vethp \
                                         -B \
                                         -D macsec_linux \
                                         -P /tmp/wpa_supplicant_ms.pid")
    sleep(6)
    assert command_code(
        context, "ip netns exec macsec_ns ip link show macsec0"
    ) == 0, "wpa_supplicant didn't create a MACsec interface"
    command_code(context, "ip netns exec macsec_ns ip link set macsec0 up")
    command_code(
        context,
        "ip netns exec macsec_ns ip addr add 172.16.10.1/24 dev macsec0")
    command_code(
        context, "ip netns exec macsec_ns dnsmasq \
                                         --pid-file=/tmp/dnsmasq_ms.pid \
                                         --dhcp-range=172.16.10.10,172.16.10.254,60m  \
                                         --interface=macsec0 \
                                         --bind-interfaces")
コード例 #29
0
def prepare_simdev(context,
                   device,
                   lease_time="2m",
                   ipv4=None,
                   ipv6=None,
                   option=None,
                   daemon_options=None):
    if ipv4 is None:
        ipv4 = "192.168.99"
    if ipv6 is None:
        ipv6 = "2620:dead:beaf"
    if daemon_options is None:
        daemon_options = ""
    if not hasattr(context, 'testvethns'):
        os.system(
            '''echo 'ENV{ID_NET_DRIVER}=="veth", ENV{INTERFACE}=="%s*", ENV{NM_UNMANAGED}="0"' >/etc/udev/rules.d/88-lr.rules'''
            % device)
        command_code(context, "udevadm control --reload-rules")
        command_code(context, "udevadm settle --timeout=5")
        command_code(context, "sleep 1")
    command_code(context, "ip netns add {device}_ns".format(device=device))
    command_code(
        context, "ip link add {device} type veth peer name {device}p".format(
            device=device))
    command_code(
        context,
        "ip link set {device}p netns {device}_ns".format(device=device))
    command_code(context, "ip link set {device} up".format(device=device))
    command_code(
        context, "ip netns exec {device}_ns ip link set {device}p up".format(
            device=device))
    command_code(
        context,
        "ip netns exec {device}_ns ip addr add {ip}.1/24 dev {device}p".format(
            device=device, ip=ipv4))
    command_code(
        context,
        "ip netns exec {device}_ns ip -6 addr add {ip}::1/64 dev {device}p".
        format(device=device, ip=ipv6))
    command_code(
        context,
        "echo '127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4' > /etc/hosts"
    )
    command_code(
        context,
        "echo '::1         localhost localhost.localdomain localhost6 localhost6.localdomain6' >> /etc/hosts"
    )
    command_code(context,
                 "echo '192.168.99.10 ip-192-168-99-10' >> /etc/hosts")
    command_code(context,
                 "echo '192.168.99.11 ip-192-168-99-11' >> /etc/hosts")
    command_code(context,
                 "echo '192.168.99.12 ip-192-168-99-12' >> /etc/hosts")
    command_code(context,
                 "echo '192.168.99.13 ip-192-168-99-13' >> /etc/hosts")
    command_code(context,
                 "echo '192.168.99.14 ip-192-168-99-14' >> /etc/hosts")
    command_code(context,
                 "echo '192.168.99.15 ip-192-168-99-15' >> /etc/hosts")
    sleep(2)

    if option:
        option = "--dhcp-option-force=" + option
    else:
        option = ""

    dnsmasq_command = "ip netns exec {device}_ns dnsmasq \
                                --interface={device}p \
                                --bind-interfaces \
                                --pid-file=/tmp/{device}_ns.pid \
                                --dhcp-leasefile=/tmp/{device}_ns.lease \
                                {option} \
                                {daemon_options}".format(
        device=device, option=option, daemon_options=daemon_options)
    dnsmasq_command += " --dhcp-range={ipv4}.10,{ipv4}.15,{lease_time} ".format(
        lease_time=lease_time, ipv4=ipv4)
    if lease_time != 'infinite':
        dnsmasq_command += " --dhcp-range={ipv6}::100,{ipv6}::fff,slaac,64,{lease_time} \
                             --enable-ra".format(lease_time=lease_time,
                                                 ipv6=ipv6)

    assert command_code(
        context, dnsmasq_command
    ) == 0, "unable to start dnsmasq using command `{dnsmasq_command}`".format(
        dnsmasq_command=dnsmasq_command)

    if not hasattr(context, 'testvethns'):
        context.testvethns = []
    context.testvethns.append("%s_ns" % device)
コード例 #30
0
def start_radvd(context, location):
    command_code(context, "rm -rf /etc/radvd.conf")
    command_code(context, "cp %s /etc/radvd.conf" % location)
    command_code(context, "systemctl restart radvd")
    sleep(2)