예제 #1
0
파일: deploy.py 프로젝트: saloniig/scap
    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
예제 #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']
예제 #3
0
파일: deploy.py 프로젝트: wikimedia/scap
    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
예제 #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'
예제 #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']
예제 #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'
예제 #7
0
def test_load_bad_type():
    with pytest.raises(checks.CheckInvalid):
        checks.load({'checks': {'foo': {'type': 'badtype'}}})
예제 #8
0
def test_load_tolerates_empty_checks():
    chks = checks.load({checks: {}})

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

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

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

    assert not chks