Merge "clarify debug logging for test fixtures"

This commit is contained in:
Zuul 2018-10-11 02:39:21 +00:00 committed by Gerrit Code Review
commit 65c449c542

View File

@ -21,6 +21,8 @@ import fixtures
from openstack_releases import processutils from openstack_releases import processutils
LOG = logging.getLogger(__name__)
class GPGKeyFixture(fixtures.Fixture): class GPGKeyFixture(fixtures.Fixture):
"""Creates a GPG key for testing. """Creates a GPG key for testing.
@ -52,6 +54,7 @@ class GPGKeyFixture(fixtures.Fixture):
gnupg_version = (0, 0, 0) gnupg_version = (0, 0, 0)
config_file = tempdir.path + '/key-config' config_file = tempdir.path + '/key-config'
LOG.debug('creating gpg config file in %s', config_file)
with open(config_file, 'wt') as f: with open(config_file, 'wt') as f:
if gnupg_version[0] == 2 and gnupg_version[1] >= 1: if gnupg_version[0] == 2 and gnupg_version[1] >= 1:
f.write(textwrap.dedent(""" f.write(textwrap.dedent("""
@ -83,13 +86,12 @@ class GPGKeyFixture(fixtures.Fixture):
cmd.append(gnupg_random) cmd.append(gnupg_random)
cmd.append('key-config') cmd.append('key-config')
LOG.debug('generating gpg key')
processutils.check_call(cmd, cwd=tempdir.path) processutils.check_call(cmd, cwd=tempdir.path)
class GitRepoFixture(fixtures.Fixture): class GitRepoFixture(fixtures.Fixture):
logger = logging.getLogger('git')
def __init__(self, workdir, name): def __init__(self, workdir, name):
self.workdir = workdir self.workdir = workdir
self.name = name self.name = name
@ -100,6 +102,7 @@ class GitRepoFixture(fixtures.Fixture):
super().setUp() super().setUp()
self.useFixture(GPGKeyFixture()) self.useFixture(GPGKeyFixture())
os.makedirs(self.path) os.makedirs(self.path)
LOG.debug('initializing repo in %s', self.path)
self.git('init', '.') self.git('init', '.')
self.git('config', '--local', 'user.email', 'example@example.com') self.git('config', '--local', 'user.email', 'example@example.com')
self.git('config', '--local', 'user.name', 'super developer') self.git('config', '--local', 'user.name', 'super developer')
@ -107,24 +110,26 @@ class GitRepoFixture(fixtures.Fixture):
'example@example.com') 'example@example.com')
def git(self, *args): def git(self, *args):
self.logger.debug('$ git %s', ' '.join(args))
output = processutils.check_output( output = processutils.check_output(
['git'] + list(args), ['git'] + list(args),
cwd=self.path, cwd=self.path,
) )
self.logger.debug(output)
return output return output
def commit(self, message='commit message'): def commit(self, message='commit message'):
LOG.debug('committing %r', message)
self.git('add', '.') self.git('add', '.')
self.git('commit', '-m', message) self.git('commit', '-m', message)
sha = self.git('log', '-n', '1', '--pretty=format:%H') sha = self.git('log', '-n', '1', '--pretty=format:%H')
LOG.debug('SHA: %r', sha)
return sha.decode('utf-8').strip() return sha.decode('utf-8').strip()
def add_file(self, name): def add_file(self, name):
LOG.debug('adding file %r', name)
with open(os.path.join(self.path, name), 'w') as f: with open(os.path.join(self.path, name), 'w') as f:
f.write('adding %s\n' % name) f.write('adding %s\n' % name)
return self.commit('add %s' % name) return self.commit('add %s' % name)
def tag(self, version): def tag(self, version):
LOG.debug('tagging %r', version)
self.git('tag', '-s', '-m', version, version) self.git('tag', '-s', '-m', version, version)