Merge "Remove '--config' option when create/update a vim"

This commit is contained in:
Jenkins 2016-08-18 02:59:51 +00:00 committed by Gerrit Code Review
commit 6b677a8f38
5 changed files with 67 additions and 46 deletions
tackerclient

@ -179,3 +179,9 @@ def validate_url(url):
if not url_parts.scheme or not url_parts.netloc or not url_parts.port: if not url_parts.scheme or not url_parts.netloc or not url_parts.port:
raise exceptions.TackerClientException(message='Invalid URL') raise exceptions.TackerClientException(message='Invalid URL')
return url_parts 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

@ -44,11 +44,10 @@ class CreateVIM(tackerV10.CreateCommand):
resource = _VIM resource = _VIM
def add_known_arguments(self, parser): def add_known_arguments(self, parser):
group = parser.add_mutually_exclusive_group(required=True) parser.add_argument(
group.add_argument('--config-file', help='Specify VIM specific ' '--config-file',
'config parameters in a file') required=True,
group.add_argument('--config', help='Specify VIM config parameters ' help='Specify VIM specific config parameters in a file')
'as a direct input')
parser.add_argument( parser.add_argument(
'name', metavar='NAME', 'name', metavar='NAME',
help='Set a name for the VIM') help='Set a name for the VIM')
@ -67,9 +66,6 @@ class CreateVIM(tackerV10.CreateCommand):
with open(parsed_args.config_file) as f: with open(parsed_args.config_file) as f:
vim_config = f.read() vim_config = f.read()
config_param = yaml.load(vim_config) 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] vim_obj = body[self.resource]
try: try:
auth_url = config_param.pop('auth_url') auth_url = config_param.pop('auth_url')
@ -92,13 +88,9 @@ class UpdateVIM(tackerV10.UpdateCommand):
resource = _VIM resource = _VIM
def add_known_arguments(self, parser): def add_known_arguments(self, parser):
group = parser.add_mutually_exclusive_group(required=True) parser.add_argument(
group.add_argument(
'--config-file', '--config-file',
help='Specify VIM specific config parameters in a 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( parser.add_argument(
'--is-default', '--is-default',
action='store_true', action='store_true',
@ -112,9 +104,6 @@ class UpdateVIM(tackerV10.UpdateCommand):
with open(parsed_args.config_file) as f: with open(parsed_args.config_file) as f:
config_yaml = f.read() config_yaml = f.read()
config_param = yaml.load(config_yaml) 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: if 'auth_url' in config_param:
raise exceptions.TackerClientException(message='Auth URL cannot ' raise exceptions.TackerClientException(message='Auth URL cannot '
'be updated', 'be updated',

@ -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'

@ -0,0 +1,5 @@
username: 'xyz'
password: '12345'
project_name: 'abc'
project_domain_name: 'prj_domain_name'
user_domain_name: 'user_domain_name'

@ -16,6 +16,8 @@
import sys import sys
from tackerclient.common import exceptions
from tackerclient.common import utils
from tackerclient.tacker.v1_0.nfvo import vim from tackerclient.tacker.v1_0.nfvo import vim
from tackerclient.tests.unit import test_cli10 from tackerclient.tests.unit import test_cli10
@ -44,49 +46,64 @@ class CLITestV10VIMJSON(test_cli10.CLITestV10Base):
name = 'my-name' name = 'my-name'
my_id = 'my-id' my_id = 'my-id'
description = 'Vim Description' description = 'Vim Description'
vim_config = {'auth_url': 'http://1.2.3.4:5000', 'username': 'xyz', vim_config = utils.get_file_path(
'password': '12345', 'project_name': 'abc', 'tests/unit/vm/samples/vim_config.yaml')
'project_domain_name': 'prj_domain_name',
'user_domain_name': 'user_domain_name'}
args = [ args = [
name, name,
'--config', str(vim_config), '--config-file', vim_config,
'--description', description, '--description', description]
] position_names = ['auth_cred', 'vim_project', 'auth_url']
position_names = ['name', 'auth_cred', 'vim_project', 'auth_url'] position_values = [self.auth_cred, self.vim_project,
position_values = [ self.auth_url]
name, extra_body = {'type': 'openstack', 'name': name,
self.auth_cred, 'description': description, 'is_default': False}
self.vim_project, self._test_create_resource(self._RESOURCE, cmd, None, my_id,
self.auth_url
]
extra_body = {'type': 'openstack', 'description': description,
'is_default': False}
self._test_create_resource(self._RESOURCE, cmd, name, my_id,
args, position_names, position_values, args, position_names, position_values,
extra_body=extra_body) 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): def test_register_vim_with_mandatory_params(self):
cmd = vim.CreateVIM(test_cli10.MyApp(sys.stdout), None) cmd = vim.CreateVIM(test_cli10.MyApp(sys.stdout), None)
name = 'my-name' name = 'my-name'
my_id = 'my-id' my_id = 'my-id'
vim_config = {'auth_url': 'http://1.2.3.4:5000', 'username': 'xyz', vim_config = utils.get_file_path(
'password': '12345', 'project_name': 'abc', 'tests/unit/vm/samples/vim_config.yaml')
'project_domain_name': 'prj_domain_name',
'user_domain_name': 'user_domain_name'}
args = [ args = [
name, 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 = [ position_values = [
name,
self.auth_cred, self.auth_cred,
self.vim_project, self.vim_project,
self.auth_url 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, self._test_create_resource(self._RESOURCE, cmd, name, my_id, args,
position_names, position_values, position_names, position_values,
extra_body=extra_body) extra_body=extra_body)
@ -109,12 +126,10 @@ class CLITestV10VIMJSON(test_cli10.CLITestV10Base):
def test_update_vim(self): def test_update_vim(self):
cmd = vim.UpdateVIM(test_cli10.MyApp(sys.stdout), None) cmd = vim.UpdateVIM(test_cli10.MyApp(sys.stdout), None)
update_config = {'username': 'xyz', 'password': '12345', update_config = utils.get_file_path(
'project_name': 'abc', 'tests/unit/vm/samples/vim_config_without_auth_url.yaml')
'project_domain_name': 'prj_domain_name',
'user_domain_name': 'user_domain_name'}
my_id = 'my-id' my_id = 'my-id'
key = 'config' key = 'config-file'
value = str(update_config) value = str(update_config)
extra_fields = {'vim_project': self.vim_project, 'auth_cred': extra_fields = {'vim_project': self.vim_project, 'auth_cred':
self.auth_cred, 'is_default': False} self.auth_cred, 'is_default': False}