]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ansible.git/commitdiff
library/cephadm_bootstrap: add registry support
authorDimitri Savineau <dsavinea@redhat.com>
Wed, 6 Jan 2021 19:06:48 +0000 (14:06 -0500)
committerGuillaume Abrioux <gabrioux@redhat.com>
Wed, 3 Feb 2021 07:27:28 +0000 (08:27 +0100)
This adds the custom registry auth support when using a registry with
authentication.

Signed-off-by: Dimitri Savineau <dsavinea@redhat.com>
library/cephadm_bootstrap.py
tests/library/test_cephadm_bootstrap.py

index 73de09e2fbeccf322d6886ca7cadfa54da20ba0b..f47a167ba74fe36a3b0c9cf65cee4b1eedb15865 100644 (file)
@@ -81,6 +81,22 @@ options:
             - Manage firewall rules with firewalld.
         required: false
         default: true
+    registry_url:
+        description:
+            - URL for custom registry.
+        required: false
+    registry_username:
+        description:
+            - Username for custom registry.
+        required: false
+    registry_password:
+        description:
+            - Password for custom registry.
+        required: false
+    registry_json:
+        description:
+            - JSON file with custom registry login info (URL, username, password).
+        required: false
 author:
     - Dimitri Savineau <dsavinea@redhat.com>
 '''
@@ -122,8 +138,20 @@ def main():
             dashboard_password=dict(type='str', required=False, no_log=True),
             monitoring=dict(type='bool', required=False, default=True),
             firewalld=dict(type='bool', required=False, default=True),
+            registry_url=dict(type='str', require=False),
+            registry_username=dict(type='str', require=False),
+            registry_password=dict(type='str', require=False, no_log=True),
+            registry_json=dict(type='path', require=False),
         ),
         supports_check_mode=True,
+        mutually_exclusive=[
+            ('registry_json', 'registry_url'),
+            ('registry_json', 'registry_username'),
+            ('registry_json', 'registry_password'),
+        ],
+        required_together=[
+            ('registry_url', 'registry_username', 'registry_password')
+        ],
     )
 
     mon_ip = module.params.get('mon_ip')
@@ -136,6 +164,10 @@ def main():
     dashboard_password = module.params.get('dashboard_password')
     monitoring = module.params.get('monitoring')
     firewalld = module.params.get('firewalld')
+    registry_url = module.params.get('registry_url')
+    registry_username = module.params.get('registry_username')
+    registry_password = module.params.get('registry_password')
+    registry_json = module.params.get('registry_json')
 
     startd = datetime.datetime.now()
 
@@ -169,6 +201,14 @@ def main():
     if not firewalld:
         cmd.append('--skip-firewalld')
 
+    if registry_url and registry_username and registry_password:
+        cmd.extend(['--registry-url', registry_url,
+                    '--registry-username', registry_username,
+                    '--registry-password', registry_password])
+
+    if registry_json:
+        cmd.extend(['--registry-json', registry_json])
+
     if module.check_mode:
         exit_module(
             module=module,
index bf755af85cf857cfcb4a2de2adbee349af309967..b9bbe0453f408d5e6e043d2ff0e23c364a4f8b57 100644 (file)
@@ -6,6 +6,10 @@ import cephadm_bootstrap
 fake_fsid = '0f1e0605-db0b-485c-b366-bd8abaa83f3b'
 fake_image = 'quay.ceph.io/ceph/daemon-base:latest-master-devel'
 fake_ip = '192.168.42.1'
+fake_registry = 'quay.ceph.io'
+fake_registry_user = 'foo'
+fake_registry_pass = 'bar'
+fake_registry_json = 'registry.json'
 
 
 class TestCephadmBootstrapModule(object):
@@ -250,3 +254,51 @@ class TestCephadmBootstrapModule(object):
         assert result['changed']
         assert result['cmd'] == ['cephadm', 'bootstrap', '--mon-ip', fake_ip, '--skip-firewalld']
         assert result['rc'] == 0
+
+    @patch('ansible.module_utils.basic.AnsibleModule.exit_json')
+    @patch('ansible.module_utils.basic.AnsibleModule.run_command')
+    def test_with_registry_credentials(self, m_run_command, m_exit_json):
+        ca_test_common.set_module_args({
+            'mon_ip': fake_ip,
+            'registry_url': fake_registry,
+            'registry_username': fake_registry_user,
+            'registry_password': fake_registry_pass
+        })
+        m_exit_json.side_effect = ca_test_common.exit_json
+        stdout = ''
+        stderr = ''
+        rc = 0
+        m_run_command.return_value = rc, stdout, stderr
+
+        with pytest.raises(ca_test_common.AnsibleExitJson) as result:
+            cephadm_bootstrap.main()
+
+        result = result.value.args[0]
+        assert result['changed']
+        assert result['cmd'] == ['cephadm', 'bootstrap', '--mon-ip', fake_ip,
+                                 '--registry-url', fake_registry,
+                                 '--registry-username', fake_registry_user,
+                                 '--registry-password', fake_registry_pass]
+        assert result['rc'] == 0
+
+    @patch('ansible.module_utils.basic.AnsibleModule.exit_json')
+    @patch('ansible.module_utils.basic.AnsibleModule.run_command')
+    def test_with_registry_json_file(self, m_run_command, m_exit_json):
+        ca_test_common.set_module_args({
+            'mon_ip': fake_ip,
+            'registry_json': fake_registry_json
+        })
+        m_exit_json.side_effect = ca_test_common.exit_json
+        stdout = ''
+        stderr = ''
+        rc = 0
+        m_run_command.return_value = rc, stdout, stderr
+
+        with pytest.raises(ca_test_common.AnsibleExitJson) as result:
+            cephadm_bootstrap.main()
+
+        result = result.value.args[0]
+        assert result['changed']
+        assert result['cmd'] == ['cephadm', 'bootstrap', '--mon-ip', fake_ip,
+                                 '--registry-json', fake_registry_json]
+        assert result['rc'] == 0