]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: add `--allow-fqdn-hostname` test 41555/head
authorMichael Fritch <mfritch@suse.com>
Fri, 28 May 2021 17:12:12 +0000 (11:12 -0600)
committerMichael Fritch <mfritch@suse.com>
Fri, 28 May 2021 17:16:15 +0000 (11:16 -0600)
Signed-off-by: Michael Fritch <mfritch@suse.com>
src/cephadm/tests/fixtures.py
src/cephadm/tests/test_cephadm.py

index 9693ead8dd0d63eae76458fc1043e47f388e31f5..2f07d6034805a5d9e3ecf1df897ede8790c59d5b 100644 (file)
@@ -84,15 +84,19 @@ def cephadm_fs(
 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'), \
@@ -100,7 +104,8 @@ def with_cephadm_ctx(
          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
index 96ffea7e3a81792d878df80d6b68a3099220de7e..6b231573fe6316d083349bef5c797d9b601390aa 100644 (file)
@@ -1140,3 +1140,20 @@ class TestBootstrap(TestCephAdm):
             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