def test_is_available_skopeo_image(): result = {'rc': 0} # test unauth secure and insecure openshift_docker_insecure_registries = ['insecure.redhat.io'] task_vars = { 'openshift_docker_insecure_registries': openshift_docker_insecure_registries } dia = DockerImageAvailability(task_vars=task_vars) with patch.object(DockerImageAvailability, 'execute_module_with_retries') as m1: m1.return_value = result assert dia.is_available_skopeo_image( 'registry.redhat.io/openshift3/ose-pod') is True m1.assert_called_with( 'command', { '_uses_shell': True, '_raw_params': ' timeout 30 skopeo --debug inspect --tls-verify=true docker://registry.redhat.io/openshift3/ose-pod' }) assert dia.is_available_skopeo_image( 'insecure.redhat.io/openshift3/ose-pod') is True m1.assert_called_with( 'command', { '_uses_shell': True, '_raw_params': ' timeout 30 skopeo --debug inspect --tls-verify=false docker://insecure.redhat.io/openshift3/ose-pod' }) # test auth task_vars = { 'oreg_auth_user': '******', 'oreg_auth_password': '******' } dia = DockerImageAvailability(task_vars=task_vars) with patch.object(DockerImageAvailability, 'execute_module_with_retries') as m1: m1.return_value = result assert dia.is_available_skopeo_image( 'registry.redhat.io/openshift3/ose-pod') is True m1.assert_called_with( 'command', { '_uses_shell': True, '_raw_params': ' timeout 30 skopeo --debug inspect --tls-verify=true --creds=test_user:test_pass docker://registry.redhat.io/openshift3/ose-pod' })
def test_registry_availability(image, registries, connection_test_failed, skopeo_failed, expect_success, expect_registries_reached): def execute_module(module_name=None, *_): if module_name == "wait_for": return dict(msg="msg", failed=connection_test_failed) elif module_name == "command": return dict(msg="msg", failed=skopeo_failed) check = DockerImageAvailability(execute_module, task_vars()) check._module_retry_interval = 0 available = check.is_available_skopeo_image(image, registries) assert available == expect_success assert expect_registries_reached == check.reachable_registries