Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bp #95

Closed
wants to merge 2 commits into from
Closed

Bp #95

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions snap/hooks/pre-refresh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

# Note (mkalcok): `microovn.switch` service, by default, stops OVS
# vswitch daemon with `--cleanup` flag that releases datapath
# resources like ports and bridges. This hook prevents such behavior
# by stopping the daemon without `--cleanup` flag during the snap
# refresh.

${SNAP}/commands/ovs-appctl exit || true
2 changes: 1 addition & 1 deletion snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ apps:
command: commands/switch.start
daemon: simple
install-mode: disable
refresh-mode: endure
stop-command: commands/switch.stop
plugs:
- firewall-control
- hardware-observe
Expand Down
8 changes: 8 additions & 0 deletions snapcraft/commands/switch.stop
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh
set -eu

export OVS_RUNDIR="${SNAP_COMMON}/run/switch"

# Stop vswitchd
"${SNAP}/commands/ovs-appctl" exit --cleanup
"${SNAP}/share/openvswitch/scripts/ovs-ctl" stop
1 change: 1 addition & 0 deletions tests/lifecycle.bats
63 changes: 63 additions & 0 deletions tests/test_helper/bats/lifecycle.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# This is a bash shell fragment -*- bash -*-

setup_file() {
load test_helper/common.bash
load test_helper/lxd.bash
load test_helper/microovn.bash


TEST_CONTAINERS=$(container_names "$BATS_TEST_FILENAME" 1)
export TEST_CONTAINERS
launch_containers jammy $TEST_CONTAINERS
wait_containers_ready $TEST_CONTAINERS
}

teardown_file() {
delete_containers $TEST_CONTAINERS
}

setup() {
load test_helper/common.bash
load test_helper/lxd.bash
load test_helper/microovn.bash
load ${ABS_TOP_TEST_DIRNAME}../.bats/bats-support/load.bash
load ${ABS_TOP_TEST_DIRNAME}../.bats/bats-assert/load.bash

# Ensure TEST_CONTAINERS is populated, otherwise the tests below will
# provide false positive results.
assert [ -n "$TEST_CONTAINERS" ]

# Trim trailing whitespace from a variable with only single container
TEST_CONTAINER="$(echo -e "${TEST_CONTAINERS}" | sed -e 's/[[:space:]]*$//')"
export TEST_CONTAINER
}

teardown() {
lxc_exec "$TEST_CONTAINER" "snap remove microovn" || true
}

@test "Cleanup OVS datapaths on snap removal" {
# Verify that removal of MicroOVN snap cleans up DP resources

# The tests will need external `ovs-dpctl` command to check DPs after
# microovn removal.
lxc_exec "$TEST_CONTAINER" "DEBIAN_FRONTEND=noninteractive apt install -yqq openvswitch-switch"

echo "Checking datapaths on container '$TEST_CONTAINER' before MicroOVN installation."
run lxc_exec "$TEST_CONTAINER" "ovs-dpctl dump-dps | wc -l"
assert_output "0"

install_microovn "$MICROOVN_SNAP_PATH" "$TEST_CONTAINER"
bootstrap_cluster "$TEST_CONTAINER"

echo "Checking datapaths on container '$TEST_CONTAINER' after MicroOVN bootstrap."
run lxc_exec "$TEST_CONTAINER" "ovs-dpctl dump-dps | wc -l"
assert_output "1"

echo "Removing MicroOVN snap."
run lxc_exec "$TEST_CONTAINER" "snap remove microovn"

echo "Checking datapaths on container '$TEST_CONTAINER' after MicroOVN removal."
run lxc_exec "$TEST_CONTAINER" "ovs-dpctl dump-dps | wc -l"
assert_output "0"
}
Loading