Skip to content

Commit 966fb48

Browse files
authored
Merge pull request #1196 from saba8814/furl-refactoring
refactor Furl() as a plain function
2 parents 26c005f + 51d5ae4 commit 966fb48

File tree

11 files changed

+54
-108
lines changed

11 files changed

+54
-108
lines changed

test/case/infix_containers/basic/test.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
The RPC actions: stop + start, and restart are also verified.
99
"""
1010
import infamy
11-
from infamy.util import until
11+
from infamy.util import until, curl
1212

1313

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

1920

2021
with infamy.Test() as test:

test/case/infix_containers/bridge/test.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"""
1212
import base64
1313
import infamy
14-
from infamy.util import until, to_binary
14+
from infamy.util import until, to_binary, curl
1515

1616
with infamy.Test() as test:
1717
NAME = "web-docker0"
@@ -81,7 +81,6 @@
8181
until(lambda: c.running(NAME), attempts=60)
8282

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

8685
with infamy.IsolatedMacVlan(hport) as ns:
8786
ns.addip(OURIP)
@@ -90,6 +89,6 @@
9089
ns.must_reach(DUTIP)
9190

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

9594
test.succeed()

test/case/infix_containers/environment/test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
3. Verify served content against environment variables
1111
"""
1212
import infamy
13-
from infamy.util import until, to_binary
13+
from infamy.util import until, to_binary, curl
1414

1515

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

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

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

108108
test.succeed()

test/case/infix_containers/firewall_basic/test.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
only reachable from the public interface `ext0`, on 192.168.0.1:8080.
2727
"""
2828
import infamy
29-
from infamy.util import until, to_binary
29+
from infamy.util import until, to_binary, curl
3030

3131

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

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

195194
test.succeed()

test/case/infix_containers/phys/test.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
given a physical interface instead of an end of a VETH pair.
77
"""
88
import infamy
9-
from infamy.util import until, to_binary
9+
from infamy.util import until, to_binary, curl
1010

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

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

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

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

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

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

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

9393
test.succeed()

test/case/infix_containers/veth/test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@
1818
"""
1919
import base64
2020
import infamy
21-
from infamy.util import until
21+
from infamy.util import until, curl
2222

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

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

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

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

109109
test.succeed()

test/case/infix_containers/volume/test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
88
"""
99
import infamy
10-
from infamy.util import until
10+
from infamy.util import until, curl
1111

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

2424
if not target.has_model("infix-containers"):
2525
test.skip()
@@ -53,7 +53,7 @@
5353
tgtssh.runsh(cmd)
5454

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

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

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

7171
test.succeed()

test/case/use_case/ospf_container/test.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
import infamy
5959
import infamy.util as util
6060
import infamy.route as route
61-
from infamy.furl import Furl
6261

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

@@ -647,12 +646,13 @@ def config_abr(target, data, link1, link2, link3):
647646
ns.addroute("0.0.0.0/0", "192.168.100.1")
648647
# breakpoint()
649648
with test.step("Verify ABR:data can access container A on R1 (10.1.1.101)"):
650-
furl = Furl("http://10.1.1.101:8080")
651-
util.until(lambda: furl.nscheck(ns, BODY))
649+
URL = "http://10.1.1.101:8080"
650+
util.until(lambda: BODY in ns.call(lambda: util.curl(URL)))
652651
with test.step("Verify ABR:data can access container A on R2 (10.1.2.101)"):
653-
furl = Furl("http://10.1.2.101:8080")
654-
util.until(lambda: furl.nscheck(ns, BODY))
652+
URL = "http://10.1.2.101:8080"
653+
util.until(lambda: BODY in ns.call(lambda: util.curl(URL)))
655654
with test.step("Verify ABR:data can access container A on R3 (10.1.3.101)"):
656-
furl = Furl("http://10.1.3.101:8080")
657-
util.until(lambda: furl.nscheck(ns, BODY))
655+
URL = "http://10.1.3.101:8080"
656+
util.until(lambda: BODY in ns.call(lambda: util.curl(URL)))
657+
658658
test.succeed()

test/infamy/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from .env import ArgumentParser
66
from .env import test_argument
77
from .firewall import Firewall
8-
from .furl import Furl
98
from .netns import IsolatedMacVlan,IsolatedMacVlans
109
from .portscanner import PortScanner
1110
from .sniffer import Sniffer

test/infamy/furl.py

Lines changed: 0 additions & 72 deletions
This file was deleted.

0 commit comments

Comments
 (0)