clarify debug logging for test fixtures

Have the fixtures report more details about what they're doing so when
we see the processutils output we can tell why the commands are being run.

Change-Id: I17374484e3e7457cf836c2dae695f0ca5a46ea8e
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
Doug Hellmann 2018-09-24 09:15:53 -04:00
parent 1fdf4b0bac
commit 27da7e8486
1 changed files with 9 additions and 4 deletions

View File

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