def is_available(): """ Return whether the udfs daemon is reachable or not """ global __is_available if not isinstance(__is_available, bool): try: udfsapi.connect() except udfsapi.exceptions.Error as error: __is_available = False # Make sure version incompatiblity is displayed to the user if isinstance(error, udfsapi.exceptions.VersionMismatch): raise else: __is_available = True return __is_available
# Spawn udfs daemon in data directory DAEMON = subprocess.Popen(["udfs", "daemon", "--enable-pubsub-experiment"]) os.environ["PY_udfsAPI_TEST_DAEMON_PID"] = str(DAEMON.pid) # Collect the exit code of `DAEMON` when `SIGCHLD` is received # (otherwise the shutdown test fails to recognize that the daemon process is dead) if os.name == "posix": import signal signal.signal(signal.SIGCHLD, lambda *a: DAEMON.poll()) # Wait for daemon to start up import udfsapi while True: try: udfsapi.connect(HOST, PORT) except udfsapi.exceptions.ConnectionError: time.sleep(0.05) else: break ################## # Run test suite # ################## PYTEST_CODE = 1 try: # Run tests in CI-mode (will stop the daemon at the end through the API) os.environ["CI"] = "true" # Make sure all required py.test plugins are loaded
def config(self, host, port): """change connect""" self.connect = udfsapi.connect(host=host, port=port)
def __init__(self, host='192.168.12.221', port='5001'): """init a connector""" self.connect = udfsapi.connect(host=host, port=port) self.log = logging.getLogger("udfs")