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 <module>
    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
This commit is contained in:
Simon Westphahl 2023-04-26 09:07:19 +02:00
parent 8ec8863eb8
commit cc2ff9742c
No known key found for this signature in database
2 changed files with 11 additions and 3 deletions

View File

@ -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()

View File

@ -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)