Exemple #1
0
    def test_creates_custom_resource_definition_if_not_exists_when_watching_it(self, get, post, crd_watcher, watcher):
        get.side_effect = NotFound("Something")
        watcher.watch.side_effect = NotFound("Something")

        expected_application = {
            'metadata': {
                'namespace': 'default',
                'name': 'applications.fiaas.schibsted.io',
                'ownerReferences': [],
                'finalizers': [],
            },
            'spec': {
                'version': 'v1',
                'group': 'fiaas.schibsted.io',
                'names': {
                    'shortNames': ['app', 'fa'],
                    'kind': 'Application',
                    'plural': 'applications'
                }
            }
        }
        expected_status = {
            'metadata': {
                'namespace': 'default',
                'name': 'application-statuses.fiaas.schibsted.io',
                'ownerReferences': [],
                'finalizers': [],
            },
            'spec': {
                'version': 'v1',
                'group': 'fiaas.schibsted.io',
                'names': {
                    'shortNames': ['status', 'appstatus', 'fs'],
                    'kind': 'ApplicationStatus',
                    'plural': 'application-statuses'
                }
            }
        }

        def make_response(data):
            mock_response = mock.create_autospec(Response)
            mock_response.json.return_value = data
            return mock_response

        post.side_effect = [make_response(expected_application), make_response(expected_status)]

        crd_watcher._watch(None)

        calls = [
            mock.call("/apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions/", expected_application),
            mock.call("/apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions/", expected_status)
        ]
        assert post.call_args_list == calls
    def test_creates_third_party_resource_if_not_exists_when_watching_it(
            self, get, post, tpr_watcher, watcher):
        get.side_effect = NotFound("Something")
        watcher.watch.side_effect = NotFound("Something")

        expected_application = {
            'metadata': {
                'namespace': 'default',
                'name': 'paasbeta-application.schibsted.io',
                'ownerReferences': [],
                'finalizers': [],
            },
            'description': 'A paas application definition',
            'versions': [{
                'name': 'v1beta'
            }]
        }
        expected_status = {
            'metadata': {
                'namespace': 'default',
                'name': 'paasbeta-status.schibsted.io',
                'ownerReferences': [],
                'finalizers': [],
            },
            'description': 'A paas application status',
            'versions': [{
                'name': 'v1beta'
            }]
        }

        def make_response(data):
            mock_response = mock.create_autospec(Response)
            mock_response.json.return_value = data
            return mock_response

        post.side_effect = [
            make_response(expected_application),
            make_response(expected_status)
        ]

        tpr_watcher._watch(None)

        calls = [
            mock.call("/apis/extensions/v1beta1/thirdpartyresources/",
                      expected_application),
            mock.call("/apis/extensions/v1beta1/thirdpartyresources/",
                      expected_status)
        ]
        assert post.call_args_list == calls
Exemple #3
0
 def test_service_created_if_not_exists(self, post, get):
     get.side_effect = NotFound()
     service = create_default_service()
     call_params = service.as_dict()
     assert service._new
     service.save()
     assert not service._new
     pytest.helpers.assert_any_call(post, SERVICES_URI, call_params)
    def test_ignore_notfound_on_cleanup(self, find, delete, app_spec):
        delete.side_effect = NotFound()
        find.return_value = [_create_status(i) for i in range(OLD_STATUSES_TO_KEEP + 1)]

        try:
            _cleanup(app_spec.name, app_spec.namespace)
        except NotFound:
            pytest.fail("delete raised NotFound on signal")
Exemple #5
0
    def test_created_if_not_exists(self, post, api_get):
        api_get.side_effect = NotFound()
        deployment = _create_default_deployment()
        call_params = deployment.as_dict()

        assert deployment._new
        deployment.save()
        assert not deployment._new

        pytest.helpers.assert_any_call(post, _uri(NAMESPACE), call_params)
Exemple #6
0
    def test_pod_created_if_not_exists(self, post, api_get):
        api_get.side_effect = NotFound()
        pod = _create_pod()
        call_params = pod.as_dict()
        post.return_value.json.return_value = call_params

        assert pod._new
        pod.save()
        assert not pod._new
        pytest.helpers.assert_any_call(post, POD_URI, call_params)
Exemple #7
0
    def test_created_if_not_exists(self, post, api_get):
        api_get.side_effect = NotFound()
        ingress = _create_default_ingress()
        call_params = ingress.as_dict()

        assert ingress._new
        ingress.save()
        assert not ingress._new

        pytest.helpers.assert_any_call(post, _uri(NAMESPACE), call_params)
Exemple #8
0
    def test_created_if_not_exists(self, post, api_get):
        api_get.side_effect = NotFound()
        configmap = _create_default_configmap()
        call_params = configmap.as_dict()

        assert configmap._new
        configmap.save()
        assert not configmap._new

        pytest.helpers.assert_any_call(post, _uri(NAMESPACE), call_params)
    def test_created_if_not_exists(self, post, api_get):
        api_get.side_effect = NotFound()
        resourcequota = _create_default_resourcequota()
        call_params = resourcequota.as_dict()
        post.return_value.json.return_value = call_params

        assert resourcequota._new
        resourcequota.save()
        assert not resourcequota._new

        pytest.helpers.assert_any_call(post, _uri(NAMESPACE), call_params)
Exemple #10
0
    def test_created_if_not_exists(self, post, api_get):
        api_get.side_effect = NotFound()
        job = _create_default_job()
        call_params = job.as_dict()
        post.return_value.json.return_value = call_params

        assert job._new
        job.save()
        assert not job._new

        pytest.helpers.assert_any_call(post, _uri(NAMESPACE), call_params)
Exemple #11
0
    def test_created_if_not_exists(self, post, api_get):
        api_get.side_effect = NotFound()
        service_account = _create_default_service_account()
        call_params = service_account.as_dict()
        post.return_value.json.return_value = call_params

        assert service_account._new
        service_account.save()
        assert not service_account._new

        pytest.helpers.assert_any_call(post, _uri(NAMESPACE), call_params)
Exemple #12
0
    def test_created_if_not_exists_with_percentage_rollout_strategy(self, post, api_get):
        api_get.side_effect = NotFound()
        deployment = _create_default_deployment()
        rolling_update = RollingUpdateDeployment(maxUnavailable="50%", maxSurge="50%")
        deployment.spec.strategy = DeploymentStrategy(type="RollingUpdate", rollingUpdate=rolling_update)
        call_params = deployment.as_dict()

        assert deployment._new
        deployment.save()
        assert not deployment._new

        pytest.helpers.assert_any_call(post, _uri(NAMESPACE), call_params)
Exemple #13
0
    def test_create_new_paasbetaapplication(self, post, get):
        get.side_effect = NotFound()
        pba = PaasbetaApplication(metadata=_create_default_metadata(), spec=_create_default_paasbetaapplicationspec())
        assert pba._new
        expected_call = pba.as_dict()
        mock_response = mock.create_autospec(Response)
        mock_response.json.return_value = expected_call
        post.return_value = mock_response

        pba.save()

        pytest.helpers.assert_any_call(post, API_BASE_PATH, expected_call)
Exemple #14
0
 def _get(url, **kwargs):
     if url.endswith("{}/".format(status_type)):
         return response
     else:
         raise NotFound()
def get():
    with mock.patch('k8s.client.Client.get') as mockk:
        mockk.side_effect = NotFound()
        yield mockk
Exemple #16
0
 def crd(self, request):
     with patch('fiaas_mast.fiaas.FiaasApplication.list') as fm:
         fm.side_effect = None if request.param else NotFound()
         yield request.param
Exemple #17
0
 def tpr(self, request):
     with patch('fiaas_mast.paasbeta.PaasbetaApplication.list') as pm:
         pm.side_effect = None if request.param else NotFound()
         yield request.param