def test_raises_api_error_despite_default(client_mock, resource, status): error = kubernetes.client.rest.ApiException(status=status) apicls_mock = client_mock.ApiextensionsV1beta1Api apicls_mock.return_value.read_custom_resource_definition.side_effect = error with pytest.raises(kubernetes.client.rest.ApiException) as e: read_crd(resource=resource, default=object()) assert e.value.status == status
def test_when_absent_with_default(client_mock, resource, default, status): error = kubernetes.client.rest.ApiException(status=status) apicls_mock = client_mock.ApiextensionsV1beta1Api apicls_mock.return_value.read_custom_resource_definition.side_effect = error crd = read_crd(resource=resource, default=default) assert crd is default
def test_when_present(client_mock, resource): apicls_mock = client_mock.ApiextensionsV1beta1Api readfn_mock = apicls_mock.return_value.read_custom_resource_definition result_mock = readfn_mock.return_value crd = read_crd(resource=resource) assert crd is result_mock assert apicls_mock.called assert apicls_mock.call_count == 1 assert readfn_mock.called assert readfn_mock.call_count == 1 assert readfn_mock.call_args_list == [ call(name=f'{resource.plural}.{resource.group}') ]
def _is_peering_legacy(name: str, namespace: Optional[str]): """ Legacy mode for the peering: cluster-scoped KopfPeering (new mode: namespaced). .. deprecated:: 1.0 This logic will be removed since 1.0. Deploy ``ClusterKopfPeering`` as per documentation, and use it normally. """ crd = fetching.read_crd(resource=LEGACY_PEERING_RESOURCE, default=None) if crd is None: return False if str(crd.get('spec', {}).get('scope', '')).lower() != 'cluster': return False # no legacy mode detected obj = fetching.read_obj(resource=LEGACY_PEERING_RESOURCE, name=name, default=None) return obj is not None