Merge "xenapi: fix rootwrap"

This commit is contained in:
Jenkins 2013-06-14 01:25:17 +00:00 committed by Gerrit Code Review
commit 0630d9d817

View File

@ -55,6 +55,7 @@ def load_configuration(exec_name, config_file):
config = ConfigParser.RawConfigParser() config = ConfigParser.RawConfigParser()
config.read(config_file) config.read(config_file)
try: try:
exec_dirs = config.get("DEFAULT", "exec_dirs").split(",")
filters_path = config.get("DEFAULT", "filters_path").split(",") filters_path = config.get("DEFAULT", "filters_path").split(",")
section = 'XENAPI' section = 'XENAPI'
url = config.get(section, "xenapi_connection_url") url = config.get(section, "xenapi_connection_url")
@ -74,10 +75,11 @@ def load_configuration(exec_name, config_file):
url=url, url=url,
username=username, username=username,
password=password, password=password,
exec_dirs=exec_dirs,
) )
def filter_command(exec_name, filters_path, user_args): def filter_command(exec_name, filters_path, user_args, exec_dirs):
# Add ../ to sys.path to allow running from branch # Add ../ to sys.path to allow running from branch
possible_topdir = os.path.normpath(os.path.join(os.path.abspath(exec_name), possible_topdir = os.path.normpath(os.path.join(os.path.abspath(exec_name),
os.pardir, os.pardir)) os.pardir, os.pardir))
@ -88,7 +90,8 @@ def filter_command(exec_name, filters_path, user_args):
# Execute command if it matches any of the loaded filters # Execute command if it matches any of the loaded filters
filters = wrapper.load_filters(filters_path) filters = wrapper.load_filters(filters_path)
filter_match = wrapper.match_filter(filters, user_args) filter_match = wrapper.match_filter(
filters, user_args, exec_dirs=exec_dirs)
if not filter_match: if not filter_match:
print "Unauthorized command: %s" % ' '.join(user_args) print "Unauthorized command: %s" % ' '.join(user_args)
sys.exit(RC_UNAUTHORIZED) sys.exit(RC_UNAUTHORIZED)
@ -110,7 +113,7 @@ def run_command(url, username, password, user_args):
def main(): def main():
exec_name, config_file, user_args = parse_args() exec_name, config_file, user_args = parse_args()
config = load_configuration(exec_name, config_file) config = load_configuration(exec_name, config_file)
filter_command(exec_name, config['filters_path'], user_args) filter_command(exec_name, config['filters_path'], user_args, config['exec_dirs'])
return run_command(config['url'], config['username'], config['password'], return run_command(config['url'], config['username'], config['password'],
user_args) user_args)