Yaniv Bronhaim has uploaded a new change for review. Change subject: centralized manualSetupDispatcher code ......................................................................
centralized manualSetupDispatcher code The list of options to manipulate the engine vm is relevant in many parts of the installation process. This patch moves the options list implementation to check_liveliness module and uses it in few events. This code is aimed to be reused on communication errors with the engine vm. Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1188663 Signed-off-by: Yaniv Bronhaim <ybron...@redhat.com> Change-Id: I360cf8e0c3c0ed9db1e9af3127ebd7881ed11d11 --- M src/ovirt_hosted_engine_setup/check_liveliness.py M src/plugins/ovirt-hosted-engine-setup/engine/add_host.py M src/plugins/ovirt-hosted-engine-setup/engine/health.py M src/plugins/ovirt-hosted-engine-setup/vm/runvm.py 4 files changed, 156 insertions(+), 187 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-hosted-engine-setup refs/changes/99/41399/1 diff --git a/src/ovirt_hosted_engine_setup/check_liveliness.py b/src/ovirt_hosted_engine_setup/check_liveliness.py index e013f4e..64c077a 100644 --- a/src/ovirt_hosted_engine_setup/check_liveliness.py +++ b/src/ovirt_hosted_engine_setup/check_liveliness.py @@ -34,6 +34,51 @@ return gettext.dgettext(message=m, domain='ovirt-hosted-engine-setup') +def manualSetupDispatcher(base, engine_fqdn=None): + response = base.dialog.queryString( + name='OVEHOSTED_ENGINE_UP', + note=_( + 'To continue make a selection from ' + 'the options below:\n' + '(1) Continue setup - VM or engine installation ' + 'is complete\n' + '(2) Power off and restart the VM\n' + '(3) Abort setup\n' + '(4) Destroy VM and abort setup\n' + '\n(@VALUES@)[@DEFAULT@]: ' + ), + prompt=True, + validValues=(_('1'), _('2'), _('3'), _('4')), + default=_('1'), + caseSensitive=False) + if response == _('1').lower(): + if engine_fqdn is None: + if not base._wait_vm_destroyed(): + base._destroy_vm() + return True + elif live_checker.isEngineUp(engine_fqdn): + return True + else: + base.dialog.note(_( + 'Engine health status page is not yet reachable.\n' + )) + elif response == _('2').lower(): + base._destroy_vm() + base._create_vm() + elif response == _('3').lower(): + raise RuntimeError('Engine polling aborted by user') + elif response == _('4').lower(): + base._destroy_vm() + raise RuntimeError( + _('VM destroyed and setup aborted by user') + ) + else: + base.logger.error( + 'Invalid option \'{0}\''.format(response) + ) + return False + + @util.export class LivelinessChecker(base.Base): diff --git a/src/plugins/ovirt-hosted-engine-setup/engine/add_host.py b/src/plugins/ovirt-hosted-engine-setup/engine/add_host.py index ebac166..545f8f7 100644 --- a/src/plugins/ovirt-hosted-engine-setup/engine/add_host.py +++ b/src/plugins/ovirt-hosted-engine-setup/engine/add_host.py @@ -47,6 +47,7 @@ from vdsm import netinfo +from ovirt_hosted_engine_setup import check_liveliness from ovirt_hosted_engine_setup import constants as ohostedcons from ovirt_hosted_engine_setup import vds_info @@ -601,118 +602,117 @@ ) ) - try: - conn = self.environment[ohostedcons.VDSMEnv.VDS_CLI] - net_info = netinfo.NetInfo(vds_info.capabilities(conn)) - bridge_port = self.environment[ohostedcons.NetworkEnv.BRIDGE_IF] - if bridge_port in net_info.vlans: - self.logger.debug( - "Updating engine's management network to be vlanned" - ) - vlan_id = net_info.vlans[bridge_port]['vlanid'] - self.logger.debug( - "Getting engine's management network via engine's APIs" - ) - mgmt_network = engine_api.networks.get( - name=self.environment[ohostedcons.NetworkEnv.BRIDGE_NAME] - ) - mgmt_network.set_vlan( - self._ovirtsdk_xml.params.VLAN(id=vlan_id) - ) - mgmt_network.update() - - cluster_name = self.environment[ - ohostedcons.EngineEnv.HOST_CLUSTER_NAME - ] - self.logger.debug( - "Getting the list of available clusters via engine's APIs" - ) - if cluster_name is not None: - if cluster_name not in [ - c.get_name() - for c in engine_api.clusters.list() - ]: - raise RuntimeError( - _( - 'Specified cluster does not exist: {cluster}' - ).format( - cluster=cluster_name, - ) + added_to_cluster = False + while not added_to_cluster: + try: + conn = self.environment[ohostedcons.VDSMEnv.VDS_CLI] + net_info = netinfo.NetInfo(vds_info.capabilities(conn)) + bridge_port = self.environment[ohostedcons.NetworkEnv.BRIDGE_IF] + if bridge_port in net_info.vlans: + self.logger.debug( + "Updating engine's management network to be vlanned" ) - else: - cluster_l = [c.get_name() for c in engine_api.clusters.list()] - cluster_name = ( - default_cluster_name if default_cluster_name in - cluster_l else cluster_l[0] - ) - cluster_name = self.dialog.queryString( - name='cluster_name', - note=_( - 'Enter the name of the cluster to which you want to ' - 'add the host (@VALUES@) [@DEFAULT@]: ' - ), - prompt=True, - default=cluster_name, - validValues=cluster_l, - ) - self.environment[ - ohostedcons.EngineEnv.HOST_CLUSTER_NAME - ] = cluster_name - cluster = engine_api.clusters.get(cluster_name) - # Configuring the cluster for Hyper Converged support if enabled - if self.environment[ - ohostedcons.StorageEnv.GLUSTER_PROVISIONING_ENABLED - ]: - cluster.set_gluster_service(True) - cluster.update() - cluster = engine_api.clusters.get(cluster_name) + vlan_id = net_info.vlans[bridge_port]['vlanid'] + self.logger.debug( + "Getting engine's management network via engine's APIs" + ) + mgmt_network = engine_api.networks.get( + name=self.environment[ohostedcons.NetworkEnv.BRIDGE_NAME] + ) + mgmt_network.set_vlan( + self._ovirtsdk_xml.params.VLAN(id=vlan_id) + ) + mgmt_network.update() - self.logger.debug('Adding the host to the cluster') - engine_api.hosts.add( - self._ovirtsdk_xml.params.Host( - name=self.environment[ - ohostedcons.EngineEnv.APP_HOST_NAME - ], - # Note that the below is required for compatibility - # with vdsm-generated pki. See bz 1178535. - # TODO: Make it configurable like engine fqdn. - address=socket.gethostname(), - reboot_after_installation=False, - cluster=cluster, - ssh=self._ovirtsdk_xml.params.SSH( - authentication_method='publickey', - port=self.environment[ - ohostedcons.NetworkEnv.SSHD_PORT + cluster_name = self.environment[ + ohostedcons.EngineEnv.HOST_CLUSTER_NAME + ] + self.logger.debug( + "Getting the list of available clusters via engine's APIs" + ) + if cluster_name is not None: + if cluster_name not in [ + c.get_name() + for c in engine_api.clusters.list() + ]: + raise RuntimeError( + _( + 'Specified cluster does not exist: {cluster}' + ).format( + cluster=cluster_name, + ) + ) + else: + cluster_l = [c.get_name() for c in engine_api.clusters.list()] + cluster_name = ( + default_cluster_name if default_cluster_name in + cluster_l else cluster_l[0] + ) + cluster_name = self.dialog.queryString( + name='cluster_name', + note=_( + 'Enter the name of the cluster to which you want to ' + 'add the host (@VALUES@) [@DEFAULT@]: ' + ), + prompt=True, + default=cluster_name, + validValues=cluster_l, + ) + self.environment[ + ohostedcons.EngineEnv.HOST_CLUSTER_NAME + ] = cluster_name + cluster = engine_api.clusters.get(cluster_name) + # Configuring the cluster for Hyper Converged support if enabled + if self.environment[ + ohostedcons.StorageEnv.GLUSTER_PROVISIONING_ENABLED + ]: + cluster.set_gluster_service(True) + cluster.update() + cluster = engine_api.clusters.get(cluster_name) + + self.logger.debug('Adding the host to the cluster') + + engine_api.hosts.add( + self._ovirtsdk_xml.params.Host( + name=self.environment[ + ohostedcons.EngineEnv.APP_HOST_NAME ], + # Note that the below is required for compatibility + # with vdsm-generated pki. See bz 1178535. + # TODO: Make it configurable like engine fqdn. + address=socket.gethostname(), + reboot_after_installation=False, + cluster=cluster, + ssh=self._ovirtsdk_xml.params.SSH( + authentication_method='publickey', + port=self.environment[ + ohostedcons.NetworkEnv.SSHD_PORT + ], + ), + override_iptables=self.environment[ + otopicons.NetEnv.IPTABLES_ENABLE + ], + ) + ) + added_to_cluster = True + except ovirtsdk.infrastructure.errors.RequestError as e: + self.logger.debug( + 'Cannot add the host to cluster {cluster}'.format( + cluster=cluster_name, ), - override_iptables=self.environment[ - otopicons.NetEnv.IPTABLES_ENABLE - ], + exc_info=True, ) - ) - except ovirtsdk.infrastructure.errors.RequestError as e: - self.logger.debug( - 'Cannot add the host to cluster {cluster}'.format( - cluster=cluster_name, - ), - exc_info=True, - ) - self.logger.error( - _( - 'Cannot automatically add the host ' - 'to cluster {cluster}:\n{details}\n' - ).format( - cluster=cluster_name, - details=e.detail + self.logger.error( + _( + 'Cannot automatically add the host ' + 'to cluster {cluster}:\n{details}\n' + ).format( + cluster=cluster_name, + details=e.detail + ) ) - ) - raise RuntimeError( - _( - 'Cannot add the host to cluster {cluster}' - ).format( - cluster=cluster_name, - ) - ) + while not check_liveliness.manualSetupDispatcher(self, '{fqdn}'): + pass up = self._wait_host_ready( engine_api, diff --git a/src/plugins/ovirt-hosted-engine-setup/engine/health.py b/src/plugins/ovirt-hosted-engine-setup/engine/health.py index 640c6af..9cb84db 100644 --- a/src/plugins/ovirt-hosted-engine-setup/engine/health.py +++ b/src/plugins/ovirt-hosted-engine-setup/engine/health.py @@ -75,7 +75,6 @@ live_checker = check_liveliness.LivelinessChecker() # manual engine setup execution if not esexecuting: - userpoll = True self.dialog.note( _('Please install and setup the engine in the VM.') ) @@ -86,44 +85,9 @@ 'in the VM.' ) ) - while userpoll: - response = self.dialog.queryString( - name='OVEHOSTED_ENGINE_UP', - note=_( - 'To continue make a selection from ' - 'the options below:\n' - '(1) Continue setup - engine installation ' - 'is complete\n' - '(2) Power off and restart the VM\n' - '(3) Abort setup\n' - '(4) Destroy VM and abort setup\n' - '\n(@VALUES@)[@DEFAULT@]: ' - ), - prompt=True, - validValues=(_('1'), _('2'), _('3'), _('4')), - default=_('1'), - caseSensitive=False) - if response == _('1').lower(): - if live_checker.isEngineUp(fqdn): - userpoll = False - else: - self.dialog.note(_( - 'Engine health status page is not yet reachable.\n' - )) - elif response == _('2').lower(): - self._destroy_vm() - self._create_vm() - elif response == _('3').lower(): - raise RuntimeError('Engine polling aborted by user') - elif response == _('4').lower(): - self._destroy_vm() - raise RuntimeError( - _('VM destroyed and setup aborted by user') - ) - else: - self.logger.error( - 'Invalid option \'{0}\''.format(response) - ) + while not check_liveliness.manualSetupDispatcher(self, fqdn): + pass + # automated engine setup execution on the appliance else: spath = ( diff --git a/src/plugins/ovirt-hosted-engine-setup/vm/runvm.py b/src/plugins/ovirt-hosted-engine-setup/vm/runvm.py index 3a65753..eecea0d 100644 --- a/src/plugins/ovirt-hosted-engine-setup/vm/runvm.py +++ b/src/plugins/ovirt-hosted-engine-setup/vm/runvm.py @@ -33,6 +33,7 @@ from vdsm import vdscli +from ovirt_hosted_engine_setup import check_liveliness from ovirt_hosted_engine_setup import constants as ohostedcons from ovirt_hosted_engine_setup import mixins @@ -147,48 +148,7 @@ while not os_installed: try: self._create_vm() - response = None - while response is None: - response = self.dialog.queryString( - name='OVEHOSTED_INSTALLING_OS', - note=_( - 'The VM has been started. ' - 'Install the OS and shut down or reboot it. ' - 'To continue please make a selection:\n\n' - '(1) Continue setup - ' - 'VM installation is complete\n' - '(2) Reboot the VM and restart installation\n' - '(3) Abort setup\n' - '(4) Destroy VM and abort setup\n' - '\n(@VALUES@)[@DEFAULT@]: ' - ), - prompt=True, - validValues=(_('1'), _('2'), _('3'), _('4')), - default=_('1'), - caseSensitive=False) - if response == _('1').lower(): - self.dialog.note( - _('Waiting for VM to shut down...\n') - ) - if not self._wait_vm_destroyed(): - self._destroy_vm() - os_installed = True - elif response == _('2').lower(): - self._destroy_vm() - elif response == _('3').lower(): - raise RuntimeError( - _('OS installation aborted by user') - ) - elif response == _('4').lower(): - self._destroy_vm() - raise RuntimeError( - _('VM destroyed and setup aborted by user') - ) - else: - self.logger.error( - 'Invalid option \'{0}\''.format(response) - ) - response = None + os_installed = check_liveliness.manualSetupDispatcher(self) except socket.error as e: self.logger.debug( 'Error talking with VDSM (%s), reconnecting.' % str(e), -- To view, visit https://gerrit.ovirt.org/41399 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I360cf8e0c3c0ed9db1e9af3127ebd7881ed11d11 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-hosted-engine-setup Gerrit-Branch: master Gerrit-Owner: Yaniv Bronhaim <ybron...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches