Sandro Bonazzola has uploaded a new change for review. Change subject: packaging: setup: avoid traceback on adding host ......................................................................
packaging: setup: avoid traceback on adding host Previously if API could not return a CPU type using 'cluster.get_cpu()', the hosted-engine script failed out, breaking the installation process. Now it avoid to break the installation process allowing the user to add manually the host to the engine after setup exit. Also increased level of debugging in order to better understand how the cluster is configured when get_cpu fails. Change-Id: I4d7bad3033258291c8ab678b41254b1d4798394a Bug-Url: https://bugzilla.redhat.com/1088572 Signed-off-by: Sandro Bonazzola <sbona...@redhat.com> --- M src/plugins/ovirt-hosted-engine-setup/engine/add_host.py 1 file changed, 65 insertions(+), 41 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-hosted-engine-setup refs/changes/87/26887/1 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 f1a41a2..e3d78c1 100644 --- a/src/plugins/ovirt-hosted-engine-setup/engine/add_host.py +++ b/src/plugins/ovirt-hosted-engine-setup/engine/add_host.py @@ -195,6 +195,15 @@ self.logger.debug(address) return address + def _debug_obj(self, ndict, k, obj): + if not hasattr(obj, '__dict__'): + ndict[k] = obj + return + ndict[k] = {} + for j in obj.__dict__: + if j not in ('parentclass',): + self._debug_obj(ndict[k], j, obj.__dict__[j]) + def _wait_host_ready(self, engine_api, host): self.logger.info(_( 'Waiting for the host to become operational in the engine. ' @@ -248,12 +257,9 @@ tries -= 1 cpu = cluster.get_cpu() if cpu is None: - self.logger.debug( - 'cluster {cluster} cluster.__dict__ {cdict}'.format( - cluster=cluster, - cdict=cluster.__dict__, - ) - ) + dump = {} + self._debug_obj(dump, 'cluster', cluster) + self.logger.debug(dump) if tries % 30 == 0: self.logger.info( _( @@ -405,6 +411,7 @@ self._getSSHkey() cluster_name = None default_cluster_name = 'Default' + host_added = False try: self.logger.debug('Connecting to the Engine') engine_api = self._ovirtsdk_api.API( @@ -471,6 +478,9 @@ override_iptables=True, ) ) + host_added = True + except RuntimeError as e: + self.logger.error(e) except ovirtsdk.infrastructure.errors.RequestError as e: self.logger.debug( 'Cannot add the host to cluster {cluster}'.format( @@ -487,47 +497,61 @@ details=e.detail ) ) - up = self._wait_host_ready( - engine_api, - self.environment[ohostedcons.EngineEnv.APP_HOST_NAME] - ) - if not up: - self.logger.error( - _( - 'Unable to add {host} to the manager' - ).format( - host=self.environment[ - ohostedcons.EngineEnv.APP_HOST_NAME - ], - ) + if host_added: + up = self._wait_host_ready( + engine_api, + self.environment[ohostedcons.EngineEnv.APP_HOST_NAME] ) - else: - # This works only if the host is up. - self.logger.debug('Setting CPU for the cluster') - try: - cluster = engine_api.clusters.get(cluster_name) - self.logger.debug(cluster.__dict__) - cpu = self._wait_cluster_cpu_ready(cluster) - self.logger.debug(cpu.__dict__) - cpu.set_id(self.environment[ohostedcons.VDSMEnv.ENGINE_CPU]) - cluster.set_cpu(cpu) - cluster.update() - except ovirtsdk.infrastructure.errors.RequestError as e: - self.logger.debug( - 'Cannot set CPU level of cluster {cluster}'.format( - cluster=cluster_name, - ), - exc_info=True, - ) + if not up: self.logger.error( _( - 'Cannot automatically set CPU level ' - 'of cluster {cluster}:\n{details}\n' + 'Unable to add {host} to the manager' ).format( - cluster=cluster_name, - details=e.detail + host=self.environment[ + ohostedcons.EngineEnv.APP_HOST_NAME + ], ) ) + else: + # This works only if the host is up. + self.logger.debug('Setting CPU for the cluster') + try: + cluster = engine_api.clusters.get(cluster_name) + dump = {} + self._debug_obj(dump, 'cluster', cluster) + self.logger.debug(dump) + cpu = self._wait_cluster_cpu_ready(cluster) + if cpu is None: + raise RuntimeError( + _( + 'Cluster has not been initialized, ' + 'please check logs' + ) + ) + dump = {} + self._debug_obj(dump, 'cpu', cpu) + self.logger.debug(dump) + cpu.set_id( + self.environment[ohostedcons.VDSMEnv.ENGINE_CPU] + ) + cluster.set_cpu(cpu) + cluster.update() + except ovirtsdk.infrastructure.errors.RequestError as e: + self.logger.debug( + 'Cannot set CPU level of cluster {cluster}'.format( + cluster=cluster_name, + ), + exc_info=True, + ) + self.logger.error( + _( + 'Cannot automatically set CPU level ' + 'of cluster {cluster}:\n{details}\n' + ).format( + cluster=cluster_name, + details=e.detail + ) + ) engine_api.disconnect() @plugin.event( -- To view, visit http://gerrit.ovirt.org/26887 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I4d7bad3033258291c8ab678b41254b1d4798394a Gerrit-PatchSet: 1 Gerrit-Project: ovirt-hosted-engine-setup Gerrit-Branch: master Gerrit-Owner: Sandro Bonazzola <sbona...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches