aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick/benchmark/scenarios/lib
diff options
context:
space:
mode:
authorJingLu5 <lvjing5@huawei.com>2017-08-10 06:00:58 +0000
committerJingLu5 <lvjing5@huawei.com>2017-08-11 01:13:24 +0000
commit4d065d2f4080e935b4e3bab4cbcf2b97f8a61ed3 (patch)
tree5d32d39b88e3901dfbe43c5f519fd1c033ddab48 /yardstick/benchmark/scenarios/lib
parent7322829b9f4e3981f9c6214b37f5693c0963b159 (diff)
Add common openstack opertation scenarios: flavor & server
JIRA: YARDSTICK-781 This patch adds some common openstack opertation scenarios Change-Id: I9e84a8894fe9b9c1754a45a0ddfdf93739164b9a Signed-off-by: JingLu5 <lvjing5@huawei.com>
Diffstat (limited to 'yardstick/benchmark/scenarios/lib')
-rw-r--r--yardstick/benchmark/scenarios/lib/create_flavor.py65
-rw-r--r--yardstick/benchmark/scenarios/lib/create_server.py72
-rw-r--r--yardstick/benchmark/scenarios/lib/delete_flavor.py56
-rw-r--r--yardstick/benchmark/scenarios/lib/get_flavor.py54
4 files changed, 247 insertions, 0 deletions
diff --git a/yardstick/benchmark/scenarios/lib/create_flavor.py b/yardstick/benchmark/scenarios/lib/create_flavor.py
new file mode 100644
index 000000000..05c7099cb
--- /dev/null
+++ b/yardstick/benchmark/scenarios/lib/create_flavor.py
@@ -0,0 +1,65 @@
+##############################################################################
+# 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 CreateFlavor(base.Scenario):
+ """Create an OpenStack flavor"""
+
+ __scenario_type__ = "CreateFlavor"
+
+ def __init__(self, scenario_cfg, context_cfg):
+ self.scenario_cfg = scenario_cfg
+ self.context_cfg = context_cfg
+ self.options = self.scenario_cfg['options']
+
+ self.flavor_name = self.options.get("flavor_name", "TestFlavor")
+ self.vcpus = self.options.get("vcpus", 2)
+ self.ram = self.options.get("ram", 1024)
+ self.disk = self.options.get("disk", 100)
+ self.public = self.options.get("is_public", True)
+
+ 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()
+
+ LOG.info("Creating flavor %s with %s vcpus, %sMB ram and %sGB disk",
+ self.flavor_name, self.vcpus, self.ram, self.disk)
+ paras = {'is_public': self.public}
+ flavor = op_utils.create_flavor(self.flavor_name,
+ self.ram, self.vcpus, self.disk,
+ **paras)
+
+ if flavor:
+ LOG.info("Create flavor successful!")
+ values = [flavor.id]
+ else:
+ LOG.info("Create flavor failed!")
+ values = []
+
+ keys = self.scenario_cfg.get('output', '').split()
+ return self._push_to_outputs(keys, values)
diff --git a/yardstick/benchmark/scenarios/lib/create_server.py b/yardstick/benchmark/scenarios/lib/create_server.py
new file mode 100644
index 000000000..45c0bfde9
--- /dev/null
+++ b/yardstick/benchmark/scenarios/lib/create_server.py
@@ -0,0 +1,72 @@
+##############################################################################
+# 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 CreateServer(base.Scenario):
+ """Create an OpenStack server"""
+
+ __scenario_type__ = "CreateSever"
+
+ def __init__(self, scenario_cfg, context_cfg):
+ self.scenario_cfg = scenario_cfg
+ self.context_cfg = context_cfg
+ self.options = self.scenario_cfg['options']
+
+ self.image_name = self.options.get("image_name", None)
+ self.flavor_name = self.options.get("flavor_name", None)
+ self.openstack = self.options.get("openstack_paras", None)
+
+ self.glance_client = op_utils.get_glance_client()
+ self.neutron_client = op_utils.get_neutron_client()
+ self.nova_client = op_utils.get_nova_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()
+
+ if self.image_name is not None:
+ self.openstack['image'] = op_utils.get_image_id(self.glance_client,
+ self.image_name)
+ if self.flavor_name is not None:
+ self.openstack['flavor'] = op_utils.get_flavor_id(self.nova_client,
+ self.flavor_name)
+
+ vm = op_utils.create_instance_and_wait_for_active(self.openstack)
+
+ if vm:
+ LOG.info("Create server successful!")
+ else:
+ LOG.error("Create server failed!")
+
+ try:
+ keys = self.scenario_cfg.get('output', '').split()
+ except KeyError:
+ pass
+ else:
+ values = [vm.id]
+ return self._push_to_outputs(keys, values)
diff --git a/yardstick/benchmark/scenarios/lib/delete_flavor.py b/yardstick/benchmark/scenarios/lib/delete_flavor.py
new file mode 100644
index 000000000..b30c37496
--- /dev/null
+++ b/yardstick/benchmark/scenarios/lib/delete_flavor.py
@@ -0,0 +1,56 @@
+##############################################################################
+# 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 DeleteFlavor(base.Scenario):
+ """Delete an OpenStack flavor by name"""
+
+ __scenario_type__ = "DeleteFlavor"
+
+ def __init__(self, scenario_cfg, context_cfg):
+ self.scenario_cfg = scenario_cfg
+ self.context_cfg = context_cfg
+ self.options = self.scenario_cfg['options']
+
+ self.flavor_name = self.options.get("flavor_name", "TestFlavor")
+ self.flavor_id = None
+
+ self.nova_client = op_utils.get_nova_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()
+
+ self.flavor_id = op_utils.get_flavor_id(self.nova_client, self.flavor_name)
+ LOG.info("Deleting flavor: %s", self.flavor_name)
+ status = op_utils.delete_flavor(self.flavor_id)
+
+ if status:
+ LOG.info("Delete flavor successful!")
+ else:
+ LOG.info("Delete flavor failed!")
diff --git a/yardstick/benchmark/scenarios/lib/get_flavor.py b/yardstick/benchmark/scenarios/lib/get_flavor.py
new file mode 100644
index 000000000..d5e33947e
--- /dev/null
+++ b/yardstick/benchmark/scenarios/lib/get_flavor.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 GetFlavor(base.Scenario):
+ """Get an OpenStack flavor by name"""
+
+ __scenario_type__ = "GetFlavor"
+
+ def __init__(self, scenario_cfg, context_cfg):
+ self.scenario_cfg = scenario_cfg
+ self.context_cfg = context_cfg
+ self.options = self.scenario_cfg['options']
+ self.flavor_name = self.options.get("flavor_name", "TestFlavor")
+ 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()
+
+ LOG.info("Querying flavor: %s", self.flavor_name)
+ flavor = op_utils.get_flavor_by_name(self.flavor_name)
+ if flavor:
+ LOG.info("Get flavor successful!")
+ values = [self._change_obj_to_dict(flavor)]
+ else:
+ LOG.info("Get flavor: no flavor matched!")
+ values = []
+
+ keys = self.scenario_cfg.get('output', '').split()
+ return self._push_to_outputs(keys, values)