forked from canonical/k8s-snap
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Strict interfaces test (canonical#748)
- Loading branch information
1 parent
e6aee64
commit 6caed50
Showing
6 changed files
with
146 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# | ||
# Copyright 2024 Canonical, Ltd. | ||
# | ||
import logging | ||
from typing import List | ||
|
||
import pytest | ||
from test_util import config, harness, snap, util | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
|
||
@pytest.mark.node_count(1) | ||
@pytest.mark.no_setup() | ||
@pytest.mark.skipif( | ||
not config.STRICT_INTERFACE_CHANNELS, reason="No strict channels configured" | ||
) | ||
def test_strict_interfaces(instances: List[harness.Instance], tmp_path): | ||
channels = config.STRICT_INTERFACE_CHANNELS | ||
cp = instances[0] | ||
current_channel = channels[0] | ||
|
||
if current_channel.lower() == "recent": | ||
if len(channels) != 3: | ||
pytest.fail( | ||
"'recent' requires the number of releases as second argument and the flavour as third argument" | ||
) | ||
_, num_channels, flavour = channels | ||
channels = snap.get_channels(int(num_channels), flavour, cp.arch, "edge", True) | ||
|
||
for channel in channels: | ||
util.setup_k8s_snap(cp, tmp_path, channel, connect_interfaces=False) | ||
|
||
# Log the current snap version on the node. | ||
out = cp.exec(["snap", "list", config.SNAP_NAME], capture_output=True) | ||
LOG.info(f"Current snap version: {out.stdout.decode().strip()}") | ||
|
||
check_snap_interfaces(cp, config.SNAP_NAME) | ||
|
||
cp.exec(["snap", "remove", config.SNAP_NAME, "--purge"]) | ||
|
||
|
||
def check_snap_interfaces(cp, snap_name): | ||
"""Check the strict snap interfaces.""" | ||
interfaces = [ | ||
"docker-privileged", | ||
"kubernetes-support", | ||
"network", | ||
"network-bind", | ||
"network-control", | ||
"network-observe", | ||
"firewall-control", | ||
"process-control", | ||
"kernel-module-observe", | ||
"cilium-module-load", | ||
"mount-observe", | ||
"hardware-observe", | ||
"system-observe", | ||
"home", | ||
"opengl", | ||
"home-read-all", | ||
"login-session-observe", | ||
"log-observe", | ||
] | ||
for interface in interfaces: | ||
cp.exec( | ||
[ | ||
"snap", | ||
"run", | ||
"--shell", | ||
snap_name, | ||
"-c", | ||
f"snapctl is-connected {interface}", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters