Ejemplo n.º 1
0
 def test_validator_valid_string_without_no_percent_escape(self):
     template = "The {one} {seven} thing is {mars} --year %Y"
     context = config_utils.ConfigContext(
         path=None,
         nodes=None,
         command_context={'mars': 'ok'},
         namespace=None,
     )
     assert self.validator(template, context)
Ejemplo n.º 2
0
 def test_validator_passes_with_context(self):
     template = "The {one} thing I {seven} is {mars}"
     context = config_utils.ConfigContext(
         None,
         None,
         {'mars': 'ok'},
         None,
     )
     assert self.validator(template, context) == template
Ejemplo n.º 3
0
 def test_validate_job_no_actions(self):
     job_config = dict(name="job_name",
                       node="localhost",
                       schedule="constant",
                       actions=[])
     config_context = config_utils.ConfigContext('config', ['localhost'],
                                                 None, None)
     expected_msg = "Required non-empty list at config.Job.job_name.actions"
     exception = assert_raises(ConfigError, valid_job, job_config,
                               config_context)
     assert_in(expected_msg, str(exception))
Ejemplo n.º 4
0
    def test_build_config_context(self):
        path, nodes, namespace = 'path', set([1,2,3]), 'namespace'
        command_context = mock.MagicMock()
        parent_context = config_utils.ConfigContext(
            path, nodes, command_context, namespace)

        child = parent_context.build_child_context('child')
        assert_equal(child.path, '%s.child' % path)
        assert_equal(child.nodes, nodes)
        assert_equal(child.namespace, namespace)
        assert_equal(child.command_context, command_context)
        assert not child.partial
Ejemplo n.º 5
0
    def test_valid_jobs_success(self):
        test_config = dict(jobs=[
            dict(name="test_job0",
                 node='node0',
                 schedule='daily',
                 expected_runtime="20m",
                 actions=[
                     dict(name="action",
                          command="command",
                          expected_runtime="20m"),
                     dict(
                         name="action_mesos",
                         command="command",
                         executor='mesos',
                         cpus=4,
                         mem=300,
                         disk=600,
                         constraints=[
                             dict(attribute='pool',
                                  operator='LIKE',
                                  value='default')
                         ],
                         docker_image='my_container:latest',
                         docker_parameters=[
                             dict(key='label', value='labelA'),
                             dict(key='label', value='labelB')
                         ],
                         env=dict(USER='******'),
                         extra_volumes=[
                             dict(container_path='/tmp',
                                  host_path='/home/tmp',
                                  mode='RO')
                         ],
                     ),
                     dict(
                         name="test_trigger_attrs",
                         command="foo",
                         triggered_by=["foo.bar"],
                         trigger_downstreams=True,
                     ),
                 ],
                 cleanup_action=dict(command="command"))
        ],
                           **BASE_CONFIG)

        expected_jobs = {
            'MASTER.test_job0':
            make_job(
                name='MASTER.test_job0',
                schedule=make_mock_schedule(),
                actions={
                    'action':
                    make_action(expected_runtime=datetime.timedelta(0,
                                                                    1200), ),
                    'action_mesos':
                    make_action(
                        name='action_mesos',
                        executor=schema.ExecutorTypes.mesos.value,
                        cpus=4.0,
                        mem=300.0,
                        disk=600.0,
                        constraints=(schema.ConfigConstraint(
                            attribute='pool',
                            operator='LIKE',
                            value='default',
                        ), ),
                        docker_image='my_container:latest',
                        docker_parameters=(
                            schema.ConfigParameter(
                                key='label',
                                value='labelA',
                            ),
                            schema.ConfigParameter(
                                key='label',
                                value='labelB',
                            ),
                        ),
                        env={'USER': '******'},
                        extra_volumes=(schema.ConfigVolume(
                            container_path='/tmp',
                            host_path='/home/tmp',
                            mode=schema.VolumeModes.RO.value,
                        ), ),
                        expected_runtime=datetime.timedelta(hours=24),
                    ),
                    'test_trigger_attrs':
                    make_action(
                        name="test_trigger_attrs",
                        command="foo",
                        triggered_by=("foo.bar", ),
                        trigger_downstreams=True,
                    ),
                },
                expected_runtime=datetime.timedelta(0, 1200),
            ),
        }

        context = config_utils.ConfigContext(
            'config',
            ['node0'],
            None,
            MASTER_NAMESPACE,
        )
        config_parse.validate_jobs(test_config, context)
        assert expected_jobs == test_config['jobs']
Ejemplo n.º 6
0
    def test_valid_jobs_and_services_success(self):
        test_config = BASE_CONFIG + textwrap.dedent("""
            jobs:
                -
                    name: "test_job0"
                    node: node0
                    schedule: "interval 20s"
                    actions:
                        -
                            name: "action0_0"
                            command: "test_command0.0"
                    cleanup_action:
                        command: "test_command0.1"
            services:
                -
                    name: "test_service0"
                    node: node0
                    command: "service_command0"
                    count: 2
                    pid_file: "/var/run/%(name)s-%(instance_number)s.pid"
                    monitor_interval: 20
                    """)
        expected_jobs = {
            'MASTER.test_job0':
            schema.ConfigJob(name='MASTER.test_job0',
                             namespace='MASTER',
                             node='node0',
                             schedule=ConfigIntervalScheduler(
                                 timedelta=datetime.timedelta(0, 20),
                                 jitter=None),
                             actions=FrozenDict({
                                 'action0_0':
                                 schema.ConfigAction(name='action0_0',
                                                     command='test_command0.0',
                                                     requires=(),
                                                     node=None)
                             }),
                             queueing=True,
                             run_limit=50,
                             all_nodes=False,
                             cleanup_action=schema.ConfigCleanupAction(
                                 command='test_command0.1',
                                 name='cleanup',
                                 node=None),
                             enabled=True,
                             allow_overlap=False,
                             max_runtime=None)
        }

        expected_services = {
            'MASTER.test_service0':
            schema.ConfigService(
                name='MASTER.test_service0',
                namespace='MASTER',
                node='node0',
                pid_file='/var/run/%(name)s-%(instance_number)s.pid',
                command='service_command0',
                monitor_interval=20,
                monitor_retries=3,
                restart_delay=None,
                count=2)
        }

        config = manager.from_string(test_config)
        context = config_utils.ConfigContext('config', ['node0'], None,
                                             MASTER_NAMESPACE)
        config_parse.validate_jobs_and_services(config, context)
        assert_equal(expected_jobs, config['jobs'])
        assert_equal(expected_services, config['services'])
Ejemplo n.º 7
0
 def test_validator_passes_with_context(self):
     template = "The %(one)s thing I %(seven)s is %(mars)s"
     context = config_utils.ConfigContext(None, None, {'mars': 'ok'}, None)
     assert self.validator(template, context)