summaryrefslogtreecommitdiffstats
path: root/yardstick/benchmark/scenarios/lib/create_image.py
diff options
context:
space:
mode:
authorJing Lu <lvjing5@huawei.com>2017-08-11 09:16:42 +0000
committerGerrit Code Review <gerrit@opnfv.org>2017-08-11 09:16:42 +0000
commit55234666785b0fdc81365da4dac5563e954f8a09 (patch)
treef1987805820b708642623bf2a4436c02f8d6bbf9 /yardstick/benchmark/scenarios/lib/create_image.py
parentd8a34ec774f96412f7722fc4ddc66c796722ac25 (diff)
parent18e1f4432adea4e115a82fac96238970389ab07e (diff)
Merge "Add common openstack opertation scenarios: image & volume"
Diffstat (limited to 'yardstick/benchmark/scenarios/lib/create_image.py')
-rw-r--r--yardstick/benchmark/scenarios/lib/create_image.py72
1 files changed, 72 insertions, 0 deletions
diff --git a/yardstick/benchmark/scenarios/lib/create_image.py b/yardstick/benchmark/scenarios/lib/create_image.py
new file mode 100644
index 000000000..bcffc7452
--- /dev/null
+++ b/yardstick/benchmark/scenarios/lib/create_image.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 CreateImage(base.Scenario):
+ """Create an OpenStack image"""
+
+ __scenario_type__ = "CreateImage"
+
+ 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", "TestImage")
+ self.file_path = self.options.get("file_path", None)
+ self.disk_format = self.options.get("disk_format", "qcow2")
+ self.container_format = self.options.get("container_format", "bare")
+ self.min_disk = self.options.get("min_disk", 0)
+ self.min_ram = self.options.get("min_ram", 0)
+ self.protected = self.options.get("protected", False)
+ self.public = self.options.get("public", "public")
+ self.tags = self.options.get("tags", [])
+ self.custom_property = self.options.get("property", {})
+
+ self.glance_client = op_utils.get_glance_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()
+
+ image_id = op_utils.create_image(self.glance_client, self.image_name,
+ self.file_path, self.disk_format,
+ self.container_format, self.min_disk,
+ self.min_ram, self.protected, self.tags,
+ self.public, **self.custom_property)
+
+ if image_id:
+ LOG.info("Create image successful!")
+ values = [image_id]
+
+ else:
+ LOG.info("Create image failed!")
+ values = []
+
+ keys = self.scenario_cfg.get('output', '').split()
+ return self._push_to_outputs(keys, values)