From: Dimitri Savineau Date: Wed, 6 Jan 2021 19:06:48 +0000 (-0500) Subject: library/cephadm_bootstrap: add registry support X-Git-Tag: v6.0.0~21 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=bc6948037faefcaeb6002404f270c06cc7cf73d7;p=ceph-ansible.git library/cephadm_bootstrap: add registry support This adds the custom registry auth support when using a registry with authentication. Signed-off-by: Dimitri Savineau --- diff --git a/library/cephadm_bootstrap.py b/library/cephadm_bootstrap.py index 73de09e2f..f47a167ba 100644 --- a/library/cephadm_bootstrap.py +++ b/library/cephadm_bootstrap.py @@ -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 ''' @@ -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, diff --git a/tests/library/test_cephadm_bootstrap.py b/tests/library/test_cephadm_bootstrap.py index bf755af85..b9bbe0453 100644 --- a/tests/library/test_cephadm_bootstrap.py +++ b/tests/library/test_cephadm_bootstrap.py @@ -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