def with_cephadm_ctx(
cmd: List[str],
container_engine: Callable = mock_podman(),
- list_networks: Optional[Dict[str,Dict[str,List[str]]]] = None
+ list_networks: Optional[Dict[str,Dict[str,List[str]]]] = None,
+ hostname: Optional[str] = None,
):
"""
:param cmd: cephadm command argv
:param container_engine: container engine mock (podman or docker)
:param list_networks: mock 'list-networks' return
+ :param hostname: mock 'socket.gethostname' return
"""
if not list_networks:
list_networks = {}
+ if not hostname:
+ hostname = 'host1'
with mock.patch('cephadm.get_parm'), \
mock.patch('cephadm.attempt_bind'), \
mock.patch('cephadm.find_executable', return_value='foo'), \
mock.patch('cephadm.is_available', return_value=True), \
mock.patch('cephadm.json_loads_retry', return_value={'epoch' : 1}), \
- mock.patch('cephadm.list_networks', return_value=list_networks):
+ mock.patch('cephadm.list_networks', return_value=list_networks), \
+ mock.patch('socket.gethostname', return_value=hostname):
ctx: cd.CephadmContext = cd.cephadm_init_ctx(cmd)
ctx.container_engine = container_engine
yield ctx
with with_cephadm_ctx(cmd, list_networks=list_networks) as ctx:
retval = cd.command_bootstrap(ctx)
assert retval == 0
+
+ def test_allow_fqdn_hostname(self, cephadm_fs):
+ hostname = 'foo.bar'
+ cmd = self._get_cmd(
+ '--mon-ip', '192.168.1.1',
+ '--skip-mon-network',
+ )
+
+ with with_cephadm_ctx(cmd, hostname=hostname) as ctx:
+ msg = r'--allow-fqdn-hostname'
+ with pytest.raises(cd.Error, match=msg):
+ cd.command_bootstrap(ctx)
+
+ cmd += ['--allow-fqdn-hostname']
+ with with_cephadm_ctx(cmd, hostname=hostname) as ctx:
+ retval = cd.command_bootstrap(ctx)
+ assert retval == 0