Skip to content

Commit f5c30a0

Browse files
authored
Merge pull request ceph#56928 from adk3798/grafana-anon-access-dropped
python-common: handle "anonymous_access: false" in to_json of Grafana spec Reviewed-by: Nizamudeen A <[email protected]>
2 parents 05121d1 + 1841c41 commit f5c30a0

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

src/python-common/ceph/deployment/service_spec.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,10 +1494,16 @@ def validate(self) -> None:
14941494
raise SpecValidationError(
14951495
'Invalid SPDK log level. Valid values are: DEBUG, INFO, WARNING, ERROR, NOTICE')
14961496

1497-
if self.spdk_ping_interval_in_seconds < 1.0:
1497+
if (
1498+
self.spdk_ping_interval_in_seconds
1499+
and self.spdk_ping_interval_in_seconds < 1.0
1500+
):
14981501
raise SpecValidationError("SPDK ping interval should be at least 1 second")
14991502

1500-
if self.allowed_consecutive_spdk_ping_failures < 1:
1503+
if (
1504+
self.allowed_consecutive_spdk_ping_failures
1505+
and self.allowed_consecutive_spdk_ping_failures < 1
1506+
):
15011507
raise SpecValidationError("Allowed consecutive SPDK ping failures should be at least 1")
15021508

15031509
if self.state_update_interval_sec < 0:
@@ -2032,7 +2038,7 @@ def __init__(self,
20322038
port: Optional[int] = None,
20332039
protocol: Optional[str] = 'https',
20342040
initial_admin_password: Optional[str] = None,
2035-
anonymous_access: Optional[bool] = True,
2041+
anonymous_access: bool = True,
20362042
extra_container_args: Optional[GeneralArgList] = None,
20372043
extra_entrypoint_args: Optional[GeneralArgList] = None,
20382044
custom_configs: Optional[List[CustomConfig]] = None,
@@ -2067,6 +2073,24 @@ def validate(self) -> None:
20672073
'be inaccessible.')
20682074
raise SpecValidationError(err_msg)
20692075

2076+
def to_json(self) -> "OrderedDict[str, Any]":
2077+
json_dict = super(GrafanaSpec, self).to_json()
2078+
if not self.anonymous_access:
2079+
# This field was added as a boolean that defaults
2080+
# to True, which makes it get dropped when the user
2081+
# sets it to False and it is converted to json. This means
2082+
# the in memory version of the spec will have the option set
2083+
# correctly, but the persistent version we store in the config-key
2084+
# store will always drop this option. It's already been backported to
2085+
# some release versions, or we'd probably just rename it to
2086+
# no_anonymous_access and default it to False. This block is to
2087+
# handle this option specially and in the future, we should avoid
2088+
# boolean fields that default to True.
2089+
if 'spec' not in json_dict:
2090+
json_dict['spec'] = {}
2091+
json_dict['spec']['anonymous_access'] = False
2092+
return json_dict
2093+
20702094

20712095
yaml.add_representer(GrafanaSpec, ServiceSpec.yaml_representer)
20722096

src/python-common/ceph/tests/test_service_spec.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,15 @@ def test_osd_unmanaged():
488488
privacy_protocol: AES
489489
snmp_destination: 192.168.1.42:162
490490
snmp_version: V3
491+
---
492+
service_type: grafana
493+
service_name: grafana
494+
placement:
495+
count: 1
496+
spec:
497+
anonymous_access: false
498+
initial_admin_password: password
499+
protocol: https
491500
""".split('---\n'))
492501
def test_yaml(y):
493502
data = yaml.safe_load(y)

0 commit comments

Comments
 (0)