]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
cephadm: move registry_login to container_engines.py
authorAdam King <adking@redhat.com>
Wed, 27 Sep 2023 18:34:42 +0000 (14:34 -0400)
committerAdam King <adking@redhat.com>
Wed, 27 Sep 2023 19:23:42 +0000 (15:23 -0400)
Signed-off-by: Adam King <adking@redhat.com>
src/cephadm/cephadm.py
src/cephadm/cephadmlib/container_engines.py
src/cephadm/tests/test_cephadm.py

index a0ebf7e96b5e9dc1678478d0e4c90a0ae16daa36..fa0bf73da57cc7761e75aaa057a630198e25cc53 100755 (executable)
@@ -100,6 +100,7 @@ from cephadmlib.container_engines import (
     Podman,
     check_container_engine,
     find_container_engine,
+    registry_login,
 )
 from cephadmlib.data_utils import (
     dict_get,
@@ -5298,20 +5299,6 @@ def command_registry_login(ctx: CephadmContext) -> int:
     return 0
 
 
-def registry_login(ctx: CephadmContext, url: Optional[str], username: Optional[str], password: Optional[str]) -> None:
-    try:
-        engine = ctx.container_engine
-        cmd = [engine.path, 'login',
-               '-u', username, '-p', password,
-               url]
-        if isinstance(engine, Podman):
-            cmd.append('--authfile=/etc/ceph/podman-auth.json')
-        out, _, _ = call_throws(ctx, cmd)
-        if isinstance(engine, Podman):
-            os.chmod('/etc/ceph/podman-auth.json', DEFAULT_MODE)
-    except Exception:
-        raise Error('Failed to login to custom registry @ %s as %s with given password' % (ctx.registry_url, ctx.registry_username))
-
 ##################################
 
 
index 01b22bd80e8f18ed4994bff6191042ca3af1b299..9a3d5f7dbe90cb29f2effe00755335b54bdd83eb 100644 (file)
@@ -1,12 +1,13 @@
 # container_engines.py - container engine types and selection funcs
 
+import os
 
 from typing import Tuple, List, Optional
 
 from .call_wrappers import call_throws, CallVerbosity
 from .context import CephadmContext
 from .container_engine_base import ContainerEngine
-from .constants import MIN_PODMAN_VERSION
+from .constants import DEFAULT_MODE, MIN_PODMAN_VERSION
 from .exceptions import Error
 
 
@@ -86,3 +87,18 @@ def _parse_podman_version(version_str):
             return to_int(val[0:-1], org_e or e)
 
     return tuple(map(to_int, version_str.split('.')))
+
+
+def registry_login(ctx: CephadmContext, url: Optional[str], username: Optional[str], password: Optional[str]) -> None:
+    try:
+        engine = ctx.container_engine
+        cmd = [engine.path, 'login',
+               '-u', username, '-p', password,
+               url]
+        if isinstance(engine, Podman):
+            cmd.append('--authfile=/etc/ceph/podman-auth.json')
+        out, _, _ = call_throws(ctx, cmd)
+        if isinstance(engine, Podman):
+            os.chmod('/etc/ceph/podman-auth.json', DEFAULT_MODE)
+    except Exception:
+        raise Error('Failed to login to custom registry @ %s as %s with given password' % (ctx.registry_url, ctx.registry_username))
index 909185a5a4f67b6a54db977aae637f703d2307a3..122292f6ea58e7468370bfea2fc373c1f6230e0b 100644 (file)
@@ -454,7 +454,7 @@ class TestCephAdm(object):
         with pytest.raises(FileNotFoundError):
             open(os.path.join(_cephadm.DATA_DIR, 'fsid', 'custom_config_files', 'mon.host1', 'no-content.conf'), 'r')
 
-    @mock.patch('cephadm.call_throws')
+    @mock.patch('cephadmlib.container_engines.call_throws')
     @mock.patch('cephadm.get_parm')
     @mock.patch('cephadm.logger')
     def test_registry_login(self, _logger, _get_parm, _call_throws):