diff options
author | Ross Brattain <ross.b.brattain@intel.com> | 2017-08-29 00:07:35 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2017-08-29 00:07:35 +0000 |
commit | b583d4bfe6bc49e0f3bf4beec6612390a1d4bd24 (patch) | |
tree | 41b230ec1a663c4cb4baef4e5368098862a73835 | |
parent | a66b78d60d7d062218df8e6b9c279f7931a030cd (diff) | |
parent | d254d748b607c43167876f28c74b9ea839090df2 (diff) |
Merge "Add common openstack opertation scenarios: router & port"
12 files changed, 496 insertions, 1 deletions
diff --git a/tests/unit/benchmark/scenarios/lib/test_delete_network.py b/tests/unit/benchmark/scenarios/lib/test_delete_network.py new file mode 100644 index 000000000..9ccaa8232 --- /dev/null +++ b/tests/unit/benchmark/scenarios/lib/test_delete_network.py @@ -0,0 +1,36 @@ +############################################################################## +# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## +import unittest +import mock +import paramiko + +from yardstick.benchmark.scenarios.lib.delete_network import DeleteNetwork + + +class DeleteNetworkTestCase(unittest.TestCase): + + @mock.patch('yardstick.common.openstack_utils.get_neutron_client') + @mock.patch('yardstick.common.openstack_utils.delete_neutron_net') + def test_delete_network(self, mock_get_neutron_client, mock_delete_neutron_net): + options = { + 'network_id': '123-123-123' + } + args = {"options": options} + obj = DeleteNetwork(args, {}) + obj.run({}) + self.assertTrue(mock_get_neutron_client.called) + self.assertTrue(mock_delete_neutron_net.called) + + +def main(): + unittest.main() + + +if __name__ == '__main__': + main() diff --git a/tests/unit/benchmark/scenarios/lib/test_delete_port.py b/tests/unit/benchmark/scenarios/lib/test_delete_port.py new file mode 100644 index 000000000..77b9c7009 --- /dev/null +++ b/tests/unit/benchmark/scenarios/lib/test_delete_port.py @@ -0,0 +1,34 @@ +############################################################################## +# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## +import unittest +import mock +import paramiko + +from yardstick.benchmark.scenarios.lib.delete_port import DeletePort + + +class DeletePortTestCase(unittest.TestCase): + + @mock.patch('yardstick.common.openstack_utils.get_neutron_client') + def test_delete_port(self, mock_get_neutron_client): + options = { + 'port_id': '123-123-123' + } + args = {"options": options} + obj = DeletePort(args, {}) + obj.run({}) + self.assertTrue(mock_get_neutron_client.called) + + +def main(): + unittest.main() + + +if __name__ == '__main__': + main() diff --git a/tests/unit/benchmark/scenarios/lib/test_delete_router.py b/tests/unit/benchmark/scenarios/lib/test_delete_router.py new file mode 100644 index 000000000..ab1ad5d35 --- /dev/null +++ b/tests/unit/benchmark/scenarios/lib/test_delete_router.py @@ -0,0 +1,36 @@ +############################################################################## +# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## +import unittest +import mock +import paramiko + +from yardstick.benchmark.scenarios.lib.delete_router import DeleteRouter + + +class DeleteRouterTestCase(unittest.TestCase): + + @mock.patch('yardstick.common.openstack_utils.get_neutron_client') + @mock.patch('yardstick.common.openstack_utils.delete_neutron_router') + def test_delete_router(self, mock_get_neutron_client, mock_delete_neutron_router): + options = { + 'router_id': '123-123-123' + } + args = {"options": options} + obj = DeleteRouter(args, {}) + obj.run({}) + self.assertTrue(mock_get_neutron_client.called) + self.assertTrue(mock_delete_neutron_router.called) + + +def main(): + unittest.main() + + +if __name__ == '__main__': + main() diff --git a/tests/unit/benchmark/scenarios/lib/test_delete_router_gateway.py b/tests/unit/benchmark/scenarios/lib/test_delete_router_gateway.py new file mode 100644 index 000000000..1150dccda --- /dev/null +++ b/tests/unit/benchmark/scenarios/lib/test_delete_router_gateway.py @@ -0,0 +1,36 @@ +############################################################################## +# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## +import unittest +import mock +import paramiko + +from yardstick.benchmark.scenarios.lib.delete_router_gateway import DeleteRouterGateway + + +class DeleteRouterGatewayTestCase(unittest.TestCase): + + @mock.patch('yardstick.common.openstack_utils.get_neutron_client') + @mock.patch('yardstick.common.openstack_utils.remove_gateway_router') + def test_delete_router_gateway(self, mock_get_neutron_client, mock_remove_gateway_router): + options = { + 'router_id': '123-123-123' + } + args = {"options": options} + obj = DeleteRouterGateway(args, {}) + obj.run({}) + self.assertTrue(mock_get_neutron_client.called) + self.assertTrue(mock_remove_gateway_router.called) + + +def main(): + unittest.main() + + +if __name__ == '__main__': + main() diff --git a/tests/unit/benchmark/scenarios/lib/test_delete_router_interface.py b/tests/unit/benchmark/scenarios/lib/test_delete_router_interface.py new file mode 100644 index 000000000..2cc9c9f37 --- /dev/null +++ b/tests/unit/benchmark/scenarios/lib/test_delete_router_interface.py @@ -0,0 +1,37 @@ +############################################################################## +# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## +import unittest +import mock +import paramiko + +from yardstick.benchmark.scenarios.lib.delete_router_interface import DeleteRouterInterface + + +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({}) + self.assertTrue(mock_get_neutron_client.called) + self.assertTrue(mock_remove_interface_router.called) + + +def main(): + unittest.main() + + +if __name__ == '__main__': + main() diff --git a/yardstick/benchmark/scenarios/lib/create_server.py b/yardstick/benchmark/scenarios/lib/create_server.py index 273b0045a..31ba18ed4 100644 --- a/yardstick/benchmark/scenarios/lib/create_server.py +++ b/yardstick/benchmark/scenarios/lib/create_server.py @@ -21,7 +21,7 @@ LOG = logging.getLogger(__name__) class CreateServer(base.Scenario): """Create an OpenStack server""" - __scenario_type__ = "CreateSever" + __scenario_type__ = "CreateServer" def __init__(self, scenario_cfg, context_cfg): self.scenario_cfg = scenario_cfg diff --git a/yardstick/benchmark/scenarios/lib/delete_network.py b/yardstick/benchmark/scenarios/lib/delete_network.py new file mode 100644 index 000000000..e8796bf82 --- /dev/null +++ b/yardstick/benchmark/scenarios/lib/delete_network.py @@ -0,0 +1,55 @@ +############################################################################## +# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# 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 + +LOG = logging.getLogger(__name__) + + +class DeleteNetwork(base.Scenario): + """Delete an OpenStack network""" + + __scenario_type__ = "DeleteNetwork" + + def __init__(self, scenario_cfg, context_cfg): + self.scenario_cfg = scenario_cfg + self.context_cfg = context_cfg + self.options = self.scenario_cfg['options'] + + self.network_id = self.options.get("network_id", None) + + self.neutron_client = op_utils.get_neutron_client() + + self.setup_done = False + + def setup(self): + """scenario setup""" + + self.setup_done = True + + def run(self, result): + """execute the test""" + + if not self.setup_done: + self.setup() + + status = op_utils.delete_neutron_net(self.neutron_client, + network_id=self.network_id) + if status: + result.update({"delete_network": 1}) + LOG.info("Delete network successful!") + else: + result.update({"delete_network": 0}) + LOG.error("Delete network failed!") diff --git a/yardstick/benchmark/scenarios/lib/delete_port.py b/yardstick/benchmark/scenarios/lib/delete_port.py new file mode 100644 index 000000000..436902998 --- /dev/null +++ b/yardstick/benchmark/scenarios/lib/delete_port.py @@ -0,0 +1,54 @@ +############################################################################## +# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# 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 + +LOG = logging.getLogger(__name__) + + +class DeletePort(base.Scenario): + """Delete an OpenStack subnetwork""" + + __scenario_type__ = "DeletePort" + + def __init__(self, scenario_cfg, context_cfg): + self.scenario_cfg = scenario_cfg + self.context_cfg = context_cfg + self.options = self.scenario_cfg['options'] + + self.port_id = self.options.get("port_id", None) + + self.neutron_client = op_utils.get_neutron_client() + + self.setup_done = False + + def setup(self): + """scenario setup""" + + self.setup_done = True + + def run(self, result): + """execute the test""" + + if not self.setup_done: + self.setup() + + status = self.neutron_client.delete_port(self.port_id) + if status: + result.update({"delete_port": 1}) + LOG.info("Delete Port successful!") + else: + result.update({"delete_port": 0}) + LOG.error("Delete Port failed!") diff --git a/yardstick/benchmark/scenarios/lib/delete_router.py b/yardstick/benchmark/scenarios/lib/delete_router.py new file mode 100644 index 000000000..358fd40cf --- /dev/null +++ b/yardstick/benchmark/scenarios/lib/delete_router.py @@ -0,0 +1,55 @@ +############################################################################## +# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# 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 + +LOG = logging.getLogger(__name__) + + +class DeleteRouter(base.Scenario): + """Delete an OpenStack router""" + + __scenario_type__ = "DeleteRouter" + + def __init__(self, scenario_cfg, context_cfg): + self.scenario_cfg = scenario_cfg + self.context_cfg = context_cfg + self.options = self.scenario_cfg['options'] + + self.router_id = self.options.get("router_id", None) + + self.neutron_client = op_utils.get_neutron_client() + + self.setup_done = False + + def setup(self): + """scenario setup""" + + self.setup_done = True + + def run(self, result): + """execute the test""" + + if not self.setup_done: + self.setup() + + status = op_utils.delete_neutron_router(self.neutron_client, + router_id=self.router_id) + if status: + result.update({"delete_router": 1}) + LOG.info("Delete router successful!") + else: + result.update({"delete_router": 0}) + LOG.error("Delete router failed!") diff --git a/yardstick/benchmark/scenarios/lib/delete_router_gateway.py b/yardstick/benchmark/scenarios/lib/delete_router_gateway.py new file mode 100644 index 000000000..af4f33f94 --- /dev/null +++ b/yardstick/benchmark/scenarios/lib/delete_router_gateway.py @@ -0,0 +1,55 @@ +############################################################################## +# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# 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 + +LOG = logging.getLogger(__name__) + + +class DeleteRouterGateway(base.Scenario): + """Unset an OpenStack router gateway""" + + __scenario_type__ = "DeleteRouterGateway" + + def __init__(self, scenario_cfg, context_cfg): + self.scenario_cfg = scenario_cfg + self.context_cfg = context_cfg + self.options = self.scenario_cfg['options'] + + self.router_id = self.options.get("router_id", None) + + self.neutron_client = op_utils.get_neutron_client() + + self.setup_done = False + + def setup(self): + """scenario setup""" + + self.setup_done = True + + def run(self, result): + """execute the test""" + + if not self.setup_done: + self.setup() + + status = op_utils.remove_gateway_router(self.neutron_client, + router_id=self.router_id) + if status: + result.update({"delete_router_gateway": 1}) + LOG.info("Delete router gateway successful!") + else: + result.update({"delete_router_gateway": 0}) + LOG.error("Delete router gateway failed!") diff --git a/yardstick/benchmark/scenarios/lib/delete_router_interface.py b/yardstick/benchmark/scenarios/lib/delete_router_interface.py new file mode 100644 index 000000000..117c80811 --- /dev/null +++ b/yardstick/benchmark/scenarios/lib/delete_router_interface.py @@ -0,0 +1,57 @@ +############################################################################## +# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# 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 + +LOG = logging.getLogger(__name__) + + +class DeleteRouterInterface(base.Scenario): + """Unset an OpenStack router interface""" + + __scenario_type__ = "DeleteRouterInterface" + + def __init__(self, scenario_cfg, context_cfg): + self.scenario_cfg = scenario_cfg + 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.neutron_client = op_utils.get_neutron_client() + + self.setup_done = False + + def setup(self): + """scenario setup""" + + self.setup_done = True + + def run(self, result): + """execute the test""" + + 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: + result.update({"delete_router_interface": 0}) + LOG.error("Delete router interface failed!") diff --git a/yardstick/common/openstack_utils.py b/yardstick/common/openstack_utils.py index c862a6ba2..d1223edd2 100644 --- a/yardstick/common/openstack_utils.py +++ b/yardstick/common/openstack_utils.py @@ -457,6 +457,15 @@ def create_neutron_net(neutron_client, json_body): # pragma: no cover return None +def delete_neutron_net(neutron_client, network_id): # pragma: no cover + try: + neutron_client.delete_network(network_id) + return True + except Exception: + log.error("Error [delete_neutron_net(neutron_client, '%s')]" % network_id) + return False + + def create_neutron_subnet(neutron_client, json_body): # pragma: no cover try: subnet = neutron_client.create_subnet(body=json_body) @@ -477,6 +486,37 @@ def create_neutron_router(neutron_client, json_body): # pragma: no cover return None +def delete_neutron_router(neutron_client, router_id): # pragma: no cover + try: + neutron_client.delete_router(router=router_id) + return True + except Exception: + log.error("Error [delete_neutron_router(neutron_client, '%s')]" % router_id) + return False + + +def remove_gateway_router(neutron_client, router_id): # pragma: no cover + try: + neutron_client.remove_gateway_router(router_id) + return True + except Exception: + log.error("Error [remove_gateway_router(neutron_client, '%s')]" % router_id) + return False + + +def remove_interface_router(neutron_client, router_id, subnet_id, + **json_body): # pragma: no cover + json_body.update({"subnet_id": subnet_id}) + try: + neutron_client.remove_interface_router(router=router_id, + body=json_body) + return True + except Exception: + log.error("Error [remove_interface_router(neutron_client, '%s', " + "'%s')]" % (router_id, subnet_id)) + return False + + def create_floating_ip(neutron_client, extnet_id): # pragma: no cover props = {'floating_network_id': extnet_id} try: |