summaryrefslogtreecommitdiffstats
path: root/src/lib/Bcfg2/Server
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/Bcfg2/Server')
-rw-r--r--src/lib/Bcfg2/Server/Admin.py21
-rw-r--r--src/lib/Bcfg2/Server/BuiltinCore.py27
-rw-r--r--src/lib/Bcfg2/Server/Core.py8
-rw-r--r--src/lib/Bcfg2/Server/FileMonitor/__init__.py2
-rw-r--r--src/lib/Bcfg2/Server/Info.py37
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Packages/Apt.py3
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Packages/Source.py19
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Packages/YumHelper.py4
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Packages/__init__.py1
-rw-r--r--src/lib/Bcfg2/Server/Plugins/Svn.py18
-rw-r--r--src/lib/Bcfg2/Server/models.py30
11 files changed, 85 insertions, 85 deletions
diff --git a/src/lib/Bcfg2/Server/Admin.py b/src/lib/Bcfg2/Server/Admin.py
index 0807fb2b0..ef7741880 100644
--- a/src/lib/Bcfg2/Server/Admin.py
+++ b/src/lib/Bcfg2/Server/Admin.py
@@ -439,15 +439,6 @@ class Compare(AdminCmd):
print("")
-class Help(AdminCmd, Bcfg2.Options.HelpCommand):
- """ Get help on a specific subcommand """
- def command_registry(self):
- return CLI.commands
-
- def run(self, setup):
- Bcfg2.Options.HelpCommand.run(self, setup)
-
-
class Init(AdminCmd):
"""Interactively initialize a new repository."""
@@ -1194,16 +1185,20 @@ class Xcmd(_ProxyAdminCmd):
class CLI(Bcfg2.Options.CommandRegistry):
""" CLI class for bcfg2-admin """
+
def __init__(self):
Bcfg2.Options.CommandRegistry.__init__(self)
- Bcfg2.Options.register_commands(self.__class__, globals().values(),
- parent=AdminCmd)
+ self.register_commands(globals().values(), parent=AdminCmd)
parser = Bcfg2.Options.get_parser(
description="Manage a running Bcfg2 server",
components=[self])
+ parser.add_options(self.subcommand_options)
parser.parse()
def run(self):
""" Run bcfg2-admin """
- self.commands[Bcfg2.Options.setup.subcommand].setup()
- return self.runcommand()
+ try:
+ self.commands[Bcfg2.Options.setup.subcommand].setup()
+ return self.runcommand()
+ finally:
+ self.shutdown()
diff --git a/src/lib/Bcfg2/Server/BuiltinCore.py b/src/lib/Bcfg2/Server/BuiltinCore.py
index 769addf55..e138c57e4 100644
--- a/src/lib/Bcfg2/Server/BuiltinCore.py
+++ b/src/lib/Bcfg2/Server/BuiltinCore.py
@@ -1,5 +1,6 @@
""" The core of the builtin Bcfg2 server. """
+import os
import sys
import time
import socket
@@ -85,20 +86,30 @@ class BuiltinCore(NetworkCore):
def _daemonize(self):
""" Open :attr:`context` to drop privileges, write the PID
file, and daemonize the server core. """
+ # Attempt to ensure lockfile is able to be created and not stale
try:
- self.context.open()
- self.logger.info("%s daemonized" % self.name)
- return True
+ self.context.pidfile.acquire()
except LockFailed:
err = sys.exc_info()[1]
self.logger.error("Failed to daemonize %s: %s" % (self.name, err))
return False
except LockTimeout:
- err = sys.exc_info()[1]
- self.logger.error("Failed to daemonize %s: Failed to acquire lock "
- "on %s" % (self.name,
- Bcfg2.Options.setup.daemon))
- return False
+ try: # attempt to break the lock
+ os.kill(self.context.pidfile.read_pid(), 0)
+ except (OSError, TypeError): # No process with locked PID
+ self.context.pidfile.break_lock()
+ else:
+ err = sys.exc_info()[1]
+ self.logger.error("Failed to daemonize %s: Failed to acquire"
+ "lock on %s" % (self.name,
+ Bcfg2.Options.setup.daemon))
+ return False
+ else:
+ self.context.pidfile.release()
+
+ self.context.open()
+ self.logger.info("%s daemonized" % self.name)
+ return True
def _run(self):
""" Create :attr:`server` to start the server listening. """
diff --git a/src/lib/Bcfg2/Server/Core.py b/src/lib/Bcfg2/Server/Core.py
index 892f2832a..bc305e47a 100644
--- a/src/lib/Bcfg2/Server/Core.py
+++ b/src/lib/Bcfg2/Server/Core.py
@@ -84,7 +84,7 @@ def close_db_connection(func):
if self._database_available: # pylint: disable=W0212
from django import db
self.logger.debug("%s: Closing database connection" %
- threading.current_thread().name)
+ threading.current_thread().getName())
db.close_connection()
return rv
@@ -783,13 +783,13 @@ class Core(object):
for plug in self.plugins_by_type(Threaded):
plug.start_threads()
+
+ self.block_for_fam_events()
+ self._block()
except:
self.shutdown()
raise
- self.block_for_fam_events()
- self._block()
-
def _run(self):
""" Start up the server; this method should return
immediately. This must be overridden by a core
diff --git a/src/lib/Bcfg2/Server/FileMonitor/__init__.py b/src/lib/Bcfg2/Server/FileMonitor/__init__.py
index d0fd70c5c..8e0dd2efe 100644
--- a/src/lib/Bcfg2/Server/FileMonitor/__init__.py
+++ b/src/lib/Bcfg2/Server/FileMonitor/__init__.py
@@ -238,6 +238,8 @@ class FileMonitor(Debuggable):
self.handles[event.requestID]))
try:
self.handles[event.requestID].HandleEvent(event)
+ except KeyboardInterrupt:
+ raise
except: # pylint: disable=W0702
err = sys.exc_info()[1]
self.logger.error("Error in handling of event %s for %s: %s" %
diff --git a/src/lib/Bcfg2/Server/Info.py b/src/lib/Bcfg2/Server/Info.py
index a5136f01d..6af561089 100644
--- a/src/lib/Bcfg2/Server/Info.py
+++ b/src/lib/Bcfg2/Server/Info.py
@@ -123,15 +123,6 @@ class InfoCmd(Bcfg2.Options.Subcommand): # pylint: disable=W0223
list(self.core.metadata.groups.keys()))
-class Help(InfoCmd, Bcfg2.Options.HelpCommand):
- """ Get help on a specific subcommand """
- def command_registry(self):
- return self.core.commands
-
- def run(self, setup):
- Bcfg2.Options.HelpCommand.run(self, setup)
-
-
class Debug(InfoCmd):
""" Shell out to a Python interpreter """
interpreters, default_interpreter = load_interpreters()
@@ -805,15 +796,12 @@ if HAS_PROFILE:
display_trace(prof)
-class InfoCore(cmd.Cmd,
- Bcfg2.Server.Core.Core,
- Bcfg2.Options.CommandRegistry):
+class InfoCore(cmd.Cmd, Bcfg2.Server.Core.Core):
"""Main class for bcfg2-info."""
def __init__(self):
cmd.Cmd.__init__(self)
Bcfg2.Server.Core.Core.__init__(self)
- Bcfg2.Options.CommandRegistry.__init__(self)
self.prompt = 'bcfg2-info> '
def get_locals(self):
@@ -849,20 +837,20 @@ class InfoCore(cmd.Cmd,
pass
def shutdown(self):
- Bcfg2.Options.CommandRegistry.shutdown(self)
Bcfg2.Server.Core.Core.shutdown(self)
-class CLI(object):
+class CLI(Bcfg2.Options.CommandRegistry):
""" The bcfg2-info CLI """
options = [Bcfg2.Options.BooleanOption("-p", "--profile", help="Profile")]
def __init__(self):
- Bcfg2.Options.register_commands(InfoCore, globals().values(),
- parent=InfoCmd)
+ Bcfg2.Options.CommandRegistry.__init__(self)
+ self.register_commands(globals().values(), parent=InfoCmd)
parser = Bcfg2.Options.get_parser(
description="Inspect a running Bcfg2 server",
components=[self, InfoCore])
+ parser.add_options(self.subcommand_options)
parser.parse()
if Bcfg2.Options.setup.profile and HAS_PROFILE:
@@ -874,11 +862,18 @@ class CLI(object):
print("Profiling functionality not available.")
self.core = InfoCore()
- for command in self.core.commands.values():
+ for command in self.commands.values():
command.core = self.core
def run(self):
""" Run bcfg2-info """
- if Bcfg2.Options.setup.subcommand != 'help':
- self.core.run()
- return self.core.runcommand()
+ try:
+ if Bcfg2.Options.setup.subcommand != 'help':
+ self.core.run()
+ return self.runcommand()
+ finally:
+ self.shutdown()
+
+ def shutdown(self):
+ Bcfg2.Options.CommandRegistry.shutdown(self)
+ self.core.shutdown()
diff --git a/src/lib/Bcfg2/Server/Plugins/Packages/Apt.py b/src/lib/Bcfg2/Server/Plugins/Packages/Apt.py
index 3d5c68e3f..cfabd8457 100644
--- a/src/lib/Bcfg2/Server/Plugins/Packages/Apt.py
+++ b/src/lib/Bcfg2/Server/Plugins/Packages/Apt.py
@@ -102,7 +102,8 @@ class AptSource(Source):
bdeps[barch][pkgname] = []
brecs[barch][pkgname] = []
elif words[0] == 'Essential' and self.essential:
- self.essentialpkgs.add(pkgname)
+ if words[1].strip() == 'yes':
+ self.essentialpkgs.add(pkgname)
elif words[0] in ['Depends', 'Pre-Depends', 'Recommends']:
vindex = 0
for dep in words[1].split(','):
diff --git a/src/lib/Bcfg2/Server/Plugins/Packages/Source.py b/src/lib/Bcfg2/Server/Plugins/Packages/Source.py
index 24db2963d..67ada2399 100644
--- a/src/lib/Bcfg2/Server/Plugins/Packages/Source.py
+++ b/src/lib/Bcfg2/Server/Plugins/Packages/Source.py
@@ -199,6 +199,9 @@ class Source(Debuggable): # pylint: disable=R0902
#: The "version" attribute from :attr:`xsource`
self.version = xsource.get('version', '')
+ #: The "name" attribute from :attr:`xsource`
+ self.name = xsource.get('name', None)
+
#: A list of predicates that are used to determine if this
#: source applies to a given
#: :class:`Bcfg2.Server.Plugins.Metadata.ClientMetadata`
@@ -274,11 +277,11 @@ class Source(Debuggable): # pylint: disable=R0902
for arch in self.arches:
if self.url:
usettings = [dict(version=self.version, component=comp,
- arch=arch)
+ arch=arch, debsrc=self.debsrc)
for comp in self.components]
else: # rawurl given
usettings = [dict(version=self.version, component=None,
- arch=arch)]
+ arch=arch, debsrc=self.debsrc)]
for setting in usettings:
if not self.rawurl:
@@ -286,6 +289,7 @@ class Source(Debuggable): # pylint: disable=R0902
else:
setting['baseurl'] = self.rawurl
setting['url'] = baseurl % setting
+ setting['name'] = self.get_repo_name(setting)
self.url_map.extend(usettings)
@property
@@ -353,7 +357,7 @@ class Source(Debuggable): # pylint: disable=R0902
if os.path.exists(self.cachefile):
try:
self.load_state()
- except:
+ except (OSError, cPickle.UnpicklingError):
err = sys.exc_info()[1]
self.logger.error("Packages: Cachefile %s load failed: %s"
% (self.cachefile, err))
@@ -388,8 +392,10 @@ class Source(Debuggable): # pylint: disable=R0902
doing other operations that require repository names. This
function tries several approaches:
- #. First, if the map contains a ``component`` key, use that as
- the name.
+ #. First, if the source element containts a ``name`` attribute,
+ use that as the name.
+ #. If the map contains a ``component`` key, use that as the
+ name.
#. If not, then try to match the repository URL against
:attr:`Bcfg2.Server.Plugins.Packages.Source.REPO_RE`. If
that succeeds, use the first matched group; additionally,
@@ -419,6 +425,9 @@ class Source(Debuggable): # pylint: disable=R0902
:type url_map: dict
:returns: string - the name of the repository.
"""
+ if self.name:
+ return self.name
+
if url_map['component']:
rname = url_map['component']
else:
diff --git a/src/lib/Bcfg2/Server/Plugins/Packages/YumHelper.py b/src/lib/Bcfg2/Server/Plugins/Packages/YumHelper.py
index 48304d26e..f26d6ba18 100644
--- a/src/lib/Bcfg2/Server/Plugins/Packages/YumHelper.py
+++ b/src/lib/Bcfg2/Server/Plugins/Packages/YumHelper.py
@@ -383,10 +383,10 @@ class CLI(Bcfg2.Options.CommandRegistry):
def __init__(self):
Bcfg2.Options.CommandRegistry.__init__(self)
- Bcfg2.Options.register_commands(self.__class__, globals().values(),
- parent=HelperSubcommand)
+ self.register_commands(globals().values(), parent=HelperSubcommand)
parser = Bcfg2.Options.get_parser("Bcfg2 yum helper",
components=[self])
+ parser.add_options(self.subcommand_options)
parser.parse()
self.logger = logging.getLogger(parser.prog)
diff --git a/src/lib/Bcfg2/Server/Plugins/Packages/__init__.py b/src/lib/Bcfg2/Server/Plugins/Packages/__init__.py
index d11ac60fe..cb533f4f1 100644
--- a/src/lib/Bcfg2/Server/Plugins/Packages/__init__.py
+++ b/src/lib/Bcfg2/Server/Plugins/Packages/__init__.py
@@ -33,6 +33,7 @@ class PackagesBackendAction(Bcfg2.Options.ComponentAction):
""" ComponentAction to load Packages backends """
bases = ['Bcfg2.Server.Plugins.Packages']
module = True
+ fail_silently = True
class OnDemandDict(MutableMapping):
diff --git a/src/lib/Bcfg2/Server/Plugins/Svn.py b/src/lib/Bcfg2/Server/Plugins/Svn.py
index b752650f0..2ca518e53 100644
--- a/src/lib/Bcfg2/Server/Plugins/Svn.py
+++ b/src/lib/Bcfg2/Server/Plugins/Svn.py
@@ -18,12 +18,6 @@ class Svn(Bcfg2.Server.Plugin.Version):
"""Svn is a version plugin for dealing with Bcfg2 repos."""
options = Bcfg2.Server.Plugin.Version.options + [
Bcfg2.Options.Option(
- cf=("svn", "conflict_resolution"), dest="svn_conflict_resolution",
- type=lambda v: v.replace("-", "_"),
- choices=dir(pysvn.wc_conflict_choice), # pylint: disable=E1101
- default=pysvn.wc_conflict_choice.postpone, # pylint: disable=E1101
- help="SVN conflict resolution method"),
- Bcfg2.Options.Option(
cf=("svn", "user"), dest="svn_user", help="SVN username"),
Bcfg2.Options.Option(
cf=("svn", "password"), dest="svn_password", help="SVN password"),
@@ -31,6 +25,18 @@ class Svn(Bcfg2.Server.Plugin.Version):
cf=("svn", "always_trust"), dest="svn_trust_ssl",
help="Always trust SSL certs from SVN server")]
+ if HAS_SVN:
+ options.append(
+ Bcfg2.Options.Option(
+ cf=("svn", "conflict_resolution"),
+ dest="svn_conflict_resolution",
+ type=lambda v: v.replace("-", "_"),
+ # pylint: disable=E1101
+ choices=dir(pysvn.wc_conflict_choice),
+ default=pysvn.wc_conflict_choice.postpone,
+ # pylint: enable=E1101
+ help="SVN conflict resolution method"))
+
__author__ = 'bcfg-dev@mcs.anl.gov'
__vcs_metadata_path__ = ".svn"
if HAS_SVN:
diff --git a/src/lib/Bcfg2/Server/models.py b/src/lib/Bcfg2/Server/models.py
index 7150c245a..8d6642a25 100644
--- a/src/lib/Bcfg2/Server/models.py
+++ b/src/lib/Bcfg2/Server/models.py
@@ -4,39 +4,19 @@ import sys
import logging
import Bcfg2.Options
import Bcfg2.Server.Plugins
-from Bcfg2.Compat import walk_packages
-LOGGER = logging.getLogger('Bcfg2.Server.models')
+LOGGER = logging.getLogger(__name__)
MODELS = []
-def _get_all_plugins():
- rv = []
- for submodule in walk_packages(path=Bcfg2.Server.Plugins.__path__,
- prefix="Bcfg2.Server.Plugins."):
- module = submodule[1].rsplit('.', 1)[-1]
- if submodule[1] == "Bcfg2.Server.Plugins.%s" % module:
- # we only include direct children of
- # Bcfg2.Server.Plugins -- e.g., all_plugins should
- # include Bcfg2.Server.Plugins.Cfg, but not
- # Bcfg2.Server.Plugins.Cfg.CfgInfoXML
- rv.append(module)
- return rv
-
-
-_ALL_PLUGINS = _get_all_plugins()
-
-
class _OptionContainer(object):
+ """Options for Bcfg2 database models."""
+
# we want to provide a different default plugin list --
# namely, _all_ plugins, so that the database is guaranteed to
# work, even if /etc/bcfg2.conf isn't set up properly
- options = [
- Bcfg2.Options.Option(
- cf=('server', 'plugins'), type=Bcfg2.Options.Types.comma_list,
- default=_ALL_PLUGINS, dest="models_plugins",
- action=Bcfg2.Options.PluginsAction)]
+ options = [Bcfg2.Options.Common.plugins]
@staticmethod
def options_parsed_hook():
@@ -58,7 +38,7 @@ def load_models(plugins=None):
global MODELS
if not plugins:
- plugins = Bcfg2.Options.setup.models_plugins
+ plugins = Bcfg2.Options.setup.plugins
if MODELS:
# load_models() has been called once, so first unload all of