diff options
author | James E. Blair <jim@acmegating.com> | 2021-08-11 14:09:22 -0700 |
---|---|---|
committer | James E. Blair <jim@acmegating.com> | 2021-08-24 10:07:41 -0700 |
commit | e2dd49b5befa843a89021dba5c776fcf7ed4a33f (patch) | |
tree | 0d8dd8891ee5a57ee8cf2b9217e02248e2d73d32 /tests/unit/test_client.py | |
parent | a0af6004de733b15d0486b67ce6c6109d6d53647 (diff) | |
download | zuul-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 'tests/unit/test_client.py')
-rw-r--r-- | tests/unit/test_client.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/unit/test_client.py b/tests/unit/test_client.py index aed2af0c1..be65f8ca5 100644 --- a/tests/unit/test_client.py +++ b/tests/unit/test_client.py @@ -24,6 +24,8 @@ import jwt import testtools from kazoo.exceptions import NoNodeError +from zuul.zk import ZooKeeperClient + from tests.base import BaseTestCase, ZuulTestCase from tests.base import FIXTURE_DIR @@ -251,3 +253,50 @@ class TestKeyOperations(ZuulTestCase): data.get('/keystorage/gerrit/org/org%2Fproject/secrets')) self.assertIsNone( data.get('/keystorage/gerrit/org/org%2Fproject/ssh')) + + +class TestZKOperations(ZuulTestCase): + tenant_config_file = 'config/single-tenant/main.yaml' + + def shutdown(self): + pass + + def assertFinalState(self): + pass + + def test_delete_state(self): + # Shut everything down (as much as possible) to reduce + # logspam and errors. + ZuulTestCase.shutdown(self) + + # Re-start the client connection because we need one for the + # test. + self.zk_client = ZooKeeperClient.fromConfig(self.config) + self.zk_client.connect() + + config_file = os.path.join(self.test_root, 'zuul.conf') + with open(config_file, 'w') as f: + self.config.write(f) + + # Save a copy of the keys in ZK + old_data = self.getZKTree('/keystorage') + + p = subprocess.Popen( + [os.path.join(sys.prefix, 'bin/zuul'), + '-c', config_file, + 'delete-state', + ], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE) + out, _ = p.communicate(b'yes\n') + self.log.debug(out.decode('utf8')) + + # Make sure the keys are still around + new_data = self.getZKTree('/keystorage') + self.assertEqual(new_data, old_data) + + # Make sure we really deleted everything + with testtools.ExpectedException(NoNodeError): + self.getZKTree('/zuul') + + self.zk_client.disconnect() |