예제 #1
0
 def do_shortcut(self, node):
     """Nodes can be specified with just a hostname string."""
     if isinstance(node, string_types):
         return schema.ConfigNode(hostname=node, name=node, **self.defaults)
예제 #2
0
    def test_attributes(self):
        expected = schema.TronConfig(
            action_runner=FrozenDict(),
            output_stream_dir='/tmp',
            command_context=FrozenDict({
                'python': '/usr/bin/python',
                'batch_dir': '/tron/batch/test/foo'
            }),
            ssh_options=schema.ConfigSSHOptions(
                agent=False,
                identities=('tests/test_id_rsa', ),
                known_hosts_file=None,
                connect_timeout=30,
                idle_connection_timeout=3600,
                jitter_min_load=4,
                jitter_max_delay=20,
                jitter_load_factor=1,
            ),
            notification_options=None,
            time_zone=pytz.timezone("EST"),
            state_persistence=config_parse.DEFAULT_STATE_PERSISTENCE,
            nodes=FrozenDict({
                'node0':
                schema.ConfigNode(name='node0',
                                  username=os.environ['USER'],
                                  hostname='node0',
                                  port=22),
                'node1':
                schema.ConfigNode(name='node1',
                                  username=os.environ['USER'],
                                  hostname='node1',
                                  port=22)
            }),
            node_pools=FrozenDict({
                'nodePool':
                schema.ConfigNodePool(nodes=('node0', 'node1'),
                                      name='nodePool')
            }),
            jobs=FrozenDict({
                '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(
                                     name='cleanup',
                                     command='test_command0.1',
                                     node=None),
                                 enabled=True,
                                 max_runtime=None,
                                 allow_overlap=False),
                'MASTER.test_job1':
                schema.ConfigJob(
                    name='MASTER.test_job1',
                    namespace='MASTER',
                    node='node0',
                    enabled=True,
                    schedule=schedule_parse.ConfigDailyScheduler(
                        days=set([1, 3, 5]),
                        hour=0,
                        minute=30,
                        second=0,
                        original="00:30:00 MWF",
                        jitter=None,
                    ),
                    actions=FrozenDict({
                        'action1_1':
                        schema.ConfigAction(name='action1_1',
                                            command='test_command1.1',
                                            requires=('action1_0', ),
                                            node=None),
                        'action1_0':
                        schema.ConfigAction(name='action1_0',
                                            command='test_command1.0',
                                            requires=(),
                                            node=None)
                    }),
                    queueing=True,
                    run_limit=50,
                    all_nodes=False,
                    cleanup_action=None,
                    max_runtime=None,
                    allow_overlap=True),
                'MASTER.test_job2':
                schema.ConfigJob(name='MASTER.test_job2',
                                 namespace='MASTER',
                                 node='node1',
                                 enabled=True,
                                 schedule=schedule_parse.ConfigDailyScheduler(
                                     days=set(),
                                     hour=16,
                                     minute=30,
                                     second=0,
                                     original="16:30:00 ",
                                     jitter=None,
                                 ),
                                 actions=FrozenDict({
                                     'action2_0':
                                     schema.ConfigAction(
                                         name='action2_0',
                                         command='test_command2.0',
                                         requires=(),
                                         node=None)
                                 }),
                                 queueing=True,
                                 run_limit=50,
                                 all_nodes=False,
                                 cleanup_action=None,
                                 max_runtime=None,
                                 allow_overlap=False),
                'MASTER.test_job3':
                schema.ConfigJob(
                    name='MASTER.test_job3',
                    namespace='MASTER',
                    node='node1',
                    schedule=ConfigConstantScheduler(),
                    enabled=True,
                    actions=FrozenDict({
                        'action3_1':
                        schema.ConfigAction(name='action3_1',
                                            command='test_command3.1',
                                            requires=(),
                                            node=None),
                        'action3_0':
                        schema.ConfigAction(name='action3_0',
                                            command='test_command3.0',
                                            requires=(),
                                            node=None),
                        'action3_2':
                        schema.ConfigAction(name='action3_2',
                                            command='test_command3.2',
                                            requires=('action3_0',
                                                      'action3_1'),
                                            node='node0')
                    }),
                    queueing=True,
                    run_limit=50,
                    all_nodes=False,
                    cleanup_action=None,
                    max_runtime=None,
                    allow_overlap=False),
                'MASTER.test_job4':
                schema.ConfigJob(name='MASTER.test_job4',
                                 namespace='MASTER',
                                 node='nodePool',
                                 schedule=schedule_parse.ConfigDailyScheduler(
                                     days=set(),
                                     hour=0,
                                     minute=0,
                                     second=0,
                                     original='00:00:00 ',
                                     jitter=None,
                                 ),
                                 actions=FrozenDict({
                                     'action4_0':
                                     schema.ConfigAction(
                                         name='action4_0',
                                         command='test_command4.0',
                                         requires=(),
                                         node=None)
                                 }),
                                 queueing=True,
                                 run_limit=50,
                                 all_nodes=True,
                                 cleanup_action=None,
                                 enabled=False,
                                 max_runtime=None,
                                 allow_overlap=False)
            }),
            services=FrozenDict({
                'MASTER.service0':
                schema.ConfigService(
                    name='MASTER.service0',
                    namespace='MASTER',
                    node='nodePool',
                    pid_file='/var/run/%(name)s-%(instance_number)s.pid',
                    command='service_command0',
                    monitor_interval=20,
                    monitor_retries=3,
                    restart_delay=None,
                    count=2)
            }))

        test_config = valid_config_from_yaml(self.config)
        assert_equal(test_config.command_context, expected.command_context)
        assert_equal(test_config.ssh_options, expected.ssh_options)
        assert_equal(test_config.notification_options,
                     expected.notification_options)
        assert_equal(test_config.time_zone, expected.time_zone)
        assert_equal(test_config.nodes, expected.nodes)
        assert_equal(test_config.node_pools, expected.node_pools)
        assert_equal(test_config.jobs['MASTER.test_job0'],
                     expected.jobs['MASTER.test_job0'])
        assert_equal(test_config.jobs['MASTER.test_job1'],
                     expected.jobs['MASTER.test_job1'])
        assert_equal(test_config.jobs['MASTER.test_job2'],
                     expected.jobs['MASTER.test_job2'])
        assert_equal(test_config.jobs['MASTER.test_job3'],
                     expected.jobs['MASTER.test_job3'])
        assert_equal(test_config.jobs['MASTER.test_job4'],
                     expected.jobs['MASTER.test_job4'])
        assert_equal(test_config.jobs, expected.jobs)
        assert_equal(test_config.services, expected.services)
        assert_equal(test_config, expected)
        assert_equal(test_config.jobs['MASTER.test_job4'].enabled, False)