From: Daniel Henrique Barboza <dhbarboza82(a)gmail.com>
- test_mock_network: using FeatureTests.is_nm_running() instead of
its own function that does the same thing
- test_model_network: changed 'interface' to interfaces, added
network manager verification on vlan tag
- test_template: added network manager verification for macvtap
network with vlan tag
- fixed copyright dates and format in all those files
Signed-off-by: Daniel Henrique Barboza <dhbarboza82(a)gmail.com>
---
tests/test_mock_network.py | 11 ++---------
tests/test_model_network.py | 38 +++++++++++++++++++++++++++++++++-----
tests/test_template.py | 12 +++++++-----
3 files changed, 42 insertions(+), 19 deletions(-)
diff --git a/tests/test_mock_network.py b/tests/test_mock_network.py
index 3a9b7b5..3a2ca64 100644
--- a/tests/test_mock_network.py
+++ b/tests/test_mock_network.py
@@ -26,7 +26,7 @@ from functools import partial
from tests.utils import get_free_port, patch_auth, request, run_server
from wok.plugins.kimchi.mockmodel import MockModel
-from wok.utils import run_command
+from wok.plugins.kimchi.model.featuretests import FeatureTests
from test_model_network import _do_network_test
@@ -57,19 +57,12 @@ def tearDownModule():
os.unlink('/tmp/obj-store-test')
-def is_network_manager_running():
- out, err, rc = run_command(['nmcli', 'dev', 'status'])
- if rc != 0:
- return False
- return True
-
-
class MockNetworkTests(unittest.TestCase):
def setUp(self):
self.request = partial(request, host, ssl_port)
model.reset()
- @unittest.skipIf(is_network_manager_running(),
+ @unittest.skipIf(FeatureTests.is_nm_running(),
'test_vlan_tag_bridge skipped because Network '
'Manager is running.')
def test_vlan_tag_bridge(self):
diff --git a/tests/test_model_network.py b/tests/test_model_network.py
index 2abdd50..e27036d 100644
--- a/tests/test_model_network.py
+++ b/tests/test_model_network.py
@@ -2,7 +2,7 @@
#
# Project Kimchi
#
-# Copyright IBM, Corp. 2015
+# Copyright IBM Corp, 2015-2016
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -29,6 +29,7 @@ from tests.utils import run_server
from wok.rollbackcontext import RollbackContext
from wok.plugins.kimchi.model.model import Model
+from wok.plugins.kimchi.model.featuretests import FeatureTests
model = None
@@ -124,7 +125,7 @@ class NetworkTests(unittest.TestCase):
network = json.loads(
self.request('/plugins/kimchi/networks/network-1').read()
)
- keys = [u'name', u'connection', u'interface',
u'subnet', u'dhcp',
+ keys = [u'name', u'connection', u'interfaces',
u'subnet', u'dhcp',
u'vms', u'in_use', u'autostart',
u'state', u'persistent']
self.assertEquals(sorted(keys), sorted(network.keys()))
@@ -143,9 +144,36 @@ class NetworkTests(unittest.TestCase):
if len(interfaces) > 0:
iface = interfaces[0]['name']
networks.append({'name': u'macvtap-network',
- 'connection': 'macvtap',
'interface': iface})
- networks.append({'name': u'bridge-network',
'connection': 'bridge',
- 'interface': iface})
+ 'connection': 'macvtap',
'interfaces': [iface]})
+ if not FeatureTests.is_nm_running():
+ networks.append({'name': u'bridge-network',
+ 'connection': 'bridge',
+ 'interfaces': [iface]})
for net in networks:
_do_network_test(self, model, net)
+
+ def test_macvtap_network_create_fails_more_than_one_interface(self):
+ network = {
+ 'name': u'macvtap-network',
+ 'connection': 'macvtap',
+ 'interfaces': ['fake_iface1', 'fake_iface2',
'fake_iface3']
+ }
+
+ expected_error_msg = "KCHNET0030E"
+ req = json.dumps(network)
+ resp = self.request('/plugins/kimchi/networks', req, 'POST')
+ self.assertEquals(400, resp.status)
+ self.assertIn(expected_error_msg, resp.read())
+
+ def test_bridge_network_create_fails_more_than_one_interface(self):
+ network = {
+ 'name': u'bridge-network',
+ 'connection': 'bridge',
+ 'interfaces': ['fake_iface1', 'fake_iface2',
'fake_iface3']
+ }
+ expected_error_msg = "KCHNET0030E"
+ req = json.dumps(network)
+ resp = self.request('/plugins/kimchi/networks', req, 'POST')
+ self.assertEquals(400, resp.status)
+ self.assertIn(expected_error_msg, resp.read())
diff --git a/tests/test_template.py b/tests/test_template.py
index da0037e..7e53ae1 100644
--- a/tests/test_template.py
+++ b/tests/test_template.py
@@ -2,7 +2,7 @@
#
# Project Kimchi
#
-# Copyright IBM, Corp. 2015-2016
+# Copyright IBM Corp, 2015-2016
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -28,6 +28,7 @@ from tests.utils import get_free_port, patch_auth, request, run_server
from wok.plugins.kimchi.config import READONLY_POOL_TYPE
from wok.plugins.kimchi.mockmodel import MockModel
+from wok.plugins.kimchi.model.featuretests import FeatureTests
model = None
@@ -320,10 +321,11 @@ class TemplateTests(unittest.TestCase):
iface = interfaces[0]['name']
networks.append({'name': u'bridge-network',
'connection': 'macvtap',
- 'interface': iface})
- networks.append({'name': u'bridge-network',
- 'connection': 'macvtap',
- 'interface': iface, 'vlan_id': 987})
+ 'interfaces': [iface]})
+ if not FeatureTests.is_nm_running():
+ networks.append({'name': u'bridge-network-with-vlan',
+ 'connection': 'bridge',
+ 'interfaces': [iface], 'vlan_id': 987})
tmpl_nets = []
for net in networks:
--
2.5.0