Skip to content

Commit

Permalink
add non legacy distro aware repo configuration #1991
Browse files Browse the repository at this point in the history
Adds distro awareness to the existing repository configuration to
encompass our next generation openSUSE Leap and Tumbleweed distribution
bases. The repository structure assumed is as proposed/detailed in the
associated issue text.

Summary:
- Add disto aware repo configuration for openSUSE Leap and Tumbleweed
(next gen Rockstor).
- Fix Rockstor NG source to rpm install transition.
- Fix compliance with unconfigured repo. Allows for updates in only one
channel i.e. preserving the user option to change the update
subscription channel when defaulting to, or having selected, a
deprecated or yet to be configured update channel.
- Fix unintended repository file permissions: auto resolves (post patch)
by visiting “Software Update” page.
- Fix Rockstor NG version display for source installs.
- Fix missing yum-changelog package dependency: package name tested with
yum on legacy and NG distros.
- For dev/source installs (no rockstor rpm installed) list entire
changelog of available rpm. Prior use of ‘None’ for date parameter was
silently interpreted as ‘all’ in older (legacy) yum-changelog but caused
command exceptions in newer openSUSE versions of the same. Manual
concurs with new use.
- Trivial code comment addition and typo.
  • Loading branch information
phillxnet committed Nov 21, 2018
1 parent 33917f1 commit 5de34b0
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 10 deletions.
2 changes: 1 addition & 1 deletion base-buildout.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ command =
postgresql-server postgresql-devel kernel-ml btrfs-progs rsync \
nfs-utils avahi netatalk smartmontools net-tools sos hdparm \
postfix cyrus-sasl-plain yum-cron nano usbutils pciutils shellinabox \
epel-release cryptsetup docker-ce python-distro
epel-release cryptsetup docker-ce python-distro yum-changelog

[rpm-deps-nut]
recipe = plone.recipe.command
Expand Down
2 changes: 1 addition & 1 deletion src/rockstor/storageadmin/views/update_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def get_queryset(self, *args, **kwargs):
return UpdateSubscription.objects.all()

def _toggle_repos(self, on='stable', off='testing', password=None):
# toggle between testing and stabel repos
# toggle between testing and stable repos
ncd = settings.UPDATE_CHANNELS[on]
fcd = settings.UPDATE_CHANNELS[off]
try:
Expand Down
47 changes: 39 additions & 8 deletions src/rockstor/system/pkg_mgmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import os
import re
import stat
from tempfile import mkstemp
from osi import run_command
from services import systemctl
Expand All @@ -27,6 +28,7 @@
import requests
from django.conf import settings
from system.exceptions import CommandException
import distro
import logging

logger = logging.getLogger(__name__)
Expand All @@ -35,7 +37,7 @@
RPM = '/usr/bin/rpm'
SYSTEMCTL = '/usr/bin/systemctl'
AT = '/usr/bin/at'
YCFILE = '/etc/yum/yum-cron.conf'
YCFILE = '/etc/yum/yum-cron.conf' # Doesn't exist in openSUSE


def install_pkg(name):
Expand Down Expand Up @@ -128,23 +130,36 @@ def rpm_build_info(pkg):


def switch_repo(subscription, on=True):
yum_file = '/etc/yum.repos.d/Rockstor-%s.repo' % subscription.name
repos_dir = '/etc/yum.repos.d'
yum_file = '{}/Rockstor-{}.repo'.format(repos_dir, subscription.name)
# Historically our base subscription url denotes our CentOS rpm repo.
subscription_distro_url = subscription.url
distro_id = distro.id()
if distro_id == 'opensuse-leap':
subscription_distro_url += '/leap/{}'.format(distro.version())
elif distro_id == 'opensuse-tumbleweed':
subscription_distro_url += '/tumbleweed'
# Check if dir /etc/yum.repos.d exists and if not create.
if not os.path.isdir(repos_dir):
# Can use os.makedirs(path) if intermediate levels also don't exist.
os.mkdir(repos_dir, )
if (on):
with open(yum_file, 'w') as rfo:
rfo.write('[Rockstor-%s]\n' % subscription.name)
rfo.write('name=%s\n' % subscription.description)
if (subscription.password is not None):
rfo.write('baseurl=http://%s:%s@%s\n' %
(subscription.appliance.uuid, subscription.password,
subscription.url))
subscription_distro_url))
else:
rfo.write('baseurl=http://%s\n' % subscription.url)
rfo.write('baseurl=http://%s\n' % subscription_distro_url)
rfo.write('enabled=1\n')
rfo.write('gpgcheck=1\n')
rfo.write('gpgkey=file://%sconf/ROCKSTOR-GPG-KEY\n'
% settings.ROOT_DIR)
rfo.write('metadata_expire=1m\n')
os.chmod(yum_file, 600)
rfo.write('metadata_expire=1h\n')
# Set file to rw- --- --- (600) via stat constants.
os.chmod(yum_file, stat.S_IRUSR | stat.S_IWUSR)
else:
if (os.path.exists(yum_file)):
os.remove(yum_file)
Expand Down Expand Up @@ -176,11 +191,27 @@ def update_check(subscription=None):

pkg = 'rockstor'
version, date = rpm_build_info(pkg)
o, e, rc = run_command([YUM, 'changelog', date, pkg])
if date is None:
# None date signifies no rpm installed so list all changelog entries.
date = 'all'
log = False
available = False
new_version = None
updates = []
try:
o, e, rc = run_command([YUM, 'changelog', date, pkg])
except CommandException as e:
# Catch as yet unconfigured repos ie Leap 15.1: error log accordingly.
# Avoids breaking current version display and update channel selection.
emsg = 'Error\\: Cannot retrieve repository metadata \\(repomd.xml\\)'
if re.match(emsg, e.err[-2]) is not None:
logger.error('Rockstor repo for distro.id ({}) version ({}) may '
'not exist: pending or deprecated.\nReceived: ({}).'
.format(distro.id(), distro.version(), e.err))
new_version = version # Explicitly set (flag) for code clarity.
return version, new_version, updates
# otherwise we raise an exception as normal.
raise e
for l in o:
if (re.search('Available Packages', l) is not None):
available = True
Expand All @@ -206,7 +237,7 @@ def update_check(subscription=None):
if (re.search('rockstor.x86_64', l) is not None):
new_version = l.strip().split()[3].split(':')[1]

return (version, new_version, updates)
return version, new_version, updates


def update_run(subscription=None, yum_update=False):
Expand Down

0 comments on commit 5de34b0

Please sign in to comment.