summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-06-19 19:28:46 +0000
committerGerrit Code Review <review@openstack.org>2017-06-19 19:28:46 +0000
commit1c7bf9cff0afcb286d38ac2a411d4cc4906159da (patch)
tree55e25515803bb0e62a23cd5a4dd32975977ff590
parentbac5948d1a6bab44955e4f8821cff4fba9d60791 (diff)
parentc09d157960f6f86e0470655df5083a313792c82d (diff)
Merge "Add external lock to image cache sqlite driver db init"
-rw-r--r--glance/image_cache/drivers/sqlite.py47
-rw-r--r--glance/tests/functional/test_bin_glance_cache_manage.py2
-rw-r--r--glance/tests/functional/test_cache_middleware.py2
-rw-r--r--releasenotes/notes/lock_path_config_option-2771feaa649e4563.yaml5
4 files changed, 36 insertions, 20 deletions
diff --git a/glance/image_cache/drivers/sqlite.py b/glance/image_cache/drivers/sqlite.py
index 89a8764..d276c4e 100644
--- a/glance/image_cache/drivers/sqlite.py
+++ b/glance/image_cache/drivers/sqlite.py
@@ -26,6 +26,7 @@ import time
26 26
27from eventlet import sleep 27from eventlet import sleep
28from eventlet import timeout 28from eventlet import timeout
29from oslo_concurrency import lockutils
29from oslo_config import cfg 30from oslo_config import cfg
30from oslo_log import log as logging 31from oslo_log import log as logging
31from oslo_utils import excutils 32from oslo_utils import excutils
@@ -119,26 +120,32 @@ class Driver(base.Driver):
119 def initialize_db(self): 120 def initialize_db(self):
120 db = CONF.image_cache_sqlite_db 121 db = CONF.image_cache_sqlite_db
121 self.db_path = os.path.join(self.base_dir, db) 122 self.db_path = os.path.join(self.base_dir, db)
122 try: 123 lockutils.set_defaults(self.base_dir)
123 conn = sqlite3.connect(self.db_path, check_same_thread=False, 124
124 factory=SqliteConnection) 125 @lockutils.synchronized('image_cache_db_init', external=True)
125 conn.executescript(""" 126 def create_db():
126 CREATE TABLE IF NOT EXISTS cached_images ( 127 try:
127 image_id TEXT PRIMARY KEY, 128 conn = sqlite3.connect(self.db_path, check_same_thread=False,
128 last_accessed REAL DEFAULT 0.0, 129 factory=SqliteConnection)
129 last_modified REAL DEFAULT 0.0, 130 conn.executescript("""
130 size INTEGER DEFAULT 0, 131 CREATE TABLE IF NOT EXISTS cached_images (
131 hits INTEGER DEFAULT 0, 132 image_id TEXT PRIMARY KEY,
132 checksum TEXT 133 last_accessed REAL DEFAULT 0.0,
133 ); 134 last_modified REAL DEFAULT 0.0,
134 """) 135 size INTEGER DEFAULT 0,
135 conn.close() 136 hits INTEGER DEFAULT 0,
136 except sqlite3.DatabaseError as e: 137 checksum TEXT
137 msg = _("Failed to initialize the image cache database. " 138 );
138 "Got error: %s") % e 139 """)
139 LOG.error(msg) 140 conn.close()
140 raise exception.BadDriverConfiguration(driver_name='sqlite', 141 except sqlite3.DatabaseError as e:
141 reason=msg) 142 msg = _("Failed to initialize the image cache database. "
143 "Got error: %s") % e
144 LOG.error(msg)
145 raise exception.BadDriverConfiguration(driver_name='sqlite',
146 reason=msg)
147
148 create_db()
142 149
143 def get_cache_size(self): 150 def get_cache_size(self):
144 """ 151 """
diff --git a/glance/tests/functional/test_bin_glance_cache_manage.py b/glance/tests/functional/test_bin_glance_cache_manage.py
index 7ab63e8..d933f78 100644
--- a/glance/tests/functional/test_bin_glance_cache_manage.py
+++ b/glance/tests/functional/test_bin_glance_cache_manage.py
@@ -214,6 +214,7 @@ class TestBinGlanceCacheManage(functional.FunctionalTest):
214 'image_cache_dir': self.api_server.image_cache_dir, 214 'image_cache_dir': self.api_server.image_cache_dir,
215 'image_cache_driver': self.image_cache_driver, 215 'image_cache_driver': self.image_cache_driver,
216 'registry_port': self.registry_server.bind_port, 216 'registry_port': self.registry_server.bind_port,
217 'lock_path': self.test_dir,
217 'log_file': os.path.join(self.test_dir, 'cache.log'), 218 'log_file': os.path.join(self.test_dir, 'cache.log'),
218 'metadata_encryption_key': "012345678901234567890123456789ab", 219 'metadata_encryption_key': "012345678901234567890123456789ab",
219 'filesystem_store_datadir': self.test_dir 220 'filesystem_store_datadir': self.test_dir
@@ -221,6 +222,7 @@ class TestBinGlanceCacheManage(functional.FunctionalTest):
221 with open(cache_config_filepath, 'w') as cache_file: 222 with open(cache_config_filepath, 'w') as cache_file:
222 cache_file.write("""[DEFAULT] 223 cache_file.write("""[DEFAULT]
223debug = True 224debug = True
225lock_path = %(lock_path)s
224image_cache_dir = %(image_cache_dir)s 226image_cache_dir = %(image_cache_dir)s
225image_cache_driver = %(image_cache_driver)s 227image_cache_driver = %(image_cache_driver)s
226registry_host = 127.0.0.1 228registry_host = 127.0.0.1
diff --git a/glance/tests/functional/test_cache_middleware.py b/glance/tests/functional/test_cache_middleware.py
index 1bc86f8..9508d97 100644
--- a/glance/tests/functional/test_cache_middleware.py
+++ b/glance/tests/functional/test_cache_middleware.py
@@ -932,12 +932,14 @@ class BaseCacheManageMiddlewareTest(object):
932 'image_cache_driver': self.image_cache_driver, 932 'image_cache_driver': self.image_cache_driver,
933 'registry_port': self.registry_server.bind_port, 933 'registry_port': self.registry_server.bind_port,
934 'log_file': os.path.join(self.test_dir, 'cache.log'), 934 'log_file': os.path.join(self.test_dir, 'cache.log'),
935 'lock_path': self.test_dir,
935 'metadata_encryption_key': "012345678901234567890123456789ab", 936 'metadata_encryption_key': "012345678901234567890123456789ab",
936 'filesystem_store_datadir': self.test_dir 937 'filesystem_store_datadir': self.test_dir
937 } 938 }
938 with open(cache_config_filepath, 'w') as cache_file: 939 with open(cache_config_filepath, 'w') as cache_file:
939 cache_file.write("""[DEFAULT] 940 cache_file.write("""[DEFAULT]
940debug = True 941debug = True
942lock_path = %(lock_path)s
941image_cache_dir = %(image_cache_dir)s 943image_cache_dir = %(image_cache_dir)s
942image_cache_driver = %(image_cache_driver)s 944image_cache_driver = %(image_cache_driver)s
943registry_host = 127.0.0.1 945registry_host = 127.0.0.1
diff --git a/releasenotes/notes/lock_path_config_option-2771feaa649e4563.yaml b/releasenotes/notes/lock_path_config_option-2771feaa649e4563.yaml
new file mode 100644
index 0000000..f6171c0
--- /dev/null
+++ b/releasenotes/notes/lock_path_config_option-2771feaa649e4563.yaml
@@ -0,0 +1,5 @@
1---
2upgrade:
3 - The lock_path config option from oslo.concurrency is now required for using
4 the sql image_cache driver. If one is not specified it will default to
5 the image_cache_dir and emit a warning.