aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick/benchmark/scenarios/networking/sfc_openstack.py
diff options
context:
space:
mode:
authorManuel Buil <manuel.buil@ericsson.com>2016-05-24 16:11:53 +0200
committerManuel Buil <manuel.buil@ericsson.com>2016-07-05 09:38:58 +0200
commit9a4ed05300b2aed28e8d2ec213049d5475655577 (patch)
treed1d63f88c6a9146e9a2b99ae54682b13cce68d28 /yardstick/benchmark/scenarios/networking/sfc_openstack.py
parent14c7413448e4690fefd0ecad908ec86d6f774d6f (diff)
SFC Yardstick test
Modifications of the SFC Yardstick test The test creates two chains. One chain blocks HTTP the other one blocks SSH. We doublecheck that HTTP works in one but not in the other and the same for SSH. There are some things that must be modified manually as ODL is not yet ready for ovs 2.5.90. Here are the instructions: https://wiki.opnfv.org/display/sfc/Yardstick Change-Id: Ide6588a682f3491ab58c47ee7335205868c109fc Signed-off-by: Manuel Buil <manuel.buil@ericsson.com>
Diffstat (limited to 'yardstick/benchmark/scenarios/networking/sfc_openstack.py')
-rw-r--r--yardstick/benchmark/scenarios/networking/sfc_openstack.py117
1 files changed, 117 insertions, 0 deletions
diff --git a/yardstick/benchmark/scenarios/networking/sfc_openstack.py b/yardstick/benchmark/scenarios/networking/sfc_openstack.py
new file mode 100644
index 000000000..2a5fbde1c
--- /dev/null
+++ b/yardstick/benchmark/scenarios/networking/sfc_openstack.py
@@ -0,0 +1,117 @@
+import os
+from novaclient.v2 import client as novaclient
+from neutronclient.v2_0 import client as neutronclient
+
+
+def get_credentials(service): # pragma: no cover
+ """Returns a creds dictionary filled with the following keys:
+ * username
+ * password/api_key (depending on the service)
+ * tenant_name/project_id (depending on the service)
+ * auth_url
+ :param service: a string indicating the name of the service
+ requesting the credentials.
+ """
+ creds = {}
+ # Unfortunately, each of the OpenStack client will request slightly
+ # different entries in their credentials dict.
+ if service.lower() in ("nova", "cinder"):
+ password = "api_key"
+ tenant = "project_id"
+ else:
+ password = "password"
+ tenant = "tenant_name"
+
+ # The most common way to pass these info to the script is to do it through
+ # environment variables.
+ creds.update({
+ "username": os.environ.get('OS_USERNAME', "admin"),
+ password: os.environ.get("OS_PASSWORD", 'admin'),
+ "auth_url": os.environ.get("OS_AUTH_URL"),
+ tenant: os.environ.get("OS_TENANT_NAME", "admin"),
+ })
+ cacert = os.environ.get("OS_CACERT")
+ if cacert is not None:
+ # each openstack client uses differnt kwargs for this
+ creds.update({"cacert": cacert,
+ "ca_cert": cacert,
+ "https_ca_cert": cacert,
+ "https_cacert": cacert,
+ "ca_file": cacert})
+ creds.update({"insecure": "True", "https_insecure": "True"})
+ if not os.path.isfile(cacert):
+ print ("WARNING: The 'OS_CACERT' environment variable is " +
+ "set to %s but the file does not exist." % cacert)
+ return creds
+
+
+def get_instances(nova_client): # pragma: no cover
+ try:
+ instances = nova_client.servers.list(search_opts={'all_tenants': 1})
+ return instances
+ except Exception, e:
+ print "Error [get_instances(nova_client)]:", e
+ return None
+
+
+def get_SFs(nova_client): # pragma: no cover
+ try:
+ instances = get_instances(nova_client)
+ SFs = []
+ for instance in instances:
+ if "sfc_test" not in instance.name:
+ SFs.append(instance)
+ return SFs
+ except Exception, e:
+ print "Error [get_SFs(nova_client)]:", e
+ return None
+
+
+def get_external_net_id(neutron_client): # pragma: no cover
+ for network in neutron_client.list_networks()['networks']:
+ if network['router:external']:
+ return network['id']
+ return False
+
+
+def create_floating_ips(neutron_client): # pragma: no cover
+ extnet_id = get_external_net_id(neutron_client)
+ ips = []
+ props = {'floating_network_id': extnet_id}
+ try:
+ while (len(ips) < 2):
+ ip_json = neutron_client.create_floatingip({'floatingip': props})
+ fip_addr = ip_json['floatingip']['floating_ip_address']
+ ips.append(fip_addr)
+ except Exception, e:
+ print "Error [create_floating_ip(neutron_client)]:", e
+ return None
+ return ips
+
+
+def floatIPtoSFs(SFs, floatips): # pragma: no cover
+ try:
+ i = 0
+ for SF in SFs:
+ SF.add_floating_ip(floatips[i])
+ i = i + 1
+ return True
+ except Exception, e:
+ print ("Error [add_floating_ip(nova_client, '%s', '%s')]:" %
+ (SF, floatips[i]), e)
+ return False
+
+
+def get_an_IP(): # pragma: no cover
+
+ creds_nova = get_credentials("nova")
+ nova_client = novaclient.Client(version='2', **creds_nova)
+ creds_neutron = get_credentials("neutron")
+ neutron_client = neutronclient.Client(**creds_neutron)
+ SFs = get_SFs(nova_client)
+ floatips = create_floating_ips(neutron_client)
+ floatIPtoSFs(SFs, floatips)
+ return floatips
+
+if __name__ == '__main__': # pragma: no cover
+ get_an_IP()