test-connectivity.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/usr/bin/env python3
  2. # Licensed to the Apache Software Foundation (ASF) under one
  3. # or more contributor license agreements. See the NOTICE file
  4. # distributed with this work for additional information
  5. # regarding copyright ownership. The ASF licenses this file
  6. # to you under the Apache License, Version 2.0 (the
  7. # "License"); you may not use this file except in compliance
  8. # with the License. You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS,
  14. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. import argparse
  18. import subprocess
  19. from pathlib import Path
  20. class Server():
  21. def __init__(self, binpath):
  22. self.binpath = binpath
  23. def __enter__(self):
  24. subprocess.run([f'{self.binpath}', 'start'], check=True)
  25. return self
  26. def __exit__(self, type, value, traceback):
  27. subprocess.run([f'{self.binpath}', 'stop'], check=True)
  28. if __name__ == '__main__':
  29. parser = argparse.ArgumentParser()
  30. parser.add_argument('--server', help="basepath to zk server", required=True)
  31. parser.add_argument('--client', help="basepath to zk client", required=True)
  32. args = parser.parse_args()
  33. server_basepath = Path(args.server).absolute()
  34. server_binpath = server_basepath / "bin" / "zkServer.sh"
  35. assert server_binpath.exists(), f"server binpath not exist: {server_binpath}"
  36. client_basepath = Path(args.client).absolute()
  37. client_binpath = client_basepath / "bin" / "zkCli.sh"
  38. assert client_binpath.exists(), f"client binpath not exist: {client_binpath}"
  39. with Server(server_binpath):
  40. subprocess.run([f'{client_binpath}', 'sync', '/'], check=True)