Merge "VIM should accept valid boolean values for is_default"
This commit is contained in:
commit
f41274150b
@ -16,6 +16,7 @@ cmd2==0.8.2
|
|||||||
contextlib2==0.5.5
|
contextlib2==0.5.5
|
||||||
coverage==4.0
|
coverage==4.0
|
||||||
cryptography==2.1
|
cryptography==2.1
|
||||||
|
ddt===1.0.1
|
||||||
debtcollector==1.19.0
|
debtcollector==1.19.0
|
||||||
decorator==4.2.1
|
decorator==4.2.1
|
||||||
deprecation==2.0
|
deprecation==2.0
|
||||||
|
@ -351,6 +351,7 @@ RESOURCE_ATTRIBUTE_MAP = {
|
|||||||
'allow_post': True,
|
'allow_post': True,
|
||||||
'allow_put': True,
|
'allow_put': True,
|
||||||
'is_visible': True,
|
'is_visible': True,
|
||||||
|
'validate': {'type:boolean': None},
|
||||||
'default': False
|
'default': False
|
||||||
},
|
},
|
||||||
'created_at': {
|
'created_at': {
|
||||||
|
@ -32,6 +32,7 @@ import testtools
|
|||||||
|
|
||||||
from tacker.common import config
|
from tacker.common import config
|
||||||
from tacker.common import rpc as n_rpc
|
from tacker.common import rpc as n_rpc
|
||||||
|
from tacker import context
|
||||||
from tacker import manager
|
from tacker import manager
|
||||||
from tacker.tests import fake_notifier
|
from tacker.tests import fake_notifier
|
||||||
from tacker.tests import post_mortem_debug
|
from tacker.tests import post_mortem_debug
|
||||||
@ -181,6 +182,9 @@ class BaseTestCase(testtools.TestCase):
|
|||||||
if sys.version_info < (2, 7) and getattr(self, 'fmt', '') == 'xml':
|
if sys.version_info < (2, 7) and getattr(self, 'fmt', '') == 'xml':
|
||||||
raise self.skipException('XML Testing Skipped in Py26')
|
raise self.skipException('XML Testing Skipped in Py26')
|
||||||
|
|
||||||
|
def fake_admin_context(self):
|
||||||
|
return context.get_admin_context()
|
||||||
|
|
||||||
def config(self, **kw):
|
def config(self, **kw):
|
||||||
"""Override some configuration values.
|
"""Override some configuration values.
|
||||||
|
|
||||||
|
0
tacker/tests/unit/api/__init__.py
Normal file
0
tacker/tests/unit/api/__init__.py
Normal file
0
tacker/tests/unit/api/v1/__init__.py
Normal file
0
tacker/tests/unit/api/v1/__init__.py
Normal file
128
tacker/tests/unit/api/v1/test_vim.py
Normal file
128
tacker/tests/unit/api/v1/test_vim.py
Normal file
@ -0,0 +1,128 @@
|
|||||||
|
# Copyright (C) 2018 NTT DATA
|
||||||
|
# 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 ddt
|
||||||
|
import mock
|
||||||
|
import six
|
||||||
|
from webob import exc
|
||||||
|
|
||||||
|
from tacker.api.v1 import base as v1_base
|
||||||
|
from tacker.extensions import nfvo
|
||||||
|
from tacker.nfvo import nfvo_plugin
|
||||||
|
from tacker.tests.unit import base
|
||||||
|
from tacker import wsgi
|
||||||
|
|
||||||
|
|
||||||
|
def get_vim_config():
|
||||||
|
return {
|
||||||
|
"vim": {
|
||||||
|
"tenant_id": 'test-project',
|
||||||
|
"type": "openstack",
|
||||||
|
"auth_url": 'http://localhost:5000',
|
||||||
|
"auth_cred": {
|
||||||
|
"username": "test_user",
|
||||||
|
"user_domain_name": "Default",
|
||||||
|
"password": "password"
|
||||||
|
},
|
||||||
|
"vim_project": {
|
||||||
|
"name": "test_project",
|
||||||
|
"project_domain_name": "Default"
|
||||||
|
},
|
||||||
|
"name": "VIM1",
|
||||||
|
"description": "Additional site",
|
||||||
|
"is_default": False
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ddt.ddt
|
||||||
|
class VIMCreateTestCase(base.TestCase):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(VIMCreateTestCase, self).setUp()
|
||||||
|
plugin = nfvo_plugin.NfvoPlugin()
|
||||||
|
resource_name = 'vim'
|
||||||
|
collection_name = resource_name + "s"
|
||||||
|
attribute_info = nfvo.RESOURCE_ATTRIBUTE_MAP[collection_name]
|
||||||
|
self.controller = v1_base.Controller(plugin, collection_name,
|
||||||
|
resource_name, attribute_info)
|
||||||
|
|
||||||
|
def _vim_create_response(self):
|
||||||
|
return {
|
||||||
|
'auth_cred': {
|
||||||
|
'auth_url': 'http://localhost:5000',
|
||||||
|
'cert_verify': 'False',
|
||||||
|
'key_type': 'barbican_key',
|
||||||
|
'password': '***',
|
||||||
|
'project_domain_name': 'Default',
|
||||||
|
'project_id': None,
|
||||||
|
'project_name': 'nfv',
|
||||||
|
'secret_uuid': '***',
|
||||||
|
'user_domain_name': 'Default',
|
||||||
|
'username': 'test_user'
|
||||||
|
},
|
||||||
|
'auth_url': 'http://localhost:5000',
|
||||||
|
'created_at': None,
|
||||||
|
'description': 'Additional site',
|
||||||
|
'id': '73493efe-3616-414c-bf87-bf450d0b3650',
|
||||||
|
'is_default': False,
|
||||||
|
'name': 'VIM1',
|
||||||
|
'placement_attr': {
|
||||||
|
'regions': [
|
||||||
|
'RegionOne'
|
||||||
|
]
|
||||||
|
},
|
||||||
|
'shared': False,
|
||||||
|
'status': 'PENDING',
|
||||||
|
'tenant_id': 'test-project',
|
||||||
|
'type': 'openstack',
|
||||||
|
'updated_at': None,
|
||||||
|
'vim_project': {
|
||||||
|
'name': 'test_project'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@mock.patch.object(nfvo_plugin.NfvoPlugin, 'create_vim')
|
||||||
|
def test_create_vim(self, mock_create_vim):
|
||||||
|
vim_dict = get_vim_config()
|
||||||
|
request = wsgi.Request.blank(
|
||||||
|
"/vims.json", method='POST',
|
||||||
|
headers={'Content-Type': "application/json"})
|
||||||
|
request.environ['tacker.context'] = self.fake_admin_context()
|
||||||
|
mock_create_vim.return_value = self._vim_create_response()
|
||||||
|
|
||||||
|
result = self.controller.create(request, vim_dict)
|
||||||
|
# End API response doesn't contain the 'shared' attribute so pop it
|
||||||
|
# from dict
|
||||||
|
resp_dict = self._vim_create_response()
|
||||||
|
resp_dict.pop('shared')
|
||||||
|
# Check whether VIM is created with the provided vim_details
|
||||||
|
self.assertEqual(resp_dict, result['vim'])
|
||||||
|
|
||||||
|
@ddt.data({'is_default': 'ABC'},
|
||||||
|
{'is_default': 123},
|
||||||
|
{'is_default': ''})
|
||||||
|
def test_create_vim_with_invalid_is_default(self, value):
|
||||||
|
vim_dict = get_vim_config()
|
||||||
|
vim_dict['vim']['is_default'] = value
|
||||||
|
request = wsgi.Request.blank("/vims.json", method='POST',
|
||||||
|
headers={'Content-Type': "application/json"})
|
||||||
|
request.environ['tacker.context'] = self.fake_admin_context()
|
||||||
|
msg = ("Invalid input for is_default. Reason: '%s' is not a "
|
||||||
|
"valid boolean value." % vim_dict['vim']['is_default'])
|
||||||
|
exp = self.assertRaises(exc.HTTPBadRequest,
|
||||||
|
self.controller.create,
|
||||||
|
request, vim_dict)
|
||||||
|
self.assertEqual(msg, six.text_type(exp))
|
@ -13,11 +13,11 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_config import fixture as config_fixture
|
from oslo_config import fixture as config_fixture
|
||||||
from oslotest import base
|
|
||||||
|
from tacker.tests import base
|
||||||
|
|
||||||
CONF = cfg.CONF
|
CONF = cfg.CONF
|
||||||
|
|
||||||
@ -27,6 +27,7 @@ class TestCase(base.BaseTestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestCase, self).setUp()
|
super(TestCase, self).setUp()
|
||||||
self.config_fixture = self.useFixture(config_fixture.Config(CONF))
|
self.config_fixture = self.useFixture(config_fixture.Config(CONF))
|
||||||
|
CONF([], default_config_files=[])
|
||||||
|
|
||||||
def _mock(self, target, new=mock.DEFAULT):
|
def _mock(self, target, new=mock.DEFAULT):
|
||||||
patcher = mock.patch(target, new)
|
patcher = mock.patch(target, new)
|
||||||
|
@ -65,11 +65,14 @@ class FakeDriverManager(mock.Mock):
|
|||||||
elif ('prepare_and_create_workflow' in args and
|
elif ('prepare_and_create_workflow' in args and
|
||||||
'delete' == kwargs['action'] and
|
'delete' == kwargs['action'] and
|
||||||
DUMMY_NS_2 == kwargs['kwargs']['ns']['id']):
|
DUMMY_NS_2 == kwargs['kwargs']['ns']['id']):
|
||||||
raise nfvo.NoTasksException()
|
raise nfvo.NoTasksException(action=kwargs['action'],
|
||||||
|
resource=kwargs['kwargs']['ns']['id'])
|
||||||
elif ('prepare_and_create_workflow' in args and
|
elif ('prepare_and_create_workflow' in args and
|
||||||
'create' == kwargs['action'] and
|
'create' == kwargs['action'] and
|
||||||
utils.DUMMY_NS_2_NAME == kwargs['kwargs']['ns']['ns']['name']):
|
utils.DUMMY_NS_2_NAME == kwargs['kwargs']['ns']['ns']['name']):
|
||||||
raise nfvo.NoTasksException()
|
raise nfvo.NoTasksException(
|
||||||
|
action=kwargs['action'],
|
||||||
|
resource=kwargs['kwargs']['ns']['ns']['name'])
|
||||||
|
|
||||||
|
|
||||||
def get_by_name():
|
def get_by_name():
|
||||||
@ -298,6 +301,7 @@ class TestNfvoPlugin(db_base.SqlTestCase):
|
|||||||
self.assertIn('placement_attr', res)
|
self.assertIn('placement_attr', res)
|
||||||
self.assertIn('created_at', res)
|
self.assertIn('created_at', res)
|
||||||
self.assertIn('updated_at', res)
|
self.assertIn('updated_at', res)
|
||||||
|
self.assertEqual(False, res['is_default'])
|
||||||
|
|
||||||
def test_delete_vim(self):
|
def test_delete_vim(self):
|
||||||
self._insert_dummy_vim()
|
self._insert_dummy_vim()
|
||||||
|
@ -713,6 +713,15 @@ class TestConvertToBoolean(base.BaseTestCase):
|
|||||||
self.assertRaises(n_exc.InvalidInput,
|
self.assertRaises(n_exc.InvalidInput,
|
||||||
attributes.convert_to_boolean,
|
attributes.convert_to_boolean,
|
||||||
'7')
|
'7')
|
||||||
|
self.assertRaises(n_exc.InvalidInput,
|
||||||
|
attributes.convert_to_boolean,
|
||||||
|
"")
|
||||||
|
self.assertRaises(n_exc.InvalidInput,
|
||||||
|
attributes.convert_to_boolean,
|
||||||
|
"abc")
|
||||||
|
self.assertRaises(n_exc.InvalidInput,
|
||||||
|
attributes.convert_to_boolean,
|
||||||
|
123)
|
||||||
|
|
||||||
|
|
||||||
class TestConvertToInt(base.BaseTestCase):
|
class TestConvertToInt(base.BaseTestCase):
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
# Despite above warning added by global sync process, please use
|
# Despite above warning added by global sync process, please use
|
||||||
# ascii betical order.
|
# ascii betical order.
|
||||||
coverage!=4.4,>=4.0 # Apache-2.0
|
coverage!=4.4,>=4.0 # Apache-2.0
|
||||||
|
ddt>=1.0.1 # MIT
|
||||||
doc8>=0.6.0 # Apache-2.0
|
doc8>=0.6.0 # Apache-2.0
|
||||||
fixtures>=3.0.0 # Apache-2.0/BSD
|
fixtures>=3.0.0 # Apache-2.0/BSD
|
||||||
hacking!=0.13.0,<0.14,>=0.12.0 # Apache-2.0
|
hacking!=0.13.0,<0.14,>=0.12.0 # Apache-2.0
|
||||||
|
Loading…
Reference in New Issue
Block a user