summaryrefslogtreecommitdiffstats
path: root/vstf/vstf/agent/unittest/env
diff options
context:
space:
mode:
Diffstat (limited to 'vstf/vstf/agent/unittest/env')
-rwxr-xr-xvstf/vstf/agent/unittest/env/Readme13
-rwxr-xr-xvstf/vstf/agent/unittest/env/__init__.py14
-rwxr-xr-xvstf/vstf/agent/unittest/env/configuration/Ti.json58
-rwxr-xr-xvstf/vstf/agent/unittest/env/configuration/Tn-ovs.json36
-rwxr-xr-xvstf/vstf/agent/unittest/env/configuration/Tn.json37
-rwxr-xr-xvstf/vstf/agent/unittest/env/configuration/Tn1v.json85
-rwxr-xr-xvstf/vstf/agent/unittest/env/configuration/Tu.json71
-rwxr-xr-xvstf/vstf/agent/unittest/env/model.py24
-rwxr-xr-xvstf/vstf/agent/unittest/env/run_test.py33
-rwxr-xr-xvstf/vstf/agent/unittest/env/test_bridge_plugin.py56
-rwxr-xr-xvstf/vstf/agent/unittest/env/test_builder.py74
-rwxr-xr-xvstf/vstf/agent/unittest/env/test_devicemanager.py38
-rwxr-xr-xvstf/vstf/agent/unittest/env/test_drivermanager.py50
-rwxr-xr-xvstf/vstf/agent/unittest/env/test_origin_driver.py44
-rwxr-xr-xvstf/vstf/agent/unittest/env/test_sourcemanager.py53
-rwxr-xr-xvstf/vstf/agent/unittest/env/test_vm9pfs.py71
-rwxr-xr-xvstf/vstf/agent/unittest/env/test_vm_manager.py69
-rwxr-xr-xvstf/vstf/agent/unittest/env/test_vs_plugin_manager.py68
18 files changed, 894 insertions, 0 deletions
diff --git a/vstf/vstf/agent/unittest/env/Readme b/vstf/vstf/agent/unittest/env/Readme
new file mode 100755
index 00000000..eb2a78d5
--- /dev/null
+++ b/vstf/vstf/agent/unittest/env/Readme
@@ -0,0 +1,13 @@
+To enable Env unittest, please make sure:
+
+ 1. br0 exists on TargetHost and connects with 'management network'.
+ 2. a vm image exists on Target Host.
+ 3. change options in configuration files in the "configuration" directory.
+ 4. copy public key to git server, for example:
+ ssh-copy-id root@192.168.188.10
+ note:
+ 192.168.188.10 is the server you config in "../configuration.py"
+ this is needed for source manager which use 'git' to pull down sources.
+
+run tests:
+ python run_test.py \ No newline at end of file
diff --git a/vstf/vstf/agent/unittest/env/__init__.py b/vstf/vstf/agent/unittest/env/__init__.py
new file mode 100755
index 00000000..89dcd4e2
--- /dev/null
+++ b/vstf/vstf/agent/unittest/env/__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/agent/unittest/env/configuration/Ti.json b/vstf/vstf/agent/unittest/env/configuration/Ti.json
new file mode 100755
index 00000000..89236612
--- /dev/null
+++ b/vstf/vstf/agent/unittest/env/configuration/Ti.json
@@ -0,0 +1,58 @@
+{
+ "scenario": "ti",
+ "env-build": [
+ {
+ "ip": "192.168.188.16",
+ "drivers": [
+ "ixgbe",
+ "vhost_net"
+ ],
+ "vms": [
+ {
+ "vm_cpu": 3,
+ "vm_name": "test1",
+ "vm_memory": 4194304,
+ "image_path": "/mnt/sdb/test1.qcow2",
+ "image_type": "qcow2",
+ "init_config": {
+ "amqp_server": "192.168.188.10",
+ "ctrl_ip_setting": "192.168.188.200/23",
+ "ctrl_gw": "192.168.188.1"
+ },
+ "taps":[
+ {
+ "tap_name": "tap_in",
+ "br_type": "ovs",
+ "br_name": "ovs1",
+ "tap_mac": "56:6f:44:a5:3f:a2",
+ "vlan_mode": "access",
+ "vlan_id": "100"
+ }
+ ],
+ "ctrl_mac": "16:6f:44:a5:3f:a2",
+ "ctrl_br": "br0"
+ }
+ ],
+ "bridges": [
+ {
+ "type": "ovs",
+ "name": "ovs1",
+ "uplinks": [
+ {
+ "bdf": "04:00.0",
+ "vlan_mode": "trunk",
+ "vlan_id": "100,200,300,400"
+ }
+ ],
+ "vtep":{},
+ "fastlink":[
+ {
+ "inport":"04: 00.0",
+ "outport":"tap_in"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+} \ No newline at end of file
diff --git a/vstf/vstf/agent/unittest/env/configuration/Tn-ovs.json b/vstf/vstf/agent/unittest/env/configuration/Tn-ovs.json
new file mode 100755
index 00000000..73be1611
--- /dev/null
+++ b/vstf/vstf/agent/unittest/env/configuration/Tn-ovs.json
@@ -0,0 +1,36 @@
+{
+ "env-build": [
+ {
+ "ip": "192.168.188.16",
+ "drivers": [
+ "ixgbe"
+ ],
+ "bridges": [
+ {
+ "type": "ovs",
+ "name": "ovs1",
+ "uplinks": [
+ {
+ "bdf": "04:00.0",
+ "vlan_mode": "trunk",
+ "vlan_id": "1,100,200"
+ },
+ {
+ "bdf": "04:00.1",
+ "vlan_mode": "trunk",
+ "vlan_id": "1,100,200"
+ }
+ ],
+ "vtep": {},
+ "fastlink": [
+ {
+ "inport": "04: 00.0",
+ "outport": "04: 00.1"
+ }
+ ]
+ }
+ ],
+ "vms": []
+ }
+ ]
+}
diff --git a/vstf/vstf/agent/unittest/env/configuration/Tn.json b/vstf/vstf/agent/unittest/env/configuration/Tn.json
new file mode 100755
index 00000000..04c160da
--- /dev/null
+++ b/vstf/vstf/agent/unittest/env/configuration/Tn.json
@@ -0,0 +1,37 @@
+{
+ "scenario": "tn",
+ "env-build": [
+ {
+ "ip": "192.168.188.16",
+ "drivers": [
+ "ixgbe"
+ ],
+ "vms": [],
+ "bridges": [
+ {
+ "type": "ovs",
+ "name": "ovs1",
+ "uplinks": [
+ {
+ "bdf": "04:00.0",
+ "vlan_mode": "trunk",
+ "vlan_id": "1,100,200"
+ },
+ {
+ "bdf": "04:00.1",
+ "vlan_mode": "trunk",
+ "vlan_id": "1,100,200"
+ }
+ ],
+ "vtep": {},
+ "fastlink": [
+ {
+ "inport": "04:00.0",
+ "outport": "04:00.1"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+} \ No newline at end of file
diff --git a/vstf/vstf/agent/unittest/env/configuration/Tn1v.json b/vstf/vstf/agent/unittest/env/configuration/Tn1v.json
new file mode 100755
index 00000000..5a25efda
--- /dev/null
+++ b/vstf/vstf/agent/unittest/env/configuration/Tn1v.json
@@ -0,0 +1,85 @@
+{
+ "scenario": "tnv",
+ "env-build": [
+ {
+ "ip": "192.168.188.16",
+ "drivers": [
+ "ixgbe",
+ "tap_vhost"
+ ],
+ "vms": [
+ {
+ "vm_cpu": 3,
+ "vm_name": "test1",
+ "vm_memory": 4194304,
+ "image_path": "/mnt/sdb/test1.qcow2",
+ "image_type": "qcow2",
+ "init_config": {
+ "amqp_server": "192.168.188.10",
+ "ctrl_ip_setting": "192.168.188.200/23",
+ "tap_pktloop_config": "dpdk",
+ "ctrl_gw": "192.168.188.1"
+ },
+ "taps": [
+ {
+ "tap_name": "tap_in",
+ "br_type": "ovs",
+ "br_name": "ovs1",
+ "tap_mac": "56:6f:44:a5:3f:a2",
+ "vlan_mode": "access",
+ "vlan_id": "100"
+ },
+ {
+ "tap_name": "tap_out",
+ "br_type": "ovs",
+ "br_name": "ovs22",
+ "tap_mac": "56:6f:44:a5:3f:a3",
+ "vlan_mode": "access",
+ "vlan_id": "200"
+ }
+ ],
+ "ctrl_mac": "16:6f:44:a5:3f:a2",
+ "ctrl_br": "br0"
+ }
+ ],
+ "bridges": [
+ {
+ "type": "ovs",
+ "name": "ovs1",
+ "uplinks": [
+ {
+ "bdf": "04: 00.0",
+ "vlan_mode": "trunk",
+ "vlan_id": "100"
+ }
+ ],
+ "vtep":{},
+ "fastlink":[
+ {
+ "inport":"04: 00.0",
+ "outport":"tap_in"
+ }
+ ]
+ },
+ {
+ "type": "ovs",
+ "name": "ovs2",
+ "uplinks": [
+ {
+ "bdf": "04: 00.1",
+ "vlan_mode": "trunk",
+ "vlan_id": "200"
+ }
+ ],
+ "vtep":{},
+ "fastlink":[
+ {
+ "inport":"04: 00.1",
+ "outport":"tap_out"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+} \ No newline at end of file
diff --git a/vstf/vstf/agent/unittest/env/configuration/Tu.json b/vstf/vstf/agent/unittest/env/configuration/Tu.json
new file mode 100755
index 00000000..15a508c0
--- /dev/null
+++ b/vstf/vstf/agent/unittest/env/configuration/Tu.json
@@ -0,0 +1,71 @@
+{
+ "scenario": "tu",
+ "env-build": [
+ {
+ "ip": "192.168.188.16",
+ "drivers": [
+ "tap_vhost"
+ ],
+ "vms": [
+ {
+ "vm_cpu": 3,
+ "vm_name": "test1",
+ "vm_memory": 4194304,
+ "image_path": "/mnt/sdb/test1.qcow2",
+ "image_type": "qcow2",
+ "init_config": {
+ "amqp_server": "192.168.188.10",
+ "ctrl_ip_setting": "192.168.188.200/23",
+ "ctrl_gw": "192.168.188.1"
+ },
+ "taps": [
+ {
+ "tap_name": "tap1",
+ "br_type": "ovs",
+ "br_name": "ovs1",
+ "tap_mac": "56:6f:44:a5:3f:a2",
+ "vlan_mode": "access",
+ "vlan_id": "100"
+ }
+ ]
+ },
+ {
+ "vm_cpu": 3,
+ "vm_name": "test2",
+ "vm_memory": 4194304,
+ "image_path": "/mnt/sdb/test2.qcow2",
+ "image_type": "qcow2",
+ "init_config": {
+ "amqp_server": "192.168.188.10",
+ "ctrl_ip_setting": "192.168.188.201/23",
+ "ctrl_gw": "192.168.188.1"
+ },
+ "taps": [
+ {
+ "tap_name": "tap2",
+ "br_type": "ovs",
+ "br_name": "ovs1",
+ "tap_mac": "56:6f:44:a5:3f:a3",
+ "vlan_mode": "access",
+ "vlan_id": "100"
+ }
+ ]
+ }
+ ],
+ "bridges": [
+ {
+ "type": "ovs",
+ "name": "ovs1",
+ "uplinks": [],
+ "vtep": {},
+ "fastlink": [
+ {
+ "inport": "tap1",
+ "outport": "tap2"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+} \ No newline at end of file
diff --git a/vstf/vstf/agent/unittest/env/model.py b/vstf/vstf/agent/unittest/env/model.py
new file mode 100755
index 00000000..e3c2bca6
--- /dev/null
+++ b/vstf/vstf/agent/unittest/env/model.py
@@ -0,0 +1,24 @@
+"""
+Created on 2015-10-9
+
+@author: y00228926
+"""
+import unittest
+
+from vstf.agent.unittest import configuration
+
+
+class Test(unittest.TestCase):
+ def setUp(self):
+ self.eth_for_test = configuration.eth_for_test
+ self.mac_of_eth = configuration.mac_of_eth
+ self.source_repo = configuration.source_repo
+ self.bdf_of_eth = configuration.bdf_of_eth
+
+ def tearDown(self):
+ pass
+
+
+if __name__ == "__main__":
+ # import sys;sys.argv = ['', 'Test.testName']
+ unittest.main()
diff --git a/vstf/vstf/agent/unittest/env/run_test.py b/vstf/vstf/agent/unittest/env/run_test.py
new file mode 100755
index 00000000..0f630c7d
--- /dev/null
+++ b/vstf/vstf/agent/unittest/env/run_test.py
@@ -0,0 +1,33 @@
+"""
+Created on 2015-9-24
+
+@author: y00228926
+"""
+import unittest
+import importlib
+
+test_order_list = [
+ "vstf.agent.unittest.env.test_origin_driver",
+ "vstf.agent.unittest.env.test_bridge_plugin",
+ "vstf.agent.unittest.env.test_drivermanager",
+ "vstf.agent.unittest.env.test_devicemanager",
+ "vstf.agent.unittest.env.test_vs_plugin_manager",
+ "vstf.agent.unittest.env.test_builder",
+ "vstf.agent.unittest.env.test_sourcemanager",
+]
+
+
+def main():
+ import logging
+ logging.getLogger(__name__)
+ logging.basicConfig(level=logging.INFO)
+ suite = unittest.TestSuite()
+ for mod_name in test_order_list:
+ mod = importlib.import_module(mod_name)
+ suit = unittest.TestLoader().loadTestsFromModule(mod)
+ suite.addTest(suit)
+ unittest.TextTestRunner().run(suite)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/vstf/vstf/agent/unittest/env/test_bridge_plugin.py b/vstf/vstf/agent/unittest/env/test_bridge_plugin.py
new file mode 100755
index 00000000..ac4eb268
--- /dev/null
+++ b/vstf/vstf/agent/unittest/env/test_bridge_plugin.py
@@ -0,0 +1,56 @@
+"""
+Created on 2015-10-12
+
+@author: y00228926
+"""
+import unittest
+
+from vstf.common.utils import check_call
+from vstf.agent.unittest.env import model
+from vstf.agent.env.vswitch_plugins import bridge_plugin
+from vstf.agent.env.driver_plugins import manager
+
+
+class Test(model.Test):
+ def setUp(self):
+ super(Test, self).setUp()
+ self.plugin = bridge_plugin.BridgePlugin()
+ self.dr_mgr = manager.DriverPluginManager()
+ self.br_cfg = {
+ "name": "br1",
+ "uplinks": [
+ {
+ "bdf": self.bdf_of_eth[0],
+ },
+ {
+ "bdf": self.bdf_of_eth[1],
+ }
+ ]
+ }
+ self.dr_mgr.clean()
+ self.dr_mgr.load(['ixgbe'])
+
+ def tearDown(self):
+ super(Test, self).tearDown()
+
+ def _check_br_exists(self, name):
+ try:
+ check_call('ifconfig %s' % name, shell=True)
+ except Exception, e:
+ return False
+ return True
+
+ def test_create_br(self):
+ self.plugin.clean()
+ self.plugin.create_br(self.br_cfg)
+ self.assertTrue(self._check_br_exists(self.br_cfg['name']))
+ self.plugin.clean()
+ self.assertFalse(self._check_br_exists(self.br_cfg['name']))
+
+
+if __name__ == "__main__":
+ import logging
+
+ logging.basicConfig(level=logging.INFO)
+ LOG = logging.getLogger(__name__)
+ unittest.main()
diff --git a/vstf/vstf/agent/unittest/env/test_builder.py b/vstf/vstf/agent/unittest/env/test_builder.py
new file mode 100755
index 00000000..fd2d4382
--- /dev/null
+++ b/vstf/vstf/agent/unittest/env/test_builder.py
@@ -0,0 +1,74 @@
+"""
+Created on 2015-9-24
+
+@author: y00228926
+"""
+import unittest
+import os
+
+from vstf.controller.env_build.cfg_intent_parse import IntentParser
+from vstf.agent.env import builder
+
+
+class Test(unittest.TestCase):
+ def setUp(self):
+ self.mgr = builder.PluginManager()
+ self.dir = os.path.dirname(__file__)
+
+ def tearDown(self):
+ self.mgr.clean()
+
+ def __build(self, filepath, drivers=None):
+ parser = IntentParser(filepath)
+ cfg_intent = parser.parse_cfg_file()
+ host_cfg = cfg_intent['env-build'][0]
+ print filepath
+ print host_cfg
+ host_cfg["src-install"] = {}
+ if drivers:
+ host_cfg['drivers'] = drivers
+ return self.mgr.build(host_cfg)
+
+ def test_build_tn_using_origin_driver(self):
+ ret = self.__build(os.path.join(self.dir, 'configuration/Tn.json'), drivers=['ixgbe'])
+ self.assertTrue(ret, "test_build_tn_using_origin_driver failed, ret = %s" % ret)
+
+ def test_build_tn1v_using_origin_driver(self):
+ ret = self.__build(os.path.join(self.dir, 'configuration/Tn1v.json'), drivers=['ixgbe', 'vhost_net'])
+ self.assertTrue(ret, "test_build_tn1v_using_origin_driver failed, ret = %s" % ret)
+
+ def test_build_ti_using_origin_driver(self):
+ ret = self.__build(os.path.join(self.dir, 'configuration/Ti.json'), drivers=['ixgbe', 'vhost_net'])
+ self.assertTrue(ret, "test_build_ti_using_origin_driver failed, ret = %s" % ret)
+
+ def test_build_tu_using_origin_driver(self):
+ ret = self.__build(os.path.join(self.dir, 'configuration/Tu.json'), drivers=['vhost_net'])
+ self.assertTrue(ret, "test_build_ti_using_origin_driver failed, ret = %s" % ret)
+
+ @unittest.skip('can be tested by tn1v')
+ def test_build_tn(self):
+ ret = self.__build(os.path.join(self.dir, 'configuration/Tn.json'))
+ self.assertTrue(ret, "test_build_tn failed, ret = %s" % ret)
+
+ @unittest.skip('can be tested by tn1v')
+ def test_build_tn1v(self):
+ ret = self.__build(os.path.join(self.dir, 'configuration/Tn1v.json'))
+ self.assertTrue(ret, "test_build_tn failed,ret = %s" % ret)
+
+ @unittest.skip('can be tested by tn1v')
+ def test_build_ti(self):
+ ret = self.__build(os.path.join(self.dir, 'configuration/Ti.json'))
+ self.assertTrue(ret, "test_build_tn failed, ret = %s" % ret)
+
+ @unittest.skip('can be tested by tn1v')
+ def test_build_tu(self):
+ ret = self.__build(os.path.join(self.dir, 'configuration/Tu.json'))
+ self.assertTrue(ret, "test_build_tn failed, ret = %s" % ret)
+
+
+if __name__ == "__main__":
+ import logging
+
+ LOG = logging.getLogger(__name__)
+ logging.basicConfig(level=logging.DEBUG)
+ unittest.main()
diff --git a/vstf/vstf/agent/unittest/env/test_devicemanager.py b/vstf/vstf/agent/unittest/env/test_devicemanager.py
new file mode 100755
index 00000000..7e5bc3b1
--- /dev/null
+++ b/vstf/vstf/agent/unittest/env/test_devicemanager.py
@@ -0,0 +1,38 @@
+"""
+Created on 2015-9-25
+
+@author: y00228926
+"""
+import unittest
+
+from vstf.agent.unittest.env import model
+from vstf.agent.env.basic.device_manager import DeviceManager
+
+
+class Test(model.Test):
+ def setUp(self):
+ super(Test, self).setUp()
+ self.dm = DeviceManager()
+ self.device_list = self.dm.list_nic_devices()
+ self.device_detail = self.device_list[0]
+
+ def tearDown(self):
+ super(Test, self).tearDown()
+
+ def test_get_device_detail(self):
+ detail1 = self.dm.get_device_detail(self.device_detail['bdf'])
+ detail2 = self.dm.get_device_detail(self.device_detail['mac'])
+ detail3 = self.dm.get_device_detail(self.device_detail['device'])
+ self.assertTrue(detail1 == detail2 == detail3 == self.device_detail)
+
+ def test_list_nic_devices(self):
+ import json
+ print json.dumps(self.device_list, indent=4)
+
+
+if __name__ == "__main__":
+ import logging
+
+ logging.basicConfig(level=logging.INFO)
+ LOG = logging.getLogger(__name__)
+ unittest.main()
diff --git a/vstf/vstf/agent/unittest/env/test_drivermanager.py b/vstf/vstf/agent/unittest/env/test_drivermanager.py
new file mode 100755
index 00000000..df6ad5df
--- /dev/null
+++ b/vstf/vstf/agent/unittest/env/test_drivermanager.py
@@ -0,0 +1,50 @@
+"""
+Created on 2015-10-9
+
+@author: y00228926
+"""
+import unittest
+
+from vstf.common.utils import check_output
+from vstf.agent.unittest.env import model
+from vstf.agent.env.driver_plugins import manager
+
+
+class Test(model.Test):
+ def setUp(self):
+ super(Test, self).setUp()
+ self.driver_mgr = manager.DriverPluginManager()
+
+ def tearDown(self):
+ super(Test, self).tearDown()
+
+ def _driver_exists(self, drivers=[]):
+ all_drivers = check_output("lsmod | awk '{print $1}'", shell=True).split()
+ for mod in drivers:
+ if mod not in all_drivers:
+ return False
+ return True
+
+ def test_load(self):
+ self.driver_mgr.clean()
+ for _, drivers in self.driver_mgr.get_all_supported_drivers().items():
+ self.assertFalse(self._driver_exists(drivers))
+
+
+ self.driver_mgr.load(['ixgbe', 'vhost_net'])
+ self.assertTrue(self._driver_exists(['ixgbe', 'vhost_net']))
+
+ self.driver_mgr.clean()
+ self.assertFalse(self._driver_exists(['ixgbe', 'vhost_net']))
+
+ def test_load_unsuported_pair(self):
+ with self.assertRaises(Exception):
+ self.driver_mgr.load(['ixgbe', 'tap_vhost'])
+
+
+if __name__ == "__main__":
+ import logging
+
+ logging.basicConfig(level=logging.INFO)
+ LOG = logging.getLogger(__name__)
+ unittest.main()
diff --git a/vstf/vstf/agent/unittest/env/test_origin_driver.py b/vstf/vstf/agent/unittest/env/test_origin_driver.py
new file mode 100755
index 00000000..8daa481f
--- /dev/null
+++ b/vstf/vstf/agent/unittest/env/test_origin_driver.py
@@ -0,0 +1,44 @@
+"""
+Created on 2015-10-9
+
+@author: y00228926
+"""
+import unittest
+
+from vstf.common.utils import check_output
+from vstf.agent.unittest.env import model
+from vstf.agent.env.driver_plugins import origin_driver
+
+
+class Test(model.Test):
+
+ def setUp(self):
+ super(Test, self).setUp()
+ self.driver_mgr = origin_driver.OriginDriverPlugin()
+
+ def tearDown(self):
+ super(Test, self).tearDown()
+
+ def _driver_exists(self, drivers=[]):
+ all_drivers = check_output("lsmod | awk '{print $1}'",shell = True).split()
+ for mod in drivers:
+ if mod not in all_drivers:
+ return False
+ return True
+
+ def test_load(self):
+ self.driver_mgr.clean()
+ self.assertFalse(self._driver_exists(self.driver_mgr.get_supported_drivers()))
+
+ self.driver_mgr.load(['ixgbe','vhost_net'])
+ self.assertTrue(self._driver_exists(['ixgbe','vhost_net']))
+
+ self.driver_mgr.clean()
+ self.assertFalse(self._driver_exists(self.driver_mgr.get_supported_drivers()))
+
+
+if __name__ == "__main__":
+ import logging
+ logging.basicConfig(level = logging.INFO)
+ LOG = logging.getLogger(__name__)
+ unittest.main() \ No newline at end of file
diff --git a/vstf/vstf/agent/unittest/env/test_sourcemanager.py b/vstf/vstf/agent/unittest/env/test_sourcemanager.py
new file mode 100755
index 00000000..fda567d8
--- /dev/null
+++ b/vstf/vstf/agent/unittest/env/test_sourcemanager.py
@@ -0,0 +1,53 @@
+"""
+Created on 2015-10-9
+
+@author: y00228926
+"""
+import unittest
+import shutil
+import time
+import os
+
+from vstf.agent.env.basic.source_manager import SourceCodeManager
+from vstf.agent.unittest.env import model
+
+
+class TestSourceManager(model.Test):
+ def setUp(self):
+ super(TestSourceManager, self).setUp()
+ self.sm = SourceCodeManager()
+ self.dest_path = '/tmp/test_source_manager'
+ os.mkdir(self.dest_path)
+
+ def tearDown(self):
+ shutil.rmtree(self.dest_path, ignore_errors = True)
+
+ def _time(self,func):
+ def _deco(*args):
+ start_time = time.time()
+ func(*args)
+ end_time = time.time()
+ return end_time - start_time
+ return _deco
+
+ def test_download_source_code(self):
+ for key, item in self.source_repo.items():
+ print self.source_repo
+ url = item['url']
+ target = os.path.join(self.dest_path, key)
+ install = item['install']
+ if install:
+ self.sm._git_pull(url, target)
+ self.assertTrue(os.path.isdir(target))
+ my_download = self._time(self.sm._git_pull)
+ t = my_download(url, target)
+ self.assertTrue(t < 1.0)
+ else:
+ self.assertFalse(os.path.isdir(target))
+
+
+if __name__ == "__main__":
+ import logging
+ logging.basicConfig(level = logging.INFO)
+ LOG = logging.getLogger(__name__)
+ unittest.main() \ No newline at end of file
diff --git a/vstf/vstf/agent/unittest/env/test_vm9pfs.py b/vstf/vstf/agent/unittest/env/test_vm9pfs.py
new file mode 100755
index 00000000..4f520133
--- /dev/null
+++ b/vstf/vstf/agent/unittest/env/test_vm9pfs.py
@@ -0,0 +1,71 @@
+"""
+Created on 2015-9-24
+
+@author: y00228926
+"""
+import unittest
+
+from vstf.agent.unittest.env import model
+from vstf.agent.env.basic.vm9pfs import VMConfigBy9pfs
+from vstf.agent.env.basic.vm_manager import VMControlOperation
+
+
+class TestVM9pfs(model.Test):
+ def setUp(self):
+ super(TestVM9pfs, self).setUp()
+ self.vm_config = {
+ 'vm_name': 'vm1',
+ 'vm_cpu': 5,
+ 'image_path': "/mnt/sdb/ubuntu_salt_master.img",
+ 'child_dir': '/mnt/sdb/',
+ 'image_type': 'qcow2',
+ 'ctrl_br': 'br0',
+ 'ctrl_mac': '56:6f:44:a5:3f:a4',
+ "taps": [
+ {
+ "tap_name": "tap_in",
+ "br_type": "bridge",
+ "br_name": "br0",
+ "tap_mac": "56:6f:44:a5:3f:a2",
+ },
+ {
+ "tap_name": "tap_out",
+ "br_type": "bridge",
+ "br_name": "br0",
+ "tap_mac": "56:6f:44:a5:3f:a3",
+ }
+ ],
+ 'init_config': {}
+ }
+ self.init_config = {
+ 'amqp_server': '192.168.188.10',
+ 'ctrl_ip_setting': '192.168.188.200/23',
+ 'tap_pktloop_config': 'dpdk',
+ 'ctrl_gw': '192.168.188.1'
+ }
+ self.mgr = VMControlOperation()
+ self.mgr.clean_all_vms()
+ self.mgr.create_vm(self.vm_config)
+ self.mgr.wait_vm(self.vm_config["vm_name"])
+ self.vm9pctrl = self.mgr.vm_9p_controllers[self.vm_config["vm_name"]]
+
+ def tearDown(self):
+ self.mgr.clean_all_vms()
+ super(TestVM9pfs, self).tearDown()
+
+ def test_init_config(self):
+ ret = self.vm9pctrl.config_ip(self.vm_config['ctrl_mac'], self.init_config['ctrl_ip_setting'])
+ self.assertTrue(ret)
+ ret = self.vm9pctrl.config_gw(self.init_config['ctrl_gw'])
+ self.assertTrue(ret)
+ ret = self.vm9pctrl.set_pktloop_dpdk([self.vm_config['taps'][0]['tap_mac'], self.vm_config['taps'][1]['tap_mac']])
+ self.assertTrue(ret)
+ ret = self.vm9pctrl.config_amqp(self.init_config['ctrl_ip_setting'].split('/')[0], self.init_config['amqp_server'])
+ self.assertTrue(ret)
+
+
+if __name__ == "__main__":
+ import logging
+ logging.basicConfig(level=logging.INFO)
+ LOG = logging.getLogger(__name__)
+ unittest.main()
diff --git a/vstf/vstf/agent/unittest/env/test_vm_manager.py b/vstf/vstf/agent/unittest/env/test_vm_manager.py
new file mode 100755
index 00000000..3c3deacc
--- /dev/null
+++ b/vstf/vstf/agent/unittest/env/test_vm_manager.py
@@ -0,0 +1,69 @@
+"""
+Created on 2015-9-24
+
+@author: y00228926
+"""
+import unittest
+
+from vstf.agent.unittest.env import model
+from vstf.agent.env.basic.vm9pfs import VMConfigBy9pfs
+from vstf.agent.env.basic.vm_manager import VMControlOperation
+
+
+class TestVM9pfs(model.Test):
+ def setUp(self):
+ super(TestVM9pfs, self).setUp()
+ self.vm_config = {
+ 'vm_name': 'vm1',
+ 'vm_cpu': 5,
+ 'image_path': "/mnt/sdb/ubuntu_salt_master.img",
+ 'child_dir': '/mnt/sdb/',
+ 'image_type': 'qcow2',
+ 'ctrl_br': 'br0',
+ 'ctrl_mac': '56:6f:44:a5:3f:a4',
+ "taps": [
+ {
+ "tap_name": "tap_in",
+ "br_type": "bridge",
+ "br_name": "br0",
+ "tap_mac": "56:6f:44:a5:3f:a2",
+ },
+ {
+ "tap_name": "tap_out",
+ "br_type": "bridge",
+ "br_name": "br0",
+ "tap_mac": "56:6f:44:a5:3f:a3",
+ }
+ ],
+ 'init_config': {
+ "amqp_passwd": "guest",
+ "amqp_user": "guest",
+ "amqp_server": "192.168.188.10",
+ "amqp_port": 5672,
+ 'ctrl_ip_setting': '192.168.188.200/23',
+ 'tap_pktloop_config': 'dpdk',
+ 'ctrl_gw': '192.168.188.1'
+ }
+ }
+ self.mgr = VMControlOperation()
+ self.mgr.clean_all_vms()
+
+ def tearDown(self):
+ self.mgr.clean_all_vms()
+ super(TestVM9pfs, self).tearDown()
+
+ def test_create_vm_bridge(self):
+ self.mgr.create_vm(self.vm_config)
+ self.mgr.wait_vm(self.vm_config["vm_name"])
+ self.mgr.init_config_vm(self.vm_config["vm_name"])
+
+ def _replace_opts(self, cfg, br_type):
+ for tap_cfg in cfg["taps"]:
+ tap_cfg["br_type"] = br_type
+
+
+if __name__ == "__main__":
+ import logging
+ logging.basicConfig(level=logging.INFO)
+ LOG = logging.getLogger(__name__)
+ unittest.main()
diff --git a/vstf/vstf/agent/unittest/env/test_vs_plugin_manager.py b/vstf/vstf/agent/unittest/env/test_vs_plugin_manager.py
new file mode 100755
index 00000000..f78c3e7d
--- /dev/null
+++ b/vstf/vstf/agent/unittest/env/test_vs_plugin_manager.py
@@ -0,0 +1,68 @@
+"""
+Created on 2015-9-24
+
+@author: y00228926
+"""
+import unittest
+
+from vstf.agent.unittest.env import model
+from vstf.agent.env.vswitch_plugins import manager
+from vstf.common.utils import check_call
+
+
+class TestVsPlugins(model.Test):
+ def setUp(self):
+ super(TestVsPlugins, self).setUp()
+ self.cfg = {
+ "type": "ovs",
+ "name": "ovs1",
+ "uplinks": [
+ {
+ "bdf": self.bdf_of_eth[0],
+ "vlan_mode": "trunk",
+ "vlan_id": "100,200,300,400"
+ },
+ {
+ "bdf": self.bdf_of_eth[1],
+ "vlan_mode": "trunk",
+ "vlan_id": "100,200,300,400"
+ }
+ ],
+ "vtep": {}
+ }
+ self.mgr = manager.VswitchPluginManager()
+
+ def tearDown(self):
+ super(TestVsPlugins, self).tearDown()
+
+ def _check_br_exists(self, name):
+ try:
+ check_call('ifconfig %s' % name, shell=True)
+ except Exception, e:
+ return False
+ return True
+
+ def test_create_bridge(self):
+ self.cfg['name'] = 'br1'
+ self.br = self.mgr.get_vs_plugin('bridge')
+ self.br.clean()
+ self.br.init()
+ self.br.create_br(self.cfg)
+ self.assertTrue(self._check_br_exists('br1'))
+ self.br.clean()
+ self.assertFalse(self._check_br_exists('br1'))
+
+ def test_clean(self):
+ self.mgr.clean()
+
+ def test_get_supported_plugins(self):
+ ret = self.mgr.get_supported_plugins()
+ self.assertEqual(set(ret), {'bridge', 'ovs'})
+
+
+if __name__ == "__main__":
+ import logging
+
+ logging.basicConfig(level=logging.INFO)
+ LOG = logging.getLogger(__name__)
+ unittest.main()