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 ##############################################################################
13 from yardstick.benchmark.scenarios import base
14 from yardstick.common import openstack_utils
15 from yardstick.common import exceptions
18 LOG = logging.getLogger(__name__)
21 class CreateFloatingIp(base.Scenario):
22 """Create an OpenStack floating ip"""
24 __scenario_type__ = "CreateFloatingIp"
26 def __init__(self, scenario_cfg, context_cfg):
27 self.scenario_cfg = scenario_cfg
28 self.context_cfg = context_cfg
29 self.ext_net_id = os.getenv("EXTERNAL_NETWORK", "external")
30 self.options = self.scenario_cfg["options"]
32 self.network_name_or_id = self.options.get("network_name_or_id", self.ext_net_id)
33 self.server = self.options.get("server")
34 self.fixed_address = self.options.get("fixed_address")
35 self.nat_destination = self.options.get("nat_destination")
36 self.port = self.options.get("port")
37 self.wait = self.options.get("wait", False)
38 self.timeout = self.options.get("timeout", 60)
40 self.shade_client = openstack_utils.get_shade_client()
42 self.setup_done = False
47 self.setup_done = True
49 def run(self, result):
50 """execute the test"""
52 if not self.setup_done:
55 floating_info = openstack_utils.create_floating_ip(
56 self.shade_client, network_name_or_id=self.network_name_or_id,
57 server=self.server, fixed_address=self.fixed_address,
58 nat_destination=self.nat_destination, port=self.port,
59 wait=self.wait, timeout=self.timeout)
62 result.update({"floating_ip_create": 0})
63 LOG.error("Creating floating ip failed!")
64 raise exceptions.ScenarioCreateFloatingIPError
66 result.update({"floating_ip_create": 1})
67 LOG.info("Creating floating ip successful!")
68 keys = self.scenario_cfg.get("output", '').split()
69 values = [floating_info["fip_id"], floating_info["fip_addr"]]
70 return self._push_to_outputs(keys, values)