Remaining changes from making database a required option
* Update example.conf * Write missing test Change-Id: I1716697f2d04947143445ac6badf61453d0d6b17
This commit is contained in:
parent
b340f08960
commit
d014d9f060
|
@ -53,8 +53,8 @@
|
|||
|
||||
;; General service settings
|
||||
|
||||
; SQLite3 database to store nodes under discovery, defaults to a temporary
|
||||
; file. Do not use :memory: here, it won't work.
|
||||
; SQLite3 database to store nodes under discovery, required.
|
||||
; Do not use :memory: here, it won't work.
|
||||
;database =
|
||||
; Comma-separated list of enabled hooks for processing pipeline.
|
||||
; Hook 'scheduler' updates the node with the minimum properties required by the
|
||||
|
|
|
@ -68,7 +68,7 @@ def init():
|
|||
global _DB_NAME
|
||||
|
||||
_DB_NAME = conf.get('discoverd', 'database').strip()
|
||||
if not _DB_NAME: # pragma: no cover
|
||||
if not _DB_NAME:
|
||||
LOG.critical('Configuration option discoverd.database should be set')
|
||||
sys.exit(1)
|
||||
|
||||
|
|
|
@ -11,7 +11,9 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import tempfile
|
||||
import time
|
||||
import unittest
|
||||
|
||||
import mock
|
||||
|
||||
|
@ -179,3 +181,23 @@ class TestNodeInfoFinished(test_base.NodeTest):
|
|||
'select finished_at, error from nodes').fetchone())
|
||||
self.assertEqual([], self.db.execute(
|
||||
"select * from attributes").fetchall())
|
||||
|
||||
|
||||
class TestInit(unittest.TestCase):
|
||||
def setUp(self):
|
||||
super(TestInit, self).setUp()
|
||||
conf.init_conf()
|
||||
conf.CONF.add_section('discoverd')
|
||||
node_cache._DB_NAME = None
|
||||
|
||||
def test_ok(self):
|
||||
with tempfile.NamedTemporaryFile() as db_file:
|
||||
conf.CONF.set('discoverd', 'database', db_file.name)
|
||||
node_cache.init()
|
||||
|
||||
self.assertIsNotNone(node_cache._DB_NAME)
|
||||
# Verify that table exists
|
||||
node_cache._db().execute("select * from nodes")
|
||||
|
||||
def test_no_database(self):
|
||||
self.assertRaises(SystemExit, node_cache.init)
|
||||
|
|
Loading…
Reference in New Issue