Wait for cloud-init to finish before provisioning 30/10930/2
authorDavid Garcia <david.garcia@canonical.com>
Wed, 26 May 2021 11:16:51 +0000 (13:16 +0200)
committergarciadav <david.garcia@canonical.com>
Tue, 1 Jun 2021 09:24:10 +0000 (11:24 +0200)
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 <david.garcia@canonical.com>
(cherry picked from commit 9074b05b797b591eeb9b86b54c5a699b30454906)

n2vc/provisioner.py

index e2b51b9..ab25993 100644 (file)
@@ -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."""
@@ -299,6 +304,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