From 63bfbb2d3c033b068167c621bf9775d615c1590d Mon Sep 17 00:00:00 2001 From: Erik Reid <erik.reid@geant.org> Date: Sun, 27 Nov 2022 17:18:38 +0100 Subject: [PATCH] pep8 --- docs/source/conf.py | 4 +--- resource_management/__init__.py | 1 - resource_management/cli.py | 12 +++++++----- resource_management/db/__init__.py | 2 +- resource_management/hardware/router.py | 7 ++++++- .../cdbd931a47d4_add_speed_column_to_ports_table.py | 4 ++-- test/conftest.py | 6 ++---- test/test_cli.py | 1 - test/test_db_model.py | 3 ++- 9 files changed, 21 insertions(+), 19 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 990f58a..f48683f 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 8b13789..e69de29 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 d354107..85c4e9d 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 b2c108a..6b3d5f7 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 13abe57..6be1a63 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 4baf5f8..9fb3a4a 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 fb80882..4b69717 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 8fbccac..66a52d7 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 7705b99..e9034b9 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 -- GitLab