Skip to content

Commit

Permalink
Merge branch 'release' into 'master'
Browse files Browse the repository at this point in the history
Release

See merge request arenadata/development/adcm!2804
  • Loading branch information
kuhella committed Jul 10, 2023
2 parents 76d6e49 + edf44de commit 40f2afd
Show file tree
Hide file tree
Showing 90 changed files with 5,823 additions and 1,302 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ data/
**/__pycache__/
config.json
go/bin/
poetry.lock
wwwroot/
1,954 changes: 1,954 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ social-auth-app-django = "*"
uwsgi = "*"
version-utils = "*"
yspec = "*"
six = "*"
django-cors-headers = "*"

[tool.poetry.group.lint]
optional = true
Expand Down
63 changes: 63 additions & 0 deletions python/adcm/mixins.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# 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 contextlib import suppress

from cm.models import (
Cluster,
ClusterObject,
GroupConfig,
Host,
HostProvider,
ServiceComponent,
)
from django.contrib.contenttypes.models import ContentType
from django.db.models import ObjectDoesNotExist


class GetParentObjectMixin:
def get_parent_object(self) -> GroupConfig | Cluster | ClusterObject | ServiceComponent | Host | None:
parent_object = None

with suppress(ObjectDoesNotExist):
if all(lookup in self.kwargs for lookup in ("component_pk", "service_pk", "cluster_pk")):
parent_object = ServiceComponent.objects.get(
pk=self.kwargs["component_pk"],
cluster_id=self.kwargs["cluster_pk"],
service_id=self.kwargs["service_pk"],
)

elif "cluster_pk" in self.kwargs and "service_pk" in self.kwargs:
parent_object = ClusterObject.objects.get(
pk=self.kwargs["service_pk"], cluster_id=self.kwargs["cluster_pk"]
)

elif "cluster_pk" in self.kwargs and "host_pk" in self.kwargs:
parent_object = Host.objects.get(pk=self.kwargs["host_pk"], cluster_id=self.kwargs["cluster_pk"])

elif "host_pk" in self.kwargs:
parent_object = Host.objects.get(pk=self.kwargs["host_pk"])

elif "cluster_pk" in self.kwargs:
parent_object = Cluster.objects.get(pk=self.kwargs["cluster_pk"])

elif "provider_pk" in self.kwargs:
parent_object = HostProvider.objects.get(pk=self.kwargs["provider_pk"])

if "config_group_pk" in self.kwargs:
parent_object = GroupConfig.objects.get(
pk=self.kwargs["config_group_pk"],
object_id=parent_object.pk,
object_type=ContentType.objects.get_for_model(model=parent_object),
)

return parent_object
6 changes: 6 additions & 0 deletions python/adcm/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,24 @@
)

VIEW_CLUSTER_PERM = "cm.view_cluster"
VIEW_CLUSTER_UPGRADE_PERM = "cm.view_upgrade_of_cluster"
VIEW_SERVICE_PERM = "cm.view_clusterobject"
VIEW_ACTION_PERM = "cm.view_action"
CHANGE_MM_PERM = "change_maintenance_mode"
ADD_SERVICE_PERM = "add_service_to"
RUN_ACTION_PERM_PREFIX = "cm.run_action_"
ADD_TASK_PERM = "cm.add_task"
ADD_HOST_TO = "add_host_to"
VIEW_HOST_PERM = "cm.view_host"
VIEW_PROVIDER_PERM = "cm.view_hostprovider"
VIEW_PROVIDER_UPGRADE_PERM = "cm.view_upgrade_of_hostprovider"
VIEW_COMPONENT_PERM = "cm.view_servicecomponent"
VIEW_HC_PERM = "cm.view_hostcomponent"
VIEW_CONFIG_PERM = "cm.view_configlog"
VIEW_GROUP_CONFIG_PERM = "cm.view_groupconfig"
VIEW_IMPORT_PERM = "view_import_of"
CHANGE_IMPORT_PERM = "change_import_of"
VIEW_CLUSTER_BIND = "view_clusterbind"


class DjangoObjectPermissionsAudit(DjangoObjectPermissions):
Expand Down
5 changes: 5 additions & 0 deletions python/adcm/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,11 @@
"cm.apps.CmConfig",
"audit",
"api_v2",
"corsheaders",
]

MIDDLEWARE = [
"corsheaders.middleware.CorsMiddleware",
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
Expand All @@ -110,6 +112,9 @@

ROOT_URLCONF = "adcm.urls"

CORS_ALLOW_ALL_ORIGINS = True
CORS_ALLOW_CREDENTIALS = True

TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
Expand Down
13 changes: 12 additions & 1 deletion python/adcm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def get_maintenance_mode_response(
obj: Host | ClusterObject | ServiceComponent,
serializer: Serializer,
) -> Response:
# pylint: disable=too-many-branches
# pylint: disable=too-many-branches, too-many-return-statements

turn_on_action_name = settings.ADCM_TURN_ON_MM_ACTION_NAME
turn_off_action_name = settings.ADCM_TURN_OFF_MM_ACTION_NAME
Expand All @@ -213,6 +213,17 @@ def get_maintenance_mode_response(
obj_name = "host"
turn_on_action_name = settings.ADCM_HOST_TURN_ON_MM_ACTION_NAME
turn_off_action_name = settings.ADCM_HOST_TURN_OFF_MM_ACTION_NAME

if not obj.cluster:
return Response(
data={
"code": "MAINTENANCE_MODE_NOT_AVAILABLE",
"level": "error",
"desc": "Maintenance mode is not available",
},
status=HTTP_409_CONFLICT,
)

prototype = obj.cluster.prototype
elif isinstance(obj, ClusterObject):
obj_name = "service"
Expand Down
2 changes: 1 addition & 1 deletion python/api/cluster/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from api.host.serializers import HostSerializer
from api.serializers import DoUpgradeSerializer, StringListSerializer
from api.utils import CommonAPIURL, ObjectURL, UrlField, check_obj
from api.validators import StartMidEndValidator
from cm.adcm_config.config import get_main_info
from cm.api import add_cluster, add_hc, bind, multi_bind
from cm.errors import AdcmEx
Expand All @@ -26,6 +25,7 @@
from cm.schemas import RequiresUISchema
from cm.status_api import get_cluster_status, get_hc_status
from cm.upgrade import get_upgrade
from cm.validators import StartMidEndValidator
from django.conf import settings
from rest_framework.exceptions import ValidationError
from rest_framework.serializers import (
Expand Down
2 changes: 1 addition & 1 deletion python/api/host/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
from api.concern.serializers import ConcernItemSerializer, ConcernItemUISerializer
from api.serializers import StringListSerializer
from api.utils import CommonAPIURL, ObjectURL, check_obj
from api.validators import HostUniqueValidator, StartMidEndValidator
from cm.adcm_config.config import get_main_info
from cm.api import add_host
from cm.issue import update_hierarchy_issues, update_issue_after_deleting
from cm.models import Action, Host, HostProvider, MaintenanceMode, Prototype
from cm.status_api import get_host_status
from cm.validators import HostUniqueValidator, StartMidEndValidator
from django.conf import settings
from rest_framework.serializers import (
BooleanField,
Expand Down
6 changes: 1 addition & 5 deletions python/api/host/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
Host,
HostComponent,
HostProvider,
MaintenanceMode,
ServiceComponent,
)
from cm.status_api import make_ui_host_status
Expand Down Expand Up @@ -308,10 +307,7 @@ def post(self, request: Request, **kwargs) -> Response:

serializer = self.get_serializer(instance=host, data=request.data)
serializer.is_valid(raise_exception=True)
if (
serializer.validated_data.get("maintenance_mode") == MaintenanceMode.ON
and not host.is_maintenance_mode_available
):
if not host.is_maintenance_mode_available:
return Response(data="MAINTENANCE_MODE_NOT_AVAILABLE", status=HTTP_409_CONFLICT)

response: Response = get_maintenance_mode_response(obj=host, serializer=serializer)
Expand Down
Binary file modified python/api/tests/files/bundle_test_min_adcm_version.tar
Binary file not shown.
6 changes: 2 additions & 4 deletions python/api_v2/action/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from cm.models import Action, Cluster
from cm.models import Action
from rest_framework.serializers import (
BooleanField,
JSONField,
Expand All @@ -29,9 +29,7 @@ class Meta:
fields = ["id", "name", "display_name", "start_impossible_reason"]

def get_start_impossible_reason(self, action: Action) -> str | None:
return action.get_start_impossible_reason(
obj=Cluster.objects.filter(pk=self.context["request"].parser_context["kwargs"]["cluster_pk"]).first()
)
return action.get_start_impossible_reason(obj=self.context["obj"])


class ActionRetrieveSerializer(ModelSerializer):
Expand Down
Loading

0 comments on commit 40f2afd

Please sign in to comment.