Create directory for database if it doesn't exist
Change-Id: Iea46947af8057c4c90f870c3b3b5725740b93b34
This commit is contained in:
parent
80ea6712e5
commit
947dcc1dcf
|
@ -15,6 +15,7 @@
|
|||
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import sqlite3
|
||||
import sys
|
||||
import time
|
||||
|
@ -104,6 +105,9 @@ def init():
|
|||
LOG.critical('Configuration option discoverd.database should be set')
|
||||
sys.exit(1)
|
||||
|
||||
db_dir = os.path.dirname(_DB_NAME)
|
||||
if db_dir and not os.path.exists(db_dir):
|
||||
os.makedirs(db_dir)
|
||||
sqlite3.connect(_DB_NAME).executescript(_SCHEMA)
|
||||
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import os
|
||||
import tempfile
|
||||
import time
|
||||
import unittest
|
||||
|
@ -268,6 +269,12 @@ class TestInit(unittest.TestCase):
|
|||
# Verify that table exists
|
||||
node_cache._db().execute("select * from nodes")
|
||||
|
||||
def test_create_dir(self):
|
||||
temp = tempfile.mkdtemp()
|
||||
conf.CONF.set('discoverd', 'database',
|
||||
os.path.join(temp, 'dir', 'file'))
|
||||
node_cache.init()
|
||||
|
||||
def test_no_database(self):
|
||||
self.assertRaises(SystemExit, node_cache.init)
|
||||
|
||||
|
|
Loading…
Reference in New Issue