Douglas Schilling Landgraf has uploaded a new change for review.
Change subject: vdsm-upgrade: adds wrapper to ovirt-node-upgrade
......................................................................
vdsm-upgrade: adds wrapper to ovirt-node-upgrade
Currently ovirt-node provides ovirt-node-upgrade tool which
should replace vdsm-upgrade. This patch re-write vdsm-upgrade
as wrapper of ovirt-node-upgrade.
Change-Id: I7b997d70a440545497246d1a19d9671b054a56a5
Bug-Url:
https://bugzilla.redhat.com/show_bug.cgi?id=1079087
Signed-off-by: Douglas Schilling Landgraf <dougsland(a)redhat.com>
---
M vdsm.spec.in
M vdsm_reg/vdsm-upgrade
2 files changed, 54 insertions(+), 153 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/44/28244/1
diff --git a/vdsm.spec.in b/vdsm.spec.in
index 35617ab..9c0e167 100644
--- a/vdsm.spec.in
+++ b/vdsm.spec.in
@@ -325,6 +325,7 @@
Requires: %{name} = %{version}-%{release}
Requires: m2crypto
Requires: openssl
+Requires: ovirt-node >= 3.0.4
%description reg
VDSM registration package. Used to register a Linux host to a Virtualization
diff --git a/vdsm_reg/vdsm-upgrade b/vdsm_reg/vdsm-upgrade
index d9bdd31..04967af 100755
--- a/vdsm_reg/vdsm-upgrade
+++ b/vdsm_reg/vdsm-upgrade
@@ -1,184 +1,84 @@
#!/usr/bin/python
+# -*- coding: utf-8 -*-
#
-# Copyright 2008 Red Hat, Inc. and/or its affiliates.
+# Copyright (C) 2008-2014 Red Hat, Inc.
#
# Licensed to you under the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. See the files README and
# LICENSE_GPL_v2 which accompany this distribution.
#
-
-import errno
-import sys
-import os
import logging
-import logging.config
-from time import strftime
-from config import config
-import deployUtil
-from ovirtnode.install import Install
+import time
-VDSM_REG_CONF_FILE = '/etc/vdsm-reg/vdsm-reg.conf'
-VDSM_CONF_FILE = '/etc/vdsm/vdsm.conf'
-log_filename =
'/var/log/vdsm-reg/vds_bootstrap_upgrade.'+strftime("%Y%m%d_%H%M%S")+'.log'
+from vdsm import utils
-try:
- logging.basicConfig(level=logging.DEBUG,
- format='%(asctime)s %(levelname)-8s %(message)s',
- datefmt='%a, %d %b %Y %H:%M:%S',
- filename=log_filename,
- filemode='w')
-except:
- log_filename =
'/var/log/vds_bootstrap_upgrade.'+strftime("%Y%m%d_%H%M%S")+'.log'
- logging.basicConfig(level=logging.DEBUG,
- format='%(asctime)s %(levelname)-8s %(message)s',
- datefmt='%a, %d %b %Y %H:%M:%S',
- filename=log_filename,
- filemode='w')
-def setMountPoint(config):
- strFile = config.get('vars', 'upgrade_iso_file')
- strMountPoint = config.get('vars', 'upgrade_mount_point')
+class VdsmService(object):
+ def __init__(self):
+ self.cmd = ['vdsm-tool', '', 'vdsmd']
- try:
- fOK = True
- ret = None
- err = ""
- out = None
+ def start(self):
+ self.cmd[1] = "service-start"
+ return utils.execCmd(self.cmd, sudo=True, raw=True)
- #First look for the upgrade file
- if not os.path.exists(strFile):
- fOK = False
- msg = "<BSTRAP component='setMountPoint' status='FAIL'
message='Upgrade file not found'/>"
- logging.error(msg)
- print (msg)
+ def stop(self):
+ self.cmd[1] = "service-stop"
+ return utils.execCmd(self.cmd, sudo=True, raw=True)
- #Now, check if we need to create a mount-point dir.
- if fOK and not os.path.exists(strMountPoint):
- try: os.mkdir(strMountPoint)
- except OSError as err:
- if err.errno != errno.EEXIST:
- fOK = False
+ def status(self):
+ self.cmd[1] = "service-status"
+ return utils.execCmd(self.cmd, sudo=True, raw=True)
- #Now, loop-mount the upgrade iso file.
- if not fOK:
- msg = "<BSTRAP component='setMountPoint' status='FAIL'
message='Failed to create mount point: " + deployUtil.escapeXML(str(err)) +
"'/>"
- print (msg)
- logging.error(msg)
- else:
- out, err, ret = deployUtil._logExec(["/bin/mount", "-o",
"loop", strFile, strMountPoint])
- fOK = (ret != None and ret == 0)
-
- msg = ""
- if fOK:
- msg = "<BSTRAP component='setMountPoint' status='OK'
message='Mount succeeded.'/>"
- logging.debug(msg)
- else:
- msg = "<BSTRAP component='setMountPoint' status='FAIL'
message='Failed to mount ISO file: " + deployUtil.escapeXML(str(err)) +
"'/>"
- logging.error(msg)
- print msg
- except Exception as e:
- fOK = False
- msg = "<BSTRAP component='setMountPoint' status='FAIL'
message='setMountPoint exception: " + deployUtil.escapeXML(str(e)) +
"'/>"
- logging.error(msg)
- print (msg)
-
- return fOK
-
-def doUpgrade(config):
- fReturn = True
-
- install = Install()
- if install.ovirt_boot_setup(reboot="Y"):
- msg = "<BSTRAP component='doUpgrade' status='OK'
message='Upgrade Succeeded. Rebooting'/>"
- print (msg)
- logging.debug(msg)
- else:
- msg = "<BSTRAP component='doUpgrade' status='FAIL'
message='Upgrade Failed!'/>"
- print (msg)
- logging.error(msg)
- fReturn = False
-
- return fReturn
-
-def umount(config, shouldReport=True):
- out = None
- err = None
- ret = None
- fReturn = True
-
- strMountPoint = config.get('vars', 'upgrade_mount_point')
-
- if os.path.exists(strMountPoint):
- out, err, ret = deployUtil._logExec(["/bin/umount", strMountPoint])
- fReturn = (ret != None and ret == 0)
-
- if fReturn:
- msg = "<BSTRAP component='umount' status='OK'
message='umount Succeeded'/>"
- else:
- msg = "<BSTRAP component='umount' status='FAIL'
message=' " + deployUtil.escapeXML(str(err)) + "'/>"
-
- if shouldReport:
- print (msg)
-
- logging.debug(msg)
- return fReturn
def main():
- """Usage: vdsm-upgrade """
- fOK = True
- fMounted = False
+ _log_file = '/var/log/vdsm-reg/vds_bootstrap_upgrade.' + \
+ time.strftime("%Y%m%d_%H%M%S")+'.log'
- # Checking the current status of vdsm
- out, err, ret = deployUtil.setService('vdsmd', 'status')
- if ret == 0:
- # Stop vdsm to avoid communication with Engine before the reboot happens
- out, err, ret = deployUtil.setService('vdsmd', 'stop')
- if ret != 0:
+ logging.basicConfig(
+ level=logging.DEBUG,
+ format='%(asctime)s %(levelname)-8s %(message)s',
+ datefmt='%a, %d %b %Y %H:%M:%S',
+ filename=_log_file,
+ filemode='w'
+ )
+
+ vdsm_service = VdsmService()
+
+ rc, out, err = vdsm_service.status()
+ if rc == 0:
+ rc, out, err = vdsm_service.stop()
+ if rc != 0:
msg = "<BSTRAP component='RHEL_INSTALL'
status='FAIL'" \
- " message='Cannot stop vdsm daemon before we" \
- " start the upgrade, please verify!'/>"
+ " message='Cannot stop vdsm daemon before we" \
+ " start the upgrade, please verify!'/>"
else:
msg = "<BSTRAP component='RHEL_INSTALL'
status='OK'" \
- " message='vdsm daemon stopped for upgrade
process!'/>"
-
+ " message='vdsm daemon stopped for upgrade
process!'/>"
else:
msg = "<BSTRAP component='RHEL_INSTALL'
status='WARN'" \
- " message='vdsm daemon is already down before we" \
- " stop it for upgrade.'/>"
-
+ " message='vdsm daemon is already down before we" \
+ " stop it for upgrade.'/>"
logging.debug(msg)
print(msg)
- try:
- config.read(VDSM_REG_CONF_FILE)
+ if rc == 0:
+ cmd = [
+ 'ovirt-node-upgrade',
+ '--iso',
+ '/data/updates/ovirt-node-iso-image.iso',
+ '--reboot=1'
+ ]
- #First, quietly try to clean any previous problems.
- umount(config, False)
+ rc, out, err = utils.execCmd(cmd, sudo=True, raw=True)
+ if rc != 0:
+ msg = "<BSTRAP component='RHEV_INSTALL'
status='FAIL'/>"
+ else:
+ msg = "<BSTRAP component='RHEV_INSTALL'
status='OK'/>"
- #Now: Try mounting
- fOK = setMountPoint(config)
- if fOK:
- fMounted = True
- fOK = doUpgrade(config)
-
- #Finally, is possible umount current upgrade file.
- if fMounted:
- umount(config) #cleanup, may fail in some cases- device busy.
- except:
- fOK = False
-
- if not fOK:
- msg = "<BSTRAP component='RHEV_INSTALL'
status='FAIL'/>"
- logging.error("<BSTRAP component='RHEV_INSTALL'
status='FAIL'/>")
- else:
- msg = "<BSTRAP component='RHEV_INSTALL'
status='OK'/>"
- logging.debug("<BSTRAP component='RHEV_INSTALL'
status='OK'/>")
- print (msg)
-
- sys.stdout.flush()
- return fOK
+ logging.debug(msg)
+ print(msg)
+ return rc
if __name__ == "__main__":
- sys.exit(not main())
-
+ main()
--
To view, visit
http://gerrit.ovirt.org/28244
To unsubscribe, visit
http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I7b997d70a440545497246d1a19d9671b054a56a5
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Douglas Schilling Landgraf <dougsland(a)redhat.com>