1 ##############################################################################
2 # Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
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 ##############################################################################
12 from yardstick.benchmark.scenarios import base
13 from yardstick.common import openstack_utils
14 from yardstick.common import exceptions
16 LOG = logging.getLogger(__name__)
19 class CreateRouter(base.Scenario):
20 """Create an OpenStack router"""
22 __scenario_type__ = "CreateRouter"
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']
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')
36 self.shade_client = openstack_utils.get_shade_client()
38 self.setup_done = False
43 self.setup_done = True
45 def run(self, result):
46 """execute the test"""
48 if not self.setup_done:
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)
58 result.update({"router_create": 0})
59 LOG.error("Create router failed!")
60 raise exceptions.ScenarioCreateRouterError
62 result.update({"router_create": 1})
63 LOG.info("Create router successful!")
64 keys = self.scenario_cfg.get('output', '').split()
66 return self._push_to_outputs(keys, values)