diff --git a/src/rockstor/smart_manager/data_collector.py b/src/rockstor/smart_manager/data_collector.py index 712705432..7803636f4 100644 --- a/src/rockstor/smart_manager/data_collector.py +++ b/src/rockstor/smart_manager/data_collector.py @@ -17,6 +17,7 @@ from smart_manager.models import CPUMetric from system.services import service_status from cli.rest_util import api_call +from system.pkg_mgmt import update_check import logging logger = logging.getLogger(__name__) @@ -352,7 +353,6 @@ def update_storage_state(self): logger.error('%s. exception: %s' % (r['error'], e.__str__())) def update_check(self): - from system.osi import update_check uinfo = update_check() self.emit('sysinfo:software-update', { 'data': uinfo, diff --git a/src/rockstor/storageadmin/static/storageadmin/js/templates/update/version_info.jst b/src/rockstor/storageadmin/static/storageadmin/js/templates/update/version_info.jst index 48b3a510c..ab2174de8 100644 --- a/src/rockstor/storageadmin/static/storageadmin/js/templates/update/version_info.jst +++ b/src/rockstor/storageadmin/static/storageadmin/js/templates/update/version_info.jst @@ -9,7 +9,11 @@

Here are the changes with this update

diff --git a/src/rockstor/storageadmin/views/command.py b/src/rockstor/storageadmin/views/command.py index 1b1222cb6..fff699025 100644 --- a/src/rockstor/storageadmin/views/command.py +++ b/src/rockstor/storageadmin/views/command.py @@ -26,8 +26,7 @@ SessionAuthentication) from storageadmin.auth import DigestAuthentication from rest_framework.permissions import IsAuthenticated -from system.osi import (uptime, refresh_nfs_exports, update_check, - update_run, current_version, kernel_info) +from system.osi import (uptime, refresh_nfs_exports, kernel_info) from fs.btrfs import (mount_share, device_scan, mount_root, qgroup_create, get_pool_info, pool_raid, pool_usage, shares_info, share_usage, snaps_info) @@ -44,7 +43,8 @@ from django.db import transaction from share_helpers import sftp_snap_toggle from oauth2_provider.ext.rest_framework import OAuth2Authentication -from system.pkg_mgmt import auto_update +from system.pkg_mgmt import (auto_update, current_version, update_check, + update_run) import logging logger = logging.getLogger(__name__) diff --git a/src/rockstor/system/osi.py b/src/rockstor/system/osi.py index 6931ac813..d2cc65a25 100644 --- a/src/rockstor/system/osi.py +++ b/src/rockstor/system/osi.py @@ -44,10 +44,8 @@ IFDOWN = '/sbin/ifdown' ROUTE = '/sbin/route' SYSTEMCTL = '/usr/bin/systemctl' -YUM = '/usr/bin/yum' AT = '/usr/bin/at' DEFAULT_MNT_DIR = '/mnt2/' -RPM = '/usr/bin/rpm' SHUTDOWN = '/usr/sbin/shutdown' GRUBBY = '/usr/sbin/grubby' CAT = '/usr/bin/cat' @@ -389,61 +387,6 @@ def update_issue(ipaddr): ifo.write(msg) -def current_version(): - out, err, rc = run_command([RPM, '-qi', 'rockstor'], throw=False) - if (rc != 0): - return '0.0-0' - return ('%s-%s' % (out[1].split(':')[-1].strip(), - out[2].split(':')[-1].strip())) - - -def update_check(): - out, err, rc = run_command([YUM, 'update', 'rockstor', '--changelog', - '--assumeno'], throw=False) - if (rc == 1): - # parse the output for the following information - # 1. what's the latest update version? - # 2. what are the updates? - updates = [] - cur_version = None - version = None - for i in range(len(out)): - if (re.match('---> Package rockstor.* updated', out[i]) - is not None): - cur_version = out[i].split()[3].split(':')[1] - if (re.match('---> Package rockstor.* be an update', out[i]) - is not None): - version = out[i].split()[3].split(':')[1] - if (re.match('ChangeLog for: ', out[i]) is not None): - i = i + 1 - while True: - if (len(out) > i): - if (out[i + 1] == ''): - break - updates.append(out[i + 1]) - i = i + 1 - if (version is None): - version = cur_version - return (cur_version, version, updates) - # no update available - out, err, rc = run_command([YUM, 'info', 'installed', 'rockstor']) - version = ('%s-%s' % (out[4].split(': ')[1], out[5].split(': ')[1])) - return (version, version, []) - - -def update_run(): - fh, npath = mkstemp() - with open(npath, 'w') as atfo: - atfo.write('%s stop rockstor\n' % SYSTEMCTL) - atfo.write('%s --setopt=timeout=600 -y update\n' % YUM) - atfo.write('%s start rockstor\n' % SYSTEMCTL) - atfo.write('/bin/rm -f %s\n' % npath) - run_command([SYSTEMCTL, 'start', 'atd']) - out, err, rc = run_command([AT, '-f', npath, 'now + 1 minutes']) - time.sleep(120) - return out, err, rc - - def sethostname(ip, hostname): """ edit /etc/hosts file and /etc/hostname diff --git a/src/rockstor/system/pkg_mgmt.py b/src/rockstor/system/pkg_mgmt.py index 9dcd2ae3b..d98d717e1 100644 --- a/src/rockstor/system/pkg_mgmt.py +++ b/src/rockstor/system/pkg_mgmt.py @@ -23,8 +23,10 @@ from osi import run_command from services import systemctl import shutil +from datetime import (datetime, timedelta) YUM = '/usr/bin/yum' +RPM = '/usr/bin/rpm' def install_pkg(name): @@ -55,3 +57,65 @@ def auto_update(enable=True): else: systemctl(service, 'stop') systemctl(service, 'disable') + +def current_version(): + out, err, rc = run_command([RPM, '-qi', 'rockstor'], throw=False) + if (rc != 0): + return '0.0-0' + return ('%s-%s' % (out[1].split(':')[-1].strip(), + out[2].split(':')[-1].strip())) + +def rpm_build_info(pkg): + version = None + date = None + o, e, rc = run_command([RPM, '-qi', pkg]) + for l in o: + if (re.match('Build Date', l) is not None): + #eg: Build Date : Tue 11 Aug 2015 02:25:24 PM PDT + #we return 2015-Aug-11 + dfields = l.strip().split() + dstr = ' '.join(dfields[3:7]) + bdate = datetime.strptime(dstr, '%a %d %b %Y') + bdate += timedelta(days=1) + date = bdate.strftime('%Y-%b-%d') + if (re.match('Version ', l) is not None): + version = l.strip().split()[2] + if (re.match('Release ', l) is not None): + version = '%s-%s' % (version, l.strip().split()[2]) + return (version, date) + +def update_check(): + pkg = 'rockstor' + version, date = rpm_build_info(pkg) + o, e, rc = run_command([YUM, 'changelog', date, pkg]) + log = False + available = False + new_version = None + updates = [] + for l in o: + if (re.search('Available Packages', l) is not None): + available = True + if (not available): + continue + if (new_version is None and (re.match('rockstor-', l) is not None)): + new_version = l.split()[0].split('rockstor-')[1].split('.x86_64')[0] + if (log is True): + updates.append(l) + if (len(l.strip()) == 0): + log = False + if (re.match('\* ', l) is not None): + log = True + return (version, new_version, updates) + + +def update_run(): + fh, npath = mkstemp() + with open(npath, 'w') as atfo: + atfo.write('%s stop rockstor\n' % SYSTEMCTL) + atfo.write('%s --setopt=timeout=600 -y update\n' % YUM) + atfo.write('%s start rockstor\n' % SYSTEMCTL) + atfo.write('/bin/rm -f %s\n' % npath) + run_command([SYSTEMCTL, 'start', 'atd']) + out, err, rc = run_command([AT, '-f', npath, 'now + 1 minutes']) + time.sleep(120) + return out, err, rc