From 25fb9b5cd6fc6d303fcd36c56db5f20e12d9d75e Mon Sep 17 00:00:00 2001 From: Jacob Boddey Date: Fri, 4 Aug 2023 15:06:17 +0100 Subject: [PATCH 1/3] Re-enable actions, fix conn module --- framework/python/src/core/testrun.py | 3 + .../src/net_orc/network_orchestrator.py | 61 ++++++++++--------- framework/python/src/net_orc/ovs_control.py | 11 ++-- modules/test/conn/python/requirements.txt | 3 +- 4 files changed, 42 insertions(+), 36 deletions(-) diff --git a/framework/python/src/core/testrun.py b/framework/python/src/core/testrun.py index 6e3a6da5d..d3dbf2fb2 100644 --- a/framework/python/src/core/testrun.py +++ b/framework/python/src/core/testrun.py @@ -84,10 +84,13 @@ def __init__(self, # Create session self._session = TestRunSession(config_file=self._config_file) + # Register runtime parameters if single_intf: self._session.add_runtime_param('single_intf') if net_only: self._session.add_runtime_param('net_only') + if not validate: + self._session.add_runtime_param('no-validate') self._load_all_devices() diff --git a/framework/python/src/net_orc/network_orchestrator.py b/framework/python/src/net_orc/network_orchestrator.py index ebeeba2dd..7d8f878ea 100644 --- a/framework/python/src/net_orc/network_orchestrator.py +++ b/framework/python/src/net_orc/network_orchestrator.py @@ -48,15 +48,10 @@ class NetworkOrchestrator: """Manage and controls a virtual testing network.""" def __init__(self, - session, - validate=True, - single_intf=False): + session): self._session = session self._monitor_in_progress = False - self._validate = validate - self._single_intf = single_intf - self._listener = None self._net_modules = [] @@ -76,8 +71,6 @@ def start(self): LOGGER.debug('Starting network orchestrator') - self._host_user = util.get_host_user() - # Get all components ready self.load_network_modules() @@ -103,8 +96,8 @@ def check_config(self): return False else: if not device_interface_ready and not internet_interface_ready: - LOGGER.error('Both device and internet interfaces are not ready for use. ' + - 'Ensure both interfaces are connected.') + LOGGER.error('Both device and internet interfaces are not ' + + ' ready for use. Ensure both interfaces are connected.') return False elif not device_interface_ready: LOGGER.error('Device interface is not ready for use. ' + @@ -125,7 +118,7 @@ def start_network(self): self.create_net() self.start_network_services() - if self._validate: + if 'no-validate' not in self._session.get_runtime_params(): # Start the validator after network is ready self.validator.start() @@ -169,7 +162,8 @@ def _device_discovered(self, mac_addr): f'Discovered device {mac_addr}. Waiting for device to obtain IP') if device is None: - LOGGER.debug(f'Device with MAC address {mac_addr} does not exist in device repository') + LOGGER.debug(f'Device with MAC address {mac_addr} does ' + + 'not exist in device repository') # Ignore device if not registered return @@ -182,7 +176,7 @@ def _device_discovered(self, mac_addr): shutil.rmtree(device_runtime_dir, ignore_errors=True) os.makedirs(device_runtime_dir, exist_ok=True) - util.run_command(f'chown -R {self._host_user} {device_runtime_dir}') + util.run_command(f'chown -R {util.get_host_user()} {device_runtime_dir}') packet_capture = sniff(iface=self._session.get_device_interface(), timeout=self._session.get_startup_timeout(), @@ -228,13 +222,14 @@ def _start_device_monitor(self, device): callback the steady state method for this device.""" LOGGER.info(f'Monitoring device with mac addr {device.mac_addr} ' f'for {str(self._session.get_monitor_period())} seconds') - + device_runtime_dir = os.path.join(RUNTIME_DIR, TEST_DIR, device.mac_addr.replace(':', '') ) - packet_capture = sniff(iface=self._session.get_device_interface(), timeout=self._session.get_monitor_period()) + packet_capture = sniff(iface=self._session.get_device_interface(), + timeout=self._session.get_monitor_period()) wrpcap( os.path.join(device_runtime_dir, 'monitor.pcap' @@ -297,24 +292,32 @@ def _ci_pre_network_create(self): 'ip route | head -n 1 | awk \'{print $3}\'', shell=True).decode('utf-8').strip() self._ipv4 = subprocess.check_output( - f'ip a show {self._session.get_internet_interface()} | grep \"inet \" | awk \'{{print $2}}\'', + f'ip a show {self._session.get_internet_interface()} ' + + '| grep \"inet \" | awk \'{{print $2}}\'', shell=True).decode('utf-8').strip() self._ipv6 = subprocess.check_output( - f'ip a show {self._session.get_internet_interface()} | grep inet6 | awk \'{{print $2}}\'', + f'ip a show {self._session.get_internet_interface()} ' + + '| grep inet6 | awk \'{{print $2}}\'', shell=True).decode('utf-8').strip() self._brd = subprocess.check_output( - f'ip a show {self._session.get_internet_interface()} | grep \"inet \" | awk \'{{print $4}}\'', + f'ip a show {self._session.get_internet_interface()} ' + + '| grep \"inet \" | awk \'{{print $4}}\'', shell=True).decode('utf-8').strip() def _ci_post_network_create(self): """ Restore network connection in CI environment """ LOGGER.info('post cr') - util.run_command(f'ip address del {self._ipv4} dev {self._session.get_internet_interface()}') - util.run_command(f'ip -6 address del {self._ipv6} dev {self._session.get_internet_interface()}') + util.run_command(f'ip address del {self._ipv4} dev ' + + f'{self._session.get_internet_interface()}') + util.run_command(f'ip -6 address del {self._ipv6} dev ' + + f'{self._session.get_internet_interface()}') util.run_command( - f'ip link set dev {self._session.get_internet_interface()} address 00:B0:D0:63:C2:26') - util.run_command(f'ip addr flush dev {self._session.get_internet_interface()}') - util.run_command(f'ip addr add dev {self._session.get_internet_interface()} 0.0.0.0') + f'ip link set dev {self._session.get_internet_interface()}' + + ' address 00:B0:D0:63:C2:26') + util.run_command(f'ip addr flush dev ' + + f'{self._session.get_internet_interface()}') + util.run_command(f'ip addr add dev ' + + f'{self._session.get_internet_interface()} 0.0.0.0') util.run_command( f'ip addr add dev {INTERNET_BRIDGE} {self._ipv4} broadcast {self._brd}') util.run_command(f'ip -6 addr add {self._ipv6} dev {INTERNET_BRIDGE} ') @@ -329,9 +332,8 @@ def _ci_post_network_create(self): def create_net(self): LOGGER.info('Creating baseline network') - # TODO: This is not just for CI - #if self._single_intf: - #self._ci_pre_network_create() + if os.getenv('GITHUB_ACTIONS'): + self._ci_pre_network_create() # Setup the virtual network if not self._ovs.create_baseline_net(verify=True): @@ -339,9 +341,8 @@ def create_net(self): self.stop() sys.exit(1) - # TODO: This is not just for CI - #if self._single_intf: - #self._ci_post_network_create() + if os.getenv("GITHUB_ACTIONS"): + self._ci_post_network_create() self._create_private_net() @@ -474,7 +475,7 @@ def _start_network_service(self, net_module): privileged=True, detach=True, mounts=net_module.mounts, - environment={'HOST_USER': self._host_user}) + environment={'HOST_USER': util.get_host_user()}) except docker.errors.ContainerError as error: LOGGER.error('Container run error') LOGGER.error(error) diff --git a/framework/python/src/net_orc/ovs_control.py b/framework/python/src/net_orc/ovs_control.py index a2769632c..25dfc1cd5 100644 --- a/framework/python/src/net_orc/ovs_control.py +++ b/framework/python/src/net_orc/ovs_control.py @@ -13,8 +13,6 @@ # limitations under the License. """OVS Control Module""" -import json -import os from common import logger from common import util @@ -80,12 +78,14 @@ def validate_baseline_network(self): int_bridge = True # Verify the device bridge - dev_bridge = self.verify_bridge(DEVICE_BRIDGE, [self._session.get_device_interface()]) + dev_bridge = self.verify_bridge(DEVICE_BRIDGE, + [self._session.get_device_interface()]) LOGGER.debug('Device bridge verified: ' + str(dev_bridge)) # Verify the internet bridge if 'single_intf' not in self._session.get_runtime_params(): - int_bridge = self.verify_bridge(INTERNET_BRIDGE, [self._session.get_internet_interface()]) + int_bridge = self.verify_bridge(INTERNET_BRIDGE, + [self._session.get_internet_interface()]) LOGGER.debug('Internet bridge verified: ' + str(int_bridge)) return dev_bridge and int_bridge @@ -118,7 +118,8 @@ def create_baseline_net(self, verify=True): # Remove IP from internet adapter if not 'single_intf' in self._session.get_runtime_params(): - self.set_interface_ip(interface=self._session.get_internet_interface(), ip_addr='0.0.0.0') + self.set_interface_ip(interface=self._session.get_internet_interface(), + ip_addr='0.0.0.0') self.add_port(self._session.get_internet_interface(), INTERNET_BRIDGE) # Enable forwarding of eapol packets diff --git a/modules/test/conn/python/requirements.txt b/modules/test/conn/python/requirements.txt index 2b8d18750..c2275b3e0 100644 --- a/modules/test/conn/python/requirements.txt +++ b/modules/test/conn/python/requirements.txt @@ -1 +1,2 @@ -pyOpenSSL \ No newline at end of file +pyOpenSSL +scapy \ No newline at end of file From f6dc8176d4584fdfb0a522b50b8975dc0f81c65c Mon Sep 17 00:00:00 2001 From: Jacob Boddey Date: Fri, 11 Aug 2023 17:51:06 +0100 Subject: [PATCH 2/3] Fix net_orc init --- framework/python/src/core/testrun.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/framework/python/src/core/testrun.py b/framework/python/src/core/testrun.py index d3dbf2fb2..3a35be624 100644 --- a/framework/python/src/core/testrun.py +++ b/framework/python/src/core/testrun.py @@ -95,9 +95,7 @@ def __init__(self, self._load_all_devices() self._net_orc = net_orc.NetworkOrchestrator( - session=self._session, - validate=validate, - single_intf = self._single_intf) + session=self._session) self._test_orc = test_orc.TestOrchestrator( self._session, self._net_orc) From 1d39ac8dda2841e8706c362076ddf103c9730b4a Mon Sep 17 00:00:00 2001 From: Jacob Boddey Date: Fri, 11 Aug 2023 18:24:03 +0100 Subject: [PATCH 3/3] Update report file name in testing --- testing/tests/test_tests | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/tests/test_tests b/testing/tests/test_tests index be7a3cef3..193b57184 100755 --- a/testing/tests/test_tests +++ b/testing/tests/test_tests @@ -112,7 +112,7 @@ for tester in $TESTERS; do sudo docker kill $tester sudo docker logs $tester | cat - cp runtime/test/${ethmac//:/}/results.json $TEST_DIR/$tester.json + cp runtime/test/${ethmac//:/}/report.json $TEST_DIR/$tester.json more $TEST_DIR/$tester.json more $testrun_log