1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 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)
|