From 2a605356b6ae95b47caab851f1639b5bd3456808 Mon Sep 17 00:00:00 2001 From: Yang Yang Date: Thu, 18 Jun 2020 21:57:59 +0800 Subject: [PATCH] chore(xudctl): refine connext status (#513) * chore(xudctl): refine connext status This PR keeps align with xud getinfo connext status. Closes #512. * fix api missing in Dict * add another status text --- images/utils/launcher/node/__init__.py | 3 ++- images/utils/launcher/node/base.py | 1 + images/utils/launcher/node/connext.py | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/images/utils/launcher/node/__init__.py b/images/utils/launcher/node/__init__.py index 2c683c0c7..7c92d3d29 100644 --- a/images/utils/launcher/node/__init__.py +++ b/images/utils/launcher/node/__init__.py @@ -94,6 +94,7 @@ class Context: shell: Shell client: docker.DockerClient image_manager: ImageManager + node_manager: 'NodeManager' class NodeNotFound(Exception): @@ -112,7 +113,7 @@ def __init__(self, config, shell): self.branch = self.config.branch self.network = self.config.network - ctx = Context(self.config, self.shell, self.client, self.image_manager) + ctx = Context(self.config, self.shell, self.client, self.image_manager, self) self.nodes = {name: globals()[name.capitalize()](name, ctx) for name in self.config.nodes} self.docker_network = self.create_docker_network() diff --git a/images/utils/launcher/node/base.py b/images/utils/launcher/node/base.py index f5132f05d..a45f691bc 100644 --- a/images/utils/launcher/node/base.py +++ b/images/utils/launcher/node/base.py @@ -59,6 +59,7 @@ def __init__(self, name: str, ctx): self.client = docker.from_env(timeout=999999999) self.config = ctx.config self.image_manager = ctx.image_manager + self.node_manager = ctx.node_manager self.name = name diff --git a/images/utils/launcher/node/connext.py b/images/utils/launcher/node/connext.py index 01a54fef5..9c8583d48 100644 --- a/images/utils/launcher/node/connext.py +++ b/images/utils/launcher/node/connext.py @@ -71,12 +71,27 @@ def __init__(self, name, ctx): self._cli = "curl -s" self.api = ConnextApi(CliBackend(self.client, self.container_name, self._logger, self._cli)) + def get_xud_getinfo_connext_status(self): + xud = self.node_manager.nodes["xud"] + info = xud.api.getinfo() + status = info["connext"]["status"] + if status == "Ready": + return "Ready" + elif "ECONNREFUSED" in status: + return "Can't connect to Connext node" + else: + return "Starting..." + def status(self): status = super().status() if status == "exited": # TODO: analyze exit reason return "Container exited" elif status == "running": + try: + return self.get_xud_getinfo_connext_status() + except: + self._logger.exception("Failed to get connext status from xud getinfo") try: healthy = self.api.is_healthy() if healthy: