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 ##############################################################################
13 from yardstick.benchmark.scenarios import base
14 from yardstick.common import openstack_utils
15 from yardstick.common import exceptions
17 LOG = logging.getLogger(__name__)
20 class CreateVolume(base.Scenario):
21 """Create an OpenStack volume"""
23 __scenario_type__ = "CreateVolume"
25 def __init__(self, scenario_cfg, context_cfg):
26 self.scenario_cfg = scenario_cfg
27 self.context_cfg = context_cfg
28 self.options = self.scenario_cfg["options"]
30 self.size = self.options["size_gb"]
31 self.wait = self.options.get("wait", True)
32 self.timeout = self.options.get("timeout")
33 self.image = self.options.get("image")
34 self.name = self.options.get("name")
35 self.description = self.options.get("description")
37 self.shade_client = openstack_utils.get_shade_client()
39 self.setup_done = False
44 self.setup_done = True
46 def run(self, result):
47 """execute the test"""
49 if not self.setup_done:
52 volume = openstack_utils.create_volume(
53 self.shade_client, self.size, wait=self.wait, timeout=self.timeout,
54 image=self.image, name=self.name, description=self.description)
57 result.update({"volume_create": 0})
58 LOG.error("Create volume failed!")
59 raise exceptions.ScenarioCreateVolumeError
61 status = volume["status"]
62 while status == "creating" or status == "downloading":
63 LOG.info("Volume status is: %s", status)
65 volume = openstack_utils.get_volume(self.shade_client, self.name)
66 status = volume["status"]
67 result.update({"volume_create": 1})
68 LOG.info("Create volume successful!")
69 values = [volume["id"]]
70 keys = self.scenario_cfg.get("output", '').split()
71 return self._push_to_outputs(keys, values)