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 json
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
@ -104,6 +105,9 @@ def init():
|
||||||
LOG.critical('Configuration option discoverd.database should be set')
|
LOG.critical('Configuration option discoverd.database should be set')
|
||||||
sys.exit(1)
|
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)
|
sqlite3.connect(_DB_NAME).executescript(_SCHEMA)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
import time
|
import time
|
||||||
import unittest
|
import unittest
|
||||||
|
@ -268,6 +269,12 @@ class TestInit(unittest.TestCase):
|
||||||
# Verify that table exists
|
# Verify that table exists
|
||||||
node_cache._db().execute("select * from nodes")
|
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):
|
def test_no_database(self):
|
||||||
self.assertRaises(SystemExit, node_cache.init)
|
self.assertRaises(SystemExit, node_cache.init)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue