Skip to content

Commit

Permalink
improvement(cleanup): remove backend from argus client
Browse files Browse the repository at this point in the history
Some cleanup work had to be done to better structure argus client for
less problematic management:
* Removed old db stuff, that cause confusion when searching for db/models
 related things. Along with old migration and prod dump scripts.
* moved common modules for backend and client to `common` module next to
 `backend` and `client` modules
* excluded `backend` module from client package. Including backend
might cause import error due backend-only required packages
* created unit tests for argus client package - build, install, basic import

closes: #480
  • Loading branch information
soyacz committed Oct 17, 2024
1 parent 49b4387 commit 4a6fb30
Show file tree
Hide file tree
Showing 35 changed files with 101 additions and 1,700 deletions.
2 changes: 1 addition & 1 deletion argus/backend/controller/testrun_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from argus.backend.service.testrun import TestRunService
from argus.backend.service.user import api_login_required
from argus.backend.util.common import get_payload
from argus.backend.util.enums import TestInvestigationStatus, TestStatus
from argus.common.enums import TestInvestigationStatus, TestStatus

bp = Blueprint('testrun_api', __name__, 'testrun')
bp.register_error_handler(Exception, handle_api_exception)
Expand Down
6 changes: 2 additions & 4 deletions argus/backend/plugins/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@
ArgusScheduleGroup,
ArgusSchedule,
ArgusScheduleTest,
ArgusScheduleAssignee,
ArgusUserView,
User
ArgusScheduleAssignee
)
from argus.backend.util.common import chunk
from argus.backend.util.enums import TestInvestigationStatus, TestStatus
from argus.common.enums import TestInvestigationStatus, TestStatus

LOGGER = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion argus/backend/plugins/driver_matrix_tests/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from argus.backend.plugins.core import PluginModelBase
from argus.backend.plugins.driver_matrix_tests.udt import TestCollection, TestSuite, TestCase, EnvironmentInfo
from argus.backend.plugins.driver_matrix_tests.raw_types import RawMatrixTestResult
from argus.backend.util.enums import TestStatus
from argus.common.enums import TestStatus


LOGGER = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion argus/backend/plugins/generic/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from argus.backend.models.web import ArgusRelease
from argus.backend.plugins.core import PluginModelBase
from argus.backend.plugins.generic.types import GenericRunFinishRequest, GenericRunSubmitRequest
from argus.backend.util.enums import TestStatus
from argus.common.enums import TestStatus


class GenericPluginException(Exception):
Expand Down
7 changes: 3 additions & 4 deletions argus/backend/plugins/sct/service.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import base64
from dataclasses import dataclass
from datetime import datetime
from functools import reduce
import logging
import math
import re
Expand All @@ -10,7 +9,7 @@
from flask import g
from argus.backend.models.web import ArgusEventTypes
from argus.backend.plugins.sct.testrun import SCTJunitReports, SCTTestRun, SubtestType
from argus.backend.plugins.sct.types import GeminiResultsRequest, PerformanceResultsRequest, ResourceUpdateRequest
from argus.common.sct_types import GeminiResultsRequest, PerformanceResultsRequest, ResourceUpdateRequest
from argus.backend.plugins.sct.udt import (
CloudInstanceDetails,
CloudResource,
Expand All @@ -22,7 +21,7 @@
)
from argus.backend.service.event_service import EventService
from argus.backend.util.common import get_build_number
from argus.backend.util.enums import NemesisStatus, ResourceState, TestStatus
from argus.common.enums import NemesisStatus, ResourceState, TestStatus

LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -488,4 +487,4 @@ def junit_get_all(run_id: str) -> list[SCTJunitReports]:

@staticmethod
def junit_get_single(run_id: str, file_name: str) -> SCTJunitReports:
return SCTJunitReports.get(test_id=run_id, file_name=file_name)
return SCTJunitReports.get(test_id=run_id, file_name=file_name)
2 changes: 1 addition & 1 deletion argus/backend/plugins/sct/udt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from cassandra.cqlengine.usertype import UserType
from cassandra.cqlengine import columns

from argus.backend.util.enums import ResourceState
from argus.common.enums import ResourceState


class PackageVersion(UserType):
Expand Down
6 changes: 3 additions & 3 deletions argus/backend/plugins/sirenada/model.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from datetime import datetime
from uuid import UUID, uuid4
from uuid import UUID
from cassandra.cqlengine import columns
from cassandra.cqlengine.usertype import UserType
from cassandra.cqlengine.models import Model
from argus.backend.db import ScyllaCluster
from argus.backend.models.web import ArgusRelease
from argus.backend.plugins.core import PluginModelBase
from argus.backend.plugins.sirenada.types import RawSirenadaRequest, SirenadaPluginException
from argus.backend.util.enums import TestStatus
from argus.common.sirenada_types import RawSirenadaRequest, SirenadaPluginException
from argus.common.enums import TestStatus


class SirenadaTest(UserType):
Expand Down
8 changes: 3 additions & 5 deletions argus/backend/service/client_service.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import operator
from dataclasses import asdict, is_dataclass
from datetime import datetime, timezone
from functools import partial
from dataclasses import asdict
from datetime import datetime
from uuid import UUID

from argus.backend.db import ScyllaCluster
from argus.backend.models.result import ArgusGenericResultMetadata, ArgusGenericResultData
from argus.backend.plugins.core import PluginModelBase
from argus.backend.plugins.loader import AVAILABLE_PLUGINS
from argus.backend.service.results_service import ResultsService, Cell
from argus.backend.util.enums import TestStatus
from argus.common.enums import TestStatus


class ClientException(Exception):
Expand Down
2 changes: 1 addition & 1 deletion argus/backend/service/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from cassandra.cqlengine.models import Model
from argus.backend.plugins.loader import all_plugin_models
from argus.backend.util.common import chunk, get_build_number
from argus.backend.util.enums import TestStatus, TestInvestigationStatus
from argus.common.enums import TestStatus, TestInvestigationStatus
from argus.backend.models.web import ArgusGithubIssue, ArgusRelease, ArgusGroup, ArgusTest,\
ArgusScheduleTest, ArgusTestRunComment, ArgusUserView
from argus.backend.db import ScyllaCluster
Expand Down
3 changes: 1 addition & 2 deletions argus/backend/service/testrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from cassandra.query import BatchStatement, ConsistencyLevel
from cassandra.cqlengine.query import BatchQuery
from argus.backend.db import ScyllaCluster
from argus.backend.models.result import ArgusGenericResultMetadata

from argus.backend.models.web import (
ArgusEvent,
Expand All @@ -38,7 +37,7 @@
from argus.backend.service.notification_manager import NotificationManagerService
from argus.backend.service.stats import ComparableTestStatus
from argus.backend.util.common import chunk, get_build_number, strip_html_tags
from argus.backend.util.enums import TestInvestigationStatus, TestStatus
from argus.common.enums import TestInvestigationStatus, TestStatus

LOGGER = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion argus/client/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import requests

from argus.backend.util.enums import TestStatus
from argus.common.enums import TestStatus
from argus.client.generic_result import GenericResultTable
from argus.client.sct.types import LogLink

Expand Down
4 changes: 2 additions & 2 deletions argus/client/driver_matrix_tests/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pathlib import Path
import click
import logging
from argus.backend.util.enums import TestStatus
from argus.common.enums import TestStatus

from argus.client.driver_matrix_tests.client import ArgusDriverMatrixClient

Expand Down Expand Up @@ -107,4 +107,4 @@ def finish_driver_matrix_run(api_key: str, base_url: str, run_id: str, status: s


if __name__ == "__main__":
cli()
cli()
2 changes: 1 addition & 1 deletion argus/client/driver_matrix_tests/client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from uuid import UUID
from argus.backend.util.enums import TestStatus
from argus.common.enums import TestStatus
from argus.client.base import ArgusClient


Expand Down
4 changes: 2 additions & 2 deletions argus/client/generic/cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import click
import logging
from argus.backend.util.enums import TestStatus

from argus.client.base import TestStatus
from argus.client.generic.client import ArgusGenericClient

LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -44,4 +44,4 @@ def finish_run(api_key: str, base_url: str, id: str, status: str, scylla_version


if __name__ == "__main__":
cli()
cli()
6 changes: 3 additions & 3 deletions argus/client/sct/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
from typing import Any
from uuid import UUID
from dataclasses import asdict
from argus.backend.plugins.sct.types import GeminiResultsRequest, PerformanceResultsRequest
from argus.backend.util.enums import ResourceState, TestStatus
from argus.common.sct_types import GeminiResultsRequest, PerformanceResultsRequest
from argus.common.enums import ResourceState, TestStatus
from argus.client.base import ArgusClient
from argus.client.sct.types import EventsInfo, LogLink, Package

Expand Down Expand Up @@ -298,4 +298,4 @@ def sct_submit_junit_report(self, file_name: str, raw_content: str) -> None:
"file_name": file_name,
"content": str(base64.encodebytes(bytes(raw_content, encoding="utf-8")), encoding="utf-8")
}
)
)
2 changes: 1 addition & 1 deletion argus/client/sirenada/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import TypedDict
from xml.etree import ElementTree

from argus.backend.plugins.sirenada.types import RawSirenadaRequest, RawSirenadaTestCase
from argus.common.sirenada_types import RawSirenadaRequest, RawSirenadaTestCase

from argus.client.base import ArgusClient

Expand Down
File renamed without changes.
19 changes: 19 additions & 0 deletions argus/client/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import shutil
from pathlib import Path

import pytest


@pytest.fixture(scope="module", autouse=True)
def test_dir():
return Path(__file__).parent


@pytest.fixture(scope="module", autouse=True)
def env_dir(test_dir):
env_dir = test_dir / 'test_env'
if env_dir.exists():
shutil.rmtree(env_dir)
yield env_dir
if env_dir.exists():
shutil.rmtree(env_dir)
48 changes: 48 additions & 0 deletions argus/client/tests/test_package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import subprocess
import venv
from pathlib import Path

import pytest


def run_command(command: list[str], cwd: str = None, env=None):
result = subprocess.run(command, cwd=cwd, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, env=env)
print(result.stdout)
return result


def create_virtualenv(env_dir: Path):
venv.create(env_dir, with_pip=True)
pip_path = env_dir / 'bin' / 'pip'
return pip_path


def extract_version_from_pyproject(pyproject_file: Path) -> str:
with pyproject_file.open() as file:
for line in file:
if line.strip().startswith("version"):
return line.split('=')[1].strip().strip('"')


def test_should_build_package():
run_command(['poetry', 'build'])


def test_should_create_env_and_install(test_dir: Path, env_dir: Path) -> None:
pyproject_file = test_dir.parents[2] / 'pyproject.toml'
version = extract_version_from_pyproject(pyproject_file)

dist_dir = test_dir.parents[2] / 'dist'
package_path = dist_dir / f"argus_alm-{version}-py3-none-any.whl"

pip_path = create_virtualenv(env_dir)
run_command([pip_path, 'install', str(package_path)])


def test_should_import_installed_package(env_dir):
python_path = env_dir / 'bin' / 'python'

run_command([python_path, '-c', 'import argus.client; import argus.common; '
'from argus.client.sct.client import ArgusSCTClient'], env={"PYTHONPATH": str(env_dir)})
with pytest.raises(subprocess.CalledProcessError):
run_command([python_path, '-c', 'import argus.client.tests.test_package'], env={"PYTHONPATH": str(env_dir)})
Empty file added argus/common/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 0 additions & 14 deletions argus/db/argus_json.py

This file was deleted.

Loading

0 comments on commit 4a6fb30

Please sign in to comment.