From c285066888e4c689bda5acae2d089e2af40143ed Mon Sep 17 00:00:00 2001 From: Patrik Segedy Date: Wed, 25 Sep 2024 18:34:21 +0200 Subject: [PATCH] chore: replace reorder-python-imports by isort black and reorder-python-imports are incompatibles https://github.com/asottile/reorder-python-imports/issues/366 https://github.com/asottile/reorder-python-imports/issues/367 https://github.com/psf/black/issues/4175 --- .pre-commit-config.yaml | 8 ++- cluster/cluster.py | 1 + common/bounded_executor.py | 1 + common/config.py | 1 + common/constants.py | 2 +- common/database_handler.py | 1 + common/feature_flags.py | 4 +- common/identity.py | 1 + common/logging.py | 1 + common/mqueue.py | 1 + common/peewee_conditions.py | 1 + common/peewee_database.py | 1 + common/peewee_model.py | 4 +- common/status_app.py | 1 + common/utils.py | 1 + common/vmaas_client.py | 1 + evaluator/common.py | 2 +- evaluator/evaluator.py | 10 +-- evaluator/logic.py | 16 ++--- evaluator/processor.py | 20 +++--- exploit_sync/exploit_sync.py | 1 + grouper/common.py | 1 + grouper/grouper.py | 8 ++- grouper/queue.py | 16 ++--- listener/advisor_processor.py | 16 ++--- listener/common.py | 1 + listener/inventory_processor.py | 20 +++--- listener/listener.py | 22 ++++--- listener/processor.py | 4 +- manager/admin.py | 3 +- manager/admin_handler.py | 13 ++-- manager/announcement_handler.py | 3 +- manager/base.py | 17 +++--- manager/cve_handler.py | 61 ++++++++++--------- manager/dashbar_handler.py | 27 ++++---- manager/dashboard_handler.py | 29 ++++----- manager/feature_handler.py | 2 +- manager/filters.py | 4 +- manager/main.py | 15 ++--- manager/playbook_handler.py | 5 +- manager/report_handler.py | 21 ++++--- manager/risk_handler.py | 3 +- manager/status_handler.py | 21 ++++--- manager/system_handler.py | 55 +++++++++-------- manager/version_handler.py | 3 +- manager/vulnerabilities_handler.py | 47 +++++++------- notificator/app.py | 1 + notificator/notificator.py | 12 ++-- notificator/notificator_queue.py | 1 + platform_mock/platform_mock.py | 2 +- platform_mock/traffic_generator.py | 1 - scripts/3scale-mock | 1 - scripts/turnpike-mock | 1 - taskomatic/jobs/common.py | 1 + taskomatic/jobs/delete_notifications.py | 1 + taskomatic/jobs/delete_systems.py | 1 + taskomatic/jobs/stale_systems.py | 2 +- taskomatic/jobs/usage_metrics.py | 1 + tests/conftest.py | 11 ++-- tests/manager_tests/conftest.py | 5 +- tests/manager_tests/test_admin_handler.py | 4 +- tests/manager_tests/test_apistatus_handler.py | 1 + tests/manager_tests/test_cve_handler.py | 1 + tests/manager_tests/test_dashbar_handler.py | 1 + tests/manager_tests/test_dashboard_handler.py | 1 + tests/manager_tests/test_links.py | 3 +- tests/manager_tests/test_manager.py | 3 +- tests/manager_tests/test_rbac_manager.py | 2 +- tests/manager_tests/test_readonly.py | 3 +- tests/manager_tests/test_report_handler.py | 2 +- tests/manager_tests/test_status_handler.py | 1 + tests/manager_tests/test_system_handler.py | 1 + .../test_vulnerabilities_handler.py | 1 + tests/manager_tests/vuln_testcase.py | 3 +- tests/notificator_tests/conftest.py | 1 + tests/notificator_tests/test_app.py | 3 +- tests/notificator_tests/test_notificator.py | 1 + .../test_notificator_conditions.py | 1 + tests/taskomatic_tests/conftest.py | 3 +- tests/taskomatic_tests/test_db_metrics.py | 1 + .../test_delete_notifications.py | 1 + tests/taskomatic_tests/test_delete_systems.py | 1 + tests/taskomatic_tests/test_rules_git_sync.py | 1 + tests/taskomatic_tests/test_stale_systems.py | 1 + tests/taskomatic_tests/test_usage_metrics.py | 1 + tests/vmaas_sync_tests/conftest.py | 3 +- tests/vmaas_sync_tests/test_vmaas_sync.py | 7 ++- tests/zz_database_tests/test_upgrade.py | 4 +- vmaas_sync/vmaas_sync.py | 3 +- 89 files changed, 343 insertions(+), 253 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e6eb359fc..f4f61ec42 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,7 +17,9 @@ repos: hooks: - id: flake8 files: "common|database|grouper|listener|evaluator|notificator|manager|vmaas_sync|taskomatic|scripts|exploit_sync|common|cluster|tests" -- repo: https://github.com/asottile/reorder-python-imports - rev: v3.13.0 +- repo: https://github.com/pycqa/isort + rev: 5.13.2 hooks: - - id: reorder-python-imports + - id: isort + name: isort + args: [--force-single-line, --profile=black] diff --git a/cluster/cluster.py b/cluster/cluster.py index 0107125ba..234011bc2 100644 --- a/cluster/cluster.py +++ b/cluster/cluster.py @@ -1,6 +1,7 @@ """ Cluster job """ + import os import subprocess from typing import List diff --git a/common/bounded_executor.py b/common/bounded_executor.py index 13cd8f8b9..6aeab0a9c 100644 --- a/common/bounded_executor.py +++ b/common/bounded_executor.py @@ -1,6 +1,7 @@ """ ThreadPoolExecutor wrapper to limit number of submited items. """ + from concurrent.futures import ThreadPoolExecutor from threading import BoundedSemaphore diff --git a/common/config.py b/common/config.py index a5a0a6e0f..46775de2a 100644 --- a/common/config.py +++ b/common/config.py @@ -1,6 +1,7 @@ """ Use Clowder config or env vars config. """ + import os import tempfile diff --git a/common/constants.py b/common/constants.py index 929a0887c..5badf12dc 100644 --- a/common/constants.py +++ b/common/constants.py @@ -1,12 +1,12 @@ """ Common constants declaration module. """ + from enum import Enum from enum import StrEnum from common.config import Config - CFG = Config() APP_VERSION = "2.40.8" diff --git a/common/database_handler.py b/common/database_handler.py index a17680824..51e7402b9 100644 --- a/common/database_handler.py +++ b/common/database_handler.py @@ -1,6 +1,7 @@ """ Module containing database handler class. """ + import asyncio import os import ssl diff --git a/common/feature_flags.py b/common/feature_flags.py index 4ac4f6880..c9b3e613a 100644 --- a/common/feature_flags.py +++ b/common/feature_flags.py @@ -1,6 +1,7 @@ """ Common feature flags with Unleash to be used for multiple apps """ + from os import path from pathlib import Path from uuid import uuid4 @@ -8,9 +9,10 @@ from UnleashClient import UnleashClient from UnleashClient.cache import FileCache -from .config import Config from common.logging import get_logger +from .config import Config + CFG = Config() APP_NAME = "vulnerability-engine" LOGGER = get_logger(__name__) diff --git a/common/identity.py b/common/identity.py index 9da68fee8..75114a98a 100644 --- a/common/identity.py +++ b/common/identity.py @@ -1,6 +1,7 @@ """ 3scale authentication functions. """ + import base64 import json diff --git a/common/logging.py b/common/logging.py index 02655c8ce..556609cef 100644 --- a/common/logging.py +++ b/common/logging.py @@ -1,6 +1,7 @@ """ Common logging functionality to be used for multiple apps """ + import json import logging import os diff --git a/common/mqueue.py b/common/mqueue.py index 329e74bf8..ea28aa365 100644 --- a/common/mqueue.py +++ b/common/mqueue.py @@ -1,4 +1,5 @@ """Module with classes for work with Kafka Message queue.""" + import asyncio import hashlib import json diff --git a/common/peewee_conditions.py b/common/peewee_conditions.py index b4a80f645..1212622c0 100644 --- a/common/peewee_conditions.py +++ b/common/peewee_conditions.py @@ -1,6 +1,7 @@ """ Module defines common conditions for queries in manager or other parts. """ + # pylint: disable=singleton-comparison,superfluous-parens from peewee import Expression from peewee import fn diff --git a/common/peewee_database.py b/common/peewee_database.py index 15102af94..59ff67a76 100644 --- a/common/peewee_database.py +++ b/common/peewee_database.py @@ -1,6 +1,7 @@ """ Postgresql settings for peewee mappings. """ + from playhouse.postgres_ext import PostgresqlExtDatabase from common.config import Config diff --git a/common/peewee_model.py b/common/peewee_model.py index 13869f652..c4f2da259 100644 --- a/common/peewee_model.py +++ b/common/peewee_model.py @@ -1,6 +1,7 @@ """ Database to peewee mappings """ + # pylint: disable=invalid-name from datetime import datetime from enum import Enum @@ -17,9 +18,10 @@ from peewee import UUIDField from playhouse.postgres_ext import BinaryJSONField +from common.config import Config + from .peewee_database import DB from .peewee_database import DB_READ_REPLICA -from common.config import Config CFG = Config() diff --git a/common/status_app.py b/common/status_app.py index 288e61f73..400e03cb0 100644 --- a/common/status_app.py +++ b/common/status_app.py @@ -2,6 +2,7 @@ Module represents health endpoint + prometheus metrics as one async server called status. """ + from aiohttp import web from prometheus_client import generate_latest diff --git a/common/utils.py b/common/utils.py index 225a20579..684da1145 100644 --- a/common/utils.py +++ b/common/utils.py @@ -1,6 +1,7 @@ """ Various utility functions. """ + import asyncio import json from datetime import datetime diff --git a/common/vmaas_client.py b/common/vmaas_client.py index 36f2a0643..5a6792ce6 100644 --- a/common/vmaas_client.py +++ b/common/vmaas_client.py @@ -1,6 +1,7 @@ """ Async VMaaS API client """ + import asyncio import ssl diff --git a/evaluator/common.py b/evaluator/common.py index e9b423ba5..969f34fe8 100644 --- a/evaluator/common.py +++ b/evaluator/common.py @@ -1,6 +1,7 @@ """ Vulnerability engine Evaluator component. """ + import json import re from collections import namedtuple @@ -14,7 +15,6 @@ from common.peewee_model import VulnerabilityState from common.utils import get_available_remediation_type - CFG = Config() PROMETHEUS_PORT = CFG.prometheus_port or str(CFG.evaluator_prometheus_port) PACKAGE_RE = re.compile(r"(([0-9]+):)?(?P[^:]+)-.*[^-:]+-.*") diff --git a/evaluator/evaluator.py b/evaluator/evaluator.py index 41b870b9d..43a450a28 100644 --- a/evaluator/evaluator.py +++ b/evaluator/evaluator.py @@ -1,6 +1,7 @@ """ Vulnerability engine evaluator component """ + import asyncio import json import signal @@ -9,10 +10,6 @@ from dateutil import parser from psycopg_pool.pool_async import AsyncConnectionPool -from .common import CFG -from .common import MESSAGE_PARSE_ERROR -from .common import PROMETHEUS_PORT -from .processor import EvaluatorProcessor from common.constants import EvaluatorMessageType from common.database_handler import setup_async_db_pool from common.feature_flags import initialize_unleash @@ -25,6 +22,11 @@ from common.utils import a_ensure_minimal_schema_version from common.utils import create_task_and_log +from .common import CFG +from .common import MESSAGE_PARSE_ERROR +from .common import PROMETHEUS_PORT +from .processor import EvaluatorProcessor + LOGGER = get_logger(__name__) diff --git a/evaluator/logic.py b/evaluator/logic.py index a2f808bb9..c7d81b05a 100644 --- a/evaluator/logic.py +++ b/evaluator/logic.py @@ -1,6 +1,7 @@ """ Vulnerability engine evaluator logic component """ + import json from datetime import datetime from typing import Dict @@ -15,26 +16,27 @@ from psycopg.types.json import Jsonb from psycopg_pool.pool_async import AsyncConnectionPool +from common.constants import format_vmaas_cve_endpoint +from common.logging import get_logger +from common.peewee_model import VulnerabilityState +from common.vmaas_client import vmaas_request + from .common import CFG +from .common import EVAL_PART_TIME +from .common import RULES_EVAL_TIME +from .common import VMAAS_EVAL_TIME from .common import CpeCache from .common import CveAdvisories from .common import CveCache from .common import CveImpactCache from .common import CveUnpatched -from .common import EVAL_PART_TIME from .common import ModuleCache from .common import PackageNameCache from .common import RuleCache -from .common import RULES_EVAL_TIME from .common import SystemPlatform from .common import SystemVulnerabilitiesRow -from .common import VMAAS_EVAL_TIME from .common import VmaasErrorException from .common import VulnerablePackageCache -from common.constants import format_vmaas_cve_endpoint -from common.logging import get_logger -from common.peewee_model import VulnerabilityState -from common.vmaas_client import vmaas_request LOGGER = get_logger(__name__) diff --git a/evaluator/processor.py b/evaluator/processor.py index 1186b5660..a36c1f604 100644 --- a/evaluator/processor.py +++ b/evaluator/processor.py @@ -1,6 +1,7 @@ """ Processing logic of grouped evaluator message for single system """ + import asyncio import json from datetime import datetime @@ -17,31 +18,32 @@ from psycopg.rows import dict_row from psycopg_pool.pool_async import AsyncConnectionPool +from common.logging import get_logger +from common.mqueue import MQWriter +from common.peewee_model import VulnerabilityState +from common.utils import executemany_fetchall +from common.utils import send_msg_to_payload_tracker +from common.utils import send_notifications +from common.utils import send_remediations_update + from .common import EMPTY_DATA_SKIP from .common import EVAL_COUNT from .common import EVAL_PART_TIME from .common import EVAL_PERFORMED_COUNT from .common import EVAL_TIME from .common import EVALUATED_EARLIER_SKIP -from .common import EvaluatorException from .common import INV_ID_NOT_FOUND from .common import PACKAGE_RE from .common import RECALC_EVENT_ERROR from .common import RECALC_PACKAGES_UNCHANGED_SKIP +from .common import VMAAS_ERRORS_SKIP +from .common import EvaluatorException from .common import RecalcEvent from .common import SystemPlatform from .common import SystemVulnerabilitiesRow -from .common import VMAAS_ERRORS_SKIP from .common import VmaasErrorException from .common import VulnerabilityDB from .logic import EvaluatorLogic -from common.logging import get_logger -from common.mqueue import MQWriter -from common.peewee_model import VulnerabilityState -from common.utils import executemany_fetchall -from common.utils import send_msg_to_payload_tracker -from common.utils import send_notifications -from common.utils import send_remediations_update LOGGER = get_logger(__name__) diff --git a/exploit_sync/exploit_sync.py b/exploit_sync/exploit_sync.py index 53a42e1d6..21dedb54d 100644 --- a/exploit_sync/exploit_sync.py +++ b/exploit_sync/exploit_sync.py @@ -1,6 +1,7 @@ """ Exploit sync job """ + import base64 import json diff --git a/grouper/common.py b/grouper/common.py index 3046cea58..68ebf9982 100644 --- a/grouper/common.py +++ b/grouper/common.py @@ -1,6 +1,7 @@ """ Common grouper tools. """ + import asyncio from dataclasses import dataclass from enum import Enum diff --git a/grouper/grouper.py b/grouper/grouper.py index e50aa5e26..e200dbea1 100644 --- a/grouper/grouper.py +++ b/grouper/grouper.py @@ -2,15 +2,13 @@ Vulnerability grouper pod, groups the messages from listener (inventory/evaluator uploads), and attempts to pair them. """ + import asyncio import json import signal from aiokafka.structs import ConsumerRecord -from .common import CFG -from .common import GrouperMessageType -from .queue import GrouperQueue from common.logging import get_logger from common.logging import init_logging from common.mqueue import MQReader @@ -18,6 +16,10 @@ from common.status_app import create_status_runner from common.utils import create_task_and_log +from .common import CFG +from .common import GrouperMessageType +from .queue import GrouperQueue + LOGGER = get_logger(__name__) diff --git a/grouper/queue.py b/grouper/queue.py index d9228ed4b..e4d7bf8d3 100644 --- a/grouper/queue.py +++ b/grouper/queue.py @@ -2,26 +2,28 @@ Grouper Queue, groups advisor and inventory msgs, and sends the grouped message to evaluator """ + import asyncio from datetime import datetime from datetime import timezone from typing import Dict +from common.constants import EvaluatorMessageType +from common.logging import get_logger +from common.mqueue import MQWriter +from common.utils import create_task_and_log +from common.utils import send_msg_to_payload_tracker + from .common import ADVISOR_QUEUE_SIZE -from .common import BoundedSemaphorePrometheus from .common import CFG from .common import CHANGED_SYSTEM from .common import INVENTORY_QUEUE_SIZE from .common import PAIR_HIT from .common import PAIR_MISS from .common import QUEUE_SIZE -from .common import QueueItem from .common import UNCHANGED_SYSTEM -from common.constants import EvaluatorMessageType -from common.logging import get_logger -from common.mqueue import MQWriter -from common.utils import create_task_and_log -from common.utils import send_msg_to_payload_tracker +from .common import BoundedSemaphorePrometheus +from .common import QueueItem LOGGER = get_logger(__name__) diff --git a/listener/advisor_processor.py b/listener/advisor_processor.py index bd1503714..b72438438 100644 --- a/listener/advisor_processor.py +++ b/listener/advisor_processor.py @@ -1,24 +1,26 @@ """ Advisor message processor """ + import hashlib import json from psycopg.rows import dict_row -from .common import AdvisorMsg +from common.logging import get_logger +from common.mqueue import MQWriter +from common.mqueue import Partitioners +from common.utils import reporter_allowed +from common.utils import send_msg_to_payload_tracker + from .common import CFG from .common import DATABASE_ERROR from .common import DELETED_UPLOADED_ADVISOR -from .common import ImportStatus from .common import NEW_SYSTEM_ADVISOR from .common import UPDATE_SYSTEM_ADVISOR +from .common import AdvisorMsg +from .common import ImportStatus from .processor import BaseProcessor -from common.logging import get_logger -from common.mqueue import MQWriter -from common.mqueue import Partitioners -from common.utils import reporter_allowed -from common.utils import send_msg_to_payload_tracker LOGGER = get_logger(__name__) diff --git a/listener/common.py b/listener/common.py index 6e1e0f651..6af6bcb20 100644 --- a/listener/common.py +++ b/listener/common.py @@ -1,6 +1,7 @@ """ Common variables for listener components. """ + import re from dataclasses import dataclass from enum import Enum diff --git a/listener/inventory_processor.py b/listener/inventory_processor.py index 24de0aec2..5d90a3432 100644 --- a/listener/inventory_processor.py +++ b/listener/inventory_processor.py @@ -1,21 +1,26 @@ """ Inventory message processor """ + import hashlib import json from urllib.parse import urlparse from psycopg.rows import dict_row +from common.logging import get_logger +from common.mqueue import MQWriter +from common.mqueue import Partitioners +from common.utils import executemany_fetchall +from common.utils import reporter_allowed +from common.utils import send_msg_to_payload_tracker + from .common import CFG from .common import DATABASE_ERROR from .common import DELETED_SYSTEM from .common import DELETED_SYSTEM_NOT_FOUND from .common import DELETED_SYSTEM_REPO from .common import DELETED_UPLOADED_INVENTORY -from .common import ImportStatus -from .common import InventoryMsg -from .common import InventoryMsgType from .common import NEW_REPO from .common import NEW_SYSTEM_INVENTORY from .common import NEW_SYSTEM_REPO @@ -27,13 +32,10 @@ from .common import UPDATED_SYSTEM from .common import UPDATED_SYSTEM_NOT_FOUND from .common import UPLOAD_NO_RPMDB +from .common import ImportStatus +from .common import InventoryMsg +from .common import InventoryMsgType from .processor import BaseProcessor -from common.logging import get_logger -from common.mqueue import MQWriter -from common.mqueue import Partitioners -from common.utils import executemany_fetchall -from common.utils import reporter_allowed -from common.utils import send_msg_to_payload_tracker LOGGER = get_logger(__name__) diff --git a/listener/listener.py b/listener/listener.py index ad11ef607..5c8550f7a 100644 --- a/listener/listener.py +++ b/listener/listener.py @@ -1,6 +1,7 @@ """ Listener main component """ + import asyncio import json import signal @@ -8,16 +9,6 @@ from aiokafka.structs import ConsumerRecord from psycopg_pool import AsyncConnectionPool -from .advisor_processor import AdvisorMsgProcessor -from .common import AdvisorMsg -from .common import CFG -from .common import InventoryMsg -from .common import InventoryMsgType -from .common import MESSAGE_PARSE_ERROR -from .common import PROCESS_MESSAGES -from .common import PROMETHEUS_PORT -from .common import SKIPPED_MESSAGES -from .inventory_processor import InventoryMsgProcessor from common.database_handler import setup_async_db_pool from common.logging import get_logger from common.logging import init_logging @@ -30,6 +21,17 @@ from common.utils import send_msg_to_payload_tracker from common.utils import validate_kafka_msg +from .advisor_processor import AdvisorMsgProcessor +from .common import CFG +from .common import MESSAGE_PARSE_ERROR +from .common import PROCESS_MESSAGES +from .common import PROMETHEUS_PORT +from .common import SKIPPED_MESSAGES +from .common import AdvisorMsg +from .common import InventoryMsg +from .common import InventoryMsgType +from .inventory_processor import InventoryMsgProcessor + LOGGER = get_logger(__name__) diff --git a/listener/processor.py b/listener/processor.py index 0ab63e51b..57b9d9a59 100644 --- a/listener/processor.py +++ b/listener/processor.py @@ -1,15 +1,17 @@ """ Inventory queue item processor """ + import asyncio from psycopg.rows import dict_row from psycopg_pool import AsyncConnectionPool -from .common import NEW_RH_ACCOUNT from common.logging import get_logger from common.mqueue import MQWriter +from .common import NEW_RH_ACCOUNT + LOGGER = get_logger(__name__) diff --git a/manager/admin.py b/manager/admin.py index de40baedf..64d70a7e5 100755 --- a/manager/admin.py +++ b/manager/admin.py @@ -2,11 +2,12 @@ """ vulnerability-manager-admin """ -from .main import create_app from common.config import Config from common.logging import get_logger from common.logging import init_logging +from .main import create_app + LOGGER = get_logger(__name__) CFG = Config() diff --git a/manager/admin_handler.py b/manager/admin_handler.py index a84a37202..98d8da7ad 100644 --- a/manager/admin_handler.py +++ b/manager/admin_handler.py @@ -8,22 +8,23 @@ from connexion import context from peewee import DatabaseError -from .base import ApplicationException -from .base import DeleteRequest -from .base import GetRequest -from .base import PutRequest -from .list_view import ListView from common.config import Config from common.logging import get_logger +from common.peewee_model import DB from common.peewee_model import Announcement from common.peewee_model import ContentVersion -from common.peewee_model import DB from common.peewee_model import InsightsRule from common.peewee_model import NotifiedAccounts from common.peewee_model import RHAccount from common.peewee_model import SystemPlatform from common.peewee_model import SystemVulnerabilities +from .base import ApplicationException +from .base import DeleteRequest +from .base import GetRequest +from .base import PutRequest +from .list_view import ListView + CFG = Config() LOGGER = get_logger(__name__) diff --git a/manager/announcement_handler.py b/manager/announcement_handler.py index 5377f78f0..0d4c21c40 100644 --- a/manager/announcement_handler.py +++ b/manager/announcement_handler.py @@ -3,9 +3,10 @@ """ import peewee -from .base import GetRequest from common.peewee_model import Announcement +from .base import GetRequest + class GetAnnouncement(GetRequest): """GET to /v1/announcement""" diff --git a/manager/base.py b/manager/base.py index 062695885..f7dc16dc7 100644 --- a/manager/base.py +++ b/manager/base.py @@ -20,27 +20,25 @@ from connexion import context from flask import Response +from peewee import JOIN +from peewee import SQL from peewee import Case from peewee import DataError from peewee import Expression -from peewee import fn -from peewee import JOIN from peewee import PeeweeException -from peewee import SQL +from peewee import fn from prometheus_client import Counter from prometheus_client import Histogram -from .filters import apply_filters -from .rbac_manager import RbacManager from common.config import Config from common.constants import remediation from common.identity import get_identity from common.logging import get_logger -from common.peewee_conditions import (system_is_active) -from common.peewee_model import CveMetadata -from common.peewee_model import CveRuleMapping +from common.peewee_conditions import system_is_active from common.peewee_model import DB from common.peewee_model import DB_READ_REPLICA +from common.peewee_model import CveMetadata +from common.peewee_model import CveRuleMapping from common.peewee_model import InsightsRule from common.peewee_model import InventoryHosts from common.peewee_model import RHAccount @@ -53,6 +51,9 @@ from common.utils import show_cves_without_errata from common.utils import validate_cve_cache_keepalive +from .filters import apply_filters +from .rbac_manager import RbacManager + LOGGER = get_logger(__name__) CFG = Config() diff --git a/manager/cve_handler.py b/manager/cve_handler.py index c8fe70cfb..382414ae9 100644 --- a/manager/cve_handler.py +++ b/manager/cve_handler.py @@ -7,41 +7,15 @@ import dateutil.parser from connexion import context +from peewee import JOIN +from peewee import SQL from peewee import DataError from peewee import DoesNotExist -from peewee import fn from peewee import IntegrityError -from peewee import JOIN -from peewee import SQL from peewee import Value +from peewee import fn from psycopg2 import IntegrityError as psycopg2IntegrityError -from .base import ApplicationException -from .base import cyndi_join -from .base import DEFAULT_BUSINESS_RISK -from .base import DEFAULT_REMEDIATION_FILTER -from .base import get_account_data -from .base import get_or_create_account -from .base import get_remediation_filter -from .base import get_rules_for_cves -from .base import GetRequest -from .base import OS_INFO_QUERY -from .base import OS_INFO_SORT -from .base import parse_int_list -from .base import parse_str_list -from .base import parse_tags -from .base import PatchRequest -from .base import reporter -from .base import STATUS_CACHE -from .base import transform_ids -from .base import transform_names -from .base import unique_bool_list -from .filters import apply_filters -from .filters import filter_types -from .list_view import ListView -from .rbac_manager import RbacFilterRoutePermissions -from .rbac_manager import RbacManager as RBAC -from .rbac_manager import RbacRoutePermissions from common.config import Config from common.constants import remediation from common.feature_flags import UNLEASH @@ -49,11 +23,11 @@ from common.peewee_conditions import system_is_abnv from common.peewee_conditions import system_is_active from common.peewee_conditions import system_is_vulnerable +from common.peewee_model import DB from common.peewee_model import BusinessRisk from common.peewee_model import CveAccountData from common.peewee_model import CveImpact from common.peewee_model import CveMetadata -from common.peewee_model import DB from common.peewee_model import InsightsRule from common.peewee_model import InventoryHosts from common.peewee_model import RHAccount @@ -65,6 +39,33 @@ from common.utils import format_datetime from common.utils import str_or_none +from .base import DEFAULT_BUSINESS_RISK +from .base import DEFAULT_REMEDIATION_FILTER +from .base import OS_INFO_QUERY +from .base import OS_INFO_SORT +from .base import STATUS_CACHE +from .base import ApplicationException +from .base import GetRequest +from .base import PatchRequest +from .base import cyndi_join +from .base import get_account_data +from .base import get_or_create_account +from .base import get_remediation_filter +from .base import get_rules_for_cves +from .base import parse_int_list +from .base import parse_str_list +from .base import parse_tags +from .base import reporter +from .base import transform_ids +from .base import transform_names +from .base import unique_bool_list +from .filters import apply_filters +from .filters import filter_types +from .list_view import ListView +from .rbac_manager import RbacFilterRoutePermissions +from .rbac_manager import RbacManager as RBAC +from .rbac_manager import RbacRoutePermissions + LOGGER = get_logger(__name__) CFG = Config() diff --git a/manager/dashbar_handler.py b/manager/dashbar_handler.py index e4b683bb8..e6b81f351 100644 --- a/manager/dashbar_handler.py +++ b/manager/dashbar_handler.py @@ -2,22 +2,11 @@ Module for /dashbar API """ from connexion import context -from peewee import Case -from peewee import fn from peewee import JOIN from peewee import SQL +from peewee import Case +from peewee import fn -from .base import cyndi_join -from .base import DEFAULT_REMEDIATION_FILTER -from .base import get_account_data -from .base import GetRequest -from .base import is_not_cacheable_request -from .base import is_valid_cache -from .base import parse_tags -from .filters import apply_filters -from .filters import filter_types -from .rbac_manager import RbacManager as RBAC -from .rbac_manager import RbacRoutePermissions from common.config import Config from common.feature_flags import UNLEASH from common.logging import get_logger @@ -31,6 +20,18 @@ from common.peewee_model import SystemPlatform from common.peewee_model import SystemVulnerabilities +from .base import DEFAULT_REMEDIATION_FILTER +from .base import GetRequest +from .base import cyndi_join +from .base import get_account_data +from .base import is_not_cacheable_request +from .base import is_valid_cache +from .base import parse_tags +from .filters import apply_filters +from .filters import filter_types +from .rbac_manager import RbacManager as RBAC +from .rbac_manager import RbacRoutePermissions + LOGGER = get_logger(__name__) CFG = Config() diff --git a/manager/dashboard_handler.py b/manager/dashboard_handler.py index a0538cb5b..65ced9e4a 100644 --- a/manager/dashboard_handler.py +++ b/manager/dashboard_handler.py @@ -6,22 +6,9 @@ from datetime import timezone from connexion import context -from peewee import fn from peewee import SQL +from peewee import fn -from .base import cyndi_join -from .base import DEFAULT_REMEDIATION_FILTER -from .base import get_account_data -from .base import get_system_count -from .base import GetRequest -from .base import is_not_cacheable_request -from .base import is_valid_cache -from .base import parse_tags -from .base import round_to_100_percent -from .filters import apply_filters -from .filters import filter_types -from .rbac_manager import RbacManager as RBAC -from .rbac_manager import RbacRoutePermissions from common.config import Config from common.feature_flags import UNLEASH from common.logging import get_logger @@ -36,6 +23,20 @@ from common.peewee_model import SystemPlatform from common.peewee_model import SystemVulnerabilities +from .base import DEFAULT_REMEDIATION_FILTER +from .base import GetRequest +from .base import cyndi_join +from .base import get_account_data +from .base import get_system_count +from .base import is_not_cacheable_request +from .base import is_valid_cache +from .base import parse_tags +from .base import round_to_100_percent +from .filters import apply_filters +from .filters import filter_types +from .rbac_manager import RbacManager as RBAC +from .rbac_manager import RbacRoutePermissions + LOGGER = get_logger(__name__) CFG = Config() FILTERS = [filter_types.SYSTEM_TAGS, diff --git a/manager/feature_handler.py b/manager/feature_handler.py index 976ea3b76..ecf80d249 100644 --- a/manager/feature_handler.py +++ b/manager/feature_handler.py @@ -7,8 +7,8 @@ from common.peewee_model import RHAccount from manager.base import ApplicationException from manager.base import DeleteRequest -from manager.base import get_account_data from manager.base import PatchRequest +from manager.base import get_account_data from manager.rbac_manager import RbacManager as RBAC from manager.rbac_manager import RbacRoutePermissions diff --git a/manager/filters.py b/manager/filters.py index 025624cc7..a274d6ce6 100644 --- a/manager/filters.py +++ b/manager/filters.py @@ -4,10 +4,10 @@ from copy import copy from enum import Enum -from peewee import Expression -from peewee import fn from peewee import SQL +from peewee import Expression from peewee import Value +from peewee import fn from common.constants import HostType from common.constants import remediation diff --git a/manager/main.py b/manager/main.py index f8a919790..30e448ed9 100755 --- a/manager/main.py +++ b/manager/main.py @@ -18,13 +18,6 @@ from prometheus_client import generate_latest from prometheus_client import multiprocess -from .base import forbidden_missing_entitlement -from .base import forbidden_rbac -from .base import init_status_cache as _init_status_cache -from .base import MissingEntitlementException -from .base import wait_on_cyndi as _wait_on_cyndi -from .middlewares import ErrorHandlerMiddleware -from .rbac_manager import RbacException from common.config import Config from common.constants import APP_VERSION from common.feature_flags import initialize_unleash @@ -33,6 +26,14 @@ from common.peewee_database import DB from common.peewee_database import DB_READ_REPLICA +from .base import MissingEntitlementException +from .base import forbidden_missing_entitlement +from .base import forbidden_rbac +from .base import init_status_cache as _init_status_cache +from .base import wait_on_cyndi as _wait_on_cyndi +from .middlewares import ErrorHandlerMiddleware +from .rbac_manager import RbacException + LOGGER = get_logger(__name__) CFG = Config() diff --git a/manager/playbook_handler.py b/manager/playbook_handler.py index 67591b229..7dcd705b8 100644 --- a/manager/playbook_handler.py +++ b/manager/playbook_handler.py @@ -4,11 +4,12 @@ from peewee import DoesNotExist from peewee import Value +from common.peewee_model import InsightsRule +from common.peewee_model import Playbook + from .base import GetRequest from .rbac_manager import RbacManager as RBAC from .rbac_manager import RbacRoutePermissions -from common.peewee_model import InsightsRule -from common.peewee_model import Playbook class GetTemplate(GetRequest): diff --git a/manager/report_handler.py b/manager/report_handler.py index 0963ee578..b28475d77 100644 --- a/manager/report_handler.py +++ b/manager/report_handler.py @@ -6,19 +6,10 @@ from datetime import timezone from connexion import context -from peewee import fn from peewee import JOIN from peewee import SQL +from peewee import fn -from .base import cyndi_join -from .base import DEFAULT_REMEDIATION_FILTER -from .base import get_account_data -from .base import get_system_count_by_type -from .base import GetRequest -from .base import is_valid_cache -from .base import round_to_100_percent -from .rbac_manager import RbacManager as RBAC -from .rbac_manager import RbacRoutePermissions from common.config import Config from common.feature_flags import UNLEASH from common.logging import get_logger @@ -33,6 +24,16 @@ from common.peewee_model import SystemPlatform from common.peewee_model import SystemVulnerabilities +from .base import DEFAULT_REMEDIATION_FILTER +from .base import GetRequest +from .base import cyndi_join +from .base import get_account_data +from .base import get_system_count_by_type +from .base import is_valid_cache +from .base import round_to_100_percent +from .rbac_manager import RbacManager as RBAC +from .rbac_manager import RbacRoutePermissions + LOGGER = get_logger(__name__) CFG = Config() diff --git a/manager/risk_handler.py b/manager/risk_handler.py index 6347cc3f2..6b41257ea 100644 --- a/manager/risk_handler.py +++ b/manager/risk_handler.py @@ -1,9 +1,10 @@ """ Module for /business_risk API endpoint """ -from .base import GetRequest from common.peewee_model import BusinessRisk +from .base import GetRequest + class GetRisk(GetRequest): """GET to /v1/business_risk""" diff --git a/manager/status_handler.py b/manager/status_handler.py index fca988bca..b0e62cbe6 100644 --- a/manager/status_handler.py +++ b/manager/status_handler.py @@ -11,25 +11,18 @@ from typing import Tuple from uuid import UUID -from peewee import DataError from peewee import EXCLUDED -from peewee import fn +from peewee import DataError from peewee import IntegrityError from peewee import Query from peewee import ValuesList +from peewee import fn from psycopg2 import IntegrityError as psycopg2IntegrityError -from .base import cyndi_join -from .base import get_or_create_account -from .base import GetRequest -from .base import parse_str_or_list -from .base import PatchRequest -from .rbac_manager import RbacManager as RBAC -from .rbac_manager import RbacRoutePermissions from common.logging import get_logger +from common.peewee_model import DB from common.peewee_model import CveAccountData from common.peewee_model import CveMetadata -from common.peewee_model import DB from common.peewee_model import InsightsRule from common.peewee_model import RHAccount from common.peewee_model import Status @@ -39,6 +32,14 @@ from common.peewee_model import SystemVulnerablePackage from common.peewee_model import VulnerablePackageCVE +from .base import GetRequest +from .base import PatchRequest +from .base import cyndi_join +from .base import get_or_create_account +from .base import parse_str_or_list +from .rbac_manager import RbacManager as RBAC +from .rbac_manager import RbacRoutePermissions + LOGGER = get_logger(__name__) StatusPair = namedtuple("StatusPair", ["status_id", "status_text"]) diff --git a/manager/system_handler.py b/manager/system_handler.py index 7625efef4..6c04f58d8 100644 --- a/manager/system_handler.py +++ b/manager/system_handler.py @@ -3,31 +3,49 @@ """ import dateutil.parser from connexion import context +from peewee import JOIN +from peewee import SQL from peewee import Case from peewee import DoesNotExist -from peewee import fn -from peewee import JOIN from peewee import NodeList -from peewee import SQL from peewee import Value +from peewee import fn + +from common.config import Config +from common.constants import remediation +from common.feature_flags import UNLEASH +from common.logging import get_logger +from common.peewee_conditions import system_is_active +from common.peewee_conditions import system_is_vulnerable +from common.peewee_model import BusinessRisk +from common.peewee_model import CveAccountData +from common.peewee_model import CveImpact +from common.peewee_model import CveMetadata +from common.peewee_model import InsightsRule +from common.peewee_model import InventoryHosts +from common.peewee_model import SystemCveData +from common.peewee_model import SystemPlatform +from common.peewee_model import SystemVulnerabilities +from common.peewee_model import SystemVulnerablePackage +from common.peewee_model import VulnerablePackageCVE -from .base import ApplicationException from .base import CVE_SYNOPSIS_SORT -from .base import cyndi_join from .base import DEFAULT_BUSINESS_RISK from .base import DEFAULT_REMEDIATION_FILTER -from .base import get_account_data -from .base import get_remediation_filter -from .base import GetRequest from .base import OS_INFO_QUERY from .base import OS_INFO_SORT +from .base import STATUS_CACHE +from .base import ApplicationException +from .base import GetRequest +from .base import PatchRequest +from .base import cyndi_join +from .base import get_account_data +from .base import get_remediation_filter from .base import parse_int_list from .base import parse_str_list from .base import parse_str_or_list from .base import parse_tags -from .base import PatchRequest from .base import reporter -from .base import STATUS_CACHE from .base import transform_ids from .base import transform_names from .base import unique_bool_list @@ -38,23 +56,6 @@ from .rbac_manager import RbacFilterRoutePermissions from .rbac_manager import RbacManager as RBAC from .rbac_manager import RbacRoutePermissions -from common.config import Config -from common.constants import remediation -from common.feature_flags import UNLEASH -from common.logging import get_logger -from common.peewee_conditions import system_is_active -from common.peewee_conditions import system_is_vulnerable -from common.peewee_model import BusinessRisk -from common.peewee_model import CveAccountData -from common.peewee_model import CveImpact -from common.peewee_model import CveMetadata -from common.peewee_model import InsightsRule -from common.peewee_model import InventoryHosts -from common.peewee_model import SystemCveData -from common.peewee_model import SystemPlatform -from common.peewee_model import SystemVulnerabilities -from common.peewee_model import SystemVulnerablePackage -from common.peewee_model import VulnerablePackageCVE LOGGER = get_logger(__name__) CFG = Config() diff --git a/manager/version_handler.py b/manager/version_handler.py index 0101824bd..5af5ac542 100644 --- a/manager/version_handler.py +++ b/manager/version_handler.py @@ -3,11 +3,12 @@ """ from peewee import DoesNotExist -from .base import GetRequest from common.constants import APP_VERSION from common.logging import get_logger from common.peewee_model import DbVersion +from .base import GetRequest + LOGGER = get_logger(__name__) diff --git a/manager/vulnerabilities_handler.py b/manager/vulnerabilities_handler.py index 0830a36df..674e146f9 100644 --- a/manager/vulnerabilities_handler.py +++ b/manager/vulnerabilities_handler.py @@ -3,28 +3,46 @@ """ import dateutil.parser from connexion import context -from peewee import Case -from peewee import fn from peewee import JOIN from peewee import SQL +from peewee import Case from peewee import Value +from peewee import fn + +from common.config import Config +from common.constants import HostType +from common.feature_flags import UNLEASH +from common.peewee_conditions import system_is_active +from common.peewee_conditions import system_is_vulnerable +from common.peewee_model import BusinessRisk +from common.peewee_model import CveAccountCache +from common.peewee_model import CveAccountData +from common.peewee_model import CveImpact +from common.peewee_model import CveMetadata +from common.peewee_model import CveRuleMapping +from common.peewee_model import InsightsRule +from common.peewee_model import SystemCveData +from common.peewee_model import SystemPlatform +from common.peewee_model import SystemVulnerabilities +from common.peewee_model import SystemVulnerablePackage +from common.peewee_model import VulnerablePackageCVE -from .base import cyndi_join from .base import DEFAULT_BUSINESS_RISK from .base import DEFAULT_REMEDIATION_FILTER +from .base import STATUS_CACHE +from .base import GetRequest +from .base import PostRequest +from .base import cyndi_join from .base import get_account_data from .base import get_remediation_filter from .base import get_rules_for_cves from .base import get_system_count_by_type -from .base import GetRequest from .base import is_not_cacheable_request from .base import is_valid_cache from .base import parse_int_list from .base import parse_str_list from .base import parse_tags -from .base import PostRequest from .base import remove_str_nulls -from .base import STATUS_CACHE from .base import transform_ids from .base import transform_names from .base import unique_bool_list @@ -34,23 +52,6 @@ from .rbac_manager import RbacFilterRoutePermissions from .rbac_manager import RbacManager as RBAC from .rbac_manager import RbacRoutePermissions -from common.config import Config -from common.constants import HostType -from common.feature_flags import UNLEASH -from common.peewee_conditions import system_is_active -from common.peewee_conditions import system_is_vulnerable -from common.peewee_model import BusinessRisk -from common.peewee_model import CveAccountCache -from common.peewee_model import CveAccountData -from common.peewee_model import CveImpact -from common.peewee_model import CveMetadata -from common.peewee_model import CveRuleMapping -from common.peewee_model import InsightsRule -from common.peewee_model import SystemCveData -from common.peewee_model import SystemPlatform -from common.peewee_model import SystemVulnerabilities -from common.peewee_model import SystemVulnerablePackage -from common.peewee_model import VulnerablePackageCVE CFG = Config() diff --git a/notificator/app.py b/notificator/app.py index 0dc6edc34..271a4e483 100644 --- a/notificator/app.py +++ b/notificator/app.py @@ -1,6 +1,7 @@ """ Notificator api handlers """ + from aiohttp import web from .notificator_queue import NotificatorQueue diff --git a/notificator/notificator.py b/notificator/notificator.py index 9cada2fdb..21d3424b7 100644 --- a/notificator/notificator.py +++ b/notificator/notificator.py @@ -2,6 +2,7 @@ Notificator service. Service sends notifications to the notifications backend. """ + import asyncio import json import signal @@ -9,11 +10,6 @@ from datetime import timedelta from datetime import timezone -from .app import CacheHandler -from .app import create_notif_app_runner -from .app import create_notificator_app -from .notificator_queue import NotificatorQueue -from .notificator_queue import QueueItem from common import mqueue from common.config import Config from common.database_handler import setup_db_pool @@ -23,6 +19,12 @@ from common.status_app import create_status_app from common.status_app import create_status_runner +from .app import CacheHandler +from .app import create_notif_app_runner +from .app import create_notificator_app +from .notificator_queue import NotificatorQueue +from .notificator_queue import QueueItem + CFG = Config() LOGGER = get_logger(__name__) NOTIFICATOR_PERIOD = 3 * 60 # 3 minutes diff --git a/notificator/notificator_queue.py b/notificator/notificator_queue.py index d648d32b7..4d421edb4 100644 --- a/notificator/notificator_queue.py +++ b/notificator/notificator_queue.py @@ -1,6 +1,7 @@ """ NotificatorQueue, processes potential notifications from queues. """ + import asyncio from datetime import datetime from datetime import timedelta diff --git a/platform_mock/platform_mock.py b/platform_mock/platform_mock.py index 240bb54d7..fc366e9ac 100644 --- a/platform_mock/platform_mock.py +++ b/platform_mock/platform_mock.py @@ -7,9 +7,9 @@ import uuid from datetime import datetime from datetime import timezone +from distutils.util import strtobool from data.rules import RULES -from distutils.util import strtobool from insights import make_metadata from insights import rule from insights import run diff --git a/platform_mock/traffic_generator.py b/platform_mock/traffic_generator.py index 71f687e83..17f4f8724 100755 --- a/platform_mock/traffic_generator.py +++ b/platform_mock/traffic_generator.py @@ -20,7 +20,6 @@ from data.yum_repos import LEN_AVAILABLE_REPOS - class Generator: '''Base message generator class''' diff --git a/scripts/3scale-mock b/scripts/3scale-mock index 49058a9b6..914723991 100755 --- a/scripts/3scale-mock +++ b/scripts/3scale-mock @@ -6,7 +6,6 @@ import os import sys from uuid import UUID - DEFAULT_IDENTITY_FILE = os.environ["HOME"] + "/.3scale-mock" DEFAULT_IDENTITY = """ { diff --git a/scripts/turnpike-mock b/scripts/turnpike-mock index efc9cd17e..4f22a5e39 100755 --- a/scripts/turnpike-mock +++ b/scripts/turnpike-mock @@ -5,7 +5,6 @@ import json import os import sys - DEFAULT_IDENTITY_FILE = os.environ["HOME"] + "/.turnpike-mock" DEFAULT_IDENTITY = """ { diff --git a/taskomatic/jobs/common.py b/taskomatic/jobs/common.py index 7f02bcdf5..918e20132 100644 --- a/taskomatic/jobs/common.py +++ b/taskomatic/jobs/common.py @@ -1,6 +1,7 @@ """ Common code shared between taskomatic modules """ + import psycopg2 from common.config import Config diff --git a/taskomatic/jobs/delete_notifications.py b/taskomatic/jobs/delete_notifications.py index cfc6f3763..37251ae8e 100644 --- a/taskomatic/jobs/delete_notifications.py +++ b/taskomatic/jobs/delete_notifications.py @@ -1,6 +1,7 @@ """ Periodic cleanup of sent notifications """ + from datetime import datetime from datetime import timedelta from datetime import timezone diff --git a/taskomatic/jobs/delete_systems.py b/taskomatic/jobs/delete_systems.py index 90e79b191..1cf45ef3b 100644 --- a/taskomatic/jobs/delete_systems.py +++ b/taskomatic/jobs/delete_systems.py @@ -1,6 +1,7 @@ """ Periodic cleanup of deleted systems """ + from datetime import datetime from datetime import timedelta diff --git a/taskomatic/jobs/stale_systems.py b/taskomatic/jobs/stale_systems.py index abe960841..c769615dd 100644 --- a/taskomatic/jobs/stale_systems.py +++ b/taskomatic/jobs/stale_systems.py @@ -1,11 +1,11 @@ """ Periodic discovery of stale systems """ + from common.logging import get_logger from common.logging import init_logging from taskomatic.jobs.common import get_conn - LOGGER = get_logger(__name__) diff --git a/taskomatic/jobs/usage_metrics.py b/taskomatic/jobs/usage_metrics.py index 954eb7c78..34821a0e3 100644 --- a/taskomatic/jobs/usage_metrics.py +++ b/taskomatic/jobs/usage_metrics.py @@ -1,6 +1,7 @@ """ Feature and product usage metrics. """ + import datetime import io import time diff --git a/tests/conftest.py b/tests/conftest.py index 5f08c6292..cfa1f843f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -8,14 +8,15 @@ import pytest from psycopg_pool import AsyncConnectionPool +from common.config import Config + +from .utils import TESTS_DIR +from .utils import VE_CYNDI_DATA from .utils import check_open_port from .utils import get_free_port from .utils import get_pg_class from .utils import restore_db from .utils import set_env -from .utils import TESTS_DIR -from .utils import VE_CYNDI_DATA -from common.config import Config VMAAS_MOCK = TESTS_DIR.joinpath("scripts", "vmaas_mock.py") VMAAS_HOST = "localhost" @@ -29,7 +30,9 @@ @pytest.fixture(scope="session") def monkeypatch_session(): """Monkeypatch for session scoped fixtures.""" - from _pytest.monkeypatch import MonkeyPatch # pylint: disable=import-outside-toplevel + from _pytest.monkeypatch import ( + MonkeyPatch, # pylint: disable=import-outside-toplevel + ) mpatch = MonkeyPatch() yield mpatch diff --git a/tests/manager_tests/conftest.py b/tests/manager_tests/conftest.py index 7e29a5e4f..709d85588 100644 --- a/tests/manager_tests/conftest.py +++ b/tests/manager_tests/conftest.py @@ -8,13 +8,14 @@ import pytest from peewee import PostgresqlDatabase -from ..utils import restore_db -from ..utils import truncate_db_version from common import database_handler from common import peewee_database from common.feature_flags import UNLEASH from common.feature_flags import UnleashClient +from ..utils import restore_db +from ..utils import truncate_db_version + peewee_database.DB = PostgresqlDatabase(None) POSTGRESQL_USER = "ve_db_user_manager" diff --git a/tests/manager_tests/test_admin_handler.py b/tests/manager_tests/test_admin_handler.py index e79846206..5353b4dc7 100644 --- a/tests/manager_tests/test_admin_handler.py +++ b/tests/manager_tests/test_admin_handler.py @@ -1,6 +1,7 @@ """ Vulnerability manager tests - Admin Handler. """ + # pylint: disable=too-many-public-methods import datetime import subprocess @@ -9,9 +10,10 @@ import requests from psycopg2.tz import FixedOffsetTimezone -from .vuln_testcase import FlaskTestCaseAdmin from common.peewee_model import DB +from .vuln_testcase import FlaskTestCaseAdmin + PID = 1368 VACUUMED_TABLE = "system_platform" VACUUMED_USER_TABLES = ["system_vulnerabilities_active_184", "system_vulnerabilities_inactive"] diff --git a/tests/manager_tests/test_apistatus_handler.py b/tests/manager_tests/test_apistatus_handler.py index 51f6dbf60..b1e5f298e 100644 --- a/tests/manager_tests/test_apistatus_handler.py +++ b/tests/manager_tests/test_apistatus_handler.py @@ -1,6 +1,7 @@ """ Unit tests for api status handler """ + # pylint: disable=missing-docstring,too-many-public-methods,invalid-name from .vuln_testcase import FlaskTestCase diff --git a/tests/manager_tests/test_cve_handler.py b/tests/manager_tests/test_cve_handler.py index 47311aa15..0e1bb76a4 100644 --- a/tests/manager_tests/test_cve_handler.py +++ b/tests/manager_tests/test_cve_handler.py @@ -1,4 +1,5 @@ """Unit tests for cve_handler""" + # pylint: disable=missing-docstring,too-many-public-methods,invalid-name import pytest diff --git a/tests/manager_tests/test_dashbar_handler.py b/tests/manager_tests/test_dashbar_handler.py index aebdd7751..c3c6e384e 100644 --- a/tests/manager_tests/test_dashbar_handler.py +++ b/tests/manager_tests/test_dashbar_handler.py @@ -1,6 +1,7 @@ """ Dashbar tests """ + import pytest from .vuln_testcase import FlaskTestCase diff --git a/tests/manager_tests/test_dashboard_handler.py b/tests/manager_tests/test_dashboard_handler.py index 3aecb1c5d..f996acff4 100644 --- a/tests/manager_tests/test_dashboard_handler.py +++ b/tests/manager_tests/test_dashboard_handler.py @@ -1,4 +1,5 @@ """Unit tests for report handler""" + # pylint: disable=missing-docstring import pytest diff --git a/tests/manager_tests/test_links.py b/tests/manager_tests/test_links.py index aa747c8b9..660fb2bba 100644 --- a/tests/manager_tests/test_links.py +++ b/tests/manager_tests/test_links.py @@ -5,11 +5,12 @@ """ import math -from .vuln_testcase import FlaskTestCase from common.peewee_model import SystemPlatform from manager.base import InvalidArgumentException from manager.list_view import ListView +from .vuln_testcase import FlaskTestCase + SORTABLE = { "id": SystemPlatform.id, "inventory_id": SystemPlatform.inventory_id, diff --git a/tests/manager_tests/test_manager.py b/tests/manager_tests/test_manager.py index b7510b905..684aebc40 100644 --- a/tests/manager_tests/test_manager.py +++ b/tests/manager_tests/test_manager.py @@ -7,13 +7,14 @@ import pytest -from .vuln_testcase import FlaskTestCase from common.config import Config from manager.base import Request from manager.base import round_to_100_percent from manager.status_handler import PatchStatus from manager.vulnerabilities_handler import GetCves +from .vuln_testcase import FlaskTestCase + CSV_EXPORT_ENDPOINTS = ( "cves/CVE-2016-1/affected_systems", "systems", diff --git a/tests/manager_tests/test_rbac_manager.py b/tests/manager_tests/test_rbac_manager.py index da244c44e..c2bc74c75 100644 --- a/tests/manager_tests/test_rbac_manager.py +++ b/tests/manager_tests/test_rbac_manager.py @@ -7,7 +7,6 @@ from connexion import context import manager.rbac_manager -from .vuln_testcase import FlaskTestCase from manager.rbac_filters import filter_excluded from manager.rbac_manager import RbacAction from manager.rbac_manager import RbacApp @@ -16,6 +15,7 @@ from manager.rbac_manager import RbacPermission from manager.rbac_manager import RbacResource +from .vuln_testcase import FlaskTestCase RBAC_RESPONSE = { "data": [ diff --git a/tests/manager_tests/test_readonly.py b/tests/manager_tests/test_readonly.py index 26b5cdfa4..ea3521f1c 100644 --- a/tests/manager_tests/test_readonly.py +++ b/tests/manager_tests/test_readonly.py @@ -3,9 +3,10 @@ """ Manager read only mode tests. """ -from .vuln_testcase import FlaskTestCase from common.config import Config +from .vuln_testcase import FlaskTestCase + CSV_EXPORT_ENDPOINTS = ( "cves/CVE-2016-1/affected_systems", "systems", diff --git a/tests/manager_tests/test_report_handler.py b/tests/manager_tests/test_report_handler.py index 6eb5d9b69..776496e7e 100644 --- a/tests/manager_tests/test_report_handler.py +++ b/tests/manager_tests/test_report_handler.py @@ -1,10 +1,10 @@ """Unit tests for report handler""" + # pylint: disable=missing-docstring,too-many-public-methods,invalid-name import pytest from .vuln_testcase import FlaskTestCase - DEFAULT_RETVAL = { "system_count": 0, "system_count_per_type": {"edge": 0, "rpmdnf": 0}, diff --git a/tests/manager_tests/test_status_handler.py b/tests/manager_tests/test_status_handler.py index 9baf03d27..376a85efa 100644 --- a/tests/manager_tests/test_status_handler.py +++ b/tests/manager_tests/test_status_handler.py @@ -1,4 +1,5 @@ """Unit tests for status_handler""" + # pylint: disable=missing-docstring,too-many-public-methods,invalid-name from .vuln_testcase import FlaskTestCase diff --git a/tests/manager_tests/test_system_handler.py b/tests/manager_tests/test_system_handler.py index 090fc4627..975b46908 100644 --- a/tests/manager_tests/test_system_handler.py +++ b/tests/manager_tests/test_system_handler.py @@ -1,4 +1,5 @@ """Unit tests for status_handler""" + # pylint: disable=missing-docstring,too-many-public-methods,invalid-name import dateutil.parser import pytest diff --git a/tests/manager_tests/test_vulnerabilities_handler.py b/tests/manager_tests/test_vulnerabilities_handler.py index cbcfbe6fe..0e677c2a5 100644 --- a/tests/manager_tests/test_vulnerabilities_handler.py +++ b/tests/manager_tests/test_vulnerabilities_handler.py @@ -1,4 +1,5 @@ """Unit tests for status_handler""" + # pylint: disable=missing-docstring,too-many-public-methods,invalid-name import pytest diff --git a/tests/manager_tests/vuln_testcase.py b/tests/manager_tests/vuln_testcase.py index 47efa64b4..d41835279 100644 --- a/tests/manager_tests/vuln_testcase.py +++ b/tests/manager_tests/vuln_testcase.py @@ -10,9 +10,10 @@ import pytest from box import Box -from .schemas import SCHEMA_MAP from manager import main +from .schemas import SCHEMA_MAP + URL_BASE = "/api/vulnerability/v1" IDENTITY = { diff --git a/tests/notificator_tests/conftest.py b/tests/notificator_tests/conftest.py index 384405732..27e7dfb95 100644 --- a/tests/notificator_tests/conftest.py +++ b/tests/notificator_tests/conftest.py @@ -1,6 +1,7 @@ """ Fixtures for notificator tests """ + import asyncpg import pytest from aiohttp import test_utils diff --git a/tests/notificator_tests/test_app.py b/tests/notificator_tests/test_app.py index 8f63ef6ac..7ec692510 100644 --- a/tests/notificator_tests/test_app.py +++ b/tests/notificator_tests/test_app.py @@ -1,12 +1,13 @@ """ Notificator handlers unit tests """ + import asyncio import pytest -from notificator.notificator import NotificationType from notificator.notificator import NOTIFICATOR_PERIOD +from notificator.notificator import NotificationType from notificator.notificator import NotificatorConditions from notificator.notificator_queue import NotificatorQueue diff --git a/tests/notificator_tests/test_notificator.py b/tests/notificator_tests/test_notificator.py index 24d86a03a..a5768feb5 100644 --- a/tests/notificator_tests/test_notificator.py +++ b/tests/notificator_tests/test_notificator.py @@ -1,6 +1,7 @@ """ Notificator unit tests """ + import json import pytest diff --git a/tests/notificator_tests/test_notificator_conditions.py b/tests/notificator_tests/test_notificator_conditions.py index 1abce2770..bd209461f 100644 --- a/tests/notificator_tests/test_notificator_conditions.py +++ b/tests/notificator_tests/test_notificator_conditions.py @@ -1,6 +1,7 @@ """ Notificator conditions unit tests """ + import pytest from common.peewee_model import NotificationType diff --git a/tests/taskomatic_tests/conftest.py b/tests/taskomatic_tests/conftest.py index de48e90c1..1babdd0b8 100644 --- a/tests/taskomatic_tests/conftest.py +++ b/tests/taskomatic_tests/conftest.py @@ -6,10 +6,11 @@ from aiohttp import web from tornado.httpclient import AsyncHTTPClient -from ..utils import restore_db from common import database_handler from taskomatic import taskomatic +from ..utils import restore_db + @pytest.fixture(scope="module") def pg_db_conn(pg_db_mod): diff --git a/tests/taskomatic_tests/test_db_metrics.py b/tests/taskomatic_tests/test_db_metrics.py index e2c6ce246..d72a3c323 100644 --- a/tests/taskomatic_tests/test_db_metrics.py +++ b/tests/taskomatic_tests/test_db_metrics.py @@ -1,6 +1,7 @@ """ Unit tests for db_metrics taskomatic job """ + import taskomatic.jobs.db_metrics as dm from common.database_handler import DatabasePoolConnection diff --git a/tests/taskomatic_tests/test_delete_notifications.py b/tests/taskomatic_tests/test_delete_notifications.py index f5f519e88..2248e1423 100644 --- a/tests/taskomatic_tests/test_delete_notifications.py +++ b/tests/taskomatic_tests/test_delete_notifications.py @@ -1,6 +1,7 @@ """ Unit tests for delete_notifications taskomatic job """ + import taskomatic.jobs.delete_notifications as dn from common.database_handler import DatabasePoolConnection diff --git a/tests/taskomatic_tests/test_delete_systems.py b/tests/taskomatic_tests/test_delete_systems.py index 776a96db7..1171b3510 100644 --- a/tests/taskomatic_tests/test_delete_systems.py +++ b/tests/taskomatic_tests/test_delete_systems.py @@ -1,6 +1,7 @@ """ Unit tests for delete_systems taskomatic job """ + import taskomatic.jobs.delete_systems as ds from common.database_handler import DatabasePoolConnection diff --git a/tests/taskomatic_tests/test_rules_git_sync.py b/tests/taskomatic_tests/test_rules_git_sync.py index a3fefebb0..566b52606 100644 --- a/tests/taskomatic_tests/test_rules_git_sync.py +++ b/tests/taskomatic_tests/test_rules_git_sync.py @@ -1,6 +1,7 @@ """ Unit tests for rules_git_sync taskomatic job """ + from os import path from pathlib import Path diff --git a/tests/taskomatic_tests/test_stale_systems.py b/tests/taskomatic_tests/test_stale_systems.py index 29e7d8987..2ad616bcf 100644 --- a/tests/taskomatic_tests/test_stale_systems.py +++ b/tests/taskomatic_tests/test_stale_systems.py @@ -1,6 +1,7 @@ """ Unit tests for stale_systems taskomatic job """ + import taskomatic.jobs.stale_systems as ss from common.database_handler import DatabasePoolConnection diff --git a/tests/taskomatic_tests/test_usage_metrics.py b/tests/taskomatic_tests/test_usage_metrics.py index 2e1beb97b..19a911b44 100644 --- a/tests/taskomatic_tests/test_usage_metrics.py +++ b/tests/taskomatic_tests/test_usage_metrics.py @@ -1,6 +1,7 @@ """ Unit tests for db_metrics taskomatic job """ + import pytest import taskomatic.jobs.usage_metrics as um diff --git a/tests/vmaas_sync_tests/conftest.py b/tests/vmaas_sync_tests/conftest.py index 43e9e0d05..2454a18b5 100644 --- a/tests/vmaas_sync_tests/conftest.py +++ b/tests/vmaas_sync_tests/conftest.py @@ -3,9 +3,10 @@ import psycopg2 import pytest -from ..utils import restore_db from common import database_handler +from ..utils import restore_db + @pytest.fixture(scope="module") def pg_db_conn(pg_db_mod): diff --git a/tests/vmaas_sync_tests/test_vmaas_sync.py b/tests/vmaas_sync_tests/test_vmaas_sync.py index a9a3e1d76..ceee01fe2 100644 --- a/tests/vmaas_sync_tests/test_vmaas_sync.py +++ b/tests/vmaas_sync_tests/test_vmaas_sync.py @@ -8,17 +8,18 @@ import logging import vmaas_sync.vmaas_sync as vmaas_sync -from ..scripts.vmaas_mock import CVES_RESPONSE -from ..scripts.vmaas_mock import REPOS_RESPONSE from common import constants from common.database_handler import DatabasePool +from vmaas_sync.vmaas_sync import LOGGER from vmaas_sync.vmaas_sync import _get_last_repobased_eval_tms from vmaas_sync.vmaas_sync import _select_repo_based_inventory_ids from vmaas_sync.vmaas_sync import _set_last_repobased_eval_tms -from vmaas_sync.vmaas_sync import LOGGER from vmaas_sync.vmaas_sync import re_evaluate_systems from vmaas_sync.vmaas_sync import sync_cve_md +from ..scripts.vmaas_mock import CVES_RESPONSE +from ..scripts.vmaas_mock import REPOS_RESPONSE + class TestMqueueWriter: """Pretends to know how to send kafka msgs""" diff --git a/tests/zz_database_tests/test_upgrade.py b/tests/zz_database_tests/test_upgrade.py index edb265335..9f3aebd0d 100644 --- a/tests/zz_database_tests/test_upgrade.py +++ b/tests/zz_database_tests/test_upgrade.py @@ -11,10 +11,10 @@ from git import Repo import common.database_handler + +from ..utils import VULN_ENG_DIR from ..utils import get_pg_class from ..utils import set_env -from ..utils import VULN_ENG_DIR - UPGRADE_FROM = os.getenv("UPGRADE_FROM", "4448350601fc0b9f0fb65b4e49e0af8f66018587") UPGRADE_TO = os.getenv("UPGRADE_TO", None) diff --git a/vmaas_sync/vmaas_sync.py b/vmaas_sync/vmaas_sync.py index 4d10f8b32..506fbc2cd 100644 --- a/vmaas_sync/vmaas_sync.py +++ b/vmaas_sync/vmaas_sync.py @@ -1,4 +1,5 @@ """VMaaS sync module.""" + import asyncio import datetime as dt import json @@ -16,9 +17,9 @@ from common import mqueue from common import utils from common.config import Config -from common.constants import EvaluatorMessageType from common.constants import VMAAS_CVES_ENDPOINT from common.constants import VMAAS_REPOS_ENDPOINT +from common.constants import EvaluatorMessageType from common.database_handler import DatabasePool from common.database_handler import DatabasePoolConnection from common.database_handler import NamedCursor