Skip to content

Commit 8a9a9d3

Browse files
committed
Merge remote-tracking branch 'origin/master' into edge
2 parents 2efdbc7 + 12e2fb7 commit 8a9a9d3

File tree

4 files changed

+29
-35
lines changed

4 files changed

+29
-35
lines changed

mig/install/generateconfs.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ def main(argv, _generate_confs=generate_confs):
192192
'log_level',
193193
'twofactor_mandatory_protos',
194194
'twofactor_auth_apps',
195+
'permanent_freeze',
195196
'freeze_to_tape',
196197
'status_system_match',
197198
'duplicati_protocols',
@@ -289,14 +290,13 @@ def main(argv, _generate_confs=generate_confs):
289290
'enable_sitestatus',
290291
'daemon_pubkey_from_dns',
291292
'seafile_ro_access',
292-
'permanent_freeze',
293293
'public_use_https',
294294
'prefer_python3',
295295
'io_account_expire',
296296
'gdp_email_notify',
297297
]
298298
names = str_names + int_names + bool_names
299-
settings = {}
299+
settings, options, result = {}, {}, {}
300300
default_val = 'DEFAULT'
301301
# Force values to expected type
302302
for key in names:
@@ -345,7 +345,7 @@ def main(argv, _generate_confs=generate_confs):
345345
else:
346346
print('Error: command line option %r not supported!' % opt_name)
347347
usage(names)
348-
sys.exit(1)
348+
return 1
349349

350350
if args:
351351
print('Error: non-option arguments are no longer supported!')
@@ -372,7 +372,7 @@ def main(argv, _generate_confs=generate_confs):
372372
if val == 'DEFAULT':
373373
del settings[key]
374374

375-
options = _generate_confs(output_path, **settings)
375+
(options, result) = _generate_confs(output_path, **settings)
376376

377377
# TODO: avoid reconstructing this path (also done inside generate_confs)
378378
instructions_path = os.path.join(options['destination_dir'],

mig/shared/install.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ def generate_confs(
591591
user_dict = _prepare(options, **expanded)
592592
_writefiles(options, user_dict)
593593
_instructions(options, user_dict)
594-
return options
594+
return (options, user_dict)
595595

596596

597597
def _generate_confs_prepare(
@@ -1046,13 +1046,7 @@ def _generate_confs_prepare(
10461046
user_dict['__SMTP_SERVER__'] = smtp_server
10471047
user_dict['__SMTP_SENDER__'] = smtp_sender
10481048
user_dict['__LOG_LEVEL__'] = log_level
1049-
1050-
if isinstance(permanent_freeze, basestring):
1051-
permanent_freeze = permanent_freeze.split(' ')
1052-
elif isinstance(permanent_freeze, bool):
1053-
permanent_freeze = ['yes' if permanent_freeze else 'no']
1054-
user_dict['__PERMANENT_FREEZE__'] = ' '.join(permanent_freeze)
1055-
1049+
user_dict['__PERMANENT_FREEZE__'] = permanent_freeze
10561050
user_dict['__FREEZE_TO_TAPE__'] = freeze_to_tape
10571051
user_dict['__STATUS_SYSTEM_MATCH__'] = status_system_match
10581052
user_dict['__IMNOTIFY_ADDRESS__'] = imnotify_address

tests/test_mig_install_generateconfs.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ def create_fake_generate_confs(return_dict=None):
5353
"""Fake generate confs helper"""
5454
def _generate_confs(*args, **kwargs):
5555
if return_dict:
56-
return return_dict
56+
return (return_dict, {})
5757
else:
58-
return {}
58+
return ({}, {})
5959
return _generate_confs
6060

6161

@@ -68,9 +68,8 @@ def test_option_permanent_freeze(self):
6868
with open(os.path.join(expected_generated_dir, "instructions.txt"),
6969
"w"):
7070
pass
71-
fake_generate_confs = create_fake_generate_confs(dict(
72-
destination_dir=expected_generated_dir
73-
))
71+
fake_generate_confs = create_fake_generate_confs(
72+
dict(destination_dir=expected_generated_dir))
7473
test_arguments = ['--permanent_freeze', 'yes']
7574

7675
exit_code = main(test_arguments, _generate_confs=fake_generate_confs)

tests/test_mig_shared_install.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def capture_defaulted(*args, **kwargs):
197197
return args[0]
198198
capture_defaulted.kwargs = None
199199

200-
options = generate_confs(
200+
(options, _) = generate_confs(
201201
'/some/arbitrary/path',
202202
_getpwnam=create_dummy_gpwnam(4321, 1234),
203203
_prepare=capture_defaulted,
@@ -237,23 +237,24 @@ def test_creates_output_files_with_permanent_freeze(self):
237237
expected_generated_dir = cleanpath('confs-stdlocal', self)
238238
symlink_path = temppath('confs', self)
239239

240-
generate_confs(
241-
self.output_path,
242-
destination=symlink_path,
243-
destination_suffix='-stdlocal',
244-
permanent_freeze=('foo', 'bar', 'baz'),
245-
_getpwnam=create_dummy_gpwnam(4321, 1234),
246-
)
240+
for arg_val in ('yes', 'no', 'foo bar baz'):
241+
generate_confs(
242+
self.output_path,
243+
destination=symlink_path,
244+
destination_suffix='-stdlocal',
245+
permanent_freeze=arg_val,
246+
_getpwnam=create_dummy_gpwnam(4321, 1234),
247+
)
247248

248-
relative_file = 'confs-stdlocal/MiGserver.conf'
249-
self.assertPathExists('confs-stdlocal/MiGserver.conf')
249+
relative_file = 'confs-stdlocal/MiGserver.conf'
250+
self.assertPathExists('confs-stdlocal/MiGserver.conf')
250251

251-
actual_file = outputpath(relative_file)
252-
self.assertConfigKey(
253-
actual_file, 'SITE', 'permanent_freeze', expected='foo bar baz')
252+
actual_file = outputpath(relative_file)
253+
self.assertConfigKey(
254+
actual_file, 'SITE', 'permanent_freeze', expected=arg_val)
254255

255256
def test_options_for_source_auto(self):
256-
options = generate_confs(
257+
(options, _) = generate_confs(
257258
'/some/arbitrary/path',
258259
source=keyword_auto,
259260
_getpwnam=create_dummy_gpwnam(4321, 1234),
@@ -266,7 +267,7 @@ def test_options_for_source_auto(self):
266267
self.assertEqual(options['template_dir'], expected_template_dir)
267268

268269
def test_options_for_source_relative(self):
269-
options = generate_confs(
270+
(options, _) = generate_confs(
270271
'/current/working/directory/mig/install',
271272
source='.',
272273
_getpwnam=create_dummy_gpwnam(4321, 1234),
@@ -279,7 +280,7 @@ def test_options_for_source_relative(self):
279280
'/current/working/directory/mig/install')
280281

281282
def test_options_for_destination_auto(self):
282-
options = generate_confs(
283+
(options, _) = generate_confs(
283284
'/some/arbitrary/path',
284285
destination=keyword_auto,
285286
destination_suffix='_suffix',
@@ -295,7 +296,7 @@ def test_options_for_destination_auto(self):
295296
'/some/arbitrary/path/confs_suffix')
296297

297298
def test_options_for_destination_relative(self):
298-
options = generate_confs(
299+
(options, _) = generate_confs(
299300
'/current/working/directory',
300301
destination='generate-confs',
301302
destination_suffix='_suffix',
@@ -311,7 +312,7 @@ def test_options_for_destination_relative(self):
311312
'/current/working/directory/generate-confs_suffix')
312313

313314
def test_options_for_destination_absolute(self):
314-
options = generate_confs(
315+
(options, _) = generate_confs(
315316
'/current/working/directory',
316317
destination='/some/other/place/confs',
317318
destination_suffix='_suffix',

0 commit comments

Comments
 (0)