Skip to content

Commit

Permalink
test: new util method to_binary()
Browse files Browse the repository at this point in the history
Signed-off-by: Joachim Wiberg <[email protected]>
  • Loading branch information
troglobit committed Oct 23, 2024
1 parent 64c20d9 commit 14fde1b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
6 changes: 3 additions & 3 deletions test/case/infix_containers/container_bridge/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"""
import base64
import infamy
from infamy.util import until
from infamy.util import until, to_binary

with infamy.Test() as test:
NAME = "web-docker0"
Expand All @@ -34,7 +34,7 @@

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": [
Expand Down Expand Up @@ -71,7 +71,7 @@
"mount": [
{
"name": "index.html",
"content": f"{enc.decode('utf-8')}",
"content": f"{data}",
"target": "/var/www/index.html"
}
],
Expand Down
14 changes: 12 additions & 2 deletions test/infamy/util.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 14fde1b

Please sign in to comment.