Ejemplo n.º 1
0
    def test_vpci_to_if_name_map(self):
        setup_helper = mock.MagicMock()
        setup_helper.vnfd_helper.interfaces = []

        helper = ProxResourceHelper(setup_helper)
        self.assertIsNone(helper._vpci_to_if_name_map)
        result = helper.vpci_to_if_name_map
        self.assertEqual(result, {})
        self.assertIs(result, helper._vpci_to_if_name_map)
        self.assertIs(result, helper.vpci_to_if_name_map)

        setup_helper.vnfd_helper.interfaces = [
            {
                'name': 'vnf1',
                'virtual-interface': {
                    'vpci': '0000:01.02.03',
                },
            },
            {
                'name': 'vnf2',
                'virtual-interface': {
                    'vpci': '0000:04.05.06',
                },
            },
        ]
        expected = {
            '0000:01.02.03': 'vnf1',
            '0000:04.05.06': 'vnf2',
        }
        helper = ProxResourceHelper(setup_helper)
        self.assertIsNone(helper._vpci_to_if_name_map)
        result = helper.vpci_to_if_name_map
        self.assertDictEqual(result, expected)
        self.assertIs(result, helper._vpci_to_if_name_map)
        self.assertIs(result, helper.vpci_to_if_name_map)
Ejemplo n.º 2
0
 def test_upload_prox_config(self):
     setup_helper = mock.MagicMock()
     helper = ProxResourceHelper(setup_helper)
     helper.write_prox_config = mock.MagicMock(return_value='a long string')
     expected = '/tmp/a'
     result = helper.upload_prox_config('a', {})
     self.assertEqual(result, expected)
Ejemplo n.º 3
0
    def test_write_prox_config(self):
        input_data = {}
        expected = ''
        result = ProxResourceHelper.write_prox_config(input_data)
        self.assertEqual(result, expected)

        input_data = {
            'section1': [],
        }
        expected = '[section1]'
        result = ProxResourceHelper.write_prox_config(input_data)
        self.assertEqual(result, expected)

        input_data = OrderedDict([('section1', []),
                                  ('section2', [
                                      ('key1', 'value1'),
                                      ('__name__', 'not this one'),
                                      ('key2', None),
                                      ('key3', 234),
                                      ('key4', 'multi-line\nvalue'),
                                  ])])
        expected = os.linesep.join([
            '[section1]',
            '[section2]',
            'key1=value1',
            'key2',
            'key3=234',
            'key4=multi-line\n\tvalue',
        ])
        result = ProxResourceHelper.write_prox_config(input_data)
        self.assertEqual(result, expected)
Ejemplo n.º 4
0
    def test_put_string_to_file(self):
        setup_helper = mock.MagicMock()
        setup_helper.vnfd_helper.interfaces = []

        helper = ProxResourceHelper(setup_helper)

        expected = 'a/b'
        result = helper.put_string_to_file('my long string', 'a/b')
        self.assertEqual(result, expected)
Ejemplo n.º 5
0
    def test__get_logical_if_name(self):
        setup_helper = mock.MagicMock()
        setup_helper.vnfd_helper.interfaces = []

        helper = ProxResourceHelper(setup_helper)
        helper._vpci_to_if_name_map = {
            'key1': 234,
            'key2': 432,
        }

        expected = 234
        result = helper._get_logical_if_name('key1')
        self.assertEqual(result, expected)
Ejemplo n.º 6
0
    def test_run_test(self, mock_time):
        @contextmanager
        def measure(*args, **kwargs):
            yield stats

        setup_helper = mock.MagicMock()
        setup_helper.vnfd_helper.interfaces = []

        stats = {
            'delta': TotStatsTuple(6, 7, 8, 9),
        }

        client = mock.MagicMock()
        client.hz.return_value = 2
        client.measure_tot_stats = measure
        client.port_stats.return_value = tuple(range(12))

        helper = ProxResourceHelper(setup_helper)
        helper.client = client
        helper.get_latency = mock.MagicMock(return_value=[3.3, 3.6, 3.8])

        with self.assertRaises(AssertionError):
            helper.run_test(980, 15, 45)

        setup_helper.vnfd_helper.interfaces = ['a', 'b', 'c', 'd']
        helper._test_cores = [3, 4]

        expected = ProxTestDataTuple(0.0, 2.0, 6, 7, 8, [3.3, 3.6, 3.8], 6, 7,
                                     1.3e7)
        result = helper.run_test(230, 60, 65)
        self.assertEqual(result, expected)
Ejemplo n.º 7
0
 def test_sut(self):
     helper = ProxResourceHelper(mock.MagicMock())
     self.assertIsNone(helper.client)
     result = helper.sut
     self.assertIsNotNone(result)
     self.assertIs(result, helper.client)
     self.assertIs(result, helper.sut)
Ejemplo n.º 8
0
    def test_execute_traffic(self, *args):
        packet_sizes = [
            10,
            100,
            1000,
        ]
        tp_config = {
            'traffic_profile': {
                'packet_sizes': packet_sizes,
            },
        }

        traffic_generator = mock.MagicMock()

        setup_helper = traffic_generator.setup_helper
        setup_helper.find_in_section.return_value = None

        prox_resource_helper = ProxResourceHelper(setup_helper)
        traffic_generator.resource_helper = prox_resource_helper

        profile = ProxProfile(tp_config)

        self.assertFalse(profile.done.is_set())
        for _ in packet_sizes:
            with self.assertRaises(NotImplementedError):
                profile.execute_traffic(traffic_generator)

        self.assertIsNone(profile.execute_traffic(traffic_generator))
        self.assertTrue(profile.done.is_set())
Ejemplo n.º 9
0
    def test__connect(self, mock_socket_helper_type, mock_time):
        client = mock_socket_helper_type()
        client.connect.side_effect = chain(repeat(socket.error, 5), [None])

        setup_helper = mock.MagicMock()
        setup_helper.vnfd_helper.interfaces = []

        helper = ProxResourceHelper(setup_helper)

        result = helper._connect()
        self.assertIs(result, client)

        client.connect.side_effect = chain(repeat(socket.error, 65), [None])

        with self.assertRaises(Exception):
            helper._connect()
Ejemplo n.º 10
0
    def test_find_pci(self):
        input_str_list = [
            'no target here',
            'nor here',
            'and still not',
        ]
        result = ProxResourceHelper.find_pci('target', input_str_list)
        self.assertFalse(result)

        input_str_list = [
            'no target here',
            'nor here',
            'this is a target',
            'did we miss it',
        ]
        result = ProxResourceHelper.find_pci('target', input_str_list)
        self.assertTrue(result)
Ejemplo n.º 11
0
    def test_latency_cores(self):
        setup_helper = mock.MagicMock()
        helper = ProxResourceHelper(setup_helper)
        helper.prox_config_dict = {}
        helper._cpu_topology = []

        expected = []
        result = helper.latency_cores
        self.assertEqual(result, expected)

        helper = ProxResourceHelper(setup_helper)
        helper.prox_config_dict = OrderedDict([
            ('section1', []),
            ('section2', [
                ('a', 'b'),
                ('c', 'd'),
            ]),
            ('core 1s3', []),
            ('core 2s5', [
                ('index', 8),
                ('mode', ''),
            ]),
            ('core 3s1', [
                ('index', 5),
                ('mode', 'lat'),
            ]),
            ('core 4s9h', [
                ('index', 7),
                ('mode', 'lat'),
            ]),
        ])
        helper._cpu_topology = {
            1: {
                3: {
                    'key1': (23, 32),
                    'key2': (12, 21),
                    'key3': (44, 33),
                },
            },
            9: {
                4: {
                    'key1': (44, 32),
                    'key2': (23, 21),
                    'key3': (12, 33),
                },
            },
        }

        self.assertIsNone(helper._latency_cores)
        expected = [12, 23]
        result = helper.latency_cores
        self.assertEqual(result, expected)
        self.assertIs(result, helper._latency_cores)
        self.assertIs(result, helper.latency_cores)
Ejemplo n.º 12
0
    def test_cpu_topology(self, mock_socket_topology):
        mock_socket_topology.parse_cpuinfo.return_value = 432

        setup_helper = mock.MagicMock()
        setup_helper.ssh_helper.execute.return_value = 0, 'output', ''

        helper = ProxResourceHelper(setup_helper)
        self.assertIsNone(helper._cpu_topology)
        result = helper.cpu_topology
        self.assertEqual(result, 432)
        self.assertIs(result, helper._cpu_topology)
        self.assertIs(result, helper.cpu_topology)
Ejemplo n.º 13
0
    def test_get_process_args_no_additional_file(self, mock_find_path):
        vnf1 = {
            'prox_args': 'c',
            'prox_path': 'd',
            'prox_config': 'e/f',
        }

        mock_find_path.side_effect = ['1', '2']
        setup_helper = mock.MagicMock()
        setup_helper.scenario_helper = ScenarioHelper('vnf1')
        setup_helper.scenario_helper.scenario_cfg = {
            'task_path': 'a/b',
            'options': {
                'vnf1': vnf1,
            },
        }

        helper = ProxResourceHelper(setup_helper)
        helper.copy_to_target = mock.MagicMock(return_value='3')
        helper.generate_prox_config_file = mock.MagicMock(return_value='4')
        helper.upload_prox_config = mock.MagicMock(return_value='5')

        expected = 'c', 'd', '5'
        result = helper.get_process_args()
        self.assertEqual(result, expected)
        self.assertFalse(helper.additional_file)
        self.assertIsNone(helper.remote_prox_file_name)
Ejemplo n.º 14
0
    def test_generate_prox_lua_file(self):
        setup_helper = mock.MagicMock()
        setup_helper.vnfd_helper.interfaces = []

        helper = ProxResourceHelper(setup_helper)
        helper.LUA_PARAMETER_NAME = 'sut'

        expected = ''
        result = helper.generate_prox_lua_file()
        self.assertEqual(result, expected)

        setup_helper.vnfd_helper.interfaces = [
            {
                'local_ip': '10.20.30.40',
                'dst_ip': '10.11.12.13',
                'virtual-interface': {
                    'dpdk_port_num': 3,
                },
            },
            {
                'local_ip': '10.20.30.45',
                'dst_ip': '10.11.12.19',
                'virtual-interface': {
                    'dpdk_port_num': 7,
                },
            },
        ]

        expected = os.linesep.join([
            'sut_hex_ip_port_3:"0a 14 1e 28"',
            'sut_ip_port_3:"10.20.30.40"',
            'gen_hex_ip_port_3:"0a 0b 0c 0d"',
            'gen_ip_port_3:"10.11.12.13"',
            'sut_hex_ip_port_7:"0a 14 1e 2d"',
            'sut_ip_port_7:"10.20.30.45"',
            'gen_hex_ip_port_7:"0a 0b 0c 13"',
            'gen_ip_port_7:"10.11.12.19"',
        ])
        result = helper.generate_prox_lua_file()
        self.assertEqual(result, expected)
Ejemplo n.º 15
0
    def test_upload_prox_lua(self):
        def identity(*args):
            return args

        setup_helper = mock.MagicMock()
        setup_helper.vnfd_helper.interfaces = []

        helper = ProxResourceHelper(setup_helper)
        helper.generate_prox_lua_file = mock.MagicMock(return_value=234)
        helper.put_string_to_file = identity

        expected = ''
        result = helper.upload_prox_lua('my_dir', {})
        self.assertEqual(result, expected)

        input_data = {
            'lua': {
                'key1': 'value1 ("inside") tail',
                'key2': 'value2',
                'key3 ("key_side") head': 'value3',
            },
        }

        expected = 234, 'my_dir/key_side'
        result = helper.upload_prox_lua('my_dir', input_data)
        self.assertEqual(result, expected)
Ejemplo n.º 16
0
    def test__get_tx_port(self):
        # no data
        input_data = {'section1': []}
        expected = -1
        result = ProxResourceHelper._get_tx_port('section1', input_data)
        self.assertEqual(result, expected)

        # data for other section
        input_data = {
            'section1': [],
            'section2': [
                ('rx port', '3'),
                ('tx port', '4'),
            ],
        }
        expected = -1
        result = ProxResourceHelper._get_tx_port('section1', input_data)
        self.assertEqual(result, expected)

        # data for section
        input_data['section1'] = section1 = [
            ('rx port', '4', 'more', 432),
            ('tx port', '3'),
        ]
        expected = 3
        result = ProxResourceHelper._get_tx_port('section1', input_data)
        self.assertEqual(result, expected)

        # more data for section,
        section1.extend([
            ('rx port', '2'),
            ('tx port', '1', 'and more', 234),
        ])
        expected = 1
        result = ProxResourceHelper._get_tx_port('section1', input_data)
        self.assertEqual(result, expected)
Ejemplo n.º 17
0
    def test_execute(self):
        setup_helper = mock.MagicMock()
        helper = ProxResourceHelper(setup_helper)
        helper.client = mock.MagicMock()

        expected = helper.client.my_command()
        result = helper.execute('my_command')
        self.assertEqual(result, expected)

        helper.client = object()

        result = helper.execute('my_command')
        self.assertIsNone(result)
Ejemplo n.º 18
0
    def test_generate_prox_config_file_negative(self, mock_parser_type):
        def init(*args):
            args[-1].update(sections_data)
            return mock.MagicMock()

        sections_data = {}

        mock_parser_type.side_effect = init

        setup_helper = mock.MagicMock()
        setup_helper.vnfd_helper.interfaces = []

        helper = ProxResourceHelper(setup_helper)
        helper.additional_file = False
        helper.remote_prox_file_name = 'remote'
        setup_helper.vnfd_helper.interfaces = [
            {
                'virtual-interface': {
                    'dpdk_port_num': 3,
                    'dst_mac': '00:00:00:de:ad:88',
                },
            },
            {
                'virtual-interface': {
                    'dpdk_port_num': 5,
                    'dst_mac': '00:00:00:de:ad:ff',
                },
            },
            {
                'virtual-interface': {
                    'dpdk_port_num': 7,
                    'dst_mac': '00:00:00:de:ad:ff',
                },
            },
        ]
        sections_data = {
            'port 3': [
                ['ip', ''],
                ['mac', 'foo'],
                ['dst mac', ''],
            ],
            'port 5': [
                ['ip', ''],
                ['dst mac', ''],
                ['tx port', '0'],
                ['???', 'dofile "here" 23'],
            ],
        }

        with self.assertRaises(Exception):
            helper.generate_prox_config_file('a/b')
Ejemplo n.º 19
0
    def test_get_latency(self):
        setup_helper = mock.MagicMock()
        setup_helper.vnfd_helper.interfaces = []

        helper = ProxResourceHelper(setup_helper)
        helper._latency_cores = []

        expected = []
        result = helper.get_latency()
        self.assertEqual(result, expected)

        helper._latency_cores = [1, 2]
        helper.client = mock.MagicMock()

        expected = helper.sut.lat_stats()
        result = helper.get_latency()
        self.assertIs(result, expected)
Ejemplo n.º 20
0
    def test__replace_quoted_with_value(self):
        # empty string
        input_str = ''
        expected = ''
        result = ProxResourceHelper._replace_quoted_with_value(
            input_str, 'cat')
        self.assertEqual(result, expected)

        # no quoted substring
        input_str = 'lion tiger bear'
        expected = 'lion tiger bear'
        result = ProxResourceHelper._replace_quoted_with_value(
            input_str, 'cat')
        self.assertEqual(result, expected)

        # partially quoted substring
        input_str = 'lion "tiger bear'
        expected = 'lion "tiger bear'
        result = ProxResourceHelper._replace_quoted_with_value(
            input_str, 'cat')
        self.assertEqual(result, expected)

        # one quoted substring
        input_str = 'lion "tiger" bear'
        expected = 'lion "cat" bear'
        result = ProxResourceHelper._replace_quoted_with_value(
            input_str, 'cat')
        self.assertEqual(result, expected)

        # two quoted substrings
        input_str = 'lion "tiger" bear "shark" whale'
        expected = 'lion "cat" bear "shark" whale'
        result = ProxResourceHelper._replace_quoted_with_value(
            input_str, 'cat')
        self.assertEqual(result, expected)

        # two quoted substrings, both replaced
        input_str = 'lion "tiger" bear "shark" whale'
        expected = 'lion "cat" bear "cat" whale'
        result = ProxResourceHelper._replace_quoted_with_value(
            input_str, 'cat', 2)
        self.assertEqual(result, expected)
Ejemplo n.º 21
0
 def test_up_post(self):
     setup_helper = mock.MagicMock()
     helper = ProxResourceHelper(setup_helper)
     helper.client = expected = mock.MagicMock()
     result = helper.up_post()
     self.assertEqual(result, expected)
Ejemplo n.º 22
0
 def test_copy_to_target(self):
     setup_helper = mock.MagicMock()
     helper = ProxResourceHelper(setup_helper)
     expected = '/tmp/c'
     result = helper.copy_to_target('a/b', 'c')
     self.assertEqual(result, expected)
Ejemplo n.º 23
0
 def test_terminate(self):
     setup_helper = mock.MagicMock()
     helper = ProxResourceHelper(setup_helper)
     self.assertIsNone(helper.terminate())
Ejemplo n.º 24
0
 def test_start_collect(self):
     setup_helper = mock.MagicMock()
     helper = ProxResourceHelper(setup_helper)
     self.assertIsNone(helper.start_collect())
Ejemplo n.º 25
0
    def test_generate_prox_config_file(self, mock_parser_type):
        def init(*args):
            args[-1].update(sections_data)
            return mock.MagicMock()

        sections_data = {}

        mock_parser_type.side_effect = init

        setup_helper = mock.MagicMock()
        setup_helper.vnfd_helper.interfaces = []

        helper = ProxResourceHelper(setup_helper)
        helper.additional_file = False

        expected = {}
        result = helper.generate_prox_config_file('a/b')
        self.assertEqual(result, expected)

        helper.additional_file = True
        helper.remote_prox_file_name = 'remote'
        setup_helper.vnfd_helper.interfaces = [
            {
                'virtual-interface': {
                    'dpdk_port_num': 3,
                    'dst_mac': '00:00:00:de:ad:88',
                },
            },
            {
                'virtual-interface': {
                    'dpdk_port_num': 5,
                    'dst_mac': '00:00:00:de:ad:ff',
                },
            },
            {
                'virtual-interface': {
                    'dpdk_port_num': 7,
                    'dst_mac': '00:00:00:de:ad:ff',
                },
            },
        ]
        sections_data = {
            'port 3': [
                ['ip', ''],
                ['mac', 'foo'],
                ['dst mac', ''],
                ['tx port', '1'],
            ],
            'port 5': [
                ['ip', ''],
                ['dst mac', ''],
                ['tx port', '0'],
                ['single'],
                ['???', 'dofile "here" 23'],
            ],
        }

        expected = {
            'port 3': [
                ['ip', ''],
                ['mac', 'hardware'],
                ['dst mac', '00:00:00:de:ad:ff'],
                ['tx port', '1'],
            ],
            'port 5': [
                ['ip', ''],
                ['dst mac', '00:00:00:de:ad:88'],
                ['tx port', '0'],
                ['single'],
                ['???', 'dofile "remote" 23'],
            ],
        }
        result = helper.generate_prox_config_file('a/b')
        self.assertDictEqual(result, expected)
Ejemplo n.º 26
0
 def test_line_rate_to_pps(self):
     expected = 0.25 * 1e8
     result = ProxResourceHelper.line_rate_to_pps(180, 4)
     self.assertEqual(result, expected)