Merge "Replace glance create image with shade client."
[yardstick.git] / yardstick / benchmark / scenarios / lib / delete_floating_ip.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.common import openstack_utils
13 from yardstick.common import exceptions
14 from yardstick.benchmark.scenarios import base
15
16
17 LOG = logging.getLogger(__name__)
18
19
20 class DeleteFloatingIp(base.Scenario):
21     """Delete an OpenStack floating ip """
22
23     __scenario_type__ = "DeleteFloatingIp"
24
25     def __init__(self, scenario_cfg, context_cfg):
26         self.scenario_cfg = scenario_cfg
27         self.context_cfg = context_cfg
28         self.options = self.scenario_cfg['options']
29
30         self.floating_ip_id = self.options["floating_ip_id"]
31         self.retry = self.options.get("retry", 1)
32
33         self.shade_client = openstack_utils.get_shade_client()
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_floating_ip(
48             self.shade_client, self.floating_ip_id,
49             retry=self.retry)
50         if not status:
51             result.update({"delete_floating_ip": 0})
52             LOG.error("Delete floating ip failed!")
53             raise exceptions.ScenarioDeleteFloatingIPError
54
55         result.update({"delete_floating_ip": 1})
56         LOG.info("Delete floating ip successful!")