aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick/common
diff options
context:
space:
mode:
Diffstat (limited to 'yardstick/common')
-rw-r--r--yardstick/common/exceptions.py12
-rw-r--r--yardstick/common/openstack_utils.py85
2 files changed, 68 insertions, 29 deletions
diff --git a/yardstick/common/exceptions.py b/yardstick/common/exceptions.py
index 517936fdc..439b9cb1b 100644
--- a/yardstick/common/exceptions.py
+++ b/yardstick/common/exceptions.py
@@ -154,3 +154,15 @@ class UnsupportedPodFormatError(YardstickException):
class ScenarioCreateRouterError(YardstickException):
message = 'Create Neutron Router Scenario failed'
+
+
+class ScenarioRemoveRouterIntError(YardstickException):
+ message = 'Remove Neutron Router Interface Scenario failed'
+
+
+class ScenarioCreateFloatingIPError(YardstickException):
+ message = 'Create Neutron Floating IP Scenario failed'
+
+
+class ScenarioDeleteFloatingIPError(YardstickException):
+ message = 'Delete Neutron Floating IP Scenario failed'
diff --git a/yardstick/common/openstack_utils.py b/yardstick/common/openstack_utils.py
index a4fd4e550..a6b53a607 100644
--- a/yardstick/common/openstack_utils.py
+++ b/yardstick/common/openstack_utils.py
@@ -429,12 +429,6 @@ def delete_keypair(nova_client, key): # pragma: no cover
# *********************************************
# NEUTRON
# *********************************************
-def get_network_id(shade_client, network_name):
- networks = shade_client.list_networks({'name': network_name})
- if networks:
- return networks[0]['id']
-
-
def create_neutron_net(shade_client, network_name, shared=False,
admin_state_up=True, external=False, provider=None,
project_id=None):
@@ -563,38 +557,71 @@ def remove_gateway_router(neutron_client, router_id): # pragma: no cover
return False
-def remove_interface_router(neutron_client, router_id, subnet_id,
- **json_body): # pragma: no cover
- json_body.update({"subnet_id": subnet_id})
+def remove_router_interface(shade_client, router, subnet_id=None,
+ port_id=None):
+ """Detach a subnet from an internal router interface.
+
+ At least one of subnet_id or port_id must be supplied. If you specify both
+ subnet and port ID, the subnet ID must correspond to the subnet ID of the
+ first IP address on the port specified by the port ID.
+ Otherwise an error occurs.
+
+ :param router: The dict object of the router being changed
+ :param subnet_id:(string) The ID of the subnet to use for the interface
+ :param port_id:(string) The ID of the port to use for the interface
+ :returns: True on success
+ """
try:
- neutron_client.remove_interface_router(router=router_id,
- body=json_body)
+ shade_client.remove_router_interface(
+ router, subnet_id=subnet_id, port_id=port_id)
return True
- except Exception: # pylint: disable=broad-except
- log.error("Error [remove_interface_router(neutron_client, '%s', "
- "'%s')]", router_id, subnet_id)
+ except exc.OpenStackCloudException as o_exc:
+ log.error("Error [remove_interface_router(shade_client)]. "
+ "Exception message: %s", o_exc.orig_message)
return False
-def create_floating_ip(neutron_client, extnet_id): # pragma: no cover
- props = {'floating_network_id': extnet_id}
+def create_floating_ip(shade_client, network_name_or_id=None, server=None,
+ fixed_address=None, nat_destination=None,
+ port=None, wait=False, timeout=60):
+ """Allocate a new floating IP from a network or a pool.
+
+ :param network_name_or_id: Name or ID of the network
+ that the floating IP should come from.
+ :param server: Server dict for the server to create
+ the IP for and to which it should be attached.
+ :param fixed_address: Fixed IP to attach the floating ip to.
+ :param nat_destination: Name or ID of the network
+ that the fixed IP to attach the floating
+ IP to should be on.
+ :param port: The port ID that the floating IP should be
+ attached to. Specifying a port conflicts with specifying a
+ server,fixed_address or nat_destination.
+ :param wait: Whether to wait for the IP to be active.Only applies
+ if a server is provided.
+ :param timeout: How long to wait for the IP to be active.Only
+ applies if a server is provided.
+
+ :returns:Floating IP id and address
+ """
try:
- ip_json = neutron_client.create_floatingip({'floatingip': props})
- fip_addr = ip_json['floatingip']['floating_ip_address']
- fip_id = ip_json['floatingip']['id']
- except Exception: # pylint: disable=broad-except
- log.error("Error [create_floating_ip(neutron_client)]")
- return None
- return {'fip_addr': fip_addr, 'fip_id': fip_id}
+ fip = shade_client.create_floating_ip(
+ network=network_name_or_id, server=server,
+ fixed_address=fixed_address, nat_destination=nat_destination,
+ port=port, wait=wait, timeout=timeout)
+ return {'fip_addr': fip['floating_ip_address'], 'fip_id': fip['id']}
+ except exc.OpenStackCloudException as o_exc:
+ log.error("Error [create_floating_ip(shade_client)]. "
+ "Exception message: %s", o_exc.orig_message)
-def delete_floating_ip(nova_client, floatingip_id): # pragma: no cover
+def delete_floating_ip(shade_client, floating_ip_id, retry=1):
try:
- nova_client.floating_ips.delete(floatingip_id)
- return True
- except Exception: # pylint: disable=broad-except
- log.error("Error [delete_floating_ip(nova_client, '%s')]",
- floatingip_id)
+ return shade_client.delete_floating_ip(floating_ip_id=floating_ip_id,
+ retry=retry)
+ except exc.OpenStackCloudException as o_exc:
+ log.error("Error [delete_floating_ip(shade_client,'%s')]. "
+ "Exception message: %s", floating_ip_id, o_exc.orig_message)
return False