Exemple #1
0
    def _execute_checks(self, stage, group=None, logger=None):
        """
        Fetch and executes all checks configured for the given stage.

        Checks are retrieved from the remote deploy host and cached within
        tmp.
        """
        # Primarily for use in script checks
        check_environment = os.environ.copy()
        check_environment['SCAP_FINAL_PATH'] = self.final_path
        check_environment['SCAP_REV_PATH'] = self.context.rev_path(self.rev)

        # Load NRPE checks
        if os.path.isdir(self.config['nrpe_dir']):
            nrpe.register(nrpe.load_directory(self.config['nrpe_dir']))

        # Load script checks
        script.register_directory(self.context.scripts_dir(self.rev))

        chks = checks.load(self.config, check_environment)
        chks = [
            chk for chk in chks.values() if self._valid_chk(chk, stage, group)
        ]

        success, done = checks.execute(chks, logger=logger)
        failed = [job.check.name for job in done if job.isfailure()]

        if success:
            return 0
        return 1 if failed else 2
Exemple #2
0
def test_custom_type():
    @checks.checktype('custom')
    class CustomCheck(checks.Check):
        pass

    try:
        chks = checks.load({
            'checks': {
                'foo': {
                    'type': 'custom',
                    'command': '/bin/true',
                    'stage': 'promote',
                }
            }
        })

        assert len(chks) == 1

        assert 'foo' in chks
        assert isinstance(chks['foo'], CustomCheck)
        assert chks['foo'].stage == 'promote'
        assert chks['foo'].command == '/bin/true'

    finally:
        del checks._TYPES['custom']
Exemple #3
0
    def _execute_checks(self, stage, group=None, logger=None):
        """
        Fetch and executes all checks configured for the given stage.

        Checks are retrieved from the remote deploy host and cached within
        tmp.
        """
        # Primarily for use in script checks
        check_environment = os.environ.copy()
        check_environment['SCAP_FINAL_PATH'] = self.final_path
        check_environment['SCAP_REV_PATH'] = self.context.rev_path(self.rev)

        # Load NRPE checks
        if os.path.isdir(self.config['nrpe_dir']):
            nrpe.register(nrpe.load_directory(self.config['nrpe_dir']))

        # Load script checks
        script.register_directory(self.context.scripts_dir(self.rev))

        chks = checks.load(self.config, check_environment)
        chks = [
            chk for chk in chks.values() if self._valid_chk(chk, stage, group)
        ]

        success, done = checks.execute(chks, logger=logger)
        failed = [job.check.name for job in done if job.isfailure()]

        if success:
            return 0
        return 1 if failed else 2
Exemple #4
0
def test_load_valid_config():
    chks = checks.load({
        'checks': {
            'foo': {
                'type': 'command',
                'command': '/bin/true',
                'stage': 'promote',
                'timeout': 60
            },
            'bar': {
                'type': 'command',
                'command': '/bin/false',
                'stage': 'promote'
            }
        }
    })

    assert len(chks) == 2

    assert 'foo' in chks
    assert isinstance(chks['foo'], checks.Check)
    assert chks['foo'].stage == 'promote'
    assert chks['foo'].command == '/bin/true'

    assert 'bar' in chks
    assert isinstance(chks['bar'], checks.Check)
    assert chks['bar'].stage == 'promote'
    assert chks['bar'].command == '/bin/false'
Exemple #5
0
def test_custom_type():
    @checks.checktype('custom')
    class CustomCheck(checks.Check):
        pass

    try:
        chks = checks.load({
            'checks': {
                'foo': {
                    'type': 'custom',
                    'command': '/bin/true',
                    'stage': 'promote',
                }}})

        assert len(chks) == 1

        assert 'foo' in chks
        assert isinstance(chks['foo'], CustomCheck)
        assert chks['foo'].stage == 'promote'
        assert chks['foo'].command == '/bin/true'

    finally:
        del checks._TYPES['custom']
Exemple #6
0
def test_load_valid_config():
    chks = checks.load({
        'checks': {
            'foo': {
                'type': 'command',
                'command': '/bin/true',
                'stage': 'promote',
                'timeout': 60},
            'bar': {
                'type': 'command',
                'command': '/bin/false',
                'stage': 'promote'}}})

    assert len(chks) == 2

    assert 'foo' in chks
    assert isinstance(chks['foo'], checks.Check)
    assert chks['foo'].stage == 'promote'
    assert chks['foo'].command == '/bin/true'

    assert 'bar' in chks
    assert isinstance(chks['bar'], checks.Check)
    assert chks['bar'].stage == 'promote'
    assert chks['bar'].command == '/bin/false'
Exemple #7
0
def test_load_bad_type():
    with pytest.raises(checks.CheckInvalid):
        checks.load({'checks': {'foo': {'type': 'badtype'}}})
Exemple #8
0
def test_load_tolerates_empty_checks():
    chks = checks.load({checks: {}})

    assert not chks
Exemple #9
0
def test_load_tolerates_empty_config():
    chks = checks.load("")

    assert not chks
Exemple #10
0
def test_load_bad_type():
    with pytest.raises(checks.CheckInvalid):
        checks.load({'checks': {'foo': {'type': 'badtype'}}})
Exemple #11
0
def test_load_tolerates_empty_checks():
    chks = checks.load({checks: {}})

    assert not chks
Exemple #12
0
def test_load_tolerates_empty_config():
    chks = checks.load("")

    assert not chks