Merge "Addition of storage of extra counters for Grafana"
[yardstick.git] / yardstick / benchmark / scenarios / lib / delete_network.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 import yardstick.common.openstack_utils as op_utils
14
15
16 LOG = logging.getLogger(__name__)
17
18
19 class DeleteNetwork(base.Scenario):
20     """Delete an OpenStack network"""
21
22     __scenario_type__ = "DeleteNetwork"
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.network_id = self.options.get("network_id", None)
30
31         self.shade_client = op_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 = op_utils.delete_neutron_net(self.shade_client,
47                                              network_id=self.network_id)
48         if status:
49             result.update({"delete_network": 1})
50             LOG.info("Delete network successful!")
51         else:
52             result.update({"delete_network": 0})
53             LOG.error("Delete network failed!")
54         return status