From a45dc07c153c4dd350b02fd30de471bbdb838ac9 Mon Sep 17 00:00:00 2001 From: Ole Troan Date: Fri, 21 Dec 2018 16:04:22 +0100 Subject: [PATCH] Revert "tests: Rework vpp config generation." This reverts commit 919efad2671993d4c6d5a0dba8eeb99d5c60edf1. Change-Id: I5ec4fa08a03f508dac684dc1ddbd7e6b85c49b97 Signed-off-by: Ole Troan --- test/framework.py | 50 ++++++------ test/test_punt.py | 4 +- test/vpp_config.py | 233 ----------------------------------------------------- 3 files changed, 29 insertions(+), 258 deletions(-) delete mode 100644 test/vpp_config.py diff --git a/test/framework.py b/test/framework.py index 2505057472e..7633ca04d0b 100644 --- a/test/framework.py +++ b/test/framework.py @@ -20,10 +20,8 @@ from traceback import format_exception from logging import FileHandler, DEBUG, Formatter from scapy.packet import Raw from hook import StepHook, PollHook, VppDiedError -from vpp_config import VppTestCaseVppConfig -from vpp_interface import VppInterface -from vpp_sub_interface import VppSubInterface from vpp_pg_interface import VppPGInterface +from vpp_sub_interface import VppSubInterface from vpp_lo_interface import VppLoInterface from vpp_papi_provider import VppPapiProvider from vpp_papi.vpp_stats import VPPStats @@ -207,8 +205,8 @@ class VppTestCase(unittest.TestCase): classes. It provides methods to create and run test case. """ - CLI_LISTEN_DEFAULT = 'localhost:5002' - config = VppTestCaseVppConfig() + extra_vpp_punt_config = [] + extra_vpp_plugin_config = [] @property def packet_infos(self): @@ -303,26 +301,32 @@ class VppTestCase(unittest.TestCase): plugin_path = cls.plugin_path elif cls.extern_plugin_path is not None: plugin_path = cls.extern_plugin_path - + debug_cli = "" if cls.step or cls.debug_gdb or cls.debug_gdbserver: - cls.config.add('unix', 'cli-listen', cls.CLI_LISTEN_DEFAULT) - + debug_cli = "cli-listen localhost:5002" coredump_size = None size = os.getenv("COREDUMP_SIZE") - cls.config.add('unix', 'coredump-size', - size if size is not None else 'unlimited') - - cls.config.add('unix', 'runtime-dir', cls.tempdir) - cls.config.add('api-segment', 'prefix', cls.shm_prefix) - cls.config.add('cpu', 'main-core', str(cls.get_least_used_cpu())) - cls.config.add('statseg', 'socket-name', cls.stats_sock) - + if size is not None: + coredump_size = "coredump-size %s" % size + if coredump_size is None: + coredump_size = "coredump-size unlimited" + + cpu_core_number = cls.get_least_used_cpu() + + cls.vpp_cmdline = [cls.vpp_bin, "unix", + "{", "nodaemon", debug_cli, "full-coredump", + coredump_size, "runtime-dir", cls.tempdir, "}", + "api-trace", "{", "on", "}", "api-segment", "{", + "prefix", cls.shm_prefix, "}", "cpu", "{", + "main-core", str(cpu_core_number), "}", "statseg", + "{", "socket-name", cls.stats_sock, "}", "plugins", + "{", "plugin", "dpdk_plugin.so", "{", "disable", + "}", "plugin", "unittest_plugin.so", "{", "enable", + "}"] + cls.extra_vpp_plugin_config + ["}", ] + if cls.extra_vpp_punt_config is not None: + cls.vpp_cmdline.extend(cls.extra_vpp_punt_config) if plugin_path is not None: - cls.config.add('plugins', 'path', plugin_path) - cls.config.add_plugin('dpdk_plugin.so', 'disable') - cls.config.add_plugin('unittest_plugin.so', 'enable') - - cls.vpp_cmdline = [cls.vpp_bin] + cls.config.shlex() + cls.vpp_cmdline.extend(["plugin_path", plugin_path]) cls.logger.info("vpp_cmdline args: %s" % cls.vpp_cmdline) cls.logger.info("vpp_cmdline: %s" % " ".join(cls.vpp_cmdline)) @@ -853,8 +857,8 @@ class VppTestCase(unittest.TestCase): for cf in checksum_fields: if hasattr(layer, cf): if ignore_zero_udp_checksums and \ - 0 == getattr(layer, cf) and \ - layer.name in udp_layers: + 0 == getattr(layer, cf) and \ + layer.name in udp_layers: continue delattr(layer, cf) checksums.append((counter, cf)) diff --git a/test/test_punt.py b/test/test_punt.py index b20dc76c61d..d57a847ef0c 100644 --- a/test/test_punt.py +++ b/test/test_punt.py @@ -121,8 +121,8 @@ class TestPuntSocket(VppTestCase): @classmethod def setUpConstants(cls): - tempdir = cls.tempdir - cls.config.add('punt', 'socket', '%s/socket_punt' % cls.tempdir) + cls.extra_vpp_punt_config = [ + "punt", "{", "socket", cls.tempdir+"/socket_punt", "}"] super(TestPuntSocket, cls).setUpConstants() def setUp(self): diff --git a/test/vpp_config.py b/test/vpp_config.py deleted file mode 100644 index 03cddf80ade..00000000000 --- a/test/vpp_config.py +++ /dev/null @@ -1,233 +0,0 @@ -# Copyright 2018 Vinci Consulting Corp. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); you may -# not use this file except in compliance with the License. You may obtain -# a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -# License for the specific language governing permissions and limitations -# under the License. - -import shlex -import unittest - - -class VppConfig(object): - stanzas = ['unix', 'api-trace', 'api-segment', - 'socksvr', 'cpu', 'statseg', 'dpdk', 'plugins', 'tuntap', - 'punt'] - kw = {'unix': ['interactive', 'nodaemon', 'log', 'full-coredump', - 'coredump-size', 'cli-listen', 'runtime-dir', 'gid'], - 'acl-plugin': ['connection hash buckets', 'connection hash memory', - 'connection count max', 'main heap size', - 'hash lookup heap size', 'hash lookup hash buckets', - 'hash lookup hash memory', 'use tuple merge', - 'tuple merge split threshold', 'reclassify sessions'], - 'api-queue': ['len', 'length'], - 'api-trace': ['on', 'enable, ''nitems', 'save-api-table'], - 'api-segment': ['prefix', 'gid'], - 'cj': ['on', 'records'], - 'cpu': ['main-core', 'corelist-workers', 'skip-cores', - 'workers', 'scheduler-policy', 'scheduler-priority'], - 'dns': ['max-cache-size', 'max-ttl'], - 'dpdk': ['dev', 'vdev', 'name', 'hqos', 'rss', - 'no-multi-seg', - 'num-mbufs', 'num-rx-queues', 'num-tx-queues', - 'num-rx-desc', 'num-tx-desc', - 'socket-mem', 'no-tx-checksum-offload', 'uio-driver', - 'vlan-strip-offload', 'workers'], - # currently don't support dynamic keys - # 'heapsize': [], - 'l2learn': ['limit'], - 'l2tp': ['lookup-v6-src', 'lookup-v6-dst', - 'lookup-session-id'], - 'nat': ['connection tracking', 'deterministic', 'dslite ce', - 'endpoint-dependent', 'inside VRF id', - 'max translations per user', - 'nat64 bib hash bucket', 'nat64 bib hash memory', - 'nat64 st hash buckets', - 'outside ip6 VRF id', 'outside VRF id', 'out2in dpo' - 'static mapping only', - 'translation hash buckets', - 'translation hash memory', - 'user hash buckets', 'user hash memory', - ], - 'mactime': ['lookup-table-buckets', 'lookup-table-memory', - 'timezone_offset'], - 'mc': ['interface', 'no-delay', 'no-validate', 'max-delay', - 'min-delay', 'n-bytes', 'n-packets', - 'max-n-bytes', - 'min-n-bytes', - 'seed', 'window', 'verbose', ], - 'oam': ['interval', 'misses-allowed'], - 'plugins': ['path', 'plugin'], - 'punt': ['socket'], - 'session': ['event-queue-length', 'preallocated-sessions', - 'v4-session-table-buckets', 'v4-halfopen-table-buckets', - 'v6-session-table-buckets', 'v6-halfopen-table-buckets', - 'v6-halfopen-table-buckets' - ], - 'socksvr': ['default', 'socket-name'], - 'statseg': ['socket-name'], - 'tapcli': ['disable', 'mtu'], - 'tcp': ['buffer-fail-fraction', 'cc-algo', 'max-rx-fifo', - 'no-tx-pacing', 'preallocated-connections', - 'preallocated-half-open-connections', - ], - 'tuntap': ['name', 'mtu', 'enable', 'disable', - 'ether', 'ethernet', - 'have-normal', 'have-normal-interface' - ], - 'vhost-user': ['coalesce-frames', 'coalesce-time', - 'dont-dump-memory'] - - - } - default_values = {'unix': {'interactive': None, - } - } - - def __init__(self): - self.values = type(self).default_values - self.plugins = [] - - def add(self, stanza, key, val): - if stanza not in type(self).stanzas: - raise ValueError("stanza '%s' must be in %s" % - (stanza, type(self).stanzas)) - if key not in type(self).kw[stanza]: - raise ValueError("key '%s' must be in %s" % - (key, type(self).kw[stanza])) - self.values[stanza][key] = val - - def add_plugin(self, key, val): - self.plugins.append((key, val,)) - - def __str__(self): - result = '' - for stanza in type(self).stanzas: - try: - if self.values[stanza]: - result = '%s\n%s {' % (result, stanza) - for key in type(self).kw[stanza]: - try: - if key in self.values[stanza]: - result = '%s\n %s %s' % ( - result, key, - self.values[stanza][key] - if self.values[stanza][key] is not - None else '') - except KeyError: - # no key: nothing to do - pass - if stanza == 'plugins' and key == 'plugin': - for plugin, val in self.plugins: - result = '%s\n plugin %s { % s }' % ( - result, plugin, - val if val is not None else '') - result = '%s\n}\n' % result - except KeyError: - # no stanza not in self.values: nothing to do - pass - return result - - def shlex(self): - return shlex.split(str(self)) - - -class MinimalVppConfig(VppConfig): - default_values = {'unix': {'interactive': None, - 'cli-listen': 'run/vpp/cli.sock', - 'gid': 1000 - } - } - - -class VppTestCaseVppConfig(VppConfig): - default_values = {'unix': {'nodaemon': None, - 'full-coredump': None, - }, - 'acl-plugin': {}, - 'api-queue': {}, - 'api-trace': {'on': None}, - 'api-segment': {}, - 'cj': {}, - 'cpu': {}, - 'dns': {}, - 'dpdk': {}, - # currently don't support dynamic keys - # 'heapsize': {}, - 'l2learn': {}, - 'l2tp': {}, - 'mactime': {}, - 'mc': {}, - 'nat': {}, - 'oam': {}, - 'plugins': {}, - 'punt': {}, - 'session': {}, - 'socksvr': {'default': None}, - 'statseg': {}, - 'tapcli': {}, - 'tcp': {}, - 'tuntap': {}, - 'vhost-user': {}, - } - - -class TestVppConfig(unittest.TestCase): - - def setUp(self): - self.config = VppTestCaseVppConfig() - - def test_unix(self): - size = None - tempdir = '/tmp' - - # reset default values for this test. - self.config.default_values['unix'] = {} - self.config.add('unix', 'coredump-size', size - if size is not None else 'unlimited') - self.assertIn('unix {\n coredump-size unlimited\n}\n', - str(self.config)) - - self.config.add('unix', 'runtime-dir', tempdir) - self.assertIn('runtime-dir /tmp', str(self.config)) - - def test_api_segment(self): - shm_prefix = '/dev/shm' - self.config.add('api-segment', 'prefix', shm_prefix) - self.assertIn('api-segment {\n prefix /dev/shm\n}\n', - str(self.config)) - - def test_cpu(self): - luc = 0 - self.config.add('cpu', 'main-core', str(luc)) - self.assertIn('cpu {\n main-core 0\n}\n', str(self.config)) - - def test_statseg(self): - stats_sock = '/stats.sock' - self.config.add('statseg', 'socket-name', stats_sock) - self.assertIn('statseg {\n socket-name /stats.sock\n}\n', - str(self.config)) - - def test_plugin(self): - plugin_path = '/foo' - self.config.add('plugins', 'path', plugin_path) - self.assertIn('plugins {\n path /foo\n}\n', - str(self.config)) - - self.config.add_plugin('dpdk_plugin.so', 'disable') - self.config.add_plugin('unittest_plugin.so', 'enable') - self.assertIn('plugin dpdk_plugin.so { disable }\n', - str(self.config)) - self.assertIn('plugin unittest_plugin.so { enable }\n', - str(self.config)) - - -if __name__ == '__main__': - unittest.main() -- 2.16.6