#1000 Fix target handling in make_task
Merged 5 years ago by mikem. Opened 5 years ago by tkopecek.
tkopecek/koji issue998  into  master

file modified
+6 -6
@@ -546,16 +546,16 @@ 

                  hastarget = True

                  break

          if hastarget:

-             if target is None:

-                 policy_data['target'] = None

-             elif isinstance(target, dict):

+             if isinstance(target, dict):

                  if 'name' not in target:

-                     hastarget = False

                      logger.warning("Bad build target parameter: %r", target)

+                     target = None

                  else:

                      target = target.get('name')

-         if hastarget:

-             policy_data['target'] = get_build_target(target, strict=True)['name']

+             if target is None:

+                 policy_data['target'] = None

+             else:

+                 policy_data['target'] = get_build_target(target, strict=True)['name']

          t_opts = params.get('opts', {})

          policy_data['scratch'] = t_opts.get('scratch', False)

  

None target means null-target, in koji-shadow it could be None.
I think if there's no target in parameters, target shouldn't be put in policy_data

Wondering if hastarget is necessary, can we use if target instead?

Add test (note for me)

We should not add a target value where there is none defined. No target defined is different from an explicit target value of None. I think instead that we should have some of the tests handle this more gracefully.

  1. BoolTest could default to false when the field is absent. Policies that care about the difference can use the has test to distinguish.
  2. Similarly our other base tests that use fields (MatchTest and CompareTest) could return False if there is no field to match
  3. We could add an explicit target test (subclass of MatchTest, similar to other such tests), that is friendlier than using the match test directly. (This part could maybe be deferred a little).

rebased onto 3d9445c

5 years ago

I've fixed the PR. @mikem Do we want to track those tests' improvements in separate issue?

Commit cd76114 fixes this pull-request

Pull-Request has been merged by mikem

5 years ago

I;ve filed #1038 and #1040 for the policy test follow ups