summaryrefslogtreecommitdiff
path: root/zuul/cmd
diff options
context:
space:
mode:
authorJames E. Blair <jim@acmegating.com>2021-08-11 14:09:22 -0700
committerJames E. Blair <jim@acmegating.com>2021-08-24 10:07:41 -0700
commite2dd49b5befa843a89021dba5c776fcf7ed4a33f (patch)
tree0d8dd8891ee5a57ee8cf2b9217e02248e2d73d32 /zuul/cmd
parenta0af6004de733b15d0486b67ce6c6109d6d53647 (diff)
downloadzuul-e2dd49b5befa843a89021dba5c776fcf7ed4a33f.tar.gz
Add delete-state command to delete everything from ZK
This will give operators a tool for manual recovery in case of emergency. Change-Id: Ia84beb08b685f59a24f76cb0b6adf518f6e64362
Diffstat (limited to 'zuul/cmd')
-rwxr-xr-xzuul/cmd/client.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/zuul/cmd/client.py b/zuul/cmd/client.py
index 969823e0a..8323b887e 100755
--- a/zuul/cmd/client.py
+++ b/zuul/cmd/client.py
@@ -431,6 +431,30 @@ class Client(zuul.cmd.ZuulApp):
help='project name')
cmd_delete_keys.set_defaults(func=self.delete_keys)
+ # ZK Maintenance
+ cmd_delete_state = subparsers.add_parser(
+ 'delete-state',
+ help='delete ephemeral ZooKeeper state',
+ formatter_class=argparse.RawDescriptionHelpFormatter,
+ description=textwrap.dedent('''\
+ Delete all ephemeral state stored in ZooKeeper
+
+ Zuul stores a considerable amount of ephemeral state
+ information in ZooKeeper. Generally it should be able to
+ detect and correct any errors, but if the state becomes
+ corrupted and it is unable to recover, this command may be
+ used to delete all ephemeral data from ZooKeeper and start
+ anew.
+
+ Do not run this command while any Zuul component is
+ running (perform a complete shutdown first).
+
+ This command will only remove ephemeral Zuul data from
+ ZooKeeper; it will not remove private keys or Nodepool
+ data.'''))
+ cmd_delete_state.set_defaults(command='delete-state')
+ cmd_delete_state.set_defaults(func=self.delete_state)
+
return parser
def parseArguments(self, args=None):
@@ -893,6 +917,16 @@ class Client(zuul.cmd.ZuulApp):
self.log.info("Delete keys from %s %s",
args.connection, args.project)
+ def delete_state(self):
+ logging.basicConfig(level=logging.INFO)
+
+ zk_client = ZooKeeperClient.fromConfig(self.config)
+ zk_client.connect()
+ confirm = input("Are you sure you want to delete "
+ "all ephemeral data from ZooKeeper? (yes/no) ")
+ if confirm.strip().lower() == 'yes':
+ zk_client.client.delete('/zuul', recursive=True)
+
def main():
Client().main()