From 125a7061b19afdd3c2e4f0e463e85572dfb3783d Mon Sep 17 00:00:00 2001 From: spisarski Date: Wed, 3 Jan 2018 10:00:43 -0700 Subject: [PATCH] Added new configuration option for OpenStackVmInstance for cloud-init Added cloud_init_timeout to VM instance configuration to override the default timeout value hardcoded @ 120 seconds. This patch not only expands the default value to 300, but also allows the client to override this value as cloud-init can take quite some time depending on what is being requested. Change-Id: Ia4d0a54ce853a93748b16945f5ddd4d5887feb7d Signed-off-by: spisarski --- snaps/config/tests/vm_inst_tests.py | 12 ++++++++---- snaps/config/vm_inst.py | 13 ++++++++----- snaps/openstack/create_instance.py | 3 +-- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/snaps/config/tests/vm_inst_tests.py b/snaps/config/tests/vm_inst_tests.py index 71d2e0b..d7fb287 100644 --- a/snaps/config/tests/vm_inst_tests.py +++ b/snaps/config/tests/vm_inst_tests.py @@ -64,6 +64,7 @@ class VmInstanceConfigUnitTests(unittest.TestCase): self.assertEqual(900, settings.vm_boot_timeout) self.assertEqual(300, settings.vm_delete_timeout) self.assertEqual(180, settings.ssh_connect_timeout) + self.assertEqual(300, settings.cloud_init_timeout) self.assertIsNone(settings.availability_zone) self.assertIsNone(settings.volume_names) @@ -82,6 +83,7 @@ class VmInstanceConfigUnitTests(unittest.TestCase): self.assertEqual(900, settings.vm_boot_timeout) self.assertEqual(300, settings.vm_delete_timeout) self.assertEqual(180, settings.ssh_connect_timeout) + self.assertEqual(300, settings.cloud_init_timeout) self.assertIsNone(settings.availability_zone) self.assertIsNone(settings.volume_names) @@ -95,8 +97,8 @@ class VmInstanceConfigUnitTests(unittest.TestCase): security_group_names=['sec_grp_1'], floating_ip_settings=[fip_settings], sudo_user='joe', vm_boot_timeout=999, vm_delete_timeout=333, - ssh_connect_timeout=111, availability_zone='server name', - volume_names=['vol1']) + ssh_connect_timeout=111, cloud_init_timeout=998, + availability_zone='server name', volume_names=['vol1']) self.assertEqual('foo', settings.name) self.assertEqual('bar', settings.flavor) self.assertEqual(1, len(settings.port_settings)) @@ -114,6 +116,7 @@ class VmInstanceConfigUnitTests(unittest.TestCase): self.assertEqual(999, settings.vm_boot_timeout) self.assertEqual(333, settings.vm_delete_timeout) self.assertEqual(111, settings.ssh_connect_timeout) + self.assertEqual(998, settings.cloud_init_timeout) self.assertEqual('server name', settings.availability_zone) self.assertEqual('vol1', settings.volume_names[0]) @@ -127,8 +130,8 @@ class VmInstanceConfigUnitTests(unittest.TestCase): 'security_group_names': ['sec_grp_1'], 'floating_ips': [fip_settings], 'sudo_user': 'joe', 'vm_boot_timeout': 999, 'vm_delete_timeout': 333, - 'ssh_connect_timeout': 111, 'availability_zone': 'server name', - 'volume_names': ['vol2']}) + 'ssh_connect_timeout': 111, 'cloud_init_timeout': 998, + 'availability_zone': 'server name', 'volume_names': ['vol2']}) self.assertEqual('foo', settings.name) self.assertEqual('bar', settings.flavor) self.assertEqual(1, len(settings.port_settings)) @@ -145,6 +148,7 @@ class VmInstanceConfigUnitTests(unittest.TestCase): self.assertEqual(999, settings.vm_boot_timeout) self.assertEqual(333, settings.vm_delete_timeout) self.assertEqual(111, settings.ssh_connect_timeout) + self.assertEqual(998, settings.cloud_init_timeout) self.assertEqual('server name', settings.availability_zone) self.assertEqual('vol2', settings.volume_names[0]) diff --git a/snaps/config/vm_inst.py b/snaps/config/vm_inst.py index 9533ea1..6a63e33 100644 --- a/snaps/config/vm_inst.py +++ b/snaps/config/vm_inst.py @@ -32,12 +32,14 @@ class VmInstanceConfig(object): :param sudo_user: the sudo user of the VM that will override the instance_settings.image_user when trying to connect to the VM - :param vm_boot_timeout: the amount of time a thread will sleep waiting + :param vm_boot_timeout: the amount of time a thread will wait for an instance to boot - :param vm_delete_timeout: the amount of time a thread will sleep - waiting for an instance to be deleted - :param ssh_connect_timeout: the amount of time a thread will sleep - waiting obtaining an SSH connection to a VM + :param vm_delete_timeout: the amount of time a thread will wait + for an instance to be deleted + :param ssh_connect_timeout: the amount of time a thread will wait + to obtain an SSH connection to a VM + :param cloud_init_timeout: the amount of time a thread will wait for + cloud-init to complete :param availability_zone: the name of the compute server on which to deploy the VM (optional) :param volume_names: a list of the names of the volume to attach @@ -93,6 +95,7 @@ class VmInstanceConfig(object): self.vm_boot_timeout = kwargs.get('vm_boot_timeout', 900) self.vm_delete_timeout = kwargs.get('vm_delete_timeout', 300) self.ssh_connect_timeout = kwargs.get('ssh_connect_timeout', 180) + self.cloud_init_timeout = kwargs.get('cloud_init_timeout', 300) self.availability_zone = kwargs.get('availability_zone') self.volume_names = kwargs.get('volume_names') diff --git a/snaps/openstack/create_instance.py b/snaps/openstack/create_instance.py index b68372e..d91e360 100644 --- a/snaps/openstack/create_instance.py +++ b/snaps/openstack/create_instance.py @@ -32,7 +32,6 @@ logger = logging.getLogger('create_instance') POLL_INTERVAL = 3 STATUS_ACTIVE = 'ACTIVE' STATUS_DELETED = 'DELETED' -CLOUD_INIT_TIMEOUT = 120 class OpenStackVmInstance(OpenStackComputeObject): @@ -680,7 +679,7 @@ class OpenStackVmInstance(OpenStackComputeObject): # sleep and wait for VM status change logger.info('Checking if cloud-init has completed') - timeout = CLOUD_INIT_TIMEOUT + timeout = self.instance_settings.cloud_init_timeout if self.vm_active(block=True) and self.vm_ssh_active(block=True): if block: -- 2.16.6