Esempio n. 1
0
def test_main_no_chronos_config():
    with patch(
        'paasta_tools.marathon_tools.load_marathon_config', autospec=True,
    ) as load_marathon_config_patch, patch(
        'paasta_tools.paasta_metastatus.load_chronos_config', autospec=True,
    ) as load_chronos_config_patch, patch(
        'paasta_tools.paasta_metastatus.get_mesos_master', autospec=True,
    ) as get_mesos_master, patch(
        'paasta_tools.metrics.metastatus_lib.get_mesos_state_status', autospec=True,
        return_value=([('fake_output', True)]),
    ) as get_mesos_state_status_patch, patch(
        'paasta_tools.metrics.metastatus_lib.get_mesos_resource_utilization_health', autospec=True,
    ) as get_mesos_resource_utilization_health_patch, patch(
        'paasta_tools.metrics.metastatus_lib.get_marathon_status', autospec=True,
        return_value=([('fake_output', True)]),
    ):
        fake_master = Mock(autospace=True)
        fake_master.metrics_snapshot.return_value = {
            'master/frameworks_active': 2,
            'master/frameworks_inactive': 0,
            'master/frameworks_connected': 2,
            'master/frameworks_disconnected': 0,
        }
        fake_master.state.return_value = {}
        get_mesos_master.return_value = fake_master

        load_marathon_config_patch.return_value = {}

        get_mesos_state_status_patch.return_value = []
        get_mesos_resource_utilization_health_patch.return_value = []

        load_chronos_config_patch.return_value = {}
        with raises(SystemExit) as excinfo:
            paasta_metastatus.main(())
        assert excinfo.value.code == 0
Esempio n. 2
0
def test_main_no_chronos_config():
    with patch(
        'paasta_tools.paasta_metastatus.load_system_paasta_config', autospec=True,
    ), patch(
        'paasta_tools.paasta_metastatus.is_mesos_available', autospec=True,
        return_value=True,
    ), patch(
        'paasta_tools.paasta_metastatus.load_chronos_config', autospec=True,
    ) as load_chronos_config_patch, patch(
        'paasta_tools.paasta_metastatus.get_mesos_master', autospec=True,
    ) as get_mesos_master, patch(
        'paasta_tools.metrics.metastatus_lib.get_mesos_state_status', autospec=True,
        return_value=([('fake_output', True)]),
    ) as get_mesos_state_status_patch, patch(
        'paasta_tools.metrics.metastatus_lib.get_mesos_resource_utilization_health', autospec=True,
    ) as get_mesos_resource_utilization_health_patch, patch(
        'paasta_tools.metrics.metastatus_lib.get_marathon_status',
        autospec=True,
        return_value=([HealthCheckResult(message='fake_output', healthy=True)]),
    ):
        fake_master = Mock(autospace=True)
        fake_master.state.return_value = {}
        get_mesos_master.return_value = fake_master

        get_mesos_state_status_patch.return_value = []
        get_mesos_resource_utilization_health_patch.return_value = []

        load_chronos_config_patch.return_value = {}
        with raises(SystemExit) as excinfo:
            paasta_metastatus.main(())
        assert excinfo.value.code == 0
Esempio n. 3
0
def test_main_marathon_jsondecode_error():
    with patch(
        "paasta_tools.paasta_metastatus.load_system_paasta_config", autospec=True
    ), patch(
        "paasta_tools.paasta_metastatus.is_mesos_available",
        autospec=True,
        return_value=True,
    ), patch(
        "paasta_tools.marathon_tools.get_marathon_servers", autospec=True
    ) as get_marathon_status_patch, patch(
        "paasta_tools.paasta_metastatus.get_mesos_master", autospec=True
    ) as get_mesos_master, patch(
        "paasta_tools.metrics.metastatus_lib.get_mesos_state_status",
        autospec=True,
        return_value=([("fake_output", True)]),
    ) as get_mesos_state_status_patch, patch(
        "paasta_tools.metrics.metastatus_lib.get_mesos_resource_utilization_health",
        autospec=True,
    ) as get_mesos_resource_utilization_health_patch, patch(
        "paasta_tools.metrics.metastatus_lib.get_marathon_status", autospec=True
    ) as get_marathon_status_patch:
        fake_master = Mock(autospace=True)
        fake_master.state.return_value = {}
        get_mesos_master.return_value = fake_master

        get_marathon_status_patch.return_value = [{"url": "http://foo"}]

        get_marathon_status_patch.side_effect = ValueError("could not decode json")

        get_mesos_state_status_patch.return_value = []
        get_mesos_resource_utilization_health_patch.return_value = []

        with raises(SystemExit) as excinfo:
            paasta_metastatus.main(())
        assert excinfo.value.code == 2
def test_main_no_chronos_config():
    with contextlib.nested(
        patch("paasta_tools.marathon_tools.load_marathon_config", autospec=True),
        patch("paasta_tools.chronos_tools.load_chronos_config", autospec=True),
        patch("paasta_tools.paasta_metastatus.get_mesos_state_from_leader", autospec=True),
        patch("paasta_tools.paasta_metastatus.get_mesos_status", autospec=True, return_value=([("fake_output", True)])),
        patch(
            "paasta_tools.paasta_metastatus.get_marathon_status", autospec=True, return_value=([("fake_output", True)])
        ),
        patch("paasta_tools.paasta_metastatus.parse_args", autospec=True),
    ) as (
        load_marathon_config_patch,
        load_chronos_config_patch,
        load_get_mesos_state_from_leader_patch,
        load_get_mesos_status_patch,
        load_get_marathon_status_patch,
        parse_args_patch,
    ):

        fake_args = Mock(verbose=0)
        parse_args_patch.return_value = fake_args
        load_chronos_config_patch.side_effect = ChronosNotConfigured
        with raises(SystemExit) as excinfo:
            paasta_metastatus.main()
        assert excinfo.value.code == 0
Esempio n. 5
0
def test_main_no_chronos_config():
    with contextlib.nested(
            patch('paasta_tools.marathon_tools.load_marathon_config',
                  autospec=True),
            patch('paasta_tools.chronos_tools.load_chronos_config',
                  autospec=True),
            patch('paasta_tools.paasta_metastatus.get_mesos_state_from_leader',
                  autospec=True),
            patch('paasta_tools.paasta_metastatus.get_mesos_status',
                  autospec=True,
                  return_value=([('fake_output', True)])),
            patch('paasta_tools.paasta_metastatus.get_marathon_status',
                  autospec=True,
                  return_value=([('fake_output', True)])),
            patch('paasta_tools.paasta_metastatus.parse_args', autospec=True),
    ) as (
            load_marathon_config_patch,
            load_chronos_config_patch,
            load_get_mesos_state_from_leader_patch,
            load_get_mesos_status_patch,
            load_get_marathon_status_patch,
            parse_args_patch,
    ):

        fake_args = Mock(verbose=0, )
        parse_args_patch.return_value = fake_args
        load_chronos_config_patch.side_effect = ChronosNotConfigured
        with raises(SystemExit) as excinfo:
            paasta_metastatus.main()
        assert excinfo.value.code == 0
Esempio n. 6
0
def test_main_marathon_jsondecode_error():
    with patch(
            'paasta_tools.paasta_metastatus.load_system_paasta_config',
            autospec=True,
    ), patch(
            'paasta_tools.marathon_tools.load_marathon_config',
            autospec=True,
    ) as load_marathon_config_patch, patch(
            'paasta_tools.paasta_metastatus.load_chronos_config',
            autospec=True,
    ), patch(
            'paasta_tools.paasta_metastatus.get_mesos_master',
            autospec=True,
    ) as get_mesos_master, patch(
            'paasta_tools.metrics.metastatus_lib.get_mesos_state_status',
            autospec=True,
            return_value=([('fake_output', True)]),
    ) as get_mesos_state_status_patch, patch(
            'paasta_tools.metrics.metastatus_lib.get_mesos_resource_utilization_health',
            autospec=True,
    ) as get_mesos_resource_utilization_health_patch, patch(
            'paasta_tools.metrics.metastatus_lib.get_marathon_client',
            autospec=True,
    ) as get_marathon_client_patch, patch(
            'paasta_tools.metrics.metastatus_lib.get_marathon_status',
            autospec=True,
    ) as get_marathon_status_patch:
        fake_master = Mock(autospace=True)
        fake_master.metrics_snapshot.return_value = {
            'master/frameworks_active': 2,
            'master/frameworks_inactive': 0,
            'master/frameworks_connected': 2,
            'master/frameworks_disconnected': 0,
        }
        fake_master.state.return_value = {}
        get_mesos_master.return_value = fake_master

        load_marathon_config_patch.return_value = {"url": "http://foo"}
        get_marathon_client_patch.return_value = Mock()

        get_marathon_status_patch.side_effect = ValueError(
            'could not decode json')

        get_mesos_state_status_patch.return_value = []
        get_mesos_resource_utilization_health_patch.return_value = []

        with raises(SystemExit) as excinfo:
            paasta_metastatus.main(())
        assert excinfo.value.code == 2
Esempio n. 7
0
def test_main_no_chronos_config():
    with contextlib.nested(
            patch('paasta_tools.marathon_tools.load_marathon_config',
                  autospec=True),
            patch('paasta_tools.paasta_metastatus.load_chronos_config',
                  autospec=True),
            patch(
                'paasta_tools.paasta_metastatus.get_mesos_state_summary_from_leader',
                autospec=True,
                return_value={}),
            patch('paasta_tools.paasta_metastatus.get_mesos_state_status',
                  autospec=True,
                  return_value=([('fake_output', True)])),
            patch('paasta_tools.paasta_metastatus.get_mesos_stats',
                  autospec=True),
            patch('paasta_tools.paasta_metastatus.get_mesos_metrics_health',
                  autospec=True),
            patch('paasta_tools.paasta_metastatus.get_marathon_status',
                  autospec=True,
                  return_value=([('fake_output', True)])),
            patch('paasta_tools.paasta_metastatus.parse_args', autospec=True),
    ) as (
            load_marathon_config_patch,
            load_chronos_config_patch,
            get_mesos_state_summary_from_leader_patch,
            get_mesos_state_status_patch,
            get_mesos_stats_patch,
            get_mesos_metrics_health_patch,
            load_get_marathon_status_patch,
            parse_args_patch,
    ):

        fake_args = Mock(verbose=0, )
        parse_args_patch.return_value = fake_args
        load_marathon_config_patch.return_value = {}

        get_mesos_state_summary_from_leader_patch.return_value = {}
        get_mesos_stats_patch.return_value = {}

        get_mesos_state_status_patch.return_value = []
        get_mesos_metrics_health_patch.return_value = []

        load_chronos_config_patch.return_value = {}
        with raises(SystemExit) as excinfo:
            paasta_metastatus.main()
        assert excinfo.value.code == 0
Esempio n. 8
0
def test_main_no_chronos_config():
    with contextlib.nested(
        patch('paasta_tools.marathon_tools.load_marathon_config', autospec=True),
        patch('paasta_tools.paasta_metastatus.load_chronos_config', autospec=True),
        patch('paasta_tools.paasta_metastatus.get_mesos_master', autospec=True),
        patch('paasta_tools.metrics.metastatus_lib.get_mesos_state_status', autospec=True,
              return_value=([('fake_output', True)])),
        patch('paasta_tools.metrics.metastatus_lib.get_mesos_resource_utilization_health', autospec=True),
        patch('paasta_tools.metrics.metastatus_lib.get_marathon_status', autospec=True,
              return_value=([('fake_output', True)])),
        patch('paasta_tools.paasta_metastatus.parse_args', autospec=True),
    ) as (
        load_marathon_config_patch,
        load_chronos_config_patch,
        get_mesos_master,
        get_mesos_state_status_patch,
        get_mesos_resource_utilization_health_patch,
        load_get_marathon_status_patch,
        parse_args_patch,
    ):

        fake_args = Mock(
            verbose=0,
        )
        fake_master = Mock(autospace=True)
        fake_master.metrics_snapshot.return_value = {
            'master/frameworks_active': 2,
            'master/frameworks_inactive': 0,
            'master/frameworks_connected': 2,
            'master/frameworks_disconnected': 0,
        }
        fake_master.state.return_value = {}
        get_mesos_master.return_value = fake_master

        parse_args_patch.return_value = fake_args
        load_marathon_config_patch.return_value = {}

        get_mesos_state_status_patch.return_value = []
        get_mesos_resource_utilization_health_patch.return_value = []

        load_chronos_config_patch.return_value = {}
        with raises(SystemExit) as excinfo:
            paasta_metastatus.main()
        assert excinfo.value.code == 0
Esempio n. 9
0
def test_main_no_marathon_servers():
    with patch(
        "paasta_tools.paasta_metastatus.load_system_paasta_config", autospec=True
    ), patch(
        "paasta_tools.marathon_tools.get_marathon_servers",
        autospec=True,
        return_value={},
    ), patch(
        "paasta_tools.paasta_metastatus.is_mesos_available",
        autospec=True,
        return_value=True,
    ), patch(
        "paasta_tools.paasta_metastatus.get_mesos_master", autospec=True
    ) as get_mesos_master, patch(
        "paasta_tools.metrics.metastatus_lib.get_mesos_state_status",
        autospec=True,
        return_value=([("fake_output", True)]),
    ) as get_mesos_state_status_patch, patch(
        "paasta_tools.metrics.metastatus_lib.get_mesos_resource_utilization_health",
        autospec=True,
    ) as get_mesos_resource_utilization_health_patch, patch(
        "paasta_tools.metrics.metastatus_lib.get_marathon_status",
        autospec=True,
        return_value=([HealthCheckResult(message="fake_output", healthy=True)]),
    ), patch(
        "paasta_tools.paasta_metastatus.get_mesos_leader",
        autospec=True,
        return_value="localhost",
    ), patch(
        "paasta_tools.paasta_metastatus.is_kubernetes_available",
        autospec=True,
        return_value=False,
    ):
        fake_master = Mock(autospace=True)
        fake_master.state.return_value = {}
        get_mesos_master.return_value = fake_master

        get_mesos_state_status_patch.return_value = []
        get_mesos_resource_utilization_health_patch.return_value = []

        with raises(SystemExit) as excinfo:
            paasta_metastatus.main(())
        assert excinfo.value.code == 0
Esempio n. 10
0
def test_main_no_chronos_config():
    with contextlib.nested(
        patch('paasta_tools.marathon_tools.load_marathon_config', autospec=True),
        patch('paasta_tools.paasta_metastatus.load_chronos_config', autospec=True),
        patch('paasta_tools.paasta_metastatus.get_mesos_state_from_leader', autospec=True, return_value={}),
        patch('paasta_tools.paasta_metastatus.get_mesos_state_status', autospec=True,
              return_value=([('fake_output', True)])),
        patch('paasta_tools.paasta_metastatus.get_mesos_stats', autospec=True),
        patch('paasta_tools.paasta_metastatus.get_mesos_metrics_health', autospec=True),
        patch('paasta_tools.paasta_metastatus.get_marathon_status', autospec=True,
              return_value=([('fake_output', True)])),
        patch('paasta_tools.paasta_metastatus.parse_args', autospec=True),
    ) as (
        load_marathon_config_patch,
        load_chronos_config_patch,
        get_mesos_state_from_leader_patch,
        get_mesos_state_status_patch,
        get_mesos_stats_patch,
        get_mesos_metrics_health_patch,
        load_get_marathon_status_patch,
        parse_args_patch,
    ):

        fake_args = Mock(
            verbose=0,
        )
        parse_args_patch.return_value = fake_args
        load_marathon_config_patch.side_effect = MarathonNotConfigured

        get_mesos_state_from_leader_patch.return_value = {}
        get_mesos_stats_patch.return_value = {}

        get_mesos_state_status_patch.return_value = []
        get_mesos_metrics_health_patch.return_value = []

        load_chronos_config_patch.side_effect = PaastaNotConfiguredError
        with raises(SystemExit) as excinfo:
            paasta_metastatus.main()
        assert excinfo.value.code == 0