#2872 hub: policy test buildtag_inheritance
Merged a year ago by tkopecek. Opened a year ago by tkopecek.
tkopecek/koji issue2870  into  master

file modified
+30 -4
@@ -9410,7 +9410,8 @@ 

      return cgs

  

  

- def policy_get_build_tags(data):

+ def policy_get_build_tags(data, taginfo=False):

+     """If taginfo is set, return list of taginfos, else list of names only"""

      if 'build_tag' in data:

          return [get_tag(data['build_tag'], strict=True)['name']]

      elif 'build_tags' in data:
@@ -9424,12 +9425,18 @@ 

              return [target['build_tag_name']]

  

      # otherwise look at buildroots

-     tags = set()

+     tags = {}

      for br_id in policy_get_brs(data):

          if br_id is None:

-             tags.add(None)

+             tags[None] = None

          else:

-             tags.add(get_buildroot(br_id, strict=True)['tag_name'])

+             tinfo = get_buildroot(br_id, strict=True)

+             tags[tinfo['tag_name']] = tinfo

+ 

+     if taginfo:

+         tags = tags.values()

+     else:

+         tags = tags.keys()

      return tags

  

  
@@ -9631,6 +9638,25 @@ 

          return False

  

  

+ class BuildTagInheritsFromTest(koji.policy.BaseSimpleTest):

+     """Check all parents of buildtag (without child tag)"""

+     name = 'buildtag_inherits_from'

+ 

+     def run(self, data):

+         test_name, *args = self.str.split()

+         assert(test_name == self.name)

+         for tinfo in policy_get_build_tags(data, taginfo=True):

+             if tinfo is None:

+                 # content generator buildroots might not have tag info

+                 continue

+ 

+             for tag in readFullInheritance(tinfo['tag_id']):

+                 if multi_fnmatch(tag['name'], args):

+                     return True

+         # otherwise...

+         return False

+ 

+ 

  class BuildTypeTest(koji.policy.BaseSimpleTest):

      """Check the build type(s) of the build"""

  

@@ -259,6 +259,64 @@ 

          self.assertFalse(obj.run(data))

  

  

+ class TestBuildTagInheritsFromTest(unittest.TestCase):

+ 

+     def setUp(self):

+         self.policy_get_build_tags = mock.patch('kojihub.policy_get_build_tags').start()

+         self.readFullInheritance = mock.patch('kojihub.readFullInheritance').start()

+ 

+     def tearDown(self):

+         mock.patch.stopall()

+ 

+     def test_wrong_test_name(self):

+         obj = kojihub.BuildTagInheritsFromTest('buildtag_inherits_from_type foo*')

+         data = {}

+         self.policy_get_build_tags.return_value = {None}

+         with self.assertRaises(AssertionError):

+             obj.run(data)

+ 

+     def test_no_buildtag(self):

+         obj = kojihub.BuildTagInheritsFromTest('buildtag_inherits_from foo*')

+         data = {}

+         self.policy_get_build_tags.return_value = {None}

+         self.assertFalse(obj.run(data))

+         self.policy_get_build_tags.assert_called_once_with(data, taginfo=True)

+         self.readFullInheritance.assert_not_called()

+ 

+     def test_no_inheritance(self):

+         obj = kojihub.BuildTagInheritsFromTest('buildtag_inherits_from foo*')

+         data = {}

+         self.policy_get_build_tags.return_value = [{'tag_id': 123, 'tag_name': 'foox'}]

+         self.readFullInheritance.return_value = []

+         self.assertFalse(obj.run(data))

+         self.policy_get_build_tags.assert_called_once_with(data, taginfo=True)

+         self.readFullInheritance.assert_called_once_with(123)

+ 

+     def test_inheritance_pass(self):

+         obj = kojihub.BuildTagInheritsFromTest('buildtag_inherits_from foo*')

+         data = {}

+         self.policy_get_build_tags.return_value = [{'tag_id': 123, 'tag_name': 'wrong'}]

+         self.readFullInheritance.return_value = [

+             {'name': 'still-wrong'},

+             {'name': 'foox'},

+         ]

+         self.assertTrue(obj.run(data))

+         self.policy_get_build_tags.assert_called_once_with(data, taginfo=True)

+         self.readFullInheritance.assert_called_once_with(123)

+ 

+     def test_inheritance_fail(self):

+         obj = kojihub.BuildTagInheritsFromTest('buildtag_inherits_from foo*')

+         data = {}

+         self.policy_get_build_tags.return_value = [{'tag_id': 123, 'tag_name': 'wrong'}]

+         self.readFullInheritance.return_value = [

+             {'name': 'still-wrong'},

+             {'name': 'still-still-wrong'},

+         ]

+         self.assertFalse(obj.run(data))

+         self.policy_get_build_tags.assert_called_once_with(data, taginfo=True)

+         self.readFullInheritance.assert_called_once_with(123)

+ 

+ 

  class TestBuildTypeTest(unittest.TestCase):

      def setUp(self):

          self.get_build_type = mock.patch('kojihub.get_build_type').start()

Maybe different test name?

I'm not sure about including the tag itself in the check, as that is already covered in the original buildtag test. We don't normally say that a tag inherits from itself, but maybe this makes sense anyway?

I'm curious if we have any hypothetical cases where someone would use this test and want/not-want to also match against the tag itself. In the MBS case that inspired this, I don't think it matters.

Maybe different test name?

I originally suggested something like "buildtag_inherits_from". If we were to go with that, I think that would definitely change the expectation to not match the buildtag itself.

Ok, with renaming it makes more sense to not include the buildtag itself. And it is simple to write rule 'buildtag or buildtag_inherits_from' if anybody wants. I'll change it.

rebased onto 15c115e

a year ago

Metadata Update from @tkopecek:
- Pull-request tagged with: testing-ready

a year ago

Commit e123907 fixes this pull-request

Pull-Request has been merged by tkopecek

a year ago

Metadata Update from @jcupova:
- Pull-request tagged with: testing-done

11 months ago