Merge "Document for Euphrates test case results"
[yardstick.git] / yardstick / benchmark / scenarios / lib / delete_server.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 LOG = logging.getLogger(__name__)
16
17
18 class DeleteServer(base.Scenario):
19     """Delete an OpenStack server"""
20
21     __scenario_type__ = "DeleteServer"
22
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.server_name_or_id = self.options["name_or_id"]
28         self.wait = self.options.get("wait", False)
29         self.timeout = self.options.get("timeout", 180)
30         self.delete_ips = self.options.get("delete_ips", False)
31         self.delete_ip_retry = self.options.get("delete_ip_retry", 1)
32         self.shade_client = openstack_utils.get_shade_client()
33
34         self.setup_done = False
35
36     def setup(self):
37         """scenario setup"""
38
39         self.setup_done = True
40
41     def run(self, result):
42         """execute the test"""
43
44         if not self.setup_done:
45             self.setup()
46
47         status = openstack_utils.delete_instance(
48             self.shade_client, self.server_name_or_id, wait=self.wait,
49             timeout=self.timeout, delete_ips=self.delete_ips,
50             delete_ip_retry=self.delete_ip_retry)
51
52         if not status:
53             result.update({"delete_server": 0})
54             LOG.error("Delete server failed!")
55             raise exceptions.ScenarioDeleteServerError
56
57         result.update({"delete_server": 1})
58         LOG.info("Delete server successful!")