Handle already created objects in "test_update_timpestamp"

In [1], if the waiting loop is executed more than once, the previously
created objects should be deleted first to avoid the problem related in
[2].

[1] https://review.opendev.org/#/c/678262
[2] https://bugs.launchpad.net/neutron/+bug/1841183/comments/3

Change-Id: I86cd17be6a776e4598abaeeb63de2eecbf0a64f9
Related-Bug: #1841183
This commit is contained in:
Rodolfo Alonso Hernandez 2019-08-27 16:16:00 +00:00
parent 4f6b8bb3e5
commit 560c56e603

View File

@ -246,26 +246,35 @@ class TimeStampDBMixinTestCase(TimeStampChangedsinceTestCase):
ctx = context.get_admin_context() ctx = context.get_admin_context()
obj = net_obj.Network(ctx, id=network_id) obj = net_obj.Network(ctx, id=network_id)
obj.create() obj.create()
return obj.standard_attr_id return obj
# Use tag as non StandardAttribute object # Use tag as non StandardAttribute object
def _save_tag(self, tags, standard_attr_id): def _save_tag(self, tags, standard_attr_id):
ctx = context.get_admin_context() ctx = context.get_admin_context()
ret = []
for tag in tags: for tag in tags:
tag_obj.Tag(ctx, standard_attr_id=standard_attr_id, _tag_obj = tag_obj.Tag(ctx, standard_attr_id=standard_attr_id,
tag=tag).create() tag=tag)
_tag_obj.create()
ret.append(_tag_obj)
return ret
def test_update_timpestamp(self): def test_update_timpestamp(self):
self._standard_attr_id = None self._network = None
self._tags = []
def save_network(): def save_network():
if self._network:
self._network.delete()
timenow.reset_mock() timenow.reset_mock()
self._standard_attr_id = self._save_network(network_id) self._network = self._save_network(network_id)
return 1 == timenow.call_count return 1 == timenow.call_count
def save_tag(): def save_tag():
for tag in self._tags:
tag.delete()
timenow.reset_mock() timenow.reset_mock()
self._save_tag(tags, self._standard_attr_id) self._tags = self._save_tag(tags, self._network.standard_attr_id)
return 0 == timenow.call_count return 0 == timenow.call_count
network_id = uuidutils.generate_uuid() network_id = uuidutils.generate_uuid()