#4483 fakepolicy dev tool
Merged by mikem. Opened by mikem.
mikem/koji fakepolicy  into  master

Download 4483.patch

This adds a new script under devtools that facilitates testing policy code against a remote instance. The script runs some heavily mocked hub code that calls out to a remote instance for actual data access.

There are several subcommands that simulate various policy checkpoints in the current code. There is also a manual subcommand for specifying arbitrary policies and data on the command line.

manual              manually specify policy and data
make-task           simulate policies for make_task
promote-build       simulate draft_promotion policy for promote_build
apply-volume        simulate volume policy for apply_volume
tag-build           simulate policy for tagging a build
move-build          simulate policy for moving a build
untag-build         simulate policy for untagging a build
add-pkg             simulate policy for adding a package

The reason for this tool's existence is that policy code is very hard to test without actual data, which is usually locked up inside a Koji instance. This script allows you to see what a given policy would do, without actually deploying it.

Consider this example

[mikem@localhost koji]$ cat mypolicy.conf 
[policy]
channel =
    has req_channel :: req
    is_child_task :: parent
    method build :: {
        target f44* :: use group1
        target f4[23]* :: use group2
    }
    all :: use default
[mikem@localhost koji]$ ./devtools/fakepolicy -f mypolicy.conf -o LogFormat='%(message)s' -p koji make-task 138128709
Loading plugin: sidetag_hub
Loading plugin: rpm-sign
Testing policy channel with data:
{'arch': 'noarch',
 'label': None,
 'method': 'build',
 'owner': 3978,
 'parent': None,
 'scratch': True,
 'source': 'git+https://src.fedoraproject.org/forks/coiby/rpms/kdump-anaconda-addon.git#3c8ae1ea20cab23bee76051645cde28bb6f7226f',
 'target': 'f42-candidate',
 'user_id': 3978}
policy start
Rule: has req_channel :: req
  has req_channel  -> False
Rule: is_child_task :: parent
  is_child_task  -> False
Rule: method build :: { ...
  method build  -> True
  matched: entering subrule
Rule: target f44* :: use group1
  target f44*  -> False
Rule: target f4[23]* :: use group2
  target f4[23]*  -> True
  rule matched: use group2
policy done
RESULT:
'use group2'

My koji profile points to the Fedora instance, so this policy execution is based on data from this task -- https://koji.fedoraproject.org/koji/taskinfo?taskID=138128709

This very simple test policy I have here would have mapped this task to the group2 channel (not a real channel in the fedora instance). The output shows the code tracing through the policy.

14 new commits added

  • flake8
  • simulate add-pkg
  • simulate untag-build
  • simulate tag-build
  • finish subcommand conversion
  • working?
  • partial
  • convert to argparse
  • fix cg lookup
  • ...
  • ...
  • additional data generation args
  • split out policy data construction
  • handle hub config overrides

3 new commits added

  • misc cleanup
  • req_channel arg
  • tweak help

rebased onto ff90fb9bf146962c04e0720f1fa3dbf4aba42bd3

@julian8628

Metadata Update from @mikem:
- Pull-request tagged with: no_qe

2 new commits added

  • avoid variable name overlap
  • compact result output

:thumbsup:

rebased onto 5ff8bab254d6cbb41c3d1ed9db5261669ab52cfe

Commit bd05c42e fixes this pull-request

Pull-Request has been merged by mikem

Metadata