Skip to content
Permalink
Browse files

test: Tests for physical mtu and mac application and restoration

Signed-off-by: Thomas Parrott <thomas.parrott@canonical.com>
  • Loading branch information...
tomponline committed May 10, 2019
1 parent 038f487 commit 97fc734c9cdfb3782a172c4bb5b975dd3ff45a8e
Showing with 155 additions and 22 deletions.
  1. +155 −22 test/suites/container_devices_nic_physical.sh
@@ -2,53 +2,186 @@ test_container_devices_nic_physical() {
ensure_import_testimage
ensure_has_localhost_remote "${LXD_ADDR}"

ct_name="nt$$"
ctName="nt$$"
dummyMAC="AA:3B:97:97:0F:D5"
ctMAC="0A:92:a7:0d:b7:D9"

# Create dummy interface for use as parent.
ip link add "${ct_name}" type dummy
ip link set "${ct_name}" up
ip link add "${ctName}" address "${dummyMAC}" type dummy

# Create test container from default profile.
lxc init testimage "${ct_name}"
lxc init testimage "${ctName}"

# Add physical device to container/
lxc config device add "${ct_name}" eth0 nic \
lxc config device add "${ctName}" eth0 nic \
nictype=physical \
parent="${ct_name}" \
parent="${ctName}" \
name=eth0 \
mtu=1400
mtu=1400 \
hwaddr="${ctMAC}"

# Lauch container and check it has nic applied correctly.
lxc start "${ct_name}"
# Launch container and check it has nic applied correctly.
lxc start "${ctName}"

# Check custom MTU is applied if feature available in LXD.
if lxc info | grep 'network_phys_macvlan_mtu: "true"' ; then
if ! lxc exec "${ct_name}" -- ip link show eth0 | grep "mtu 1400" ; then
if ! lxc exec "${ctName}" -- grep "1400" /sys/class/net/eth0/mtu ; then
echo "mtu invalid"
false
fi
fi

lxc config device remove "${ct_name}" eth0
# Check custom MAC is applied in container.
if ! lxc exec "${ctName}" -- grep -i "${ctMAC}" /sys/class/net/eth0/address ; then
echo "mac invalid"
false
fi

# Stop container and check MTU is restored.
lxc stop "${ctName}"

# Check original MTU is restored on physical device.
if lxc info | grep 'network_phys_macvlan_mtu: "true"' ; then
if ! grep "1500" /sys/class/net/"${ctName}"/mtu ; then
echo "mtu invalid"
false
fi
fi

# Check original MAC is restored on physical device.
if ! grep -i "${dummyMAC}" /sys/class/net/"${ctName}"/address ; then
echo "mac invalid"
false
fi

# Remove boot time physical device and check MTU is restored.
lxc start "${ctName}"
lxc config device remove "${ctName}" eth0

# Check original MTU is restored on physical device.
if lxc info | grep 'network_phys_macvlan_mtu: "true"' ; then
if ! grep "1500" /sys/class/net/"${ctName}"/mtu ; then
echo "mtu invalid"
false
fi
fi

# Check original MAC is restored on physical device.
if ! grep -i "${dummyMAC}" /sys/class/net/"${ctName}"/address ; then
echo "mac invalid"
false
fi

# Test hot-plugging physical device based on vlan parent.
ip link set "${ct_name}" up
lxc config device add "${ct_name}" eth0 nic \
# Make the MTU higher than the original boot time 1400 MTU above to check that the
# parent device's MTU is reset on removal to the pre-boot value on host (expect >=1500).
ip link set "${ctName}" up #VLAN requires parent nic be up.
lxc config device add "${ctName}" eth0 nic \
nictype=physical \
parent="${ct_name}" \
parent="${ctName}" \
name=eth0 \
vlan=10 \
mtu=1399 #This must be less than or equal to the MTU of the parent device (which is not being reset)
hwaddr="${ctMAC}" \
mtu=1401 #Higher than 1400 boot time value above

# Check custom MTU is applied if feature available in LXD.
if lxc info | grep 'network_phys_macvlan_mtu: "true"' ; then
if ! lxc exec "${ctName}" -- grep "1401" /sys/class/net/eth0/mtu ; then
echo "mtu invalid"
false
fi
fi

# Check custom MAC is applied in container.
if ! lxc exec "${ctName}" -- grep -i "${ctMAC}" /sys/class/net/eth0/address ; then
echo "mac invalid"
false
fi

# Remove hot-plugged physical device and check MTU is restored.
lxc config device remove "${ctName}" eth0

# Check original MTU is restored on physical device.
if lxc info | grep 'network_phys_macvlan_mtu: "true"' ; then
if ! grep "1500" /sys/class/net/"${ctName}"/mtu ; then
echo "mtu invalid"
false
fi
fi

# Check original MAC is restored on physical device.
if ! grep -i "${dummyMAC}" /sys/class/net/"${ctName}"/address ; then
echo "mac invalid"
false
fi

# Test hot-plugging physical device based on existing parent.
# Make the MTU higher than the original boot time 1400 MTU above to check that the
# parent device's MTU is reset on removal to the pre-boot value on host (expect >=1500).
lxc config device add "${ctName}" eth0 nic \
nictype=physical \
parent="${ctName}" \
name=eth0 \
hwaddr="${ctMAC}" \
mtu=1402 #Higher than 1400 boot time value above

# Check custom MTU is applied if feature available in LXD.
if lxc info | grep 'network_phys_macvlan_mtu: "true"' ; then
if ! lxc exec "${ctName}" -- grep "1402" /sys/class/net/eth0/mtu ; then
echo "mtu invalid"
false
fi
fi

# Check custom MAC is applied in container.
if ! lxc exec "${ctName}" -- grep -i "${ctMAC}" /sys/class/net/eth0/address ; then
echo "mac invalid"
false
fi

# Test removing a physical device an check its MTU gets restored to default 1500 mtu
lxc config device remove "${ctName}" eth0

# Check original MTU is restored on physical device.
if lxc info | grep 'network_phys_macvlan_mtu: "true"' ; then
if ! grep "1500" /sys/class/net/"${ctName}"/mtu ; then
echo "mtu invalid"
false
fi
fi

# Check original MAC is restored on physical device.
if ! grep -i "${dummyMAC}" /sys/class/net/"${ctName}"/address ; then
echo "mac invalid"
false
fi

# Test hot-plugging physical device based on existing parent with new name that LXC doesn't know about.
lxc config device add "${ctName}" eth1 nic \
nictype=physical \
parent="${ctName}" \
hwaddr="${ctMAC}" \
mtu=1402 #Higher than 1400 boot time value above

# Stop the container, LXC doesn't know about the nic, so we will rely on LXD to restore it.
lxc stop "${ctName}"

# Check original MTU is restored on physical device.
if lxc info | grep 'network_phys_macvlan_mtu: "true"' ; then
if ! grep "1500" /sys/class/net/"${ctName}"/mtu ; then
echo "mtu invalid"
false
fi
fi

# Check custom MTU is applied.
if ! lxc exec "${ct_name}" -- ip link show eth0 | grep "mtu 1399" ; then
echo "mtu invalid"
# Check original MAC is restored on physical device.
if ! grep -i "${dummyMAC}" /sys/class/net/"${ctName}"/address ; then
echo "mac invalid"
false
fi

# Destroy the container and check the physical interface is returned to the host for clean up.
lxc delete "${ct_name}" -f
lxc delete "${ctName}"

# Remove dummy interface if present.
ip link delete "${ct_name}" || true
# Remove dummy interface (should still exist).
ip link delete "${ctName}"
}

0 comments on commit 97fc734

Please sign in to comment.
You can’t perform that action at this time.