From fbddc72ec817051c3b616226d6fddd1eba6e7f11 Mon Sep 17 00:00:00 2001 From: "James E. Blair" Date: Fri, 10 Feb 2023 09:39:54 -0800 Subject: [PATCH] Remove layout_uuid from PipelineState create call This argument is no longer necessary because it is set via an inderect route through the pipeline and tenant objects. Remove it, and also validate that it is set correctly in unit tests. Change-Id: I62ce18a61a416cbc397866838f8ac3b0ec1bd564 --- tests/unit/test_zk.py | 16 ++++++++++++---- zuul/manager/__init__.py | 2 +- zuul/model.py | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/tests/unit/test_zk.py b/tests/unit/test_zk.py index f5c1fd4c42..b5697ee361 100644 --- a/tests/unit/test_zk.py +++ b/tests/unit/test_zk.py @@ -2052,10 +2052,11 @@ class TestPipelineInit(ZooKeeperBaseTestCase): layout = model.Layout(tenant) tenant.layout = layout pipeline.state = model.PipelineState.create( - pipeline, layout.uuid, pipeline.state) + pipeline, pipeline.state) context = ZKContext(self.zk_client, None, None, self.log) pipeline.state.refresh(context) self.assertTrue(self.zk_client.client.exists(pipeline.state.getPath())) + self.assertEqual(pipeline.state.layout_uuid, layout.uuid) def test_pipeline_state_existing_object(self): # Test the initialize-on-refresh code path with a pre-existing object @@ -2065,7 +2066,7 @@ class TestPipelineInit(ZooKeeperBaseTestCase): tenant.layout = layout pipeline.manager = mock.Mock() pipeline.state = model.PipelineState.create( - pipeline, layout.uuid, pipeline.state) + pipeline, pipeline.state) pipeline.change_list = model.PipelineChangeList.create( pipeline) context = ZKContext(self.zk_client, None, None, self.log) @@ -2077,6 +2078,7 @@ class TestPipelineInit(ZooKeeperBaseTestCase): self.assertTrue( self.zk_client.client.exists(pipeline.change_list.getPath())) self.assertTrue(self.zk_client.client.exists(pipeline.state.getPath())) + self.assertEqual(pipeline.state.layout_uuid, layout.uuid) def test_pipeline_change_list_new_object(self): # Test the initialize-on-refresh code path with no existing object @@ -2085,13 +2087,16 @@ class TestPipelineInit(ZooKeeperBaseTestCase): layout = model.Layout(tenant) tenant.layout = layout pipeline.state = model.PipelineState.create( - pipeline, layout.uuid, pipeline.state) + pipeline, pipeline.state) pipeline.change_list = model.PipelineChangeList.create( pipeline) context = ZKContext(self.zk_client, None, None, self.log) pipeline.change_list.refresh(context) self.assertTrue( self.zk_client.client.exists(pipeline.change_list.getPath())) + pipeline.manager = mock.Mock() + pipeline.state.refresh(context) + self.assertEqual(pipeline.state.layout_uuid, layout.uuid) def test_pipeline_change_list_new_object_without_lock(self): # Test the initialize-on-refresh code path if we don't have @@ -2101,7 +2106,7 @@ class TestPipelineInit(ZooKeeperBaseTestCase): layout = model.Layout(tenant) tenant.layout = layout pipeline.state = model.PipelineState.create( - pipeline, layout.uuid, pipeline.state) + pipeline, pipeline.state) pipeline.change_list = model.PipelineChangeList.create( pipeline) context = ZKContext(self.zk_client, None, None, self.log) @@ -2109,3 +2114,6 @@ class TestPipelineInit(ZooKeeperBaseTestCase): pipeline.change_list.refresh(context, allow_init=False) self.assertIsNone( self.zk_client.client.exists(pipeline.change_list.getPath())) + pipeline.manager = mock.Mock() + pipeline.state.refresh(context) + self.assertEqual(pipeline.state.layout_uuid, layout.uuid) diff --git a/zuul/manager/__init__.py b/zuul/manager/__init__.py index e85d5124e6..36361df118 100644 --- a/zuul/manager/__init__.py +++ b/zuul/manager/__init__.py @@ -108,7 +108,7 @@ class PipelineManager(metaclass=ABCMeta): # These will be out of date until they are refreshed later. self.pipeline.state = PipelineState.create( - self.pipeline, layout.uuid, self.pipeline.state) + self.pipeline, self.pipeline.state) self.pipeline.change_list = PipelineChangeList.create( self.pipeline) diff --git a/zuul/model.py b/zuul/model.py index 3b6a497104..39e5302bc5 100644 --- a/zuul/model.py +++ b/zuul/model.py @@ -643,7 +643,7 @@ class PipelineState(zkobject.ZKObject): return obj @classmethod - def create(cls, pipeline, layout_uuid, old_state=None): + def create(cls, pipeline, old_state=None): # If we are resetting an existing pipeline, we will have an # old_state, so just clean up the object references there and # let the next refresh handle updating any data.