diff options
author | Ruan HE <ruan.he@orange.com> | 2017-11-10 09:46:52 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2017-11-10 09:46:52 +0000 |
commit | 00eb18e358640691a3023de569aedea5865484ea (patch) | |
tree | 84489c1d29a84c6d4444e2af7d9ea968981d3550 /moonv4 | |
parent | 7ce33e7a01ac4433fc91882fa1a224396664362d (diff) | |
parent | 2400dc978822b66e3bad999e6dc6375c3b3308a0 (diff) |
Merge "Update the db_manager in order to use it for tests"
Diffstat (limited to 'moonv4')
-rw-r--r-- | moonv4/moon_db/Changelog | 4 | ||||
-rw-r--r-- | moonv4/moon_db/moon_db/__init__.py | 2 | ||||
-rw-r--r-- | moonv4/moon_db/moon_db/db_manager.py | 83 |
3 files changed, 55 insertions, 34 deletions
diff --git a/moonv4/moon_db/Changelog b/moonv4/moon_db/Changelog index fa84ca92..c1e8a770 100644 --- a/moonv4/moon_db/Changelog +++ b/moonv4/moon_db/Changelog @@ -32,3 +32,7 @@ CHANGES ----- - When adding a subject, check the existence of that user in the Keystone DB and create it if necessary + +1.2.0 +----- +- Update the db_manager in order to use it for tests
\ No newline at end of file diff --git a/moonv4/moon_db/moon_db/__init__.py b/moonv4/moon_db/moon_db/__init__.py index ac014182..5eb389d3 100644 --- a/moonv4/moon_db/moon_db/__init__.py +++ b/moonv4/moon_db/moon_db/__init__.py @@ -3,5 +3,5 @@ # license which can be found in the file 'LICENSE' in this package distribution # or at 'http://www.apache.org/licenses/LICENSE-2.0'. -__version__ = "1.1.0" +__version__ = "1.2.0" diff --git a/moonv4/moon_db/moon_db/db_manager.py b/moonv4/moon_db/moon_db/db_manager.py index 81e6fe77..88d5b7d3 100644 --- a/moonv4/moon_db/moon_db/db_manager.py +++ b/moonv4/moon_db/moon_db/db_manager.py @@ -14,51 +14,68 @@ from sqlalchemy import create_engine from moon_db.migrate_repo import versions from moon_utilities import configuration -parser = argparse.ArgumentParser() -parser.add_argument('command', help='command (upgrade or downgrade)', nargs=1) -parser.add_argument("--verbose", "-v", action='store_true', help="verbose mode") -parser.add_argument("--debug", "-d", action='store_true', help="debug mode") -args = parser.parse_args() -FORMAT = '%(asctime)-15s %(levelname)s %(message)s' -if args.debug: - logging.basicConfig( - format=FORMAT, - level=logging.DEBUG) -elif args.verbose: - logging.basicConfig( - format=FORMAT, - level=logging.INFO) -else: - logging.basicConfig( - format=FORMAT, - level=logging.WARNING) +def init_args(): + parser = argparse.ArgumentParser() + parser.add_argument('command', help='command (upgrade or downgrade)', + nargs=1) + parser.add_argument("--verbose", "-v", action='store_true', + help="verbose mode") + parser.add_argument("--debug", "-d", action='store_true', + help="debug mode") + args = parser.parse_args() -requests_log = logging.getLogger("requests.packages.urllib3") -requests_log.setLevel(logging.WARNING) -requests_log.propagate = True + FORMAT = '%(asctime)-15s %(levelname)s %(message)s' + if args.debug: + logging.basicConfig( + format=FORMAT, + level=logging.DEBUG) + elif args.verbose: + logging.basicConfig( + format=FORMAT, + level=logging.INFO) + else: + logging.basicConfig( + format=FORMAT, + level=logging.WARNING) -logger = logging.getLogger("moon.db.manager") + requests_log = logging.getLogger("requests.packages.urllib3") + requests_log.setLevel(logging.WARNING) + requests_log.propagate = True -db_conf = configuration.get_configuration("database")["database"] -engine = create_engine(db_conf['url']) + logger = logging.getLogger("moon.db.manager") + return args, logger -def format_data(ext): - return ext.name, ext.obj.upgrade() +def init_engine(): + db_conf = configuration.get_configuration("database")["database"] + return create_engine(db_conf['url']) -def run(): +# def format_data(ext): +# return ext.name, ext.obj.upgrade() + + +def run(command, logger, engine): files = glob.glob(versions.__path__[0] + "/[0-9][0-9][0-9]*.py") for filename in files: filename = os.path.basename(filename).replace(".py", "") - o = importlib.import_module("moon_db.migrate_repo.versions.{}".format(filename)) - logger.info("Command is {}".format(args.command[0])) - if args.command[0] in ("upgrade", "u", "up"): - logger.info("upgrading moon_db.migrate_repo.versions.{}".format(filename)) + o = importlib.import_module( + "moon_db.migrate_repo.versions.{}".format(filename)) + logger.info("Command is {}".format(command)) + if command in ("upgrade", "u", "up"): + logger.info( + "upgrading moon_db.migrate_repo.versions.{}".format(filename)) o.upgrade(engine) - elif args.command[0] in ("downgrade", "d", "down"): - logger.info("downgrading moon_db.migrate_repo.versions.{}".format(filename)) + elif command in ("downgrade", "d", "down"): + logger.info( + "downgrading moon_db.migrate_repo.versions.{}".format( + filename)) o.downgrade(engine) else: logger.critical("Cannot understand the command!") + +if __name__ == "__main__": + args, logger = init_args() + engine = init_engine() + run(args.command[0], logger, engine) |