mirror of
https://github.com/kernelkit/infix.git
synced 2026-08-06 23:43:20 +02:00
test: new util method to_binary()
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
@@ -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
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user