Simone Tiraboschi has uploaded a new change for review. Change subject: packaging: setup: avoid copying answerfile over scp ......................................................................
packaging: setup: avoid copying answerfile over scp On additional hosts: - Reading hosted-engine.conf to gather storage domain and conf image info - Reading first host answerfile from the shared storage Change-Id: I1ddd660d745887814b77ce4db4c1065e5b2128bd Signed-off-by: Simone Tiraboschi <[email protected]> --- M ovirt-hosted-engine-setup.spec.in M src/ovirt_hosted_engine_setup/constants.py M src/plugins/ovirt-hosted-engine-setup/core/remote_answerfile.py 3 files changed, 32 insertions(+), 213 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-hosted-engine-setup refs/changes/24/42224/1 diff --git a/ovirt-hosted-engine-setup.spec.in b/ovirt-hosted-engine-setup.spec.in index 9e6c78e..e75e555 100644 --- a/ovirt-hosted-engine-setup.spec.in +++ b/ovirt-hosted-engine-setup.spec.in @@ -45,7 +45,6 @@ Requires: openssl Requires: python Requires: python-ethtool >= 0.6-3 -Requires: python-paramiko Requires: python-netaddr Requires: sanlock >= 2.8 Requires: sanlock-python >= 2.8 diff --git a/src/ovirt_hosted_engine_setup/constants.py b/src/ovirt_hosted_engine_setup/constants.py index a741f37..78bbe09 100644 --- a/src/ovirt_hosted_engine_setup/constants.py +++ b/src/ovirt_hosted_engine_setup/constants.py @@ -1006,13 +1006,4 @@ SETTINGS = 'SETTINGS_PROCEED' [email protected] [email protected] -class FirstHostEnv(object): - FQDN = 'OVEHOSTED_FIRST_HOST/fqdn' - ROOT_PASSWORD = 'OVEHOSTED_FIRST_HOST/rootPassword' - FETCH_ANSWER = 'OVEHOSTED_FIRST_HOST/fetchAnswer' - SSHD_PORT = 'OVEHOSTED_FIRST_HOST/sshdPort' - - # vim: expandtab tabstop=4 shiftwidth=4 diff --git a/src/plugins/ovirt-hosted-engine-setup/core/remote_answerfile.py b/src/plugins/ovirt-hosted-engine-setup/core/remote_answerfile.py index ac1be22..65df23f 100644 --- a/src/plugins/ovirt-hosted-engine-setup/core/remote_answerfile.py +++ b/src/plugins/ovirt-hosted-engine-setup/core/remote_answerfile.py @@ -23,11 +23,7 @@ import configparser import gettext -import os -import paramiko -import socket -import tempfile - +from io import StringIO from otopi import common from otopi import constants as otopicons @@ -36,6 +32,9 @@ from ovirt_hosted_engine_setup import constants as ohostedcons +from ovirt_hosted_engine_setup import heconflib +from ovirt_hosted_engine_setup import util as ohostedutil +from ovirt_hosted_engine_ha.env import config def _(m): @@ -52,136 +51,38 @@ self._config.optionxform = str self._tmp_ans = None - def _get_fqdn(self): - fqdn_interactive = self.environment[ - ohostedcons.FirstHostEnv.FQDN - ] is None - valid = False - while not valid: - if fqdn_interactive: - self.environment[ - ohostedcons.FirstHostEnv.FQDN - ] = self.dialog.queryString( - name='OVEHOSTED_NET_FIRST_HOST_FQDN', - note=_( - 'Please provide the FQDN or IP of the first host: ' - ), - prompt=True, - caseSensitive=True, - ) - transport = None - try: - transport = paramiko.Transport((self.environment[ - ohostedcons.FirstHostEnv.FQDN - ], 22)) - valid = True - except (paramiko.SSHException, socket.gaierror) as e: - self.logger.debug('exception', exc_info=True) - if fqdn_interactive: - self.logger.error( - _( - 'Unable to connect to {fqdn}. Error: {error}' - ).format( - fqdn=self.environment[ - ohostedcons.FirstHostEnv.FQDN - ], - error=e, - ) - ) - else: - raise RuntimeError( - _( - 'Unable to connect to {fqdn}. Error: {error}' - ).format( - fqdn=self.environment[ - ohostedcons.FirstHostEnv.FQDN - ], - error=e, - ) - ) - finally: - if transport is not None: - transport.close() - def _fetch_answer_file(self): self.logger.debug('_fetch_answer_file') - fqdn = self.environment[ohostedcons.FirstHostEnv.FQDN] - interactive = ( - self.environment[ohostedcons.FirstHostEnv.ROOT_PASSWORD] is None + + heconf = config.Config() + + sd_uuid = heconf.get(config.ENGINE, config.SD_UUID) + dom_type = heconf.get(config.ENGINE, config.DOMAIN_TYPE) + conf_volume = heconf.get(config.ENGINE, config.CONF_VOLUME_UUID) + conf_image = heconf.get(config.ENGINE, config.CONF_IMAGE_UUID) + + source = ohostedutil.get_volume_path( + dom_type, + sd_uuid, + conf_image, + conf_volume, ) - while self.environment[ohostedcons.FirstHostEnv.ROOT_PASSWORD] is None: - if interactive: - password = self.dialog.queryString( - name='HOST_FIRST_HOST_ROOT_PASSWORD', - note=_( - "Enter 'root' user password for host {fqdn}: " - ).format( - fqdn=fqdn, - ), - prompt=True, - hidden=True, - ) - transport = None - try: - transport = paramiko.Transport( - ( - fqdn, - self.environment[ohostedcons.FirstHostEnv.SSHD_PORT], - ) - ) - transport.connect(username='root', password=password) - self.environment[ - ohostedcons.FirstHostEnv.ROOT_PASSWORD - ] = password - try: - fd, self._tmp_ans = tempfile.mkstemp( - dir=self.environment[ohostedcons.CoreEnv.TEMPDIR], - ) - os.close(fd) - sftp = paramiko.SFTPClient.from_transport(transport) - sftp.get( - self.environment[ohostedcons.CoreEnv.ETC_ANSWER_FILE], - self._tmp_ans - ) - finally: - sftp.close() - except paramiko.AuthenticationException as e: - self.logger.error( - _('Invalid password for host {fqdn}').format( - fqdn=fqdn, - ) - ) - if not interactive: - raise RuntimeError( - _( - 'Cannot deploy Hosted Engine on additional host: ' - 'unable to fetch the configuration used ' - 'on first host' - ) - ) - except (paramiko.SSHException, socket.gaierror) as e: - self.logger.debug('exception', exc_info=True) - self.logger.error( - _('Unable to connect to {fqdn}. Error:{error}').format( - fqdn=fqdn, - error=e, - ) - ) - if not interactive: - raise RuntimeError( - _( - 'Cannot deploy Hosted Engine on additional host: ' - 'unable to fetch the configuration used ' - 'on first host' - ) - ) - finally: - if transport is not None: - transport.close() - self.logger.info(_('Answer file successfully downloaded')) + self.logger.debug('fetching from: ' + str(source)) + + if not heconflib.validateConfImage(self.logger, source): + msg = _('Unable to get the answerfile from the shared storage') + self.logger.error(msg) + raise RuntimeError(msg) + self._tmp_ans = heconflib.extractConfFile( + self._logger, + source, + ohostedcons.FileLocations.HECONFD_ANSWERFILE, + ) + self.logger.info(_('Answer file successfully loaded')) def _parse_answer_file(self): - self._config.read(self._tmp_ans) + buf = StringIO(unicode(self._tmp_ans)) + self._config.readfp(buf) for name, value in self._config.items( otopicons.Const.CONFIG_SECTION_DEFAULT ): @@ -202,30 +103,6 @@ self.environment[name] = value @plugin.event( - stage=plugin.Stages.STAGE_INIT, - ) - def _init(self): - self.environment.setdefault( - ohostedcons.FirstHostEnv.FQDN, - None - ) - self.environment.setdefault( - ohostedcons.FirstHostEnv.ROOT_PASSWORD, - None - ) - self.environment[otopicons.CoreEnv.LOG_FILTER_KEYS].append( - ohostedcons.FirstHostEnv.ROOT_PASSWORD - ) - self.environment.setdefault( - ohostedcons.FirstHostEnv.FETCH_ANSWER, - None - ) - self.environment.setdefault( - ohostedcons.FirstHostEnv.SSHD_PORT, - ohostedcons.Defaults.DEFAULT_SSHD_PORT - ) - - @plugin.event( name=ohostedcons.Stages.REQUIRE_ANSWER_FILE, stage=plugin.Stages.STAGE_CUSTOMIZATION, after=( @@ -236,60 +113,12 @@ ohostedcons.Stages.DIALOG_TITLES_E_SYSTEM, ), condition=lambda self: ( - self.environment[ohostedcons.CoreEnv.IS_ADDITIONAL_HOST] and - self.environment[otopicons.CoreEnv.CONFIG_FILE_APPEND] is None + self.environment[ohostedcons.CoreEnv.IS_ADDITIONAL_HOST] ), ) def _customization(self): - self.logger.warning( - _( - 'A configuration file must be supplied to deploy ' - 'Hosted Engine on an additional host.' - ) - ) - - interactive = self.environment[ - ohostedcons.FirstHostEnv.FETCH_ANSWER - ] is None - if interactive: - self.environment[ - ohostedcons.FirstHostEnv.FETCH_ANSWER - ] = self.dialog.queryString( - name='OVEHOSTED_CORE_FETCH_ANSWER', - note=_( - 'The answer file may be fetched from the first host ' - 'using scp.\n' - 'If you do not want to download it ' - 'automatically you can abort the setup answering no ' - 'to the following question.\n' - 'Do you want to scp the answer file from the first host? ' - '(@VALUES@)[@DEFAULT@]: ' - ), - prompt=True, - validValues=(_('Yes'), _('No')), - caseSensitive=False, - default=_('Yes') - ) == _('Yes').lower() - - if not self.environment[ohostedcons.FirstHostEnv.FETCH_ANSWER]: - raise RuntimeError( - _( - 'Cannot deploy Hosted Engine on additional hosts ' - 'without access to the configuration used on ' - 'the first host' - ) - ) - - self._get_fqdn() self._fetch_answer_file() self._parse_answer_file() - - @plugin.event( - stage=plugin.Stages.STAGE_CLEANUP, - ) - def _cleanup(self): - if self._tmp_ans and os.path.exists(self._tmp_ans): - os.unlink(self._tmp_ans) # vim: expandtab tabstop=4 shiftwidth=4 -- To view, visit https://gerrit.ovirt.org/42224 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I1ddd660d745887814b77ce4db4c1065e5b2128bd Gerrit-PatchSet: 1 Gerrit-Project: ovirt-hosted-engine-setup Gerrit-Branch: master Gerrit-Owner: Simone Tiraboschi <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
