Exemple #1
0
    def test_execute_snapshot(self):
        build = self.create_build(self.create_project(), cause=Cause.snapshot)
        job = self.create_job(build)

        buildstep = DefaultBuildStep(commands=[{'script': 'ls', 'type': 'collect_tests'},
                                               {'script': 'setup_command', 'type': 'setup'},
                                               {'script': 'default_command'},
                                               {'script': 'make snapshot', 'type': 'snapshot'}])
        buildstep.execute(job)

        step = job.phases[0].steps[0]

        assert step.data['release'] == DEFAULT_RELEASE
        assert step.status == Status.pending_allocation
        assert step.cluster is None

        # collect tests and default commands shouldn't be added
        commands = step.commands
        assert len(commands) == 3

        # skip blacklist removal command
        idx = 1

        assert commands[idx].script == 'setup_command'
        assert commands[idx].cwd == DEFAULT_PATH
        assert commands[idx].type == CommandType.setup
        assert tuple(commands[idx].artifacts) == tuple(DEFAULT_ARTIFACTS)
        assert commands[idx].env == DEFAULT_ENV

        idx += 1
        assert commands[idx].script == 'make snapshot'
        assert commands[idx].cwd == DEFAULT_PATH
        assert commands[idx].type == CommandType.snapshot
        assert tuple(commands[idx].artifacts) == tuple(DEFAULT_ARTIFACTS)
        assert commands[idx].env == DEFAULT_ENV
Exemple #2
0
    def test_execute_collection_step(self, get_vcs):
        build = self.create_build(self.create_project())
        job = self.create_job(build)

        vcs = mock.Mock(spec=Vcs)
        vcs.get_buildstep_clone.return_value = 'git clone https://example.com'
        get_vcs.return_value = vcs

        buildstep = DefaultBuildStep(commands=[{'script': 'ls', 'type': 'collect_tests'},
                                               {'script': 'setup_command', 'type': 'setup'},
                                               {'script': 'default_command'},
                                               {'script': 'make snapshot', 'type': 'snapshot'}])
        buildstep.execute(job)

        step = job.phases[0].steps[0]

        assert step.data['release'] == DEFAULT_RELEASE
        assert step.status == Status.pending_allocation

        commands = step.commands
        assert len(commands) == 2

        assert commands[0].script == 'git clone https://example.com'
        assert commands[0].cwd == ''
        assert commands[0].type == CommandType.infra_setup
        assert commands[0].env == DEFAULT_ENV

        assert commands[1].script == 'ls'
        assert commands[1].cwd == DEFAULT_PATH
        assert commands[1].type == CommandType.collect_tests
        assert tuple(commands[1].artifacts) == tuple(DEFAULT_ARTIFACTS)
        assert commands[1].env == DEFAULT_ENV
Exemple #3
0
    def test_execute_snapshot(self):
        build = self.create_build(self.create_project(), cause=Cause.snapshot)
        job = self.create_job(build)

        buildstep = DefaultBuildStep(commands=[{'script': 'ls', 'type': 'collect_tests'},
                                               {'script': 'setup_command', 'type': 'setup'},
                                               {'script': 'default_command'},
                                               {'script': 'make snapshot', 'type': 'snapshot'}])
        buildstep.execute(job)

        step = job.phases[0].steps[0]

        assert step.data['release'] == DEFAULT_RELEASE
        assert step.status == Status.pending_allocation

        # collect tests and default commands shouldn't be added
        commands = step.commands
        assert len(commands) == 2

        assert commands[0].script == 'setup_command'
        assert commands[0].cwd == DEFAULT_PATH
        assert commands[0].type == CommandType.setup
        assert tuple(commands[0].artifacts) == tuple(DEFAULT_ARTIFACTS)
        assert commands[1].env == DEFAULT_ENV

        assert commands[1].script == 'make snapshot'
        assert commands[1].cwd == DEFAULT_PATH
        assert commands[1].type == CommandType.snapshot
        assert tuple(commands[1].artifacts) == tuple(DEFAULT_ARTIFACTS)
        assert commands[1].env == DEFAULT_ENV
Exemple #4
0
    def test_execute_collection_step(self, get_vcs):
        build = self.create_build(self.create_project(), label='buildlabel')
        job = self.create_job(build)

        vcs = mock.Mock(spec=Vcs)
        vcs.get_buildstep_clone.return_value = 'git clone https://example.com'
        get_vcs.return_value = vcs

        buildstep = DefaultBuildStep(commands=[{
            'script': 'ls',
            'type': 'collect_tests',
            'path': 'subdir'
        }, {
            'script': 'setup_command',
            'type': 'setup'
        }, {
            'script': 'default_command'
        }, {
            'script': 'make snapshot',
            'type': 'snapshot'
        }],
                                     repo_path='source',
                                     path='tests')
        buildstep.execute(job)

        vcs.get_buildstep_clone.assert_called_with(job.source, 'source', True,
                                                   None)

        assert job.phases[0].label == 'Collect tests'
        step = job.phases[0].steps[0]

        assert step.data['release'] == DEFAULT_RELEASE
        assert step.status == Status.pending_allocation
        assert step.cluster is None
        assert step.label == 'Collect tests'

        commands = step.commands
        assert len(commands) == 3

        idx = 0
        assert commands[idx].script == 'git clone https://example.com'
        assert commands[idx].cwd == ''
        assert commands[idx].type == CommandType.infra_setup
        assert commands[idx].env == DEFAULT_ENV

        # skip blacklist removal command
        idx += 1

        idx += 1
        assert commands[idx].script == 'ls'
        assert commands[idx].cwd == 'source/tests/subdir'
        assert commands[idx].type == CommandType.collect_tests
        assert tuple(commands[idx].artifacts) == tuple(DEFAULT_ARTIFACTS)
        assert commands[idx].env == DEFAULT_ENV
Exemple #5
0
    def test_execute_other_repos(self, git_get_clone_command, mercurial_get_clone_command, get_vcs):
        build = self.create_build(self.create_project(), label='buildlabel')
        job = self.create_job(build)

        vcs = mock.Mock(spec=Vcs)
        vcs.get_buildstep_clone.return_value = 'git clone https://example.com'
        get_vcs.return_value = vcs

        git_get_clone_command.return_value = 'git clone'
        mercurial_get_clone_command.return_value = 'hg clone'

        current_app.config['GIT_DEFAULT_BASE_URI'] = '[email protected]:'
        current_app.config['MERCURIAL_DEFAULT_BASE_URI'] = '[email protected]/'
        buildstep = DefaultBuildStep(commands=[{'script': 'ls'}],
                                     repo_path='source', path='tests',
                                     other_repos=[{'repo': 'changes.git', 'path': 'changes', 'revision': 'abcdefg'},
                                                  {'repo': 'hg_repo', 'path': '/mercurial_repo', 'backend': 'hg'},
                                                  {'repo': '[email protected]:foo.git', 'path': '/foo', 'backend': 'git'}])
        buildstep.execute(job)

        vcs.get_buildstep_clone.assert_called_with(job.source, 'source', True, None)

        git_get_clone_command.assert_any_call('[email protected]:changes.git', 'changes', 'abcdefg', True, None)
        git_get_clone_command.assert_any_call('[email protected]:foo.git', '/foo', 'origin/master', True, None)
        mercurial_get_clone_command.assert_any_call('[email protected]/hg_repo', '/mercurial_repo', 'default', True, None)

        assert job.phases[0].label == 'buildlabel'
        step = job.phases[0].steps[0]

        commands = step.commands
        assert len(commands) == 6

        idx = 0
        assert commands[idx].script == 'git clone https://example.com'
        assert commands[idx].cwd == ''
        assert commands[idx].type == CommandType.infra_setup
        assert commands[idx].env == DEFAULT_ENV

        for i in xrange(idx, idx + 3):
            assert commands[idx].type == CommandType.infra_setup
        idx += 3

        # skip blacklist removal command
        idx += 1

        idx += 1
        assert commands[idx].script == 'ls'
Exemple #6
0
    def test_execute_collection_step(self, get_vcs):
        build = self.create_build(self.create_project(), label='buildlabel')
        job = self.create_job(build)

        vcs = mock.Mock(spec=Vcs)
        vcs.get_buildstep_clone.return_value = 'git clone https://example.com'
        get_vcs.return_value = vcs

        buildstep = DefaultBuildStep(commands=[{'script': 'ls', 'type': 'collect_tests', 'path': 'subdir'},
                                               {'script': 'setup_command', 'type': 'setup'},
                                               {'script': 'default_command'},
                                               {'script': 'make snapshot', 'type': 'snapshot'}],
                                     repo_path='source', path='tests')
        buildstep.execute(job)

        vcs.get_buildstep_clone.assert_called_with(job.source, 'source', True, None)

        assert job.phases[0].label == 'Collect tests'
        step = job.phases[0].steps[0]

        assert step.data['release'] == DEFAULT_RELEASE
        assert step.status == Status.pending_allocation
        assert step.cluster is None
        assert step.label == 'Collect tests'

        commands = step.commands
        assert len(commands) == 3

        idx = 0
        assert commands[idx].script == 'git clone https://example.com'
        assert commands[idx].cwd == ''
        assert commands[idx].type == CommandType.infra_setup
        assert commands[idx].env == DEFAULT_ENV

        # skip blacklist removal command
        idx += 1

        idx += 1
        assert commands[idx].script == 'ls'
        assert commands[idx].cwd == 'source/tests/subdir'
        assert commands[idx].type == CommandType.collect_tests
        assert tuple(commands[idx].artifacts) == tuple(DEFAULT_ARTIFACTS)
        assert commands[idx].env == DEFAULT_ENV
Exemple #7
0
 def get_buildstep(self, **kwargs):
     return DefaultBuildStep(commands=(
         dict(
             script='echo "hello world 2"',
             path='/usr/test/1',
             artifacts=['artifact1.txt', 'artifact2.txt'],
             env={'PATH': '/usr/test/1'},
             type='setup',
         ),
         dict(script='echo "hello world 1"', ),
     ),
                             **kwargs)
Exemple #8
0
 def get_buildstep(self):
     return DefaultBuildStep(commands=(
         dict(
             script='echo "hello world 2"',
             path='/usr/test/1',
             artifacts=['artifact1.txt', 'artifact2.txt'],
             env={'PATH': '/usr/test/1'},
         ),
         dict(
             script='echo "hello world 2"',
             path='/usr/test/2',
             artifacts=['artifact3.txt', 'artifact4.txt'],
         ),
     ))
Exemple #9
0
    def test_execute_other_repos(self, git_get_clone_command,
                                 mercurial_get_clone_command, get_vcs):
        build = self.create_build(self.create_project(), label='buildlabel')
        job = self.create_job(build)

        vcs = mock.Mock(spec=Vcs)
        vcs.get_buildstep_clone.return_value = 'git clone https://example.com'
        get_vcs.return_value = vcs

        git_get_clone_command.return_value = 'git clone'
        mercurial_get_clone_command.return_value = 'hg clone'

        current_app.config['GIT_DEFAULT_BASE_URI'] = '[email protected]:'
        current_app.config['MERCURIAL_DEFAULT_BASE_URI'] = '[email protected]/'
        buildstep = DefaultBuildStep(commands=[{
            'script': 'ls'
        }],
                                     repo_path='source',
                                     path='tests',
                                     other_repos=[{
                                         'repo': 'changes.git',
                                         'path': 'changes',
                                         'revision': 'abcdefg'
                                     }, {
                                         'repo': 'hg_repo',
                                         'path': '/mercurial_repo',
                                         'backend': 'hg'
                                     }, {
                                         'repo': '[email protected]:foo.git',
                                         'path': '/foo',
                                         'backend': 'git'
                                     }])
        buildstep.execute(job)

        vcs.get_buildstep_clone.assert_called_with(job.source, 'source', True,
                                                   None)

        git_get_clone_command.assert_any_call('[email protected]:changes.git',
                                              'changes', 'abcdefg', True, None)
        git_get_clone_command.assert_any_call('[email protected]:foo.git',
                                              '/foo', 'origin/master', True,
                                              None)
        mercurial_get_clone_command.assert_any_call('[email protected]/hg_repo',
                                                    '/mercurial_repo',
                                                    'default', True, None)

        assert job.phases[0].label == 'buildlabel'
        step = job.phases[0].steps[0]

        commands = step.commands
        assert len(commands) == 6

        idx = 0
        assert commands[idx].script == 'git clone https://example.com'
        assert commands[idx].cwd == ''
        assert commands[idx].type == CommandType.infra_setup
        assert commands[idx].env == DEFAULT_ENV

        for i in xrange(idx, idx + 3):
            assert commands[idx].type == CommandType.infra_setup
        idx += 3

        # skip blacklist removal command
        idx += 1

        idx += 1
        assert commands[idx].script == 'ls'