aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com>2018-03-27 16:46:22 +0000
committerGerrit Code Review <gerrit@opnfv.org>2018-03-27 16:46:22 +0000
commit3006badbe2123ae4697c924744656fc13584505e (patch)
treefdaae47c8fdf52227ef3d0a42e92e5a7a27ea7c4
parentebd835c33cc8d0f9124fd2568231c4c069b00661 (diff)
parent68c934be759962d18d109fde35726f416088a126 (diff)
Merge "Replace neutron router interface deletion with shade."
-rw-r--r--yardstick/benchmark/scenarios/lib/delete_router_interface.py28
-rw-r--r--yardstick/common/exceptions.py4
-rw-r--r--yardstick/common/openstack_utils.py27
-rw-r--r--yardstick/tests/unit/benchmark/scenarios/lib/test_delete_router_interface.py54
-rw-r--r--yardstick/tests/unit/common/test_openstack_utils.py23
5 files changed, 101 insertions, 35 deletions
diff --git a/yardstick/benchmark/scenarios/lib/delete_router_interface.py b/yardstick/benchmark/scenarios/lib/delete_router_interface.py
index 117c80811..e71aed3ef 100644
--- a/yardstick/benchmark/scenarios/lib/delete_router_interface.py
+++ b/yardstick/benchmark/scenarios/lib/delete_router_interface.py
@@ -7,13 +7,11 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-from __future__ import print_function
-from __future__ import absolute_import
-
import logging
from yardstick.benchmark.scenarios import base
-import yardstick.common.openstack_utils as op_utils
+from yardstick.common import openstack_utils
+from yardstick.common import exceptions
LOG = logging.getLogger(__name__)
@@ -28,10 +26,11 @@ class DeleteRouterInterface(base.Scenario):
self.context_cfg = context_cfg
self.options = self.scenario_cfg['options']
- self.subnet_id = self.options.get("subnet_id", None)
- self.router_id = self.options.get("router_id", None)
+ self.router = self.options["router"]
+ self.subnet_id = self.options.get("subnet_id")
+ self.port_id = self.options.get("port_id")
- self.neutron_client = op_utils.get_neutron_client()
+ self.shade_client = openstack_utils.get_shade_client()
self.setup_done = False
@@ -46,12 +45,13 @@ class DeleteRouterInterface(base.Scenario):
if not self.setup_done:
self.setup()
- status = op_utils.remove_interface_router(self.neutron_client,
- router_id=self.router_id,
- subnet_id=self.subnet_id)
- if status:
- result.update({"delete_router_interface": 1})
- LOG.info("Delete router interface successful!")
- else:
+ status = openstack_utils.remove_router_interface(
+ self.shade_client, self.router, subnet_id=self.subnet_id,
+ port_id=self.port_id)
+ if not status:
result.update({"delete_router_interface": 0})
LOG.error("Delete router interface failed!")
+ raise exceptions.ScenarioRemoveRouterIntError
+
+ result.update({"delete_router_interface": 1})
+ LOG.info("Delete router interface successful!")
diff --git a/yardstick/common/exceptions.py b/yardstick/common/exceptions.py
index 8160c5b0c..972486c8d 100644
--- a/yardstick/common/exceptions.py
+++ b/yardstick/common/exceptions.py
@@ -124,3 +124,7 @@ class UnsupportedPodFormatError(YardstickException):
class ScenarioCreateRouterError(YardstickException):
message = 'Create Neutron Router Scenario failed'
+
+
+class ScenarioRemoveRouterIntError(YardstickException):
+ message = 'Remove Neutron Router Interface Scenario failed'
diff --git a/yardstick/common/openstack_utils.py b/yardstick/common/openstack_utils.py
index a4fd4e550..e1a133fe9 100644
--- a/yardstick/common/openstack_utils.py
+++ b/yardstick/common/openstack_utils.py
@@ -563,16 +563,27 @@ def remove_gateway_router(neutron_client, router_id): # pragma: no cover
return False
-def remove_interface_router(neutron_client, router_id, subnet_id,
- **json_body): # pragma: no cover
- json_body.update({"subnet_id": subnet_id})
+def remove_router_interface(shade_client, router, subnet_id=None,
+ port_id=None):
+ """Detach a subnet from an internal router interface.
+
+ At least one of subnet_id or port_id must be supplied. If you specify both
+ subnet and port ID, the subnet ID must correspond to the subnet ID of the
+ first IP address on the port specified by the port ID.
+ Otherwise an error occurs.
+
+ :param router: The dict object of the router being changed
+ :param subnet_id:(string) The ID of the subnet to use for the interface
+ :param port_id:(string) The ID of the port to use for the interface
+ :returns: True on success
+ """
try:
- neutron_client.remove_interface_router(router=router_id,
- body=json_body)
+ shade_client.remove_router_interface(
+ router, subnet_id=subnet_id, port_id=port_id)
return True
- except Exception: # pylint: disable=broad-except
- log.error("Error [remove_interface_router(neutron_client, '%s', "
- "'%s')]", router_id, subnet_id)
+ except exc.OpenStackCloudException as o_exc:
+ log.error("Error [remove_interface_router(shade_client)]. "
+ "Exception message: %s", o_exc.orig_message)
return False
diff --git a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_router_interface.py b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_router_interface.py
index 9e9c5a5b6..823cb951a 100644
--- a/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_router_interface.py
+++ b/yardstick/tests/unit/benchmark/scenarios/lib/test_delete_router_interface.py
@@ -6,23 +6,51 @@
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
+
+from oslo_utils import uuidutils
import unittest
import mock
-from yardstick.benchmark.scenarios.lib.delete_router_interface import DeleteRouterInterface
+from yardstick.benchmark.scenarios.lib import delete_router_interface
+from yardstick.common import openstack_utils
+from yardstick.common import exceptions
class DeleteRouterInterfaceTestCase(unittest.TestCase):
- @mock.patch('yardstick.common.openstack_utils.get_neutron_client')
- @mock.patch('yardstick.common.openstack_utils.remove_interface_router')
- def test_delete_router_interface(self, mock_get_neutron_client, mock_remove_interface_router):
- options = {
- 'router_id': '123-123-123',
- 'subnet_id': '321-321-321'
- }
- args = {"options": options}
- obj = DeleteRouterInterface(args, {})
- obj.run({})
- mock_get_neutron_client.assert_called_once()
- mock_remove_interface_router.assert_called_once()
+ def setUp(self):
+ self._mock_remove_router_interface = mock.patch.object(
+ openstack_utils, 'remove_router_interface')
+ self.mock_remove_router_interface = (
+ self._mock_remove_router_interface.start())
+ self._mock_get_shade_client = mock.patch.object(
+ openstack_utils, 'get_shade_client')
+ self.mock_get_shade_client = self._mock_get_shade_client.start()
+ self._mock_log = mock.patch.object(delete_router_interface, 'LOG')
+ self.mock_log = self._mock_log.start()
+ self.args = {'options': {'router': uuidutils.generate_uuid()}}
+ self.result = {}
+ self.delrout_obj = delete_router_interface.DeleteRouterInterface(
+ self.args, mock.ANY)
+
+ self.addCleanup(self._stop_mock)
+
+ def _stop_mock(self):
+ self._mock_remove_router_interface.stop()
+ self._mock_get_shade_client.stop()
+ self._mock_log.stop()
+
+ def test_run(self):
+ self.mock_remove_router_interface.return_value = True
+ self.assertIsNone(self.delrout_obj.run(self.result))
+ self.assertEqual({"delete_router_interface": 1}, self.result)
+ self.mock_log.info.assert_called_once_with(
+ "Delete router interface successful!")
+
+ def test_run_fail(self):
+ self.mock_remove_router_interface.return_value = False
+ with self.assertRaises(exceptions.ScenarioRemoveRouterIntError):
+ self.delrout_obj.run(self.result)
+ self.assertEqual({"delete_router_interface": 0}, self.result)
+ self.mock_log.error.assert_called_once_with(
+ "Delete router interface failed!")
diff --git a/yardstick/tests/unit/common/test_openstack_utils.py b/yardstick/tests/unit/common/test_openstack_utils.py
index e39a13f1b..640d2d2c9 100644
--- a/yardstick/tests/unit/common/test_openstack_utils.py
+++ b/yardstick/tests/unit/common/test_openstack_utils.py
@@ -185,3 +185,26 @@ class CreateNeutronRouterTestCase(unittest.TestCase):
self.mock_shade_client)
mock_logger.error.assert_called_once()
self.assertIsNone(output)
+
+
+class RemoveRouterInterfaceTestCase(unittest.TestCase):
+
+ def setUp(self):
+ self.mock_shade_client = mock.Mock()
+ self.router = 'router'
+ self.mock_shade_client.remove_router_interface = mock.Mock()
+
+ def test_remove_router_interface(self):
+ self.mock_shade_client.remove_router_interface.return_value = True
+ output = openstack_utils.remove_router_interface(
+ self.mock_shade_client, self.router)
+ self.assertTrue(output)
+
+ @mock.patch.object(openstack_utils, 'log')
+ def test_remove_router_interface_exception(self, mock_logger):
+ self.mock_shade_client.remove_router_interface.side_effect = (
+ exc.OpenStackCloudException('error message'))
+ output = openstack_utils.remove_router_interface(
+ self.mock_shade_client, self.router)
+ mock_logger.error.assert_called_once()
+ self.assertFalse(output)