def test_stl_examples(self): examples_dir = '../trex_control_plane/stl/examples' examples_to_test = [ 'stl_imix.py', ] for example in examples_to_test: return_code, stdout, stderr = run_command("sh -c 'cd %s; %s %s -s %s'" % (examples_dir, sys.executable, example, CTRexScenario.configuration.trex['trex_name'])) assert return_code == 0, 'example %s failed.\nstdout: %s\nstderr: %s' % (return_code, stdout, stderr)
def run_client_package_stf_example(self, python_version): commands = [ 'cd %s' % CTRexScenario.scripts_path, 'source find_python.sh --%s' % python_version, 'which $PYTHON', 'cd trex_client/stf/examples', '$PYTHON stf_example.py -s %s' % self.configuration.trex['trex_name'], ] return_code, _, stderr = run_command("bash -ce '%s'" % '; '.join(commands)) if return_code: self.fail('Error in running stf_example using %s: %s' % (python_version, stderr))
def test_stl_examples(self): examples_dir = "../trex_control_plane/stl/examples" examples_to_test = ["stl_imix.py"] for example in examples_to_test: self.explicitSetUp() return_code, stdout, stderr = run_command( "sh -c 'cd %s; %s %s -s %s'" % (examples_dir, sys.executable, example, CTRexScenario.configuration.trex["trex_name"]) ) self.explicitTearDown() assert return_code == 0, "example %s failed.\nstdout: %s\nstderr: %s" % (return_code, stdout, stderr)
def unzip_client_package(): client_pkg_files = glob('%s/trex_client*.tar.gz' % CTRexScenario.scripts_path) if not len(client_pkg_files): raise Exception('Could not find client package') if len(client_pkg_files) > 1: raise Exception('Found more than one client packages') if not os.path.exists('%s/trex_client' % CTRexScenario.scripts_path): print('\nUnzipping package') return_code, _, stderr = misc_methods.run_command("tar -xzf %s -C %s" % (client_pkg_files[0], CTRexScenario.scripts_path)) if return_code: raise Exception('Could not untar the client package: %s' % stderr) else: print('\nClient package is untarred')
def run_client_package_stl_example(self, python_version): commands = [ 'cd %s' % CTRexScenario.scripts_path, 'source find_python.sh --%s' % python_version, 'which $PYTHON', 'cd trex_client/interactive', '$PYTHON -m trex.examples.stl.stl_imix -s %s' % self.configuration.trex['trex_name'], ] return_code, stdout, stderr = run_command("bash -ce '%s'" % '; '.join(commands)) if return_code: self.fail('Error in running stf_example using %s: %s' % (python_version, [return_code, stdout, stderr]))
def test_astf_prof_examples(self): examples_dir = '../trex_control_plane/interactive' examples_to_test = [ 'astf_example', ] for example in examples_to_test: cmd = "-m trex.examples.astf.{0}".format(example) self.explicitSetUp() return_code, stdout, stderr = run_command( "sh -c 'cd %s; %s %s -s %s'" % (examples_dir, sys.executable, cmd, CTRexScenario.configuration.trex['trex_name'])) self.explicitTearDown() assert return_code == 0, 'example %s failed.\nstdout: %s\nstderr: %s' % ( return_code, stdout, stderr)
def _update_trex(self, timeout=600): client = CTRexScenario.trex if client.master_daemon.is_trex_daemon_running( ) and client.get_trex_cmds() and not self.kill_running: fatal( "Can't update TRex, it's running. Consider adding --kill-running flag." ) ret, out, err = misc_methods.run_command('sha1sum -b %s' % self.pkg) if ret: fatal('Could not calculate sha1 of package. Got: %s' % [ret, out, err]) sha1 = out.strip().split()[0] if client.master_daemon.get_package_sha1() == sha1: print('Server is up to date with package: %s' % self.pkg) CTRexScenario.pkg_updated = True return print('Updating TRex to: %s' % self.pkg) client.master_daemon.update_trex(self.pkg) sys.stdout.write('Waiting for update to finish') sys.stdout.flush() start_time = time.time() while True: if time.time() > start_time + timeout: fatal(' timeout of %ss while updating TRex.' % timeout) sys.stdout.write('.') sys.stdout.flush() time.sleep(1) if not client.master_daemon.is_updating(): print(' finished.') break master_pkg_sha1 = client.master_daemon.get_package_sha1() if master_pkg_sha1 == sha1: print('Hash matches needed package, success.') CTRexScenario.pkg_updated = True return else: error = client.master_daemon.get_update_error() if error: print('Error happened while updating package. %s' % error) fatal('Hash does not match (%s), stuck with old package.' % master_pkg_sha1)