Beispiel #1
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()
    def test_signals_start_of_deploy(self, app_spec, lifecycle, lifecycle_subject, deployer, annotations, repository):
        if annotations:
            app_spec = app_spec._replace(annotations=LabelAndAnnotationSpec(*[annotations] * 6))
        deployer._queue = [DeployerEvent("UPDATE", app_spec, lifecycle_subject)]
        deployer()

        lifecycle.state_change_signal.send.assert_called_with(status=STATUS_STARTED, subject=lifecycle_subject)
Beispiel #3
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()
 def deployer(self, app_spec, bookkeeper, adapter, scheduler, lifecycle,
              lifecycle_subject, config):
     deployer = Deployer(Queue(), bookkeeper, adapter, scheduler, lifecycle,
                         config)
     deployer._queue = [
         DeployerEvent("UPDATE", app_spec, lifecycle_subject)
     ]
     return deployer
    def test_signals_failure_on_exception(self, app_spec, lifecycle, lifecycle_subject, deployer, adapter, annotations, repository):
        if annotations:
            app_spec = app_spec._replace(annotations=LabelAndAnnotationSpec(*[annotations] * 6))
        deployer._queue = [DeployerEvent("UPDATE", app_spec, lifecycle_subject)]
        adapter.deploy.side_effect = Exception("message")

        deployer()

        lifecycle.state_change_signal.send.assert_called_with(status=STATUS_FAILED, subject=lifecycle_subject)
    def test_signals_start_of_deploy(self, app_spec, lifecycle, deployer,
                                     annotations, repository):
        if annotations:
            app_spec = app_spec._replace(annotations=LabelAndAnnotationSpec(
                *[annotations] * 5))
        deployer._queue = [DeployerEvent("UPDATE", app_spec)]
        deployer()

        lifecycle.deploy_signal.send.assert_called_with(
            app_name=app_spec.name,
            namespace=app_spec.namespace,
            deployment_id=app_spec.deployment_id,
            repository=repository)
    def test_signals_failure_on_exception(self, app_spec, lifecycle, deployer,
                                          adapter, annotations, repository):
        if annotations:
            app_spec = app_spec._replace(annotations=LabelAndAnnotationSpec(
                *[annotations] * 5))
        deployer._queue = [DeployerEvent("UPDATE", app_spec)]
        adapter.deploy.side_effect = Exception("message")

        deployer()

        lifecycle.success_signal.send.assert_not_called()
        lifecycle.error_signal.send.assert_called_with(
            app_name=app_spec.name,
            namespace=app_spec.namespace,
            deployment_id=app_spec.deployment_id,
            repository=repository)
Beispiel #8
0
 def deployer(self, app_spec, bookkeeper, adapter, scheduler, lifecycle):
     deployer = Deployer(Queue(), bookkeeper, adapter, scheduler, lifecycle)
     deployer._queue = [DeployerEvent("UPDATE", app_spec)]
     return deployer