summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-06-16 15:32:56 +0000
committerGerrit Code Review <review@openstack.org>2017-06-16 15:32:56 +0000
commit8381f498b443bc366cf2d0c26fb44c26b2c2539f (patch)
tree6bf1879bdc13ff332adb91faa0fad6639e841d4c
parent589062596c5d53d8e73bb9ef44d77c6e1fbfe1c8 (diff)
parentfcec378594388eff0fec4437fd55f001a6a173a7 (diff)
Merge "Use new oslo db EngineFacade"
-rw-r--r--ironic_inspector/db.py75
-rw-r--r--ironic_inspector/migrations/env.py4
-rw-r--r--ironic_inspector/test/base.py6
-rw-r--r--ironic_inspector/test/unit/test_db.py77
-rw-r--r--ironic_inspector/test/unit/test_migrations.py15
-rw-r--r--ironic_inspector/test/unit/test_node_cache.py48
6 files changed, 162 insertions, 63 deletions
diff --git a/ironic_inspector/db.py b/ironic_inspector/db.py
index 042ff06..99bc413 100644
--- a/ironic_inspector/db.py
+++ b/ironic_inspector/db.py
@@ -17,10 +17,11 @@
17 17
18import contextlib 18import contextlib
19 19
20from oslo_concurrency import lockutils
20from oslo_config import cfg 21from oslo_config import cfg
21from oslo_db import options as db_opts 22from oslo_db import options as db_opts
23from oslo_db.sqlalchemy import enginefacade
22from oslo_db.sqlalchemy import models 24from oslo_db.sqlalchemy import models
23from oslo_db.sqlalchemy import session as db_session
24from oslo_db.sqlalchemy import types as db_types 25from oslo_db.sqlalchemy import types as db_types
25from sqlalchemy import (Boolean, Column, DateTime, Enum, ForeignKey, 26from sqlalchemy import (Boolean, Column, DateTime, Enum, ForeignKey,
26 Integer, String, Text) 27 Integer, String, Text)
@@ -39,9 +40,11 @@ class ModelBase(models.ModelBase):
39Base = declarative_base(cls=ModelBase) 40Base = declarative_base(cls=ModelBase)
40CONF = cfg.CONF 41CONF = cfg.CONF
41_DEFAULT_SQL_CONNECTION = 'sqlite:///ironic_inspector.sqlite' 42_DEFAULT_SQL_CONNECTION = 'sqlite:///ironic_inspector.sqlite'
42_FACADE = None 43_CTX_MANAGER = None
43 44
44db_opts.set_defaults(cfg.CONF, connection=_DEFAULT_SQL_CONNECTION) 45db_opts.set_defaults(CONF, connection=_DEFAULT_SQL_CONNECTION)
46
47_synchronized = lockutils.synchronized_with_prefix("ironic-inspector-")
45 48
46 49
47class Node(Base): 50class Node(Base):
@@ -131,18 +134,12 @@ class RuleAction(Base):
131 134
132 135
133def init(): 136def init():
134 """Initialize the database.""" 137 """Initialize the database.
135 return get_session()
136
137
138def get_session(**kwargs):
139 facade = create_facade_lazily()
140 return facade.get_session(**kwargs)
141 138
142 139 Method called on service start up, initialize transaction
143def get_engine(): 140 context manager and try to create db session.
144 facade = create_facade_lazily() 141 """
145 return facade.get_engine() 142 get_writer_session()
146 143
147 144
148def model_query(model, *args, **kwargs): 145def model_query(model, *args, **kwargs):
@@ -150,21 +147,51 @@ def model_query(model, *args, **kwargs):
150 147
151 :param session: if present, the session to use 148 :param session: if present, the session to use
152 """ 149 """
153 150 session = kwargs.get('session') or get_reader_session()
154 session = kwargs.get('session') or get_session()
155 query = session.query(model, *args) 151 query = session.query(model, *args)
156 return query 152 return query
157 153
158 154
159def create_facade_lazily():
160 global _FACADE
161 if _FACADE is None:
162 _FACADE = db_session.EngineFacade.from_config(cfg.CONF)
163 return _FACADE
164
165
166@contextlib.contextmanager 155@contextlib.contextmanager
167def ensure_transaction(session=None): 156def ensure_transaction(session=None):
168 session = session or get_session() 157 session = session or get_writer_session()
169 with session.begin(subtransactions=True): 158 with session.begin(subtransactions=True):
170 yield session 159 yield session
160
161
162@_synchronized("transaction-context-manager")
163def _create_context_manager():
164 _ctx_mgr = enginefacade.transaction_context()
165 # TODO(aarefiev): enable foreign keys for SQLite once all unit
166 # tests with failed constraint will be fixed.
167 _ctx_mgr.configure(sqlite_fk=False)
168
169 return _ctx_mgr
170
171
172def get_context_manager():
173 """Create transaction context manager lazily.
174
175 :returns: The transaction context manager.
176 """
177 global _CTX_MANAGER
178 if _CTX_MANAGER is None:
179 _CTX_MANAGER = _create_context_manager()
180
181 return _CTX_MANAGER
182
183
184def get_reader_session():
185 """Help method to get reader session.
186
187 :returns: The reader session.
188 """
189 return get_context_manager().reader.get_sessionmaker()()
190
191
192def get_writer_session():
193 """Help method to get writer session.
194
195 :returns: The writer session.
196 """
197 return get_context_manager().writer.get_sessionmaker()()
diff --git a/ironic_inspector/migrations/env.py b/ironic_inspector/migrations/env.py
index 775d1f9..71b186f 100644
--- a/ironic_inspector/migrations/env.py
+++ b/ironic_inspector/migrations/env.py
@@ -66,8 +66,8 @@ def run_migrations_online():
66 and associate a connection with the context. 66 and associate a connection with the context.
67 67
68 """ 68 """
69 connectable = db.create_facade_lazily().get_engine() 69 session = db.get_writer_session()
70 with connectable.connect() as connection: 70 with session.connection() as connection:
71 context.configure( 71 context.configure(
72 connection=connection, 72 connection=connection,
73 target_metadata=target_metadata 73 target_metadata=target_metadata
diff --git a/ironic_inspector/test/base.py b/ironic_inspector/test/base.py
index 69ce18a..9142ef5 100644
--- a/ironic_inspector/test/base.py
+++ b/ironic_inspector/test/base.py
@@ -45,11 +45,11 @@ class BaseTest(test_base.BaseTestCase):
45 super(BaseTest, self).setUp() 45 super(BaseTest, self).setUp()
46 if not self.IS_FUNCTIONAL: 46 if not self.IS_FUNCTIONAL:
47 self.init_test_conf() 47 self.init_test_conf()
48 self.session = db.get_session() 48 self.session = db.get_writer_session()
49 engine = db.get_engine() 49 engine = self.session.get_bind()
50 db.Base.metadata.create_all(engine) 50 db.Base.metadata.create_all(engine)
51 engine.connect() 51 engine.connect()
52 self.addCleanup(db.get_engine().dispose) 52 self.addCleanup(engine.dispose)
53 plugins_base._HOOKS_MGR = None 53 plugins_base._HOOKS_MGR = None
54 node_cache._SEMAPHORES = lockutils.Semaphores() 54 node_cache._SEMAPHORES = lockutils.Semaphores()
55 patch = mock.patch.object(i18n, '_', lambda s: s) 55 patch = mock.patch.object(i18n, '_', lambda s: s)
diff --git a/ironic_inspector/test/unit/test_db.py b/ironic_inspector/test/unit/test_db.py
new file mode 100644
index 0000000..7b2a445
--- /dev/null
+++ b/ironic_inspector/test/unit/test_db.py
@@ -0,0 +1,77 @@
1# Licensed under the Apache License, Version 2.0 (the "License"); you may
2# not use this file except in compliance with the License. You may obtain
3# a copy of the License at
4#
5# http://www.apache.org/licenses/LICENSE-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10# License for the specific language governing permissions and limitations
11# under the License.
12
13
14import mock
15
16from ironic_inspector import db
17from ironic_inspector.test import base as test_base
18
19
20class TestDB(test_base.NodeTest):
21 @mock.patch.object(db, 'get_reader_session', autospec=True)
22 def test_model_query(self, mock_reader):
23 mock_session = mock_reader.return_value
24 fake_query = mock_session.query.return_value
25
26 query = db.model_query('db.Node')
27
28 mock_reader.assert_called_once_with()
29 mock_session.query.assert_called_once_with('db.Node')
30 self.assertEqual(fake_query, query)
31
32 @mock.patch.object(db, 'get_writer_session', autospec=True)
33 def test_ensure_transaction_new_session(self, mock_writer):
34 mock_session = mock_writer.return_value
35
36 with db.ensure_transaction() as session:
37 mock_writer.assert_called_once_with()
38 mock_session.begin.assert_called_once_with(subtransactions=True)
39 self.assertEqual(mock_session, session)
40
41 @mock.patch.object(db, 'get_writer_session', autospec=True)
42 def test_ensure_transaction_session(self, mock_writer):
43 mock_session = mock.MagicMock()
44
45 with db.ensure_transaction(session=mock_session) as session:
46 self.assertFalse(mock_writer.called)
47 mock_session.begin.assert_called_once_with(subtransactions=True)
48 self.assertEqual(mock_session, session)
49
50 @mock.patch.object(db.enginefacade, 'transaction_context', autospec=True)
51 def test__create_context_manager(self, mock_cnxt):
52 mock_ctx_mgr = mock_cnxt.return_value
53
54 ctx_mgr = db._create_context_manager()
55
56 mock_ctx_mgr.configure.assert_called_once_with(sqlite_fk=False)
57 self.assertEqual(mock_ctx_mgr, ctx_mgr)
58
59 @mock.patch.object(db, 'get_context_manager', autospec=True)
60 def test_get_reader_session(self, mock_cnxt_mgr):
61 mock_cnxt = mock_cnxt_mgr.return_value
62 mock_sess_maker = mock_cnxt.reader.get_sessionmaker.return_value
63
64 session = db.get_reader_session()
65
66 mock_sess_maker.assert_called_once_with()
67 self.assertEqual(mock_sess_maker.return_value, session)
68
69 @mock.patch.object(db, 'get_context_manager', autospec=True)
70 def test_get_writer_session(self, mock_cnxt_mgr):
71 mock_cnxt = mock_cnxt_mgr.return_value
72 mock_sess_maker = mock_cnxt.writer.get_sessionmaker.return_value
73
74 session = db.get_writer_session()
75
76 mock_sess_maker.assert_called_once_with()
77 self.assertEqual(mock_sess_maker.return_value, session)
diff --git a/ironic_inspector/test/unit/test_migrations.py b/ironic_inspector/test/unit/test_migrations.py
index 407fdac..dd7fa37 100644
--- a/ironic_inspector/test/unit/test_migrations.py
+++ b/ironic_inspector/test/unit/test_migrations.py
@@ -31,6 +31,7 @@ from alembic import script
31import mock 31import mock
32from oslo_config import cfg 32from oslo_config import cfg
33from oslo_db.sqlalchemy.migration_cli import ext_alembic 33from oslo_db.sqlalchemy.migration_cli import ext_alembic
34from oslo_db.sqlalchemy import orm
34from oslo_db.sqlalchemy import test_base 35from oslo_db.sqlalchemy import test_base
35from oslo_db.sqlalchemy import test_migrations 36from oslo_db.sqlalchemy import test_migrations
36from oslo_db.sqlalchemy import utils as db_utils 37from oslo_db.sqlalchemy import utils as db_utils
@@ -82,18 +83,12 @@ def _is_backend_avail(backend, user, passwd, database):
82 return True 83 return True
83 84
84 85
85class FakeFacade(object):
86 def __init__(self, engine):
87 self.engine = engine
88
89 def get_engine(self):
90 return self.engine
91
92
93@contextlib.contextmanager 86@contextlib.contextmanager
94def patch_with_engine(engine): 87def patch_with_engine(engine):
95 with mock.patch.object(db, 'create_facade_lazily') as patch_engine: 88 with mock.patch.object(db, 'get_writer_session') as patch_w_sess, \
96 patch_engine.return_value = FakeFacade(engine) 89 mock.patch.object(db, 'get_reader_session') as patch_r_sess:
90 patch_w_sess.return_value = patch_r_sess.return_value = (
91 orm.get_maker(engine)())
97 yield 92 yield
98 93
99 94
diff --git a/ironic_inspector/test/unit/test_node_cache.py b/ironic_inspector/test/unit/test_node_cache.py
index ff0f1f7..6ce9bab 100644
--- a/ironic_inspector/test/unit/test_node_cache.py
+++ b/ironic_inspector/test/unit/test_node_cache.py
@@ -38,7 +38,7 @@ class TestNodeCache(test_base.NodeTest):
38 def test_add_node(self): 38 def test_add_node(self):
39 # Ensure previous node information is cleared 39 # Ensure previous node information is cleared
40 uuid2 = uuidutils.generate_uuid() 40 uuid2 = uuidutils.generate_uuid()
41 session = db.get_session() 41 session = db.get_writer_session()
42 with session.begin(): 42 with session.begin():
43 db.Node(uuid=self.node.uuid, 43 db.Node(uuid=self.node.uuid,
44 state=istate.States.starting).save(session) 44 state=istate.States.starting).save(session)
@@ -75,7 +75,7 @@ class TestNodeCache(test_base.NodeTest):
75 [(row.name, row.value, row.node_uuid) for row in res]) 75 [(row.name, row.value, row.node_uuid) for row in res])
76 76
77 def test__delete_node(self): 77 def test__delete_node(self):
78 session = db.get_session() 78 session = db.get_writer_session()
79 with session.begin(): 79 with session.begin():
80 db.Node(uuid=self.node.uuid, 80 db.Node(uuid=self.node.uuid,
81 state=istate.States.finished).save(session) 81 state=istate.States.finished).save(session)
@@ -88,7 +88,7 @@ class TestNodeCache(test_base.NodeTest):
88 session) 88 session)
89 89
90 node_cache._delete_node(self.uuid) 90 node_cache._delete_node(self.uuid)
91 session = db.get_session() 91 session = db.get_writer_session()
92 row_node = db.model_query(db.Node).filter_by( 92 row_node = db.model_query(db.Node).filter_by(
93 uuid=self.uuid).first() 93 uuid=self.uuid).first()
94 self.assertIsNone(row_node) 94 self.assertIsNone(row_node)
@@ -108,7 +108,7 @@ class TestNodeCache(test_base.NodeTest):
108 uuid2 = uuidutils.generate_uuid() 108 uuid2 = uuidutils.generate_uuid()
109 uuids = {self.uuid} 109 uuids = {self.uuid}
110 mock__list_node_uuids.return_value = {self.uuid, uuid2} 110 mock__list_node_uuids.return_value = {self.uuid, uuid2}
111 session = db.get_session() 111 session = db.get_writer_session()
112 with session.begin(): 112 with session.begin():
113 node_cache.delete_nodes_not_in_list(uuids) 113 node_cache.delete_nodes_not_in_list(uuids)
114 mock__delete_node.assert_called_once_with(uuid2) 114 mock__delete_node.assert_called_once_with(uuid2)
@@ -116,7 +116,7 @@ class TestNodeCache(test_base.NodeTest):
116 mock__get_lock_ctx.return_value.__enter__.assert_called_once_with() 116 mock__get_lock_ctx.return_value.__enter__.assert_called_once_with()
117 117
118 def test_active_macs(self): 118 def test_active_macs(self):
119 session = db.get_session() 119 session = db.get_writer_session()
120 with session.begin(): 120 with session.begin():
121 db.Node(uuid=self.node.uuid, 121 db.Node(uuid=self.node.uuid,
122 state=istate.States.starting).save(session) 122 state=istate.States.starting).save(session)
@@ -129,7 +129,7 @@ class TestNodeCache(test_base.NodeTest):
129 node_cache.active_macs()) 129 node_cache.active_macs())
130 130
131 def test__list_node_uuids(self): 131 def test__list_node_uuids(self):
132 session = db.get_session() 132 session = db.get_writer_session()
133 uuid2 = uuidutils.generate_uuid() 133 uuid2 = uuidutils.generate_uuid()
134 with session.begin(): 134 with session.begin():
135 db.Node(uuid=self.node.uuid, 135 db.Node(uuid=self.node.uuid,
@@ -141,7 +141,7 @@ class TestNodeCache(test_base.NodeTest):
141 self.assertEqual({self.uuid, uuid2}, node_uuid_list) 141 self.assertEqual({self.uuid, uuid2}, node_uuid_list)
142 142
143 def test_add_attribute(self): 143 def test_add_attribute(self):
144 session = db.get_session() 144 session = db.get_writer_session()
145 with session.begin(): 145 with session.begin():
146 db.Node(uuid=self.node.uuid, 146 db.Node(uuid=self.node.uuid,
147 state=istate.States.starting).save(session) 147 state=istate.States.starting).save(session)
@@ -158,7 +158,7 @@ class TestNodeCache(test_base.NodeTest):
158 self.assertEqual({'key': ['value']}, node_info.attributes) 158 self.assertEqual({'key': ['value']}, node_info.attributes)
159 159
160 def test_add_attribute_same_name(self): 160 def test_add_attribute_same_name(self):
161 session = db.get_session() 161 session = db.get_writer_session()
162 with session.begin(): 162 with session.begin():
163 db.Node(uuid=self.node.uuid, 163 db.Node(uuid=self.node.uuid,
164 state=istate.States.starting).save(session) 164 state=istate.States.starting).save(session)
@@ -175,7 +175,7 @@ class TestNodeCache(test_base.NodeTest):
175 [tuple(row) for row in res]) 175 [tuple(row) for row in res])
176 176
177 def test_add_attribute_same_value(self): 177 def test_add_attribute_same_value(self):
178 session = db.get_session() 178 session = db.get_writer_session()
179 with session.begin(): 179 with session.begin():
180 db.Node(uuid=self.node.uuid, 180 db.Node(uuid=self.node.uuid,
181 state=istate.States.starting).save(session) 181 state=istate.States.starting).save(session)
@@ -198,7 +198,7 @@ class TestNodeCache(test_base.NodeTest):
198 'mac': self.macs}, 198 'mac': self.macs},
199 node_info.attributes) 199 node_info.attributes)
200 # check invalidation 200 # check invalidation
201 session = db.get_session() 201 session = db.get_writer_session()
202 with session.begin(): 202 with session.begin():
203 db.Attribute(uuid=uuidutils.generate_uuid(), name='foo', 203 db.Attribute(uuid=uuidutils.generate_uuid(), name='foo',
204 value='bar', node_uuid=self.uuid).save(session) 204 value='bar', node_uuid=self.uuid).save(session)
@@ -285,7 +285,7 @@ class TestNodeCacheFind(test_base.NodeTest):
285 self.assertTrue(res._locked) 285 self.assertTrue(res._locked)
286 286
287 def test_inconsistency(self): 287 def test_inconsistency(self):
288 session = db.get_session() 288 session = db.get_writer_session()
289 with session.begin(): 289 with session.begin():
290 (db.model_query(db.Node).filter_by(uuid=self.uuid). 290 (db.model_query(db.Node).filter_by(uuid=self.uuid).
291 delete()) 291 delete())
@@ -293,7 +293,7 @@ class TestNodeCacheFind(test_base.NodeTest):
293 bmc_address='1.2.3.4') 293 bmc_address='1.2.3.4')
294 294
295 def test_already_finished(self): 295 def test_already_finished(self):
296 session = db.get_session() 296 session = db.get_writer_session()
297 with session.begin(): 297 with session.begin():
298 (db.model_query(db.Node).filter_by(uuid=self.uuid). 298 (db.model_query(db.Node).filter_by(uuid=self.uuid).
299 update({'finished_at': datetime.datetime.utcnow()})) 299 update({'finished_at': datetime.datetime.utcnow()}))
@@ -305,7 +305,7 @@ class TestNodeCacheCleanUp(test_base.NodeTest):
305 def setUp(self): 305 def setUp(self):
306 super(TestNodeCacheCleanUp, self).setUp() 306 super(TestNodeCacheCleanUp, self).setUp()
307 self.started_at = datetime.datetime.utcnow() 307 self.started_at = datetime.datetime.utcnow()
308 session = db.get_session() 308 session = db.get_writer_session()
309 with session.begin(): 309 with session.begin():
310 db.Node(uuid=self.uuid, 310 db.Node(uuid=self.uuid,
311 state=istate.States.waiting, 311 state=istate.States.waiting,
@@ -350,7 +350,7 @@ class TestNodeCacheCleanUp(test_base.NodeTest):
350 def test_timeout(self, time_mock, get_lock_mock): 350 def test_timeout(self, time_mock, get_lock_mock):
351 # Add a finished node to confirm we don't try to timeout it 351 # Add a finished node to confirm we don't try to timeout it
352 time_mock.return_value = self.started_at 352 time_mock.return_value = self.started_at
353 session = db.get_session() 353 session = db.get_writer_session()
354 finished_at = self.started_at + datetime.timedelta(seconds=60) 354 finished_at = self.started_at + datetime.timedelta(seconds=60)
355 with session.begin(): 355 with session.begin():
356 db.Node(uuid=self.uuid + '1', started_at=self.started_at, 356 db.Node(uuid=self.uuid + '1', started_at=self.started_at,
@@ -380,7 +380,7 @@ class TestNodeCacheCleanUp(test_base.NodeTest):
380 @mock.patch.object(timeutils, 'utcnow') 380 @mock.patch.object(timeutils, 'utcnow')
381 def test_timeout_active_state(self, time_mock, get_lock_mock): 381 def test_timeout_active_state(self, time_mock, get_lock_mock):
382 time_mock.return_value = self.started_at 382 time_mock.return_value = self.started_at
383 session = db.get_session() 383 session = db.get_writer_session()
384 CONF.set_override('timeout', 1) 384 CONF.set_override('timeout', 1)
385 for state in [istate.States.starting, istate.States.enrolling, 385 for state in [istate.States.starting, istate.States.enrolling,
386 istate.States.processing, istate.States.reapplying]: 386 istate.States.processing, istate.States.reapplying]:
@@ -400,7 +400,7 @@ class TestNodeCacheCleanUp(test_base.NodeTest):
400 400
401 def test_old_status(self): 401 def test_old_status(self):
402 CONF.set_override('node_status_keep_time', 42) 402 CONF.set_override('node_status_keep_time', 42)
403 session = db.get_session() 403 session = db.get_writer_session()
404 with session.begin(): 404 with session.begin():
405 db.model_query(db.Node).update( 405 db.model_query(db.Node).update(
406 {'finished_at': (datetime.datetime.utcnow() - 406 {'finished_at': (datetime.datetime.utcnow() -
@@ -412,7 +412,7 @@ class TestNodeCacheCleanUp(test_base.NodeTest):
412 412
413 def test_old_status_disabled(self): 413 def test_old_status_disabled(self):
414 # Status clean up is disabled by default 414 # Status clean up is disabled by default
415 session = db.get_session() 415 session = db.get_writer_session()
416 with session.begin(): 416 with session.begin():
417 db.model_query(db.Node).update( 417 db.model_query(db.Node).update(
418 {'finished_at': (datetime.datetime.utcnow() - 418 {'finished_at': (datetime.datetime.utcnow() -
@@ -427,7 +427,7 @@ class TestNodeCacheGetNode(test_base.NodeTest):
427 def test_ok(self): 427 def test_ok(self):
428 started_at = (datetime.datetime.utcnow() - 428 started_at = (datetime.datetime.utcnow() -
429 datetime.timedelta(seconds=42)) 429 datetime.timedelta(seconds=42))
430 session = db.get_session() 430 session = db.get_writer_session()
431 with session.begin(): 431 with session.begin():
432 db.Node(uuid=self.uuid, 432 db.Node(uuid=self.uuid,
433 state=istate.States.starting, 433 state=istate.States.starting,
@@ -443,7 +443,7 @@ class TestNodeCacheGetNode(test_base.NodeTest):
443 def test_locked(self): 443 def test_locked(self):
444 started_at = (datetime.datetime.utcnow() - 444 started_at = (datetime.datetime.utcnow() -
445 datetime.timedelta(seconds=42)) 445 datetime.timedelta(seconds=42))
446 session = db.get_session() 446 session = db.get_writer_session()
447 with session.begin(): 447 with session.begin():
448 db.Node(uuid=self.uuid, 448 db.Node(uuid=self.uuid,
449 state=istate.States.starting, 449 state=istate.States.starting,
@@ -463,7 +463,7 @@ class TestNodeCacheGetNode(test_base.NodeTest):
463 def test_with_name(self): 463 def test_with_name(self):
464 started_at = (datetime.datetime.utcnow() - 464 started_at = (datetime.datetime.utcnow() -
465 datetime.timedelta(seconds=42)) 465 datetime.timedelta(seconds=42))
466 session = db.get_session() 466 session = db.get_writer_session()
467 with session.begin(): 467 with session.begin():
468 db.Node(uuid=self.uuid, 468 db.Node(uuid=self.uuid,
469 state=istate.States.starting, 469 state=istate.States.starting,
@@ -491,7 +491,7 @@ class TestNodeInfoFinished(test_base.NodeTest):
491 mac=self.macs) 491 mac=self.macs)
492 self.node_info = node_cache.NodeInfo( 492 self.node_info = node_cache.NodeInfo(
493 uuid=self.uuid, started_at=datetime.datetime(3, 1, 4)) 493 uuid=self.uuid, started_at=datetime.datetime(3, 1, 4))
494 session = db.get_session() 494 session = db.get_writer_session()
495 with session.begin(): 495 with session.begin():
496 db.Option(uuid=self.uuid, name='foo', value='bar').save( 496 db.Option(uuid=self.uuid, name='foo', value='bar').save(
497 session) 497 session)
@@ -499,7 +499,7 @@ class TestNodeInfoFinished(test_base.NodeTest):
499 def test_success(self): 499 def test_success(self):
500 self.node_info.finished() 500 self.node_info.finished()
501 501
502 session = db.get_session() 502 session = db.get_writer_session()
503 with session.begin(): 503 with session.begin():
504 self.assertEqual((datetime.datetime(1, 1, 1), None), 504 self.assertEqual((datetime.datetime(1, 1, 1), None),
505 tuple(db.model_query( 505 tuple(db.model_query(
@@ -533,7 +533,7 @@ class TestNodeInfoOptions(test_base.NodeTest):
533 bmc_address='1.2.3.4', 533 bmc_address='1.2.3.4',
534 mac=self.macs) 534 mac=self.macs)
535 self.node_info = node_cache.NodeInfo(uuid=self.uuid, started_at=3.14) 535 self.node_info = node_cache.NodeInfo(uuid=self.uuid, started_at=3.14)
536 session = db.get_session() 536 session = db.get_writer_session()
537 with session.begin(): 537 with session.begin():
538 db.Option(uuid=self.uuid, name='foo', value='"bar"').save( 538 db.Option(uuid=self.uuid, name='foo', value='"bar"').save(
539 session) 539 session)
@@ -927,7 +927,7 @@ class TestNodeCacheListNode(test_base.NodeTest):
927 def setUp(self): 927 def setUp(self):
928 super(TestNodeCacheListNode, self).setUp() 928 super(TestNodeCacheListNode, self).setUp()
929 self.uuid2 = uuidutils.generate_uuid() 929 self.uuid2 = uuidutils.generate_uuid()
930 session = db.get_session() 930 session = db.get_writer_session()
931 with session.begin(): 931 with session.begin():
932 db.Node(uuid=self.uuid, 932 db.Node(uuid=self.uuid,
933 started_at=datetime.datetime(1, 1, 2)).save(session) 933 started_at=datetime.datetime(1, 1, 2)).save(session)