#2934 Add btype to protonmsg
Merged 10 months ago by tkopecek. Opened 10 months ago by jcupova.
jcupova/koji issue-1217  into  master

file modified
+6 -4
@@ -4613,10 +4613,12 @@ 

      Returns a dictionary whose keys are type names and whose values are

      the type info corresponding to that type

      """

- 

-     binfo = get_build(buildInfo, strict=strict)

-     if not binfo:

-         return None

+     if not isinstance(buildInfo, dict) or 'extra' not in buildInfo:

+         binfo = get_build(buildInfo, strict=strict)

+         if not binfo:

+             return None

+     else:

+         binfo = buildInfo

  

      query = QueryProcessor(

          tables=['btype'],

file modified
+3 -1
@@ -17,7 +17,7 @@ 

  import koji

  from koji.context import context

  from koji.plugin import callback, convert_datetime, ignore_error

- from kojihub import QueryProcessor, InsertProcessor

+ from kojihub import QueryProcessor, InsertProcessor, get_build_type

  

  CONFIG_FILE = '/etc/koji-hub/plugins/protonmsg.conf'

  CONFIG = None
@@ -210,11 +210,13 @@ 

          old = koji.BUILD_STATES[old]

      new = koji.BUILD_STATES[kws['new']]

      address = 'build.' + new.lower()

+     btypeinfo = get_build_type(kws['info'])

      kws['info'] = _strip_extra(kws['info'])

      props = {'type': cbtype[4:],

               'name': kws['info']['name'],

               'version': kws['info']['version'],

               'release': kws['info']['release'],

+              'btypes': btypeinfo,

               'attribute': kws['attribute'],

               'old': old,

               'new': new}

@@ -1,13 +1,17 @@ 

  from __future__ import absolute_import

- import six

- import protonmsg

+ 

  import tempfile

  import unittest

  

+ import protonmsg

+ import mock

+ import six

  from mock import patch, MagicMock

- from koji.context import context

  from six.moves.configparser import ConfigParser, SafeConfigParser

  

+ from koji.context import context

+ 

+ 

  class TestProtonMsg(unittest.TestCase):

      def setUp(self):

          self.conf = tempfile.NamedTemporaryFile()
@@ -26,6 +30,7 @@ 

          protonmsg.CONFIG_FILE = self.conf.name

          protonmsg.CONFIG = None

          protonmsg.LOG = MagicMock()

+         self.get_build_type = mock.patch('protonmsg.get_build_type').start()

  

      def tearDown(self):

          if hasattr(context, 'protonmsg_msgs'):
@@ -122,18 +127,48 @@ 

      def test_prep_build_state_change(self):

          info = {'name': 'test-pkg',

                  'version': '1.0',

-                 'release': '1'}

+                 'release': '1',

+                 'build_id': 1}

+         assert_info = {'name': 'test-pkg',

+                        'version': '1.0',

+                        'release': '1',

+                        'btypes': {'image': {'build_id': 1}}}

+         self.get_build_type.return_value = {'image': {'build_id': 1}}

          protonmsg.prep_build_state_change('postBuildStateChange',

                                            info=info, attribute='volume_id',

                                            old=0, new=1)

          # no messages should be created for callbacks where attribute != state

          self.assertFalse(hasattr(context, 'protonmsg_msgs'))

+         self.get_build_type.return_value = {'image': {'build_id': 1}}

          protonmsg.prep_build_state_change('postBuildStateChange',

                                            info=info, attribute='state',

                                            old=0, new=1)

          self.assertMsg('build.complete', type='BuildStateChange',

                         attribute='state', old='BUILDING', new='COMPLETE',

-                        **info)

+                        **assert_info)

+ 

+     def test_prep_build_state_change_with_empty_build_type(self):

+         info = {'name': 'test-pkg',

+                 'version': '1.0',

+                 'release': '1',

+                 'build_id': 1}

+         assert_info = {'name': 'test-pkg',

+                        'version': '1.0',

+                        'release': '1',

+                        'btypes': {}}

+         self.get_build_type.return_value = {}

+         protonmsg.prep_build_state_change('postBuildStateChange',

+                                           info=info, attribute='volume_id',

+                                           old=0, new=1)

+         # no messages should be created for callbacks where attribute != state

+         self.assertFalse(hasattr(context, 'protonmsg_msgs'))

+         self.get_build_type.return_value = {}

+         protonmsg.prep_build_state_change('postBuildStateChange',

+                                           info=info, attribute='state',

+                                           old=0, new=1)

+         self.assertMsg('build.complete', type='BuildStateChange',

+                        attribute='state', old='BUILDING', new='COMPLETE',

+                        **assert_info)

  

      def test_prep_import(self):

          build = {'name': 'test-pkg', 'version': '1.0', 'release': '1'}
@@ -185,8 +220,9 @@ 

                         user='test-user', **build)

  

      def test_prep_repo_init(self):

-         protonmsg.prep_repo_init('postRepoInit', tag={'name': 'test-tag',

-             'arches': set(['x86_64', 'i386'])}, repo_id=1234, task_id=25)

+         protonmsg.prep_repo_init('postRepoInit',

+                                  tag={'name': 'test-tag', 'arches': set(['x86_64', 'i386'])},

+                                  repo_id=1234, task_id=25)

          self.assertMsg('repo.init', type='RepoInit', tag='test-tag', repo_id=1234, task_id=25)

  

      def test_prep_repo_done(self):
@@ -222,6 +258,7 @@ 

      def test_send_queued_msgs_success(self, Container):

          context.protonmsg_msgs = [{'address': 'test.topic', 'props': {'testheader': 1},

                                     'body': 'test body'}]

+ 

          def clear_msgs():

              del context.protonmsg_msgs[:]

          Container.return_value.run.side_effect = clear_msgs
@@ -248,6 +285,7 @@ 

          conf.flush()

          protonmsg.CONFIG_FILE = conf.name

          protonmsg.CONFIG = None

+ 

          def clear_msgs():

              del context.protonmsg_msgs[:]

          Container.return_value.run.side_effect = clear_msgs

when buildInfo is a dict with nvr like

{'name': 'N',
  'version': 'V',
  'release': 'R'}

it is still a valid input to trigger get_build().
Maybe checking if extra is present when it is a dict is better?

once get_build_type() get optimized, this line could be

btypeinfo = get_build_type(kws['info'])

to save one get_build() call

rebased onto b30904e2880e27eace2f8d50759c6d6733ef1c7c

10 months ago

... or not 'extra' in buildInfo - most extra could be there and could be empty.

Shouldn't we return all btypes? @julian8628?

Shouldn't we return all btypes? @julian8628?

oh, yes. it should be all btypes

rebased onto 57b30d80455b5e1fa8245ea13676d802aa87feb2

10 months ago

maybe 'build_types' or 'build types' to indicate it is a dict?

rebased onto cea2cca05581ed325682da028d165cee3252d3d1

10 months ago

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

10 months ago

Can we just name this "btypes" instead of "build types"? The term "btype" means something specifically in Koji.

EDIT: Ok, I read get_build_type() and I see that can return multiple types, so plural is right.

EDIT2: I'm wondering if all messaging systems support a space character in a header (like "build type")

rebased onto 3018bf6

10 months ago

ok, let's use btypes :)

@ktdreyer fixed

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

10 months ago

Commit 9b45805 fixes this pull-request

Pull-Request has been merged by tkopecek

10 months ago