'updated_at' field value after node is updated
node.save() doesn't update object from db because 'updated_at' field for the node is not up-to-date after a save(). Change-Id: I58076d71e5977dded3f5485f295b3235d467872d Partial-Bug: #1281638 Co-Authored-By: Galyna Zholtkevych <gzholtkevych@mirantis.com>
This commit is contained in:
parent
cd4d09846f
commit
065326c0f5
@ -359,7 +359,13 @@ class Node(base.IronicObject, object_base.VersionedObjectDictCompat):
|
||||
# Clean driver_internal_info when changes driver
|
||||
self.driver_internal_info = {}
|
||||
updates = self.obj_get_changes()
|
||||
self.dbapi.update_node(self.uuid, updates)
|
||||
db_node = self.dbapi.update_node(self.uuid, updates)
|
||||
|
||||
# TODO(galyna): updating specific field not touching others to not
|
||||
# change default behaviour. Otherwise it will break a bunch of tests
|
||||
# This can be updated in other way when more fields like `updated_at`
|
||||
# will appear
|
||||
self.updated_at = db_node['updated_at']
|
||||
self.obj_reset_changes()
|
||||
|
||||
# NOTE(xek): We don't want to enable RPC on this call just yet. Remotable
|
||||
|
@ -13,6 +13,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import datetime
|
||||
import mock
|
||||
from testtools import matchers
|
||||
|
||||
@ -76,7 +77,7 @@ class TestNodeObject(base.DbTestCase):
|
||||
mock_get_node.return_value = self.fake_node
|
||||
with mock.patch.object(self.dbapi, 'update_node',
|
||||
autospec=True) as mock_update_node:
|
||||
|
||||
mock_update_node.return_value = utils.get_test_node()
|
||||
n = objects.Node.get(self.context, uuid)
|
||||
self.assertEqual({"private_state": "secret value"},
|
||||
n.driver_internal_info)
|
||||
@ -92,6 +93,36 @@ class TestNodeObject(base.DbTestCase):
|
||||
self.assertEqual(self.context, n._context)
|
||||
self.assertEqual({}, n.driver_internal_info)
|
||||
|
||||
def test_save_updated_at_field(self):
|
||||
uuid = self.fake_node['uuid']
|
||||
extra = {"test": 123}
|
||||
test_time = datetime.datetime(2000, 1, 1, 0, 0)
|
||||
with mock.patch.object(self.dbapi, 'get_node_by_uuid',
|
||||
autospec=True) as mock_get_node:
|
||||
mock_get_node.return_value = self.fake_node
|
||||
with mock.patch.object(self.dbapi, 'update_node',
|
||||
autospec=True) as mock_update_node:
|
||||
mock_update_node.return_value = (
|
||||
utils.get_test_node(extra=extra, updated_at=test_time))
|
||||
n = objects.Node.get(self.context, uuid)
|
||||
self.assertEqual({"private_state": "secret value"},
|
||||
n.driver_internal_info)
|
||||
n.properties = {"fake": "property"}
|
||||
n.extra = extra
|
||||
n.driver = "fake-driver"
|
||||
n.driver_internal_info = {}
|
||||
n.save()
|
||||
|
||||
mock_get_node.assert_called_once_with(uuid)
|
||||
mock_update_node.assert_called_once_with(
|
||||
uuid, {'properties': {"fake": "property"},
|
||||
'driver': 'fake-driver',
|
||||
'driver_internal_info': {},
|
||||
'extra': {'test': 123}})
|
||||
self.assertEqual(self.context, n._context)
|
||||
res_updated_at = n.updated_at.replace(tzinfo=None)
|
||||
self.assertEqual(test_time, res_updated_at)
|
||||
|
||||
def test_refresh(self):
|
||||
uuid = self.fake_node['uuid']
|
||||
returns = [dict(self.fake_node, properties={"fake": "first"}),
|
||||
@ -163,6 +194,10 @@ class TestNodeObject(base.DbTestCase):
|
||||
node.touch_provisioning()
|
||||
mock_touch.assert_called_once_with(node.id)
|
||||
|
||||
def test_create(self):
|
||||
node = objects.Node(self.context, **self.fake_node)
|
||||
node.create()
|
||||
|
||||
def test_create_with_invalid_properties(self):
|
||||
node = objects.Node(self.context, **self.fake_node)
|
||||
node.properties = {"local_gb": "5G"}
|
||||
|
@ -0,0 +1,4 @@
|
||||
---
|
||||
fixes:
|
||||
- Set correct node's "updated_at" field after
|
||||
node has been updated.
|
Loading…
Reference in New Issue
Block a user