From 931b7d52a023ea73e596d90c6e9e938de903100b Mon Sep 17 00:00:00 2001 From: Pavel Kotucek Date: Wed, 22 May 2019 15:23:41 +0200 Subject: Docker test improvements Small changes to enable kept running vpp and sysrepo instances after test execution. Fixed typos (file name and and method in py file). Change-Id: I32e56464e61bf1548984ea9845a8d08cf6a3917b Signed-off-by: Pavel Kotucek --- test/framework.py | 45 ++++++++++++++++++++++++++++++++++++++++++++ test/framewrok.py | 38 ------------------------------------- test/netopeer_controler.py | 5 +++-- test/test_ietf_interfaces.py | 4 ++-- test/topology.py | 21 +++++++++++++++++---- test/vpp_controler.py | 7 ++++++- 6 files changed, 73 insertions(+), 47 deletions(-) create mode 100644 test/framework.py delete mode 100644 test/framewrok.py diff --git a/test/framework.py b/test/framework.py new file mode 100644 index 0000000..b308a1a --- /dev/null +++ b/test/framework.py @@ -0,0 +1,45 @@ +# +# Copyright (c) 2019 PANTHEON.tech. +# +# 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 unittest + +from topology import Topology + +class SweetcombTestCase(unittest.TestCase): + + @classmethod + def instance(cls): + """Return the instance of this testcase""" + + return cls.instance + + @classmethod + def create_topology(cls, debug=False): + + cls.topology = Topology() + cls.topology.create_topology(debug) + + cls.vpp = cls.topology.get_vpp() + cls.netopeer_cli = cls.topology.get_netopeer_cli() + + def check_response(self, resps, expected_result, checks): + assert resps[1] == expected_result + + for key,val in checks.items(): + for resp in resps: + r = str(resp).strip() + if r.find("<"+key+">") == 0: + assert r[r.find("<"+key+">")+len("<"+key+">"):r.rfind("")] == val diff --git a/test/framewrok.py b/test/framewrok.py deleted file mode 100644 index 9fbf240..0000000 --- a/test/framewrok.py +++ /dev/null @@ -1,38 +0,0 @@ -# -# Copyright (c) 2019 PANTHEON.tech. -# -# 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 unittest - -from topology import Topology - -class SweetcombTestCase(unittest.TestCase): - - @classmethod - def instance(cls): - """Return the instance of this testcase""" - - return cls.instance - - @classmethod - def create_topoly(cls): - - cls.topology = Topology() - cls.topology.create_topology() - - cls.vpp = cls.topology.get_vpp() - cls.netopeer_cli = cls.topology.get_netopeer_cli() - - diff --git a/test/netopeer_controler.py b/test/netopeer_controler.py index 74c7dc6..e95cbb4 100644 --- a/test/netopeer_controler.py +++ b/test/netopeer_controler.py @@ -42,6 +42,7 @@ class Netopeer_controler: def spawn(self): self.child = pexpect.spawn(self.name) self.child.logfile = open('/var/log/Netopeer_controler.log', 'wb') + self.child.setwinsize(1,1024) self.pid = self.child.pid self.child.expect(">") self.child.sendline("connect\r") @@ -58,7 +59,7 @@ class Netopeer_controler: def get(self, msg): self.child.sendline("get --filter-xpath {}\r".format(msg)) self.child.expect("> ") - print(self.child.before.decode('ascii')) + return self.child.before.decode('ascii') def edit_config(self, msg): f = open("/tmp/tmp_example.xml", "w") @@ -67,4 +68,4 @@ class Netopeer_controler: self.child.sendline("edit-config --target running --config=/tmp/tmp_example.xml\r") self.child.expect("> ") - print(self.child.before.decode('ascii')) + return self.child.before.decode('ascii') diff --git a/test/test_ietf_interfaces.py b/test/test_ietf_interfaces.py index 55ef029..2b421d3 100644 --- a/test/test_ietf_interfaces.py +++ b/test/test_ietf_interfaces.py @@ -17,14 +17,14 @@ import unittest import util -from framewrok import SweetcombTestCase +from framework import SweetcombTestCase class TestIetfInterfaces(SweetcombTestCase): def setUp(self): super(TestIetfInterfaces, self).setUp() - self.create_topoly() + self.create_topology() def tearDown(self): super(TestIetfInterfaces, self).setUp() diff --git a/test/topology.py b/test/topology.py index 43f15e3..617601b 100644 --- a/test/topology.py +++ b/test/topology.py @@ -24,6 +24,8 @@ import psutil import time class Topology: + debug = False + def __init__(self): self.process = [] @@ -31,6 +33,8 @@ class Topology: self._kill_process() def _kill_process(self): + if self.debug: + return if not self.process: return @@ -67,7 +71,11 @@ class Topology: print("Start sysrepo deamon.") #TODO: Need property close. err = open("/var/log/sysrepod", 'wb') - self.sysrepo = subprocess.Popen(["sysrepod", "-d", "-l 3"], + if self.debug: + params = "-l 4" + else: + params = "-l 3" + self.sysrepo = subprocess.Popen(["sysrepod", "-d", params], stdout=subprocess.PIPE, stderr=err) self.process.append(self.sysrepo) @@ -75,7 +83,11 @@ class Topology: print("Start sysrepo plugins.") #TODO: Need property close. err = open("/var/log/sysrepo-plugind", 'wb') - self.splugin = subprocess.Popen(["sysrepo-plugind", "-d", "-l 3"], + if self.debug: + params = "-l 4" + else: + params = "-l 3" + self.splugin = subprocess.Popen(["sysrepo-plugind", "-d", params], stdout=subprocess.PIPE, stderr=err) self.process.append(self.splugin) @@ -93,7 +105,7 @@ class Topology: def _start_vpp(self): print("Start VPP.") - self.vpp = Vpp_controler() + self.vpp = Vpp_controler(self.debug) self.vpp.spawn() self.process.append(self.vpp) @@ -103,8 +115,9 @@ class Topology: def get_netopeer_cli(self): return self.netopeer_cli - def create_topology(self): + def create_topology(self, debug=False): #try: + self.debug = debug self._prepare_linux_enviroment() self._start_vpp() self._start_sysrepo() diff --git a/test/vpp_controler.py b/test/vpp_controler.py index 561f5a0..e764e9b 100644 --- a/test/vpp_controler.py +++ b/test/vpp_controler.py @@ -19,11 +19,14 @@ import time import psutil class Vpp_controler: - def __init__(self): + debug = False + + def __init__(self, debug=False): self.cmd = "vpp" self.ccmd = "vppctl" self.configuration = "/root/src/sweetcomb/test/conf/vpp.conf" self.process = None + self.debug = debug def __del__(self): #self.kill() @@ -50,6 +53,8 @@ class Vpp_controler: self.process = None def terminate(self): + if self.debug: + return if self.process is None: return -- cgit 1.2.3-korg