X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=conformance-tests%2Fosm_client.py;h=9dd7f19b6974ee0fe667703780283741b79cf42c;hb=6be83cfdc5a5b01e44c4cfeff39328fcd09821a0;hp=70831e44c138580ee1b8b6e6bc2eec094253c640;hpb=e570b10455cf0ca49f1597e91282ce75c06688ea;p=osm%2Ftests.git diff --git a/conformance-tests/osm_client.py b/conformance-tests/osm_client.py index 70831e4..9dd7f19 100644 --- a/conformance-tests/osm_client.py +++ b/conformance-tests/osm_client.py @@ -15,6 +15,8 @@ from subprocess import run, PIPE import requests +import time +import os class OSMException(Exception): """A base class for MyProject exceptions.""" @@ -25,8 +27,9 @@ class ResourceException(OSMException): self.message = kwargs.get('message') class OSM: - def __init__(self, osm_hostname): + def __init__(self, osm_hostname, port): self.osm_hostname = osm_hostname + self.port = port def run_command(self, command): p = run(["osm {}".format(command)], shell=True, stdout=PIPE, stderr=PIPE) @@ -38,7 +41,8 @@ class OSM: return self.clean_output(p.stdout) def get_auth_token(self): - r = requests.post("https://{}:9999/osm/admin/v1/tokens".format(self.osm_hostname), verify=False, headers={"Accept":"application/json"}, json={ + + r = requests.post("https://{}:{}/osm/admin/v1/tokens".format(self.osm_hostname, self.port), verify=False, headers={"Accept":"application/json"}, json={ "username": "admin", "password": "admin", "project": "admin" @@ -54,8 +58,17 @@ class OSM: def create_vnfd(self, filename): return self.run_command("vnfd-create {}".format(filename)) + def create_ns(self, name, nsd, vim): + return self.run_command("ns-create --ns_name {} --nsd_name {} --vim_account {}".format(name, nsd, vim)) + def delete_nsd(self, id): return self.run_command("nsd-delete {}".format(id)) def delete_vnfd(self, id): - return self.run_command("vnfd-delete {}".format(id)) \ No newline at end of file + return self.run_command("vnfd-delete {}".format(id)) + + def delete_ns(self, id): + self.run_command("ns-delete {}".format(id)) + while (requests.get("https://{}:{}/osm/nslcm/v1/ns_instances/{}".format(self.osm_hostname, self.port, id), verify=False, headers={"Accept":"application/json", "Authorization":"Bearer {}".format(os.environ["AUTH_TOKEN"])}).status_code != 404): + print("Deleting NS...") + time.sleep(5)