Merge "Correct LOG.debug use"

This commit is contained in:
Jenkins 2014-07-21 18:34:57 +00:00 committed by Gerrit Code Review
commit aab56ad423
2 changed files with 23 additions and 12 deletions

View File

@ -60,35 +60,38 @@ class TypeDriverHelper(api.TypeDriver):
# Segment not allocated
LOG.debug("%(type)s segment %(segment)s allocate "
"started ",
type=network_type, segment=raw_segment)
{"type": network_type,
"segment": raw_segment})
count = (session.query(self.model).
filter_by(allocated=False, **raw_segment).
update({"allocated": True}))
if count:
LOG.debug("%(type)s segment %(segment)s allocate "
"done ",
type=network_type, segment=raw_segment)
{"type": network_type,
"segment": raw_segment})
return alloc
# Segment allocated or deleted since select
LOG.debug("%(type)s segment %(segment)s allocate "
"failed: segment has been allocated or "
"deleted",
type=network_type, segment=raw_segment)
{"type": network_type,
"segment": raw_segment})
# Segment to create or already allocated
LOG.debug("%(type)s segment %(segment)s create started",
type=network_type, segment=raw_segment)
{"type": network_type, "segment": raw_segment})
alloc = self.model(allocated=True, **raw_segment)
alloc.save(session)
LOG.debug("%(type)s segment %(segment)s create done",
type=network_type, segment=raw_segment)
{"type": network_type, "segment": raw_segment})
except db_exc.DBDuplicateEntry:
# Segment already allocated (insert failure)
alloc = None
LOG.debug("%(type)s segment %(segment)s create failed",
type=network_type, segment=raw_segment)
{"type": network_type, "segment": raw_segment})
return alloc
@ -115,24 +118,24 @@ class TypeDriverHelper(api.TypeDriver):
raw_segment = dict((k, alloc[k]) for k in self.primary_keys)
LOG.debug("%(type)s segment allocate from pool, attempt "
"%(attempt)s started with %(segment)s ",
type=network_type, attempt=attempt,
segment=raw_segment)
{"type": network_type, "attempt": attempt,
"segment": raw_segment})
count = (session.query(self.model).
filter_by(allocated=False, **raw_segment).
update({"allocated": True}))
if count:
LOG.debug("%(type)s segment allocate from pool, attempt "
"%(attempt)s success with %(segment)s ",
type=network_type, attempt=attempt,
segment=raw_segment)
{"type": network_type, "attempt": attempt,
"segment": raw_segment})
return alloc
# Segment allocated since select
LOG.debug("Allocate %(type)s segment from pool, "
"attempt %(attempt)s failed with segment "
"%(segment)s",
type=network_type, attempt=attempt,
segment=raw_segment)
{"type": network_type, "attempt": attempt,
"segment": raw_segment})
LOG.warning(_("Allocate %(type)s segment from pool failed "
"after %(number)s failed attempts"),

View File

@ -13,6 +13,8 @@
# License for the specific language governing permissions and limitations
# under the License.
import fixtures
import logging
import mock
from sqlalchemy.orm import query
@ -42,6 +44,12 @@ class HelpersTest(base.BaseTestCase):
self.driver._sync_vlan_allocations()
self.session = db.get_session()
self.addCleanup(db.clear_db)
self.useFixture(
fixtures.FakeLogger(
name=helpers.__name__,
format=base.LOG_FORMAT,
level=logging.DEBUG
))
def check_raw_segment(self, expected, observed):
for key, value in expected.items():