1 ##############################################################################
2 # Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
11 from yardstick.benchmark.scenarios import base
12 from yardstick.common import openstack_utils
13 from yardstick.common import exceptions
15 LOG = logging.getLogger(__name__)
18 class CreateImage(base.Scenario):
19 """Create an OpenStack image"""
21 __scenario_type__ = "CreateImage"
23 def __init__(self, scenario_cfg, context_cfg):
24 self.scenario_cfg = scenario_cfg
25 self.context_cfg = context_cfg
26 self.options = self.scenario_cfg["options"]
28 self.name = self.options["image_name"]
29 self.file_name = self.options.get("file_name")
30 self.container = self.options.get("container", 'images')
31 self.md5 = self.options.get("md5")
32 self.sha256 = self.options.get("sha256")
33 self.disk_format = self.options.get("disk_format")
34 self.container_format = self.options.get("container_format",)
35 self.disable_vendor_agent = self.options.get("disable_vendor_agent", True)
36 self.wait = self.options.get("wait", True)
37 self.timeout = self.options.get("timeout", 3600)
38 self.allow_duplicates = self.options.get("allow_duplicates", False)
39 self.meta = self.options.get("meta")
40 self.volume = self.options.get("volume")
42 self.shade_client = openstack_utils.get_shade_client()
44 self.setup_done = False
49 self.setup_done = True
51 def run(self, result):
52 """execute the test"""
54 if not self.setup_done:
57 image_id = openstack_utils.create_image(
58 self.shade_client, self.name, filename=self.file_name,
59 container=self.container, md5=self.md5, sha256=self.sha256,
60 disk_format=self.disk_format,
61 container_format=self.container_format,
62 disable_vendor_agent=self.disable_vendor_agent, wait=self.wait,
63 timeout=self.timeout, allow_duplicates=self.allow_duplicates,
64 meta=self.meta, volume=self.volume)
67 result.update({"image_create": 0})
68 LOG.error("Create image failed!")
69 raise exceptions.ScenarioCreateImageError
71 result.update({"image_create": 1})
72 LOG.info("Create image successful!")
73 keys = self.scenario_cfg.get("output", '').split()
75 return self._push_to_outputs(keys, values)