From: Anderson Bravalheri Date: Thu, 12 Mar 2020 12:41:32 +0000 (+0000) Subject: Prevent URL trailing char errors in VIM/WIM X-Git-Tag: v7.1.0rc1~1^2~15 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=96a262702650a52e8f3075ba4fb5d043d7f88147;p=osm%2FRO.git Prevent URL trailing char errors in VIM/WIM It is very common for users to copy/paste the URL in the web GUI form when registering new VIMs/WIMs. This can be error prone, since it might introduce trailing characters that might pass unnoticed (e.g. when copying from "OpenStack Rocky > Project > API Access" a trailing space will be introduced). This change tries to prevent that from happening. Change-Id: I8ef83afe39ef854696ca43072273437ffd396c33 Signed-off-by: Anderson Bravalheri --- diff --git a/RO/osm_ro/nfvo.py b/RO/osm_ro/nfvo.py index 23c5f1c5..4d78e441 100644 --- a/RO/osm_ro/nfvo.py +++ b/RO/osm_ro/nfvo.py @@ -29,6 +29,7 @@ __date__ ="$16-sep-2014 22:05:01$" # import imp import json +import string import yaml from random import choice as random_choice from osm_ro import utils @@ -5112,6 +5113,15 @@ def new_datacenter(mydb, datacenter_descriptor): datacenter_type = datacenter_descriptor.get("type", "openvim"); # module_info = None + for url_field in ('vim_url', 'vim_url_admin'): + # It is common that users copy and paste the URL from the VIM website + # (example OpenStack), therefore a common mistake is to include blank + # characters at the end of the URL. Let's remove it and just in case, + # lets remove trailing slash as well. + url = datacenter_descriptor.get(url_field) + if url: + datacenter_descriptor[url_field] = url.strip(string.whitespace + '/') + # load plugin plugin_name = "rovim_" + datacenter_type if plugin_name not in plugins: diff --git a/RO/osm_ro/wim/persistence.py b/RO/osm_ro/wim/persistence.py index 32a46b35..f4945bb9 100644 --- a/RO/osm_ro/wim/persistence.py +++ b/RO/osm_ro/wim/persistence.py @@ -40,6 +40,7 @@ No domain logic/architectural concern should be present in this file. """ import json import logging +import string from contextlib import contextmanager from hashlib import sha1 from itertools import groupby @@ -307,6 +308,11 @@ class WimPersistence(object): if "config" in wim_descriptor: wim_descriptor["config"] = _serialize(wim_descriptor["config"]) + url = wim_descriptor["wim_url"] + wim_descriptor["wim_url"] = url.strip(string.whitespace + "/") + # ^ This avoid the common problem caused by trailing spaces/slashes in + # the URL (due to CTRL+C/CTRL+V) + return self.db.new_row( "wims", wim_descriptor, add_uuid=True, confidential_data=True)