#44 Catch exception thrown by PDC when updating a module
Merged 3 years ago by pingou. Opened 3 years ago by pingou.

@@ -102,6 +102,48 @@ 

  

          assert client[pdc_api][123].mock_calls == [call._.__iadd__({"koji_tag": "tag"})]

  

+     @patch("toddlers.plugins.pdc_modules.pdc_client_for_config")

+     def test_process_failing_uid(self, pdc, caplog, toddler):

+         caplog.set_level(logging.INFO)

+ 

+         client = MagicMock()

+         pdc_api = "modules"

+         pdc.return_value = client

+ 

+         msg = fedora_messaging.api.Message()

+         msg.id = 123

+         msg.topic = "org.fedoraproject.prod.mbs.module.state.change"

+         msg.body = {

+             "state_name": "build",

+             "name": "module",

+             "stream": 6,

+             "version": 6.1,

+             "koji_tag": "tag",

+         }

+         uid = "module:6:6.1:00000000"

+ 

+         res = Mock()

+         res.status_code = 404

+         client[pdc_api][uid]._.__iadd__.side_effect = beanbag.BeanBagException(

+             res, "foo!"

+         )

+ 

+         toddler.process({"config": "foobar"}, msg)

+ 

+         print(client[pdc_api]._.mock_calls)

+ 

+         assert call(page_size=1) in client[pdc_api]._.mock_calls

+         assert call(page_size=-1, uid=uid) in client[pdc_api]._.mock_calls

+ 

+         assert client[pdc_api][123].mock_calls == [call._.__iadd__({"koji_tag": "tag"})]

+ 

+         assert len(caplog.records) == 2

+         # the uid is a mock object, so I can't check it in the string of the exception

+         assert caplog.records[-1].message.startswith(

+             "Failed to update PDC (modules) for uid: "

+         )

+         assert caplog.records[-1].message.endswith("and koji_tag: tag")

+ 

      @patch("toddlers.plugins.pdc_modules.koji")

      @patch("toddlers.plugins.pdc_modules.Modulemd")

      @patch("toddlers.plugins.pdc_modules.pdc_client_for_config")

@@ -90,7 +90,15 @@ 

  

          if state == "build":

              # At this point we can update the Koji tag from MBS

-             pdc[pdc_api][uid]._ += {"koji_tag": message.body["koji_tag"]}

+             try:

+                 pdc[pdc_api][uid]._ += {"koji_tag": message.body["koji_tag"]}

+             except beanbag.BeanBagException:

+                 _log.exception(

+                     "Failed to update PDC (%s) for uid: %s and koji_tag: %s",

+                     pdc_api,

+                     uid,

+                     message.body["koji_tag"],

+                 )

          elif state == "ready":

              _log.info("%r ready.  Patching with rpms and active=True.", uid)

              rpms = self._get_module_rpms(config, pdc, module)

We have observed in production that the messages:
https://apps.fedoraproject.org/datagrepper/id?id=2020-dfeecf92-ebd8-4057-9758-f6ca86857b3b&is_raw=true&size=extra-large
and
https://apps.fedoraproject.org/datagrepper/id?id=2020-7b68144c-d96f-4dff-b52c-ca104f30ffef&is_raw=true&size=extra-large
do not pass the pdc_modules toddler.
They lead to the following backtrace:

  File "/code/toddlers/runner.py", line 96, in __call__
    toddler.process(self.toddler_config[toddler.name], message)
  File "/code/toddlers/plugins/pdc_modules.py", line 93, in process
    pdc[pdc_api][uid]._ += {"koji_tag": message.body["koji_tag"]}
  File "/usr/lib/python3.8/site-packages/pdc_client/__init__.py", line 365, in __iadd__
    return self.client.__iadd__(value)
  File "/usr/lib/python3.8/site-packages/beanbag/namespace.py", line 142, in fn
    r = basefn(getattr(self, ".base"), getattr(self, ".path"),
  File "/usr/lib/python3.8/site-packages/beanbag/url_v1.py", line 137, in iadd
    self.make_request(path, "PATCH", {}, val)
  File "/usr/lib/python3.8/site-packages/beanbag/url_v1.py", line 154, in make_request
    raise BeanBagException(r,
beanbag.bbexcept.BeanBagException: Bad response code: 404

So apparently, we fail to update PDC for some reason (no idea what
triggers the 404).

This commit allows to log that exception and discard the action since:
a) we don't know what triggered the 404
b) the old pdc-updater client would ignore these errors just like we will
do now and no-one seems to have complained about it

So here we go!

Signed-off-by: Pierre-Yves Chibon pingou@pingoured.fr

Build succeeded.

  • tox : SUCCESS in 6m 05s

Pull-Request has been merged by pingou

3 years ago