def test_is_able_to_watch_custom_resource_definition(
            self, crd_watcher, deploy_queue, watcher):
        watcher.watch.return_value = [WatchEvent(ADD_EVENT, FiaasApplication)]

        assert deploy_queue.qsize() == 0
        crd_watcher._watch(None)
        assert deploy_queue.qsize() == 1
示例#2
0
    def test_deploy(self, crd_watcher, deploy_queue, spec_factory, watcher, app_spec, event, deployer_event_type, lifecycle,
                    annotations, repository):
        event["object"]["metadata"]["annotations"] = annotations
        watcher.watch.return_value = [WatchEvent(event, FiaasApplication)]

        spec = event["object"]["spec"]
        app_name = spec["application"]
        namespace = event["object"]["metadata"]["namespace"]
        deployment_id = (event["object"]["metadata"]["labels"]["fiaas/deployment_id"]
                         if deployer_event_type != "DELETE" else "deletion")

        app_spec = app_spec._replace(name=app_name, namespace=namespace, deployment_id=deployment_id)
        spec_factory.return_value = app_spec

        crd_watcher._watch(None)

        if event in [ADD_EVENT, MODIFIED_EVENT]:
            lifecycle.initiate.assert_called_once_with(app_name=event["object"]["spec"]["application"],
                                                       namespace=event["object"]["metadata"]["namespace"],
                                                       deployment_id='deployment_id',
                                                       repository=repository)

        app_config = spec["config"]
        spec_factory.assert_called_once_with(name=app_name, image=spec["image"], app_config=app_config,
                                             teams=[], tags=[],
                                             deployment_id=deployment_id,
                                             namespace=namespace)

        assert deploy_queue.qsize() == 1
        deployer_event = deploy_queue.get_nowait()
        assert deployer_event == DeployerEvent(deployer_event_type, app_spec)
        assert deploy_queue.empty()
示例#3
0
    def test_deploy(self, crd_watcher, deploy_queue, spec_factory, watcher,
                    app_spec, event, deployer_event_type, lifecycle,
                    annotations, repository):
        event["object"]["spec"]["config"]["annotations"] = annotations
        watcher.watch.return_value = [WatchEvent(event, FiaasApplication)]

        spec = event["object"]["spec"]
        app_name = spec["application"]
        uid = event["object"]["metadata"]["uid"]
        namespace = event["object"]["metadata"]["namespace"]
        deployment_id = (
            event["object"]["metadata"]["labels"]["fiaas/deployment_id"]
            if deployer_event_type != "DELETE" else "deletion")

        app_spec = app_spec._replace(name=app_name,
                                     namespace=namespace,
                                     deployment_id=deployment_id)
        spec_factory.return_value = app_spec
        lifecycle_subject = Subject(uid, app_name, namespace, deployment_id,
                                    repository, app_spec.labels.status,
                                    app_spec.annotations.status)
        lifecycle.initiate.return_value = lifecycle_subject

        crd_watcher._watch(None)

        if event in [ADD_EVENT, MODIFIED_EVENT]:
            lifecycle.initiate.assert_called_once_with(
                uid=event["object"]["metadata"]["uid"],
                app_name=event["object"]["spec"]["application"],
                namespace=event["object"]["metadata"]["namespace"],
                deployment_id='deployment_id',
                repository=repository,
                labels=None,
                annotations=None)

        app_config = spec["config"]
        additional_labels = AdditionalLabelsOrAnnotations()
        additional_annotations = AdditionalLabelsOrAnnotations()
        spec_factory.assert_called_once_with(
            uid="c1f34517-6f54-11ea-8eaf-0ad3d9992c8c",
            name=app_name,
            image=spec["image"],
            app_config=app_config,
            teams=[],
            tags=[],
            deployment_id=deployment_id,
            namespace=namespace,
            additional_labels=additional_labels,
            additional_annotations=additional_annotations)

        assert deploy_queue.qsize() == 1
        deployer_event = deploy_queue.get_nowait()
        if event in [ADD_EVENT, MODIFIED_EVENT]:
            assert deployer_event == DeployerEvent(deployer_event_type,
                                                   app_spec, lifecycle_subject)
        else:
            assert deployer_event == DeployerEvent(deployer_event_type,
                                                   app_spec, None)
        assert deploy_queue.empty()
示例#4
0
 def test_watch_event_deleted(self):
     watch_event = WatchEvent({
         "type": "DELETED",
         "object": {
             "value": 42
         }
     }, Example)
     assert watch_event.type == WatchEvent.DELETED
     assert watch_event.object == Example(value=42)
示例#5
0
 def test_watch_event_modified(self):
     watch_event = WatchEvent({
         "type": "MODIFIED",
         "object": {
             "value": 42
         }
     }, Example)
     assert watch_event.type == WatchEvent.MODIFIED
     assert watch_event.object == Example(value=42)
示例#6
0
 def test_watch_event_added(self):
     watch_event = WatchEvent({
         "type": "ADDED",
         "object": {
             "value": 42
         }
     }, Example)
     assert watch_event.type == WatchEvent.ADDED
     assert watch_event.object == Example(value=42)
    def test_is_able_to_watch_third_party_resource(self, tpr_watcher,
                                                   deploy_queue, watcher):
        watcher.watch.return_value = [
            WatchEvent(ADD_EVENT, PaasbetaApplication)
        ]

        assert deploy_queue.qsize() == 0
        tpr_watcher._watch(None)
        assert deploy_queue.qsize() == 1
    def test_deploy_based_on_status_result(self, crd_watcher, deploy_queue,
                                           watcher, status_get, result, count):
        watcher.watch.return_value = [WatchEvent(ADD_EVENT, FiaasApplication)]
        status_get.side_effect = lambda *args, **kwargs: mock.DEFAULT  # disable default behavior of raising NotFound
        status_get.return_value = FiaasApplicationStatus(new=False,
                                                         result=result)

        assert deploy_queue.qsize() == 0
        crd_watcher._watch(None)
        assert deploy_queue.qsize() == count
示例#9
0
    def test_deploy_reports_failure_on_exception(self, crd_watcher, deploy_queue, spec_factory, watcher, event, deployer_event_type,
                                                 error, lifecycle, annotations, repository):
        event["object"]["metadata"]["annotations"] = annotations
        watcher.watch.return_value = [WatchEvent(event, FiaasApplication)]

        spec_factory.side_effect = error

        crd_watcher._watch(None)

        lifecycle.failed.assert_called_once_with(app_name=event["object"]["spec"]["application"],
                                                 namespace=event["object"]["metadata"]["namespace"],
                                                 deployment_id='deployment_id',
                                                 repository=repository)
        assert deploy_queue.empty()