Skip to content

CI: Restore MiniInternetTestCase #281

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 13, 2025
Merged
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
54 changes: 38 additions & 16 deletions tests/SeedEmuTestCase.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ class SeedEmuTestCase(ut.TestCase):
container_count_after_up_container: int
docker_compose_version:int
online_testing:bool

@classmethod
def setUpClass(cls, testLogOverwrite:bool=False, online:bool=True) -> None:
'''!
@brief A classmethod to construct the some thing before
this test case is started. For this test case, it will create
a test_log directory, create emulation files, build containers
@brief A classmethod to construct the some thing before
this test case is started. For this test case, it will create
a test_log directory, create emulation files, build containers
and up containers.

Parameters
----------
testLogOverwrite : bool, optional
Expand Down Expand Up @@ -70,7 +70,7 @@ def setUpClass(cls, testLogOverwrite:bool=False, online:bool=True) -> None:
cls.up_emulator()

return

@classmethod
def tearDownClass(cls) -> None:
'''
Expand All @@ -81,16 +81,16 @@ def tearDownClass(cls) -> None:
cls.down_emulator()

return super().tearDownClass()

@classmethod
def gen_emulation_files(cls):
"""!
@brief generate emulation files.
"""
cls.printLog("Generating Emulation Files...")

os.chdir(cls.emulator_code_dir)

log_file = os.path.join(cls.init_dir, cls.test_log, "compile_log")
f = open(log_file, 'w')
if os.path.exists(cls.output_dir):
Expand All @@ -109,7 +109,7 @@ def build_emulator(cls):
"""
cls.printLog("Building Docker Containers...")
os.chdir(os.path.join(cls.emulator_code_dir, cls.output_dir))

log_file = os.path.join(cls.init_dir, cls.test_log, "build_log")
f = open(log_file, 'w')
if(cls.docker_compose_version == 1):
Expand Down Expand Up @@ -176,15 +176,15 @@ def createDirectory(cls, directory:str, override:bool = False):
@classmethod
def wait_until_all_containers_up(cls, total_containers:int) -> None:
"""!
@brief wait until all containers up before running a testcase.
@brief wait until all containers up before running a testcase.

@param total_containers a expected total container counts
@param total_containers a expected total container counts
"""
current_time = time.time()
while True:
cls.printLog("--------------------------------------------------")
cls.printLog("------ Waiting until all containers up : {} ------".format(total_containers))

cls.containers = cls.client.containers.list()

cur_container_count = len(cls.containers) - cls.container_count_before_up_container
Expand All @@ -199,7 +199,7 @@ def wait_until_all_containers_up(cls, total_containers:int) -> None:
return False
time.sleep(10)

@classmethod
@classmethod
def ping_test(cls, container, ip, expected_exit_code=0):
"""!
@brief test ping 3 times
Expand All @@ -215,7 +215,29 @@ def ping_test(cls, container, ip, expected_exit_code=0):
if exit_code == 0: cls.printLog("ping test {} Succeed".format(ip))
else: cls.printLog("ping test {} Failed".format(ip))
return exit_code == expected_exit_code


@classmethod
def http_get_test(cls, container, dst, expected_status_code:int = 200) -> bool:
"""!
@brief Send an HTTP GET request with curl.

@param container Container to send the request
@param dst Request destination

@returns True if the HTTP status code of the response is `expected_status_code`.
"""
ec, output = container.exec_run(f"curl -so /dev/null -w '%{{http_code}}' {dst}")
if ec != 0:
cls.printLog(f"http GET {dst} test failed: {output.decode()}")
return False
http_status = int(output.decode())
if http_status != expected_status_code:
cls.printLog(f"http GET test {dst} failed with HTTP status {http_status}"
f", expected {expected_status_code}")
return False
cls.printLog(f"http GET {dst} test succeeded")
return True

@classmethod
def get_test_suite(cls):
"""!
Expand All @@ -234,7 +256,7 @@ def get_test_suite(cls):
'''

raise NotImplementedError('getTestSuite not implemented')

@classmethod
def printLog(cls, *args, **kwargs):
"""!
Expand Down
10 changes: 4 additions & 6 deletions tests/internet/mini_internet/MiniInternetTestCase.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from tests import SeedEmuTestCase

class MiniInternetTestCase(SeedEmuTestCase):

@classmethod
def setUpClass(cls) -> None:
super().setUpClass()
Expand All @@ -14,8 +14,8 @@ def setUpClass(cls) -> None:
if "10.150.0.71" in container.name:
cls.source_host = container
break
return
return

def test_internet_connection(self):
asns = [151, 152, 153, 154, 160, 161, 162, 163, 164, 170, 171]
for asn in asns:
Expand All @@ -34,11 +34,10 @@ def test_real_world_as(self):
self.printLog("real world as 11872")
self.printLog("check real world ip : 128.230.18.63")
# 128.230.18.63 - ip of syr.edu
self.assertTrue(self.ping_test(self.source_host, "128.230.18.63"))
self.assertTrue(self.http_get_test(self.source_host, "128.230.18.63", 301))

def test_vpn(self):
return


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

3 changes: 3 additions & 0 deletions tests/run-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@

if args.ci:
test_case_list = [
MiniInternetTestCase,
IPAnyCastTestCase,
HostMgmtTestCase,
ScionBgpMixedTestCase,
ScionBwtesterTestCase,
DottedDictTestCase,
Expand Down
Loading