diff --git a/src/aap_eda/api/serializers/__init__.py b/src/aap_eda/api/serializers/__init__.py index 2272a7e82..642a61a5c 100644 --- a/src/aap_eda/api/serializers/__init__.py +++ b/src/aap_eda/api/serializers/__init__.py @@ -61,7 +61,6 @@ RulesetOutSerializer, RulesetSerializer, ) -from .tasks import TaskRefSerializer, TaskSerializer from .user import ( AwxTokenCreateSerializer, AwxTokenSerializer, @@ -94,9 +93,6 @@ "RulesetSerializer", "RuleOutSerializer", "RuleSerializer", - # tasks - "TaskRefSerializer", - "TaskSerializer", # activations "ActivationSerializer", "ActivationListSerializer", diff --git a/src/aap_eda/api/serializers/project.py b/src/aap_eda/api/serializers/project.py index e325c2759..745d07c57 100644 --- a/src/aap_eda/api/serializers/project.py +++ b/src/aap_eda/api/serializers/project.py @@ -30,7 +30,6 @@ class Meta: "git_hash", "import_state", "import_error", - "import_task_id", "created_at", "modified_at", ] @@ -98,7 +97,6 @@ class Meta: "git_hash", "import_state", "import_error", - "import_task_id", "created_at", "modified_at", ] @@ -126,7 +124,6 @@ def to_representation(self, project): "credential": credential, "import_state": project["import_state"], "import_error": project["import_error"], - "import_task_id": project["import_task_id"], "created_at": project["created_at"], "modified_at": project["modified_at"], } diff --git a/src/aap_eda/api/serializers/tasks.py b/src/aap_eda/api/serializers/tasks.py deleted file mode 100644 index 995067636..000000000 --- a/src/aap_eda/api/serializers/tasks.py +++ /dev/null @@ -1,46 +0,0 @@ -# Copyright 2023 Red Hat, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -from drf_spectacular.utils import extend_schema_field -from rest_framework import serializers -from rest_framework.reverse import reverse -from rq.job import JobStatus - -from aap_eda.core.tasking import Job - - -class TaskRefSerializer(serializers.Serializer): - id = serializers.UUIDField() - href = serializers.SerializerMethodField() - - @extend_schema_field(serializers.URLField) - def get_href(self, data: dict): - return reverse( - "task-detail", args=[data["id"]], request=self.context["request"] - ) - - -class TaskSerializer(serializers.Serializer): - id = serializers.UUIDField() - status = serializers.SerializerMethodField() - created_at = serializers.DateTimeField(allow_null=True) - enqueued_at = serializers.DateTimeField(allow_null=True) - started_at = serializers.DateTimeField(allow_null=True) - finished_at = serializers.DateTimeField(allow_null=True, source="ended_at") - result = serializers.JSONField() - - @extend_schema_field( - serializers.ChoiceField(choices=[x.value for x in JobStatus]) - ) - def get_status(self, instance: Job) -> str: - return instance.get_status() diff --git a/src/aap_eda/api/urls.py b/src/aap_eda/api/urls.py index 96a174ec4..0a4d24062 100644 --- a/src/aap_eda/api/urls.py +++ b/src/aap_eda/api/urls.py @@ -31,7 +31,6 @@ router.register("rulesets", views.RulesetViewSet) router.register("rules", views.RuleViewSet) router.register("roles", views.RoleViewSet) -router.register("tasks", views.TaskViewSet, basename="task") router.register("activations", views.ActivationViewSet) router.register("activation-instances", views.ActivationInstanceViewSet) router.register("audit-rules", views.AuditRuleViewSet) diff --git a/src/aap_eda/api/views/__init__.py b/src/aap_eda/api/views/__init__.py index ea4b3e433..bc514bc49 100644 --- a/src/aap_eda/api/views/__init__.py +++ b/src/aap_eda/api/views/__init__.py @@ -23,7 +23,6 @@ RulesetViewSet, RuleViewSet, ) -from .tasks import TaskViewSet from .user import CurrentUserAwxTokenViewSet, CurrentUserView, UserViewSet __all__ = ( @@ -38,8 +37,6 @@ "RulebookViewSet", "RulesetViewSet", "RuleViewSet", - # tasks - "TaskViewSet", # activations "ActivationViewSet", "ActivationInstanceViewSet", diff --git a/src/aap_eda/api/views/tasks.py b/src/aap_eda/api/views/tasks.py deleted file mode 100644 index b50fc2030..000000000 --- a/src/aap_eda/api/views/tasks.py +++ /dev/null @@ -1,68 +0,0 @@ -# Copyright 2023 Red Hat, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -from itertools import chain -from typing import Iterator, Optional - -from drf_spectacular.types import OpenApiTypes -from drf_spectacular.utils import OpenApiParameter, extend_schema -from rest_framework import exceptions, status -from rest_framework.response import Response -from rest_framework.viewsets import ViewSet - -from aap_eda.api import serializers -from aap_eda.core.tasking import Job, get_queue - - -class TaskViewSet(ViewSet): - @extend_schema( - responses={status.HTTP_200_OK: serializers.TaskSerializer}, - ) - def list(self, _request): - jobs = list_jobs() - serializer = serializers.TaskSerializer(jobs, many=True) - return Response(serializer.data) - - @extend_schema( - parameters=[ - OpenApiParameter("id", OpenApiTypes.UUID, OpenApiParameter.PATH) - ], - responses={ - status.HTTP_200_OK: serializers.TaskSerializer, - }, - ) - def retrieve(self, _request, pk): - job = get_job(pk) - if job is None: - raise exceptions.NotFound - serializer = serializers.TaskSerializer(job) - return Response(serializer.data) - - -def list_jobs() -> Iterator[Job]: - queue = get_queue() - all_job_ids = chain( - queue.get_job_ids(), - queue.started_job_registry.get_job_ids(), - queue.failed_job_registry.get_job_ids(), - queue.scheduled_job_registry.get_job_ids(), - queue.finished_job_registry.get_job_ids(), - queue.canceled_job_registry.get_job_ids(), - queue.deferred_job_registry.get_job_ids(), - ) - return map(queue.fetch_job, all_job_ids) - - -def get_job(job_id: str) -> Optional[Job]: - queue = get_queue() - return queue.fetch_job(job_id) diff --git a/src/aap_eda/core/enums.py b/src/aap_eda/core/enums.py index 7db5467d2..22cee3a5e 100644 --- a/src/aap_eda/core/enums.py +++ b/src/aap_eda/core/enums.py @@ -42,10 +42,8 @@ class ResourceType(DjangoStrEnum): ACTIVATION_INSTANCE = "activation_instance" AUDIT_RULE = "audit_rule" AUDIT_EVENT = "audit_event" - TASK = "task" USER = "user" PROJECT = "project" - INVENTORY = "inventory" EXTRA_VAR = "extra_var" RULEBOOK = "rulebook" ROLE = "role" @@ -63,13 +61,6 @@ class Action(DjangoStrEnum): RESTART = "restart" -class InventorySource(DjangoStrEnum): - PROJECT = "project" - COLLECTION = "collection" - USER_DEFINED = "user_defined" - EXECUTION_ENV = "execution_env" - - # TODO: rename to "RulebookProcessStatus" or "ParentProcessStatus" class ActivationStatus(DjangoStrEnum): STARTING = "starting" diff --git a/src/aap_eda/core/management/commands/create_initial_data.py b/src/aap_eda/core/management/commands/create_initial_data.py index 4009bc4d9..9a39b37b1 100644 --- a/src/aap_eda/core/management/commands/create_initial_data.py +++ b/src/aap_eda/core/management/commands/create_initial_data.py @@ -36,10 +36,8 @@ "activation_instance": ["read", "delete"], "audit_rule": ["read"], "audit_event": ["read"], - "task": ["read"], "user": ["create", "read", "update", "delete"], "project": ["create", "read", "update", "delete"], - "inventory": ["create", "read", "update", "delete"], "extra_var": ["create", "read", "update", "delete"], "rulebook": ["create", "read", "update", "delete"], "role": ["create", "read", "update", "delete"], @@ -56,9 +54,7 @@ "activation_instance": ["read"], "audit_rule": ["read"], "audit_event": ["read"], - "task": ["read"], "project": ["create", "read", "update", "delete"], - "inventory": ["create", "read", "update", "delete"], "extra_var": ["create", "read", "update", "delete"], "rulebook": ["create", "read", "update", "delete"], "decision_environment": ["create", "read", "update", "delete"], @@ -86,9 +82,7 @@ "activation_instance": ["read", "delete"], "audit_rule": ["read"], "audit_event": ["read"], - "task": ["read"], "project": ["create", "read", "update", "delete"], - "inventory": ["create", "read", "update", "delete"], "extra_var": ["create", "read", "update", "delete"], "rulebook": ["create", "read", "update", "delete"], "decision_environment": ["create", "read", "update", "delete"], @@ -107,9 +101,7 @@ "activation_instance": ["read"], "audit_rule": ["read"], "audit_event": ["read"], - "task": ["read"], "project": ["read"], - "inventory": ["read"], "extra_var": ["read"], "rulebook": ["read"], "decision_environment": ["read"], @@ -125,10 +117,8 @@ "activation_instance": ["read"], "audit_rule": ["read"], "audit_event": ["read"], - "task": ["read"], "user": ["read"], "project": ["read"], - "inventory": ["read"], "extra_var": ["read"], "rulebook": ["read"], "role": ["read"], @@ -145,9 +135,7 @@ "activation_instance": ["read"], "audit_rule": ["read"], "audit_event": ["read"], - "task": ["read"], "project": ["read"], - "inventory": ["read"], "extra_var": ["read"], "rulebook": ["read"], "decision_environment": ["read"], diff --git a/src/aap_eda/core/migrations/0023_alter_permission_resource_type_delete_inventory.py b/src/aap_eda/core/migrations/0023_alter_permission_resource_type_delete_inventory.py new file mode 100644 index 000000000..a1c92729e --- /dev/null +++ b/src/aap_eda/core/migrations/0023_alter_permission_resource_type_delete_inventory.py @@ -0,0 +1,34 @@ +# Generated by Django 4.2.7 on 2024-02-09 14:43 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("core", "0022_activationrequestqueue_process_parent_id_and_more"), + ] + + operations = [ + migrations.AlterField( + model_name="permission", + name="resource_type", + field=models.TextField( + choices=[ + ("activation", "activation"), + ("activation_instance", "activation_instance"), + ("audit_rule", "audit_rule"), + ("audit_event", "audit_event"), + ("user", "user"), + ("project", "project"), + ("extra_var", "extra_var"), + ("rulebook", "rulebook"), + ("role", "role"), + ("decision_environment", "decision_environment"), + ("credential", "credential"), + ] + ), + ), + migrations.DeleteModel( + name="Inventory", + ), + ] diff --git a/src/aap_eda/core/models/__init__.py b/src/aap_eda/core/models/__init__.py index c2dbb876c..c377653d9 100644 --- a/src/aap_eda/core/models/__init__.py +++ b/src/aap_eda/core/models/__init__.py @@ -17,7 +17,6 @@ from .credential import Credential from .decision_environment import DecisionEnvironment from .event_stream import EventStream -from .inventory import Inventory from .job import ( ActivationInstanceJobInstance, Job, @@ -47,7 +46,6 @@ "AuditEvent", "AuditRule", "ExtraVar", - "Inventory", "JobInstanceEvent", "JobInstanceHost", "JobInstance", diff --git a/src/aap_eda/core/models/inventory.py b/src/aap_eda/core/models/inventory.py deleted file mode 100644 index 75b6e0b1b..000000000 --- a/src/aap_eda/core/models/inventory.py +++ /dev/null @@ -1,49 +0,0 @@ -# Copyright 2022 Red Hat, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from django.db import models - -from aap_eda.core.enums import InventorySource - -__all__ = "Inventory" - - -class Inventory(models.Model): - class Meta: - db_table = "core_inventory" - constraints = [ - models.CheckConstraint( - check=models.Q(inventory_source__in=InventorySource.values()), - name="ck_inventory_source_values", - ), - models.CheckConstraint( - check=~models.Q(name=""), - name="ck_empty_inventory_name", - ), - ] - indexes = [ - models.Index( - fields=["inventory_source"], name="ix_inventory_inv_src" - ), - ] - - name = models.TextField(null=False, unique=True) - description = models.TextField(null=True, default="") - inventory = models.TextField(null=True) - inventory_source = models.TextField( - choices=InventorySource.choices(), null=False - ) - project = models.ForeignKey("Project", on_delete=models.CASCADE, null=True) - created_at = models.DateTimeField(auto_now_add=True, null=False) - modified_at = models.DateTimeField(auto_now=True, null=False) diff --git a/tests/integration/api/test_project.py b/tests/integration/api/test_project.py index 13e726cd0..4c03a9b02 100644 --- a/tests/integration/api/test_project.py +++ b/tests/integration/api/test_project.py @@ -143,7 +143,6 @@ def test_retrieve_project_failed_state(client: APIClient): data = response.json() assert data["import_state"] == "failed" - assert data["import_task_id"] == "3677eb4a-de4a-421a-a73b-411aa502484d" assert data["import_error"] == "Unexpected error. Please contact support." assert_project_data_details(data, project) @@ -496,10 +495,6 @@ def assert_project_data_details(data: Dict[str, Any], project: models.Project): def model_to_data_common(project: models.Project): - import_task_id = project.import_task_id - if import_task_id is not None: - import_task_id = str(import_task_id) - return { "id": project.id, "url": project.url, @@ -507,7 +502,6 @@ def model_to_data_common(project: models.Project): "description": project.description, "git_hash": project.git_hash, "import_state": project.import_state, - "import_task_id": import_task_id, "import_error": project.import_error, "created_at": project.created_at.strftime(DATETIME_FORMAT), "modified_at": project.modified_at.strftime(DATETIME_FORMAT), diff --git a/tests/integration/api/test_task.py b/tests/integration/api/test_task.py deleted file mode 100644 index 08323980f..000000000 --- a/tests/integration/api/test_task.py +++ /dev/null @@ -1,134 +0,0 @@ -# Copyright 2023 Red Hat, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -import uuid -from datetime import datetime -from typing import Any, Optional, Union -from unittest import mock - -import pytest -from rest_framework import status -from rest_framework.test import APIClient -from rq.job import JobStatus - -from tests.integration.constants import api_url_v1 - - -@pytest.mark.django_db -@mock.patch("aap_eda.api.views.tasks.list_jobs") -def test_list_tasks(list_jobs: mock.Mock, client: APIClient): - list_jobs.return_value = [ - _create_job( - "6636aad2-7998-4376-bb4d-ef19796fd1b3", - JobStatus.QUEUED, - created_at="2023-01-25T15:24:45.148282", - enqueued_at="2023-01-25T15:24:47.123923", - ), - _create_job( - "3992e416-b0f5-4e2e-8ae1-432bcdbc3de3", - JobStatus.FINISHED, - created_at="2023-01-25T15:25:19.220850", - enqueued_at="2023-01-25T15:25:19.804863", - started_at="2023-01-25T15:25:21.572900", - ended_at="2023-01-25T15:25:22.284716", - result={ - "obj_id": 42, - }, - ), - ] - response = client.get(f"{api_url_v1}/tasks/") - assert response.status_code == status.HTTP_200_OK - assert response.data == [ - { - "id": "6636aad2-7998-4376-bb4d-ef19796fd1b3", - "status": "queued", - "created_at": "2023-01-25T15:24:45.148282Z", - "enqueued_at": "2023-01-25T15:24:47.123923Z", - "started_at": None, - "finished_at": None, - "result": None, - }, - { - "id": "3992e416-b0f5-4e2e-8ae1-432bcdbc3de3", - "status": "finished", - "created_at": "2023-01-25T15:25:19.220850Z", - "enqueued_at": "2023-01-25T15:25:19.804863Z", - "started_at": "2023-01-25T15:25:21.572900Z", - "finished_at": "2023-01-25T15:25:22.284716Z", - "result": {"obj_id": 42}, - }, - ] - - -@pytest.mark.django_db -@mock.patch("aap_eda.api.views.tasks.get_job") -def test_retrieve_task(get_job: mock.Mock, client: APIClient): - get_job.return_value = _create_job( - "6636aad2-7998-4376-bb4d-ef19796fd1b3", - JobStatus.QUEUED, - created_at="2023-01-25T15:24:45.148282", - enqueued_at="2023-01-25T15:24:47.123923", - ) - response = client.get( - f"{api_url_v1}/tasks/6636aad2-7998-4376-bb4d-ef19796fd1b3/" - ) - assert response.status_code == status.HTTP_200_OK - assert response.data == { - "id": "6636aad2-7998-4376-bb4d-ef19796fd1b3", - "status": "queued", - "created_at": "2023-01-25T15:24:45.148282Z", - "enqueued_at": "2023-01-25T15:24:47.123923Z", - "started_at": None, - "finished_at": None, - "result": None, - } - - -@pytest.mark.django_db -@mock.patch("aap_eda.api.views.tasks.get_job") -def test_retrieve_task_not_exists(get_job: mock.Mock, client: APIClient): - get_job.return_value = None - response = client.get( - f"{api_url_v1}/tasks/a13f539c-aaa1-46b6-80c3-7dbfad941292/" - ) - assert response.status_code == status.HTTP_404_NOT_FOUND - - -def _parse_datetime(date_string: Optional[str]) -> Optional[datetime]: - if date_string is None: - return None - return datetime.fromisoformat(date_string) - - -def _create_job( - id_: Union[str, uuid.UUID], - status: JobStatus, - *, - created_at: Optional[str] = None, - enqueued_at: Optional[str] = None, - started_at: Optional[str] = None, - ended_at: Optional[str] = None, - result: Any = None, -) -> mock.Mock: - job = mock.Mock() - job.id = id_ - job.result = result - - job.get_status.return_value = status.value - - job.created_at = _parse_datetime(created_at) - job.enqueued_at = _parse_datetime(enqueued_at) - job.started_at = _parse_datetime(started_at) - job.ended_at = _parse_datetime(ended_at) - - return job diff --git a/tests/integration/wsapi/test_consumer.py b/tests/integration/wsapi/test_consumer.py index 29e059c40..3be7cdb3c 100644 --- a/tests/integration/wsapi/test_consumer.py +++ b/tests/integration/wsapi/test_consumer.py @@ -17,15 +17,6 @@ DATETIME_FORMAT = "%Y-%m-%dT%H:%M:%S.%fZ" -TEST_INVENTORY = """ ---- -all: - hosts: - localhost: - ansible_connection: local - ansible_python_interpreter: /usr/bin/python3 -""" - TEST_EXTRA_VAR = """ --- collections: