From f7886316a99c65316f7910105cafa5f09fe14de9 Mon Sep 17 00:00:00 2001 From: Lin Yang Date: Tue, 8 Nov 2016 14:20:49 -0800 Subject: [PATCH] Support more flexible url build Previously, it directly joins all url parts as string, which will return wrong url if admin input podm base url with ending slash. So use urljoin() to cover both cases. Change-Id: I545d8fa99df4788458f4ea5b42eabc7e486a3484 Closes-Bug: #1640325 --- valence/redfish/redfish.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/valence/redfish/redfish.py b/valence/redfish/redfish.py index 1e9c850..d9504e2 100644 --- a/valence/redfish/redfish.py +++ b/valence/redfish/redfish.py @@ -15,6 +15,7 @@ import json import logging +import os import requests from requests.auth import HTTPBasicAuth from valence import config as cfg @@ -26,12 +27,11 @@ LOG = logging.getLogger(__name__) def get_rfs_url(serviceext): REDFISH_BASE_EXT = "/redfish/v1/" - INDEX = '' - # '/index.json' if REDFISH_BASE_EXT in serviceext: - return cfg.podm_url + serviceext + INDEX + relative_url = serviceext else: - return cfg.podm_url + REDFISH_BASE_EXT + serviceext + INDEX + relative_url = os.path.join(REDFISH_BASE_EXT, serviceext) + return requests.compat.urljoin(cfg.podm_url, relative_url) def send_request(resource, method="GET", **kwargs):