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 GetFlavor(base.Scenario):
19 """Get an OpenStack flavor by name"""
21 __scenario_type__ = "GetFlavor"
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"]
27 self.name_or_id = self.options["name_or_id"]
28 self.filters = self.options.get("filters")
29 self.get_extra = self.options.get("get_extra", True)
30 self.shade_client = openstack_utils.get_shade_client()
32 self.setup_done = False
37 self.setup_done = True
39 def run(self, result):
40 """execute the test"""
42 if not self.setup_done:
45 LOG.info("Querying flavor: %s", self.name_or_id)
46 flavor = openstack_utils.get_flavor(
47 self.shade_client, self.name_or_id, filters=self.filters,
48 get_extra=self.get_extra)
51 result.update({"get_flavor": 0})
52 LOG.error("Get flavor failed!")
53 raise exceptions.ScenarioGetFlavorError
55 result.update({"get_flavor": 1})
56 LOG.info("Get flavor successful!")
58 keys = self.scenario_cfg.get("output", '').split()
59 return self._push_to_outputs(keys, values)