Exemplo n.º 1
0
 def test_set_action_runs_duplicate(self):
     run_collection = mock.create_autospec(actionrun.ActionRunCollection)
     assert_raises(
         ValueError,
         self.job_run._set_action_runs,
         run_collection,
     )
Exemplo n.º 2
0
    def test_disabled_with_exception(self):
        def testfunc():
            with self.manager.disabled():
                raise ValueError()

        assert_raises(ValueError, testfunc)
        assert self.manager.enabled
Exemplo n.º 3
0
 def test_create_missing_master(self):
     config_mapping = {'other': mock.Mock()}
     assert_raises(
         ConfigError,
         config_parse.ConfigContainer.create,
         config_mapping,
     )
Exemplo n.º 4
0
 def test_validate_metadata_mismatch(self):
     metadata = {'version': (200, 1, 1)}
     assert_raises(
         VersionMismatchError,
         StateMetadata.validate_metadata,
         metadata,
     )
Exemplo n.º 5
0
 def test_valid_cleanup_action_name_fail(self):
     assert_raises(
         ConfigError,
         valid_cleanup_action_name,
         'other',
         NullConfigContext,
     )
Exemplo n.º 6
0
 def test_create_missing_master(self):
     config_mapping = {'other': mock.Mock()}
     assert_raises(
         ConfigError,
         config_parse.ConfigContainer.create,
         config_mapping,
     )
Exemplo n.º 7
0
 def test_mesos_default_volumes(self):
     mesos_options = {'master_address': 'mesos_master'}
     mesos_options['default_volumes'] = [
         {
             'container_path': '/nail/srv',
             'host_path': '/tmp',
             'mode': 'RO',
         },
         {
             'container_path': '/nail/srv',
             'host_path': '/tmp',
             'mode': 'invalid',
         },
     ]
     assert_raises(
         ConfigError,
         config_parse.valid_mesos_options.validate,
         mesos_options,
         self.context,
     )
     # After we fix the error, expect error to go away.
     mesos_options['default_volumes'][1]['mode'] = 'RW'
     assert config_parse.valid_mesos_options.validate(
         mesos_options,
         self.context,
     )
Exemplo n.º 8
0
 def test_valid_cleanup_action_name_fail(self):
     assert_raises(
         ConfigError,
         valid_cleanup_action_name,
         'other',
         NullConfigContext,
     )
Exemplo n.º 9
0
    def test_disabled_with_exception(self):
        def testfunc():
            with self.manager.disabled():
                raise ValueError()

        assert_raises(ValueError, testfunc)
        assert self.manager.enabled
Exemplo n.º 10
0
 def test_set_action_runs_duplicate(self):
     run_collection = mock.create_autospec(actionrun.ActionRunCollection)
     assert_raises(
         ValueError,
         self.job_run._set_action_runs,
         run_collection,
     )
Exemplo n.º 11
0
 def test_validate_metadata_mismatch(self):
     metadata = {'version': (200, 1, 1)}
     assert_raises(
         VersionMismatchError,
         StateMetadata.validate_metadata,
         metadata,
     )
Exemplo n.º 12
0
    def test_working_dir_with_exception(self):
        def with_exc():
            with tool_utils.working_dir(self.temp_dir):
                assert_equal(os.getcwd(), self.temp_dir)
                raise Exception("oops")

        assert_raises(Exception, with_exc)
        assert_equal(os.getcwd(), self.cwd)
Exemplo n.º 13
0
 def test_valid_time_invalid(self):
     assert_raises(
         ConfigError,
         config_utils.valid_time,
         "14:32:12:34",
         self.context,
     )
     assert_raises(ConfigError, config_utils.valid_time, None, self.context)
Exemplo n.º 14
0
    def test_working_dir_with_exception(self):
        def with_exc():
            with tool_utils.working_dir(self.temp_dir):
                assert_equal(os.getcwd(), self.temp_dir)
                raise Exception("oops")

        assert_raises(Exception, with_exc)
        assert_equal(os.getcwd(), self.cwd)
Exemplo n.º 15
0
 def test_valid_time_delta_invalid_unit(self):
     for jitter in ['1 year', '3 mo', '3 months']:
         assert_raises(
             ConfigError,
             config_utils.valid_time_delta,
             jitter,
             self.context,
         )
Exemplo n.º 16
0
 def test_valid_time_delta_invalid_unit(self):
     for jitter in ['1 year', '3 mo', '3 months']:
         assert_raises(
             ConfigError,
             config_utils.valid_time_delta,
             jitter,
             self.context,
         )
Exemplo n.º 17
0
 def test_valid_time_invalid(self):
     assert_raises(
         ConfigError,
         config_utils.valid_time,
         "14:32:12:34",
         self.context,
     )
     assert_raises(ConfigError, config_utils.valid_time, None, self.context)
Exemplo n.º 18
0
 def test_post_validation_failed(self):
     if 'SSH_AUTH_SOCK' in os.environ:
         del os.environ['SSH_AUTH_SOCK']
     assert_raises(
         ConfigError,
         config_parse.valid_ssh_options.validate,
         self.config,
         self.context,
     )
Exemplo n.º 19
0
 def test_post_validation_failed(self):
     if 'SSH_AUTH_SOCK' in os.environ:
         del os.environ['SSH_AUTH_SOCK']
     assert_raises(
         ConfigError,
         config_parse.valid_ssh_options.validate,
         self.config,
         self.context,
     )
Exemplo n.º 20
0
 def test_save_failed(self):
     self.store.save.side_effect = PersistenceStoreError("blah")
     assert_raises(
         PersistenceStoreError,
         self.manager.save,
         None,
         None,
         None,
     )
Exemplo n.º 21
0
 def test_save_failed(self):
     self.store.save.side_effect = PersistenceStoreError("blah")
     assert_raises(
         PersistenceStoreError,
         self.manager.save,
         None,
         None,
         None,
     )
Exemplo n.º 22
0
 def test_restore_state_with_runs(self):
     assert_raises(
         ValueError,
         self.run_collection.restore_state,
         None,
         None,
         None,
         None,
         None,
     )
Exemplo n.º 23
0
    def test_check_consistency_failed(self):
        state = {runstate.JOB_STATE: {'name': mock.Mock()}}

        with mock.patch.object(
                self.store,
                'save',
                side_effect=PersistenceStoreError,
                autospec=None,
        ):
            assert_raises(PersistenceStoreError,
                          self.manager._check_consistency, state)
Exemplo n.º 24
0
 def test_validate_unknown_nodes(self):
     service = {
         'name': 'some_name',
         'node': 'unknown_node',
         'command': 'do things',
         'pid_file': '/tmp',
         'monitor_interval': 30
     }
     config = {'services': [service]}
     self.container.add('third', config)
     assert_raises(ConfigError, self.container.validate)
Exemplo n.º 25
0
 def test_invalid_mode(self):
     config = {
         'container_path': '/nail/srv',
         'host_path': '/tmp',
         'mode': 'RA',
     }
     assert_raises(
         ConfigError,
         config_parse.valid_volume.validate,
         config,
         self.context,
     )
Exemplo n.º 26
0
 def test_invalid_mode(self):
     config = {
         'container_path': '/nail/srv',
         'host_path': '/tmp',
         'mode': 'RA',
     }
     assert_raises(
         ConfigError,
         config_parse.valid_volume.validate,
         config,
         self.context,
     )
Exemplo n.º 27
0
 def test_missing_container_path(self):
     config = {
         'container_path_typo': '/nail/srv',
         'host_path': '/tmp',
         'mode': 'RO',
     }
     assert_raises(
         ConfigError,
         config_parse.valid_volume.validate,
         config,
         self.context,
     )
Exemplo n.º 28
0
 def test_missing_container_path(self):
     config = {
         'container_path_typo': '/nail/srv',
         'host_path': '/tmp',
         'mode': 'RO',
     }
     assert_raises(
         ConfigError,
         config_parse.valid_volume.validate,
         config,
         self.context,
     )
Exemplo n.º 29
0
 def test_cleanup_missing_docker_image(self):
     config = dict(
         command='echo hello',
         executor=schema.ExecutorTypes.mesos,
         cpus=0.2,
         mem=150,
     )
     assert_raises(
         ConfigError,
         config_parse.valid_action,
         config,
         NullConfigContext,
     )
Exemplo n.º 30
0
    def test_check_consistency_failed(self):
        state = {runstate.JOB_STATE: {'name': mock.Mock()}}

        with mock.patch.object(
            self.store,
            'save',
            side_effect=PersistenceStoreError,
            autospec=None,
        ):
            assert_raises(
                PersistenceStoreError,
                self.manager._check_consistency,
                state
            )
Exemplo n.º 31
0
 def test_request_error(self):
     exception = assert_raises(
         client.RequestError,
         self.client.request,
         '/jobs',
     )
     assert_in(self.url, str(exception))
Exemplo n.º 32
0
    def test_invalid_job_collation(self):
        jobs = FrozenDict({'test_collision0': ConfigJob(name='test_collision0',
            node='node0',
            schedule=ConfigIntervalScheduler(timedelta=datetime.timedelta(0,
                                                                          20)),
            actions=FrozenDict({'action0_0': ConfigAction(name='action0_0',
                                                          command='test_command0.0',
                                                          requires=(),
                                                          node=None)}),
            queueing=True,
            run_limit=50,
            all_nodes=False,
            cleanup_action=ConfigCleanupAction(command='test_command0.1',
                                               requires=(),
                                               name='cleanup',
                                               node=None),
            enabled=True,
            allow_overlap=False)})

        services = FrozenDict({'test_collision0': ConfigService(name='test_collision0',
                        node='node0',
                        pid_file='/var/run/%(name)s-%(instance_number)s.pid',
                        command='service_command0',
                        monitor_interval=20,
                        restart_interval=None,
                        count=2)})
        fake_config = mock.Mock()
        setattr(fake_config, 'jobs', jobs)
        setattr(fake_config, 'services', services)
        expected_message = "Collision found for identifier 'MASTER.test_collision0'"
        exception = assert_raises(ConfigError, collate_jobs_and_services, {'MASTER': fake_config})
        assert_in(expected_message, str(exception))
Exemplo n.º 33
0
 def test_invalid_named_update(self):
     test_config = """bozray:"""
     test_config = yaml.load(test_config)
     expected_message = "Unknown keys in NamedConfigFragment : bozray"
     exception = assert_raises(ConfigError, validate_fragment, 'foo',
                               test_config)
     assert_in(expected_message, str(exception))
Exemplo n.º 34
0
 def test_overlap_node_and_node_pools(self):
     tron_config = dict(
         nodes=[dict(name="sameName", hostname="localhost")],
         node_pools=[dict(name="sameName", nodes=["sameNode"])])
     expected_msg = "Node and NodePool names must be unique sameName"
     exception = assert_raises(ConfigError, valid_config, tron_config)
     assert_in(expected_msg, str(exception))
Exemplo n.º 35
0
    def test_invalid_action_node_with_master_context(self):
        master_config = dict(
            nodes=[dict(
                name="node0",
                hostname="node0",
            )],
            node_pools=[dict(
                name="nodepool0",
                nodes=["node0"],
            )]
        )
        test_config = dict(
            jobs=[
                dict(
                    name="test_job",
                    namespace='test_namespace',
                    node="node0",
                    schedule="interval 20s",
                    actions=
                    [dict(name="action", node="nodepool1", command="command")],
                    cleanup_action=dict(command="command"),
                )
            ]
        )
        expected_message = "Unknown node name nodepool1 at test_namespace.NamedConfigFragment.jobs.Job.test_job.actions.Action.action.node"

        exception = assert_raises(
            ConfigError,
            validate_fragment,
            'test_namespace',
            test_config,
            master_config,
        )
        assert_in(expected_message, str(exception))
Exemplo n.º 36
0
    def test_invalid_node_pool_config(self):
        test_config = dict(
            nodes=[
                dict(name='node0', hostname='node0'),
                dict(name='node1', hostname='node1')
            ],
            node_pools=[
                dict(name='pool0', hostname=['node1']),
                dict(name='pool1', nodes=['node0', 'pool0'])
            ],
            jobs=[
                dict(
                    name='test_job0',
                    node='pool1',
                    schedule='interval 20s',
                    actions=[dict(name='action', command='cmd')]
                )
            ]
        )

        expected_msg = "NodePool pool0 is missing options"
        exception = assert_raises(
            ConfigError,
            valid_config,
            test_config,
        )
        assert_in(expected_msg, str(exception))
Exemplo n.º 37
0
    def test_bad_requires(self):
        test_config = BASE_CONFIG + """
jobs:
    -
        name: "test_job0"
        node: node0
        schedule: "interval 20s"
        actions:
            -
                name: "action0_0"
                command: "test_command0.0"
            -
                name: "action0_1"
                command: "test_command0.1"

    -
        name: "test_job1"
        node: node0
        schedule: "interval 20s"
        actions:
            -
                name: "action1_0"
                command: "test_command1.0"
                requires: [action0_0]

        """
        expected_message = ('jobs.MASTER.test_job1.action1_0 has a dependency '
                '"action0_0" that is not in the same job!')
        exception = assert_raises(ConfigError, valid_config_from_yaml, test_config)
        assert_in(expected_message, str(exception))
Exemplo n.º 38
0
    def test_bad_requires(self):
        test_config = dict(
            jobs=[
                dict(
                    name='test_job0',
                    node='node0',
                    schedule='interval 20s',
                    actions=[dict(name='action', command='cmd')]
                ),
                dict(
                    name='test_job1',
                    node='node0',
                    schedule='interval 20s',
                    actions=[
                        dict(
                            name='action1', command='cmd', requires=['action']
                        )
                    ]
                )
            ],
            **BASE_CONFIG
        )

        expected_message = (
            'jobs.MASTER.test_job1.action1 has a dependency '
            '"action" that is not in the same job!'
        )
        exception = assert_raises(
            ConfigError,
            valid_config,
            test_config,
        )
        assert_in(expected_message, str(exception))
Exemplo n.º 39
0
    def test_circular_dependency(self):
        test_config = dict(
            jobs=[
                dict(
                    name='test_job0',
                    node='node0',
                    schedule='interval 20s',
                    actions=[
                        dict(
                            name='action1',
                            command='cmd',
                            requires=['action2']
                        ),
                        dict(
                            name='action2',
                            command='cmd',
                            requires=['action1']
                        ),
                    ]
                )
            ],
            **BASE_CONFIG
        )

        expect = "Circular dependency in job.MASTER.test_job0: action1 -> action2"
        exception = assert_raises(
            ConfigError,
            valid_config,
            test_config,
        )
        assert_in(expect, str(exception))
Exemplo n.º 40
0
    def test_bad_requires(self):
        test_config = BASE_CONFIG + """
jobs:
    -
        name: "test_job0"
        node: node0
        schedule: "interval 20s"
        actions:
            -
                name: "action0_0"
                command: "test_command0.0"
            -
                name: "action0_1"
                command: "test_command0.1"

    -
        name: "test_job1"
        node: node0
        schedule: "interval 20s"
        actions:
            -
                name: "action1_0"
                command: "test_command1.0"
                requires: [action0_0]

        """
        expected_message = ('jobs.MASTER.test_job1.action1_0 has a dependency '
                            '"action0_0" that is not in the same job!')
        exception = assert_raises(ConfigError, valid_config_from_yaml,
                                  test_config)
        assert_in(expected_message, str(exception))
Exemplo n.º 41
0
 def test_overlap_node_and_node_pools(self):
     tron_config = dict(
         nodes=[dict(name="sameName", hostname="localhost")], node_pools=[dict(name="sameName", nodes=["sameNode"])]
     )
     expected_msg = "Node and NodePool names must be unique sameName"
     exception = assert_raises(ConfigError, valid_config, tron_config)
     assert_in(expected_msg, str(exception))
Exemplo n.º 42
0
    def test_bad_requires(self):
        test_config = (
            BASE_CONFIG
            + """
jobs:
    -
        name: "test_job0"
        node: node0
        schedule: "interval 20s"
        actions:
            -
                name: "action0_0"
                command: "test_command0.0"
            -
                name: "action0_1"
                command: "test_command0.1"

    -
        name: "test_job1"
        node: node0
        schedule: "interval 20s"
        actions:
            -
                name: "action1_0"
                command: "test_command1.0"
                requires: action0_0

        """
        )
        expected_message = "jobs.test_job1.action1_0 has a dependency " '"action0_0" that is not in the same job!'
        exception = assert_raises(ConfigError, load_config, test_config)
        assert_in(expected_message, str(exception))
Exemplo n.º 43
0
    def test_invalid_action_node_with_master_context(self):
        master_config = dict(
            nodes=[dict(
                name="node0",
                hostname="node0",
            )],
            node_pools=[dict(
                name="nodepool0",
                nodes=["node0"],
            )])
        test_config = dict(jobs=[
            dict(
                name="test_job",
                namespace='test_namespace',
                node="node0",
                schedule="daily 00:30:00 ",
                actions=[
                    dict(name="action", node="nodepool1", command="command")
                ],
                cleanup_action=dict(command="command"),
            )
        ])
        expected_message = "Unknown node name nodepool1 at test_namespace.NamedConfigFragment.jobs.Job.test_job.actions.Action.action.node"

        exception = assert_raises(
            ConfigError,
            validate_fragment,
            'test_namespace',
            test_config,
            master_config,
        )
        assert_in(expected_message, str(exception))
Exemplo n.º 44
0
    def test_invalid_node_pool_config(self):
        test_config = textwrap.dedent("""
            nodes:
                - name: node0
                  hostname: node0

            node_pools:
                - name: pool0
                  hostname: node1
                - name: pool1
                  nodes: [node0, pool0]
            jobs:
                - name: somejob
                  node: pool1
                  schedule: "interval 30s"
                  actions:
                    - name: first
                      command: "echo 1"
        """)
        expected_msg = "NodePool pool0 is missing options"
        exception = assert_raises(
            ConfigError,
            valid_config_from_yaml,
            test_config,
        )
        assert_in(expected_msg, str(exception))
Exemplo n.º 45
0
    def test_invalid_nested_node_pools(self):
        test_config = dict(
            nodes=[
                dict(name='node0', hostname='node0'),
                dict(name='node1', hostname='node1')
            ],
            node_pools=[
                dict(name='pool0', nodes=['node1']),
                dict(name='pool1', nodes=['node0', 'pool0'])
            ],
            jobs=[
                dict(
                    name='test_job0',
                    node='pool1',
                    schedule='constant',
                    actions=[dict(name='action', command='cmd')]
                )
            ]
        )

        expected_msg = "NodePool pool1 contains other NodePools: pool0"
        exception = assert_raises(
            ConfigError,
            valid_config,
            test_config,
        )
        assert_in(expected_msg, str(exception))
Exemplo n.º 46
0
 def test_missing_dir(self):
     exception = assert_raises(
         ConfigError,
         valid_output_stream_dir,
         'bogus-dir',
         NullConfigContext,
     )
     assert_in("is not a directory", str(exception))
Exemplo n.º 47
0
 def test_valid_identity_file_missing_private_key(self):
     exception = assert_raises(
         ConfigError,
         config_parse.valid_identity_file,
         '/file/not/exist',
         self.context,
     )
     assert_in("Private key file", str(exception))
Exemplo n.º 48
0
 def test_valid_time_delta_invalid(self):
     exception = assert_raises(
         ConfigError,
         config_utils.valid_time_delta,
         'no time',
         self.context,
     )
     assert_in('not a valid time delta: no time', str(exception))
Exemplo n.º 49
0
 def test_valid_known_hosts_file_missing(self):
     exception = assert_raises(
         ConfigError,
         config_parse.valid_known_hosts_file,
         '/bogus/path',
         self.context,
     )
     assert_in('Known hosts file /bogus/path', str(exception))
Exemplo n.º 50
0
    def test_invalid_named_update(self):
        test_config = """
config_name: "foo"
bozray:
        """
        expected_message = "Unknown options in NamedTron : bozray"
        exception = assert_raises(ConfigError, load_config, test_config)
        assert_in(expected_message, str(exception))
Exemplo n.º 51
0
 def test_get_url_from_identifier_no_match(self):
     exc = assert_raises(
         ValueError,
         get_object_type_from_identifier,
         self.index,
         'MASTER.namec',
     )
     assert_in('namec', str(exc))
Exemplo n.º 52
0
 def test_valid_identity_file_missing_private_key(self):
     exception = assert_raises(
         ConfigError,
         config_parse.valid_identity_file,
         '/file/not/exist',
         self.context,
     )
     assert_in("Private key file", str(exception))
Exemplo n.º 53
0
 def test_get_url_from_identifier_no_match(self):
     exc = assert_raises(
         ValueError,
         get_object_type_from_identifier,
         self.index,
         'MASTER.namec',
     )
     assert_in('namec', str(exc))
Exemplo n.º 54
0
 def test_missing_dir(self):
     exception = assert_raises(
         ConfigError,
         valid_output_stream_dir,
         'bogus-dir',
         NullConfigContext,
     )
     assert_in("is not a directory", str(exception))
Exemplo n.º 55
0
 def test_valid_time_delta_invalid(self):
     exception = assert_raises(
         ConfigError,
         config_utils.valid_time_delta,
         'no time',
         self.context,
     )
     assert_in('not a valid time delta: no time', str(exception))
Exemplo n.º 56
0
 def test_valid_known_hosts_file_missing(self):
     exception = assert_raises(
         ConfigError,
         config_parse.valid_known_hosts_file,
         '/bogus/path',
         self.context,
     )
     assert_in('Known hosts file /bogus/path', str(exception))
Exemplo n.º 57
0
 def test_validator_unknown_variable_error(self):
     template = "The {one} thing I {seven} is {unknown}"
     exception = assert_raises(
         ConfigError,
         self.validator,
         template,
         NullConfigContext,
     )
     assert_in("Unknown context variable", str(exception))
Exemplo n.º 58
0
 def test_validate_with_none(self):
     expected_msg = "A StubObject is required"
     exception = assert_raises(
         ConfigError,
         self.validator.validate,
         None,
         config_utils.NullConfigContext,
     )
     assert_in(expected_msg, str(exception))
Exemplo n.º 59
0
 def test_validate_with_none(self):
     expected_msg = "A StubObject is required"
     exception = assert_raises(
         ConfigError,
         self.validator.validate,
         None,
         config_utils.NullConfigContext,
     )
     assert_in(expected_msg, str(exception))
Exemplo n.º 60
0
 def test_valid_identity_files_missing_public_key(self):
     filename = self.private_file.name
     exception = assert_raises(
         ConfigError,
         config_parse.valid_identity_file,
         filename,
         self.context,
     )
     assert_in("Public key file", str(exception))