diff options
author | George Paraskevopoulos <geopar@intracom-telecom.com> | 2017-03-17 11:56:43 +0200 |
---|---|---|
committer | Manuel Buil <mbuil@suse.com> | 2017-03-18 10:29:03 +0000 |
commit | c94460eef60d18efc533adf30b49e7c56fa6b2ed (patch) | |
tree | b6c4a8f02a95d4c65662f5a0be67fa440721b7c9 /sfc/lib/utils.py | |
parent | 2aa568e857f459555e5d2e2deae773d15318468c (diff) |
Add ODL cleanup utilities
ODL does not clean all resources properly after tacker deletions, so we
add this as a post processing step
Change-Id: Ic485ee32b195f72235922ebe613af6c010cb57db
Signed-off-by: George Paraskevopoulos <geopar@intracom-telecom.com>
(cherry picked from commit e48b950bc77e37fbda611415577a7388e19c1ff6)
Diffstat (limited to 'sfc/lib/utils.py')
-rw-r--r-- | sfc/lib/utils.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/sfc/lib/utils.py b/sfc/lib/utils.py index c3a587e0..39a8da91 100644 --- a/sfc/lib/utils.py +++ b/sfc/lib/utils.py @@ -11,7 +11,9 @@ import os import re import subprocess +import requests import time +import xmltodict import yaml import functest.utils.functest_logger as ft_logger @@ -472,3 +474,47 @@ def get_nova_id(tacker_client, resource, vnf_id=None, vnf_name=None): logger.error("Cannot get nova ID for VNF (id='%s', name='%s')" % (vnf_id, vnf_name)) return None + + +def get_odl_ip_port(nodes): + local_jetty = os.path.join(os.getcwd(), 'jetty.xml') + odl_node = next(n for n in nodes if n.is_odl()) + odl_node.get_file('/opt/opendaylight/etc/jetty.xml', local_jetty) + with open(local_jetty) as fd: + parsed = xmltodict.parse(fd.read(), dict_constructor=dict) + + ip = (parsed['Configure']['Call'][0]['Arg']['New'] + ['Set'][0]['Property']['@default']) + port = (parsed['Configure']['Call'][0]['Arg']['New'] + ['Set'][1]['Property']['@default']) + return ip, port + + +def pluralize(s): + return '{0}s'.format(s) + + +def format_odl_resource_list_url(odl_ip, odl_port, resource, + odl_user='admin', odl_pwd='admin'): + return ('http://{usr}:{pwd}@{ip}:{port}/restconf/config/{rsrc}:{rsrcs}' + .format(usr=odl_user, pwd=odl_pwd, ip=odl_ip, port=odl_port, + rsrc=resource, rsrcs=pluralize(resource))) + + +def format_odl_resource_elem_url(odl_ip, odl_port, resource, elem_name): + list_url = format_odl_resource_list_url(odl_ip, odl_port, resource) + return ('{0}/{1}/{2}'.format(list_url, resource, elem_name)) + + +def odl_resource_list_names(resource, resource_json): + return [r['name'] for r in resource_json[pluralize(resource)][resource]] + + +def get_odl_resource_list(odl_ip, odl_port, resource): + url = format_odl_resource_list_url(odl_ip, odl_port, resource) + return requests.get(url).json() + + +def delete_odl_resource_elem(odl_ip, odl_port, resource, elem_name): + url = format_odl_resource_elem_url(odl_ip, odl_port, resource, elem_name) + requests.delete(url) |