예제 #1
0
    def test_printTaskInfo_no_task(self):
        """Test _printTaskInfo with no task found"""
        session = mock.MagicMock()
        task_id = 1
        session.getTaskInfo.return_value = None

        with self.assertRaises(koji.GenericError) as cm:
            _printTaskInfo(session, task_id, '/')
        self.assertEquals(str(cm.exception), "No such task: %d" % task_id)
예제 #2
0
    def test_printTaskInfo_no_task(self):
        """Test _printTaskInfo with no task found"""
        session = mock.MagicMock()
        task_id = 1
        session.getTaskInfo.return_value = None

        with self.assertRaises(koji.GenericError) as cm:
            _printTaskInfo(session, task_id, '/')
        self.assertEquals(str(cm.exception), "No such task: %d" % task_id)
예제 #3
0
    def test_printTaskInfo_build_srpm(self, list_task_output_mock):
        session = mock.MagicMock()

        parent = self.task_info_templ.copy()
        parent.update({
            'method': 'build',
        })

        child_build = parent.copy()
        child_build.update({
            'id':
            2,
            'parent':
            1,
            'request':
            ['path/to/bash.src.rpm', 2, 'x86_64', True, {
                'repo_id': 1
            }],
            'method':
            'buildArch',
        })

        child_tag = parent.copy()
        child_tag.update({
            'id': 3,
            'parent': 1,
            'request': [1, 1, False, None, True],
            'arch': 'noarch',
            'method': 'tagBuild'
        })

        buildroot_info = [{
            'id': 1,
            'repo_id': 1,
            'tag_name': 'fedora26-build',
            'host_name': 'kojibuilder',
        }]

        build_info = [{
            'package_name': 'bash',
            'version': '4.4.12',
            'release': '5.fc26',
            'epoch': None,
            'nvr': 'bash-4.4.12-5.fc26',
            'build_id': 1,
        }]

        files = {
            'bash-debuginfo-4.4.12-5.fc26.x86_64.rpm': ['DEFAULT'],
            'hw_info.log': ['DEFAULT'],
            'build.log': ['DEFAULT'],
            'bash-4.4.12-5.fc26.src.rpm': ['DEFAULT'],
            'root.log': ['DEFAULT'],
            'state.log': ['DEFAULT'],
            'mock_output.log': ['DEFAULT'],
            'bash-4.4.12-5.fc26.x86_64.rpm': ['DEFAULT'],
            'installed_pkgs.log': ['DEFAULT'],
            'bash-doc-4.4.12-5.fc26.x86_64.rpm': ['DEFAULT']
        }

        # need ordered dict to get same results
        files = collections.OrderedDict(
            sorted(files.items(), key=lambda t: t[0]))

        list_task_output_mock.side_effect = [[], files, {}]

        session.getTaskInfo.side_effect = [parent, child_build, child_tag]
        session.listBuildroots.side_effect = [[], buildroot_info, []]
        session.listBuilds.side_effect = [build_info, [], []]

        session.getTag.return_value = self.tag_info
        session.getUser.return_value = self.user_info
        session.getBuild.return_value = build_info[0]

        session.getHost.return_value = self.host_info
        session.getTaskRequest.side_effect = [
            ['path/to/bash-4.4.12-5.fc26.src.rpm', 'fedora26-build', {}],
            [
                'path/to/bash-4.4.12-5.fc26.src.rpm', 2, 'x86_64', True, {
                    'repo_id': 1
                }
            ], [1, 1, False, None, True]
        ]

        session.getTaskChildren.side_effect = [[child_build, child_tag], [],
                                               []]

        expected = """\
Task: 1
Type: build
Request Parameters:
  Source: path/to/bash-4.4.12-5.fc26.src.rpm
  Build Target: fedora26-build
Owner: kojiadmin
State: closed
Created: Thu Jan  1 00:16:40 1970
Started: Thu Jan  1 00:33:20 1970
Finished: Thu Jan  1 00:50:00 1970
Host: kojibuilder
Build: bash-4.4.12-5.fc26 (1)

  Task: 2
  Type: buildArch
  Request Parameters:
    SRPM: /mnt/koji/work/path/to/bash-4.4.12-5.fc26.src.rpm
    Build Tag: fedora26-build
    Build Arch: x86_64
    SRPM Kept: True
    Options:
      repo_id: 1
  Owner: kojiadmin
  State: closed
  Created: Thu Jan  1 00:16:40 1970
  Started: Thu Jan  1 00:33:20 1970
  Finished: Thu Jan  1 00:50:00 1970
  Host: kojibuilder
  Buildroots:
    /var/lib/mock/fedora26-build-1-1/
  Log Files:
    /mnt/koji/work/tasks/2/2/build.log
    /mnt/koji/work/tasks/2/2/hw_info.log
    /mnt/koji/work/tasks/2/2/installed_pkgs.log
    /mnt/koji/work/tasks/2/2/mock_output.log
    /mnt/koji/work/tasks/2/2/root.log
    /mnt/koji/work/tasks/2/2/state.log
  Output:
    /mnt/koji/work/tasks/2/2/bash-4.4.12-5.fc26.src.rpm
    /mnt/koji/work/tasks/2/2/bash-4.4.12-5.fc26.x86_64.rpm
    /mnt/koji/work/tasks/2/2/bash-debuginfo-4.4.12-5.fc26.x86_64.rpm
    /mnt/koji/work/tasks/2/2/bash-doc-4.4.12-5.fc26.x86_64.rpm

  Task: 3
  Type: tagBuild
  Request Parameters:
    Destination Tag: fedora26-build
    Build: bash-4.4.12-5.fc26
  Owner: kojiadmin
  State: closed
  Created: Thu Jan  1 00:16:40 1970
  Started: Thu Jan  1 00:33:20 1970
  Finished: Thu Jan  1 00:50:00 1970
  Host: kojibuilder

"""
        with mock.patch('sys.stdout', new_callable=six.StringIO) as stdout, \
                mock.patch('time.localtime', new=time.gmtime):
            _printTaskInfo(session, 1, '/mnt/koji')
        self.assert_console_message(stdout, expected)
예제 #4
0
    def test_printTaskInfo_create_repo(self, list_task_output_mock):
        session = mock.MagicMock()

        parent = self.task_info_templ.copy()
        parent.update({
            'method': 'newRepo',
            'host_id': None,
        })

        children = self.task_info_templ.copy()
        children.update({
            'id': 2,
            'parent': 1,
            'request': [1, 'x86_64', None],
            'label': 'x86_64',
            'channel_id': 2,
            'host_id': None,
            'method': 'createrepo'
        })

        session.getTaskInfo.side_effect = [parent, children]

        session.listBuildroots.return_value = {}
        session.listBuilds.return_value = {}

        session.getTag.return_value = self.tag_info
        session.getUser.return_value = self.user_info

        session.getTaskRequest.return_value = [1, 'x86_64', None]
        session.getTaskChildren.side_effect = [[children], []]
        task_output = {
            'mergerepos.log': ['DEFAULT'],
            'createrepo.log': ['DEFAULT']
        }
        list_task_output_mock.side_effect = [{}, task_output]
        expected = """\
Task: 1
Type: newRepo
Request Parameters:
  Tag: fedora26-build
Owner: kojiadmin
State: closed
Created: Thu Jan  1 00:16:40 1970
Started: Thu Jan  1 00:33:20 1970
Finished: Thu Jan  1 00:50:00 1970

  Task: 2
  Type: createrepo
  Request Parameters:
    Repo ID: 1
    Arch: x86_64
  Owner: kojiadmin
  State: closed
  Created: Thu Jan  1 00:16:40 1970
  Started: Thu Jan  1 00:33:20 1970
  Finished: Thu Jan  1 00:50:00 1970
  Log Files:
    %s
    %s

""" % tuple('/mnt/koji/work/tasks/2/2/' + k for k in task_output.keys())

        with mock.patch('sys.stdout', new_callable=six.StringIO) as stdout, \
                mock.patch('time.localtime', new=time.gmtime):
            _printTaskInfo(session, 1, '/mnt/koji')
        self.assert_console_message(stdout, expected)
예제 #5
0
    def test_printTaskInfo_build_srpm(self, list_task_output_mock):
        session = mock.MagicMock()

        parent = self.task_info_templ.copy()
        parent.update({
            'method': 'build',
        })

        child_build = parent.copy()
        child_build.update({
            'id': 2,
            'parent': 1,
            'request': ['path/to/bash.src.rpm', 2, 'x86_64', True, {'repo_id': 1}],
            'method': 'buildArch',
        })

        child_tag = parent.copy()
        child_tag.update({
            'id': 3,
            'parent': 1,
            'request': [1, 1, False, None, True],
            'arch': 'noarch',
            'method': 'tagBuild'
        })

        buildroot_info = [{
            'id': 1,
            'repo_id': 1,
            'tag_name': 'fedora26-build',
            'host_name': 'kojibuilder',
        }]

        build_info = [{
            'package_name': 'bash',
            'version': '4.4.12',
            'release': '5.fc26',
            'epoch': None,
            'nvr': 'bash-4.4.12-5.fc26',
            'build_id': 1,
        }]

        files = {
            'bash-debuginfo-4.4.12-5.fc26.x86_64.rpm': ['DEFAULT'],
            'hw_info.log': ['DEFAULT'],
            'build.log': ['DEFAULT'],
            'bash-4.4.12-5.fc26.src.rpm': ['DEFAULT'],
            'root.log': ['DEFAULT'],
            'state.log': ['DEFAULT'],
            'mock_output.log': ['DEFAULT'],
            'bash-4.4.12-5.fc26.x86_64.rpm': ['DEFAULT'],
            'installed_pkgs.log': ['DEFAULT'],
            'bash-doc-4.4.12-5.fc26.x86_64.rpm': ['DEFAULT']
        }

        # need ordered dict to get same results
        files = collections.OrderedDict(sorted(list(files.items()),
                                        key=lambda t: t[0]))

        list_task_output_mock.side_effect = [[], files, {}]

        session.getTaskInfo.side_effect = [parent, child_build, child_tag]
        session.listBuildroots.side_effect = [[], buildroot_info, []]
        session.listBuilds.side_effect = [build_info, [], []]

        session.getTag.return_value = self.tag_info
        session.getUser.return_value = self.user_info
        session.getBuild.return_value = build_info[0]

        session.getHost.return_value = self.host_info
        session.getTaskRequest.side_effect = [
            ['path/to/bash-4.4.12-5.fc26.src.rpm', 'fedora26-build', {}],
            ['path/to/bash-4.4.12-5.fc26.src.rpm', 2, 'x86_64', True, {'repo_id': 1}],
            [1, 1, False, None, True]
        ]

        session.getTaskChildren.side_effect = [[child_build, child_tag], [], []]

        expected = """\
Task: 1
Type: build
Request Parameters:
  Source: path/to/bash-4.4.12-5.fc26.src.rpm
  Build Target: fedora26-build
Owner: kojiadmin
State: closed
Created: Thu Jan  1 00:16:40 1970
Started: Thu Jan  1 00:33:20 1970
Finished: Thu Jan  1 00:50:00 1970
Host: kojibuilder
Build: bash-4.4.12-5.fc26 (1)

  Task: 2
  Type: buildArch
  Request Parameters:
    SRPM: /mnt/koji/work/path/to/bash-4.4.12-5.fc26.src.rpm
    Build Tag: fedora26-build
    Build Arch: x86_64
    SRPM Kept: True
    Options:
      repo_id: 1
  Owner: kojiadmin
  State: closed
  Created: Thu Jan  1 00:16:40 1970
  Started: Thu Jan  1 00:33:20 1970
  Finished: Thu Jan  1 00:50:00 1970
  Host: kojibuilder
  Buildroots:
    /var/lib/mock/fedora26-build-1-1/
  Log Files:
    /mnt/koji/work/tasks/2/2/build.log
    /mnt/koji/work/tasks/2/2/hw_info.log
    /mnt/koji/work/tasks/2/2/installed_pkgs.log
    /mnt/koji/work/tasks/2/2/mock_output.log
    /mnt/koji/work/tasks/2/2/root.log
    /mnt/koji/work/tasks/2/2/state.log
  Output:
    /mnt/koji/work/tasks/2/2/bash-4.4.12-5.fc26.src.rpm
    /mnt/koji/work/tasks/2/2/bash-4.4.12-5.fc26.x86_64.rpm
    /mnt/koji/work/tasks/2/2/bash-debuginfo-4.4.12-5.fc26.x86_64.rpm
    /mnt/koji/work/tasks/2/2/bash-doc-4.4.12-5.fc26.x86_64.rpm

  Task: 3
  Type: tagBuild
  Request Parameters:
    Destination Tag: fedora26-build
    Build: bash-4.4.12-5.fc26
  Owner: kojiadmin
  State: closed
  Created: Thu Jan  1 00:16:40 1970
  Started: Thu Jan  1 00:33:20 1970
  Finished: Thu Jan  1 00:50:00 1970
  Host: kojibuilder

"""
        with mock.patch('sys.stdout', new_callable=six.StringIO) as stdout:
            with mock.patch('time.localtime', new=time.gmtime):
                _printTaskInfo(session, 1, '/mnt/koji')
        self.assert_console_message(stdout, expected)
예제 #6
0
    def test_printTaskInfo_create_repo(self, list_task_output_mock):
        session = mock.MagicMock()

        parent = self.task_info_templ.copy()
        parent.update({
            'method': 'newRepo',
            'host_id': None,
        })

        children = self.task_info_templ.copy()
        children.update({
            'id': 2,
            'parent': 1,
            'request': [1, 'x86_64', None],
            'label': 'x86_64',
            'channel_id': 2,
            'host_id': None,
            'method': 'createrepo'
        })

        session.getTaskInfo.side_effect = [parent, children]

        session.listBuildroots.return_value = {}
        session.listBuilds.return_value = {}

        session.getTag.return_value = self.tag_info
        session.getUser.return_value = self.user_info

        session.getTaskRequest.return_value = [1, 'x86_64', None]
        session.getTaskChildren.side_effect = [[children], []]
        task_output = {
            'mergerepos.log': ['DEFAULT'],
            'createrepo.log': ['DEFAULT']
        }
        list_task_output_mock.side_effect = [
            {},
            task_output
        ]
        expected = """\
Task: 1
Type: newRepo
Request Parameters:
  Tag: fedora26-build
Owner: kojiadmin
State: closed
Created: Thu Jan  1 00:16:40 1970
Started: Thu Jan  1 00:33:20 1970
Finished: Thu Jan  1 00:50:00 1970

  Task: 2
  Type: createrepo
  Request Parameters:
    Repo ID: 1
    Arch: x86_64
  Owner: kojiadmin
  State: closed
  Created: Thu Jan  1 00:16:40 1970
  Started: Thu Jan  1 00:33:20 1970
  Finished: Thu Jan  1 00:50:00 1970
  Log Files:
    %s
    %s

""" % tuple('/mnt/koji/work/tasks/2/2/' + k for k in task_output.keys())

        with mock.patch('sys.stdout', new_callable=six.StringIO) as stdout:
            with mock.patch('time.localtime', new=time.gmtime):
                _printTaskInfo(session, 1, '/mnt/koji')
        self.assert_console_message(stdout, expected)