From 024a13ac0d2e25dec620003e2538acb4598598fd Mon Sep 17 00:00:00 2001 From: Andrej Kozemcak Date: Fri, 31 May 2019 08:52:45 +0200 Subject: [TEST] - Init log - init log - clean output Change-Id: Ia4f722eb5c989df8d2f5f14f602ed30657db9975 Signed-off-by: Andrej Kozemcak --- test/framework.py | 7 +++++++ test/log.py | 23 +++++++++++++++++++++++ test/run_test.py | 3 ++- test/test_ietf_interfaces.py | 10 ++++++++++ test/test_oc_interfaces.py | 10 ++++++++++ test/topology.py | 21 ++++++++++----------- test/vpp_controler.py | 8 ++++++-- 7 files changed, 68 insertions(+), 14 deletions(-) create mode 100644 test/log.py diff --git a/test/framework.py b/test/framework.py index bd42b48..8a8c42c 100644 --- a/test/framework.py +++ b/test/framework.py @@ -20,6 +20,7 @@ import unittest from topology import Topology import vppctl import sys +import log class SweetcombTestCase(unittest.TestCase): @@ -40,6 +41,12 @@ class SweetcombTestCase(unittest.TestCase): cls.netopeer_cli = cls.topology.get_netopeer_cli() cls.vppctl = vppctl.Vppctl() + @classmethod + def setUpClass(cls): + + super(SweetcombTestCase, cls).setUpClass() + cls.logger = log.get_logger(cls.__name__) + def runTest(self): pass diff --git a/test/log.py b/test/log.py new file mode 100644 index 0000000..35da229 --- /dev/null +++ b/test/log.py @@ -0,0 +1,23 @@ +# +# Copyright (c) 2019 Cisco and/or its affiliates. +# +# 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 logging + + +def get_logger(name): + logger = logging.getLogger(name) + logger.setLevel(logging.DEBUG) + return logger diff --git a/test/run_test.py b/test/run_test.py index 7acd152..63c3f63 100755 --- a/test/run_test.py +++ b/test/run_test.py @@ -106,5 +106,6 @@ if __name__ == '__main__': #map(full_suite.addTests, suites) for suite in suites: full_suite.addTests(suite) - result = SweetcombTestRunner(print_summary=True).run(full_suite) + result = SweetcombTestRunner(verbosity=1, + print_summary=True).run(full_suite) diff --git a/test/test_ietf_interfaces.py b/test/test_ietf_interfaces.py index a4ebf78..7908225 100644 --- a/test/test_ietf_interfaces.py +++ b/test/test_ietf_interfaces.py @@ -39,6 +39,9 @@ class TestIetfInterfaces(SweetcombTestCase): self.topology.close_topology() def test_interface(self): + + self.logger.info("IETF_INTERFACE_TEST_START_001") + name = "host-vpp1" crud_service = CRUDService() @@ -74,7 +77,12 @@ class TestIetfInterfaces(SweetcombTestCase): self.assertIsNotNone(p) self.assertEquals(interface.enabled, p.State) + self.logger.info("IETF_INTERFACE_TEST_FINISH_001") + def test_ipv4(self): + + self.logger.info("IETF_INTERFACE_TEST_START_002") + name = "host-vpp1" crud_service = CRUDService() @@ -118,6 +126,8 @@ class TestIetfInterfaces(SweetcombTestCase): self.assertIsNone(a) + self.logger.info("IETF_INTERFACE_TEST_FINISH_002") + if __name__ == '__main__': unittest.main(testRunner=SweetcombTestRunner) diff --git a/test/test_oc_interfaces.py b/test/test_oc_interfaces.py index be87eed..82168f5 100644 --- a/test/test_oc_interfaces.py +++ b/test/test_oc_interfaces.py @@ -39,6 +39,9 @@ class TestOcInterfaces(SweetcombTestCase): self.topology.close_topology() def test_interface(self): + + self.logger.info("OC_INTERFACE_START_001") + name = "host-vpp1" crud_service = CRUDService() @@ -67,8 +70,13 @@ class TestOcInterfaces(SweetcombTestCase): self.assertIsNotNone(p) self.assertEquals(interface.config.enabled, p.State) + self.logger.info("OC_INTERFACE_FINISH_001") + @unittest.skip("YDK return error when try set IP address") def test_interface_ipv4(self): + + self.logger.info("OC_INTERFACE_START_002") + name = "host-vpp1" crud_service = CRUDService() @@ -94,5 +102,7 @@ class TestOcInterfaces(SweetcombTestCase): a = self.vppctl.show_address(name) + self.logger.info("OC_INTERFACE_FINISH_002") + if __name__ == '__main__': unittest.main(testRunner=SweetcombTestRunner) diff --git a/test/topology.py b/test/topology.py index 26dc622..d8fab1c 100644 --- a/test/topology.py +++ b/test/topology.py @@ -70,7 +70,8 @@ class Topology: ip.addr('add', index=vpp2, address='192.168.1.2', prefixlen=24) def _start_sysrepo(self): - print("Start sysrepo deamon.") + #TODO: Add to log + #print("Start sysrepo deamon.") #TODO: Need property close. err = open("/var/log/sysrepod", 'wb') if self.debug: @@ -82,7 +83,8 @@ class Topology: self.process.append(self.sysrepo) def _start_sysrepo_plugins(self): - print("Start sysrepo plugins.") + #TODO: Add to log + #print("Start sysrepo plugins.") #TODO: Need property close. err = open("/var/log/sysrepo-plugind", 'wb') if self.debug: @@ -94,25 +96,27 @@ class Topology: self.process.append(self.splugin) def _start_netopeer_server(self): - print("Start netopeer server.") + #TODO: Add to log + #print("Start netopeer server.") self.netopeer_server = subprocess.Popen("netopeer2-server", stdout=subprocess.PIPE) self.process.append(self.netopeer_server) def _start_netopeer_cli(self): - print("Start netopeer client.") + #TODO: Add to log + #print("Start netopeer client.") self.netopeer_cli = Netopeer_controler() self.process.append(self.netopeer_cli) self.netopeer_cli.spawn() def _start_vpp(self): - print("Start VPP.") + #print("Start VPP.") self.vpp = Vpp_controler(self.debug) self.vpp.spawn() self.process.append(self.vpp) def _start_netconfclient(self): - print("Start NetconfClient") + #print("Start NetconfClient") self.netconf_client = NetConfClient(address="127.0.0.1", username="root", password="0000") self.process.append(self.netconf_client) @@ -121,11 +125,9 @@ class Topology: return self.vpp def get_netopeer_cli(self): - #return self.netopeer_cli return self.netconf_client def create_topology(self, debug=False): - #try: self.debug = debug self._prepare_linux_enviroment() self._start_vpp() @@ -136,10 +138,7 @@ class Topology: #Wait for netopeer server time.sleep(1) - #self._start_netopeer_cli() self._start_netconfclient() - #except: - #self._kill_process() def close_topology(self): self._kill_process() diff --git a/test/vpp_controler.py b/test/vpp_controler.py index b29f00e..816ed4c 100644 --- a/test/vpp_controler.py +++ b/test/vpp_controler.py @@ -39,8 +39,12 @@ class Vpp_controler: if self.process is None: return - subprocess.run(self.ccmd + " create host name vpp1", shell=True) - subprocess.run(self.ccmd + " create host name vpp2", shell=True) + subprocess.run(self.ccmd + " create host name vpp1", shell=True, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + subprocess.run(self.ccmd + " create host name vpp2", shell=True, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) def spawn(self): self.process = subprocess.Popen([self.cmd, "-c", self.configuration], -- cgit 1.2.3-korg