From 45ba206824b8757c14fb0c0e84bce0ae5971b976 Mon Sep 17 00:00:00 2001 From: David Garcia Date: Mon, 1 Jun 2020 13:48:48 +0200 Subject: [PATCH] Fix magmagw: race condition when orch not ready yet --- .../charms/magmagw/src/charm.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/magma/hackfest_magma-agw-enb_vnfd/charms/magmagw/src/charm.py b/magma/hackfest_magma-agw-enb_vnfd/charms/magmagw/src/charm.py index 86c2fc46..c19ba711 100755 --- a/magma/hackfest_magma-agw-enb_vnfd/charms/magmagw/src/charm.py +++ b/magma/hackfest_magma-agw-enb_vnfd/charms/magmagw/src/charm.py @@ -173,11 +173,20 @@ class SimpleHAProxyCharm(CharmBase): orch_ip = event.params["orch_ip"] orch_net = event.params["orch_net"] proxy = self.get_ssh_proxy() - stdout, stderr = proxy.run( - "/home/magma/addnet.py --orch_ip {} --orch_net {}".format( - orch_ip, orch_net - ) - ) + + attempt = 0 + while attempt < 50: + try: + stdout, stderr = proxy.run( + "/home/magma/addnet.py --orch_ip {} --orch_net {}".format( + orch_ip, orch_net + ) + ) + break + except subprocess.CalledProcessError: + attempt += 1 + import time + time.sleep(5) event.set_results({"output": stdout, "stderr": stderr}) else: event.fail("Unit is not leader") -- GitLab