From f8bb518893b183fa68d0137fea6486ba42f54d84 Mon Sep 17 00:00:00 2001 From: gong yong sheng Date: Mon, 18 Jul 2016 12:50:30 +0800 Subject: [PATCH] Add domain information into auth cred. If we use v3 keystone, these information should be passed into tacker server. Change-Id: Ieb5612c966b2110930faac0401f5dabde064ffc1 Partial-Bug: #1603851 (cherry picked from commit 0aa7efd2921a191ad4b5ccf600cea39c8299acc7) --- tackerclient/tacker/v1_0/nfvo/vim_utils.py | 8 ++- tackerclient/tests/unit/nfvo/__init__.py | 0 .../tests/unit/nfvo/test_vim_utils.py | 52 +++++++++++++++++++ tackerclient/tests/unit/vm/test_cli10_vim.py | 18 +++++-- 4 files changed, 71 insertions(+), 7 deletions(-) create mode 100644 tackerclient/tests/unit/nfvo/__init__.py create mode 100644 tackerclient/tests/unit/nfvo/test_vim_utils.py diff --git a/tackerclient/tacker/v1_0/nfvo/vim_utils.py b/tackerclient/tacker/v1_0/nfvo/vim_utils.py index b06dd645..5162643c 100644 --- a/tackerclient/tacker/v1_0/nfvo/vim_utils.py +++ b/tackerclient/tacker/v1_0/nfvo/vim_utils.py @@ -25,11 +25,15 @@ def args2body_vim(config_param, vim): :return: vim body with args populated """ vim['vim_project'] = {'id': config_param.pop('project_id', ''), - 'name': config_param.pop('project_name', '')} + 'name': config_param.pop('project_name', ''), + 'project_domain_name': + config_param.pop('project_domain_name', '')} if not vim['vim_project']['id'] and not vim['vim_project']['name']: raise exceptions.TackerClientException(message='Project Id or name ' 'must be specified', status_code=404) vim['auth_cred'] = {'username': config_param.pop('username', ''), 'password': config_param.pop('password', ''), - 'user_id': config_param.pop('user_id', '')} + 'user_id': config_param.pop('user_id', ''), + 'user_domain_name': + config_param.pop('user_domain_name', '')} diff --git a/tackerclient/tests/unit/nfvo/__init__.py b/tackerclient/tests/unit/nfvo/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tackerclient/tests/unit/nfvo/test_vim_utils.py b/tackerclient/tests/unit/nfvo/test_vim_utils.py new file mode 100644 index 00000000..58e456f9 --- /dev/null +++ b/tackerclient/tests/unit/nfvo/test_vim_utils.py @@ -0,0 +1,52 @@ +# Copyright 2016 OpenStack Foundation. +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + + +from mock import sentinel +import testtools + +from tackerclient.common import exceptions +from tackerclient.tacker.v1_0.nfvo import vim_utils + + +class CLITestAuthNoAuth(testtools.TestCase): + + def test_args2body_vim(self): + config_param = {'project_id': sentinel.prj_id1, + 'username': sentinel.usrname1, + 'password': sentinel.password1, + 'project_domain_name': sentinel.prj_domain_name1, + 'user_domain_name': sentinel.user_domain.name, } + vim = {} + auth_cred = config_param.copy() + auth_cred.pop('project_id') + auth_cred.pop('project_domain_name') + auth_cred.update({'user_id': ''}) + expected_vim = {'auth_cred': auth_cred, + 'vim_project': + {'id': sentinel.prj_id1, + 'name': '', + 'project_domain_name': sentinel.prj_domain_name1}} + vim_utils.args2body_vim(config_param.copy(), vim) + self.assertEqual(expected_vim, vim) + + def test_args2body_vim_no_project(self): + config_param = {'username': sentinel.usrname1, + 'password': sentinel.password1, + 'user_domain_name': sentinel.user_domain.name, } + vim = {} + self.assertRaises(exceptions.TackerClientException, + vim_utils.args2body_vim, + config_param, vim) diff --git a/tackerclient/tests/unit/vm/test_cli10_vim.py b/tackerclient/tests/unit/vm/test_cli10_vim.py index 99de8530..8b445ebe 100644 --- a/tackerclient/tests/unit/vm/test_cli10_vim.py +++ b/tackerclient/tests/unit/vm/test_cli10_vim.py @@ -34,9 +34,11 @@ class CLITestV10VIMJSON(test_cli10.CLITestV10Base): def setUp(self): plurals = {'vims': 'vim'} super(CLITestV10VIMJSON, self).setUp(plurals=plurals) - self.vim_project = {'name': 'abc', 'id': ''} + self.vim_project = { + 'name': 'abc', 'id': '', + 'project_domain_name': 'prj_domain_name'} self.auth_cred = {'username': 'xyz', 'password': '12345', 'user_id': - ''} + '', 'user_domain_name': 'user_domain_name'} self.auth_url = 'http://1.2.3.4:5000' def test_register_vim_all_params(self): @@ -45,7 +47,9 @@ class CLITestV10VIMJSON(test_cli10.CLITestV10Base): name = 'test_vim' description = 'Vim Description' vim_config = {'auth_url': 'http://1.2.3.4:5000', 'username': 'xyz', - 'password': '12345', 'project_name': 'abc'} + 'password': '12345', 'project_name': 'abc', + 'project_domain_name': 'prj_domain_name', + 'user_domain_name': 'user_domain_name'} args = [ '--config', str(vim_config), '--name', name, @@ -63,7 +67,9 @@ class CLITestV10VIMJSON(test_cli10.CLITestV10Base): my_id = 'my-id' vim_config = {'auth_url': 'http://1.2.3.4:5000', 'username': 'xyz', - 'password': '12345', 'project_name': 'abc'} + 'password': '12345', 'project_name': 'abc', + 'project_domain_name': 'prj_domain_name', + 'user_domain_name': 'user_domain_name'} args = [ '--config', str(vim_config), ] @@ -126,7 +132,9 @@ class CLITestV10VIMJSON(test_cli10.CLITestV10Base): def test_update_vim(self): cmd = vim.UpdateVIM(test_cli10.MyApp(sys.stdout), None) update_config = {'username': 'xyz', 'password': '12345', - 'project_name': 'abc'} + 'project_name': 'abc', + 'project_domain_name': 'prj_domain_name', + 'user_domain_name': 'user_domain_name'} my_id = 'my-id' key = 'config' value = str(update_config)