SUSE Hack Week 2024 - Day 4

> posts > 2024 > Nov

Published:

Today was the focus on writing the pagure ci plugin and fine-tune my design and architecture assumptions on the way. Basically transferring the outcome of day 3 into some code. I decided to use a Test-Driven approach and to keep a close eye on existing pagure ci related tests while I have to refactor some existing code too.

Before I started to write tests, I wanted to validate a couple of assumptions on my pagure dev instance. Unfortunately I had to fix a couple errors over there (file permissions, pagure_worker runs as apache and not git user, db scheme forgotten to upgrade...) before I finally could start. It's always a good opportunity, you learn most when things are broken. But I lost quite some coding time that way...

Speaking of coding, the main challenge was that some information I want/need in my generic plugin are currently not passed.

What we currently have doesn't leaves much room for the plugin to get additional data:

def trigger_build(
    project_path,
    url,
    job,
    token,
    branch,
    branch_to,
    cause,
    ci_username=None,
    ci_password=None,
):

What I want in future to make things more flexible:

def trigger_build(
        project: model.Project,
        ci_url: str,
        ci_job: str,
        ci_token: str,
        branch: str,
        branch_to: str,
        is_pull_request: bool = False,
        is_commit: bool = False,
        commit_hash: str = None,
        pull_request_id: str = None,
        pull_request_uid: str = None,
        ci_username = None,
        ci_password = None,
) -> None:

This could be further improved by passing model.PullRequest instead of pull_request_id and pull_request_uid. Then it's up to the pagure ci plugin to decide what data are needed, similar as with project. When I'm done with the generic plugin then the existing jenkins need some refactoring to work with the new parameters.

I started to write the tests and iterate through the different plugin functionality. All that went well until I hit a problem that still drives me crazy. It shouldn't be hard to verify that a method was called with the expected args by using assert_called_once_with. But it throws a nice AssertionError: expected call not found. even though Expected and Actual match:

E           AssertionError: expected call not found.
E           Expected: trigger_build(project=Project(1, name:test, namespace:None, url:None, is_fork:False, parent_id:None), ci_url='https://ci.example.com/', ci_job='pagure', ci_token='random_token', branch='feature', branch_to='main', is_pull_request=True, is_commit=False, commit_hash=None, pull_request_id='1', pull_request_uid='720a0568c1274e74966e54b433b2003e', ci_username=None, ci_password=None)
E           Actual:   trigger_build(project=Project(1, name:test, namespace:None, url:None, is_fork:False, parent_id:None), ci_url='https://ci.example.com/', ci_job='pagure', ci_token='random_token', branch='feature', branch_to='main', is_pull_request=True, is_commit=False, commit_hash=None, pull_request_id='1', pull_request_uid='720a0568c1274e74966e54b433b2003e', ci_username=None, ci_password=None)

I take a break and try it again tomorrow after some sleep. Maybe I'm tired and missing something obvious. But for me both look the same and there shouldn't be an assertion error.

Let's hope I can figure out tomorrow what's going wrong here...

[ Show Source | Download PDF ]