Update Intel Copyright for files edited in 2019
[yardstick.git] / yardstick / benchmark / scenarios / lib / create_router.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 CreateRouter(base.Scenario):
20     """Create an OpenStack router"""
21
22     __scenario_type__ = "CreateRouter"
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.name = self.options.get('name')
30         self.admin_state_up = self.options.get('admin_state_up', True)
31         self.ext_gateway_net_id = self.options.get('ext_gateway_net_id')
32         self.enable_snat = self.options.get('enable_snat')
33         self.ext_fixed_ips = self.options.get('ext_fixed_ips')
34         self.project_id = self.options.get('project_id')
35
36         self.shade_client = openstack_utils.get_shade_client()
37
38         self.setup_done = False
39
40     def setup(self):
41         """scenario setup"""
42
43         self.setup_done = True
44
45     def run(self, result):
46         """execute the test"""
47
48         if not self.setup_done:
49             self.setup()
50
51         router_id = openstack_utils.create_neutron_router(
52             self.shade_client, name=self.name,
53             admin_state_up=self.admin_state_up,
54             ext_gateway_net_id=self.ext_gateway_net_id,
55             enable_snat=self.enable_snat, ext_fixed_ips=self.ext_fixed_ips,
56             project_id=self.project_id)
57         if not router_id:
58             result.update({"router_create": 0})
59             LOG.error("Create router failed!")
60             raise exceptions.ScenarioCreateRouterError
61
62         result.update({"router_create": 1})
63         LOG.info("Create router successful!")
64         keys = self.scenario_cfg.get('output', '').split()
65         values = [router_id]
66         return self._push_to_outputs(keys, values)