Ejemplo n.º 1
0
 def test_from_assigned_task_shell(self):
     interval_secs = 17
     initial_interval_secs = 3
     max_consecutive_failures = 2
     timeout_secs = 5
     shell_config = ShellHealthChecker(shell_command='failed command')
     task_config = TaskConfig(executorConfig=ExecutorConfig(
         name='thermos-generic',
         data=MESOS_JOB(
             task=HELLO_WORLD,
             health_check_config=HealthCheckConfig(
                 health_checker=HealthCheckerConfig(shell=shell_config),
                 interval_secs=interval_secs,
                 initial_interval_secs=initial_interval_secs,
                 max_consecutive_failures=max_consecutive_failures,
                 timeout_secs=timeout_secs,
             )).json_dumps()))
     assigned_task = AssignedTask(task=task_config, instanceId=1)
     execconfig_data = json.loads(assigned_task.task.executorConfig.data)
     assert execconfig_data['health_check_config']['health_checker'][
         'shell']['shell_command'] == 'failed command'
     health_checker = HealthCheckerProvider().from_assigned_task(
         assigned_task, None)
     assert health_checker.threaded_health_checker.interval == interval_secs
     assert health_checker.threaded_health_checker.initial_interval == initial_interval_secs
     hct_max_fail = health_checker.threaded_health_checker.max_consecutive_failures
     assert hct_max_fail == max_consecutive_failures
Ejemplo n.º 2
0
 def test_interpolate_cmd(self):
     """Making sure thermos.ports[foo] gets correctly substituted with assignedPorts info."""
     interval_secs = 17
     initial_interval_secs = 3
     max_consecutive_failures = 2
     timeout_secs = 5
     shell_cmd = 'FOO_PORT={{thermos.ports[foo]}} failed command'
     shell_config = ShellHealthChecker(shell_command=shell_cmd)
     task_config = TaskConfig(executorConfig=ExecutorConfig(
         name='thermos-generic',
         data=MESOS_JOB(
             task=HELLO_WORLD,
             health_check_config=HealthCheckConfig(
                 health_checker=HealthCheckerConfig(shell=shell_config),
                 interval_secs=interval_secs,
                 initial_interval_secs=initial_interval_secs,
                 max_consecutive_failures=max_consecutive_failures,
                 timeout_secs=timeout_secs,
             )).json_dumps()))
     assigned_task = AssignedTask(task=task_config,
                                  instanceId=1,
                                  assignedPorts={'foo': 9001})
     interpolated_cmd = HealthCheckerProvider.interpolate_cmd(assigned_task,
                                                              cmd=shell_cmd)
     assert interpolated_cmd == 'FOO_PORT=9001 failed command'
Ejemplo n.º 3
0
 def test_from_assigned_task_shell_no_demotion(self, mock_getpwnam):
     interval_secs = 17
     initial_interval_secs = 3
     max_consecutive_failures = 2
     timeout_secs = 5
     shell_config = ShellHealthChecker(shell_command='failed command')
     task_config = TaskConfig(
         job=JobKey(role='role', environment='env', name='name'),
         executorConfig=ExecutorConfig(
             name='thermos-generic',
             data=MESOS_JOB(
                 task=HELLO_WORLD,
                 health_check_config=HealthCheckConfig(
                     health_checker=HealthCheckerConfig(shell=shell_config),
                     interval_secs=interval_secs,
                     initial_interval_secs=initial_interval_secs,
                     max_consecutive_failures=max_consecutive_failures,
                     timeout_secs=timeout_secs,
                 )).json_dumps()))
     assigned_task = AssignedTask(task=task_config,
                                  instanceId=1,
                                  assignedPorts={'foo': 9001})
     execconfig_data = json.loads(assigned_task.task.executorConfig.data)
     assert execconfig_data['health_check_config']['health_checker'][
         'shell']['shell_command'] == 'failed command'
     health_checker = HealthCheckerProvider(
         nosetuid_health_checks=True).from_assigned_task(
             assigned_task, None)
     assert health_checker.threaded_health_checker.interval == interval_secs
     assert health_checker.threaded_health_checker.initial_interval == initial_interval_secs
     hct_max_fail = health_checker.threaded_health_checker.max_consecutive_failures
     assert hct_max_fail == max_consecutive_failures
     # Should not be trying to access role's user info.
     assert not mock_getpwnam.called
Ejemplo n.º 4
0
def test_health_check_config_shell_no_command():
    # If we chose shell config, we must define shell_command.
    base_job = Job(
        name='hello_bond',
        role='james',
        cluster='marine-cluster',
        health_check_config=HealthCheckConfig(
            max_consecutive_failures=1,
            health_checker=HealthCheckerConfig(shell=ShellHealthChecker())),
        task=Task(name='main',
                  processes=[],
                  resources=Resources(cpu=0.1, ram=64 * MB, disk=64 * MB)))
    with pytest.raises(SystemExit):
        config._validate_health_check_config(AuroraConfig(base_job))
Ejemplo n.º 5
0
def test_health_check_config_shell_ok():
    base_job = Job(name='hello_bond',
                   role='james',
                   cluster='marine-cluster',
                   health_check_config=HealthCheckConfig(
                       max_consecutive_failures=1,
                       health_checker=HealthCheckerConfig(
                           shell=ShellHealthChecker(shell_command='foo bar'))),
                   task=Task(name='main',
                             processes=[],
                             resources=Resources(cpu=0.1,
                                                 ram=64 * MB,
                                                 disk=64 * MB)))
    config._validate_health_check_config(AuroraConfig(base_job))
Ejemplo n.º 6
0
    def test_from_assigned_task_shell_filesystem_image(self, mock_getpwnam):
        interval_secs = 17
        initial_interval_secs = 3
        max_consecutive_failures = 2
        timeout_secs = 5
        shell_config = ShellHealthChecker(shell_command='failed command')
        task_config = TaskConfig(
            job=JobKey(role='role', environment='env', name='name'),
            executorConfig=ExecutorConfig(
                name='thermos-generic',
                data=MESOS_JOB(
                    task=HELLO_WORLD,
                    health_check_config=HealthCheckConfig(
                        health_checker=HealthCheckerConfig(shell=shell_config),
                        interval_secs=interval_secs,
                        initial_interval_secs=initial_interval_secs,
                        max_consecutive_failures=max_consecutive_failures,
                        timeout_secs=timeout_secs,
                    )).json_dumps()))
        assigned_task = AssignedTask(task=task_config,
                                     instanceId=1,
                                     assignedPorts={'foo': 9001})
        execconfig_data = json.loads(assigned_task.task.executorConfig.data)
        assert execconfig_data['health_check_config']['health_checker'][
            'shell']['shell_command'] == 'failed command'

        mock_sandbox = mock.Mock(spec_set=SandboxInterface)
        type(mock_sandbox).root = mock.PropertyMock(return_value='/some/path')
        type(mock_sandbox).is_filesystem_image = mock.PropertyMock(
            return_value=True)

        with mock.patch(
                'apache.aurora.executor.common.health_checker.ShellHealthCheck'
        ) as mock_shell:
            HealthCheckerProvider(
                nosetuid_health_checks=False,
                mesos_containerizer_path='/some/path/mesos-containerizer'
            ).from_assigned_task(assigned_task, mock_sandbox)

            class NotNone(object):
                def __eq__(self, other):
                    return other is not None

            assert mock_shell.mock_calls == [
                mock.call(cmd='failed command',
                          wrapper_fn=NotNone(),
                          preexec_fn=None,
                          timeout_secs=5.0)
            ]
Ejemplo n.º 7
0
    def test_from_assigned_task_shell(self, mock_getpwnam):
        interval_secs = 17
        initial_interval_secs = 3
        max_consecutive_failures = 2
        timeout_secs = 5
        shell_config = ShellHealthChecker(shell_command='failed command')
        task_config = TaskConfig(
            job=JobKey(role='role', environment='env', name='name'),
            executorConfig=ExecutorConfig(
                name='thermos-generic',
                data=MESOS_JOB(
                    task=HELLO_WORLD,
                    health_check_config=HealthCheckConfig(
                        health_checker=HealthCheckerConfig(shell=shell_config),
                        interval_secs=interval_secs,
                        initial_interval_secs=initial_interval_secs,
                        max_consecutive_failures=max_consecutive_failures,
                        timeout_secs=timeout_secs,
                    )).json_dumps()))
        assigned_task = AssignedTask(task=task_config,
                                     instanceId=1,
                                     assignedPorts={'foo': 9001})
        execconfig_data = json.loads(assigned_task.task.executorConfig.data)
        assert execconfig_data['health_check_config']['health_checker'][
            'shell']['shell_command'] == 'failed command'

        mock_sandbox = mock.Mock(spec_set=SandboxInterface)
        type(mock_sandbox).root = mock.PropertyMock(return_value='/some/path')
        type(mock_sandbox).is_filesystem_image = mock.PropertyMock(
            return_value=False)

        health_checker = HealthCheckerProvider().from_assigned_task(
            assigned_task, mock_sandbox)
        assert health_checker.threaded_health_checker.interval == interval_secs
        assert health_checker.threaded_health_checker.initial_interval == initial_interval_secs
        hct_max_fail = health_checker.threaded_health_checker.max_consecutive_failures
        assert hct_max_fail == max_consecutive_failures
        mock_getpwnam.assert_called_once_with(task_config.job.role)