Implement client to support Kubernetes as VIM
This patch will add changes to support Kubernetes as VIM feature in python-tackerclient. After this change, user have to provide VIM type in VIM config file when creating or updating VIM. The default VIM type is openstack. Partially Implements: blueprint kubernetes-as-vim Change-Id: I1b1610cb89a78a2a8fe134265b83dd469d72fdcd
This commit is contained in:
@@ -80,7 +80,6 @@ class CreateVIM(tackerV10.CreateCommand):
|
|||||||
'specified',
|
'specified',
|
||||||
status_code=404)
|
status_code=404)
|
||||||
vim_obj['auth_url'] = vim_utils.validate_auth_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)
|
vim_utils.args2body_vim(config_param, vim_obj)
|
||||||
tackerV10.update_dict(parsed_args, body[self.resource],
|
tackerV10.update_dict(parsed_args, body[self.resource],
|
||||||
['tenant_id', 'name', 'description',
|
['tenant_id', 'name', 'description',
|
||||||
@@ -127,6 +126,9 @@ class UpdateVIM(tackerV10.UpdateCommand):
|
|||||||
tackerV10.update_dict(parsed_args, body[self.resource],
|
tackerV10.update_dict(parsed_args, body[self.resource],
|
||||||
['tenant_id', 'name', 'description',
|
['tenant_id', 'name', 'description',
|
||||||
'is_default'])
|
'is_default'])
|
||||||
|
# type attribute is read-only, it can't be updated, so remove it
|
||||||
|
# in update method
|
||||||
|
body['vim'].pop('type')
|
||||||
return body
|
return body
|
||||||
|
|
||||||
|
|
||||||
|
@@ -24,17 +24,58 @@ def args2body_vim(config_param, vim):
|
|||||||
:param vim: vim request object
|
:param vim: vim request object
|
||||||
:return: vim body with args populated
|
:return: vim body with args populated
|
||||||
"""
|
"""
|
||||||
vim['vim_project'] = {'name': config_param.pop('project_name', ''),
|
vim_type = ['openstack', 'kubernetes']
|
||||||
|
if 'type' in config_param:
|
||||||
|
vim['type'] = config_param.pop('type', '')
|
||||||
|
if not vim['type'] in vim_type:
|
||||||
|
raise exceptions.TackerClientException(
|
||||||
|
message='Supported VIM types: openstack, kubernetes',
|
||||||
|
status_code=400)
|
||||||
|
else:
|
||||||
|
vim['type'] = 'openstack'
|
||||||
|
if vim['type'] == 'openstack':
|
||||||
|
vim['vim_project'] = {
|
||||||
|
'name': config_param.pop('project_name', ''),
|
||||||
'project_domain_name':
|
'project_domain_name':
|
||||||
config_param.pop('project_domain_name', '')}
|
config_param.pop('project_domain_name', '')}
|
||||||
if not vim['vim_project']['name']:
|
if not vim['vim_project']['name']:
|
||||||
raise exceptions.TackerClientException(message='Project name '
|
raise exceptions.TackerClientException(
|
||||||
'must be specified',
|
message='Project name must be specified',
|
||||||
status_code=404)
|
status_code=404)
|
||||||
vim['auth_cred'] = {'username': config_param.pop('username', ''),
|
vim['auth_cred'] = {'username': config_param.pop('username', ''),
|
||||||
'password': config_param.pop('password', ''),
|
'password': config_param.pop('password', ''),
|
||||||
'user_domain_name':
|
'user_domain_name':
|
||||||
config_param.pop('user_domain_name', '')}
|
config_param.pop('user_domain_name', '')}
|
||||||
|
elif vim['type'] == 'kubernetes':
|
||||||
|
vim['vim_project'] = {
|
||||||
|
'name': config_param.pop('project_name', '')}
|
||||||
|
if not vim['vim_project']['name']:
|
||||||
|
raise exceptions.TackerClientException(
|
||||||
|
message='Project name must be specified in Kubernetes VIM,'
|
||||||
|
'it is namespace in Kubernetes environment',
|
||||||
|
status_code=404)
|
||||||
|
if ('username' in config_param) and ('password' in config_param):
|
||||||
|
vim['auth_cred'] = {
|
||||||
|
'username': config_param.pop('username', ''),
|
||||||
|
'password': config_param.pop('password', '')}
|
||||||
|
elif 'bearer_token' in config_param:
|
||||||
|
vim['auth_cred'] = {
|
||||||
|
'bearer_token': config_param.pop('bearer_token', '')}
|
||||||
|
else:
|
||||||
|
raise exceptions.TackerClientException(
|
||||||
|
message='username and password or bearer_token must be'
|
||||||
|
'provided',
|
||||||
|
status_code=404)
|
||||||
|
if 'ssl_ca_cert' in config_param:
|
||||||
|
ssl_ca_cert = config_param.pop('ssl_ca_cert', '')
|
||||||
|
if ssl_ca_cert == 'None':
|
||||||
|
vim['auth_cred']['ssl_ca_cert'] = None
|
||||||
|
else:
|
||||||
|
vim['auth_cred']['ssl_ca_cert'] = ssl_ca_cert
|
||||||
|
else:
|
||||||
|
raise exceptions.TackerClientException(
|
||||||
|
message='ssl_ca_cert must be provided or leave it with None',
|
||||||
|
status_code=404)
|
||||||
|
|
||||||
|
|
||||||
def validate_auth_url(url):
|
def validate_auth_url(url):
|
||||||
|
@@ -4,3 +4,4 @@ password: '12345'
|
|||||||
project_name: 'abc'
|
project_name: 'abc'
|
||||||
project_domain_name: 'prj_domain_name'
|
project_domain_name: 'prj_domain_name'
|
||||||
user_domain_name: 'user_domain_name'
|
user_domain_name: 'user_domain_name'
|
||||||
|
type: 'openstack'
|
@@ -3,3 +3,4 @@ password: '12345'
|
|||||||
project_name: 'abc'
|
project_name: 'abc'
|
||||||
project_domain_name: 'prj_domain_name'
|
project_domain_name: 'prj_domain_name'
|
||||||
user_domain_name: 'user_domain_name'
|
user_domain_name: 'user_domain_name'
|
||||||
|
type: 'openstack'
|
||||||
|
@@ -0,0 +1,5 @@
|
|||||||
|
auth_url: 'https://1.2.3.4:6443'
|
||||||
|
bearer_token: 'xyz'
|
||||||
|
ssl_ca_cert: None
|
||||||
|
project_name: 'default'
|
||||||
|
type: 'kubernetes'
|
@@ -0,0 +1,4 @@
|
|||||||
|
bearer_token: 'xyz'
|
||||||
|
ssl_ca_cert: None
|
||||||
|
project_name: 'default'
|
||||||
|
type: 'kubernetes'
|
6
tackerclient/tests/unit/vm/samples/vim_k8s_config.yaml
Normal file
6
tackerclient/tests/unit/vm/samples/vim_k8s_config.yaml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
auth_url: 'https://1.2.3.4:6443'
|
||||||
|
username: 'xyz'
|
||||||
|
password: '12345'
|
||||||
|
ssl_ca_cert: 'abcxyz'
|
||||||
|
project_name: 'default'
|
||||||
|
type: 'kubernetes'
|
@@ -0,0 +1,5 @@
|
|||||||
|
username: 'xyz'
|
||||||
|
password: '12345'
|
||||||
|
ssl_ca_cert: 'abcxyz'
|
||||||
|
project_name: 'default'
|
||||||
|
type: 'kubernetes'
|
@@ -40,6 +40,7 @@ class CLITestV10VIMJSON(test_cli10.CLITestV10Base):
|
|||||||
self.auth_cred = {'username': 'xyz', 'password': '12345',
|
self.auth_cred = {'username': 'xyz', 'password': '12345',
|
||||||
'user_domain_name': 'user_domain_name'}
|
'user_domain_name': 'user_domain_name'}
|
||||||
self.auth_url = 'http://1.2.3.4:5000'
|
self.auth_url = 'http://1.2.3.4:5000'
|
||||||
|
self.type = 'openstack'
|
||||||
|
|
||||||
def test_register_vim_all_params(self):
|
def test_register_vim_all_params(self):
|
||||||
cmd = vim.CreateVIM(test_cli10.MyApp(sys.stdout), None)
|
cmd = vim.CreateVIM(test_cli10.MyApp(sys.stdout), None)
|
||||||
@@ -52,9 +53,9 @@ class CLITestV10VIMJSON(test_cli10.CLITestV10Base):
|
|||||||
name,
|
name,
|
||||||
'--config-file', vim_config,
|
'--config-file', vim_config,
|
||||||
'--description', description]
|
'--description', description]
|
||||||
position_names = ['auth_cred', 'vim_project', 'auth_url']
|
position_names = ['auth_cred', 'vim_project', 'auth_url', 'type']
|
||||||
position_values = [self.auth_cred, self.vim_project,
|
position_values = [self.auth_cred, self.vim_project,
|
||||||
self.auth_url]
|
self.auth_url, self.type]
|
||||||
extra_body = {'type': 'openstack', 'name': name,
|
extra_body = {'type': 'openstack', 'name': name,
|
||||||
'description': description, 'is_default': False}
|
'description': description, 'is_default': False}
|
||||||
self._test_create_resource(self._RESOURCE, cmd, None, my_id,
|
self._test_create_resource(self._RESOURCE, cmd, None, my_id,
|
||||||
@@ -72,9 +73,9 @@ class CLITestV10VIMJSON(test_cli10.CLITestV10Base):
|
|||||||
name,
|
name,
|
||||||
'--config-file', vim_config,
|
'--config-file', vim_config,
|
||||||
'--description', description]
|
'--description', description]
|
||||||
position_names = ['auth_cred', 'vim_project', 'auth_url']
|
position_names = ['auth_cred', 'vim_project', 'auth_url', 'type']
|
||||||
position_values = [self.auth_cred, self.vim_project,
|
position_values = [self.auth_cred, self.vim_project,
|
||||||
self.auth_url]
|
self.auth_url, self.type]
|
||||||
extra_body = {'type': 'openstack', 'name': name,
|
extra_body = {'type': 'openstack', 'name': name,
|
||||||
'description': description, 'is_default': False}
|
'description': description, 'is_default': False}
|
||||||
message = 'Auth URL must be specified'
|
message = 'Auth URL must be specified'
|
||||||
@@ -97,11 +98,12 @@ class CLITestV10VIMJSON(test_cli10.CLITestV10Base):
|
|||||||
name,
|
name,
|
||||||
'--config-file', vim_config,
|
'--config-file', vim_config,
|
||||||
]
|
]
|
||||||
position_names = ['auth_cred', 'vim_project', 'auth_url']
|
position_names = ['auth_cred', 'vim_project', 'auth_url', 'type']
|
||||||
position_values = [
|
position_values = [
|
||||||
self.auth_cred,
|
self.auth_cred,
|
||||||
self.vim_project,
|
self.vim_project,
|
||||||
self.auth_url
|
self.auth_url,
|
||||||
|
self.type
|
||||||
]
|
]
|
||||||
extra_body = {'type': 'openstack', 'name': name, '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,
|
||||||
@@ -138,8 +140,9 @@ class CLITestV10VIMJSON(test_cli10.CLITestV10Base):
|
|||||||
'--name', name,
|
'--name', name,
|
||||||
'--description', description,
|
'--description', description,
|
||||||
'--is_default', is_default]
|
'--is_default', is_default]
|
||||||
extra_fields = {'vim_project': self.vim_project, 'auth_cred':
|
extra_fields = {'vim_project': self.vim_project,
|
||||||
self.auth_cred, 'is_default': 'True',
|
'auth_cred': self.auth_cred,
|
||||||
|
'is_default': 'True',
|
||||||
'name': name, 'description': description}
|
'name': name, 'description': description}
|
||||||
self._test_update_resource(self._RESOURCE, cmd, my_id, args,
|
self._test_update_resource(self._RESOURCE, cmd, my_id, args,
|
||||||
extra_fields)
|
extra_fields)
|
||||||
|
172
tackerclient/tests/unit/vm/test_cli10_vim_k8s.py
Normal file
172
tackerclient/tests/unit/vm/test_cli10_vim_k8s.py
Normal file
@@ -0,0 +1,172 @@
|
|||||||
|
# Copyright 2015-2016 Brocade Communications Systems Inc
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
API_VERSION = "1.0"
|
||||||
|
FORMAT = 'json'
|
||||||
|
TOKEN = 'testtoken'
|
||||||
|
ENDURL = 'localurl'
|
||||||
|
|
||||||
|
|
||||||
|
class CLITestV10VIMJSON(test_cli10.CLITestV10Base):
|
||||||
|
_RESOURCE = 'vim'
|
||||||
|
_RESOURCES = 'vims'
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
plurals = {'vims': 'vim'}
|
||||||
|
super(CLITestV10VIMJSON, self).setUp(plurals=plurals)
|
||||||
|
self.vim_project = {'name': 'default'}
|
||||||
|
self.auth_cred = {'username': 'xyz', 'password': '12345',
|
||||||
|
'ssl_ca_cert': 'abcxyz'}
|
||||||
|
self.auth_url = 'https://1.2.3.4:6443'
|
||||||
|
self.type = 'kubernetes'
|
||||||
|
|
||||||
|
def test_register_vim_all_params(self):
|
||||||
|
cmd = vim.CreateVIM(test_cli10.MyApp(sys.stdout), None)
|
||||||
|
name = 'my-name'
|
||||||
|
my_id = 'my-id'
|
||||||
|
description = 'Vim Description'
|
||||||
|
vim_config = utils.get_file_path(
|
||||||
|
'tests/unit/vm/samples/vim_k8s_config.yaml')
|
||||||
|
args = [
|
||||||
|
name,
|
||||||
|
'--config-file', vim_config,
|
||||||
|
'--description', description]
|
||||||
|
position_names = ['auth_cred', 'vim_project', 'auth_url', 'type']
|
||||||
|
position_values = [self.auth_cred, self.vim_project,
|
||||||
|
self.auth_url, self.type]
|
||||||
|
extra_body = {'type': 'kubernetes', '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_k8s_config_without_auth_url.yaml')
|
||||||
|
args = [
|
||||||
|
name,
|
||||||
|
'--config-file', vim_config,
|
||||||
|
'--description', description]
|
||||||
|
position_names = ['auth_cred', 'vim_project', 'auth_url', 'type']
|
||||||
|
position_values = [self.auth_cred, self.vim_project,
|
||||||
|
self.auth_url, self.type]
|
||||||
|
extra_body = {'type': 'kubernetes', '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 = utils.get_file_path(
|
||||||
|
'tests/unit/vm/samples/vim_k8s_config.yaml')
|
||||||
|
args = [
|
||||||
|
name,
|
||||||
|
'--config-file', vim_config,
|
||||||
|
]
|
||||||
|
position_names = ['auth_cred', 'vim_project', 'auth_url', 'type']
|
||||||
|
position_values = [
|
||||||
|
self.auth_cred,
|
||||||
|
self.vim_project,
|
||||||
|
self.auth_url,
|
||||||
|
self.type
|
||||||
|
]
|
||||||
|
extra_body = {'type': 'kubernetes', 'name': name, 'is_default': False}
|
||||||
|
self._test_create_resource(self._RESOURCE, cmd, name, my_id, args,
|
||||||
|
position_names, position_values,
|
||||||
|
extra_body=extra_body)
|
||||||
|
|
||||||
|
def test_list_vims(self):
|
||||||
|
cmd = vim.ListVIM(test_cli10.MyApp(sys.stdout), None)
|
||||||
|
self._test_list_resources(self._RESOURCES, cmd, True)
|
||||||
|
|
||||||
|
def test_show_vim_id(self):
|
||||||
|
cmd = vim.ShowVIM(test_cli10.MyApp(sys.stdout), None)
|
||||||
|
args = ['--fields', 'id', self.test_id]
|
||||||
|
self._test_show_resource(self._RESOURCE, cmd, self.test_id, args,
|
||||||
|
['id'])
|
||||||
|
|
||||||
|
def test_show_vim_id_name(self):
|
||||||
|
cmd = vim.ShowVIM(test_cli10.MyApp(sys.stdout), None)
|
||||||
|
args = ['--fields', 'id', '--fields', 'name', self.test_id]
|
||||||
|
self._test_show_resource(self._RESOURCE, cmd, self.test_id,
|
||||||
|
args, ['id', 'name'])
|
||||||
|
|
||||||
|
def test_update_vim_all_params(self):
|
||||||
|
cmd = vim.UpdateVIM(test_cli10.MyApp(sys.stdout), None)
|
||||||
|
update_config = utils.get_file_path(
|
||||||
|
'tests/unit/vm/samples/vim_k8s_config_without_auth_url.yaml')
|
||||||
|
my_id = 'my-id'
|
||||||
|
name = 'new_name'
|
||||||
|
name = 'new_name'
|
||||||
|
description = 'new_description'
|
||||||
|
is_default = 'True'
|
||||||
|
args = [
|
||||||
|
my_id,
|
||||||
|
'--config-file', str(update_config),
|
||||||
|
'--name', name,
|
||||||
|
'--description', description,
|
||||||
|
'--is_default', is_default]
|
||||||
|
extra_fields = {'vim_project': self.vim_project,
|
||||||
|
'auth_cred': self.auth_cred,
|
||||||
|
'is_default': 'True',
|
||||||
|
'name': name, 'description': description}
|
||||||
|
self._test_update_resource(self._RESOURCE, cmd, my_id, args,
|
||||||
|
extra_fields)
|
||||||
|
|
||||||
|
def test_update_vim_with_mandatory_params(self):
|
||||||
|
cmd = vim.UpdateVIM(test_cli10.MyApp(sys.stdout), None)
|
||||||
|
update_config = utils.get_file_path(
|
||||||
|
'tests/unit/vm/samples/vim_k8s_config_without_auth_url.yaml')
|
||||||
|
my_id = 'my-id'
|
||||||
|
args = [
|
||||||
|
my_id,
|
||||||
|
'--config-file', str(update_config)]
|
||||||
|
extra_fields = {'vim_project': self.vim_project,
|
||||||
|
'auth_cred': self.auth_cred}
|
||||||
|
self._test_update_resource(self._RESOURCE, cmd, my_id, args,
|
||||||
|
extra_fields)
|
||||||
|
|
||||||
|
def test_delete_vim(self):
|
||||||
|
cmd = vim.DeleteVIM(test_cli10.MyApp(sys.stdout), None)
|
||||||
|
my_id = 'my-id'
|
||||||
|
args = [my_id]
|
||||||
|
self._test_delete_resource(self._RESOURCE, cmd, my_id, args)
|
||||||
|
|
||||||
|
def test_multi_delete_vim(self):
|
||||||
|
cmd = vim.DeleteVIM(test_cli10.MyApp(sys.stdout), None)
|
||||||
|
vim_ids = 'my-id1 my-id2 my-id3'
|
||||||
|
args = [vim_ids]
|
||||||
|
self._test_delete_resource(self._RESOURCE, cmd, vim_ids, args)
|
@@ -0,0 +1,170 @@
|
|||||||
|
# Copyright 2015-2016 Brocade Communications Systems Inc
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
API_VERSION = "1.0"
|
||||||
|
FORMAT = 'json'
|
||||||
|
TOKEN = 'testtoken'
|
||||||
|
ENDURL = 'localurl'
|
||||||
|
|
||||||
|
|
||||||
|
class CLITestV10VIMJSON(test_cli10.CLITestV10Base):
|
||||||
|
_RESOURCE = 'vim'
|
||||||
|
_RESOURCES = 'vims'
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
plurals = {'vims': 'vim'}
|
||||||
|
super(CLITestV10VIMJSON, self).setUp(plurals=plurals)
|
||||||
|
self.vim_project = {'name': 'default'}
|
||||||
|
self.auth_cred = {'bearer_token': 'xyz', 'ssl_ca_cert': None}
|
||||||
|
self.auth_url = 'https://1.2.3.4:6443'
|
||||||
|
self.type = 'kubernetes'
|
||||||
|
|
||||||
|
def test_register_vim_all_params(self):
|
||||||
|
cmd = vim.CreateVIM(test_cli10.MyApp(sys.stdout), None)
|
||||||
|
name = 'my-name'
|
||||||
|
my_id = 'my-id'
|
||||||
|
description = 'Vim Description'
|
||||||
|
vim_config = utils.get_file_path(
|
||||||
|
'tests/unit/vm/samples/vim_k8s_bearer_token.yaml')
|
||||||
|
args = [
|
||||||
|
name,
|
||||||
|
'--config-file', vim_config,
|
||||||
|
'--description', description]
|
||||||
|
position_names = ['auth_cred', 'vim_project', 'auth_url', 'type']
|
||||||
|
position_values = [self.auth_cred, self.vim_project,
|
||||||
|
self.auth_url, self.type]
|
||||||
|
extra_body = {'type': 'kubernetes', '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_k8s_bearer_token_without_auth_url.yaml')
|
||||||
|
args = [
|
||||||
|
name,
|
||||||
|
'--config-file', vim_config,
|
||||||
|
'--description', description]
|
||||||
|
position_names = ['auth_cred', 'vim_project', 'auth_url', 'type']
|
||||||
|
position_values = [self.auth_cred, self.vim_project,
|
||||||
|
self.auth_url, self.type]
|
||||||
|
extra_body = {'type': 'kubernetes', '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 = utils.get_file_path(
|
||||||
|
'tests/unit/vm/samples/vim_k8s_bearer_token.yaml')
|
||||||
|
args = [
|
||||||
|
name,
|
||||||
|
'--config-file', vim_config,
|
||||||
|
]
|
||||||
|
position_names = ['auth_cred', 'vim_project', 'auth_url', 'type']
|
||||||
|
position_values = [
|
||||||
|
self.auth_cred,
|
||||||
|
self.vim_project,
|
||||||
|
self.auth_url,
|
||||||
|
self.type
|
||||||
|
]
|
||||||
|
extra_body = {'type': 'kubernetes', 'name': name, 'is_default': False}
|
||||||
|
self._test_create_resource(self._RESOURCE, cmd, name, my_id, args,
|
||||||
|
position_names, position_values,
|
||||||
|
extra_body=extra_body)
|
||||||
|
|
||||||
|
def test_list_vims(self):
|
||||||
|
cmd = vim.ListVIM(test_cli10.MyApp(sys.stdout), None)
|
||||||
|
self._test_list_resources(self._RESOURCES, cmd, True)
|
||||||
|
|
||||||
|
def test_show_vim_id(self):
|
||||||
|
cmd = vim.ShowVIM(test_cli10.MyApp(sys.stdout), None)
|
||||||
|
args = ['--fields', 'id', self.test_id]
|
||||||
|
self._test_show_resource(self._RESOURCE, cmd, self.test_id, args,
|
||||||
|
['id'])
|
||||||
|
|
||||||
|
def test_show_vim_id_name(self):
|
||||||
|
cmd = vim.ShowVIM(test_cli10.MyApp(sys.stdout), None)
|
||||||
|
args = ['--fields', 'id', '--fields', 'name', self.test_id]
|
||||||
|
self._test_show_resource(self._RESOURCE, cmd, self.test_id,
|
||||||
|
args, ['id', 'name'])
|
||||||
|
|
||||||
|
def test_update_vim_all_params(self):
|
||||||
|
cmd = vim.UpdateVIM(test_cli10.MyApp(sys.stdout), None)
|
||||||
|
update_config = utils.get_file_path(
|
||||||
|
'tests/unit/vm/samples/vim_k8s_bearer_token_without_auth_url.yaml')
|
||||||
|
my_id = 'my-id'
|
||||||
|
name = 'new_name'
|
||||||
|
description = 'new_description'
|
||||||
|
is_default = 'True'
|
||||||
|
args = [
|
||||||
|
my_id,
|
||||||
|
'--config-file', str(update_config),
|
||||||
|
'--name', name,
|
||||||
|
'--description', description,
|
||||||
|
'--is_default', is_default]
|
||||||
|
extra_fields = {'vim_project': self.vim_project,
|
||||||
|
'auth_cred': self.auth_cred,
|
||||||
|
'is_default': 'True',
|
||||||
|
'name': name, 'description': description}
|
||||||
|
self._test_update_resource(self._RESOURCE, cmd, my_id, args,
|
||||||
|
extra_fields)
|
||||||
|
|
||||||
|
def test_update_vim_with_mandatory_params(self):
|
||||||
|
cmd = vim.UpdateVIM(test_cli10.MyApp(sys.stdout), None)
|
||||||
|
update_config = utils.get_file_path(
|
||||||
|
'tests/unit/vm/samples/vim_k8s_bearer_token_without_auth_url.yaml')
|
||||||
|
my_id = 'my-id'
|
||||||
|
args = [
|
||||||
|
my_id,
|
||||||
|
'--config-file', str(update_config)]
|
||||||
|
extra_fields = {'vim_project': self.vim_project,
|
||||||
|
'auth_cred': self.auth_cred}
|
||||||
|
self._test_update_resource(self._RESOURCE, cmd, my_id, args,
|
||||||
|
extra_fields)
|
||||||
|
|
||||||
|
def test_delete_vim(self):
|
||||||
|
cmd = vim.DeleteVIM(test_cli10.MyApp(sys.stdout), None)
|
||||||
|
my_id = 'my-id'
|
||||||
|
args = [my_id]
|
||||||
|
self._test_delete_resource(self._RESOURCE, cmd, my_id, args)
|
||||||
|
|
||||||
|
def test_multi_delete_vim(self):
|
||||||
|
cmd = vim.DeleteVIM(test_cli10.MyApp(sys.stdout), None)
|
||||||
|
vim_ids = 'my-id1 my-id2 my-id3'
|
||||||
|
args = [vim_ids]
|
||||||
|
self._test_delete_resource(self._RESOURCE, cmd, vim_ids, args)
|
@@ -28,22 +28,59 @@ class TestVIMUtils(testtools.TestCase):
|
|||||||
'username': sentinel.usrname1,
|
'username': sentinel.usrname1,
|
||||||
'password': sentinel.password1,
|
'password': sentinel.password1,
|
||||||
'project_domain_name': sentinel.prj_domain_name1,
|
'project_domain_name': sentinel.prj_domain_name1,
|
||||||
'user_domain_name': sentinel.user_domain.name, }
|
'user_domain_name': sentinel.user_domain.name,
|
||||||
|
'type': 'openstack'}
|
||||||
vim = {}
|
vim = {}
|
||||||
auth_cred = config_param.copy()
|
auth_cred = config_param.copy()
|
||||||
auth_cred.pop('project_name')
|
auth_cred.pop('project_name')
|
||||||
auth_cred.pop('project_domain_name')
|
auth_cred.pop('project_domain_name')
|
||||||
|
auth_cred.pop('type')
|
||||||
expected_vim = {'auth_cred': auth_cred,
|
expected_vim = {'auth_cred': auth_cred,
|
||||||
'vim_project':
|
'vim_project':
|
||||||
{'name': sentinel.prj_name,
|
{'name': sentinel.prj_name,
|
||||||
'project_domain_name': sentinel.prj_domain_name1}}
|
'project_domain_name': sentinel.prj_domain_name1},
|
||||||
|
'type': 'openstack'}
|
||||||
|
vim_utils.args2body_vim(config_param.copy(), vim)
|
||||||
|
self.assertEqual(expected_vim, vim)
|
||||||
|
|
||||||
|
def test_args2body_kubernetes_vim(self):
|
||||||
|
config_param = {'username': sentinel.usrname1,
|
||||||
|
'password': sentinel.password1,
|
||||||
|
'ssl_ca_cert': 'abcxyz',
|
||||||
|
'project_name': sentinel.prj_name,
|
||||||
|
'type': 'kubernetes'}
|
||||||
|
vim = {}
|
||||||
|
auth_cred = config_param.copy()
|
||||||
|
auth_cred.pop('project_name')
|
||||||
|
auth_cred.pop('type')
|
||||||
|
expected_vim = {'auth_cred': auth_cred,
|
||||||
|
'vim_project':
|
||||||
|
{'name': sentinel.prj_name},
|
||||||
|
'type': 'kubernetes'}
|
||||||
|
vim_utils.args2body_vim(config_param.copy(), vim)
|
||||||
|
self.assertEqual(expected_vim, vim)
|
||||||
|
|
||||||
|
def test_args2body_kubernetes_vim_bearer(self):
|
||||||
|
config_param = {'bearer_token': sentinel.bearer_token,
|
||||||
|
'ssl_ca_cert': None,
|
||||||
|
'project_name': sentinel.prj_name,
|
||||||
|
'type': 'kubernetes'}
|
||||||
|
vim = {}
|
||||||
|
auth_cred = config_param.copy()
|
||||||
|
auth_cred.pop('project_name')
|
||||||
|
auth_cred.pop('type')
|
||||||
|
expected_vim = {'auth_cred': auth_cred,
|
||||||
|
'vim_project':
|
||||||
|
{'name': sentinel.prj_name},
|
||||||
|
'type': 'kubernetes'}
|
||||||
vim_utils.args2body_vim(config_param.copy(), vim)
|
vim_utils.args2body_vim(config_param.copy(), vim)
|
||||||
self.assertEqual(expected_vim, vim)
|
self.assertEqual(expected_vim, vim)
|
||||||
|
|
||||||
def test_args2body_vim_no_project(self):
|
def test_args2body_vim_no_project(self):
|
||||||
config_param = {'username': sentinel.usrname1,
|
config_param = {'username': sentinel.usrname1,
|
||||||
'password': sentinel.password1,
|
'password': sentinel.password1,
|
||||||
'user_domain_name': sentinel.user_domain.name, }
|
'user_domain_name': sentinel.user_domain.name,
|
||||||
|
'type': 'openstack'}
|
||||||
vim = {}
|
vim = {}
|
||||||
self.assertRaises(exceptions.TackerClientException,
|
self.assertRaises(exceptions.TackerClientException,
|
||||||
vim_utils.args2body_vim,
|
vim_utils.args2body_vim,
|
||||||
|
Reference in New Issue
Block a user