Skip to content

Commit 5b84ac4

Browse files
committed
Manually merge PR152 to make checkconf helper useful again e.g. for docker-migrid self-tests
git-svn-id: svn+ssh://svn.code.sf.net/p/migrid/code/trunk@6166 b75ad72c-e7d7-11dd-a971-7dbc132099af
1 parent eba299f commit 5b84ac4

File tree

6 files changed

+170
-142
lines changed

6 files changed

+170
-142
lines changed

mig/install/MiGserver-template.conf

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,7 @@ events_home = %(state_path)s/events_home/
119119
twofactor_home = %(state_path)s/twofactor_home/
120120
gdp_home = %(state_path)s/gdp_home/
121121
workflows_home = %(state_path)s/workflows_home/
122-
workflows_db_home = %(workflows_home)sworkflows_db_home/
123-
workflows_db = %(workflows_db_home)sworkflows_db.pickle
124-
workflows_db_lock = %(workflows_db_home)sworkflows_db.lock
122+
workflows_db_home = %(state_path)s/workflows_db_home/
125123
notify_home = %(state_path)s/notify_home/
126124
quota_home = %(state_path)s/quota_home/
127125

@@ -164,8 +162,8 @@ vgrid_monitor = monitor
164162
public_key_file = ~/.ssh/id_rsa.pub
165163

166164
# x.509 certificate and key used for interserver communication
167-
server_cert = %(certs_path)s/MiGservercert.pem
168-
server_key = %(certs_path)s/MiGserverkey.pem
165+
server_cert = %(certs_path)s/combined.pem
166+
server_key = %(certs_path)s/combined.pem
169167
ca_cert = %(certs_path)s/cacert.pem
170168
sss_home = %(state_path)s/sss_home/
171169

mig/java-bin/README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The contents of this folder is by the java sandbox resources.

mig/server/checkconf.py

Lines changed: 162 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# --- BEGIN_HEADER ---
55
#
66
# checkconf - check MiGserver.conf file
7-
# Copyright (C) 2003-2021 The MiG Project lead by Brian Vinter
7+
# Copyright (C) 2003-2024 The MiG Project lead by Brian Vinter
88
#
99
# This file is part of MiG.
1010
#
@@ -25,14 +25,17 @@
2525
# -- END_HEADER ---
2626
#
2727

28-
"""Check MiGserver.conf or specified MiG server conf file:
29-
Currently only checks that files and dirs exist, but could be
30-
extended to include other variable checks.
28+
"""Check MiGserver.conf either in specified path, pointed to in MIG_CONF or in
29+
default mig/server/ location.
30+
Currently mainly checks that required files and dirs exist, but may be extended
31+
to include other variable checks.
3132
"""
3233

3334
from __future__ import print_function
3435
from __future__ import absolute_import
3536

37+
from builtins import input
38+
from past.builtins import basestring
3639
import os
3740
import re
3841
import sys
@@ -56,7 +59,7 @@ def usage():
5659
def ask_reply(question):
5760
"""Read user input"""
5861

59-
return raw_input(question)
62+
return input(question)
6063

6164

6265
def ask_confirm(question, allow_always=False):
@@ -79,135 +82,163 @@ def touch_file(path):
7982
open(path, 'w').close()
8083

8184

82-
argc = len(sys.argv)
83-
if argc == 1:
84-
85-
# Change CWD to ../mig/server/ to allow relative paths
86-
87-
server_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
88-
conf_file = server_dir + os.sep + 'MiGserver.conf'
89-
elif argc == 2:
90-
conf_file = sys.argv[1]
91-
else:
92-
print(usage())
93-
sys.exit(2)
94-
95-
conf = None
96-
if not os.path.isfile(conf_file):
97-
if YES == ask_confirm('Configuration file %s does not exist! %s'
98-
% (conf_file, 'create it? [Y/n] ')):
99-
try:
100-
touch_file(conf_file)
101-
print('created empty configuration file: %s' % conf_file)
102-
except Exception as err:
103-
print('could not create %s: %s' % (conf_file, err))
85+
def check_conf(conf_file):
86+
"""Verify conf_file to be complete and have all referenced paths"""
87+
conf = None
88+
if not os.path.isfile(conf_file):
89+
if YES == ask_confirm('Configuration file %s does not exist! %s' %
90+
(conf_file, 'create it? [Y/n] ')):
91+
try:
92+
touch_file(conf_file)
93+
print('created empty configuration file: %s' % conf_file)
94+
except Exception as err:
95+
print('could not create %s: %s' % (conf_file, err))
96+
else:
97+
return 2
10498
else:
105-
sys.exit(1)
106-
else:
107-
try:
108-
conf = Configuration(conf_file)
109-
except Exception as err:
110-
print('configuration file %s is incomplete! %s' % (conf_file,
111-
err))
112-
113-
if not conf:
114-
if YES == ask_confirm('Add missing configuration options? [Y/n] '):
115-
fix_missing(conf_file)
11699
try:
117100
conf = Configuration(conf_file)
118101
except Exception as err:
119-
print('configuration file %s is still incomplete! %s'
120-
% (conf_file, err))
121-
sys.exit(1)
102+
print('configuration file %s is incomplete! %s' % (conf_file, err))
103+
104+
if not conf:
105+
if YES == ask_confirm('Add missing configuration options? [Y/n] '):
106+
fix_missing(conf_file)
107+
try:
108+
conf = Configuration(conf_file)
109+
except Exception as err:
110+
print('configuration file %s is still incomplete! %s' %
111+
(conf_file, err))
112+
return 1
113+
else:
114+
return 2
115+
116+
# Search object attributes for possible paths
117+
118+
attrs = []
119+
ignore_attrs = ['__class__', '__doc__', '__module__']
120+
path_re = re.compile('(' + os.sep + "[\w\._-]*)+$")
121+
122+
_logger = conf.logger
123+
_logger.info('Checking configuration paths in %s ...', conf_file)
124+
print('Checking configuration paths in %s ...' % conf_file)
125+
warnings = 0
126+
missing_paths = []
127+
conf_parser = ConfigParser()
128+
conf_parser.read([conf_file])
129+
for (name, val) in conf_parser.items('GLOBAL'):
130+
if not isinstance(val, basestring):
131+
132+
# ignore non-string values
133+
134+
continue
135+
elif not val:
136+
137+
# ignore empty string values
138+
139+
continue
140+
elif name.endswith('_url') or val.find('://') != -1:
141+
142+
# ignore url values
143+
144+
continue
145+
elif val.find('/emailAddress=') != -1:
146+
147+
# ignore x509 DN values
148+
149+
continue
150+
elif path_re.match(val):
151+
path = os.path.normpath(val)
152+
if os.path.isdir(path):
153+
_logger.info('%s OK: %s is a dir', name, val)
154+
elif os.path.isfile(path):
155+
_logger.info('%s OK: %s is a file', name, val)
156+
elif os.path.exists(path):
157+
_logger.info('%s OK: %s exists', name, val)
158+
else:
159+
_logger.warning('%s: %s does not exist!', name, val)
160+
print('* WARNING *: %s: %s does not exist!' % (name, val))
161+
if not path in missing_paths:
162+
missing_paths.append(path)
163+
warnings += 1
164+
165+
_logger.info('Found %d configuration problem(s)', warnings)
166+
print('Found %d configuration problem(s)' % warnings)
167+
168+
if warnings > 0:
169+
answer = ask_confirm('Add missing path(s)? [Y/n/a]: ',
170+
allow_always=True)
171+
if answer != NO:
172+
173+
# Sort missing paths to avoid overlaps resulting in errors
174+
175+
missing_paths.sort()
176+
177+
for path in missing_paths:
178+
if ALWAYS == answer:
179+
180+
# 'always' answer reults in default type for all missing entries
181+
182+
path_type = None
183+
elif YES == answer:
184+
path_type = \
185+
ask_reply('Create %s as a (d)irectory, (f)ile or (p)ipe? [D/f/p] '
186+
% path)
187+
if not path_type or 'D' == path_type.upper():
188+
try:
189+
os.makedirs(path)
190+
print('created directory %s' % path)
191+
except Exception as err:
192+
print('could not create directory %s: %s' %
193+
(path, err))
194+
elif 'F' == path_type.upper():
195+
try:
196+
dirname = os.path.dirname(path)
197+
if dirname and not os.path.exists(dirname):
198+
os.makedirs(dirname)
199+
print('created directory %s' % dirname)
200+
touch_file(path)
201+
print('created file %s' % path)
202+
except Exception as err:
203+
print('could not create file %s: %s' % (path, err))
204+
elif 'P' == path_type.upper():
205+
try:
206+
dirname = os.path.dirname(path)
207+
if dirname and not os.path.exists(dirname):
208+
os.makedirs(dirname)
209+
print('created directory %s' % dirname)
210+
os.mkfifo(path)
211+
print('created pipe %s' % path)
212+
except Exception as err:
213+
print('could not create file %s: %s' % (path, err))
214+
print('completed check of %s: %d warning(s)' % (conf_file, warnings))
215+
return warnings
216+
217+
218+
if __name__ == "__main__":
219+
if sys.argv[1:]:
220+
file_list = sys.argv[1:]
122221
else:
123-
sys.exit(1)
124-
125-
# Search object attributes for possible paths
126-
127-
attrs = []
128-
ignore_attrs = ['__class__', '__doc__', '__module__']
129-
path_re = re.compile('(' + os.sep + "\w+)+")
130-
131-
conf.logger.info('Checking configuration paths in %s ...', conf_file)
132-
print('Checking configuration paths in %s ...' % conf_file)
133-
warnings = 0
134-
missing_paths = []
135-
conf_parser = ConfigParser()
136-
conf_parser.read([conf_file])
137-
for (name, val) in conf_parser.items('GLOBAL'):
138-
if not isinstance(val, basestring):
139-
140-
# ignore non-string values
141-
142-
continue
143-
elif not val:
144-
145-
# ignore empty string values
146-
147-
continue
148-
elif path_re.match(val):
149-
path = os.path.normpath(val)
150-
if os.path.isdir(path):
151-
conf.logger.info('%s OK: %s is a dir', name, val)
152-
elif os.path.isfile(path):
153-
conf.logger.info('%s OK: %s is a file', name, val)
154-
elif os.path.exists(path):
155-
conf.logger.info('%s OK: %s exists', name, val)
222+
env_conf = os.environ.get('MIG_CONF', '')
223+
if env_conf:
224+
conf_file = env_conf
156225
else:
157-
conf.logger.warning('%s: %s does not exist!', name, val)
158-
print('* WARNING *: %s: %s does not exist!' % (name, val))
159-
if not path in missing_paths:
160-
missing_paths.append(path)
161-
warnings += 1
162-
163-
conf.logger.info('Found %d configuration problem(s)', warnings)
164-
print('Found %d configuration problem(s)' % warnings)
165-
166-
if warnings > 0:
167-
answer = ask_confirm('Add missing path(s)? [Y/n/a]: ',
168-
allow_always=True)
169-
if answer != NO:
170-
171-
# Sort missing paths to avoid overlaps resulting in errors
172-
173-
missing_paths.sort()
174-
175-
for path in missing_paths:
176-
if ALWAYS == answer:
177-
178-
# 'always' answer reults in default type for all missing entries
179-
180-
path_type = None
181-
elif YES == answer:
182-
path_type = \
183-
ask_reply('Create %s as a (d)irectory, (f)ile or (p)ipe? [D/f/p] '
184-
% path)
185-
if not path_type or 'D' == path_type.upper():
186-
try:
187-
os.makedirs(path)
188-
print('created directory %s' % path)
189-
except Exception as err:
190-
print('could not create directory %s: %s' % (path,
191-
err))
192-
elif 'F' == path_type.upper():
193-
try:
194-
dirname = os.path.dirname(path)
195-
if dirname and not os.path.exists(dirname):
196-
os.makedirs(dirname)
197-
print('created directory %s' % dirname)
198-
touch_file(path)
199-
print('created file %s' % path)
200-
except Exception as err:
201-
print('could not create file %s: %s' % (path, err))
202-
elif 'P' == path_type.upper():
203-
try:
204-
dirname = os.path.dirname(path)
205-
if dirname and not os.path.exists(dirname):
206-
os.makedirs(dirname)
207-
print('created directory %s' % dirname)
208-
os.mkfifo(path)
209-
print('created pipe %s' % path)
210-
except Exception as err:
211-
print('could not create file %s: %s' % (path, err))
212-
213-
sys.exit(0)
226+
# We may be called from MIG_ROOT/mig/server or from MIG_ROOT/bin
227+
current_dir = os.path.dirname(os.path.abspath(sys.argv[0]))
228+
parent_dir = os.path.dirname(current_dir)
229+
if os.path.basename(current_dir) == 'bin':
230+
base_dir = parent_dir
231+
else:
232+
base_dir = os.path.dirname(parent_dir)
233+
234+
conf_file = os.path.join(base_dir, "mig", "server",
235+
'MiGserver.conf')
236+
if not os.path.isfile(conf_file):
237+
print(usage())
238+
sys.exit(2)
239+
file_list = [conf_file]
240+
241+
retval = 0
242+
for conf_file in file_list:
243+
retval += check_conf(conf_file)
244+
sys.exit(retval)

mig/shared/configuration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def fix_missing(config_file, verbose=True):
201201
'twofactor_home': '~/state/twofactor_home/',
202202
'gdp_home': '~/state/gdp_home/',
203203
'workflows_home': '~/state/workflows_home/',
204-
'workflows_db_home': '~/state/workflows_home/workflows_db_home/',
204+
'workflows_db_home': '~/state/workflows_db_home/',
205205
'notify_home': '~/state/notify_home',
206206
'site_vgrid_links': 'files web tracker workflows monitor',
207207
'site_vgrid_creators': 'distinguished_name:.*',

state/workflows_db_home/.placeholder

Whitespace-only changes.

tests/fixture/confs-stdlocal/MiGserver.conf

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,7 @@ events_home = %(state_path)s/events_home/
119119
twofactor_home = %(state_path)s/twofactor_home/
120120
gdp_home = %(state_path)s/gdp_home/
121121
workflows_home = %(state_path)s/workflows_home/
122-
workflows_db_home = %(workflows_home)sworkflows_db_home/
123-
workflows_db = %(workflows_db_home)sworkflows_db.pickle
124-
workflows_db_lock = %(workflows_db_home)sworkflows_db.lock
122+
workflows_db_home = %(state_path)s/workflows_db_home/
125123
notify_home = %(state_path)s/notify_home/
126124
quota_home = %(state_path)s/quota_home/
127125

@@ -164,8 +162,8 @@ vgrid_monitor = monitor
164162
public_key_file = ~/.ssh/id_rsa.pub
165163

166164
# x.509 certificate and key used for interserver communication
167-
server_cert = %(certs_path)s/MiGservercert.pem
168-
server_key = %(certs_path)s/MiGserverkey.pem
165+
server_cert = %(certs_path)s/combined.pem
166+
server_key = %(certs_path)s/combined.pem
169167
ca_cert = %(certs_path)s/cacert.pem
170168
sss_home = %(state_path)s/sss_home/
171169

0 commit comments

Comments
 (0)