Esempio n. 1
0
    def test_failed_two_blocks(self):
        """Testing cleanup when a task has failed (ordered with two blocks)."""
        hooks = Hooks()
        hooks.cleanup = '''echo cleanup hello'''
        pipeline = FakePipeline(hooks=hooks)
        tasks = Tasks(pipeline, parallel=False)

        definition = [{
            'shell': {
                'script': '''exit 123''',
                'when': ''
            }
        }, {
            'shell': {
                'script': '''echo hello1''',
                'when': ''
            }
        }, {
            'env': {
                'block': 'two'
            }
        }, {
            'shell': {
                'script': '''echo hello2''',
                'when': ''
            }
        }]
        result = tasks.process(definition)
        output = [line for line in result['output'] if line.find("hello") >= 0]

        assert_that(result['success'], equal_to(False))
        assert_that(len(output), equal_to(1))
        assert_that(output[0], equal_to('cleanup hello'))
Esempio n. 2
0
    def test_failed_parallel(self):
        """Testing cleanup when a task has failed (parallel)."""
        hooks = Hooks()
        hooks.cleanup = '''echo cleanup 123'''
        pipeline = FakePipeline(hooks=hooks)
        tasks = Tasks(pipeline, parallel=True)

        definition = [{
            'shell': {
                'script': '''exit 123''',
                'when': ''
            }
        }, {
            'shell': {
                'script': '''echo hello''',
                'when': ''
            }
        }]
        result = tasks.process(definition)
        output = sorted([
            line for line in result['output']
            if line.find("hello") >= 0 or line.find("cleanup") >= 0
        ])

        assert_that(result['success'], equal_to(False))
        assert_that(len(output), equal_to(2))
        assert_that(output[0], equal_to('cleanup 123'))
        assert_that(output[1], equal_to('hello'))
Esempio n. 3
0
    def test_simple_failed_pipeline(self):
        """Testing of a simple failed pipeline."""
        definition = [{
            'stage(test)': [{
                'tasks': [{
                    'shell': {
                        'script': '''echo tasks1:hello1''',
                        'when': ''
                    }
                }, {
                    'shell': {
                        'script': '''exit 123''',
                        'when': ''
                    }
                }, {
                    'shell': {
                        'script': '''echo tasks1:hello3''',
                        'when': ''
                    }
                }]
            }]
        }]
        hooks = Hooks()
        hooks.cleanup = '''echo cleanup hello'''
        pipeline = Pipeline(options=ApplicationOptions(definition='fake.yaml'))
        pipeline.hooks = hooks
        result = pipeline.process(definition)
        output = [line for line in result['output'] if line.find("hello") >= 0]

        assert_that(result['success'], equal_to(False))
        assert_that(len(output), equal_to(2))
        assert_that(output[0], equal_to('tasks1:hello1'))
        assert_that(output[1], equal_to('cleanup hello'))
        assert_that(pipeline.hooks, equal_to(hooks))
Esempio n. 4
0
    def test_environment_variables(self):
        """Testing of a simple valid pipeline with environment variables."""
        definition = [{
            'env': {
                'message': 'pipeline hello'
            }
        }, {
            'stage(test)': [{
                'tasks': [{
                    'shell': {
                        'script': '''echo $message''',
                        'when': ''
                    }
                }, {
                    'shell': {
                        'script': '''echo tasks1:hello''',
                        'when': ''
                    }
                }]
            }]
        }]
        hooks = Hooks()
        hooks.cleanup = '''echo cleanup hello'''
        pipeline = Pipeline(options=ApplicationOptions(definition='fake.yaml'))
        pipeline.hooks = hooks
        result = pipeline.process(definition)
        output = [line for line in result['output'] if line.find("hello") >= 0]

        assert_that(result['success'], equal_to(True))
        assert_that(len(output), equal_to(3))
        assert_that(output[0], equal_to('pipeline hello'))
        assert_that(output[1], equal_to('tasks1:hello'))
        assert_that(output[2], equal_to('cleanup hello'))
Esempio n. 5
0
    def run(self, definition):
        """Processing the pipeline."""
        self.logger.info("Running with Python %s",
                         sys.version.replace("\n", ""))
        self.logger.info("Running on platform %s", platform.platform())
        self.logger.info("Current cpu count is %d",
                         multiprocessing.cpu_count())
        self.logger.info("Processing pipeline definition '%s'", definition)

        document = self.validate_document(definition)
        if self.options.validate_only:
            self.logger.info("Stopping after validation as requested!")
            return []

        self.provide_temporary_scripts_path()

        versions = VersionsCheck().process(document)
        VersionsReport().process(versions)

        collector = Application.create_and_run_collector(
            document, self.options)
        matrix = find_matrix(document)
        output = []
        if len(matrix) == 0:
            model = {} if 'model' not in document else document['model']
            pipeline = Pipeline(model=model, options=self.options)
            pipeline.hooks = Hooks(document)
            result = pipeline.process(document['pipeline'])
        else:
            result = self.run_matrix(matrix, document)

        output = result['output']
        self.shutdown(collector, success=result['success'])
        return output
Esempio n. 6
0
    def test_failed(self):
        """Testing for failed stage."""
        hooks = Hooks()
        hooks.cleanup = '''echo cleanup hello'''
        pipeline = FakePipeline(hooks=hooks)
        stage = Stage(pipeline, 'test')

        definition = [{
            'tasks': [{
                'shell': {
                    'script': '''echo tasks1:hello1''',
                    'when': ''
                }
            }, {
                'shell': {
                    'script': '''exit 123''',
                    'when': ''
                }
            }]
        }, {
            'tasks': [{
                'shell': {
                    'script': '''echo tasks2:hello1''',
                    'when': ''
                }
            }, {
                'shell': {
                    'script': '''echo tasks2:hello2''',
                    'when': ''
                }
            }]
        }]
        result = stage.process(definition)
        output = [line for line in result['output'] if line.find("hello") >= 0]

        assert_that(result['success'], equal_to(False))
        assert_that(len(output), equal_to(2))
        assert_that(output[0], equal_to('tasks1:hello1'))
        assert_that(output[1], equal_to('cleanup hello'))
Esempio n. 7
0
    def run_matrix(self, matrix_definition, document):
        """
        Running pipeline via a matrix.

        Args:
            matrix_definition (dict): one concrete matrix item.
            document (dict): spline document (complete) as loaded from yaml file.
        """
        matrix = Matrix(matrix_definition, 'matrix(parallel)' in document)

        process_data = MatrixProcessData()
        process_data.options = self.options
        process_data.pipeline = document['pipeline']
        process_data.model = {} if 'model' not in document else document[
            'model']
        process_data.hooks = Hooks(document)

        return matrix.process(process_data)
Esempio n. 8
0
 def test_simple(self):
     """Testing hooks without a document."""
     hooks = Hooks()
     assert_that(hooks.cleanup, equal_to(''))
Esempio n. 9
0
 def test_document(self):
     """Testing hooks with a document."""
     hooks = Hooks({'hooks': {'cleanup': {}}})
     assert_that(hooks.cleanup, equal_to(''))
     hooks = Hooks({'hooks': {'cleanup': {'script': 'echo "hello"'}}})
     assert_that(hooks.cleanup, equal_to('echo "hello"'))