~paelzer/ubuntu-helpers:lp-test-small-fixes

Last commit made on 2022-06-22
Get this branch:
git clone -b lp-test-small-fixes https://git.launchpad.net/~paelzer/ubuntu-helpers
Only Christian Ehrhardt  can upload to this branch. If you are Christian Ehrhardt  please log in for upload directions.

Branch merges

Branch information

Name:
lp-test-small-fixes
Repository:
lp:~paelzer/ubuntu-helpers

Recent commits

fd36e0f... by Christian Ehrhardt 

lp-test-ppa: fulfill flake8 two line rule

Before we hit a few of:
  E305 expected 2 blank lines after class or function definition

Signed-off-by: Christian Ehrhardt <email address hidden>

dac65dc... by Christian Ehrhardt 

lp-test-ppa: fix time of running jobs

Commit 789da2bf "lp-test-ppa: Add a Job class to contain data elements" broke
the display of time:
old:
    0:00:20 roundcube jammy s390x ci-train-ppa-service/4872
new:
    10 roundcube jammy s390x ci-train-ppa-service/4872

Since internal data and presentation shall be split this is still needed
but not added in the parsing. Instead it is now added to the function
that outputs the running job info.

Signed-off-by: Christian Ehrhardt <email address hidden>

9eb8558... by Christian Ehrhardt 

lp-test-ppa: credential_store isn't used later

Signed-off-by: Christian Ehrhardt <email address hidden>

d89b4c5... by Christian Ehrhardt 

lp-test-ppa: overwriting a local variable renders --arch useless

Signed-off-by: Christian Ehrhardt <email address hidden>

efb5a67... by Christian Ehrhardt 

lp-test-ppa: fix use of base launchpad api reference

Signed-off-by: Christian Ehrhardt <email address hidden>

63b4c95... by Bryce Harrington

lp-test-ppa: Skip private jobs

Fixes an exception thrown if there are jobs labeled 'private job' in the
waiting queue. The error looks like:

    Traceback (most recent call last):
      File "/home/bryce/bin/lp-test-ppa", line 421, in <module>
        showActive(release, ppa_user, ppa_name)
      File "/home/bryce/bin/lp-test-ppa", line 128, in showActive
        waiting = getWaiting()
      File "/home/bryce/bin/lp-test-ppa", line 60, in getWaiting
        jobinfo = json.loads(json_data)
      File "/usr/lib/python3.8/json/__init__.py", line 357, in loads
        return _default_decoder.decode(s)
      File "/usr/lib/python3.8/json/decoder.py", line 337, in decode
        obj, end = self.raw_decode(s, idx=_w(s, 0).end())
      File "/usr/lib/python3.8/json/decoder.py", line 355, in raw_decode
        raise JSONDecodeError("Expecting value", s, err.value) from None
    json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

The data being processed looks like:

    ...
    key = 'minilla
    {"submit-time": "2022-06-16 01:58:54", "triggers": ["libmodule-runtime-perl/0.016-2"]}'
    key = 'perlimports
    {"submit-time": "2022-06-16 01:58:54", "triggers": ["libmodule-runtime-perl/0.016-2"]}'
    key = 'private job'

The code attempts to split key, which normally gives a package name and
json object:

    (pkg, json_data) = key.split(maxsplit=1)

We get pkg="private" and json_data="job", which is invalid.

For our purposes we can simply skip private jobs.

789da2b... by Bryce Harrington

lp-test-ppa: Add a Job class to contain data elements

Promotes a dict of job information into a class to encapsulate the
information.

Fixes a (theoretical?) bug where autopkgtest could return multiple PPAs
for a given job, which would result in a failed check here:

    running = [e for e in running if e['ppa'] == target]

In the case of multiple ppas, e['ppa'] will have been set to, say,
'user/foo,user/bar' and if we're testing for 'user/foo' it will fail.
The fix is to test if target is within the list of ppas:

    running = [e for e in running if target in e.ppas]

This also fixes a logic error, where the 'ppas' list is looked up, and
defaults to a string, when it should be defaulting to a list:

    ppas = ','.join(jobinfo.get('ppas', '-'))

This is purely theoretical though since lp-test-ppa requires a ppa
argument be given when run, so there should always be (at least) one ppa
defined. A similar issue may exist with 'triggers' (and may be less
theoretical). Both cases are fixed by returning a list for default:

    return self.jobinfo.get('ppas', ['-'])

7d63013... by Bryce Harrington

lp-test-ppa: Fix indentation consistency

3a1e2a2... by Bryce Harrington

lp-test-ppa: Add an error() helper

There's only one defined error condition (so far), but it should be
printed to stderr.

0dd44f1... by Bryce Harrington

lp-test-ppa: Move global code into a main() routine

The argparse setup code moves to its own subroutine (for testability
purposes).

ARCHES is expected to be a global, so make that more apparent.