Skip to content

Commit

Permalink
Merge branch 'sysv-http' of https://github.com/nathanolla/bcfg2 into …
Browse files Browse the repository at this point in the history
…maint
  • Loading branch information
solj committed Aug 26, 2014
2 parents 8738109 + d5b3c70 commit 172c31a
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 4 deletions.
23 changes: 22 additions & 1 deletion doc/client/tools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,28 @@ Systemd service support.
SYSV
----

Handles System V Packaging format that is available on Solaris.
Handles `System V Packaging <http://docs.oracle.com/cd/E19683-01/806-7008/index.html>`_ format that is available on Solaris.

.. note::

If the Packages specified in the PackageList are datastream format packages distributed via HTTP, you must specify a simplename attribute. Such packages will be downloaded and installed from a local path.

datastream format over HTTP:

.. code-block:: xml
<PackageList url='http://install/packages' type='sysv' priority='0'>
<Package name='SCbcfg2' version='1.3.4' simplename='bcfg-1.3.4-1' />
</PackageList>
File system format over NFS or local path:

.. code-block:: xml
<PackageList url='/mnt/install/packages' type='sysv' priority='0'>
<Package name='SCbcfg2' version='1.3.4' />
</PackageList>
Upstart
-------
Expand Down
2 changes: 2 additions & 0 deletions doc/development/compat.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ behavior (e.g., :func:`input`) do not cause unexpected side-effects.
+---------------------------------+--------------------------------------------------+---------------------------------------------------------+
| urlparse | :func:`urlparse.urlparse` | :func:`urllib.parse.urlparse` |
+---------------------------------+--------------------------------------------------+---------------------------------------------------------+
| urlretrieve | :func:`urllib.urlretrieve` | :func:`urllib.request.urlretrieve` |
+---------------------------------+--------------------------------------------------+---------------------------------------------------------+
| HTTPBasicAuthHandler | :class:`urllib2.HTTPBasicAuthHandler` | :class:`urllib.request.HTTPBasicAuthHandler` |
+---------------------------------+--------------------------------------------------+---------------------------------------------------------+
| HTTPPasswordMgrWithDefaultRealm | :class:`urllib2.HTTPPasswordMgrWithDefaultRealm` | :class:`urllib.request.HTTPPasswordMgrWithDefaultRealm` |
Expand Down
44 changes: 42 additions & 2 deletions src/lib/Bcfg2/Client/Tools/SYSV.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from Bcfg2.Compat import any # pylint: disable=W0622
import Bcfg2.Client.Tools
import Bcfg2.Client.XML
from Bcfg2.Compat import urlretrieve


# pylint: disable=C0103
noask = '''
Expand Down Expand Up @@ -37,6 +39,8 @@ def __init__(self, logger, setup, config):
# noaskfile needs to live beyond __init__ otherwise file is removed
self.noaskfile = tempfile.NamedTemporaryFile()
self.noaskname = self.noaskfile.name
# for any pkg files downloaded
self.tmpfiles = []
try:
self.noaskfile.write(noask)
# flush admin file contents to disk
Expand All @@ -45,6 +49,42 @@ def __init__(self, logger, setup, config):
self.pkgtool[1])
except: # pylint: disable=W0702
self.pkgtool = (self.pkgtool[0] % "", self.pkgtool[1])
self.origpkgtool = self.pkgtool

def pkgmogrify(self, packages):
""" Take a list of pkg objects, check for a 'simplename' attribute.
If present, insert a _sysv_pkg_path attribute to the package and
download the datastream format SYSV package to a temporary file.
"""
for pkg in packages:
if pkg.get('simplename'):
tmpfile = tempfile.NamedTemporaryFile()
self.tmpfiles.append(tmpfile)
self.logger.info("Downloading %s%s to %s" % (pkg.get('url'),
pkg.get('simplename'), tmpfile.name))
urlretrieve("%s/%s" % (pkg.get('url'), pkg.get('simplename')),
tmpfile.name)
pkg.set('_sysv_pkg_path', tmpfile.name)

def _get_package_command(self, packages):
"""Override the default _get_package_command, replacing the attribute
'url' if '_sysv_pkg_path' if necessary in the returned command
string
"""
if hasattr(self, 'origpkgtool'):
if len(packages) == 1 and '_sysv_pkg_path' in packages[0].keys():
self.pkgtool = (self.pkgtool[0], ('%s %s',
['_sysv_pkg_path', 'name']))
else:
self.pkgtool = self.origpkgtool

pkgcmd = super(SYSV, self)._get_package_command(packages)
self.logger.debug("Calling install command: %s" % pkgcmd)
return pkgcmd

def Install(self, packages, states):
self.pkgmogrify(packages)
super(SYSV, self).Install(packages, states)

def RefreshPackages(self):
"""Refresh memory hashes of packages."""
Expand Down Expand Up @@ -80,8 +120,8 @@ def VerifyPackage(self, entry, modlist):
self.logger.debug("Package %s not installed" %
entry.get("name"))
else:
if (self.setup['quick'] or
entry.attrib.get('verify', 'true') == 'false'):
if self.setup['quick'] or \
entry.attrib.get('verify', 'true') == 'false':
return True
rv = self.cmd.run("/usr/sbin/pkgchk -n %s" % entry.get('name'))
if rv.success:
Expand Down
4 changes: 3 additions & 1 deletion src/lib/Bcfg2/Compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@
# urllib imports
try:
from urllib import quote_plus
from urllib import urlretrieve
from urlparse import urljoin, urlparse
from urllib2 import HTTPBasicAuthHandler, \
HTTPPasswordMgrWithDefaultRealm, build_opener, install_opener, \
urlopen, HTTPError, URLError
except ImportError:
from urllib.parse import urljoin, urlparse, quote_plus
from urllib.request import HTTPBasicAuthHandler, \
HTTPPasswordMgrWithDefaultRealm, build_opener, install_opener, urlopen
HTTPPasswordMgrWithDefaultRealm, build_opener, install_opener, \
urlopen, urlretrieve
from urllib.error import HTTPError, URLError

try:
Expand Down

0 comments on commit 172c31a

Please sign in to comment.