Skip to content

Commit

Permalink
Code review PR 6705 ManageIQ#2
Browse files Browse the repository at this point in the history
Updated logging calls to not use format() as that is unnecessary.
Also had to add an import of logger to coverage_report_sprout.py.
  • Loading branch information
jamesooden committed Mar 2, 2018
1 parent 10592e8 commit 47c45c8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
40 changes: 19 additions & 21 deletions scripts/coverage_report_jenkins.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ def merge_coverage_data(ssh, coverage_dir):
logger.info(str(cmd))
percentage = re.search(r'LOC\s+\((\d+.\d+%)\)\s+covered\.', str(cmd))
if percentage:
logger.info('COVERAGE={};'.format(percentage.groups()[0]))
logger.info('COVERAGE=%s', percentage.groups()[0])
else:
logger.info('COVERAGE=unknown;')
logger.info('COVERAGE=unknown')

# The sonar-scanner will actually need the .resultset.json file it
# uses to be in /coverage/.resultset.json (i.e. the root of the coverarage
Expand Down Expand Up @@ -279,10 +279,10 @@ def install_sonar_scanner(ssh, project_version, scanner_url, scanner_dir, server
version=str(project_version).strip())

# Write the config file locally and then copy to remote.
logger.info('Writing {}'.format(local_conf))
logger.info('Writing %s', local_conf)
with open(local_conf, 'w') as f:
f.write(config_data)
logger.info('Copying {} to appliance as {}'.format(local_conf, remote_conf))
logger.info('Copying %s to appliance as %s', local_conf, remote_conf)
ssh.put_file(local_conf, remote_conf)


Expand All @@ -300,8 +300,8 @@ def run_sonar_scanner(ssh, scanner_dir, timeout):
Nothing
"""
logger.info('Running sonar scan. This may take a while.')
logger.info(' timeout={}'.format(timeout))
logger.info(' start_time={}'.format(time.strftime('%T')))
logger.info(' timeout=%s', timeout)
logger.info(' start_time=%s', time.strftime('%T'))
scanner_executable = '{}/bin/sonar-scanner'.format(scanner_dir)

# It's very important that we run the sonar-scanner from / as this
Expand All @@ -312,7 +312,7 @@ def run_sonar_scanner(ssh, scanner_dir, timeout):
result = ssh.run_command(cmd, timeout=timeout)
if not result:
raise Exception("sonar scan failed!\ncmd: {}\noutput: {}".format(cmd, result))
logger.info(' end_time={}'.format(time.strftime('%T')))
logger.info(' end_time=%s', time.strftime('%T'))


def sonar_scan(ssh, project_version, scanner_url, scanner_dir, server_url, timeout):
Expand Down Expand Up @@ -346,7 +346,7 @@ def main(appliance, jenkins_url, jenkins_user, jenkins_token, job_name):
'--jenkins-user and --jenkins-token not provided and credentials yaml does not '
'contain the jenkins_app entry with user and token')
appliance_version = str(appliance.version).strip()
logger.info('Looking for appliance version {} in {}'.format(appliance_version, job_name))
logger.info('Looking for appliance version %s in %s', appliance_version, job_name)
client = jenkins.Jenkins(jenkins_url, username=jenkins_user, password=jenkins_token)
build_numbers = get_build_numbers(client, job_name)
if not build_numbers:
Expand All @@ -360,33 +360,30 @@ def main(appliance, jenkins_url, jenkins_user, jenkins_token, job_name):
if not artifacts:
raise ValueError()
except (KeyError, ValueError):
logger.info('No artifacts for {}/{}'.format(job_name, build_number))
logger.info('No artifacts for %s/%s', job_name, build_number)
continue

artifacts = group_list_dict_by(artifacts, 'fileName')
if 'appliance_version' not in artifacts:
logger.info(
'appliance_version not in artifacts of {}/{}'.format(job_name, build_number))
logger.info('appliance_version not in artifacts of %s/%s', job_name, build_number)
continue

build_appliance_version = download_artifact(
jenkins_user, jenkins_token, jenkins_url, job_name, build_number,
artifacts['appliance_version']['relativePath']).strip()

if not build_appliance_version:
logger.info('Appliance version unspecified for build {}'.format(build_number))
logger.info('Appliance version unspecified for build %s', build_number)
continue

if Version(build_appliance_version) < Version(appliance_version):
logger.info(
'Build {} already has lower version ({})'.format(
build_number, build_appliance_version))
'Build %s already has lower version (%s)', build_number, build_appliance_version)
logger.info('Ending here')
break

if 'coverage-results.tgz' not in artifacts:
logger.info(
'coverage-results.tgz not in artifacts of {}/{}'.format(job_name, build_number))
logger.info('coverage-results.tgz not in artifacts of %s/%s', job_name, build_number)
continue

if not check_artifact(
Expand All @@ -396,12 +393,13 @@ def main(appliance, jenkins_url, jenkins_user, jenkins_token, job_name):
continue

if build_appliance_version == appliance_version:
logger.info('Build {} was found to contain what is needed'.format(build_number))
logger.info('Build %s was found to contain what is needed', build_number)
eligible_build_numbers.add(build_number)
else:
logger.info(
'Skipping build {} because it does not have correct version ({})'.format(
build_number, build_appliance_version))
'Skipping build %s because it does not have correct version (%s)',
build_number,
build_appliance_version)

if not eligible_build_numbers:
raise Exception(
Expand All @@ -424,7 +422,7 @@ def main(appliance, jenkins_url, jenkins_user, jenkins_token, job_name):

# Download and extract all the coverage data
for build_number in eligible_build_numbers:
logger.info('Downloading the coverage data from build {}'.format(build_number))
logger.info('Downloading the coverage data from build %s', build_number)
download_url = jenkins_artifact_url(
jenkins_user, jenkins_token, jenkins_url, job_name, build_number,
artifacts['coverage-results.tgz']['relativePath'])
Expand All @@ -435,7 +433,7 @@ def main(appliance, jenkins_url, jenkins_user, jenkins_token, job_name):
raise Exception('Could not download! - {}'.format(str(cmd)))

# Extract coverage data
logger.info('Extracting the coverage data from build {}'.format(build_number))
logger.info('Extracting the coverage data from build %s', build_number)
extract_command = ' && '.join([
'cd {}'.format(coverage_dir),
'tar xf tmp.tgz --strip-components=1',
Expand Down
8 changes: 5 additions & 3 deletions scripts/coverage_report_sprout.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
from cfme.utils.appliance import IPAppliance
from cfme.utils.conf import env

# Note we get our logging setup from this load too.
from coverage_report_jenkins import main as coverage_report_jenkins
from coverage_report_jenkins import logger

if __name__ == '__main__':
parser = argparse.ArgumentParser()
Expand All @@ -23,18 +25,18 @@
# TODO: Upstream support
group = 'downstream-' + ''.join(args.version.split('.')[:2]) + 'z'
sprout = SproutClient.from_config()
logger.info('requesting an appliance from sprout for {}/{}'.format(group, args.version))
logger.info('requesting an appliance from sprout for %s/%s', group, args.version)
pool_id = sprout.request_appliances(
group,
version=args.version,
lease_time=env.sonarqube.scanner_lease)
logger.info('Requested pool {}'.format(pool_id))
logger.info('Requested pool %s', pool_id)
result = None
try:
while not result or not (result['fulfilled'] and result['finished']):
result = sprout.request_check(pool_id)
appliance_ip = result['appliances'][0]['ip_address']
logger.info('received an appliance with IP address: {}'.format(appliance_ip))
logger.info('received an appliance with IP address: %s', appliance_ip)
with IPAppliance(hostname=appliance_ip) as appliance:
exit(
coverage_report_jenkins(
Expand Down

0 comments on commit 47c45c8

Please sign in to comment.