From e5457e506243bb8b366dd4263d1c37df2d7169b5 Mon Sep 17 00:00:00 2001 From: xu-haiwei <hai-xu@xr.jp.nec.com> Date: Tue, 31 May 2016 11:26:56 +0900 Subject: [PATCH] Remove '--config' option when create/update a vim When create/update a vim, only enable '--config-file' option, will remove '--config' option. Change-Id: I8a728134ce0229db98de10bff5f4f46e7f2a9f2c Closes-bug: #1587216 --- tackerclient/common/utils.py | 6 ++ tackerclient/tacker/v1_0/nfvo/vim.py | 21 ++---- .../tests/unit/vm/samples/vim_config.yaml | 6 ++ .../samples/vim_config_without_auth_url.yaml | 5 ++ tackerclient/tests/unit/vm/test_cli10_vim.py | 75 +++++++++++-------- 5 files changed, 67 insertions(+), 46 deletions(-) create mode 100644 tackerclient/tests/unit/vm/samples/vim_config.yaml create mode 100644 tackerclient/tests/unit/vm/samples/vim_config_without_auth_url.yaml diff --git a/tackerclient/common/utils.py b/tackerclient/common/utils.py index 08d833f6..6a336369 100644 --- a/tackerclient/common/utils.py +++ b/tackerclient/common/utils.py @@ -179,3 +179,9 @@ def validate_url(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)) + return file_path diff --git a/tackerclient/tacker/v1_0/nfvo/vim.py b/tackerclient/tacker/v1_0/nfvo/vim.py index 9d59d9cd..fef6dc14 100644 --- a/tackerclient/tacker/v1_0/nfvo/vim.py +++ b/tackerclient/tacker/v1_0/nfvo/vim.py @@ -44,11 +44,10 @@ class CreateVIM(tackerV10.CreateCommand): resource = _VIM def add_known_arguments(self, parser): - group = parser.add_mutually_exclusive_group(required=True) - group.add_argument('--config-file', help='Specify VIM specific ' - 'config parameters in a file') - group.add_argument('--config', help='Specify VIM config parameters ' - 'as a direct input') + parser.add_argument( + '--config-file', + required=True, + help='Specify VIM specific config parameters in a file') parser.add_argument( 'name', metavar='NAME', help='Set a name for the VIM') @@ -67,9 +66,6 @@ class CreateVIM(tackerV10.CreateCommand): with open(parsed_args.config_file) as f: vim_config = f.read() config_param = yaml.load(vim_config) - if parsed_args.config: - parsed_args.config = parsed_args.config.decode('unicode_escape') - config_param = yaml.load(parsed_args.config) vim_obj = body[self.resource] try: auth_url = config_param.pop('auth_url') @@ -92,13 +88,9 @@ class UpdateVIM(tackerV10.UpdateCommand): resource = _VIM def add_known_arguments(self, parser): - group = parser.add_mutually_exclusive_group(required=True) - group.add_argument( + parser.add_argument( '--config-file', help='Specify VIM specific config parameters in a file') - group.add_argument( - '--config', - help='Specify VIM config parameters as a direct input') parser.add_argument( '--is-default', action='store_true', @@ -112,9 +104,6 @@ class UpdateVIM(tackerV10.UpdateCommand): with open(parsed_args.config_file) as f: config_yaml = f.read() config_param = yaml.load(config_yaml) - if parsed_args.config: - parsed_args.config = parsed_args.config.decode('unicode_escape') - config_param = yaml.load(parsed_args.config) if 'auth_url' in config_param: raise exceptions.TackerClientException(message='Auth URL cannot ' 'be updated', diff --git a/tackerclient/tests/unit/vm/samples/vim_config.yaml b/tackerclient/tests/unit/vm/samples/vim_config.yaml new file mode 100644 index 00000000..aa9dbc0b --- /dev/null +++ b/tackerclient/tests/unit/vm/samples/vim_config.yaml @@ -0,0 +1,6 @@ +auth_url: 'http://1.2.3.4:5000' +username: 'xyz' +password: '12345' +project_name: 'abc' +project_domain_name: 'prj_domain_name' +user_domain_name: 'user_domain_name' diff --git a/tackerclient/tests/unit/vm/samples/vim_config_without_auth_url.yaml b/tackerclient/tests/unit/vm/samples/vim_config_without_auth_url.yaml new file mode 100644 index 00000000..db73c40d --- /dev/null +++ b/tackerclient/tests/unit/vm/samples/vim_config_without_auth_url.yaml @@ -0,0 +1,5 @@ +username: 'xyz' +password: '12345' +project_name: 'abc' +project_domain_name: 'prj_domain_name' +user_domain_name: 'user_domain_name' diff --git a/tackerclient/tests/unit/vm/test_cli10_vim.py b/tackerclient/tests/unit/vm/test_cli10_vim.py index cba62816..f8dab37b 100644 --- a/tackerclient/tests/unit/vm/test_cli10_vim.py +++ b/tackerclient/tests/unit/vm/test_cli10_vim.py @@ -16,6 +16,8 @@ import sys +from tackerclient.common import exceptions +from tackerclient.common import utils from tackerclient.tacker.v1_0.nfvo import vim from tackerclient.tests.unit import test_cli10 @@ -44,49 +46,64 @@ class CLITestV10VIMJSON(test_cli10.CLITestV10Base): name = 'my-name' my_id = 'my-id' description = 'Vim Description' - vim_config = {'auth_url': 'http://1.2.3.4:5000', 'username': 'xyz', - 'password': '12345', 'project_name': 'abc', - 'project_domain_name': 'prj_domain_name', - 'user_domain_name': 'user_domain_name'} + vim_config = utils.get_file_path( + 'tests/unit/vm/samples/vim_config.yaml') args = [ name, - '--config', str(vim_config), - '--description', description, - ] - position_names = ['name', 'auth_cred', 'vim_project', 'auth_url'] - position_values = [ - name, - self.auth_cred, - self.vim_project, - self.auth_url - ] - extra_body = {'type': 'openstack', 'description': description, - 'is_default': False} - self._test_create_resource(self._RESOURCE, cmd, name, my_id, + '--config-file', vim_config, + '--description', description] + position_names = ['auth_cred', 'vim_project', 'auth_url'] + position_values = [self.auth_cred, self.vim_project, + self.auth_url] + extra_body = {'type': 'openstack', 'name': name, + 'description': description, 'is_default': False} + self._test_create_resource(self._RESOURCE, cmd, None, my_id, args, position_names, position_values, extra_body=extra_body) + def test_register_vim_with_no_auth_url(self): + cmd = vim.CreateVIM(test_cli10.MyApp(sys.stdout), None) + my_id = 'my-id' + name = 'test_vim' + description = 'Vim Description' + vim_config = utils.get_file_path( + 'tests/unit/vm/samples/vim_config_without_auth_url.yaml') + args = [ + name, + '--config-file', vim_config, + '--description', description] + position_names = ['auth_cred', 'vim_project', 'auth_url'] + position_values = [self.auth_cred, self.vim_project, + self.auth_url] + extra_body = {'type': 'openstack', 'name': name, + 'description': description, 'is_default': False} + message = 'Auth URL must be specified' + ex = self.assertRaises(exceptions.TackerClientException, + self._test_create_resource, + self._RESOURCE, cmd, None, my_id, args, + position_names, position_values, + extra_body=extra_body) + self.assertEqual(message, ex.message) + self.assertEqual(404, ex.status_code) + def test_register_vim_with_mandatory_params(self): cmd = vim.CreateVIM(test_cli10.MyApp(sys.stdout), None) name = 'my-name' my_id = 'my-id' - vim_config = {'auth_url': 'http://1.2.3.4:5000', 'username': 'xyz', - 'password': '12345', 'project_name': 'abc', - 'project_domain_name': 'prj_domain_name', - 'user_domain_name': 'user_domain_name'} + vim_config = utils.get_file_path( + 'tests/unit/vm/samples/vim_config.yaml') args = [ name, - '--config', str(vim_config), + '--config-file', vim_config, ] - position_names = ['name', 'auth_cred', 'vim_project', 'auth_url'] + position_names = ['auth_cred', 'vim_project', 'auth_url'] position_values = [ - name, self.auth_cred, self.vim_project, self.auth_url ] - extra_body = {'type': 'openstack', 'is_default': False} + extra_body = {'type': 'openstack', 'name': name, 'is_default': False} self._test_create_resource(self._RESOURCE, cmd, name, my_id, args, position_names, position_values, extra_body=extra_body) @@ -109,12 +126,10 @@ 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_domain_name': 'prj_domain_name', - 'user_domain_name': 'user_domain_name'} + update_config = utils.get_file_path( + 'tests/unit/vm/samples/vim_config_without_auth_url.yaml') my_id = 'my-id' - key = 'config' + key = 'config-file' value = str(update_config) extra_fields = {'vim_project': self.vim_project, 'auth_cred': self.auth_cred, 'is_default': False}