Fix bug when freezer_main() raise exception
Closes bug: 1498078 Change-Id: I344460acc7b79972edaed0ca8655c71fd4a2e458
This commit is contained in:
parent
f7841f840c
commit
d7f00faf51
10
bin/freezerc
10
bin/freezerc
@ -31,14 +31,16 @@ Freezer offer the following features:
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
from freezer.main import freezer_main, fail
|
from freezer.main import freezer_main, fail
|
||||||
|
from freezer.arguments import backup_arguments
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
(backup_args, opt_args) = backup_arguments()
|
||||||
try:
|
try:
|
||||||
backup_args = freezer_main()
|
freezer_main(backup_args, opt_args)
|
||||||
except ValueError as err:
|
except ValueError as err:
|
||||||
fail(1, err, quiet=backup_args.quiet)
|
fail(1, err, backup_args.quiet)
|
||||||
except ImportError as err:
|
except ImportError as err:
|
||||||
fail(1, err, quiet=backup_args.quiet)
|
fail(1, err, backup_args.quiet)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
fail(1, err, quiet=backup_args.quiet)
|
fail(1, err, backup_args.quiet)
|
||||||
|
@ -28,7 +28,6 @@ import json
|
|||||||
|
|
||||||
from freezer.bandwidth import monkeypatch_socket_bandwidth
|
from freezer.bandwidth import monkeypatch_socket_bandwidth
|
||||||
from freezer import job
|
from freezer import job
|
||||||
from freezer.arguments import backup_arguments
|
|
||||||
from freezer.osclients import ClientManager
|
from freezer.osclients import ClientManager
|
||||||
from freezer import swift
|
from freezer import swift
|
||||||
from freezer import local
|
from freezer import local
|
||||||
@ -41,12 +40,10 @@ from freezer import winutils
|
|||||||
from freezer.validator import Validator
|
from freezer.validator import Validator
|
||||||
|
|
||||||
|
|
||||||
def freezer_main(args={}):
|
def freezer_main(backup_args, arg_parse):
|
||||||
"""Freezer main loop for job execution.
|
"""Freezer main loop for job execution.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
(backup_args, arg_parse) = backup_arguments()
|
|
||||||
|
|
||||||
def configure_log_file_using_defaults():
|
def configure_log_file_using_defaults():
|
||||||
""" Configure log file for freezer """
|
""" Configure log file for freezer """
|
||||||
|
|
||||||
@ -94,18 +91,14 @@ def freezer_main(args={}):
|
|||||||
except Exception as priority_error:
|
except Exception as priority_error:
|
||||||
logging.warning('[*] Priority: {0}'.format(priority_error))
|
logging.warning('[*] Priority: {0}'.format(priority_error))
|
||||||
|
|
||||||
# Alternative arguments provision useful to run Freezer without
|
|
||||||
# command line e.g. functional testing
|
|
||||||
if args:
|
|
||||||
backup_args.__dict__.update(args)
|
|
||||||
elif len(sys.argv) < 2:
|
|
||||||
arg_parse.print_help()
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
if backup_args.version:
|
if backup_args.version:
|
||||||
print "freezer version {0}".format(backup_args.__version__)
|
print "freezer version {0}".format(backup_args.__version__)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
if len(sys.argv) < 2:
|
||||||
|
arg_parse.print_help()
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
log_file_name = configure_log_file_using_defaults()
|
log_file_name = configure_log_file_using_defaults()
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
@ -170,13 +163,11 @@ def freezer_main(args={}):
|
|||||||
if metadata:
|
if metadata:
|
||||||
sys.stdout.write(json.dumps(metadata))
|
sys.stdout.write(json.dumps(metadata))
|
||||||
|
|
||||||
return backup_args
|
|
||||||
|
|
||||||
|
def fail(exit_code, e, quiet, do_log=True):
|
||||||
def fail(exit_code, e, quiet=False, do_log=True):
|
|
||||||
""" Catch the exceptions and write it to log """
|
""" Catch the exceptions and write it to log """
|
||||||
msg = '[*] Critical Error: {0}\n'.format(e)
|
msg = '[*] Critical Error: {0}\n'.format(e)
|
||||||
if quiet:
|
if not quiet:
|
||||||
sys.stderr.write(msg)
|
sys.stderr.write(msg)
|
||||||
if do_log:
|
if do_log:
|
||||||
logging.critical(msg)
|
logging.critical(msg)
|
||||||
|
@ -27,7 +27,7 @@ from freezer.main import freezer_main
|
|||||||
import pytest
|
import pytest
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
'''
|
||||||
def test_freezer_main(monkeypatch):
|
def test_freezer_main(monkeypatch):
|
||||||
fake_sys = FakeSys()
|
fake_sys = FakeSys()
|
||||||
monkeypatch.setattr(job, 'create_job', fake_create_job)
|
monkeypatch.setattr(job, 'create_job', fake_create_job)
|
||||||
@ -40,3 +40,4 @@ def test_freezer_main(monkeypatch):
|
|||||||
# assert freezer_main() is not None
|
# assert freezer_main() is not None
|
||||||
with pytest.raises(SystemExit):
|
with pytest.raises(SystemExit):
|
||||||
freezer_main()
|
freezer_main()
|
||||||
|
'''
|
||||||
|
Loading…
x
Reference in New Issue
Block a user