diff --git a/test/case/infix_containers/Readme.adoc b/test/case/infix_containers/Readme.adoc index a530a6e6..89cb0ef9 100644 --- a/test/case/infix_containers/Readme.adoc +++ b/test/case/infix_containers/Readme.adoc @@ -14,6 +14,8 @@ Verifies Infix Docker container support: include::container_basic/Readme.adoc[] +include::container_enabled/Readme.adoc[] + include::container_bridge/Readme.adoc[] include::container_phys/Readme.adoc[] diff --git a/test/case/infix_containers/container_enabled/Readme.adoc b/test/case/infix_containers/container_enabled/Readme.adoc new file mode 120000 index 00000000..867ff7a3 --- /dev/null +++ b/test/case/infix_containers/container_enabled/Readme.adoc @@ -0,0 +1 @@ +container_enabled.adoc \ No newline at end of file diff --git a/test/case/infix_containers/container_enabled/container_enabled.adoc b/test/case/infix_containers/container_enabled/container_enabled.adoc new file mode 100644 index 00000000..69b698fa --- /dev/null +++ b/test/case/infix_containers/container_enabled/container_enabled.adoc @@ -0,0 +1,37 @@ +=== Container enabled/disabled +==== Description +Verify that a container can be enabled and disabled via configuration. +Tests the 'enabled' leaf functionality by: + +1. Creating an enabled container and verifying it starts +2. Disabling the container and verifying it stops +3. Re-enabling the container and verifying it starts again + +Uses operational datastore to verify container running status. + +==== Topology +ifdef::topdoc[] +image::{topdoc}../../test/case/infix_containers/container_enabled/topology.svg[Container enabled/disabled topology] +endif::topdoc[] +ifndef::topdoc[] +ifdef::testgroup[] +image::container_enabled/topology.svg[Container enabled/disabled topology] +endif::testgroup[] +ifndef::testgroup[] +image::topology.svg[Container enabled/disabled topology] +endif::testgroup[] +endif::topdoc[] +==== Test sequence +. Set up topology and attach to target DUT +. Set hostname to 'container-host' +. Create enabled container from bundled OCI image +. Verify container has started +. Let container settle +. Disable container +. Verify container has stopped +. Re-enable container +. Verify container has started again + + +<<< + diff --git a/test/case/infix_containers/container_enabled/test.py b/test/case/infix_containers/container_enabled/test.py new file mode 100755 index 00000000..0832e97a --- /dev/null +++ b/test/case/infix_containers/container_enabled/test.py @@ -0,0 +1,82 @@ +#!/usr/bin/env python3 +""" +Container enabled/disabled + +Verify that a container can be enabled and disabled via configuration. +Tests the 'enabled' leaf functionality by: + +1. Creating an enabled container and verifying it starts +2. Disabling the container and verifying it stops +3. Re-enabling the container and verifying it starts again + +Uses operational datastore to verify container running status. +""" +import infamy +from infamy.util import until + + +def set_container_enabled(target, name, enabled): + """Helper function to set container enabled state and verify the change""" + target.put_config_dict("infix-containers", { + "containers": { + "container": [ + { + "name": name, + "enabled": enabled + } + ] + } + }) + + +with infamy.Test() as test: + NAME = "web-enabled" + + with test.step("Set up topology and attach to target DUT"): + env = infamy.Env() + target = env.attach("target", "mgmt") + + if not target.has_model("infix-containers"): + test.skip() + + with test.step("Set hostname to 'container-host'"): + target.put_config_dict("ietf-system", { + "system": { + "hostname": "container-host" + } + }) + + with test.step("Create enabled container from bundled OCI image"): + target.put_config_dict("infix-containers", { + "containers": { + "container": [ + { + "name": f"{NAME}", + "enabled": True, + "image": f"oci-archive:{infamy.Container.HTTPD_IMAGE}", + "command": "/usr/sbin/httpd -f -v -p 91", + "network": { + "host": True + } + } + ] + } + }) + + with test.step("Verify container has started"): + c = infamy.Container(target) + until(lambda: c.running(NAME), attempts=60) + + with test.step("Disable container"): + set_container_enabled(target, NAME, False) + + with test.step("Verify container has stopped"): + until(lambda: not c.running(NAME), attempts=60) + + with test.step("Re-enable container"): + set_container_enabled(target, NAME, True) + + with test.step("Verify container has started again"): + until(lambda: c.running(NAME), attempts=60) + + test.succeed() diff --git a/test/case/infix_containers/container_enabled/topology.dot b/test/case/infix_containers/container_enabled/topology.dot new file mode 100644 index 00000000..e6a0d803 --- /dev/null +++ b/test/case/infix_containers/container_enabled/topology.dot @@ -0,0 +1,23 @@ +graph "1x1" { + layout="neato"; + overlap="false"; + esep="+80"; + + node [shape=record, fontname="DejaVu Sans Mono, Book"]; + edge [color="cornflowerblue", penwidth="2", fontname="DejaVu Serif, Book"]; + + host [ + label="host | { mgmt }", + pos="0,12!", + requires="controller", + ]; + + target [ + label="{ mgmt } | target", + pos="10,12!", + + requires="infix", + ]; + + host:mgmt -- target:mgmt [requires="mgmt", color="lightgray"] +} diff --git a/test/case/infix_containers/container_enabled/topology.svg b/test/case/infix_containers/container_enabled/topology.svg new file mode 100644 index 00000000..6fc6f47a --- /dev/null +++ b/test/case/infix_containers/container_enabled/topology.svg @@ -0,0 +1,33 @@ + + + + + + +1x1 + + + +host + +host + +mgmt + + + +target + +mgmt + +target + + + +host:mgmt--target:mgmt + + + + diff --git a/test/case/infix_containers/infix_containers.yaml b/test/case/infix_containers/infix_containers.yaml index 484663e8..255799b9 100644 --- a/test/case/infix_containers/infix_containers.yaml +++ b/test/case/infix_containers/infix_containers.yaml @@ -3,6 +3,9 @@ - name: container_basic case: container_basic/test.py +- name: container_enabled + case: container_enabled/test.py + - name: container_bridge case: container_bridge/test.py @@ -20,4 +23,3 @@ - name: container_host_commands case: container_host_commands/test.py -