From: David Garcia Date: Wed, 26 May 2021 11:16:51 +0000 (+0200) Subject: Wait for cloud-init to finish before provisioning X-Git-Tag: v9.1.2~4 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=refs%2Fchanges%2F31%2F10931%2F1;p=osm%2FN2VC.git Wait for cloud-init to finish before provisioning Before provisioning a native charm, a script is executed to wait until cloud-init finishes. This will avoid some racing conditions. Fixes bug 1184 Change-Id: Icc87f90f5941cf7b13bdd7dd01e5544122fb769e Signed-off-by: David Garcia (cherry picked from commit 9074b05b797b591eeb9b86b54c5a699b30454906) --- diff --git a/n2vc/provisioner.py b/n2vc/provisioner.py index 91d5c04..32ae94d 100644 --- a/n2vc/provisioner.py +++ b/n2vc/provisioner.py @@ -85,6 +85,11 @@ firewall-cmd --direct --permanent --add-rule ipv4 nat OUTPUT 0 -d {} -p tcp \ firewall-cmd --reload """ +CLOUD_INIT_WAIT_SCRIPT = """#!/bin/bash +set -e +cloud-init status --wait +""" + class AsyncSSHProvisioner: """Provision a manually created machine via SSH.""" @@ -296,6 +301,12 @@ class AsyncSSHProvisioner: - 127.0.0.1:17070 - '[::1]:17070' """ + try: + # Wait until cloud-init finish + await self._run_configure_script(CLOUD_INIT_WAIT_SCRIPT) + except Exception: + self.log.debug("cloud-init not present in machine {}".format(machine_id)) + if proxy: m = re.search(r"apiaddresses:\n- (\d+\.\d+\.\d+\.\d+):17070", results.script) apiaddress = m.group(1)