Skip to content

Commit

Permalink
Merge pull request #1280 from arenadata/develop
Browse files Browse the repository at this point in the history
Release 2021.11.18
  • Loading branch information
acmnu authored Nov 18, 2021
2 parents 9221bc1 + 275b1ca commit a1469a5
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 6 deletions.
1 change: 1 addition & 0 deletions python/adcm/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@
'file': {
'level': 'DEBUG',
'filters': ['require_debug_false'],
'formatter': 'adwp',
'class': 'logging.FileHandler',
'filename': os.path.join(BASE_DIR, 'data/log/adcm_debug.log'),
},
Expand Down
29 changes: 24 additions & 5 deletions python/api/group_config/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
MultiHyperlinkedIdentityField,
UIConfigField,
)
from cm.adcm_config import config_is_ro
from cm.api import update_obj_config
from cm.errors import AdcmEx
from cm.models import GroupConfig, Host, ObjectConfig, ConfigLog
Expand Down Expand Up @@ -249,19 +250,37 @@ class Meta:
extra_kwargs = {'config': {'required': True}}

def validate(self, attrs):
def check_value_unselected_field(cc, nc, gk):
def check_value_unselected_field(cc, nc, gk, spec, obj):
"""
Check value unselected field
:param cc: Current config
:param nc: New config
:param gk: group_keys from attr
:param spec: Config specification
:param obj: Parent object (Cluster, Service, Component Provider or Host)
"""
for k, v in gk.items():
if isinstance(v, Mapping):
check_value_unselected_field(cc[k], nc[k], gk[k])
check_value_unselected_field(cc[k], nc[k], gk[k], spec[k]['fields'], obj)
else:
if not v and k in cc and k in nc and cc[k] != nc[k]:
raise AdcmEx('GROUP_CONFIG_CHANGE_UNSELECTED_FIELD')
is_read_only_list_or_map = (
config_is_ro(obj, k, spec[k]['limits'])
and spec[k]['type'] in ['list', 'map']
)
if not is_read_only_list_or_map:
if not v and k in cc and k in nc and cc[k] != nc[k]:
raise AdcmEx('GROUP_CONFIG_CHANGE_UNSELECTED_FIELD')

obj_ref = self.context['obj_ref']
config_spec = obj_ref.object.get_config_spec()
parent_obj = obj_ref.object.object
current_config = ConfigLog.objects.get(id=obj_ref.current).config
new_config = attrs.get('config')
group_keys = attrs.get('attr', {}).get('group_keys', {})
check_value_unselected_field(current_config, new_config, group_keys)
check_value_unselected_field(
current_config, new_config, group_keys, config_spec, parent_obj
)
return super().validate(attrs)

@atomic
Expand Down
8 changes: 8 additions & 0 deletions python/cm/adcm_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,14 @@ def check_read_only(obj, spec, conf, old_conf):
flat_old_conf = to_flat_dict(old_conf, spec)
for s in spec:
if config_is_ro(obj, s, spec[s].limits) and s in flat_conf:

if spec[s].type == 'list':
if isinstance(flat_conf[s], list) and not flat_conf[s]:
continue
if spec[s].type == 'map':
if isinstance(flat_conf[s], dict) and not flat_conf[s]:
continue

if flat_conf[s] != flat_old_conf[s]:
msg = 'config key {} of {} is read only'
err('CONFIG_VALUE_ERROR', msg.format(s, proto_ref(obj.prototype)))
Expand Down
6 changes: 5 additions & 1 deletion python/cm/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,11 @@ def get_config_spec(self):
group_customization = field.group_customization
if group_customization is None:
group_customization = self.object.prototype.config_group_customization
field_spec = {'type': field.type, 'group_customization': group_customization}
field_spec = {
'type': field.type,
'group_customization': group_customization,
'limits': field.limits,
}
if field.subname == '':
if field.type == 'group':
field_spec.update({'fields': {}})
Expand Down
4 changes: 4 additions & 0 deletions python/cm/unit_tests/test_config_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,24 @@ def test_get_config_spec(self):
'group': {
'type': 'group',
'group_customization': False,
'limits': {},
'fields': {
'string': {
'type': 'string',
'group_customization': False,
'limits': {},
}
},
},
'activatable_group': {
'type': 'group',
'group_customization': False,
'limits': {},
'fields': {
'integer': {
'type': 'integer',
'group_customization': False,
'limits': {},
}
},
},
Expand Down

0 comments on commit a1469a5

Please sign in to comment.