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 GetServer(base.Scenario):
19 """Get a server instance
22 name_or_id - Name or ID of the server
24 filters - meta data to use for further filtering
26 detailed: Whether or not to add detailed additional information.
28 bare: Whether to skip adding any additional information to the server
31 all_projects: Whether to get server from all projects or just the current
36 rc - response code of getting server instance
40 server - instance of the server
45 __scenario_type__ = 'GetServer'
47 def __init__(self, scenario_cfg, context_cfg):
48 self.scenario_cfg = scenario_cfg
49 self.context_cfg = context_cfg
50 self.options = self.scenario_cfg['options']
52 self.server_name_or_id = self.options.get('name_or_id')
53 self.filters = self.options.get('filters')
54 self.detailed = self.options.get('detailed', False)
55 self.bare = self.options.get('bare', False)
57 self.shade_client = openstack_utils.get_shade_client()
59 def run(self, result):
60 """execute the test"""
62 server = openstack_utils.get_server(
63 self.shade_client, name_or_id=self.server_name_or_id,
64 filters=self.filters, detailed=self.detailed, bare=self.bare)
67 result.update({'get_server': 0})
68 LOG.error('Get Server failed!')
69 raise exceptions.ScenarioGetServerError
71 result.update({'get_server': 1})
72 LOG.info('Get Server successful!')
73 keys = self.scenario_cfg.get('output', '').split()
75 return self._push_to_outputs(keys, values)