Merge "Remove '--config' option when create/update a vim"
This commit is contained in:
commit
6b677a8f38
tackerclient
common
tacker/v1_0/nfvo
tests/unit/vm
@ -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
|
||||
|
@ -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',
|
||||
|
6
tackerclient/tests/unit/vm/samples/vim_config.yaml
Normal file
6
tackerclient/tests/unit/vm/samples/vim_config.yaml
Normal file
@ -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
|
||||
|
||||
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}
|
||||
|
Loading…
x
Reference in New Issue
Block a user