Merge "DRAFT: model: remove vld_id not needed"
authorRoss Brattain <ross.b.brattain@intel.com>
Tue, 29 Aug 2017 22:29:30 +0000 (22:29 +0000)
committerGerrit Code Review <gerrit@opnfv.org>
Tue, 29 Aug 2017 22:29:30 +0000 (22:29 +0000)
13 files changed:
tests/unit/benchmark/scenarios/lib/test_delete_network.py [new file with mode: 0644]
tests/unit/benchmark/scenarios/lib/test_delete_port.py [new file with mode: 0644]
tests/unit/benchmark/scenarios/lib/test_delete_router.py [new file with mode: 0644]
tests/unit/benchmark/scenarios/lib/test_delete_router_gateway.py [new file with mode: 0644]
tests/unit/benchmark/scenarios/lib/test_delete_router_interface.py [new file with mode: 0644]
yardstick/benchmark/scenarios/lib/create_server.py
yardstick/benchmark/scenarios/lib/delete_network.py [new file with mode: 0644]
yardstick/benchmark/scenarios/lib/delete_port.py [new file with mode: 0644]
yardstick/benchmark/scenarios/lib/delete_router.py [new file with mode: 0644]
yardstick/benchmark/scenarios/lib/delete_router_gateway.py [new file with mode: 0644]
yardstick/benchmark/scenarios/lib/delete_router_interface.py [new file with mode: 0644]
yardstick/common/openstack_utils.py
yardstick/common/utils.py

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 (file)
index 0000000..9ccaa82
--- /dev/null
@@ -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 (file)
index 0000000..77b9c70
--- /dev/null
@@ -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 (file)
index 0000000..ab1ad5d
--- /dev/null
@@ -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 (file)
index 0000000..1150dcc
--- /dev/null
@@ -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 (file)
index 0000000..2cc9c9f
--- /dev/null
@@ -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()
index 273b004..31ba18e 100644 (file)
@@ -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 (file)
index 0000000..e8796bf
--- /dev/null
@@ -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 (file)
index 0000000..4369029
--- /dev/null
@@ -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 (file)
index 0000000..358fd40
--- /dev/null
@@ -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 (file)
index 0000000..af4f33f
--- /dev/null
@@ -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 (file)
index 0000000..117c808
--- /dev/null
@@ -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!")
index c862a6b..d1223ed 100644 (file)
@@ -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:
index 1d7ea07..68c9ed6 100644 (file)
@@ -90,7 +90,7 @@ def import_modules_from_package(package):
         for module_name in missing_modules:
             try:
                 sys.modules[module_name] = importutils.import_module(module_name)
-            except ImportError:
+            except (ImportError, SyntaxError):
                 logger.exception("unable to import %s", module_name)