diff --git a/docs/source/conf.py b/docs/source/conf.py index 990f58aa5b5a2b24776500d4a0f9142a7b05b2d1..f48683f27618c584dacca9bf31c72d140722ccf7 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -21,6 +21,7 @@ sys.path.insert(0, os.path.abspath( os.path.dirname(__file__), '..', '..', 'resource_management'))) + class RenderAsJSON(Directive): # cf. https://stackoverflow.com/a/59883833 @@ -65,8 +66,6 @@ extensions = [ templates_path = ['_templates'] exclude_patterns = [] - - # -- Options for HTML output ------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output @@ -81,4 +80,3 @@ autodoc_typehints = 'none' # Display todos by setting to True todo_include_todos = True - diff --git a/resource_management/__init__.py b/resource_management/__init__.py index 8b137891791fe96927ad78e64b0aad7bded08bdc..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 --- a/resource_management/__init__.py +++ b/resource_management/__init__.py @@ -1 +0,0 @@ - diff --git a/resource_management/cli.py b/resource_management/cli.py index d354107c876b97ae436f0ac9fae5639cad0bc153..85c4e9d493be0bda7891435a0df187d885754f99 100644 --- a/resource_management/cli.py +++ b/resource_management/cli.py @@ -31,7 +31,8 @@ import click import logging from jsonschema import validate, ValidationError -from resource_management.hardware.router import load_line_cards, LINE_CARDS_LIST_SCHEMA +from resource_management.hardware.router \ + import load_line_cards, LINE_CARDS_LIST_SCHEMA from resource_management import db, config, environment environment.setup_logging() @@ -97,10 +98,11 @@ def cli(config, fqdn): validate(line_cards, LINE_CARDS_LIST_SCHEMA) mysql_config = config["mysql"] - dsn = db.mysql_dsn(mysql_config["username"], - mysql_config["password"], - mysql_config["hostname"], - mysql_config["dbname"]) + dsn = db.mysql_dsn( + username=mysql_config["username"], + password=mysql_config["password"], + hostname=mysql_config["hostname"], + db_name=mysql_config["dbname"]) logger.info("MYSQL DSN is: {0}".format(dsn)) db.init_db_model(dsn) diff --git a/resource_management/db/__init__.py b/resource_management/db/__init__.py index b2c108a60f71b6cd0942994d46232cd0cb4d5f53..6b3d5f7d10462f13c5eaa4842e20972853b1e155 100644 --- a/resource_management/db/__init__.py +++ b/resource_management/db/__init__.py @@ -1,6 +1,6 @@ import contextlib import logging -from typing import Optional, Union, Callable, Iterator +from typing import Union, Iterator from sqlalchemy import create_engine from sqlalchemy.exc import SQLAlchemyError diff --git a/resource_management/hardware/router.py b/resource_management/hardware/router.py index 13abe5725b56e4ff5851b9c4df8a12d140daed96..6be1a6332d2c250ad737dd0a7bd9986c3e18257f 100644 --- a/resource_management/hardware/router.py +++ b/resource_management/hardware/router.py @@ -25,7 +25,11 @@ LINE_CARDS_LIST_SCHEMA = { 'items': { 'type': 'object', 'properties': { - 'name': {'type': 'string', 'pattern': '^[a-z]{2}\\-[0-9]{1,2}\\/[0-9]{1,2}\\/[0-9]{1,3}'}, + 'name': { + 'type': 'string', + 'pattern': + '^[a-z]{2}\\-[0-9]{1,2}\\/[0-9]{1,2}\\/[0-9]{1,3}' + }, 'speed': {'type': 'integer', 'minimum': 0} }, 'required': ['name', 'speed'], @@ -48,6 +52,7 @@ LINE_CARDS_LIST_SCHEMA = { } } + @contextlib.contextmanager def device(hostname, ssh_config, port=830): diff --git a/resource_management/migrations/versions/cdbd931a47d4_add_speed_column_to_ports_table.py b/resource_management/migrations/versions/cdbd931a47d4_add_speed_column_to_ports_table.py index 4baf5f829f1e936efcced302a9ecb40ff4999785..9fb3a4a216b75cfb37b053ddce4be00bc4ea864a 100644 --- a/resource_management/migrations/versions/cdbd931a47d4_add_speed_column_to_ports_table.py +++ b/resource_management/migrations/versions/cdbd931a47d4_add_speed_column_to_ports_table.py @@ -19,10 +19,10 @@ depends_on = None def upgrade() -> None: with op.batch_alter_table('ports') as batch_op: batch_op.add_column( - Column('speed', sa.Integer, nullable=False)), + sa.Column('speed', sa.Integer, nullable=False), insert_after='name' ) def downgrade() -> None: - op.drop_column('ports','speed') + op.drop_column('ports', 'speed') diff --git a/test/conftest.py b/test/conftest.py index fb80882634988ffe8a9cd504ef9886cd478f18f6..4b697170a57cff71d6166b874777e969bfa3e36c 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -10,6 +10,7 @@ from sqlalchemy.pool import StaticPool from resource_management.db import model +DATA_DIR = os.path.join(os.path.dirname(__file__), 'data') HOSTNAMES = [ 'vmx', 'mx1.lab.office.geant.net', @@ -86,10 +87,6 @@ def resources_db(): yield # wait until caller context ends - -DATA_DIR = os.path.join(os.path.dirname(__file__), 'data') - - def _load_pyez_json_table(router_name, table_name): filename = f'{router_name}-{table_name}.json' with open(os.path.join(DATA_DIR, filename)) as f: @@ -141,6 +138,7 @@ def mocked_router(router_name): yield # stay in this block until caller context exits + @pytest.fixture def mocked_router_input_tables(router_name): # this is the mocked data used as input to pyez diff --git a/test/test_cli.py b/test/test_cli.py index 8fbccac7075efcb24f14b1fe6a5e8a785b013a7a..66a52d76225b7f4d3aedca733ef5d6a36bb1853f 100644 --- a/test/test_cli.py +++ b/test/test_cli.py @@ -14,4 +14,3 @@ def test_cli_happy_flow( '--config', config_filename, '--fqdn', router_name]) assert result.exit_code == 0 - diff --git a/test/test_db_model.py b/test/test_db_model.py index 7705b99e3b2145d7058a3a49d50f7303b24de1c2..e9034b94e9088fbdfad16a53e9dfb20ae383b957 100644 --- a/test/test_db_model.py +++ b/test/test_db_model.py @@ -53,7 +53,8 @@ def test_save_router_info(resources_db, router_name, mocked_router): assert expected_fpc_positions == fpc_positions for fpc in node.line_cards: - expected_ports = {p['name'] for p in fpc_position_dict[fpc.position]} + expected_ports = { + p['name'] for p in fpc_position_dict[fpc.position]} port_names = {p.name for p in fpc.ports} assert expected_ports == port_names