test: new util method to_binary()

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2024-10-23 10:08:10 +02:00
parent 64c20d96ad
commit 14fde1bf90
2 changed files with 15 additions and 5 deletions
@@ -16,7 +16,7 @@ port accessed from the host.
"""
import base64
import infamy
from infamy.util import until
from infamy.util import until, to_binary
with infamy.Test() as test:
NAME = "web-docker0"
@@ -34,7 +34,7 @@ with infamy.Test() as test:
with test.step("Create container 'web-docker0' from bundled OCI image"):
_, ifname = env.ltop.xlate("target", "data")
enc = base64.b64encode(BODY.encode('utf-8'))
data = to_binary(BODY)
target.put_config_dict("ietf-interfaces", {
"interfaces": {
"interface": [
@@ -71,7 +71,7 @@ with infamy.Test() as test:
"mount": [
{
"name": "index.html",
"content": f"{enc.decode('utf-8')}",
"content": f"{data}",
"target": "/var/www/index.html"
}
],
+12 -2
View File
@@ -1,8 +1,10 @@
"""Helper functions for tests"""
import base64
import time
import threading
import infamy.neigh
import infamy.netconf as netconf
import infamy.restconf as restconf
from infamy import netconf
from infamy import restconf
class ParallelFn(threading.Thread):
@@ -59,6 +61,14 @@ def is_reachable(neigh, env, pwd):
return netconf_reachable and restconf_reachable
def to_binary(text):
"""Base64 encode the text, removing newlines"""
enc = base64.b64encode(text.encode('utf-8'))
# Convert the encoded bytes to a string and remove any newlines
return enc.decode('utf-8').replace('\n', '')
def wait_boot(target, env):
print(f"{target} is shutting down ...")
until(lambda: not target.reachable(), attempts=100)