Use RFC 8040 URL for 'odl-mdsal-lowlevel-*' RPCs
[integration/test.git] / csit / libraries / AuthStandalone.py
index 5e0c0eae4b180acc5a04a992224306d20b299a1b..6e766a1e05ef6e68f1ce8dd4ab1e456a2d0ba70d 100644 (file)
@@ -32,16 +32,16 @@ as URIs not starting with /restconf/ are not supported yet.
 # terms of the Eclipse Public License v1.0 which accompanies this distribution,
 # and is available at http://www.eclipse.org/legal/epl-v10.html
 
+import json
+import requests
+
+
 __author__ = "Vratko Polak"
 __copyright__ = "Copyright(c) 2015, Cisco Systems, Inc."
 __license__ = "Eclipse Public License v1.0"
 __email__ = "vrpolak@cisco.com"
 
 
-import json
-import requests
-
-
 #
 # Karaf Keyword definitions.
 #
@@ -87,12 +87,14 @@ class _BasicReusingSession(object):
 
     def __init__(self, ip, username="", password="", port="8181"):
         """Initialize session using hardcoded text data, remember credentials."""
-        self.rest_prefix = "http://" + ip + ":" + port + "/restconf/"
+        self.rest_prefix = "http://" + ip + ":" + port + "/rests/"
         self.session = requests.Session()
         if username:
             self.session.auth = (username, password)  # May work with non-string values
         else:
-            self.session.auth = None  # Supports "no authentication mode" as in odl-restconf-noauth
+            self.session.auth = (
+                None  # Supports "no authentication mode" as in odl-restconf-noauth
+            )
 
     def robust_method(self, method, uri, **kwargs):
         """Try method once using session credentials. Return last response."""
@@ -105,11 +107,13 @@ class _BasicClosingSession(object):
 
     def __init__(self, ip, username="", password="", port="8181"):
         """Prepare session initialization data using hardcoded text, remember credentials."""
-        self.rest_prefix = "http://" + ip + ":" + port + "/restconf/"
+        self.rest_prefix = "http://" + ip + ":" + port + "/rests/"
         if username:
             self.auth = (username, password)  # May work with non-string values
         else:
-            self.auth = None  # Supports "no authentication mode" as in odl-restconf-noauth
+            self.auth = (
+                None  # Supports "no authentication mode" as in odl-restconf-noauth
+            )
         self.session = None
 
     def robust_method(self, method, uri, **kwargs):
@@ -131,7 +135,7 @@ class _TokenReusingSession(object):
     def __init__(self, ip, username, password, scope, port="8181"):
         """Initialize session using hardcoded text data."""
         self.auth_url = "http://" + ip + ":" + port + "/oauth2/token"
-        self.rest_prefix = "http://" + ip + ":" + port + "/restconf/"
+        self.rest_prefix = "http://" + ip + ":" + port + "/rests/"
         self.auth_data = "grant_type=password&username=" + username
         self.auth_data += "&password=" + password + "&scope=" + scope
         self.auth_header = {"Content-Type": "application/x-www-form-urlencoded"}
@@ -144,7 +148,9 @@ class _TokenReusingSession(object):
         if self.session:
             self.session.close()
         self.session = requests.Session()
-        resp = self.session.post(self.auth_url, data=self.auth_data, headers=self.auth_header)
+        resp = self.session.post(
+            self.auth_url, data=self.auth_data, headers=self.auth_header
+        )
         resp_obj = json.loads(resp.text)
         try:
             token = resp_obj["access_token"]
@@ -152,7 +158,6 @@ class _TokenReusingSession(object):
             raise RuntimeError("Parse failed: " + resp.text)
         self.token = token
         # TODO: Use logging so that callers could see token refreshes.
-        # print "DEBUG: token:", token
         # We keep self.session to use for the following restconf requests.
 
     def oneshot_method(self, method, uri, **kwargs):
@@ -179,7 +184,7 @@ class _TokenClosingSession(object):
     def __init__(self, ip, username, password, scope, port="8181"):
         """Prepare session initialization data using hardcoded text."""
         self.auth_url = "http://" + ip + ":" + port + "/oauth2/token"
-        self.rest_prefix = "http://" + ip + ":" + port + "/restconf/"
+        self.rest_prefix = "http://" + ip + ":" + port + "/rests/"
         self.auth_data = "grant_type=password&username=" + username
         self.auth_data += "&password=" + password + "&scope=" + scope
         self.auth_header = {"Content-Type": "application/x-www-form-urlencoded"}
@@ -192,7 +197,9 @@ class _TokenClosingSession(object):
         if self.session:
             self.session.close()
         self.session = requests.Session()
-        resp = self.session.post(self.auth_url, data=self.auth_data, headers=self.auth_header)
+        resp = self.session.post(
+            self.auth_url, data=self.auth_data, headers=self.auth_header
+        )
         resp_obj = json.loads(resp.text)
         try:
             token = resp_obj["access_token"]
@@ -200,7 +207,6 @@ class _TokenClosingSession(object):
             raise RuntimeError("Parse failed: " + resp.text)
         self.token = token
         # TODO: Use logging so that callers could see token refreshes.
-        # print "DEBUG: token:", token
         # We keep self.session to use for the following restconf requests.
 
     def oneshot_method(self, method, uri, **kwargs):