|
16 | 16 | import redis
|
17 | 17 | from ansible_base.rbac.api.related import check_related_permissions
|
18 | 18 | from ansible_base.rbac.models import RoleDefinition
|
| 19 | +from django.conf import settings |
19 | 20 | from django.db import transaction
|
20 | 21 | from django.forms import model_to_dict
|
21 | 22 | from django_filters import rest_framework as defaultfilters
|
|
40 | 41 | start_rulebook_process,
|
41 | 42 | stop_rulebook_process,
|
42 | 43 | )
|
| 44 | +from aap_eda.utils import str_to_bool |
43 | 45 |
|
44 | 46 | from .mixins import RedisDependencyMixin
|
45 | 47 |
|
@@ -476,15 +478,42 @@ def disable(self, request, pk):
|
476 | 478 | None,
|
477 | 479 | description="Activation not enabled.",
|
478 | 480 | ),
|
| 481 | + status.HTTP_409_CONFLICT: OpenApiResponse( |
| 482 | + None, |
| 483 | + description="Activation blocked while Workers offline.", |
| 484 | + ), |
479 | 485 | }
|
480 | 486 | | RedisDependencyMixin.redis_unavailable_response(),
|
| 487 | + parameters=[ |
| 488 | + OpenApiParameter( |
| 489 | + name="force", |
| 490 | + description="Force restart after worker node offline", |
| 491 | + required=False, |
| 492 | + type=bool, |
| 493 | + ) |
| 494 | + ], |
481 | 495 | )
|
482 | 496 | @action(methods=["post"], detail=True, rbac_action=Action.RESTART)
|
483 | 497 | def restart(self, request, pk):
|
484 | 498 | activation = self.get_object()
|
485 |
| - |
486 | 499 | self._check_deleting(activation)
|
| 500 | + force_restart = str_to_bool( |
| 501 | + request.query_params.get("force", "false"), |
| 502 | + ) |
487 | 503 |
|
| 504 | + if ( |
| 505 | + settings.DEPLOYMENT_TYPE == "podman" |
| 506 | + and activation.status == ActivationStatus.WORKERS_OFFLINE |
| 507 | + and not force_restart |
| 508 | + ): |
| 509 | + # block the restart and return an error |
| 510 | + raise api_exc.Conflict( |
| 511 | + "An activation with an activation_status of 'Workers offline' " |
| 512 | + "cannot be Restarted because this will leave an orphaned " |
| 513 | + "container running on one of the 'activation-worker-node's. " |
| 514 | + "If you want to force a restart, please add the " |
| 515 | + "/?force=true query param." |
| 516 | + ) |
488 | 517 | if not activation.is_enabled:
|
489 | 518 | raise api_exc.Forbidden(
|
490 | 519 | detail="Activation is disabled and cannot be run."
|
|
0 commit comments