CephContainer,
InitContainer,
is_container_running,
+ extract_uid_gid,
)
from cephadmlib.decorators import (
deprecated_command,
)
-def extract_uid_gid(ctx, img='', file_path='/var/lib/ceph'):
- # type: (CephadmContext, str, Union[str, List[str]]) -> Tuple[int, int]
-
- if not img:
- img = ctx.image
-
- if isinstance(file_path, str):
- paths = [file_path]
- else:
- paths = file_path
-
- ex: Optional[Tuple[str, RuntimeError]] = None
-
- for fp in paths:
- try:
- out = CephContainer(
- ctx,
- image=img,
- entrypoint='stat',
- args=['-c', '%u %g', fp]
- ).run(verbosity=CallVerbosity.QUIET_UNLESS_ERROR)
- uid, gid = out.split(' ')
- return int(uid), int(gid)
- except RuntimeError as e:
- ex = (fp, e)
- if ex:
- raise Error(f'Failed to extract uid/gid for path {ex[0]}: {ex[1]}')
-
- raise RuntimeError('uid/gid not found')
-
-
def deploy_daemon(
ctx: CephadmContext,
ident: 'DaemonIdentity',
import os
-from typing import Dict, List, Optional, Any
+from typing import Dict, List, Optional, Any, Union, Tuple
from .call_wrappers import call, call_throws, CallVerbosity
from .constants import DEFAULT_TIMEOUT
if out.strip() == 'running':
return name
return None
+
+
+def extract_uid_gid(ctx, img='', file_path='/var/lib/ceph'):
+ # type: (CephadmContext, str, Union[str, List[str]]) -> Tuple[int, int]
+
+ if not img:
+ img = ctx.image
+
+ if isinstance(file_path, str):
+ paths = [file_path]
+ else:
+ paths = file_path
+
+ ex: Optional[Tuple[str, RuntimeError]] = None
+
+ for fp in paths:
+ try:
+ out = CephContainer(
+ ctx,
+ image=img,
+ entrypoint='stat',
+ args=['-c', '%u %g', fp]
+ ).run(verbosity=CallVerbosity.QUIET_UNLESS_ERROR)
+ uid, gid = out.split(' ')
+ return int(uid), int(gid)
+ except RuntimeError as e:
+ ex = (fp, e)
+ if ex:
+ raise Error(f'Failed to extract uid/gid for path {ex[0]}: {ex[1]}')
+
+ raise RuntimeError('uid/gid not found')
good_haproxy_json(),
SAMPLE_HAPROXY_IMAGE,
)
- with mock.patch("cephadm.CephContainer") as cc:
+ with mock.patch("cephadmlib.container_types.CephContainer") as cc:
cc.return_value.run.return_value = "500 500"
uid, gid = hap.uid_gid(ctx)
cc.return_value.run.assert_called()
good_keepalived_json(),
SAMPLE_KEEPALIVED_IMAGE,
)
- with mock.patch("cephadm.CephContainer") as cc:
+ with mock.patch("cephadmlib.container_types.CephContainer") as cc:
cc.return_value.run.return_value = "500 500"
uid, gid = kad.uid_gid(ctx)
cc.return_value.run.assert_called()