)
]
- def _check_valid_addr(self, host: str, addr: str) -> None:
+ def _check_valid_addr(self, host: str, addr: str) -> str:
# make sure hostname is resolvable before trying to make a connection
try:
- utils.resolve_ip(addr)
+ ip_addr = utils.resolve_ip(addr)
except OrchestratorError as e:
msg = str(e) + f'''
You may need to supply an address for {addr}
errors = [_i.replace("ERROR: ", "") for _i in err if _i.startswith('ERROR')]
raise OrchestratorError('Host %s (%s) failed check(s): %s' % (
host, addr, errors))
+ return ip_addr
def _add_host(self, spec):
# type: (HostSpec) -> str
:param host: host name
"""
assert_valid_host(spec.hostname)
- self._check_valid_addr(spec.hostname, spec.addr)
+ ip_addr = self._check_valid_addr(spec.hostname, spec.addr)
+ if spec.addr == spec.hostname and ip_addr:
+ spec.addr = ip_addr
# prime crush map?
if spec.location:
self.offline_hosts_remove(spec.hostname)
self.event.set() # refresh stray health check
self.log.info('Added host %s' % spec.hostname)
- return "Added host '{}'".format(spec.hostname)
+ return "Added host '{}' with addr '{}'".format(spec.hostname, spec.addr)
@handle_orch_error
def add_host(self, spec: HostSpec) -> str:
def test_host(self, cephadm_module):
assert wait(cephadm_module, cephadm_module.get_hosts()) == []
with with_host(cephadm_module, 'test'):
- assert wait(cephadm_module, cephadm_module.get_hosts()) == [HostSpec('test', 'test')]
+ assert wait(cephadm_module, cephadm_module.get_hosts()) == [HostSpec('test', '1.2.3.4')]
# Be careful with backward compatibility when changing things here:
assert json.loads(cephadm_module.get_store('inventory')) == \
- {"test": {"hostname": "test", "addr": "test", "labels": [], "status": ""}}
+ {"test": {"hostname": "test", "addr": "1.2.3.4", "labels": [], "status": ""}}
- with with_host(cephadm_module, 'second'):
+ with with_host(cephadm_module, 'second', '1.2.3.5'):
assert wait(cephadm_module, cephadm_module.get_hosts()) == [
- HostSpec('test', 'test'),
- HostSpec('second', 'second')
+ HostSpec('test', '1.2.3.4'),
+ HostSpec('second', '1.2.3.5')
]
- assert wait(cephadm_module, cephadm_module.get_hosts()) == [HostSpec('test', 'test')]
+ assert wait(cephadm_module, cephadm_module.get_hosts()) == [HostSpec('test', '1.2.3.4')]
assert wait(cephadm_module, cephadm_module.get_hosts()) == []
@mock.patch("cephadm.serve.CephadmServe._run_cephadm", _run_cephadm('[]'))
with mock.patch("cephadm.module.CephadmOrchestrator.mon_command") as _mon_cmd:
CephadmServe(cephadm_module)._check_daemons()
_mon_cmd.assert_any_call(
- {'prefix': 'dashboard set-grafana-api-url', 'value': 'https://test:3000'},
+ {'prefix': 'dashboard set-grafana-api-url', 'value': 'https://1.2.3.4:3000'},
None)
@mock.patch("cephadm.serve.CephadmServe._run_cephadm", _run_cephadm('[]'))
assert "Host 'test' not found" in err
out = wait(cephadm_module, cephadm_module.get_hosts())[0].to_json()
- assert out == HostSpec('test', 'test', status='Offline').to_json()
+ assert out == HostSpec('test', '1.2.3.4', status='Offline').to_json()
_get_connection.side_effect = None
assert CephadmServe(cephadm_module)._check_host('test') is None
out = wait(cephadm_module, cephadm_module.get_hosts())[0].to_json()
- assert out == HostSpec('test', 'test').to_json()
+ assert out == HostSpec('test', '1.2.3.4').to_json()
@mock.patch("cephadm.serve.CephadmServe._run_cephadm", _run_cephadm('{}'))
def test_dont_touch_offline_or_maintenance_host_daemons(self, cephadm_module):