Skip to content

Commit 3d66754

Browse files
authored
Merge pull request #281 from netsys-lab/ci-tests-pr
CI: Restore MiniInternetTestCase
2 parents 0d949dc + 058e545 commit 3d66754

File tree

3 files changed

+45
-22
lines changed

3 files changed

+45
-22
lines changed

tests/SeedEmuTestCase.py

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ class SeedEmuTestCase(ut.TestCase):
1919
container_count_after_up_container: int
2020
docker_compose_version:int
2121
online_testing:bool
22-
22+
2323
@classmethod
2424
def setUpClass(cls, testLogOverwrite:bool=False, online:bool=True) -> None:
2525
'''!
26-
@brief A classmethod to construct the some thing before
27-
this test case is started. For this test case, it will create
28-
a test_log directory, create emulation files, build containers
26+
@brief A classmethod to construct the some thing before
27+
this test case is started. For this test case, it will create
28+
a test_log directory, create emulation files, build containers
2929
and up containers.
30-
30+
3131
Parameters
3232
----------
3333
testLogOverwrite : bool, optional
@@ -71,7 +71,7 @@ def setUpClass(cls, testLogOverwrite:bool=False, online:bool=True) -> None:
7171
cls.up_emulator()
7272

7373
return
74-
74+
7575
@classmethod
7676
def tearDownClass(cls) -> None:
7777
'''
@@ -82,16 +82,16 @@ def tearDownClass(cls) -> None:
8282
cls.down_emulator()
8383

8484
return super().tearDownClass()
85-
85+
8686
@classmethod
8787
def gen_emulation_files(cls):
8888
"""!
8989
@brief generate emulation files.
9090
"""
9191
cls.printLog("Generating Emulation Files...")
92-
92+
9393
os.chdir(cls.emulator_code_dir)
94-
94+
9595
log_file = os.path.join(cls.init_dir, cls.test_log, "compile_log")
9696
f = open(log_file, 'w')
9797
if os.path.exists(cls.output_dir):
@@ -119,7 +119,7 @@ def build_emulator(cls):
119119
"""
120120
cls.printLog("Building Docker Containers...")
121121
os.chdir(os.path.join(cls.emulator_code_dir, cls.output_dir))
122-
122+
123123
log_file = os.path.join(cls.init_dir, cls.test_log, "build_log")
124124
f = open(log_file, 'w')
125125
if(cls.docker_compose_version == 1):
@@ -186,15 +186,15 @@ def createDirectory(cls, directory:str, override:bool = False):
186186
@classmethod
187187
def wait_until_all_containers_up(cls, total_containers:int) -> None:
188188
"""!
189-
@brief wait until all containers up before running a testcase.
189+
@brief wait until all containers up before running a testcase.
190190
191-
@param total_containers a expected total container counts
191+
@param total_containers a expected total container counts
192192
"""
193193
current_time = time.time()
194194
while True:
195195
cls.printLog("--------------------------------------------------")
196196
cls.printLog("------ Waiting until all containers up : {} ------".format(total_containers))
197-
197+
198198
cls.containers = cls.client.containers.list()
199199

200200
cur_container_count = len(cls.containers) - cls.container_count_before_up_container
@@ -209,7 +209,7 @@ def wait_until_all_containers_up(cls, total_containers:int) -> None:
209209
return False
210210
time.sleep(10)
211211

212-
@classmethod
212+
@classmethod
213213
def ping_test(cls, container, ip, expected_exit_code=0):
214214
"""!
215215
@brief test ping 3 times
@@ -225,7 +225,29 @@ def ping_test(cls, container, ip, expected_exit_code=0):
225225
if exit_code == 0: cls.printLog("ping test {} Succeed".format(ip))
226226
else: cls.printLog("ping test {} Failed".format(ip))
227227
return exit_code == expected_exit_code
228-
228+
229+
@classmethod
230+
def http_get_test(cls, container, dst, expected_status_code:int = 200) -> bool:
231+
"""!
232+
@brief Send an HTTP GET request with curl.
233+
234+
@param container Container to send the request
235+
@param dst Request destination
236+
237+
@returns True if the HTTP status code of the response is `expected_status_code`.
238+
"""
239+
ec, output = container.exec_run(f"curl -so /dev/null -w '%{{http_code}}' {dst}")
240+
if ec != 0:
241+
cls.printLog(f"http GET {dst} test failed: {output.decode()}")
242+
return False
243+
http_status = int(output.decode())
244+
if http_status != expected_status_code:
245+
cls.printLog(f"http GET test {dst} failed with HTTP status {http_status}"
246+
f", expected {expected_status_code}")
247+
return False
248+
cls.printLog(f"http GET {dst} test succeeded")
249+
return True
250+
229251
@classmethod
230252
def get_test_suite(cls):
231253
"""!
@@ -244,7 +266,7 @@ def get_test_suite(cls):
244266
'''
245267

246268
raise NotImplementedError('getTestSuite not implemented')
247-
269+
248270
@classmethod
249271
def printLog(cls, *args, **kwargs):
250272
"""!

tests/internet/mini_internet/MiniInternetTestCase.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from tests import SeedEmuTestCase
66

77
class MiniInternetTestCase(SeedEmuTestCase):
8-
8+
99
@classmethod
1010
def setUpClass(cls) -> None:
1111
super().setUpClass()
@@ -14,8 +14,8 @@ def setUpClass(cls) -> None:
1414
if "10.150.0.71" in container.name:
1515
cls.source_host = container
1616
break
17-
return
18-
17+
return
18+
1919
def test_internet_connection(self):
2020
asns = [151, 152, 153, 154, 160, 161, 162, 163, 164, 170, 171]
2121
for asn in asns:
@@ -34,11 +34,10 @@ def test_real_world_as(self):
3434
self.printLog("real world as 11872")
3535
self.printLog("check real world ip : 128.230.18.63")
3636
# 128.230.18.63 - ip of syr.edu
37-
self.assertTrue(self.ping_test(self.source_host, "128.230.18.63"))
37+
self.assertTrue(self.http_get_test(self.source_host, "128.230.18.63", 301))
3838

3939
def test_vpn(self):
4040
return
41-
4241

4342
@classmethod
4443
def get_test_suite(cls):
@@ -55,4 +54,3 @@ def get_test_suite(cls):
5554
MiniInternetTestCase.printLog("==========Test=========")
5655
num, errs, fails = res.testsRun, len(res.errors), len(res.failures)
5756
MiniInternetTestCase.printLog("score: %d of %d (%d errors, %d failures)" % (num - (errs+fails), num, errs, fails))
58-

tests/run-tests.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141

4242
if args.ci:
4343
test_case_list = [
44+
MiniInternetTestCase,
45+
IPAnyCastTestCase,
46+
HostMgmtTestCase,
4447
ScionBgpMixedTestCase,
4548
ScionBwtesterTestCase,
4649
DottedDictTestCase,

0 commit comments

Comments
 (0)