Ejemplo n.º 1
0
def test_marathon_smartstack_status(
    mock_get_slaves,
    mock_get_expected_instance_count_for_namespace,
    mock_get_backends,
    mock_match_backends_and_tasks,
):
    mock_get_slaves.return_value = [{
        "hostname": "host1.paasta.party",
        "attributes": {
            "region": "us-north-3"
        }
    }]
    mock_get_expected_instance_count_for_namespace.return_value = 2

    mock_backend = HaproxyBackend(
        status="UP",
        svname="host1_1.2.3.4:123",
        check_status="L7OK",
        check_code="0",
        check_duration="1",
        lastchg="9876",
    )
    mock_task = mock.create_autospec(MarathonTask)
    mock_match_backends_and_tasks.return_value = [(mock_backend, mock_task)]

    settings.system_paasta_config = mock.create_autospec(SystemPaastaConfig)
    settings.system_paasta_config.get_deploy_blacklist.return_value = []
    mock_service_config = marathon_tools.MarathonServiceConfig(
        service="fake_service",
        cluster="fake_cluster",
        instance="fake_instance",
        config_dict={"bounce_method": "fake_bounce"},
        branch_dict=None,
    )
    mock_service_namespace_config = ServiceNamespaceConfig()

    smartstack_status = instance.marathon_smartstack_status(
        "fake_service",
        "fake_instance",
        mock_service_config,
        mock_service_namespace_config,
        tasks=[mock_task],
        should_return_individual_backends=True,
    )
    assert smartstack_status == {
        "registration":
        "fake_service.fake_instance",
        "expected_backends_per_location":
        2,
        "locations": [{
            "name":
            "us-north-3",
            "running_backends_count":
            1,
            "backends": [{
                "hostname": "host1",
                "port": 123,
                "status": "UP",
                "check_status": "L7OK",
                "check_code": "0",
                "last_change": 9876,
                "has_associated_task": True,
                "check_duration": 1,
            }],
        }],
    }
Ejemplo n.º 2
0
def test_kubernetes_smartstack_status(
    mock_get_expected_instance_count_for_namespace,
    mock_get_all_nodes,
    mock_kube_smartstack_replication_checker,
    mock_get_backends,
    mock_match_backends_and_pods,
):
    mock_get_all_nodes.return_value = [{
        "hostname": "host1.paasta.party",
        "attributes": {
            "region": "us-north-3"
        }
    }]

    mock_kube_smartstack_replication_checker.return_value.get_allowed_locations_and_hosts.return_value = {
        "us-north-3":
        [DiscoveredHost(hostname="host1.paasta.party", pool="default")]
    }

    mock_get_expected_instance_count_for_namespace.return_value = 2
    mock_backend = HaproxyBackend(
        status="UP",
        svname="host1_1.2.3.4:123",
        check_status="L7OK",
        check_code="0",
        check_duration="1",
        lastchg="9876",
    )
    mock_pod = mock.create_autospec(V1Pod)
    mock_match_backends_and_pods.return_value = [(mock_backend, mock_pod)]

    mock_job_config = kubernetes_tools.KubernetesDeploymentConfig(
        service="fake_service",
        cluster="fake_cluster",
        instance="fake_instance",
        config_dict={"bounce_method": "fake_bounce"},
        branch_dict=None,
    )
    mock_service_namespace_config = ServiceNamespaceConfig()
    mock_settings = mock.Mock()

    smartstack_status = instance.pik.mesh_status(
        service="fake_service",
        service_mesh=ServiceMesh.SMARTSTACK,
        instance="fake_instance",
        job_config=mock_job_config,
        service_namespace_config=mock_service_namespace_config,
        pods=[mock_pod],
        should_return_individual_backends=True,
        settings=mock_settings,
    )
    assert smartstack_status == {
        "registration":
        "fake_service.fake_instance",
        "expected_backends_per_location":
        2,
        "locations": [{
            "name":
            "us-north-3",
            "running_backends_count":
            1,
            "backends": [{
                "hostname": "host1:1.2.3.4",
                "port": 123,
                "status": "UP",
                "check_status": "L7OK",
                "check_code": "0",
                "last_change": 9876,
                "has_associated_task": True,
                "check_duration": 1,
            }],
        }],
    }