Update rc support a manifest change
Currently, we don't support a manifest change when we update a rc. This patch fix this problem so that we can update the replica count or other useful attributes of a rc. Change-Id: I8e42768f215c6dd30fae6e1a9f20cf34bfe8bd93 Implements: blueprint magnum-resource-manifest-update
This commit is contained in:
parent
73000071fe
commit
6f320d3a8d
|
@ -273,21 +273,21 @@ class ReplicationControllersController(rest.RestController):
|
|||
raise exception.OperationNotPermitted
|
||||
|
||||
rpc_rc = api_utils.get_rpc_resource('ReplicationController', rc_ident)
|
||||
# Init manifest and manifest_url field because we don't store them
|
||||
# in database.
|
||||
rpc_rc['manifest'] = None
|
||||
rpc_rc['manifest_url'] = None
|
||||
try:
|
||||
rc_dict = rpc_rc.as_dict()
|
||||
rc = ReplicationController(**api_utils.apply_jsonpatch(rc_dict,
|
||||
patch))
|
||||
if rc.manifest or rc.manifest_url:
|
||||
rc.parse_manifest()
|
||||
except api_utils.JSONPATCH_EXCEPTIONS as e:
|
||||
raise exception.PatchError(patch=patch, reason=e)
|
||||
|
||||
# Update only the fields that have changed
|
||||
for field in objects.ReplicationController.fields:
|
||||
# ignore manifest_url as it was used for create rc
|
||||
if field == 'manifest_url':
|
||||
continue
|
||||
# ignore manifest as it was used for create rc
|
||||
if field == 'manifest':
|
||||
continue
|
||||
try:
|
||||
patch_val = getattr(rc, field)
|
||||
except AttributeError:
|
||||
|
@ -298,7 +298,10 @@ class ReplicationControllersController(rest.RestController):
|
|||
if rpc_rc[field] != patch_val:
|
||||
rpc_rc[field] = patch_val
|
||||
|
||||
rpc_rc.save()
|
||||
if rc.manifest or rc.manifest_url:
|
||||
pecan.request.rpcapi.rc_update(rpc_rc)
|
||||
else:
|
||||
rpc_rc.save()
|
||||
return ReplicationController.convert_with_links(rpc_rc)
|
||||
|
||||
@wsme_pecan.wsexpose(None, types.uuid_or_name, status_code=204)
|
||||
|
|
|
@ -104,6 +104,9 @@ class API(rpc_service.API):
|
|||
def rc_create(self, rc):
|
||||
return self._call('rc_create', rc=rc)
|
||||
|
||||
def rc_update(self, rc):
|
||||
return self._call('rc_update', rc=rc)
|
||||
|
||||
def rc_list(self, context, limit, marker, sort_key, sort_dir):
|
||||
return objects.ReplicationController.list(context, limit, marker,
|
||||
sort_key, sort_dir)
|
||||
|
|
|
@ -197,6 +197,7 @@ class Handler(object):
|
|||
return None
|
||||
# call the rc object to persist in db
|
||||
rc.refresh(context)
|
||||
rc.save()
|
||||
return rc
|
||||
|
||||
def rc_delete(self, context, uuid):
|
||||
|
|
|
@ -181,6 +181,10 @@ class ReplicationController(base.MagnumObject):
|
|||
"""
|
||||
current = self.__class__.get_by_uuid(self._context, uuid=self.uuid)
|
||||
for field in self.fields:
|
||||
if field == 'manifest_url':
|
||||
continue
|
||||
if field == 'manifest':
|
||||
continue
|
||||
if (hasattr(self, base.get_attrname(field)) and
|
||||
self[field] != current[field]):
|
||||
self[field] = current[field]
|
||||
|
|
|
@ -151,6 +151,8 @@ class TestPatch(api_base.FunctionalTest):
|
|||
obj_utils.create_test_bay(self.context)
|
||||
self.rc = obj_utils.create_test_rc(self.context,
|
||||
images=['rc_example_A_image'])
|
||||
self.another_bay = obj_utils.create_test_bay(self.context,
|
||||
uuid=utils.generate_uuid())
|
||||
|
||||
@mock.patch('oslo_utils.timeutils.utcnow')
|
||||
def test_replace_ok(self, mock_utcnow):
|
||||
|
@ -175,11 +177,9 @@ class TestPatch(api_base.FunctionalTest):
|
|||
self.assertEqual(test_time, return_updated_at)
|
||||
|
||||
def test_replace_bay_uuid(self):
|
||||
another_bay = obj_utils.create_test_bay(self.context,
|
||||
uuid=utils.generate_uuid())
|
||||
response = self.patch_json('/rcs/%s' % self.rc.uuid,
|
||||
[{'path': '/bay_uuid',
|
||||
'value': another_bay.uuid,
|
||||
'value': self.another_bay.uuid,
|
||||
'op': 'replace'}],
|
||||
expect_errors=True)
|
||||
self.assertEqual('application/json', response.content_type)
|
||||
|
@ -213,6 +213,18 @@ class TestPatch(api_base.FunctionalTest):
|
|||
self.assertEqual('application/json', response.content_type)
|
||||
self.assertTrue(response.json['error_message'])
|
||||
|
||||
@mock.patch.object(rpcapi.API, 'rc_update')
|
||||
@mock.patch.object(api_rc.ReplicationController, 'parse_manifest')
|
||||
def test_replace_with_manifest(self, parse_manifest, rc_update):
|
||||
response = self.patch_json('/rcs/%s' % self.rc.uuid,
|
||||
[{'path': '/manifest',
|
||||
'value': '{}',
|
||||
'op': 'replace'}])
|
||||
self.assertEqual(200, response.status_int)
|
||||
self.assertEqual('application/json', response.content_type)
|
||||
parse_manifest.assert_called_once_with()
|
||||
self.assertTrue(rc_update.is_called)
|
||||
|
||||
def test_add_ok(self):
|
||||
new_image = 'rc_example_B_image'
|
||||
response = self.patch_json('/rcs/%s' % self.rc.uuid,
|
||||
|
|
|
@ -387,6 +387,7 @@ class TestKube(base.TestCase):
|
|||
expected_rc = self.mock_rc()
|
||||
expected_rc.uuid = 'test-uuid'
|
||||
expected_rc.refresh = mock.MagicMock()
|
||||
expected_rc.save = mock.MagicMock()
|
||||
|
||||
mock_retrieve_k8s_master_url.return_value = expected_master_url
|
||||
with patch.object(self.kube_handler, 'kube_cli') as mock_kube_cli:
|
||||
|
@ -396,6 +397,7 @@ class TestKube(base.TestCase):
|
|||
mock_kube_cli.rc_update.assert_called_once_with(
|
||||
expected_master_url, expected_rc)
|
||||
expected_rc.refresh.assert_called_once_with(self.context)
|
||||
expected_rc.save.assert_called_once_with()
|
||||
|
||||
@patch('magnum.conductor.handlers.kube._retrieve_k8s_master_url')
|
||||
def test_rc_update_with_failure(self,
|
||||
|
|
|
@ -147,6 +147,12 @@ class RPCAPITestCase(base.DbTestCase):
|
|||
version='1.0',
|
||||
rc=self.fake_rc)
|
||||
|
||||
def test_rc_update(self):
|
||||
self._test_rpcapi('rc_update',
|
||||
'call',
|
||||
version='1.0',
|
||||
rc=self.fake_rc)
|
||||
|
||||
def test_rc_delete(self):
|
||||
self._test_rpcapi('rc_delete',
|
||||
'call',
|
||||
|
|
Loading…
Reference in New Issue