#!/bin/bash -x

ip link del eth1
nmcli c del bond0
nmcli c del bond0-port1

ip link add eth1 address 00:23:45:67:89:1a type veth peer name eth1peer
ip link set eth1 up
ip link set eth1peer up
ip link set eth1peer netns tmp
ip netns exec tmp ip link set eth1peer up

nmcli device set eth1 managed yes

nmcli c add type bond ifname bond0 connection.id bond0 \
    ipv4.method disabled ipv6.method disabled

nmcli c add type ethernet connection.id bond0-port1 \
    802-3-ethernet.mac-address 00:23:45:67:89:1a \
    connection.controller bond0 connection.port-type bond

nmcli c up bond0
nmcli c up bond0-port1

nmcli c modify bond0-port1 bond-port.prio 10

nmcli c down bond0-port1
nmcli c up bond0-port1

NEW_PRIO=$(ip -j -d link show eth1  | \
    jq '.[0]."linkinfo"."info_slave_data"."prio"')

if [ $NEW_PRIO -ne 10 ];then
    echo "FAILED, current bond port prio is ${NEW_PRIO}"
    exit 1
fi
