diff --git a/tackerclient/common/utils.py b/tackerclient/common/utils.py index ee79ad4a..fb62cf5f 100644 --- a/tackerclient/common/utils.py +++ b/tackerclient/common/utils.py @@ -25,7 +25,6 @@ from oslo_log import versionutils from oslo_utils import encodeutils from oslo_utils import importutils import six -import six.moves.urllib.parse as urlparse from tackerclient.common import exceptions from tackerclient.i18n import _ @@ -175,13 +174,6 @@ def add_boolean_argument(parser, name, **kwargs): **kwargs) -def validate_url(url): - url_parts = urlparse.urlparse(url) - if not url_parts.scheme or not url_parts.netloc or not url_parts.port: - raise exceptions.TackerClientException(message='Invalid URL') - return url_parts - - def get_file_path(filename): file_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '../%s' % filename)) diff --git a/tackerclient/tacker/v1_0/nfvo/vim.py b/tackerclient/tacker/v1_0/nfvo/vim.py index 58fb0f3f..a9080d99 100644 --- a/tackerclient/tacker/v1_0/nfvo/vim.py +++ b/tackerclient/tacker/v1_0/nfvo/vim.py @@ -17,7 +17,6 @@ import yaml from tackerclient.common import exceptions -from tackerclient.common import utils from tackerclient.tacker import v1_0 as tackerV10 from tackerclient.tacker.v1_0.nfvo import vim_utils @@ -73,7 +72,7 @@ class CreateVIM(tackerV10.CreateCommand): raise exceptions.TackerClientException(message='Auth URL must be ' 'specified', status_code=404) - vim_obj['auth_url'] = utils.validate_url(auth_url).geturl() + vim_obj['auth_url'] = vim_utils.validate_auth_url(auth_url).geturl() vim_obj['type'] = config_param.pop('type', 'openstack') vim_utils.args2body_vim(config_param, vim_obj) tackerV10.update_dict(parsed_args, body[self.resource], diff --git a/tackerclient/tacker/v1_0/nfvo/vim_utils.py b/tackerclient/tacker/v1_0/nfvo/vim_utils.py index 5162643c..43c2df84 100644 --- a/tackerclient/tacker/v1_0/nfvo/vim_utils.py +++ b/tackerclient/tacker/v1_0/nfvo/vim_utils.py @@ -13,7 +13,7 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. - +import six.moves.urllib.parse as urlparse from tackerclient.common import exceptions @@ -37,3 +37,10 @@ def args2body_vim(config_param, vim): 'user_id': config_param.pop('user_id', ''), 'user_domain_name': config_param.pop('user_domain_name', '')} + + +def validate_auth_url(url): + url_parts = urlparse.urlparse(url) + if not url_parts.scheme or not url_parts.netloc: + raise exceptions.TackerClientException(message='Invalid auth URL') + return url_parts diff --git a/tackerclient/tests/unit/vm/test_vim_utils.py b/tackerclient/tests/unit/vm/test_vim_utils.py index 58e456f9..f2535894 100644 --- a/tackerclient/tests/unit/vm/test_vim_utils.py +++ b/tackerclient/tests/unit/vm/test_vim_utils.py @@ -21,7 +21,7 @@ from tackerclient.common import exceptions from tackerclient.tacker.v1_0.nfvo import vim_utils -class CLITestAuthNoAuth(testtools.TestCase): +class TestVIMUtils(testtools.TestCase): def test_args2body_vim(self): config_param = {'project_id': sentinel.prj_id1, @@ -50,3 +50,22 @@ class CLITestAuthNoAuth(testtools.TestCase): self.assertRaises(exceptions.TackerClientException, vim_utils.args2body_vim, config_param, vim) + + def test_validate_auth_url_with_port(self): + auth_url = "http://localhost:8000/test" + url_parts = vim_utils.validate_auth_url(auth_url) + self.assertEqual('http', url_parts.scheme) + self.assertEqual('localhost:8000', url_parts.netloc) + self.assertEqual(8000, url_parts.port) + + def test_validate_auth_url_without_port(self): + auth_url = "http://localhost/test" + url_parts = vim_utils.validate_auth_url(auth_url) + self.assertEqual('http', url_parts.scheme) + self.assertEqual('localhost', url_parts.netloc) + + def test_validate_auth_url_exception(self): + auth_url = "localhost/test" + self.assertRaises(exceptions.TackerClientException, + vim_utils.validate_auth_url, + auth_url)