From 60e04455c55a175a04c9c25f864c5aa9b51b5dfa Mon Sep 17 00:00:00 2001 From: Erik Olof Gunnar Andersson Date: Wed, 22 Nov 2023 08:10:49 -0800 Subject: [PATCH] Fix Producer shard range ignoring the last shard We define the shard range like this in objects > 'shard': fields.IntegerFields(nullable=True, minimum=0, maximum=4095), The problem is that in code we handle it using range(0, 4095), but that range does not include the final shard value of 4095. Closes-bug: #2044278 Change-Id: I71b0b1b237b5d5f12209f431db19cda1b44a1112 (cherry picked from commit 54d2d2cf187aec8d73bd7588dabdc4279ca8851b) --- designate/producer/service.py | 2 +- designate/tests/test_producer/test_service.py | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/designate/producer/service.py b/designate/producer/service.py index a862dde6c..4a5e2ef9e 100644 --- a/designate/producer/service.py +++ b/designate/producer/service.py @@ -79,7 +79,7 @@ class Service(service.RPCService): self._partitioner = coordination.Partitioner( self.coordination.coordinator, self.service_name, - self.coordination.coordination_id.encode(), range(0, 4095) + self.coordination.coordination_id.encode(), range(0, 4096) ) self._partitioner.start() diff --git a/designate/tests/test_producer/test_service.py b/designate/tests/test_producer/test_service.py index 18c052b1f..cf2c18d96 100644 --- a/designate/tests/test_producer/test_service.py +++ b/designate/tests/test_producer/test_service.py @@ -15,13 +15,26 @@ # under the License. from oslo_log import log as logging +from designate import objects from designate.tests import TestCase + LOG = logging.getLogger(__name__) class ProducerServiceTest(TestCase): + def setUp(self): + super().setUp() + self.producer_service = self.start_service('producer') + def test_stop(self): - # Test stopping the service - service = self.start_service("producer") - service.stop() + self.producer_service.stop() + + def test_validate_partition_range(self): + self.producer_service.start() + + min_partition = objects.Zone.fields['shard'].min + max_partition = objects.Zone.fields['shard'].max + + self.assertIn(min_partition, self.producer_service.partition_range) + self.assertIn(max_partition, self.producer_service.partition_range)