Пример #1
0
def main():
    args = parse_args()
    if args.verbose:
        logging.basicConfig(level=logging.DEBUG)
    else:
        logging.basicConfig(level=logging.WARNING)

    autoscale_local_cluster()
Пример #2
0
def main():
    args = parse_args()
    if args.verbose >= 2:
        logging.basicConfig(level=logging.DEBUG)
    elif args.verbose == 1:
        logging.basicConfig(level=logging.INFO)
    else:
        logging.basicConfig(level=logging.WARNING)

    autoscale_local_cluster(dry_run=args.dry_run)
Пример #3
0
def main():
    args = parse_args()
    if args.verbose >= 2:
        logging.basicConfig(level=logging.DEBUG)
    elif args.verbose == 1:
        logging.basicConfig(level=logging.INFO)
    else:
        logging.basicConfig(level=logging.WARNING)

    autoscale_local_cluster()
Пример #4
0
def main():
    args = parse_args()
    log_format = '%(asctime)s:%(levelname)s:%(name)s:%(message)s'
    if args.verbose >= 2:
        logging.basicConfig(level=logging.DEBUG, format=log_format)
    elif args.verbose == 1:
        logging.basicConfig(level=logging.INFO, format=log_format)
    else:
        logging.basicConfig(level=logging.WARNING, format=log_format)

    autoscale_local_cluster(dry_run=args.dry_run)
Пример #5
0
def main():
    args = parse_args()
    log_format = '%(asctime)s:%(levelname)s:%(name)s:%(message)s'
    if args.verbose >= 2:
        logging.basicConfig(level=logging.DEBUG, format=log_format)
    elif args.verbose == 1:
        logging.basicConfig(level=logging.INFO, format=log_format)
    else:
        logging.basicConfig(level=logging.WARNING, format=log_format)

    autoscale_local_cluster(dry_run=args.dry_run)
Пример #6
0
def test_autoscale_local_cluster():
    with contextlib.nested(
        mock.patch('paasta_tools.autoscaling_lib.load_system_paasta_config', autospec=True),
        mock.patch('paasta_tools.autoscaling_lib.get_mesos_state_from_leader', autospec=True),
        mock.patch('paasta_tools.autoscaling_lib.get_cluster_metrics_provider', autospec=True),
        mock.patch('paasta_tools.autoscaling_lib.get_scaler', autospec=True),
        mock.patch('paasta_tools.autoscaling_lib.sort_slaves_to_kill', autospec=True),
    ) as (
        mock_get_paasta_config,
        mock_mesos_state,
        mock_get_metrics_provider,
        mock_get_scaler,
        mock_sort_slaves_to_kill
    ):

        mock_scaling_resources = {'id1': {'id': 'sfr-blah', 'type': 'sfr', 'pool': 'default'}}
        mock_resource_pool_settings = {'default': {'drain_timeout': 123, 'target_utilization': 0.75}}
        mock_get_cluster_autoscaling_resources = mock.Mock(return_value=mock_scaling_resources)
        mock_get_resource_pool_settings = mock.Mock(return_value=mock_resource_pool_settings)
        mock_get_resources = mock.Mock(get_cluster_autoscaling_resources=mock_get_cluster_autoscaling_resources,
                                       get_resource_pool_settings=mock_get_resource_pool_settings)
        mock_get_paasta_config.return_value = mock_get_resources
        mock_metrics_provider = mock.Mock()
        mock_metrics_provider.return_value = (2, 6)
        mock_get_metrics_provider.return_value = mock_metrics_provider
        mock_scaler = mock.Mock()
        mock_get_scaler.return_value = mock_scaler

        # test scale up
        autoscaling_lib.autoscale_local_cluster()
        mock_get_metrics_provider.assert_called_with('sfr')
        mock_metrics_provider.assert_called_with('sfr-blah', mock_mesos_state(),
                                                 {'id': 'sfr-blah', 'type': 'sfr', 'pool': 'default'},
                                                 {'drain_timeout': 123, 'target_utilization': 0.75})
        mock_get_scaler.assert_called_with('sfr')
        mock_scaler.assert_called_with({'id': 'sfr-blah', 'type': 'sfr', 'pool': 'default'}, 2, 6, [],
                                       {'drain_timeout': 123, 'target_utilization': 0.75}, False)

        # test scale down
        mock_metrics_provider.return_value = (6, 2)
        mock_sort_slaves_to_kill.return_value = ['a_slave', 'another_slave']
        autoscaling_lib.autoscale_local_cluster()
        mock_get_metrics_provider.assert_called_with('sfr')
        mock_metrics_provider.assert_called_with('sfr-blah', mock_mesos_state(),
                                                 {'id': 'sfr-blah', 'type': 'sfr', 'pool': 'default'},
                                                 {'drain_timeout': 123, 'target_utilization': 0.75})
        mock_get_scaler.assert_called_with('sfr')
        mock_scaler.assert_called_with({'id': 'sfr-blah', 'type': 'sfr', 'pool': 'default'},
                                       6, 2, ['a_slave', 'another_slave'],
                                       {'drain_timeout': 123, 'target_utilization': 0.75}, False)
Пример #7
0
def test_autoscale_local_cluster():
    with contextlib.nested(
        mock.patch('paasta_tools.autoscaling_lib.load_system_paasta_config', autospec=True),
        mock.patch('paasta_tools.autoscaling_lib.get_mesos_state_from_leader', autospec=True),
        mock.patch('paasta_tools.autoscaling_lib.get_cluster_metrics_provider', autospec=True),
        mock.patch('paasta_tools.autoscaling_lib.get_scaler', autospec=True),
        mock.patch('paasta_tools.autoscaling_lib.sort_slaves_to_kill', autospec=True),
    ) as (
        mock_get_paasta_config,
        mock_mesos_state,
        mock_get_metrics_provider,
        mock_get_scaler,
        mock_sort_slaves_to_kill
    ):

        mock_scaling_resources = {'id1': {'id': 'sfr-blah', 'type': 'sfr', 'pool': 'default'}}
        mock_get_cluster_autoscaling_resources = mock.Mock(return_value=mock_scaling_resources)
        mock_get_resources = mock.Mock(get_cluster_autoscaling_resources=mock_get_cluster_autoscaling_resources)
        mock_get_paasta_config.return_value = mock_get_resources
        mock_metrics_provider = mock.Mock()
        mock_metrics_provider.return_value = (2, 6)
        mock_get_metrics_provider.return_value = mock_metrics_provider
        mock_scaler = mock.Mock()
        mock_get_scaler.return_value = mock_scaler

        # test scale up
        autoscaling_lib.autoscale_local_cluster()
        mock_get_metrics_provider.assert_called_with('sfr')
        mock_metrics_provider.assert_called_with('sfr-blah', mock_mesos_state(), {'id': 'sfr-blah', 'type': 'sfr',
                                                                                  'pool': 'default'})
        mock_get_scaler.assert_called_with('sfr')
        mock_scaler.assert_called_with({'id': 'sfr-blah', 'type': 'sfr', 'pool': 'default'}, 2, 6, [], False)

        # test scale down
        mock_metrics_provider.return_value = (6, 2)
        mock_sort_slaves_to_kill.return_value = ['a_slave', 'another_slave']
        autoscaling_lib.autoscale_local_cluster()
        mock_get_metrics_provider.assert_called_with('sfr')
        mock_metrics_provider.assert_called_with('sfr-blah', mock_mesos_state(), {'id': 'sfr-blah', 'type': 'sfr',
                                                                                  'pool': 'default'})
        mock_get_scaler.assert_called_with('sfr')
        mock_scaler.assert_called_with({'id': 'sfr-blah', 'type': 'sfr', 'pool': 'default'},
                                       6, 2, ['a_slave', 'another_slave'], False)
Пример #8
0
def test_autoscale_local_cluster():
    with contextlib.nested(
        mock.patch("paasta_tools.autoscaling_lib.load_system_paasta_config", autospec=True),
        mock.patch("paasta_tools.autoscaling_lib.get_mesos_state_from_leader", autospec=True),
        mock.patch("paasta_tools.autoscaling_lib.get_cluster_metrics_provider", autospec=True),
        mock.patch("paasta_tools.autoscaling_lib.get_scaler", autospec=True),
        mock.patch("paasta_tools.autoscaling_lib.sort_slaves_to_kill", autospec=True),
    ) as (
        mock_get_paasta_config,
        mock_mesos_state,
        mock_get_metrics_provider,
        mock_get_scaler,
        mock_sort_slaves_to_kill,
    ):

        mock_scaling_resources = {"id1": {"id": "sfr-blah", "type": "sfr", "pool": "default"}}
        mock_resource_pool_settings = {"default": {"drain_timeout": 123, "target_utilization": 0.75}}
        mock_get_cluster_autoscaling_resources = mock.Mock(return_value=mock_scaling_resources)
        mock_get_resource_pool_settings = mock.Mock(return_value=mock_resource_pool_settings)
        mock_get_resources = mock.Mock(
            get_cluster_autoscaling_resources=mock_get_cluster_autoscaling_resources,
            get_resource_pool_settings=mock_get_resource_pool_settings,
        )
        mock_get_paasta_config.return_value = mock_get_resources
        mock_metrics_provider = mock.Mock()
        mock_metrics_provider.return_value = (2, 6)
        mock_get_metrics_provider.return_value = mock_metrics_provider
        mock_scaler = mock.Mock()
        mock_get_scaler.return_value = mock_scaler

        # test scale up
        autoscaling_lib.autoscale_local_cluster()
        mock_get_metrics_provider.assert_called_with("sfr")
        mock_metrics_provider.assert_called_with(
            "sfr-blah",
            mock_mesos_state(),
            {"id": "sfr-blah", "type": "sfr", "pool": "default"},
            {"drain_timeout": 123, "target_utilization": 0.75},
        )
        mock_get_scaler.assert_called_with("sfr")
        mock_scaler.assert_called_with(
            {"id": "sfr-blah", "type": "sfr", "pool": "default"},
            2,
            6,
            [],
            {"drain_timeout": 123, "target_utilization": 0.75},
            False,
        )

        # test scale down
        mock_metrics_provider.return_value = (6, 2)
        mock_sort_slaves_to_kill.return_value = ["a_slave", "another_slave"]
        autoscaling_lib.autoscale_local_cluster()
        mock_get_metrics_provider.assert_called_with("sfr")
        mock_metrics_provider.assert_called_with(
            "sfr-blah",
            mock_mesos_state(),
            {"id": "sfr-blah", "type": "sfr", "pool": "default"},
            {"drain_timeout": 123, "target_utilization": 0.75},
        )
        mock_get_scaler.assert_called_with("sfr")
        mock_scaler.assert_called_with(
            {"id": "sfr-blah", "type": "sfr", "pool": "default"},
            6,
            2,
            ["a_slave", "another_slave"],
            {"drain_timeout": 123, "target_utilization": 0.75},
            False,
        )