Merge "Document for Euphrates test case results"
[yardstick.git] / yardstick / benchmark / scenarios / lib / delete_keypair.py
1 ##############################################################################
2 # Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
3 #
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 ##############################################################################
9 import logging
10
11 from yardstick.common import openstack_utils
12 from yardstick.common import exceptions
13 from yardstick.benchmark.scenarios import base
14
15
16 LOG = logging.getLogger(__name__)
17
18
19 class DeleteKeypair(base.Scenario):
20     """Delete an OpenStack keypair"""
21
22     __scenario_type__ = "DeleteKeypair"
23
24     def __init__(self, scenario_cfg, context_cfg):
25         self.scenario_cfg = scenario_cfg
26         self.context_cfg = context_cfg
27         self.options = self.scenario_cfg["options"]
28
29         self.key_name = self.options["key_name"]
30
31         self.shade_client = openstack_utils.get_shade_client()
32
33         self.setup_done = False
34
35     def setup(self):
36         """scenario setup"""
37
38         self.setup_done = True
39
40     def run(self, result):
41         """execute the test"""
42
43         if not self.setup_done:
44             self.setup()
45
46         status = openstack_utils.delete_keypair(self.shade_client,
47                                                 self.key_name)
48
49         if not status:
50             result.update({"delete_keypair": 0})
51             LOG.error("Delete keypair failed!")
52             raise exceptions.ScenarioDeleteKeypairError
53
54         result.update({"delete_keypair": 1})
55         LOG.info("Delete keypair successful!")