From d9e31c9a794ee3940a826df650e2816a39d94dae Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Sep 30 2019 20:11:33 +0000 Subject: [PATCH 1/2] tox.ini: Add {posargs} to commands= This allows passing positional args to the `tox` CLI. E.g. we need this if we just want to run one test. Signed-off-by: Jonathan Lebon --- diff --git a/tox.ini b/tox.ini index 33fd182..c40f48a 100644 --- a/tox.ini +++ b/tox.ini @@ -11,4 +11,4 @@ deps = # Add koji here because we can't depend on it in setup.py, see the comment there. koji commands = - python -m pytest -v + python -m pytest -v {posargs} From 62352e3a2b4773a3d85a4b42a4b882a7301e4e2a Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Sep 30 2019 20:11:35 +0000 Subject: [PATCH 2/2] Respond to CoreOS requests with the same body Responding with the `build_id` and `stream` is good, though let's just simplify and respond with the full message body. One use case for this is that I'd like the request side of this transaction (the FCOS pipeline) to just include a generated `request_id` to have a trivial foolproof way to match up requests and responses, instead of checking for `build_id` and `stream`. We could later on teach this `request_id` concept to RoboSignatory so we can have idempotence from a client somehow sending the same request multiple times. Signed-off-by: Jonathan Lebon --- diff --git a/robosignatory/coreos.py b/robosignatory/coreos.py index 72ba206..45fa3c9 100644 --- a/robosignatory/coreos.py +++ b/robosignatory/coreos.py @@ -51,11 +51,8 @@ class CoreOSSigner(object): response = Message( topic="{}.finished".format(msg.topic), - body={ - "build_id": msg.body["build_id"], - "stream": msg.body["stream"], - "basearch": msg.body["basearch"], - } + # respond with the same body, but clone so we keep the original one + body=dict(msg.body) ) try: diff --git a/tests/test_coreos.py b/tests/test_coreos.py index 83a9755..b00e64f 100644 --- a/tests/test_coreos.py +++ b/tests/test_coreos.py @@ -74,14 +74,11 @@ class TestCoreOS(unittest.TestCase): self.consumer.bucket = mock.Mock() def _get_response_message(self, source_msg, failed=False): + body = dict(source_msg.body) + body.update({"status": "FAILURE" if failed else "SUCCESS"}) return Message( topic=source_msg.topic + ".finished", - body={ - "build_id": source_msg.body["build_id"], - "stream": source_msg.body["stream"], - "basearch": source_msg.body["basearch"], - "status": "FAILURE" if failed else "SUCCESS", - } + body=body ) @mock.patch('robosignatory.coreos.utils.run_command') @@ -122,7 +119,7 @@ class TestCoreOS(unittest.TestCase): new_body["artifacts"][0]["checksum"] = "sha256:wrong-checksum" msg = Message(topic=ARTIFACTS_MESSAGE.topic, body=new_body) self.consumer.bucket.download_file.side_effect = fake_download - expected_response = self._get_response_message(ARTIFACTS_MESSAGE, failed=True) + expected_response = self._get_response_message(msg, failed=True) with mock_sends(expected_response): self.consumer.consume(msg)