#2574 hub: limit CGImport to allow only one CG per import
Merged a year ago by tkopecek. Opened 2 years ago by tkopecek.
tkopecek/koji issue2511a  into  master

file modified
+12 -12
@@ -6277,22 +6277,24 @@ 

      def assert_cg_access(self):

          """Check that user has access for all referenced content generators"""

  

-         cgs = set()

+         cg_id = None

          for brdata in self.metadata['buildroots']:

              cginfo = brdata['content_generator']

              cg = lookup_name('content_generator', cginfo['name'], strict=True)

-             cgs.add(cg['id'])

-             brdata['cg_id'] = cg['id']

-         for cg_id in cgs:

-             assert_cg(cg_id)

-         self.cgs = cgs

+             if cg_id is None:

+                 cg_id = cg['id']

+             elif cg_id != cg['id']:

+                 raise koji.GenericError("Koji now support only one content-generator per import")

+             brdata['cg_id'] = cg_id

+         assert_cg(cg_id)

+         self.cg = cg_id

  

      def assert_policy(self):

          policy_data = {

              'package': self.buildinfo['name'],

              'source': self.buildinfo.get('source'),

              'metadata_only': self.metadata_only,

-             'cg_list': list(self.cgs),

+             'cg_list': [self.cg],

              # TODO: provide more data

          }

          assert_policy('cg_import', policy_data)
@@ -6305,7 +6307,7 @@ 

              'version': self.buildinfo['version'],

              'release': self.buildinfo['release'],

              'source': self.buildinfo['source'],

-             'cg_list': list(self.cgs),

+             'cg_list': [self.cg],

              'import': True,

              'import_type': 'cg',

          }
@@ -6327,10 +6329,7 @@ 

      def prep_build(self, token=None):

          metadata = self.metadata

          if metadata['build'].get('build_id'):

-             if len(self.cgs) != 1:

-                 raise koji.GenericError(

-                     "Reserved builds can handle only single content generator.")

-             cg_id = list(self.cgs)[0]

+             cg_id = self.cg

              build_id = metadata['build']['build_id']

              buildinfo = get_build(build_id, strict=True)

              build_token = get_reservation_token(build_id)
@@ -6374,6 +6373,7 @@ 

              if not isinstance(owner, str):

                  raise koji.GenericError("Invalid owner format (expected username): %s" % owner)

              buildinfo['owner'] = get_user(owner, strict=True)['id']

+         buildinfo['cg_id'] = self.cg

          self.buildinfo = buildinfo

  

          koji.check_NVR(buildinfo, strict=True)

@@ -67,19 +67,23 @@ 

          x = kojihub.CG_Importer()

          x.get_metadata('default.json', 'cg_importer_json')

          x.assert_cg_access()

-         assert x.cgs

-         assert isinstance(x.cgs, set)

+         assert x.cg

+         assert isinstance(x.cg, int)

  

+     @mock.patch("kojihub.get_build")

      @mock.patch("kojihub.get_user")

      @mock.patch('kojihub.context')

      @mock.patch("koji.pathinfo.work")

-     def test_prep_build(self, work, context, get_user):

+     def test_prep_build(self, work, context, get_user, get_build):

          work.return_value = os.path.dirname(__file__)

          cursor = mock.MagicMock()

          context.cnx.cursor.return_value = cursor

+         cursor.fetchall.return_value = [(1, 'foo'), (2, 'bar')]

          get_user.return_value = {'id': 123}

+         get_build.return_value = {}

          x = kojihub.CG_Importer()

          x.get_metadata('default.json', 'cg_importer_json')

+         x.assert_cg_access()

          x.prep_build()

          assert x.buildinfo

          assert isinstance(x.buildinfo, dict)
@@ -128,12 +132,14 @@ 

      def test_get_build(self, work, context, new_build_id, get_build, get_user):

          work.return_value = os.path.dirname(__file__)

          cursor = mock.MagicMock()

+         cursor.fetchall.return_value = [(1, 'foo'), (2, 'bar')]

          context.cnx.cursor.return_value = cursor

          new_build_id.return_value = 42

          get_build.return_value = False

          get_user.return_value = {'id': 123}

          x = kojihub.CG_Importer()

          x.get_metadata('default.json', 'cg_importer_json')

+         x.assert_cg_access()

          x.prep_build()

          x.prepped_outputs = []

          get_build.return_value = {'id': 43, 'package_id': 1,

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

a year ago

The testing ready tag was removed temporarily because of conflict with other PR.

Metadata Update from @mfilip:
- Pull-request untagged with: testing-ready

a year ago

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

a year ago

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

a year ago

pretty please pagure-ci rebuild

a year ago

1 new commit added

  • fix tests
a year ago

Commit 812c1a8 fixes this pull-request

Pull-Request has been merged by tkopecek

a year ago