use runs_sql instead of hackery
This commit is contained in:
parent
f62d5b4ac6
commit
4587c9b762
@ -1,8 +1,6 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||||
|
|
||||||
# Copyright 2010 United States Government as represented by the
|
|
||||||
# Administrator of the National Aeronautics and Space Administration.
|
|
||||||
# Copyright 2011 OpenStack LLC.
|
# Copyright 2011 OpenStack LLC.
|
||||||
# All Rights Reserved.
|
# All Rights Reserved.
|
||||||
#
|
#
|
||||||
|
@ -235,14 +235,10 @@ class FunctionalTest(unittest.TestCase):
|
|||||||
servers and clients and not just the stubbed out interfaces
|
servers and clients and not just the stubbed out interfaces
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def _set_environment(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|
||||||
self.test_id = random.randint(0, 100000)
|
self.test_id = random.randint(0, 100000)
|
||||||
self.test_dir = os.path.join("/", "tmp", "test.%d" % self.test_id)
|
self.test_dir = os.path.join("/", "tmp", "test.%d" % self.test_id)
|
||||||
self._set_environment()
|
|
||||||
|
|
||||||
self.api_port = get_unused_port()
|
self.api_port = get_unused_port()
|
||||||
self.registry_port = get_unused_port()
|
self.registry_port = get_unused_port()
|
||||||
|
@ -25,7 +25,6 @@ from tests import functional
|
|||||||
from tests.utils import execute
|
from tests.utils import execute
|
||||||
|
|
||||||
from glance import client
|
from glance import client
|
||||||
from glance.registry.db import api as db_api
|
|
||||||
|
|
||||||
|
|
||||||
TEST_IMAGE_DATA = '*' * 5 * 1024
|
TEST_IMAGE_DATA = '*' * 5 * 1024
|
||||||
@ -42,19 +41,7 @@ class TestScrubber(functional.FunctionalTest):
|
|||||||
def _get_client(self):
|
def _get_client(self):
|
||||||
return client.Client("localhost", self.api_port)
|
return client.Client("localhost", self.api_port)
|
||||||
|
|
||||||
def _set_environment(self):
|
@functional.runs_sql
|
||||||
db_connection = "sqlite:///" + self.test_dir + "/glance.db"
|
|
||||||
os.environ['GLANCE_TEST_SQL_CONNECTION'] = db_connection
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
super(TestScrubber, self).setUp()
|
|
||||||
|
|
||||||
# NOTE(jkoelker): We go behind the scenes here to get raw access
|
|
||||||
# to the database so we can check the status
|
|
||||||
# of deletes.
|
|
||||||
db_api._MAKER = None
|
|
||||||
db_api._ENGINE = create_engine(self.scrubber_daemon.sql_connection)
|
|
||||||
|
|
||||||
def test_immediate_delete(self):
|
def test_immediate_delete(self):
|
||||||
"""
|
"""
|
||||||
test that images get deleted immediately by default
|
test that images get deleted immediately by default
|
||||||
@ -66,17 +53,24 @@ class TestScrubber(functional.FunctionalTest):
|
|||||||
client = self._get_client()
|
client = self._get_client()
|
||||||
meta = client.add_image(TEST_IMAGE_META, TEST_IMAGE_DATA)
|
meta = client.add_image(TEST_IMAGE_META, TEST_IMAGE_DATA)
|
||||||
id = meta['id']
|
id = meta['id']
|
||||||
self.assertFalse(db_api.image_get_all_pending_delete(None))
|
|
||||||
|
sql = "SELECT * FROM images WHERE status = 'pending_delete'"
|
||||||
|
recs = list(self.run_sql_cmd(sql))
|
||||||
|
self.assertFalse(recs)
|
||||||
|
|
||||||
client.delete_image(id)
|
client.delete_image(id)
|
||||||
self.assertFalse(db_api.image_get_all_pending_delete(None))
|
recs = list(self.run_sql_cmd(sql))
|
||||||
|
self.assertFalse(recs)
|
||||||
|
|
||||||
db_meta = db_api.image_get({'deleted': True}, id)
|
sql = "SELECT * FROM images WHERE id = '%s'" % id
|
||||||
self.assertTrue(db_meta)
|
recs = list(self.run_sql_cmd(sql))
|
||||||
self.assertEqual(db_meta['status'], 'deleted')
|
self.assertTrue(recs)
|
||||||
|
for rec in recs:
|
||||||
|
self.assertEqual(rec['status'], 'deleted')
|
||||||
|
|
||||||
self.stop_servers()
|
self.stop_servers()
|
||||||
|
|
||||||
|
@functional.runs_sql
|
||||||
def test_delayed_delete(self):
|
def test_delayed_delete(self):
|
||||||
"""
|
"""
|
||||||
test that images don't get deleted immediatly and that the scrubber
|
test that images don't get deleted immediatly and that the scrubber
|
||||||
@ -84,24 +78,34 @@ class TestScrubber(functional.FunctionalTest):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
self.cleanup()
|
self.cleanup()
|
||||||
self.start_servers(delayed_delete=True, daemon=True)
|
registry_db = self.registry_server.sql_connection
|
||||||
|
self.start_servers(delayed_delete=True, sql_connection=registry_db,
|
||||||
|
daemon=True)
|
||||||
|
|
||||||
client = self._get_client()
|
client = self._get_client()
|
||||||
meta = client.add_image(TEST_IMAGE_META, TEST_IMAGE_DATA)
|
meta = client.add_image(TEST_IMAGE_META, TEST_IMAGE_DATA)
|
||||||
id = meta['id']
|
id = meta['id']
|
||||||
self.assertFalse(db_api.image_get_all_pending_delete(None))
|
|
||||||
|
sql = "SELECT * FROM images WHERE status = 'pending_delete'"
|
||||||
|
recs = list(self.run_sql_cmd(sql))
|
||||||
|
self.assertFalse(recs)
|
||||||
|
|
||||||
client.delete_image(id)
|
client.delete_image(id)
|
||||||
self.assertTrue(db_api.image_get_all_pending_delete(None))
|
recs = self.run_sql_cmd(sql)
|
||||||
|
self.assertTrue(recs)
|
||||||
|
|
||||||
db_meta = db_api.image_get({'deleted': True}, id)
|
sql = "SELECT * FROM images WHERE id = '%s'" % id
|
||||||
self.assertTrue(db_meta)
|
recs = list(self.run_sql_cmd(sql))
|
||||||
self.assertEqual(db_meta['status'], 'pending_delete')
|
self.assertTrue(recs)
|
||||||
|
for rec in recs:
|
||||||
|
self.assertEqual(rec['status'], 'pending_delete')
|
||||||
|
|
||||||
# Wait 15 seconds for the scrubber to scrub
|
# Wait 15 seconds for the scrubber to scrub
|
||||||
time.sleep(15)
|
time.sleep(15)
|
||||||
|
|
||||||
db_meta = db_api.image_get({'deleted': True}, id)
|
recs = list(self.run_sql_cmd(sql))
|
||||||
self.assertTrue(db_meta)
|
self.assertTrue(recs)
|
||||||
self.assertEqual(db_meta['status'], 'deleted')
|
for rec in recs:
|
||||||
|
self.assertEqual(rec['status'], 'deleted')
|
||||||
|
|
||||||
self.stop_servers()
|
self.stop_servers()
|
||||||
|
Loading…
Reference in New Issue
Block a user