Use maybe_get more

Some suggestions in the review of the related change:

 * use maybe_get in another obvious place
 * make maybe_gets test assertions stronger

Related-Change-Id: Ifd54d76ab1a5a9d82848f3cae89c3e53134aa129

Change-Id: I751f1086d885c18d938f18e8afe1dd0e9c0c57e5
This commit is contained in:
Clay Gerrard 2018-05-22 15:03:30 -07:00
parent 2e321d94ed
commit 6714af8042
2 changed files with 2 additions and 5 deletions

View File

@ -888,11 +888,8 @@ class ContainerBroker(DatabaseBroker):
def _populate_instance_cache(self, conn=None):
# load cached instance attributes from the database if necessary
if self.container is None:
if conn:
with self.maybe_get(conn) as conn:
self._do_get_info_query(conn)
else:
with self.get() as conn:
self._do_get_info_query(conn)
def _get_alternate_object_stats(self):
state = self.get_db_state()

View File

@ -618,7 +618,7 @@ class TestExampleBroker(unittest.TestCase):
with broker.get() as other_conn:
self.assertEqual(broker.conn, None)
with broker.maybe_get(other_conn) as identity_conn:
self.assertEqual(other_conn, identity_conn)
self.assertIs(other_conn, identity_conn)
self.assertEqual(broker.conn, None)
self.assertEqual(broker.conn, None)
self.assertEqual(broker.conn, conn)