summaryrefslogtreecommitdiff
path: root/glance/tests/unit/v2/test_metadef_resources.py
diff options
context:
space:
mode:
Diffstat (limited to 'glance/tests/unit/v2/test_metadef_resources.py')
-rw-r--r--glance/tests/unit/v2/test_metadef_resources.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/glance/tests/unit/v2/test_metadef_resources.py b/glance/tests/unit/v2/test_metadef_resources.py
index 781bce0fb..0969a7ae7 100644
--- a/glance/tests/unit/v2/test_metadef_resources.py
+++ b/glance/tests/unit/v2/test_metadef_resources.py
@@ -18,6 +18,7 @@ from unittest import mock
from oslo_serialization import jsonutils
import webob
+import wsme
from glance.api import policy
from glance.api.v2 import metadef_namespaces as namespaces
@@ -296,6 +297,44 @@ class TestMetadefsControllers(base.IsolatedUnitTest):
expected = set([NAMESPACE1, NAMESPACE3])
self.assertEqual(expected, actual)
+ def test_namespace_index_resource_type_delete_race(self):
+ request = unit_test_utils.get_fake_request()
+ filters = {'resource_types': [RESOURCE_TYPE1]}
+
+ real_gmrtr = self.namespace_controller.gateway.\
+ get_metadef_resource_type_repo
+
+ def race_delete(*a, **k):
+ self.db.metadef_namespace_delete(request.context, NAMESPACE3)
+ return real_gmrtr(*a, **k)
+
+ with mock.patch.object(self.namespace_controller.gateway,
+ 'get_metadef_resource_type_repo') as g:
+ # NOTE(danms): We simulate a late delete of one of our
+ # namespaces by hijacking the call to get the metadef RT
+ # repo and doing a delete at that point, before we iterate
+ # the list of namespaces we already pulled from the DB. If
+ # the code in the index API method changes, this will need
+ # to be updated.
+ g.side_effect = race_delete
+ output = self.namespace_controller.index(request, filters=filters)
+ output = output.to_dict()
+ self.assertEqual(2, len(output['namespaces']))
+ actual = set([namespace.namespace for namespace
+ in output['namespaces']])
+ # We should still see both namespaces
+ expected = set([NAMESPACE1, NAMESPACE3])
+ self.assertEqual(expected, actual)
+
+ # And the first (undeleted) one should have the expected
+ # associations...
+ self.assertEqual(
+ 1, len(output['namespaces'][0].resource_type_associations))
+ # ...but the one we deleted should be empty
+ self.assertEqual(
+ wsme.types.Unset,
+ output['namespaces'][1].resource_type_associations)
+
def test_namespace_show(self):
request = unit_test_utils.get_fake_request()
output = self.namespace_controller.show(request, NAMESPACE1)