Merge "Add "host_name_separator" variable to Context class"
[yardstick.git] / yardstick / benchmark / scenarios / lib / delete_image.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
10 import logging
11
12 from yardstick.benchmark.scenarios import base
13 from yardstick.common import openstack_utils
14 from yardstick.common import exceptions
15
16 LOG = logging.getLogger(__name__)
17
18
19 class DeleteImage(base.Scenario):
20     """Delete an OpenStack image"""
21
22     __scenario_type__ = "DeleteImage"
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.image_name_or_id = self.options["name_or_id"]
30         self.wait = self.options.get("wait", False)
31         self.timeout = self.options.get("timeout", 3600)
32         self.delete_objects = self.options.get("delete_objects", True)
33
34         self.shade_client = openstack_utils.get_shade_client()
35
36         self.setup_done = False
37
38     def setup(self):
39         """scenario setup"""
40
41         self.setup_done = True
42
43     def run(self, result):
44         """execute the test"""
45
46         if not self.setup_done:
47             self.setup()
48
49         status = openstack_utils.delete_image(
50             self.shade_client, self.image_name_or_id, wait=self.wait,
51             timeout=self.timeout, delete_objects=self.delete_objects)
52
53         if not status:
54             result.update({"delete_image": 0})
55             LOG.error("Delete image failed!")
56             raise exceptions.ScenarioDeleteImageError
57
58         result.update({"delete_image": 1})
59         LOG.info("Delete image successful!")