Skip to content

Commit 82c350d

Browse files
authored
Merge pull request ceph#60587 from phlogistonjohn/jjm-more-py312-fixes
various python 3.12 fixes Reviewed-by: Adam King <[email protected]>
2 parents c0db4b6 + 881d111 commit 82c350d

File tree

27 files changed

+123
-100
lines changed

27 files changed

+123
-100
lines changed

src/cephadm/cephadm.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4489,8 +4489,9 @@ def _rm_cluster(ctx: CephadmContext, keep_logs: bool, zap_osds: bool) -> None:
44894489
##################################
44904490

44914491

4492-
def check_time_sync(ctx, enabler=None):
4493-
# type: (CephadmContext, Optional[Packager]) -> bool
4492+
def check_time_sync(
4493+
ctx: CephadmContext, enabler: Optional[Packager] = None
4494+
) -> bool:
44944495
units = [
44954496
'chrony.service', # 18.04 (at least)
44964497
'chronyd.service', # el / opensuse

src/cephadm/cephadmlib/call_wrappers.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,14 +311,14 @@ def call_throws(
311311
return out, err, ret
312312

313313

314-
def call_timeout(ctx, command, timeout):
315-
# type: (CephadmContext, List[str], int) -> int
314+
def call_timeout(
315+
ctx: CephadmContext, command: List[str], timeout: int
316+
) -> int:
316317
logger.debug(
317318
'Running command (timeout=%s): %s' % (timeout, ' '.join(command))
318319
)
319320

320-
def raise_timeout(command, timeout):
321-
# type: (List[str], int) -> NoReturn
321+
def raise_timeout(command: List[str], timeout: int) -> NoReturn:
322322
msg = 'Command `%s` timed out after %s seconds' % (command, timeout)
323323
logger.debug(msg)
324324
raise TimeoutExpired(msg)

src/cephadm/cephadmlib/daemon_identity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def sidecar_service_name(self) -> str:
157157
)
158158

159159
def sidecar_script(self, base_data_dir: Union[str, os.PathLike]) -> str:
160-
sname = f'sidecar-{ self.subcomponent }.run'
160+
sname = f'sidecar-{self.subcomponent}.run'
161161
return str(pathlib.Path(self.data_dir(base_data_dir)) / sname)
162162

163163
@property

src/cephadm/cephadmlib/daemons/ingress.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ def create_daemon_dirs(self, data_dir: str, uid: int, gid: int) -> None:
8282
def get_daemon_args(self) -> List[str]:
8383
return ['haproxy', '-f', '/var/lib/haproxy/haproxy.cfg']
8484

85-
def validate(self):
86-
# type: () -> None
85+
def validate(self) -> None:
8786
if not is_fsid(self.fsid):
8887
raise Error('not an fsid: %s' % self.fsid)
8988
if not self.daemon_id:
@@ -99,12 +98,10 @@ def validate(self):
9998
'required file missing from config-json: %s' % fname
10099
)
101100

102-
def get_daemon_name(self):
103-
# type: () -> str
101+
def get_daemon_name(self) -> str:
104102
return '%s.%s' % (self.daemon_type, self.daemon_id)
105103

106-
def get_container_name(self, desc=None):
107-
# type: (Optional[str]) -> str
104+
def get_container_name(self, desc: Optional[str] = None) -> str:
108105
cname = 'ceph-%s-%s' % (self.fsid, self.get_daemon_name())
109106
if desc:
110107
cname = '%s-%s' % (cname, desc)
@@ -212,8 +209,7 @@ def create_daemon_dirs(self, data_dir: str, uid: int, gid: int) -> None:
212209
# populate files from the config-json
213210
populate_files(data_dir, self.files, uid, gid)
214211

215-
def validate(self):
216-
# type: () -> None
212+
def validate(self) -> None:
217213
if not is_fsid(self.fsid):
218214
raise Error('not an fsid: %s' % self.fsid)
219215
if not self.daemon_id:
@@ -229,20 +225,17 @@ def validate(self):
229225
'required file missing from config-json: %s' % fname
230226
)
231227

232-
def get_daemon_name(self):
233-
# type: () -> str
228+
def get_daemon_name(self) -> str:
234229
return '%s.%s' % (self.daemon_type, self.daemon_id)
235230

236-
def get_container_name(self, desc=None):
237-
# type: (Optional[str]) -> str
231+
def get_container_name(self, desc: Optional[str] = None) -> str:
238232
cname = 'ceph-%s-%s' % (self.fsid, self.get_daemon_name())
239233
if desc:
240234
cname = '%s-%s' % (cname, desc)
241235
return cname
242236

243237
@staticmethod
244-
def get_container_envs():
245-
# type: () -> List[str]
238+
def get_container_envs() -> List[str]:
246239
envs = [
247240
'KEEPALIVED_AUTOCONF=false',
248241
'KEEPALIVED_CONF=/etc/keepalived/keepalived.conf',

src/cephadm/cephadmlib/daemons/nfs.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,13 @@ def for_daemon_type(cls, daemon_type: str) -> bool:
4242
return cls.daemon_type == daemon_type
4343

4444
def __init__(
45-
self, ctx, fsid, daemon_id, config_json, image=DEFAULT_IMAGE
46-
):
47-
# type: (CephadmContext, str, Union[int, str], Dict, str) -> None
45+
self,
46+
ctx: CephadmContext,
47+
fsid: str,
48+
daemon_id: Union[int, str],
49+
config_json: Dict,
50+
image: str = DEFAULT_IMAGE,
51+
) -> None:
4852
self.ctx = ctx
4953
self.fsid = fsid
5054
self.daemon_id = daemon_id
@@ -62,8 +66,9 @@ def __init__(
6266
self.validate()
6367

6468
@classmethod
65-
def init(cls, ctx, fsid, daemon_id):
66-
# type: (CephadmContext, str, Union[int, str]) -> NFSGanesha
69+
def init(
70+
cls, ctx: CephadmContext, fsid: str, daemon_id: Union[int, str]
71+
) -> 'NFSGanesha':
6772
return cls(ctx, fsid, daemon_id, fetch_configs(ctx), ctx.image)
6873

6974
@classmethod

src/cephadm/cephadmlib/daemons/nvmeof.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,13 @@ def for_daemon_type(cls, daemon_type: str) -> bool:
3333
return cls.daemon_type == daemon_type
3434

3535
def __init__(
36-
self, ctx, fsid, daemon_id, config_json, image=DEFAULT_NVMEOF_IMAGE
37-
):
38-
# type: (CephadmContext, str, Union[int, str], Dict, str) -> None
36+
self,
37+
ctx: CephadmContext,
38+
fsid: str,
39+
daemon_id: Union[int, str],
40+
config_json: Dict,
41+
image: str = DEFAULT_NVMEOF_IMAGE,
42+
) -> None:
3943
self.ctx = ctx
4044
self.fsid = fsid
4145
self.daemon_id = daemon_id
@@ -48,8 +52,9 @@ def __init__(
4852
self.validate()
4953

5054
@classmethod
51-
def init(cls, ctx, fsid, daemon_id):
52-
# type: (CephadmContext, str, Union[int, str]) -> CephNvmeof
55+
def init(
56+
cls, ctx: CephadmContext, fsid: str, daemon_id: Union[int, str]
57+
) -> 'CephNvmeof':
5358
return cls(ctx, fsid, daemon_id, fetch_configs(ctx), ctx.image)
5459

5560
@classmethod

src/cephadm/cephadmlib/data_utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,9 @@ def normalize_image_digest(digest: str) -> str:
189189
return digest
190190

191191

192-
def get_legacy_config_fsid(cluster, legacy_dir=None):
193-
# type: (str, Optional[str]) -> Optional[str]
192+
def get_legacy_config_fsid(
193+
cluster: str, legacy_dir: Optional[str] = None
194+
) -> Optional[str]:
194195
config_file = '/etc/ceph/%s.conf' % cluster
195196
if legacy_dir is not None:
196197
config_file = os.path.abspath(legacy_dir + config_file)

src/cephadm/cephadmlib/file_utils.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ def write_new(
5252
os.rename(tempname, destination)
5353

5454

55-
def populate_files(config_dir, config_files, uid, gid):
56-
# type: (str, Dict, int, int) -> None
55+
def populate_files(
56+
config_dir: str, config_files: Dict, uid: int, gid: int
57+
) -> None:
5758
"""create config files for different services"""
5859
for fname in config_files:
5960
config_file = os.path.join(config_dir, fname)
@@ -71,8 +72,7 @@ def touch(
7172
os.chown(file_path, uid, gid)
7273

7374

74-
def write_tmp(s, uid, gid):
75-
# type: (str, int, int) -> IO[str]
75+
def write_tmp(s: str, uid: int, gid: int) -> IO[str]:
7676
tmp_f = tempfile.NamedTemporaryFile(mode='w', prefix='ceph-tmp')
7777
os.fchown(tmp_f.fileno(), uid, gid)
7878
tmp_f.write(s)
@@ -97,8 +97,7 @@ def recursive_chown(path: str, uid: int, gid: int) -> None:
9797
os.chown(os.path.join(dirpath, filename), uid, gid)
9898

9999

100-
def read_file(path_list, file_name=''):
101-
# type: (List[str], str) -> str
100+
def read_file(path_list: List[str], file_name: str = '') -> str:
102101
"""Returns the content of the first file found within the `path_list`
103102
104103
:param path_list: list of file paths to search
@@ -123,14 +122,12 @@ def read_file(path_list, file_name=''):
123122
return 'Unknown'
124123

125124

126-
def pathify(p):
127-
# type: (str) -> str
125+
def pathify(p: str) -> str:
128126
p = os.path.expanduser(p)
129127
return os.path.abspath(p)
130128

131129

132-
def get_file_timestamp(fn):
133-
# type: (str) -> Optional[str]
130+
def get_file_timestamp(fn: str) -> Optional[str]:
134131
try:
135132
mt = os.path.getmtime(fn)
136133
return datetime.datetime.fromtimestamp(

src/cephadm/cephadmlib/systemd.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
logger = logging.getLogger()
1212

1313

14-
def check_unit(ctx, unit_name):
15-
# type: (CephadmContext, str) -> Tuple[bool, str, bool]
14+
def check_unit(ctx: CephadmContext, unit_name: str) -> Tuple[bool, str, bool]:
1615
# NOTE: we ignore the exit code here because systemctl outputs
1716
# various exit codes based on the state of the service, but the
1817
# string result is more explicit (and sufficient).
@@ -56,8 +55,9 @@ def check_unit(ctx, unit_name):
5655
return (enabled, state, installed)
5756

5857

59-
def check_units(ctx, units, enabler=None):
60-
# type: (CephadmContext, List[str], Optional[Packager]) -> bool
58+
def check_units(
59+
ctx: CephadmContext, units: List[str], enabler: Optional[Packager] = None
60+
) -> bool:
6161
for u in units:
6262
(enabled, state, installed) = check_unit(ctx, u)
6363
if enabled and state == 'running':

src/cephadm/tests/test_agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ def recv(self, len: Optional[int] = None):
668668
agent.mgr_listener.run()
669669

670670
# verify payload was correctly extracted
671-
assert _handle_json_payload.called_with(json.loads(payload))
671+
_handle_json_payload.assert_called_with(json.loads(payload))
672672
FakeConn.send.assert_called_once_with(b'ACK')
673673

674674
# second run, with bad json data received

0 commit comments

Comments
 (0)