Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions test/case/infix_containers/container_basic/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
The RPC actions: stop + start, and restart are also verified.
"""
import infamy
from infamy.util import until
from infamy.util import until, curl


def _verify(server):
# TODO: Should really use mDNS here....
url = infamy.Furl(f"http://[{server}]:91/index.html")
return url.check("It works")
url = f"http://[{server}]:91/index.html"
response = curl(url)
return response is not None and "It works" in response


with infamy.Test() as test:
Expand Down
5 changes: 2 additions & 3 deletions test/case/infix_containers/container_bridge/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"""
import base64
import infamy
from infamy.util import until, to_binary
from infamy.util import until, to_binary, curl

with infamy.Test() as test:
NAME = "web-docker0"
Expand Down Expand Up @@ -81,7 +81,6 @@
until(lambda: c.running(NAME), attempts=60)

_, hport = env.ltop.xlate("host", "data")
url = infamy.Furl(URL)

with infamy.IsolatedMacVlan(hport) as ns:
ns.addip(OURIP)
Expand All @@ -90,6 +89,6 @@
ns.must_reach(DUTIP)

with test.step("Verify container is reachable on http://10.0.0.2:8080"):
until(lambda: url.nscheck(ns, MESG), attempts=10)
until(lambda: MESG in ns.call(lambda: curl(URL)), attempts=10)

test.succeed()
6 changes: 3 additions & 3 deletions test/case/infix_containers/container_environment/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
3. Verify served content against environment variables
"""
import infamy
from infamy.util import until, to_binary
from infamy.util import until, to_binary, curl


with infamy.Test() as test:
Expand All @@ -23,7 +23,7 @@
NAME = "web-env"
DUTIP = "10.0.0.2"
OURIP = "10.0.0.1"
url = infamy.Furl(f"http://{DUTIP}:8080/cgi-bin/env.cgi")
URL =f"http://{DUTIP}:8080/cgi-bin/env.cgi"

with test.step("Set up topology and attach to target DUT"):
env = infamy.Env()
Expand Down Expand Up @@ -103,6 +103,6 @@
for var in ENV_VARS:
expected_strings.append(f'{var["key"]}={var["value"]}')

until(lambda: url.nscheck(ns, expected_strings))
until(lambda: all(string in ns.call(lambda: curl(URL)) for string in expected_strings))

test.succeed()
11 changes: 5 additions & 6 deletions test/case/infix_containers/container_firewall_basic/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
only reachable from the public interface `ext0`, on 192.168.0.1:8080.
"""
import infamy
from infamy.util import until, to_binary
from infamy.util import until, to_binary, curl


with infamy.Test() as test:
Expand Down Expand Up @@ -181,15 +181,14 @@
until(lambda: c.running(WEBNM), attempts=60)

with infamy.IsolatedMacVlan(hport) as ns:
NEEDLE = "tiny web server from the curiOS docker"
MESG = "tiny web server from the curiOS docker"
ns.addip(OURIP)
with test.step("Verify connectivity, host can reach target:ext0"):
ns.must_reach(EXTIP)
with test.step("Verify 'web' is NOT reachable on http://container-host.local:91"):
url = infamy.Furl(BAD_URL)
until(lambda: not url.nscheck(ns, NEEDLE))
until(lambda: not ns.call(lambda: curl(BAD_URL)))
with test.step("Verify 'web' is reachable on http://container-host.local:8080"):
url = infamy.Furl(GOOD_URL)
until(lambda: url.nscheck(ns, NEEDLE))
until(lambda: MESG in ns.call(lambda: curl(GOOD_URL)))


test.succeed()
12 changes: 6 additions & 6 deletions test/case/infix_containers/container_phys/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
given a physical interface instead of an end of a VETH pair.
"""
import infamy
from infamy.util import until, to_binary
from infamy.util import until, to_binary, curl

with infamy.Test() as test:
NAME = "web-phys"
DUTIP = "10.0.0.2"
OURIP = "10.0.0.1"
MESG = "Kilroy was here"
BODY = f"<html><body><p>{MESG}</p></body></html>"
MESG1 = "It works"
MESG2 = "Kilroy was here"
BODY = f"<html><body><p>{MESG2}</p></body></html>"
URL = f"http://{DUTIP}:91/index.html"

with test.step("Set up topology and attach to target DUT"):
Expand Down Expand Up @@ -60,15 +61,14 @@
until(lambda: c.running(NAME), attempts=60)

_, hport = env.ltop.xlate("host", "data")
url = infamy.Furl(URL)

with infamy.IsolatedMacVlan(hport) as ns:
ns.addip(OURIP)
with test.step("Verify host:data can ping 10.0.0.2"):
ns.must_reach(DUTIP)

with test.step("Verify container is reachable on http://10.0.0.2:91"):
until(lambda: url.nscheck(ns, "It works"), attempts=10)
until(lambda: MESG1 in ns.call(lambda: curl(URL)), attempts=10)

with test.step("Add a content mount, overriding index.html"):
# Verify modifying a running container takes, issue #930
Expand All @@ -88,6 +88,6 @@
})

with test.step("Verify server is restarted and returns new content"):
until(lambda: url.nscheck(ns, MESG), attempts=60)
until(lambda: MESG2 in ns.call(lambda: curl(URL)), attempts=60)

test.succeed()
6 changes: 3 additions & 3 deletions test/case/infix_containers/container_veth/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@
"""
import base64
import infamy
from infamy.util import until
from infamy.util import until, curl

with infamy.Test() as test:
NAME = "web-br0-veth"
DUTIP = "10.0.0.2"
OURIP = "10.0.0.1"
URL = f"http://{DUTIP}:91/index.html"
MESG = "It works"

with test.step("Set up topology and attach to target DUT"):
env = infamy.Env()
Expand Down Expand Up @@ -97,13 +98,12 @@
until(lambda: c.running(NAME), attempts=60)

_, hport = env.ltop.xlate("host", "data")
url = infamy.Furl(URL)

with infamy.IsolatedMacVlan(hport) as ns:
ns.addip(OURIP)
with test.step("Verify basic DUT connectivity, host:data can ping DUT 10.0.0.2"):
ns.must_reach(DUTIP)
with test.step("Verify container 'web-br0-veth' is reachable on http://10.0.0.2:91"):
until(lambda: url.nscheck(ns, "It works"), attempts=10)
until(lambda: MESG in ns.call(lambda: curl(URL)), attempts=10)

test.succeed()
8 changes: 4 additions & 4 deletions test/case/infix_containers/container_volume/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

"""
import infamy
from infamy.util import until
from infamy.util import until, curl

with infamy.Test() as test:
NAME = "web-volume"
Expand All @@ -19,7 +19,7 @@
target = env.attach("target", "mgmt")
tgtssh = env.attach("target", "mgmt", "ssh")
addr = target.get_mgmt_ip()
url = infamy.Furl(f"http://[{addr}]:{PORT}/index.html")
URL = f"http://[{addr}]:{PORT}/index.html"

if not target.has_model("infix-containers"):
test.skip()
Expand Down Expand Up @@ -53,7 +53,7 @@
tgtssh.runsh(cmd)

with test.step("Verify container volume content"):
until(lambda: url.check(MESG), attempts=10)
until(lambda: MESG in curl(URL), attempts=10)

with test.step("Upgrade container"):
out = tgtssh.runsh(f"sudo container upgrade {NAME}")
Expand All @@ -66,6 +66,6 @@
# print(f"Container {NAME} upgraded: {out.stdout}")

with test.step("Verify container volume content survived upgrade"):
until(lambda: url.check(MESG), attempts=60)
until(lambda: MESG in curl(URL), attempts=60)

test.succeed()
14 changes: 7 additions & 7 deletions test/case/use_case/ospf_container/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
import infamy
import infamy.util as util
import infamy.route as route
from infamy.furl import Furl

BODY = "<html><body><p>Router responding</p></body></html>"

Expand Down Expand Up @@ -647,12 +646,13 @@ def config_abr(target, data, link1, link2, link3):
ns.addroute("0.0.0.0/0", "192.168.100.1")
# breakpoint()
with test.step("Verify ABR:data can access container A on R1 (10.1.1.101)"):
furl = Furl("http://10.1.1.101:8080")
util.until(lambda: furl.nscheck(ns, BODY))
URL = "http://10.1.1.101:8080"
util.until(lambda: BODY in ns.call(lambda: util.curl(URL)))
with test.step("Verify ABR:data can access container A on R2 (10.1.2.101)"):
furl = Furl("http://10.1.2.101:8080")
util.until(lambda: furl.nscheck(ns, BODY))
URL = "http://10.1.2.101:8080"
util.until(lambda: BODY in ns.call(lambda: util.curl(URL)))
with test.step("Verify ABR:data can access container A on R3 (10.1.3.101)"):
furl = Furl("http://10.1.3.101:8080")
util.until(lambda: furl.nscheck(ns, BODY))
URL = "http://10.1.3.101:8080"
util.until(lambda: BODY in ns.call(lambda: util.curl(URL)))

test.succeed()
1 change: 0 additions & 1 deletion test/infamy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from .env import ArgumentParser
from .env import test_argument
from .firewall import Firewall
from .furl import Furl
from .netns import IsolatedMacVlan,IsolatedMacVlans
from .portscanner import PortScanner
from .sniffer import Sniffer
Expand Down
72 changes: 0 additions & 72 deletions test/infamy/furl.py

This file was deleted.

20 changes: 20 additions & 0 deletions test/infamy/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import infamy.neigh
from infamy import netconf
from infamy import restconf
import urllib.request


class ParallelFn(threading.Thread):
Expand Down Expand Up @@ -97,3 +98,22 @@ def warn(msg):
YELLOW = "\033[93m"
RST = "\033[0m"
print(f"{YELLOW}warn - {msg}{RST}")

def curl(url, timeout=10):
"""Fetch a URL and return its response body as a UTF-8 string.

Args:
url (str): The full URL to fetch.
timeout (int): Request timeout in seconds.

Returns:
str | None: Response body as text, or None if the request failed.
"""
url = urllib.parse.quote(url, safe='/:')

try:
with urllib.request.urlopen(url, timeout=timeout) as response:
return response.read().decode('utf-8', errors='replace')
except (urllib.error.URLError, ConnectionResetError, UnicodeEncodeError) as e:
print(f"[WARN] curl: failed to fetch {url}: {e}")
return ""