Skip to content

Commit

Permalink
Run isort
Browse files Browse the repository at this point in the history
  • Loading branch information
mxsasha committed Feb 23, 2023
1 parent f3afd08 commit 8cf25a1
Show file tree
Hide file tree
Showing 115 changed files with 603 additions and 351 deletions.
2 changes: 1 addition & 1 deletion irrd/conf/known_keys.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from irrd.conf import AUTH_SET_CREATION_COMMON_KEY
from irrd.rpsl.passwords import PASSWORD_HASHERS_ALL
from irrd.vendor.dotted.collection import DottedDict
from irrd.rpsl.rpsl_objects import OBJECT_CLASS_MAPPING, RPSLSet
from irrd.vendor.dotted.collection import DottedDict

# Note that sources are checked separately,
# and 'access_lists' is always permitted
Expand Down
12 changes: 9 additions & 3 deletions irrd/conf/test_conf.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import os
import signal
import textwrap
from typing import Dict

import pytest
import signal
import yaml
from typing import Dict

from . import get_setting, ConfigurationError, config_init, is_config_initialised, get_configuration
from . import (
ConfigurationError,
config_init,
get_configuration,
get_setting,
is_config_initialised,
)


@pytest.fixture()
Expand Down
17 changes: 8 additions & 9 deletions irrd/daemon/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python
# flake8: noqa: E402
import argparse
import grp
import logging
import multiprocessing
import os
Expand All @@ -9,25 +10,23 @@
import sys
import time
from pathlib import Path
from typing import Tuple, Optional
from typing import Optional, Tuple

import daemon
import grp
import psutil
from daemon.daemon import change_process_owner
from pid import PidFile, PidFileError

logger = logging.getLogger(__name__)
sys.path.append(str(Path(__file__).resolve().parents[2]))

from irrd.utils.process_support import ExceptionLoggingProcess, set_traceback_handler
from irrd.storage.preload import PreloadStoreManager
from irrd.server.whois.server import start_whois_server
from irrd.server.http.server import run_http_server
from irrd import ENV_MAIN_PROCESS_PID, __version__
from irrd.conf import CONFIG_PATH_DEFAULT, config_init, get_configuration, get_setting
from irrd.mirroring.scheduler import MirrorScheduler
from irrd.conf import config_init, CONFIG_PATH_DEFAULT, get_setting, get_configuration
from irrd import __version__, ENV_MAIN_PROCESS_PID

from irrd.server.http.server import run_http_server
from irrd.server.whois.server import start_whois_server
from irrd.storage.preload import PreloadStoreManager
from irrd.utils.process_support import ExceptionLoggingProcess, set_traceback_handler

# This file does not have a unit test, but is instead tested through
# the integration tests. Writing a unit test would be too complex.
Expand Down
54 changes: 37 additions & 17 deletions irrd/integration_tests/run.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,53 @@
import sys
import time
import unittest

import ujson

import base64
import email
import os
import requests
import signal
import socket
import sqlalchemy as sa
import subprocess
import sys
import textwrap
import yaml
from alembic import command, config
import time
import unittest
from pathlib import Path

import requests
import sqlalchemy as sa
import ujson
import yaml
from alembic import command, config
from python_graphql_client import GraphqlClient

from irrd.conf import config_init, PASSWORD_HASH_DUMMY_VALUE
from irrd.utils.rpsl_samples import (SAMPLE_MNTNER, SAMPLE_PERSON, SAMPLE_KEY_CERT, SIGNED_PERSON_UPDATE_VALID,
SAMPLE_AS_SET, SAMPLE_AUT_NUM, SAMPLE_DOMAIN, SAMPLE_FILTER_SET, SAMPLE_INET_RTR,
SAMPLE_INET6NUM, SAMPLE_INETNUM, SAMPLE_PEERING_SET, SAMPLE_ROLE, SAMPLE_ROUTE,
SAMPLE_ROUTE_SET, SAMPLE_ROUTE6, SAMPLE_RTR_SET, SAMPLE_AS_BLOCK)
from irrd.conf import PASSWORD_HASH_DUMMY_VALUE, config_init
from irrd.utils.rpsl_samples import (
SAMPLE_AS_BLOCK,
SAMPLE_AS_SET,
SAMPLE_AUT_NUM,
SAMPLE_DOMAIN,
SAMPLE_FILTER_SET,
SAMPLE_INET6NUM,
SAMPLE_INET_RTR,
SAMPLE_INETNUM,
SAMPLE_KEY_CERT,
SAMPLE_MNTNER,
SAMPLE_PEERING_SET,
SAMPLE_PERSON,
SAMPLE_ROLE,
SAMPLE_ROUTE,
SAMPLE_ROUTE6,
SAMPLE_ROUTE_SET,
SAMPLE_RTR_SET,
SIGNED_PERSON_UPDATE_VALID,
)
from irrd.utils.whois_client import whois_query, whois_query_irrd
from .constants import (EMAIL_SMTP_PORT, EMAIL_DISCARD_MSGS_COMMAND, EMAIL_RETURN_MSGS_COMMAND, EMAIL_SEPARATOR,
EMAIL_END)

from ..storage import translate_url
from .constants import (
EMAIL_DISCARD_MSGS_COMMAND,
EMAIL_END,
EMAIL_RETURN_MSGS_COMMAND,
EMAIL_SEPARATOR,
EMAIL_SMTP_PORT,
)

IRRD_ROOT_PATH = str(Path(__file__).resolve().parents[2])
sys.path.append(IRRD_ROOT_PATH)
Expand Down
5 changes: 2 additions & 3 deletions irrd/mirroring/mirror_runners_export.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os

import gzip
import logging
import os
import shutil
from pathlib import Path
from tempfile import NamedTemporaryFile
Expand All @@ -11,7 +10,7 @@
from irrd.rpki.status import RPKIStatus
from irrd.scopefilter.status import ScopeFilterStatus
from irrd.storage.database_handler import DatabaseHandler
from irrd.storage.queries import RPSLDatabaseQuery, DatabaseStatusQuery
from irrd.storage.queries import DatabaseStatusQuery, RPSLDatabaseQuery
from irrd.utils.text import remove_auth_hashes as remove_auth_hashes_func

EXPORT_PERMISSIONS = 0o644
Expand Down
9 changes: 5 additions & 4 deletions irrd/mirroring/mirror_runners_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,25 @@
import shutil
from io import BytesIO
from tempfile import NamedTemporaryFile
from typing import Optional, Tuple, Any, IO
from typing import IO, Any, Optional, Tuple
from urllib import request
from urllib.parse import urlparse
from urllib.error import URLError
from urllib.parse import urlparse

import requests

from irrd.conf import get_setting, RPKI_IRR_PSEUDO_SOURCE
from irrd.conf import RPKI_IRR_PSEUDO_SOURCE, get_setting
from irrd.conf.defaults import DEFAULT_SOURCE_NRTM_PORT
from irrd.routepref.routepref import update_route_preference_status
from irrd.rpki.importer import ROADataImporter, ROAParserException
from irrd.rpki.notifications import notify_rpki_invalid_owners
from irrd.rpki.validators import BulkRouteROAValidator
from irrd.routepref.routepref import update_route_preference_status
from irrd.scopefilter.validators import ScopeFilterValidator
from irrd.storage.database_handler import DatabaseHandler
from irrd.storage.event_stream import EventStreamPublisher
from irrd.storage.queries import DatabaseStatusQuery
from irrd.utils.whois_client import whois_query

from .parsers import MirrorFileImportParser, NRTMStreamParser

logger = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion irrd/mirroring/nrtm_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from irrd.conf import get_setting
from irrd.storage.database_handler import DatabaseHandler
from irrd.storage.queries import RPSLDatabaseJournalQuery, DatabaseStatusQuery
from irrd.storage.queries import DatabaseStatusQuery, RPSLDatabaseJournalQuery
from irrd.utils.text import remove_auth_hashes as remove_auth_hashes_func


Expand Down
4 changes: 2 additions & 2 deletions irrd/mirroring/nrtm_operation.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import logging
from typing import Optional, List
from typing import List, Optional

from irrd.rpki.validators import SingleRouteROAValidator
from irrd.rpsl.parser import UnknownRPSLObjectClassException
from irrd.rpsl.rpsl_objects import rpsl_object_from_text, RPSLKeyCert
from irrd.rpsl.rpsl_objects import RPSLKeyCert, rpsl_object_from_text
from irrd.scopefilter.validators import ScopeFilterValidator
from irrd.storage.database_handler import DatabaseHandler
from irrd.storage.models import DatabaseOperation, JournalEntryOrigin
Expand Down
11 changes: 6 additions & 5 deletions irrd/mirroring/parsers.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import logging
import re
from typing import List, Set, Optional
from typing import List, Optional, Set

from irrd.conf import get_setting
from irrd.rpki.validators import BulkRouteROAValidator
from irrd.rpsl.parser import UnknownRPSLObjectClassException, RPSLObject
from irrd.rpsl.rpsl_objects import rpsl_object_from_text, RPSLKeyCert
from irrd.rpsl.parser import RPSLObject, UnknownRPSLObjectClassException
from irrd.rpsl.rpsl_objects import RPSLKeyCert, rpsl_object_from_text
from irrd.scopefilter.validators import ScopeFilterValidator
from irrd.storage.database_handler import DatabaseHandler
from irrd.storage.models import DatabaseOperation, JournalEntryOrigin
from irrd.utils.text import split_paragraphs_rpsl, remove_last_modified
from .nrtm_operation import NRTMOperation
from irrd.utils.text import remove_last_modified, split_paragraphs_rpsl

from ..storage.queries import RPSLDatabaseQuery
from .nrtm_operation import NRTMOperation

logger = logging.getLogger(__name__)
nrtm_start_line_re = re.compile(r'^% *START *Version: *(?P<version>\d+) +(?P<source>[\w-]+) +(?P<first_serial>\d+)-(?P<last_serial>\d+)( FILTERED)?\n$', flags=re.MULTILINE)
Expand Down
22 changes: 13 additions & 9 deletions irrd/mirroring/scheduler.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import time
from collections import defaultdict

import gc
import logging
import multiprocessing

import signal
from setproctitle import setproctitle
import time
from collections import defaultdict
from typing import Dict

from irrd.conf import get_setting, RPKI_IRR_PSEUDO_SOURCE
from irrd.conf.defaults import DEFAULT_SOURCE_IMPORT_TIMER, DEFAULT_SOURCE_EXPORT_TIMER
from setproctitle import setproctitle

from irrd.conf import RPKI_IRR_PSEUDO_SOURCE, get_setting
from irrd.conf.defaults import DEFAULT_SOURCE_EXPORT_TIMER, DEFAULT_SOURCE_IMPORT_TIMER

from .mirror_runners_export import SourceExportRunner
from .mirror_runners_import import RPSLMirrorImportUpdateRunner, ROAImportRunner, \
ScopeFilterUpdateRunner, RoutePreferenceUpdateRunner
from .mirror_runners_import import (
ROAImportRunner,
RoutePreferenceUpdateRunner,
RPSLMirrorImportUpdateRunner,
ScopeFilterUpdateRunner,
)

logger = logging.getLogger(__name__)

Expand Down
5 changes: 3 additions & 2 deletions irrd/mirroring/tests/test_mirror_runners_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
from pathlib import Path
from unittest.mock import Mock

from irrd.rpki.status import RPKIStatus
from irrd.routepref.status import RoutePreferenceStatus
from irrd.rpki.status import RPKIStatus
from irrd.scopefilter.status import ScopeFilterStatus
from irrd.utils.test_utils import flatten_mock_calls
from ..mirror_runners_export import SourceExportRunner, EXPORT_PERMISSIONS

from ..mirror_runners_export import EXPORT_PERMISSIONS, SourceExportRunner


class TestSourceExportRunner:
Expand Down
13 changes: 9 additions & 4 deletions irrd/mirroring/tests/test_mirror_runners_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@

import pytest

from irrd.routepref.routepref import update_route_preference_status
from irrd.rpki.importer import ROAParserException
from irrd.rpki.validators import BulkRouteROAValidator
from irrd.routepref.routepref import update_route_preference_status
from irrd.storage.database_handler import DatabaseHandler
from irrd.scopefilter.validators import ScopeFilterValidator
from irrd.storage.database_handler import DatabaseHandler
from irrd.utils.test_utils import flatten_mock_calls

from ..mirror_runners_import import (
RPSLMirrorImportUpdateRunner, RPSLMirrorFullImportRunner, NRTMImportUpdateStreamRunner,
ROAImportRunner, ScopeFilterUpdateRunner, RoutePreferenceUpdateRunner
NRTMImportUpdateStreamRunner,
ROAImportRunner,
RoutePreferenceUpdateRunner,
RPSLMirrorFullImportRunner,
RPSLMirrorImportUpdateRunner,
ScopeFilterUpdateRunner,
)


Expand Down
5 changes: 3 additions & 2 deletions irrd/mirroring/tests/test_nrtm_generator.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import textwrap
from itertools import cycle, repeat
from unittest.mock import Mock

import pytest
import textwrap
from unittest.mock import Mock

from irrd.storage.models import DatabaseOperation

from ..nrtm_generator import NRTMGenerator, NRTMGeneratorException


Expand Down
12 changes: 9 additions & 3 deletions irrd/mirroring/tests/test_nrtm_operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@
from irrd.scopefilter.status import ScopeFilterStatus
from irrd.scopefilter.validators import ScopeFilterValidator
from irrd.storage.models import DatabaseOperation, JournalEntryOrigin
from irrd.utils.rpsl_samples import (SAMPLE_MNTNER, SAMPLE_UNKNOWN_CLASS,
SAMPLE_MALFORMED_EMPTY_LINE, SAMPLE_KEY_CERT,
KEY_CERT_SIGNED_MESSAGE_VALID, SAMPLE_ROUTE)
from irrd.utils.rpsl_samples import (
KEY_CERT_SIGNED_MESSAGE_VALID,
SAMPLE_KEY_CERT,
SAMPLE_MALFORMED_EMPTY_LINE,
SAMPLE_MNTNER,
SAMPLE_ROUTE,
SAMPLE_UNKNOWN_CLASS,
)

from ..nrtm_operation import NRTMOperation


Expand Down
36 changes: 28 additions & 8 deletions irrd/mirroring/tests/test_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,35 @@
from irrd.scopefilter.validators import ScopeFilterValidator
from irrd.storage.models import DatabaseOperation, JournalEntryOrigin
from irrd.utils.rpsl_samples import (
SAMPLE_ROUTE, SAMPLE_UNKNOWN_CLASS, SAMPLE_UNKNOWN_ATTRIBUTE, SAMPLE_MALFORMED_PK,
SAMPLE_ROUTE6, SAMPLE_KEY_CERT, KEY_CERT_SIGNED_MESSAGE_VALID, SAMPLE_LEGACY_IRRD_ARTIFACT,
SAMPLE_ROLE, SAMPLE_RTR_SET)
KEY_CERT_SIGNED_MESSAGE_VALID,
SAMPLE_KEY_CERT,
SAMPLE_LEGACY_IRRD_ARTIFACT,
SAMPLE_MALFORMED_PK,
SAMPLE_ROLE,
SAMPLE_ROUTE,
SAMPLE_ROUTE6,
SAMPLE_RTR_SET,
SAMPLE_UNKNOWN_ATTRIBUTE,
SAMPLE_UNKNOWN_CLASS,
)
from irrd.utils.test_utils import flatten_mock_calls
from .nrtm_samples import (SAMPLE_NRTM_V3, SAMPLE_NRTM_V1, SAMPLE_NRTM_V1_TOO_MANY_ITEMS,
SAMPLE_NRTM_INVALID_VERSION, SAMPLE_NRTM_V3_NO_END,
SAMPLE_NRTM_V3_SERIAL_GAP, SAMPLE_NRTM_V3_INVALID_MULTIPLE_START_LINES,
SAMPLE_NRTM_INVALID_NO_START_LINE, SAMPLE_NRTM_V3_SERIAL_OUT_OF_ORDER)
from ..parsers import NRTMStreamParser, MirrorFileImportParser, MirrorUpdateFileImportParser

from ..parsers import (
MirrorFileImportParser,
MirrorUpdateFileImportParser,
NRTMStreamParser,
)
from .nrtm_samples import (
SAMPLE_NRTM_INVALID_NO_START_LINE,
SAMPLE_NRTM_INVALID_VERSION,
SAMPLE_NRTM_V1,
SAMPLE_NRTM_V1_TOO_MANY_ITEMS,
SAMPLE_NRTM_V3,
SAMPLE_NRTM_V3_INVALID_MULTIPLE_START_LINES,
SAMPLE_NRTM_V3_NO_END,
SAMPLE_NRTM_V3_SERIAL_GAP,
SAMPLE_NRTM_V3_SERIAL_OUT_OF_ORDER,
)


@pytest.fixture
Expand Down
5 changes: 2 additions & 3 deletions irrd/mirroring/tests/test_scheduler.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import time

import threading
import time

from ..scheduler import MirrorScheduler, ScheduledTaskProcess, MAX_SIMULTANEOUS_RUNS
from ..scheduler import MAX_SIMULTANEOUS_RUNS, MirrorScheduler, ScheduledTaskProcess

thread_run_count = 0

Expand Down
Loading

0 comments on commit 8cf25a1

Please sign in to comment.