From bbcdcc37069158678b6a7e0168ba3e718ac7b54a Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Thu, 7 Feb 2019 12:14:10 +0100 Subject: [PATCH] Applying configured timeout options --- etc/create-vmware-template.ini.default | 5 +++- lib/cr_vmware_tpl/config.py | 39 ++++++++++++++++++-------- lib/cr_vmware_tpl/handler.py | 11 ++++---- 3 files changed, 37 insertions(+), 18 deletions(-) diff --git a/etc/create-vmware-template.ini.default b/etc/create-vmware-template.ini.default index 3545369..4b2ab55 100644 --- a/etc/create-vmware-template.ini.default +++ b/etc/create-vmware-template.ini.default @@ -47,7 +47,10 @@ ;max_wait_for_poweron_vm = 15 ; Timeout in seconds for shutting down a VM in VSphere -;max_wait_for_shutdown_vm = 15 +;max_wait_for_shutdown_vm = 60 + +; Timeout in seconds for purging a VM in VSphere in case of fatal errors +;max_wait_for_purge_vm = 15 ; Timeout in seconds for waiting of completing the installation of the template VM ;max_wait_for_finish_install = 3600 diff --git a/lib/cr_vmware_tpl/config.py b/lib/cr_vmware_tpl/config.py index de72e35..4e8998d 100644 --- a/lib/cr_vmware_tpl/config.py +++ b/lib/cr_vmware_tpl/config.py @@ -17,7 +17,7 @@ import re # Own modules from fb_tools.config import ConfigError, BaseConfiguration -__version__ = '1.1.1' +__version__ = '1.2.0' LOG = logging.getLogger(__name__) @@ -50,6 +50,7 @@ class CrTplConfiguration(BaseConfiguration): default_network = '192.168.88.0_23' default_mac_address = '00:16:3e:54:ab:2b' default_max_wait_for_general = 15 + default_max_wait_for_shutdown = 600 default_max_wait_for_finish_install = 60 * 60 default_max_nr_templates_stay = 4 default_vmware_cfg_version = 'vmx-13' @@ -84,7 +85,8 @@ class CrTplConfiguration(BaseConfiguration): self.max_wait_for_general = self.default_max_wait_for_general self.max_wait_for_create_vm = None self.max_wait_for_poweron_vm = None - self.max_wait_for_shutdown_vm = None + self.max_wait_for_shutdown_vm = self.default_max_wait_for_shutdown + self.max_wait_for_purge_vm = None self.max_wait_for_finish_install = self.default_max_wait_for_finish_install self.max_nr_templates_stay = self.default_max_nr_templates_stay self.vmware_cfg_version = self.default_vmware_cfg_version @@ -151,6 +153,24 @@ class CrTplConfiguration(BaseConfiguration): return res + # ------------------------------------------------------------------------- + def eval_config(self, config): + """Evaluating of all found configuration options.""" + + super(CrTplConfiguration, self).eval_config(config) + + if self.verbose > 1: + LOG.debug("Checking for unconfigured options ...") + + if self.max_wait_for_create_vm is None: + self.max_wait_for_create_vm = self.max_wait_for_general + if self.max_wait_for_poweron_vm is None: + self.max_wait_for_poweron_vm = self.max_wait_for_general + if self.max_wait_for_purge_vm is None: + self.max_wait_for_purge_vm = self.max_wait_for_general + if self.max_wait_for_shutdown_vm is None: + self.max_wait_for_shutdown_vm = self.max_wait_for_general + # ------------------------------------------------------------------------- def eval_config_section(self, config, section_name): @@ -260,8 +280,6 @@ class CrTplConfiguration(BaseConfiguration): elif key.lower() == 'os_version': self.os_version = value.strip() - self._eval_config_timeouts(config, section_name) - return # ------------------------------------------------------------------------- @@ -328,6 +346,12 @@ class CrTplConfiguration(BaseConfiguration): prop_name='max_wait_for_shutdown_vm', value=value, min_val=self.min_max_wait_for_finish_general, max_val=self.max_max_wait_for_finish_general, + default_val=self.default_max_wait_for_shutdown) + elif key.lower() == 'max_wait_for_purge_vm': + self._eval_timeout_value( + prop_name='max_wait_for_purge_vm', value=value, + min_val=self.min_max_wait_for_finish_general, + max_val=self.max_max_wait_for_finish_general, default_val=self.max_wait_for_general) elif key.lower() == 'max_wait_for_finish_install': self._eval_timeout_value( @@ -336,13 +360,6 @@ class CrTplConfiguration(BaseConfiguration): max_val=self.max_max_wait_for_finish_install, default_val=self.default_max_wait_for_finish_install) - if self.max_wait_for_create_vm is None: - self.max_wait_for_create_vm = self.max_wait_for_general - if self.max_wait_for_poweron_vm is None: - self.max_wait_for_poweron_vm = self.max_wait_for_general - if self.max_wait_for_shutdown_vm is None: - self.max_wait_for_shutdown_vm = self.max_wait_for_general - # ============================================================================= if __name__ == "__main__": diff --git a/lib/cr_vmware_tpl/handler.py b/lib/cr_vmware_tpl/handler.py index b9d67c6..f94eda5 100644 --- a/lib/cr_vmware_tpl/handler.py +++ b/lib/cr_vmware_tpl/handler.py @@ -36,7 +36,7 @@ from fb_tools.vsphere.iface import VsphereVmInterface from .config import CrTplConfiguration -__version__ = '1.1.0' +__version__ = '1.2.0' LOG = logging.getLogger(__name__) TZ = pytz.timezone('Europe/Berlin') @@ -94,7 +94,6 @@ class CrTplHandler(BaseHandler): self.ssh_port = 22 self.ssh_user = 'root' self.ssh_timeout = 30 - self.max_wait_for_shutdown = 600 self.rotate_only = False self.abort = False self.postinstall_errors = None @@ -186,7 +185,7 @@ class CrTplHandler(BaseHandler): else: raise HandlerError("Could not find VM after creating.") - self.vsphere.poweron_vm(self.tpl_vm) + self.vsphere.poweron_vm(self.tpl_vm, max_wait=self.config.max_wait_for_poweron_vm) self.ts_start_install = time.time() self.wait_for_finish_install() @@ -197,7 +196,7 @@ class CrTplHandler(BaseHandler): else: self.post_install_tasks_ssh() if self.postinstall_errors: - self.vsphere.purge_vm(self.tpl_vm) + self.vsphere.purge_vm(self.tpl_vm, max_wait=self.config.max_wait_for_purge_vm) return 10 else: self.poweroff_vm() @@ -313,7 +312,7 @@ class CrTplHandler(BaseHandler): self.vsphere.create_vm( name=self.config.template_vm, vm_folder=tpl_vm_folder, vm_config_spec=vm_spec, - pool=self.cluster.resource_pool, max_wait=15) + pool=self.cluster.resource_pool, max_wait=self.config.max_wait_for_create_vm) # ------------------------------------------------------------------------- def wait_for_finish_install(self): @@ -707,7 +706,7 @@ class CrTplHandler(BaseHandler): LOG.info("Template VM {h!r} was shutting down in {t:0.1f} seconds.".format( h=self.config.template_vm, t=cur_diff)) return - if cur_diff >= self.max_wait_for_shutdown: + if cur_diff >= self.config.max_wait_for_shutdown_vm: break print('', flush=True) -- 2.39.5