1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
##############################################################################
# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
import logging
from yardstick.benchmark.scenarios import base
from yardstick.common import openstack_utils
from yardstick.common import exceptions
LOG = logging.getLogger(__name__)
class GetServer(base.Scenario):
"""Get a server instance
Parameters:
name_or_id - Name or ID of the server
type: string
filters - meta data to use for further filtering
type: dict
detailed: Whether or not to add detailed additional information.
type: bool
bare: Whether to skip adding any additional information to the server
record.
type: bool
all_projects: Whether to get server from all projects or just the current
auth scoped project.
type: bool
Outputs:
rc - response code of getting server instance
1 for success
0 for failure
type: int
server - instance of the server
type: dict
"""
__scenario_type__ = 'GetServer'
def __init__(self, scenario_cfg, context_cfg):
self.scenario_cfg = scenario_cfg
self.context_cfg = context_cfg
self.options = self.scenario_cfg['options']
self.server_name_or_id = self.options.get('name_or_id')
self.filters = self.options.get('filters')
self.detailed = self.options.get('detailed', False)
self.bare = self.options.get('bare', False)
self.shade_client = openstack_utils.get_shade_client()
def run(self, result):
"""execute the test"""
server = openstack_utils.get_server(
self.shade_client, name_or_id=self.server_name_or_id,
filters=self.filters, detailed=self.detailed, bare=self.bare)
if not server:
result.update({'get_server': 0})
LOG.error('Get Server failed!')
raise exceptions.ScenarioGetServerError
result.update({'get_server': 1})
LOG.info('Get Server successful!')
keys = self.scenario_cfg.get('output', '').split()
values = [server]
return self._push_to_outputs(keys, values)
|