def _run_cephadm(self,
host: str,
- entity: Optional[str],
+ entity: str,
command: str,
args: List[str],
- addr: Optional[str] = None,
- stdin: Optional[str] = None,
- no_fsid=False,
- error_ok=False,
- image: Optional[str] = None,
- env_vars: Optional[List[str]] = None,
+ addr: Optional[str] = "",
+ stdin: Optional[str] = "",
+ no_fsid: Optional[bool] = False,
+ error_ok: Optional[bool] = False,
+ image: Optional[str] = "",
+ env_vars: Optional[List[str]]= None,
) -> Tuple[List[str], List[str], int]:
"""
Run cephadm on the remote host with the given command + args
if dd.daemon_type == 'osd':
"""
The osd count can't be determined by the Placement spec.
- It's rather pointless to show a actual/expected representation
+ It's rather pointless to show a actual/expected representation
here. So we're setting running = size for now.
"""
osd_count += 1
deps.append(dd.name())
return sorted(deps)
- def _get_config_and_keyring(self, daemon_type, daemon_id,
+ def _get_config_and_keyring(self, daemon_type, daemon_id, host=None,
keyring=None,
extra_ceph_config=None):
- # type: (str, str, Optional[str], Optional[str]) -> Dict[str, Any]
+ # type: (str, str, Optional[str], Optional[str], Optional[str]) -> Dict[str, Any]
# keyring
if not keyring:
- ename = utils.name_to_auth_entity(daemon_type + '.' + daemon_id)
+ ename = utils.name_to_auth_entity(daemon_type, daemon_id, host=host)
ret, keyring, err = self.check_mon_command({
'prefix': 'auth get',
'entity': ename,
else:
# Ceph.daemons (mon, mgr, mds, osd, etc)
cephadm_config = self._get_config_and_keyring(
- daemon_type, daemon_id,
+ daemon_type, daemon_id, host,
keyring=keyring,
extra_ceph_config=extra_config.pop('config', ''))
if extra_config:
last_monmap = None # just in case clocks are skewed
daemons = self.cache.get_daemons()
- daemons_post = defaultdict(list)
+ daemons_post: Dict[str, List[orchestrator.DaemonDescription]] = defaultdict(list)
for dd in daemons:
# orphan?
spec = self.spec_store.specs.get(dd.service_name(), None)
if not host:
raise OrchestratorError('no hosts defined')
out, err, code = self._run_cephadm(
- host, None, 'pull', [],
+ host, '', 'pull', [],
image=image_name,
no_fsid=True,
error_ok=True)
def create(self, igw_id, host, spec) -> str:
ret, keyring, err = self.mgr.check_mon_command({
'prefix': 'auth get-or-create',
- 'entity': utils.name_to_auth_entity('iscsi') + '.' + igw_id,
+ 'entity': utils.name_to_auth_entity('iscsi', igw_id),
'caps': ['mon', 'profile rbd, '
'allow command "osd blacklist", '
'allow command "config-key get" with "key" prefix "iscsi/"',
--- /dev/null
+import pytest
+
+from orchestrator import OrchestratorError
+from cephadm.utils import name_to_auth_entity
+
+def test_name_to_auth_entity(fs):
+
+ for daemon_type in ['rgw', 'rbd-mirror', 'nfs', "iscsi"]:
+ assert "client.%s.id1" % (daemon_type) == name_to_auth_entity(daemon_type, "id1", "host")
+ assert "client.%s.id1" % (daemon_type) == name_to_auth_entity(daemon_type, "id1", "")
+ assert "client.%s.id1" % (daemon_type) == name_to_auth_entity(daemon_type, "id1")
+
+ assert "client.crash.host" == name_to_auth_entity("crash", "id1", "host")
+ with pytest.raises(OrchestratorError):
+ t = name_to_auth_entity("crash", "id1", "")
+ t = name_to_auth_entity("crash", "id1")
+
+ assert "mon." == name_to_auth_entity("mon", "id1", "host")
+ assert "mon." == name_to_auth_entity("mon", "id1", "")
+ assert "mon." == name_to_auth_entity("mon", "id1")
+
+ assert "mgr.id1" == name_to_auth_entity("mgr", "id1", "host")
+ assert "mgr.id1" == name_to_auth_entity("mgr", "id1", "")
+ assert "mgr.id1" == name_to_auth_entity("mgr", "id1")
+
+ for daemon_type in ["osd", "mds", "client"]:
+ assert "%s.id1" % daemon_type == name_to_auth_entity(daemon_type, "id1", "host")
+ assert "%s.id1" % daemon_type == name_to_auth_entity(daemon_type, "id1", "")
+ assert "%s.id1" % daemon_type == name_to_auth_entity(daemon_type, "id1")
+
+ with pytest.raises(OrchestratorError):
+ name_to_auth_entity("whatever", "id1", "host")
+ name_to_auth_entity("whatever", "id1", "")
+ name_to_auth_entity("whatever", "id1")
# make sure host has latest container image
out, err, code = self.mgr._run_cephadm(
- d.hostname, None, 'inspect-image', [],
+ d.hostname, '', 'inspect-image', [],
image=target_name, no_fsid=True, error_ok=True)
if code or json.loads(''.join(out)).get('image_id') != target_id:
logger.info('Upgrade: Pulling %s on %s' % (target_name,
d.hostname))
out, err, code = self.mgr._run_cephadm(
- d.hostname, None, 'pull', [],
+ d.hostname, '', 'pull', [],
image=target_name, no_fsid=True, error_ok=True)
if code:
self._fail_upgrade('UPGRADE_FAILED_PULL', {
from orchestrator import OrchestratorError
-def name_to_config_section(name):
+from typing import Optional
+
+def name_to_config_section(name: str) -> str:
"""
Map from daemon names to ceph entity names (as seen in config)
"""
else:
return 'mon'
-
-def name_to_auth_entity(name) -> str:
+def name_to_auth_entity(daemon_type, # type: str
+ daemon_id, # type: str
+ host = "" # type Optional[str] = ""
+ ):
"""
- Map from daemon names to ceph entity names (as seen in config)
+ Map from daemon names/host to ceph entity names (as seen in config)
"""
- daemon_type = name.split('.', 1)[0]
- if daemon_type in ['rgw', 'rbd-mirror', 'nfs', 'crash', 'iscsi']:
- return 'client.' + name
+ if daemon_type in ['rgw', 'rbd-mirror', 'nfs', "iscsi"]:
+ return 'client.' + daemon_type + "." + daemon_id
+ elif daemon_type == 'crash':
+ if host == "":
+ raise OrchestratorError("Host not provided to generate <crash> auth entity name")
+ return 'client.' + daemon_type + "." + host
elif daemon_type == 'mon':
return 'mon.'
- elif daemon_type in ['osd', 'mds', 'mgr', 'client']:
- return name
+ elif daemon_type == 'mgr':
+ return daemon_type + "." + daemon_id
+ elif daemon_type in ['osd', 'mds', 'client']:
+ return daemon_type + "." + daemon_id
else:
raise OrchestratorError("unknown auth entity name")