예제 #1
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'))
예제 #2
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))
예제 #3
0
    def test_failed_parallel(self):
        """Testing failed parallel."""
        matrix_definition = [{
            'name': 'one',
            'env': {
                'message': 'hello1'
            }
        }, {
            'name': 'two',
            'env': {
                'message': 'hello2'
            }
        }]
        pipeline_definition = [{
            'stage(test)': [{
                'tasks': [{
                    'shell': {
                        'script': '''exit 123''',
                        'when': ''
                    }
                }]
            }]
        }]

        process_data = MatrixProcessData()
        process_data.pipeline = pipeline_definition
        process_data.options = ApplicationOptions(definition='fake.yaml')

        matrix = Matrix(matrix_definition, parallel=True)
        result = matrix.process(process_data)
        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(0))
예제 #4
0
    def test_matrix_worker(self):
        """Testing worker for matrix used in multiprocessing."""
        pipeline_definition = [{
            'stage(test)': [{
                'tasks': [{
                    'shell': {
                        'script': '''echo $message''',
                        'when': ''
                    }
                }]
            }]
        }]

        result = matrix_worker({
            'matrix': {
                'name': 'one',
                'env': {
                    'message': 'hello1'
                }
            },
            'pipeline':
            pipeline_definition,
            'model': {},
            'options':
            ApplicationOptions(definition='fake.yaml'),
            'hooks':
            None
        })

        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(1))
예제 #5
0
    def test_run_matrix(self):
        """Testing method Application.run_matrix."""
        mdef = [{
            'name': 'test1',
            'env': {
                'message': 'hello 1'
            }
        }, {
            'name': 'test2',
            'env': {
                'message': 'hello 2'
            }
        }]
        pdef = {
            'pipeline': [{
                'stage(Test)': [{
                    'tasks': [{
                        'shell': {
                            'script': 'echo "{{ env.message }}"',
                            'when': ''
                        }
                    }]
                }]
            }]
        }

        application = Application(ApplicationOptions(definition='fake.yaml'))
        result = application.run_matrix(mdef, pdef)

        assert_that(result['success'], equal_to(True))
        output = [line for line in result['output'] if line.find('hello') >= 0]
        assert_that(len(output), equal_to(2))
        assert_that(output[0], equal_to('hello 1'))
        assert_that(output[1], equal_to('hello 2'))
예제 #6
0
    def test_simple_with_one_entry(self):
        """Testing simple matrix with one entry."""
        matrix_definition = [{'name': 'one', 'env': {'message': 'hello'}}]
        pipeline_definition = [{
            'stage(test)': [{
                'tasks': [{
                    'shell': {
                        'script': '''echo tasks1:hello1''',
                        'when': ''
                    }
                }, {
                    'shell': {
                        'script': '''echo tasks1:hello2''',
                        'when': ''
                    }
                }]
            }]
        }]

        process_data = MatrixProcessData()
        process_data.pipeline = pipeline_definition
        process_data.options = ApplicationOptions(definition='fake.yaml')

        matrix = Matrix(matrix_definition, parallel=False)
        result = matrix.process(process_data)
        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(2))
        assert_that(output[0], equal_to('tasks1:hello1'))
        assert_that(output[1], equal_to('tasks1:hello2'))
예제 #7
0
 def test_missing_mandatory(self):
     """Testing missing mandatory parameter."""
     try:
         ApplicationOptions()
         self.assertFalse("RuntimeError expected")
     except RuntimeError as exception:
         assert_that(str(exception), equal_to("Missing keys: 'definition'"))
예제 #8
0
 def test_simple(self):
     """Testing application for a very simple example."""
     filename = os.path.join(os.path.dirname(__file__), 'data/simple.yaml')
     options = ApplicationOptions(definition=filename)
     application = Application(options)
     output = application.run(options.definition)
     assert_that(len(output), equal_to(1))
     assert_that(output[0], equal_to("hello world!"))
예제 #9
0
 def test_invalidate_document(self):
     """Testing invalid document."""
     application = Application(
         ApplicationOptions(definition='data/invalid.yaml'))
     with patch('sys.exit') as mocked_exit:
         path = os.path.dirname(__file__)
         application.validate_document(
             os.path.join(path, "data/invalid.yaml"))
         mocked_exit.assert_called_once_with(1)
예제 #10
0
 def test_report(self, item):
     """Testing missing mandatory parameter."""
     try:
         options = {'definition': 'fake.yml'}
         options.update({'report': item[0]})
         ApplicationOptions(**options)
         if not item[1]:
             self.assertFalse("RuntimeError expected")
     except RuntimeError as exception:
         if item[1]:
             self.assertFalse("Unexpected exception %s" % exception)
예제 #11
0
 def test_validate_document(self):
     """Testing valid document."""
     application = Application(
         ApplicationOptions(definition='data/simple.yaml'))
     application.validate_only = True
     with patch('sys.exit') as mocked_exit:
         path = os.path.dirname(__file__)
         document = application.validate_document(
             os.path.join(path, "data/simple.yaml"))
         mocked_exit.assert_not_called()
         assert_that(isinstance(document, dict), equal_to(True))
예제 #12
0
 def test_init(self):
     """Testing c'tor only."""
     tags = 'prepare,build'
     matrix_tags = "py27,py35"
     options = ApplicationOptions(definition='fake.yaml',
                                  matrix_tags=matrix_tags,
                                  tags=tags)
     application = Application(options)
     assert_that(application.options.tags, equal_to(['prepare', 'build']))
     assert_that(application.options.matrix_tags, equal_to(['py27',
                                                            'py35']))
     assert_that(application.options.validate_only, equal_to(False))
     assert_that(application.options.logging_config, equal_to(''))
예제 #13
0
 def test_minimal_valid(self):
     """Testing to provide mandatory parameters only."""
     options = ApplicationOptions(definition='fake.yml')
     assert_that(options.definition, equal_to('fake.yml'))
     assert_that(options.matrix_tags, equal_to([]))
     assert_that(options.tags, equal_to([]))
     assert_that(options.logging_config, equal_to(''))
     assert_that(options.event_logging, equal_to(False))
     assert_that(options.validate_only, equal_to(False))
     assert_that(options.dry_run, equal_to(False))
     assert_that(options.debug, equal_to(False))
     assert_that(options.strict, equal_to(False))
     assert_that(options.report, equal_to('off'))
     assert_that(options.temporary_scripts_path, equal_to(''))
예제 #14
0
 def test_run_collector(self):
     """Test create, run and stop of collector."""
     # we have to disable the spawning of the process otherwise
     # the coverage won't work ...
     with patch("spline.application.Collector.start") as mocked_start:
         collector = Application.create_and_run_collector(
             document={},
             options=ApplicationOptions(definition='fake.html',
                                        report='html'))
         assert_that(collector.is_alive(), equal_to(False))
         mocked_start.assert_called_once()
         with patch("logging.Logger.info") as mocked_logging:
             collector.queue.put(None)
             collector.run()
             mocked_logging.assert_called_once_with(
                 "Stopping collector process ...")
예제 #15
0
    def test_with_tags_and_filter_parallel(self):
        """Testing simple matrix with tags and filtering."""
        matrix_definition = [{
            'name': 'one',
            'env': {
                'message': 'hello1'
            },
            'tags': ['group-a']
        }, {
            'name': 'two',
            'env': {
                'message': 'hello2'
            },
            'tags': ['group-b']
        }, {
            'name': 'three',
            'env': {
                'message': 'hello3'
            },
            'tags': ['group-a']
        }]
        pipeline_definition = [{
            'stage(test)': [{
                'tasks': [{
                    'shell': {
                        'script': '''echo $message''',
                        'when': ''
                    }
                }]
            }]
        }]

        process_data = MatrixProcessData()
        process_data.pipeline = pipeline_definition
        process_data.options = ApplicationOptions(definition='fake.yaml',
                                                  matrix_tags='group-a')

        matrix = Matrix(matrix_definition, parallel=True)
        result = matrix.process(process_data)
        output = sorted(
            [line for line in result['output'] if line.find("hello") >= 0])

        assert_that(result['success'], equal_to(True))
        assert_that(len(output), equal_to(2))
        assert_that(output[0], equal_to('hello1'))
        assert_that(output[1], equal_to('hello3'))
예제 #16
0
    def test_dry_run(self):
        """Testing simple matrix with tags and filtering."""
        matrix_definition = [{
            'name': 'one',
            'env': {
                'message': 'hello1'
            }
        }, {
            'name': 'two',
            'env': {
                'message': 'hello2'
            }
        }, {
            'name': 'three',
            'env': {
                'message': 'hello3'
            }
        }]
        pipeline_definition = [{
            'stage(test)': [{
                'tasks': [{
                    'shell': {
                        'script': '''echo {{ env.message }}''',
                        'when': ''
                    }
                }]
            }]
        }]

        process_data = MatrixProcessData()
        process_data.pipeline = pipeline_definition
        process_data.options = ApplicationOptions(definition='fake.yaml',
                                                  dry_run=True)

        matrix = Matrix(matrix_definition, parallel=True)
        result = matrix.process(process_data)
        output = [line for line in result['output'] if len(line) > 0]

        assert_that(result['success'], equal_to(True))
        assert_that(len(output), equal_to(6))
        assert_that(output[0], equal_to('#!/bin/bash'))
        assert_that(output[1], equal_to('echo hello1'))
        assert_that(output[2], equal_to('#!/bin/bash'))
        assert_that(output[3], equal_to('echo hello2'))
        assert_that(output[4], equal_to('#!/bin/bash'))
        assert_that(output[5], equal_to('echo hello3'))
예제 #17
0
def main(**kwargs):
    """The Pipeline tool."""
    options = ApplicationOptions(**kwargs)
    Event.configure(is_logging_enabled=options.event_logging)
    application = Application(options)
    application.run(options.definition)
예제 #18
0
 def __init__(self, hooks=None):
     """Initialization of fake pipeline."""
     self.data = PipelineData(hooks)
     self.model = {}
     self.options = ApplicationOptions(definition='fake.yaml')
     self.variables = {}