summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmit Saha <asaha@redhat.com>2014-06-21 23:57:15 +1000
committerAmit Saha <asaha@redhat.com>2014-07-15 10:04:05 +1000
commitbecffc3b151bfc37d207cee6fe790d5fe73ff877 (patch)
tree378386bc7cb3041127a25658e16c64d5d0c3c567
parentd83caddcb20053e2ef4ce3450c87693342360c84 (diff)
Server tools should display a helpful error message when it fails to
read the server configuration due to insufficient permission Bug: 1111491 Change-Id: I00baef8967c66946f3c6a166429b5f61cc3e5636
-rw-r--r--Server/bkr/server/tools/beakerd.py4
-rw-r--r--Server/bkr/server/tools/create_kickstart.py4
-rwxr-xr-xServer/bkr/server/tools/init.py4
-rw-r--r--Server/bkr/server/tools/ipxe_image.py5
-rwxr-xr-xServer/bkr/server/tools/log_delete.py5
-rw-r--r--Server/bkr/server/tools/nag_email.py4
-rwxr-xr-xServer/bkr/server/tools/product_update.py4
-rw-r--r--Server/bkr/server/tools/refresh_ldap.py4
-rwxr-xr-xServer/bkr/server/tools/repo_update.py4
-rw-r--r--Server/bkr/server/util.py9
-rw-r--r--documentation/admin-guide/man/beaker-create-kickstart.rst4
11 files changed, 31 insertions, 20 deletions
diff --git a/Server/bkr/server/tools/beakerd.py b/Server/bkr/server/tools/beakerd.py
index 4350143..55c9b0f 100644
--- a/Server/bkr/server/tools/beakerd.py
+++ b/Server/bkr/server/tools/beakerd.py
@@ -27,7 +27,7 @@ from bkr.server.model import (Job, RecipeSet, Recipe, MachineRecipe,
SystemAccessPolicy, SystemPermission, ConfigItem)
from bkr.server.model.scheduler import machine_guest_map
from bkr.server.needpropertyxml import XmlHost
-from bkr.server.util import load_config, log_traceback
+from bkr.server.util import load_config_or_exit, log_traceback
from bkr.server.recipetasks import RecipeTasks
from turbogears.database import session
from turbogears import config
@@ -833,7 +833,7 @@ def main():
parser = get_parser()
opts, args = parser.parse_args()
- load_config(opts.configfile)
+ load_config_or_exit(opts.configfile)
signal.signal(signal.SIGINT, sigterm_handler)
signal.signal(signal.SIGTERM, sigterm_handler)
diff --git a/Server/bkr/server/tools/create_kickstart.py b/Server/bkr/server/tools/create_kickstart.py
index cf1fcf8..fbede45 100644
--- a/Server/bkr/server/tools/create_kickstart.py
+++ b/Server/bkr/server/tools/create_kickstart.py
@@ -10,7 +10,7 @@ from turbogears.database import session
from sqlalchemy.orm.exc import NoResultFound
from bkr.common import __version__
from bkr.server.model import DistroTree, System, User, Recipe
-from bkr.server.util import load_config
+from bkr.server.util import load_config_or_exit
from bkr.server.installopts import InstallOptions
from bkr.server.kickstart import generate_kickstart, template_env, add_to_template_searchpath
@@ -49,7 +49,7 @@ def main(*args):
elif not options.system:
parser.error('Must specify a system when not specifying a recipe')
- load_config()
+ load_config_or_exit()
with session.begin():
user = User.by_user_name(options.user)
ks_appends = None
diff --git a/Server/bkr/server/tools/init.py b/Server/bkr/server/tools/init.py
index b6d80d0..b1af0fb 100755
--- a/Server/bkr/server/tools/init.py
+++ b/Server/bkr/server/tools/init.py
@@ -18,7 +18,7 @@ from sqlalchemy.orm.exc import NoResultFound
from bkr.log import log_to_stream
from bkr.server.model import (User, Group, Permission, Hypervisor, KernelType,
Arch, PowerType, Key, Response, RetentionTag, ConfigItem, UserGroup)
-from bkr.server.util import load_config
+from bkr.server.util import load_config_or_exit
from turbogears.database import session
from os.path import dirname, exists, join
from os import getcwd
@@ -208,7 +208,7 @@ def get_parser():
def main():
parser = get_parser()
opts, args = parser.parse_args()
- load_config(opts.configfile)
+ load_config_or_exit(opts.configfile)
log_to_stream(sys.stderr)
init_db(user_name=opts.user_name, password=opts.password,
user_display_name=opts.display_name,
diff --git a/Server/bkr/server/tools/ipxe_image.py b/Server/bkr/server/tools/ipxe_image.py
index 459b374..889eded 100644
--- a/Server/bkr/server/tools/ipxe_image.py
+++ b/Server/bkr/server/tools/ipxe_image.py
@@ -25,7 +25,7 @@ import keystoneclient.v2_0.client
import glanceclient
from turbogears import config
from bkr.log import log_to_stream
-from bkr.server.util import load_config, absolute_url
+from bkr.server.util import load_config_or_exit, absolute_url
from bkr.server.model import session, OpenStackRegion
log = logging.getLogger(__name__)
@@ -89,8 +89,7 @@ def main():
parser.add_option('--os-tenant-name', help='OpenStack tenant name')
parser.set_defaults(debug=False, upload=True)
options, args = parser.parse_args()
-
- load_config(options.config_file)
+ load_config_or_exit(options.config_file)
log_to_stream(sys.stderr, level=logging.DEBUG if options.debug else logging.WARNING)
if options.upload:
diff --git a/Server/bkr/server/tools/log_delete.py b/Server/bkr/server/tools/log_delete.py
index 5acd5ff..d4673b9 100755
--- a/Server/bkr/server/tools/log_delete.py
+++ b/Server/bkr/server/tools/log_delete.py
@@ -21,7 +21,7 @@ from bkr.common import __version__
from bkr.log import log_to_stream
from optparse import OptionParser
from bkr.server.model import Job
-from bkr.server.util import load_config
+from bkr.server.util import load_config_or_exit
from turbogears.database import session
import logging
@@ -73,7 +73,8 @@ def main(argv=None):
help='Set a limit on the number of jobs whose logs will be deleted')
parser.set_defaults(verbose=False, debug=False, dry_run=False)
options, args = parser.parse_args(argv)
- load_config(options.config)
+ load_config_or_exit(options.config)
+
# urllib3 installs a NullHandler, we can just remove it and let the messages propagate
logging.getLogger('requests.packages.urllib3').handlers[:] = []
log_to_stream(sys.stderr, level=logging.DEBUG if options.debug else logging.WARNING)
diff --git a/Server/bkr/server/tools/nag_email.py b/Server/bkr/server/tools/nag_email.py
index 5f5fe12..0ce5dc5 100644
--- a/Server/bkr/server/tools/nag_email.py
+++ b/Server/bkr/server/tools/nag_email.py
@@ -16,7 +16,7 @@ from sqlalchemy.sql import and_
from sqlalchemy.orm import contains_eager, joinedload
from bkr.log import log_to_stream
from bkr.server.model import System, Reservation
-from bkr.server.util import load_config
+from bkr.server.util import load_config_or_exit
from turbogears import config
from turbogears.database import get_engine
from turbomail.control import interface
@@ -56,7 +56,7 @@ def main():
reservation_type = opts.reservation_type.decode(sys.stdin.encoding or 'utf8')
testing = opts.testing
configfile = opts.configfile
- load_config(configfile)
+ load_config_or_exit(configfile)
log_to_stream(sys.stderr)
interface.start(config)
get_engine()
diff --git a/Server/bkr/server/tools/product_update.py b/Server/bkr/server/tools/product_update.py
index ebbe4dd..92b9ca7 100755
--- a/Server/bkr/server/tools/product_update.py
+++ b/Server/bkr/server/tools/product_update.py
@@ -13,7 +13,7 @@ __requires__ = ['CherryPy < 3.0']
import sys
from bkr.log import log_to_stream
from bkr.server.model import Product
-from bkr.server.util import load_config
+from bkr.server.util import load_config_or_exit
from lxml import etree
from optparse import OptionParser
from turbogears.database import session
@@ -66,7 +66,7 @@ def main():
opts,args = parser.parse_args()
configfile = opts.configfile
xml_file = opts.productfile
- load_config(configfile)
+ load_config_or_exit(configfile)
log_to_stream(sys.stderr)
update_products(xml_file)
diff --git a/Server/bkr/server/tools/refresh_ldap.py b/Server/bkr/server/tools/refresh_ldap.py
index 15c7af1..8180e8f 100644
--- a/Server/bkr/server/tools/refresh_ldap.py
+++ b/Server/bkr/server/tools/refresh_ldap.py
@@ -19,7 +19,7 @@ import ldap
from turbogears import config
from bkr.common import __version__
from bkr.log import log_to_stream
-from bkr.server.util import load_config
+from bkr.server.util import load_config_or_exit
from bkr.server.model import session, Group
def refresh_ldap():
@@ -39,7 +39,7 @@ def main():
help='Print debugging messages to stderr')
parser.set_defaults(debug=False)
options, args = parser.parse_args()
- load_config(options.config)
+ load_config_or_exit(options.config)
log_to_stream(sys.stderr, level=logging.DEBUG if options.debug else logging.WARNING)
# beaker-server ships a cron job to run this command, so exit silently
diff --git a/Server/bkr/server/tools/repo_update.py b/Server/bkr/server/tools/repo_update.py
index 598def2..76c19cc 100755
--- a/Server/bkr/server/tools/repo_update.py
+++ b/Server/bkr/server/tools/repo_update.py
@@ -12,7 +12,7 @@ __requires__ = ['CherryPy < 3.0']
from bkr.log import log_to_stream
from bkr.server.model import OSMajor
-from bkr.server.util import load_config, run_createrepo
+from bkr.server.util import load_config_or_exit, run_createrepo
from optparse import OptionParser
from turbogears.config import get
import os
@@ -129,7 +129,7 @@ def main():
# The base URL is always a directory with a trailing slash
if not baseurl.endswith('/'):
baseurl += '/'
- load_config(configfile)
+ load_config_or_exit(configfile)
log_to_stream(sys.stderr, level=logging.DEBUG if opts.debug else logging.WARNING)
if opts.basepath:
basepath = opts.basepath
diff --git a/Server/bkr/server/util.py b/Server/bkr/server/util.py
index 8f401e3..0802f22 100644
--- a/Server/bkr/server/util.py
+++ b/Server/bkr/server/util.py
@@ -30,6 +30,15 @@ from bkr.server.bexceptions import DatabaseLookupError
log = logging.getLogger(__name__)
_config_loaded = None
+
+def load_config_or_exit(configfile=None):
+ try:
+ load_config(configfile=configfile)
+ except Exception as e:
+ sys.stderr.write('Failed to read server configuration. %s.\n'
+ 'Hint: run this command as root\n' % e)
+ sys.exit(1)
+
def load_config(configfile=None):
""" Loads Beaker's configuration and configures logging. """
setupdir = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
diff --git a/documentation/admin-guide/man/beaker-create-kickstart.rst b/documentation/admin-guide/man/beaker-create-kickstart.rst
index b6f3391..dcb5691 100644
--- a/documentation/admin-guide/man/beaker-create-kickstart.rst
+++ b/documentation/admin-guide/man/beaker-create-kickstart.rst
@@ -15,7 +15,9 @@ Description
``beaker-create-kickstart`` is used to generate customised kickstarts. Its
main purpose is for testing alternative templates, template variables, and
-kernel options. It needs root privileges to run.
+kernel options. It requires read access to the beaker server
+configuration and hence should be run as root or as another user with
+read access to the configuration file.
The generated kickstart is based off of a combination of a running/completed
recipe, system, and distro tree. It can then be further modified with any of