Example #1
0
def service_should_show_up_in_pnsrh_n_times(context, expected_num):
    mesosslave_ips = {x[4][0] for x in socket.getaddrinfo('mesosslave', 5051)}

    results = []
    for mesosslave_ip in mesosslave_ips:
        results.extend(
            paasta_native_services_running_here(
                hostname=mesosslave_ip,
                framework_id=context.scheduler.framework_id,  # Ignore anything from other itests.
            ),
        )

    matching_results = [res for res in results if res == (context.service, context.instance, mock.ANY)]
    assert len(matching_results) == expected_num, ("matching results %r, all results %r" % (matching_results, results))
Example #2
0
def test_paasta_native_services_running_here(mock_get_local_slave_state):
    id_1 = 'klingon.ships.detected.249qwiomelht4jioewglkemr.someuuid'
    id_2 = 'fire.photon.torpedos.jtgriemot5yhtwe94.someuuid'
    id_3 = 'dota.axe.cleave.482u9jyoi4wed.someuuid'
    id_4 = 'mesos.deployment.is.hard.someuuid'
    id_5 = 'how.to.fake.data.someuuid'
    ports_1 = '[111-111]'
    ports_2 = '[222-222]'
    ports_3 = '[333-333]'
    ports_4 = '[444-444]'
    ports_5 = '[555-555]'
    mock_get_local_slave_state.return_value = {
        'frameworks': [
            {
                'executors': [
                    {
                        'id': id_1,
                        'resources': {
                            'ports': ports_1
                        },
                        'tasks': [{
                            'state': 'TASK_RUNNING'
                        }],
                    },
                    {
                        'id': id_2,
                        'resources': {
                            'ports': ports_2
                        },
                        'tasks': [{
                            'state': 'TASK_RUNNING'
                        }]
                    },
                ],
                'name':
                'paasta_native service.instance-1111111',
            },
            {
                'executors': [
                    {
                        'id': id_3,
                        'resources': {
                            'ports': ports_3
                        },
                        'tasks': [{
                            'state': 'TASK_RUNNING'
                        }]
                    },
                    {
                        'id': id_4,
                        'resources': {
                            'ports': ports_4
                        },
                        'tasks': [{
                            'state': 'TASK_RUNNING'
                        }]
                    },
                ],
                'name':
                'paasta_native service.instance-3145jgreoifd',
            },
            {
                'executors': [
                    {
                        'id': id_5,
                        'resources': {
                            'ports': ports_5
                        },
                        'tasks': [{
                            'state': 'TASK_STAGED'
                        }]
                    },
                ],
                'name':
                'paasta_native service.instance-754rchoeurcho',
            },
            {
                'executors': [
                    {
                        'id': 'bunk',
                        'resources': {
                            'ports': '[65-65]'
                        },
                        'tasks': [{
                            'state': 'TASK_RUNNING'
                        }]
                    },
                ],
                'name':
                'super_bunk',
            },
        ],
    }
    expected = [
        ('klingon', 'ships', 111),
        ('fire', 'photon', 222),
        ('dota', 'axe', 333),
        ('mesos', 'deployment', 444),
    ]
    actual = native_mesos_scheduler.paasta_native_services_running_here()
    mock_get_local_slave_state.assert_called_once_with(hostname=None)
    assert expected == actual
def test_paasta_native_services_running_here(mock_get_local_slave_state):
    id_1 = "klingon.ships.detected.249qwiomelht4jioewglkemr.someuuid"
    id_2 = "fire.photon.torpedos.jtgriemot5yhtwe94.someuuid"
    id_3 = "dota.axe.cleave.482u9jyoi4wed.someuuid"
    id_4 = "mesos.deployment.is.hard.someuuid"
    id_5 = "how.to.fake.data.someuuid"
    ports_1 = "[111-111]"
    ports_2 = "[222-222]"
    ports_3 = "[333-333]"
    ports_4 = "[444-444]"
    ports_5 = "[555-555]"
    mock_get_local_slave_state.return_value = {
        "frameworks": [
            {
                "executors": [
                    {
                        "id": id_1,
                        "resources": {"ports": ports_1},
                        "tasks": [{"state": "TASK_RUNNING"}],
                    },
                    {
                        "id": id_2,
                        "resources": {"ports": ports_2},
                        "tasks": [{"state": "TASK_RUNNING"}],
                    },
                ],
                "name": "paasta_native service.instance-1111111",
            },
            {
                "executors": [
                    {
                        "id": id_3,
                        "resources": {"ports": ports_3},
                        "tasks": [{"state": "TASK_RUNNING"}],
                    },
                    {
                        "id": id_4,
                        "resources": {"ports": ports_4},
                        "tasks": [{"state": "TASK_RUNNING"}],
                    },
                ],
                "name": "paasta_native service.instance-3145jgreoifd",
            },
            {
                "executors": [
                    {
                        "id": id_5,
                        "resources": {"ports": ports_5},
                        "tasks": [{"state": "TASK_STAGED"}],
                    }
                ],
                "name": "paasta_native service.instance-754rchoeurcho",
            },
            {
                "executors": [
                    {
                        "id": "bunk",
                        "resources": {"ports": "[65-65]"},
                        "tasks": [{"state": "TASK_RUNNING"}],
                    }
                ],
                "name": "super_bunk",
            },
        ]
    }
    expected = [
        ("klingon", "ships", 111),
        ("fire", "photon", 222),
        ("dota", "axe", 333),
        ("mesos", "deployment", 444),
    ]
    actual = native_mesos_scheduler.paasta_native_services_running_here()
    mock_get_local_slave_state.assert_called_once_with(hostname=None)
    assert expected == actual