summaryrefslogtreecommitdiffstats
path: root/vstf/vstf/controller/unittest
diff options
context:
space:
mode:
Diffstat (limited to 'vstf/vstf/controller/unittest')
-rwxr-xr-xvstf/vstf/controller/unittest/README49
-rwxr-xr-xvstf/vstf/controller/unittest/__init__.py14
-rwxr-xr-xvstf/vstf/controller/unittest/configuration.py17
-rwxr-xr-xvstf/vstf/controller/unittest/model.py27
-rwxr-xr-xvstf/vstf/controller/unittest/test_cfg_intent_parse.py32
-rwxr-xr-xvstf/vstf/controller/unittest/test_collect.py41
-rwxr-xr-xvstf/vstf/controller/unittest/test_driver_function.py27
-rwxr-xr-xvstf/vstf/controller/unittest/test_env_build.py55
-rwxr-xr-xvstf/vstf/controller/unittest/test_perf.py120
-rwxr-xr-xvstf/vstf/controller/unittest/test_ssh.py32
10 files changed, 414 insertions, 0 deletions
diff --git a/vstf/vstf/controller/unittest/README b/vstf/vstf/controller/unittest/README
new file mode 100755
index 00000000..f9414e95
--- /dev/null
+++ b/vstf/vstf/controller/unittest/README
@@ -0,0 +1,49 @@
+"""
+Created on 2015-9-28
+
+@author: y00228926
+"""
+
+the procedure to integrate a module unit testing into the unit testing framework:
+
+1.create your own unit test module, the name should start by 'test', for example, test_env.py
+
+2.create the test cases inside the module, inherit unittest.TestCase, for example:
+ class TestNetnsManager(unittest.TestCase):
+ def setUp(self): // preparing the testig
+ pass
+ def tearDown(self):// cleanup after testing
+ pass
+ def testCase1(self):// cases
+ pass
+
+3.single modules testing, appending below code at the end of the module, execute 'python test_env.py'.
+
+if __name__ == "__main__":
+ import logging
+ logging.getLogger(__name__)
+ logging.basicConfig(level = logging.DEBUG)
+ unittest.main()
+
+4.multiple modules integration, create run_test.py,run_test.py the example code as below:
+
+import unittest
+import importlib
+
+test_order_list = [
+ "vstf.services.agent.unittest.perf.test_utils",
+ "vstf.services.agent.unittest.perf.test_netns",
+ "vstf.services.agent.unittest.perf.test_netperf",
+ "vstf.services.agent.unittest.perf.test_qperf",
+ "vstf.services.agent.unittest.perf.test_pktgen",
+]
+
+if __name__ == '__main__':
+ import logging
+ logging.getLogger(__name__)
+ logging.basicConfig(level = logging.DEBUG)
+ for mod_name in test_order_list:
+ mod = importlib.import_module(mod_name)
+ suit = unittest.TestLoader().loadTestsFromModule(mod)
+ unittest.TextTestRunner().run(suit)
+
diff --git a/vstf/vstf/controller/unittest/__init__.py b/vstf/vstf/controller/unittest/__init__.py
new file mode 100755
index 00000000..89dcd4e2
--- /dev/null
+++ b/vstf/vstf/controller/unittest/__init__.py
@@ -0,0 +1,14 @@
+# Copyright Huawei Technologies Co., Ltd. 1998-2015.
+# 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.
diff --git a/vstf/vstf/controller/unittest/configuration.py b/vstf/vstf/controller/unittest/configuration.py
new file mode 100755
index 00000000..9364bbbf
--- /dev/null
+++ b/vstf/vstf/controller/unittest/configuration.py
@@ -0,0 +1,17 @@
+"""
+Created on 2015-9-24
+
+@author: y00228926
+"""
+
+rabbit_mq_server = '192.168.188.10'
+
+tester_host = '192.168.188.14'
+
+target_host = '192.168.188.16'
+
+source_repo = {
+ "passwd": "root",
+ "ip": "192.168.188.10",
+ "user": "root"
+} \ No newline at end of file
diff --git a/vstf/vstf/controller/unittest/model.py b/vstf/vstf/controller/unittest/model.py
new file mode 100755
index 00000000..c4e992ce
--- /dev/null
+++ b/vstf/vstf/controller/unittest/model.py
@@ -0,0 +1,27 @@
+"""
+Created on 2015-9-28
+
+@author: y00228926
+"""
+import unittest
+
+from vstf.rpc_frame_work import rpc_producer
+from vstf.controller.unittest import configuration
+
+
+class Test(unittest.TestCase):
+
+ def setUp(self):
+ self.controller = configuration.rabbit_mq_server
+ self.tester_host = configuration.tester_host
+ self.target_host = configuration.target_host
+ self.source_repo = configuration.source_repo
+ self.conn = rpc_producer.Server(self.controller)
+
+ def tearDown(self):
+ self.conn.close()
+
+
+if __name__ == "__main__":
+ #import sys;sys.argv = ['', 'Test.testName']
+ unittest.main() \ No newline at end of file
diff --git a/vstf/vstf/controller/unittest/test_cfg_intent_parse.py b/vstf/vstf/controller/unittest/test_cfg_intent_parse.py
new file mode 100755
index 00000000..665732aa
--- /dev/null
+++ b/vstf/vstf/controller/unittest/test_cfg_intent_parse.py
@@ -0,0 +1,32 @@
+"""
+Created on 2015-10-14
+
+@author: y00228926
+"""
+import os
+import unittest
+
+from vstf.controller.unittest import model
+from vstf.controller.env_build.cfg_intent_parse import IntentParser
+
+
+class Test(model.Test):
+ def setUp(self):
+ super(Test, self).setUp()
+ self.dir = os.path.dirname(__file__)
+
+ def tearDown(self):
+ super(Test, self).tearDown()
+
+ def test_parse_cfg_file(self):
+ for m in ['Ti', 'Tu', 'Tn', 'Tnv']:
+ filepath = os.path.join(self.dir, 'configuration/env/%s.json' % m)
+ parser = IntentParser(filepath)
+ parser.parse_cfg_file()
+
+
+if __name__ == "__main__":
+ import logging
+
+ logging.basicConfig(level=logging.INFO)
+ unittest.main() \ No newline at end of file
diff --git a/vstf/vstf/controller/unittest/test_collect.py b/vstf/vstf/controller/unittest/test_collect.py
new file mode 100755
index 00000000..f1d54a95
--- /dev/null
+++ b/vstf/vstf/controller/unittest/test_collect.py
@@ -0,0 +1,41 @@
+"""
+Created on 2015-9-28
+
+@author: y00228926
+"""
+import unittest
+import json
+
+from vstf.controller.env_build import env_collect
+from vstf.controller.unittest import model
+
+
+class TestCollect(model.Test):
+
+ def setUp(self):
+ super(TestCollect, self).setUp()
+ self.obj = env_collect.EnvCollectApi(self.conn)
+
+ def test_collect_host_info(self):
+ ret_str = json.dumps(self.obj.collect_host_info(self.tester_host), indent = 4)
+ for key in ("CPU INFO","MEMORY INFO","HW_INFO","OS INFO"):
+ self.assertTrue(key in ret_str, "collect_host_info failed, ret_str = %s" % ret_str)
+
+ def test_list_nic_devices(self):
+ ret_str = json.dumps(self.obj.list_nic_devices(self.tester_host), indent = 4)
+ for key in ("device","mac","bdf","desc"):
+ self.assertTrue(key in ret_str, "list_nic_devices failed, ret_str = %s" % ret_str)
+ print ret_str
+
+ def test_get_device_detail(self):
+ identity = "01:00.0"
+ ret = self.obj.get_device_detail(self.tester_host, "01:00.0")
+ for key in ("device","mac","bdf","desc"):
+ self.assertTrue(key in ret)
+ self.assertTrue(ret['bdf'] == identity)
+
+
+if __name__ == "__main__":
+ import logging
+ logging.basicConfig(level = logging.INFO)
+ unittest.main() \ No newline at end of file
diff --git a/vstf/vstf/controller/unittest/test_driver_function.py b/vstf/vstf/controller/unittest/test_driver_function.py
new file mode 100755
index 00000000..05804421
--- /dev/null
+++ b/vstf/vstf/controller/unittest/test_driver_function.py
@@ -0,0 +1,27 @@
+"""
+Created on 2015-10-27
+@author: l00190809
+"""
+import unittest
+import json
+
+from vstf.controller.functiontest.driver.drivertest import config_setup
+from vstf.controller.unittest import model
+
+
+class TestDriverFunction(model.Test):
+ def setUp(self):
+ logging.info("start driver function test unit test.")
+
+ def test_config_setup(self):
+ config ,_ = config_setup()
+ for key in ("test_scene","bond_flag","switch_module"):
+ self.assertTrue(key in config.keys(), "config_setup function failure.")
+
+ def teardown(self):
+ logging.info("stop driver function test unit test.")
+
+if __name__ == "__main__":
+ import logging
+ logging.basicConfig(level = logging.INFO)
+ unittest.main() \ No newline at end of file
diff --git a/vstf/vstf/controller/unittest/test_env_build.py b/vstf/vstf/controller/unittest/test_env_build.py
new file mode 100755
index 00000000..2d2d882b
--- /dev/null
+++ b/vstf/vstf/controller/unittest/test_env_build.py
@@ -0,0 +1,55 @@
+'''
+Created on 2015-9-28
+
+@author: y00228926
+'''
+import unittest
+import os
+
+from vstf.controller.unittest import model
+from vstf.controller.env_build import env_build
+
+
+class TestEnvBuilder(model.Test):
+ def setUp(self):
+ super(TestEnvBuilder, self).setUp()
+ self.dir = os.path.dirname(__file__)
+
+ @unittest.skip('for now')
+ def test_build_tn(self):
+ filepath = os.path.join(self.dir,'../../../etc/vstf/env/Tn.json')
+ self.mgr = env_build.EnvBuildApi(self.conn, filepath)
+ ret = self.mgr.build()
+ self.assertTrue(ret, "build_tn failed,ret = %s" % ret)
+
+ @unittest.skip('for now')
+ def test_build_tn1v(self):
+ filepath = os.path.join(self.dir,'../../../etc/vstf/env/Tnv.json')
+ self.mgr = env_build.EnvBuildApi(self.conn, filepath)
+ ret = self.mgr.build()
+ self.assertTrue(ret, "build_tn1v failed,ret = %s" % ret)
+
+ @unittest.skip('for now')
+ def test_build_ti(self):
+ filepath = os.path.join(self.dir,'../../../etc/vstf/env/Ti.json')
+ self.mgr = env_build.EnvBuildApi(self.conn, filepath)
+ ret = self.mgr.build()
+ self.assertTrue(ret, "build_ti failed,ret = %s" % ret)
+
+ @unittest.skip('for now')
+ def test_build_tu(self):
+ filepath = os.path.join(self.dir,'../../../etc/vstf/env/Tu.json')
+ self.mgr = env_build.EnvBuildApi(self.conn, filepath)
+ ret = self.mgr.build()
+ self.assertTrue(ret, "build_tu failed,ret = %s" % ret)
+
+ def test_build_tu_bridge(self):
+ filepath = os.path.join(self.dir,'../../../etc/vstf/env/Tu_br.json')
+ self.mgr = env_build.EnvBuildApi(self.conn, filepath)
+ ret = self.mgr.build()
+ self.assertTrue(ret, "build_tu failed,ret = %s" % ret)
+
+if __name__ == "__main__":
+ import logging
+ logging.basicConfig(level = logging.INFO)
+ unittest.main() \ No newline at end of file
diff --git a/vstf/vstf/controller/unittest/test_perf.py b/vstf/vstf/controller/unittest/test_perf.py
new file mode 100755
index 00000000..5a54b826
--- /dev/null
+++ b/vstf/vstf/controller/unittest/test_perf.py
@@ -0,0 +1,120 @@
+#!/usr/bin/python
+# -*- coding: utf8 -*-
+# author: wly
+# date: 2015-10-30
+# see license for license details
+
+import unittest
+import os
+import logging
+
+from vstf.controller.unittest import model
+from vstf.controller.settings.flows_settings import FlowsSettings
+from vstf.controller.settings.tool_settings import ToolSettings
+from vstf.controller.settings.perf_settings import PerfSettings
+from vstf.controller.sw_perf.perf_provider import PerfProvider
+from vstf.controller.sw_perf.flow_producer import FlowsProducer
+from vstf.controller.settings.tester_settings import TesterSettings
+from vstf.controller.env_build.env_build import EnvBuildApi as Builder
+from vstf.common.log import setup_logging
+import vstf.controller.sw_perf.performance as pf
+
+LOG = logging.getLogger(__name__)
+
+
+class TestPerf(model.Test):
+
+ def setUp(self):
+ LOG.info("start performance unit test.")
+ super(TestPerf, self).setUp()
+ self.dir = os.path.dirname(__file__)
+ self.perf_path = os.path.join(self.dir, '../../../etc/vstf/perf')
+ self.base_path = os.path.join(self.dir, '../../../etc/vstf/env')
+
+ def teardown(self):
+ LOG.info("stop performance unit test.")
+
+ @unittest.skip('for now')
+ def test_batch_perf(self):
+
+ LOG.info(self.perf_path)
+ LOG.info(self.base_path)
+ perf_settings = PerfSettings(path=self.perf_path)
+ flows_settings = FlowsSettings(path=self.perf_path)
+ tool_settings = ToolSettings(path=self.base_path)
+ tester_settings = TesterSettings(path=self.base_path)
+ flow_producer = FlowsProducer(self.conn, flows_settings)
+ provider = PerfProvider(flows_settings.settings, tool_settings.settings, tester_settings.settings)
+ perf = pf.Performance(self.conn, provider)
+ tests = perf_settings.settings
+ for scenario, cases in tests.items():
+ if not cases:
+ continue
+
+ config_file = os.path.join(self.base_path, scenario + '.json')
+
+ LOG.info(config_file)
+
+ env = Builder(self.conn, config_file)
+ env.build()
+
+ for case in cases:
+ casetag = case['case']
+ tool = case['tool']
+ protocol = case['protocol']
+ profile = case['profile']
+ ttype = case['type']
+ sizes = case['sizes']
+
+ flow_producer.create(scenario, casetag)
+ result = perf.run(tool, protocol, ttype, sizes)
+ self.assertEqual(True, isinstance(result, dict))
+ LOG.info(result)
+
+ @unittest.skip('for now')
+ def test_perf_settings(self):
+ perf_settings = PerfSettings()
+ self.assertEqual(True, perf_settings.input())
+
+ def test_tool_settings(self):
+ tool_settings = ToolSettings()
+ value = {
+ "time": 20,
+ "threads": 1
+ }
+ tool_settings.set_pktgen(value)
+ tool_settings.set_netperf(value)
+ tool_settings.set_iperf(value)
+ tool_settings.set_qperf(value)
+ LOG.info(tool_settings.settings)
+
+ def test_flow_settings(self):
+ tests = {
+ "Tn": ["Tn-1", "Tn-2", "Tn-3", "Tn-4"],
+ "Tnv": ["Tnv-1", "Tnv-2", "Tnv-3", "Tnv-4"],
+ "Ti": ["Ti-1", "Ti-2", "Ti-3", "Ti-4", "Ti-5", "Ti-6"],
+ "Tu": ["Tu-1", "Tu-2", "Tu-3", "Tu-4", "Tu-5", "Tu-6"]
+ }
+ flows_settings = FlowsSettings(path=self.perf_path)
+ flow_producer = FlowsProducer(self.conn, flows_settings)
+
+ for scenario, cases in tests.items():
+ if not cases:
+ continue
+
+ config_file = os.path.join(self.base_path, scenario + '.json')
+
+ LOG.info(config_file)
+
+ env = Builder(self.conn, config_file)
+ env.build()
+
+ for case in cases:
+ LOG.info(case)
+ flow_producer.create(scenario, case)
+ LOG.info(flows_settings.settings)
+
+
+if __name__ == "__main__":
+ setup_logging(level=logging.INFO, log_file="/var/log/vstf/vstf-unit-test.log", clevel=logging.INFO)
+ unittest.main() \ No newline at end of file
diff --git a/vstf/vstf/controller/unittest/test_ssh.py b/vstf/vstf/controller/unittest/test_ssh.py
new file mode 100755
index 00000000..844f8ff5
--- /dev/null
+++ b/vstf/vstf/controller/unittest/test_ssh.py
@@ -0,0 +1,32 @@
+"""
+Created on 2015-10-10
+
+@author: y00228926
+"""
+import unittest
+
+from vstf.common import ssh
+from vstf.controller.unittest import model
+
+
+class Test(model.Test):
+
+ def setUp(self):
+ super(Test, self).setUp()
+ self.host = self.source_repo["ip"]
+ self.user = self.source_repo["user"]
+ self.passwd = self.source_repo["passwd"]
+
+
+ def tearDown(self):
+ super(Test, self).tearDown()
+
+
+ def test_run_cmd(self):
+ ssh.run_cmd(self.host, self.user, self.passwd, 'ls')
+
+
+if __name__ == "__main__":
+ import logging
+ logging.basicConfig(level = logging.INFO)
+ unittest.main() \ No newline at end of file