Update Intel Copyright for files edited in 2019
[yardstick.git] / yardstick / benchmark / scenarios / lib / delete_router_interface.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 DeleteRouterInterface(base.Scenario):
20     """Unset an OpenStack router interface"""
21
22     __scenario_type__ = "DeleteRouterInterface"
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.router = self.options["router"]
30         self.subnet_id = self.options.get("subnet_id")
31         self.port_id = self.options.get("port_id")
32
33         self.shade_client = openstack_utils.get_shade_client()
34
35         self.setup_done = False
36
37     def setup(self):
38         """scenario setup"""
39
40         self.setup_done = True
41
42     def run(self, result):
43         """execute the test"""
44
45         if not self.setup_done:
46             self.setup()
47
48         status = openstack_utils.remove_router_interface(
49             self.shade_client, self.router, subnet_id=self.subnet_id,
50             port_id=self.port_id)
51         if not status:
52             result.update({"delete_router_interface": 0})
53             LOG.error("Delete router interface failed!")
54             raise exceptions.ScenarioRemoveRouterIntError
55
56         result.update({"delete_router_interface": 1})
57         LOG.info("Delete router interface successful!")