From cc2ff9742c4e6def006ff83af8b2f2e4edbb3585 Mon Sep 17 00:00:00 2001 From: Simon Westphahl Date: Wed, 26 Apr 2023 09:07:19 +0200 Subject: [PATCH] Fix delete-pipeline-state command This change also extends the test to assert that the pipeline change list was re-creates by asserting that the node exists in Zookeeper. Traceback (most recent call last): File "/home/westphahl/src/opendev/zuul/zuul/.nox/tests/bin/zuul-admin", line 10, in sys.exit(main()) File "/home/westphahl/src/opendev/zuul/zuul/zuul/cmd/client.py", line 1066, in main Client().main() File "/home/westphahl/src/opendev/zuul/zuul/zuul/cmd/client.py", line 592, in main if self.args.func(): File "/home/westphahl/src/opendev/zuul/zuul/zuul/cmd/client.py", line 1045, in delete_pipeline_state PipelineChangeList.new(context) File "/home/westphahl/src/opendev/zuul/zuul/zuul/zk/zkobject.py", line 225, in new obj._save(context, data, create=True) File "/home/westphahl/src/opendev/zuul/zuul/zuul/zk/zkobject.py", line 507, in _save path = self.getPath() File "/home/westphahl/src/opendev/zuul/zuul/zuul/model.py", line 982, in getPath return self.getChangeListPath(self.pipeline) AttributeError: 'PipelineChangeList' object has no attribute 'pipeline' Change-Id: I8d7bf2fdb3ebf4790ca9cf15519dff4b761fbf2e --- tests/unit/test_client.py | 4 ++++ zuul/cmd/client.py | 10 +++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/tests/unit/test_client.py b/tests/unit/test_client.py index 2e90d3fb41..30e3049c89 100644 --- a/tests/unit/test_client.py +++ b/tests/unit/test_client.py @@ -444,10 +444,14 @@ class TestOnlineZKOperations(ZuulTestCase): # Delete the pipeline state out, _ = p.communicate() self.log.debug(out.decode('utf8')) + self.assertEqual(p.returncode, 0, 'The command must exit 0') # Make sure it's deleted with testtools.ExpectedException(NoNodeError): self.getZKTree( f'/zuul/tenant/{tenant.name}/pipeline/{pipeline}/item') + # Make sure the change list is re-created + self.getZKTree( + f'/zuul/tenant/{tenant.name}/pipeline/{pipeline}/change_list') finally: sched.run_handler_lock.release() diff --git a/zuul/cmd/client.py b/zuul/cmd/client.py index 6fa20c7c4a..bb35cfb35c 100755 --- a/zuul/cmd/client.py +++ b/zuul/cmd/client.py @@ -33,7 +33,9 @@ import urllib.parse import zuul.cmd from zuul.lib.config import get_default -from zuul.model import SystemAttributes, PipelineState, PipelineChangeList +from zuul.model import ( + SystemAttributes, Pipeline, PipelineState, PipelineChangeList +) from zuul.zk import ZooKeeperClient from zuul.lib.keystorage import KeyStorage from zuul.zk.locks import tenant_read_lock, pipeline_lock @@ -1035,14 +1037,16 @@ class Client(zuul.cmd.ZuulApp): with tenant_read_lock(zk_client, args.tenant): path = f'/zuul/tenant/{safe_tenant}/pipeline/{safe_pipeline}' self.log.info('get pipe') + pipeline = Pipeline(args.tenant, args.pipeline) with pipeline_lock( zk_client, args.tenant, args.pipeline ) as plock: self.log.info('got locks') zk_client.client.delete(path, recursive=True) with ZKContext(zk_client, plock, None, self.log) as context: - PipelineState.new(context, _path=path, layout_uuid=None) - PipelineChangeList.new(context) + pipeline.state = PipelineState.new( + context, _path=path, layout_uuid=None) + PipelineChangeList.new(context, pipeline=pipeline) sys.exit(0)