1#!/router/bin/python
2from .trex_general_test import CTRexGeneral_Test, CTRexScenario
3from misc_methods import run_command
4from nose.plugins.attrib import attr
5
6
7@attr('client_package')
8class CTRexClientPKG_Test(CTRexGeneral_Test):
9    """This class tests TRex client package"""
10
11    def setUp(self):
12        CTRexGeneral_Test.setUp(self)
13        if not self.is_loopback and not CTRexScenario.router_cfg['no_dut_config']:
14            self.router.configure_basic_interfaces()
15            self.router.config_pbr(mode = 'config')
16        self.unzip_client_package()
17
18    def run_client_package_stf_example(self, python_version):
19        commands = [
20                    'cd %s' % CTRexScenario.scripts_path,
21                    'source find_python.sh --%s' % python_version,
22                    'which $PYTHON',
23                    'cd trex_client/stf/examples',
24                    '$PYTHON stf_example.py -s %s' % self.configuration.trex['trex_name'],
25                   ]
26        return_code, _, stderr = run_command("bash -ce '%s'" % '; '.join(commands))
27        if return_code:
28            self.fail('Error in running stf_example using %s: %s' % (python_version, stderr))
29
30    def test_client_python2(self):
31        self.run_client_package_stf_example(python_version = 'python2')
32
33    def test_client_python3(self):
34        self.run_client_package_stf_example(python_version = 'python3')
35