예제 #1
0
 def test_validate_config_mapping(self):
     master_config = manager.from_string(self.config)
     other_config = manager.from_string(NamedConfigTestCase.config)
     config_mapping = {'other': other_config, MASTER_NAMESPACE: master_config}
     result = list(config_parse.validate_config_mapping(config_mapping))
     assert_equal(len(result), 2)
     assert_equal(result[0][0], MASTER_NAMESPACE)
     assert_equal(result[1][0], 'other')
예제 #2
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,
                          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'])
예제 #3
0
 def test_from_string_valid(self):
     content = "{'one': 'thing', 'another': 'thing'}\n"
     actual = manager.from_string(content)
     expected = {'one': 'thing', 'another': 'thing'}
     assert_equal(actual, expected)
예제 #4
0
def valid_config_from_yaml(config_content):
    return valid_config(manager.from_string(config_content))
예제 #5
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',
                monitoring={},
                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,
                time_zone=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=5,
                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'])
예제 #6
0
 def test_from_string_valid(self):
     content = "{'one': 'thing', 'another': 'thing'}\n"
     actual = manager.from_string(content)
     expected = {'one': 'thing', 'another': 'thing'}
     assert_equal(actual, expected)
예제 #7
0
def valid_config_from_yaml(config_content):
    return valid_config(manager.from_string(config_content))