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 ##############################################################################
10 from __future__ import print_function
11 from __future__ import absolute_import
16 from yardstick.benchmark.scenarios import base
17 import yardstick.common.openstack_utils as op_utils
19 LOG = logging.getLogger(__name__)
22 class CreateVolume(base.Scenario):
23 """Create an OpenStack volume"""
25 __scenario_type__ = "CreateVolume"
27 def __init__(self, scenario_cfg, context_cfg):
28 self.scenario_cfg = scenario_cfg
29 self.context_cfg = context_cfg
30 self.options = self.scenario_cfg['options']
32 self.volume_name = self.options.get("volume_name", "TestVolume")
33 self.volume_size = self.options.get("size", 100)
34 self.image_name = self.options.get("image", None)
37 self.glance_client = op_utils.get_glance_client()
38 self.cinder_client = op_utils.get_cinder_client()
40 self.setup_done = False
45 self.setup_done = True
48 """execute the test"""
50 if not self.setup_done:
53 self.image_id = op_utils.get_image_id(self.glance_client,
56 volume = op_utils.create_volume(self.cinder_client, self.volume_name,
57 self.volume_size, self.image_id)
59 status = volume.status
60 while(status == 'creating' or status == 'downloading'):
61 LOG.info("Volume status is: %s", status)
63 volume = op_utils.get_volume_by_name(self.volume_name)
64 status = volume.status
66 LOG.info("Create volume successful!")
69 keys = self.scenario_cfg.get('output', '').split()
70 return self._push_to_outputs(keys, values)