]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
node-proxy: support more Location value formats 56251/head
authorGuillaume Abrioux <gabrioux@ibm.com>
Fri, 15 Mar 2024 14:20:29 +0000 (14:20 +0000)
committerGuillaume Abrioux <gabrioux@redhat.com>
Mon, 18 Mar 2024 08:48:04 +0000 (08:48 +0000)
After some tests, it turns out that depending on the hardware,
the header 'Location' which is returned by the server after logged can be different.
I could notice the following:

either:

Location: scheme://address:port/redfish/v1/SessionService/Session

or

Location: /redfish/v1/SessionService/Session

a previous tracker [1] was opened because I thought only the first one existed, which is wrong.

Fixes: https://tracker.ceph.com/issues/64951
[1] https://tracker.ceph.com/issues/64894

Signed-off-by: Guillaume Abrioux <gabrioux@ibm.com>
(cherry picked from commit d7ccf26983c41344a12f33b2a30fc79b65cc548f)

src/ceph-node-proxy/ceph_node_proxy/redfish_client.py

index d75c3db1e2180551fe073f6787f9822532a06a77..64a4e44dfe3db5fa3c88913fb7fb6a8ae39ac620 100644 (file)
@@ -30,6 +30,7 @@ class RedFishClient(BaseClient):
             oob_credentials = json.dumps({'UserName': self.username,
                                           'Password': self.password})
             headers = {'Content-Type': 'application/json'}
+            location_endpoint: str = ''
 
             try:
                 _headers, _data, _status_code = self.query(data=oob_credentials,
@@ -43,8 +44,14 @@ class RedFishClient(BaseClient):
                 self.log.error(msg)
                 raise RuntimeError
             self.token = _headers['X-Auth-Token']
-            location_endpoint: str = _headers['Location'].split('/', 3)[-1:][0]
-            self.location = f'/{location_endpoint}'
+            if _headers['Location'].startswith('http'):
+                # We assume the value has the following format:
+                # scheme://address:port/redfish/v1/SessionService/Session
+                location_endpoint = f"/{_headers['Location'].split('/', 3)[-1:][0]}"
+            else:
+                location_endpoint = _headers['Location']
+            self.location = location_endpoint
+            self.log.info(f'Logged in to {self.url}, Received header "Location": {self.location}')
 
     def is_logged_in(self) -> bool:
         self.log.debug(f'Checking token validity for {self.url}')