Fix the network_driver update invalid parameter can be update

Now, we update the network_driver value. The invalid value can be update.
The network_driver validate function dosen't work.

Change-Id: If3672fa7a11ec8c414ce9c94c676c90ede216115
Closed-Bug: #1536098
This commit is contained in:
wangqun 2016-01-20 10:21:29 +00:00
parent c09af59f0f
commit c46681ae2b
2 changed files with 16 additions and 5 deletions

View File

@ -99,7 +99,14 @@ def enforce_network_driver_types_update():
@decorator.decorator
def wrapper(func, *args, **kwargs):
baymodel_ident = args[1]
patch = args[2]
baymodel = api_utils.get_rpc_resource('BayModel', baymodel_ident)
try:
baymodel_dict = api_utils.apply_jsonpatch(baymodel.as_dict(),
patch)
except api_utils.JSONPATCH_EXCEPTIONS as e:
raise exception.PatchError(patch=patch, reason=e)
baymodel = objects.BayModel(pecan.request.context, **baymodel_dict)
_enforce_network_driver_types(baymodel)
return func(*args, **kwargs)

View File

@ -264,15 +264,19 @@ class TestValidation(base.BaseTestCase):
assert_raised=False):
@v.enforce_network_driver_types_update()
def test(self, baymodel_ident):
def test(self, baymodel_ident, patch):
pass
for key, val in network_driver_config_dict.items():
cfg.CONF.set_override(key, val, 'baymodel')
baymodel_ident = 'test_uuid_or_name'
baymodel = mock.MagicMock()
patch = [{'path': '/network_driver', 'value': network_driver_type,
'op': 'replace'}]
context = mock_pecan_request.context
baymodel = obj_utils.get_test_baymodel(context,
uuid=baymodel_ident,
coe='kubernetes')
baymodel.network_driver = network_driver_type
baymodel.coe = 'kubernetes'
mock_get_rpc_resource.return_value = baymodel
# Reload the validator module so that baymodel configs are
@ -283,9 +287,9 @@ class TestValidation(base.BaseTestCase):
if assert_raised:
self.assertRaises(exception.InvalidParameterValue,
test, self, baymodel_ident)
test, self, baymodel_ident, patch)
else:
test(self, baymodel_ident)
test(self, baymodel_ident, patch)
mock_get_rpc_resource.assert_called_once_with(
'BayModel', baymodel_ident)