Skip to content
Snippets Groups Projects
Commit 63bfbb2d authored by Erik Reid's avatar Erik Reid
Browse files

pep8

parent 0b815656
No related branches found
No related tags found
No related merge requests found
...@@ -21,6 +21,7 @@ sys.path.insert(0, os.path.abspath( ...@@ -21,6 +21,7 @@ sys.path.insert(0, os.path.abspath(
os.path.dirname(__file__), os.path.dirname(__file__),
'..', '..', 'resource_management'))) '..', '..', 'resource_management')))
class RenderAsJSON(Directive): class RenderAsJSON(Directive):
# cf. https://stackoverflow.com/a/59883833 # cf. https://stackoverflow.com/a/59883833
...@@ -65,8 +66,6 @@ extensions = [ ...@@ -65,8 +66,6 @@ extensions = [
templates_path = ['_templates'] templates_path = ['_templates']
exclude_patterns = [] exclude_patterns = []
# -- Options for HTML output ------------------------------------------------- # -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#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' ...@@ -81,4 +80,3 @@ autodoc_typehints = 'none'
# Display todos by setting to True # Display todos by setting to True
todo_include_todos = True todo_include_todos = True
...@@ -31,7 +31,8 @@ import click ...@@ -31,7 +31,8 @@ import click
import logging import logging
from jsonschema import validate, ValidationError 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 from resource_management import db, config, environment
environment.setup_logging() environment.setup_logging()
...@@ -97,10 +98,11 @@ def cli(config, fqdn): ...@@ -97,10 +98,11 @@ def cli(config, fqdn):
validate(line_cards, LINE_CARDS_LIST_SCHEMA) validate(line_cards, LINE_CARDS_LIST_SCHEMA)
mysql_config = config["mysql"] mysql_config = config["mysql"]
dsn = db.mysql_dsn(mysql_config["username"], dsn = db.mysql_dsn(
mysql_config["password"], username=mysql_config["username"],
mysql_config["hostname"], password=mysql_config["password"],
mysql_config["dbname"]) hostname=mysql_config["hostname"],
db_name=mysql_config["dbname"])
logger.info("MYSQL DSN is: {0}".format(dsn)) logger.info("MYSQL DSN is: {0}".format(dsn))
db.init_db_model(dsn) db.init_db_model(dsn)
......
import contextlib import contextlib
import logging import logging
from typing import Optional, Union, Callable, Iterator from typing import Union, Iterator
from sqlalchemy import create_engine from sqlalchemy import create_engine
from sqlalchemy.exc import SQLAlchemyError from sqlalchemy.exc import SQLAlchemyError
......
...@@ -25,7 +25,11 @@ LINE_CARDS_LIST_SCHEMA = { ...@@ -25,7 +25,11 @@ LINE_CARDS_LIST_SCHEMA = {
'items': { 'items': {
'type': 'object', 'type': 'object',
'properties': { '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} 'speed': {'type': 'integer', 'minimum': 0}
}, },
'required': ['name', 'speed'], 'required': ['name', 'speed'],
...@@ -48,6 +52,7 @@ LINE_CARDS_LIST_SCHEMA = { ...@@ -48,6 +52,7 @@ LINE_CARDS_LIST_SCHEMA = {
} }
} }
@contextlib.contextmanager @contextlib.contextmanager
def device(hostname, ssh_config, port=830): def device(hostname, ssh_config, port=830):
......
...@@ -19,10 +19,10 @@ depends_on = None ...@@ -19,10 +19,10 @@ depends_on = None
def upgrade() -> None: def upgrade() -> None:
with op.batch_alter_table('ports') as batch_op: with op.batch_alter_table('ports') as batch_op:
batch_op.add_column( batch_op.add_column(
Column('speed', sa.Integer, nullable=False)), sa.Column('speed', sa.Integer, nullable=False),
insert_after='name' insert_after='name'
) )
def downgrade() -> None: def downgrade() -> None:
op.drop_column('ports','speed') op.drop_column('ports', 'speed')
...@@ -10,6 +10,7 @@ from sqlalchemy.pool import StaticPool ...@@ -10,6 +10,7 @@ from sqlalchemy.pool import StaticPool
from resource_management.db import model from resource_management.db import model
DATA_DIR = os.path.join(os.path.dirname(__file__), 'data')
HOSTNAMES = [ HOSTNAMES = [
'vmx', 'vmx',
'mx1.lab.office.geant.net', 'mx1.lab.office.geant.net',
...@@ -86,10 +87,6 @@ def resources_db(): ...@@ -86,10 +87,6 @@ def resources_db():
yield # wait until caller context ends 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): def _load_pyez_json_table(router_name, table_name):
filename = f'{router_name}-{table_name}.json' filename = f'{router_name}-{table_name}.json'
with open(os.path.join(DATA_DIR, filename)) as f: with open(os.path.join(DATA_DIR, filename)) as f:
...@@ -141,6 +138,7 @@ def mocked_router(router_name): ...@@ -141,6 +138,7 @@ def mocked_router(router_name):
yield # stay in this block until caller context exits yield # stay in this block until caller context exits
@pytest.fixture @pytest.fixture
def mocked_router_input_tables(router_name): def mocked_router_input_tables(router_name):
# this is the mocked data used as input to pyez # this is the mocked data used as input to pyez
......
...@@ -14,4 +14,3 @@ def test_cli_happy_flow( ...@@ -14,4 +14,3 @@ def test_cli_happy_flow(
'--config', config_filename, '--config', config_filename,
'--fqdn', router_name]) '--fqdn', router_name])
assert result.exit_code == 0 assert result.exit_code == 0
...@@ -53,7 +53,8 @@ def test_save_router_info(resources_db, router_name, mocked_router): ...@@ -53,7 +53,8 @@ def test_save_router_info(resources_db, router_name, mocked_router):
assert expected_fpc_positions == fpc_positions assert expected_fpc_positions == fpc_positions
for fpc in node.line_cards: 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} port_names = {p.name for p in fpc.ports}
assert expected_ports == port_names assert expected_ports == port_names
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment