Sandro Bonazzola has uploaded a new change for review. Change subject: packaging: setup: validate host id ......................................................................
packaging: setup: validate host id added host id validation on additional hosts setup. Requires: http://gerrit.ovirt.org/19140 Change-Id: I2487abfe1f722cb60e6f7c2a8daa4a81fb654bfd Signed-off-by: Sandro Bonazzola <sbona...@redhat.com> --- M src/plugins/ovirt-hosted-engine-setup/storage/storage.py 1 file changed, 49 insertions(+), 1 deletion(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-hosted-engine-setup refs/changes/71/19171/1 diff --git a/src/plugins/ovirt-hosted-engine-setup/storage/storage.py b/src/plugins/ovirt-hosted-engine-setup/storage/storage.py index 12d3f37..87fd1f9 100644 --- a/src/plugins/ovirt-hosted-engine-setup/storage/storage.py +++ b/src/plugins/ovirt-hosted-engine-setup/storage/storage.py @@ -22,6 +22,7 @@ Local storage domain plugin. """ +import glob import os import uuid import gettext @@ -36,6 +37,9 @@ from ovirt_hosted_engine_setup import constants as ohostedcons from ovirt_hosted_engine_setup import domains as ohosteddomains from ovirt_hosted_engine_setup import tasks + + +from ovirt_hosted_engine_ha.client import client _ = lambda m: gettext.dgettext(message=m, domain='ovirt-hosted-engine-setup') @@ -104,6 +108,28 @@ ) return rc + def _get_dom_md_path(self): + """ + Return path of storage domain holding engine vm + """ + domains = glob.glob( + os.path.join( + ohostedcons.FileLocations.SD_MOUNT_PARENT_DIR, + '*', + self.environment[ohostedcons.StorageEnv.SD_UUID], + ) + ) + if not domains: + raise RuntimeError( + _( + 'Path to storage domain {sd_uuid} not found in {root}' + ).format( + sd_uuid=self.environment[ohostedcons.StorageEnv.SD_UUID], + root=ohostedcons.FileLocations.SD_MOUNT_PARENT_DIR, + ) + ) + return domains[0] + def _handleHostId(self): if not self.environment[ ohostedcons.CoreEnv.ADDITIONAL_HOST_ENABLED @@ -159,7 +185,7 @@ default=ohostedcons.Const.FIRST_HOST_ID + 1, ) try: - valid = True + # ensure it's an int and not the FIRST_HOST_ID. if int( self.environment[ohostedcons.StorageEnv.HOST_ID] ) == ohostedcons.Const.FIRST_HOST_ID: @@ -172,6 +198,28 @@ raise RuntimeError( _('Cannot use the same ID used by first host') ) + # ensure nobody else is using it + ha_cli = client.HAClient() + all_host_stats = ha_cli.get_all_host_stats_direct( + dom_path=self._get_dom_md_path(), + service_type=self.environment[ + ohostedcons.SanlockEnv.LOCKSPACE_NAME + ], + ) + if self.environment[ + ohostedcons.StorageEnv.HOST_ID + ] in all_host_stats.keys(): + valid = False + if interactive: + self.logger.error( + _('Invalid value for Host ID: already used') + ) + else: + raise RuntimeError( + _('Invalid value for Host ID: already used') + ) + else: + valid = True except ValueError: valid = False if interactive: -- To view, visit http://gerrit.ovirt.org/19171 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I2487abfe1f722cb60e6f7c2a8daa4a81fb654bfd 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