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 CreateKeypair(base.Scenario):
19 """Create an OpenStack keypair"""
21 __scenario_type__ = "CreateKeypair"
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"]
28 self.name = self.options["key_name"]
29 self.public_key = self.options.get("public_key")
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 keypair = openstack_utils.create_keypair(
46 self.shade_client, self.name, public_key=self.public_key)
49 result.update({"keypair_create": 0})
50 LOG.error("Create keypair failed!")
51 raise exceptions.ScenarioCreateKeypairError
53 result.update({"keypair_create": 1})
54 LOG.info("Create keypair successful!")
55 keys = self.scenario_cfg.get("output", '').split()
56 keypair_id = keypair["id"]
58 return self._push_to_outputs(keys, values)