Skip to content

Commit

Permalink
move rpm/yum functions to pkg_mgmt. rockstor#695
Browse files Browse the repository at this point in the history
  • Loading branch information
schakrava committed Aug 20, 2015
1 parent 8a5a768 commit f9a0ea7
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 62 deletions.
2 changes: 1 addition & 1 deletion src/rockstor/smart_manager/data_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@
<h4>Here are the changes with this update</h4>
<ul>
<% _.each(changeList, function(item) { %>
<li><h4><%= item %></h4></li>
<% if (item == '') { %>
<br>
<% } else { %>
<li><h4><%= item %></h4></li>
<% } %>
<% }); %>
</ul>
<div class="row">
Expand Down
6 changes: 3 additions & 3 deletions src/rockstor/storageadmin/views/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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__)

Expand Down
57 changes: 0 additions & 57 deletions src/rockstor/system/osi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down
64 changes: 64 additions & 0 deletions src/rockstor/system/pkg_mgmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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

0 comments on commit f9a0ea7

Please sign in to comment.