Exemplo n.º 1
0
def test_download_build_unsupported_build_type(m_write_file,
                                               m_get_koji_session,
                                               m_assert_command):
    """Test download_build_data function for unsupported build types."""
    BUILD_INFO = {
        'task_id': 123,
        'id': 1,
        'source': 'http://some.url',
        'extra': {},
        'state': koji.BUILD_STATES['COMPLETE']
    }
    TASK_INFO = {
        'method': 'randomType'
    }  # I.e. value not present in Analyzer.SUPPORTED_BUILD_TYPES

    m_koji = mock.Mock()
    m_koji.getBuild.return_value = BUILD_INFO
    m_koji.getTaskInfo.return_value = TASK_INFO
    m_get_koji_session.return_value = m_koji

    with pytest.raises(BuildTypeNotSupported):
        utils.download_build_data(1, '/some/path')

    # Assert that the brew calls we expect happened.
    m_koji.getBuild.assert_called_once_with(1)
    m_koji.getTaskInfo.assert_called_once_with(123)
Exemplo n.º 2
0
def test_download_build_data_empty_data(m_write_file, m_get_koji_session,
                                        m_assert_command):
    """Test the download_build_data function with missing data."""
    # Setup for a 'full data' test. The actual values of most return values doesn't matter.
    PATH = '/some/path'
    BUILD_INFO = {'task_id': None}
    RPM_INFO = []
    ARCHIVE_INFO = []

    m_koji = mock.Mock()
    m_koji.getBuild.return_value = BUILD_INFO
    m_koji.getTaskInfo.return_value = None
    m_koji.getMavenBuild.return_value = None
    m_koji.listRPMs.return_value = RPM_INFO
    m_koji.listArchives.return_value = ARCHIVE_INFO
    m_koji.getBuildrootListing.return_value = None
    m_get_koji_session.return_value = m_koji

    utils.download_build_data(1, PATH)

    # Assert that the brew calls we expect happened.
    m_koji.getBuild.assert_called_once_with(1)
    assert m_koji.getTaskInfo.call_count == 0
    m_koji.getMavenBuild.assert_called_once_with(1)
    # One regular and one for the image
    m_koji.listRPMs.assert_called_once_with(1)
    m_koji.listArchives.assert_called_once_with(1)
    assert m_koji.getBuildrootListings.call_count == 0

    # Now assert that only the data we returned was successfully written through to the files.

    assert m_write_file.call_count == 1
    m_write_file.assert_has_calls([
        mock.call(BUILD_INFO, PATH, Analyzer.BUILD_FILE),
    ])
Exemplo n.º 3
0
def test_download_build_invalid_state(m_get_koji_session, m_assert_command):
    """Test download_build_data function for invalid build state."""
    BUILD_INFO = {
        'task_id': 123,
        'id': 1,
        'state': koji.BUILD_STATES['DELETED']
    }

    m_koji = mock.Mock()
    m_koji.getBuild.return_value = BUILD_INFO
    m_get_koji_session.return_value = m_koji

    with pytest.raises(BuildInvalidState):
        utils.download_build_data(1, '/some/path')

    # Assert that the brew calls we expect happened.
    m_koji.getBuild.assert_called_once_with(1)
Exemplo n.º 4
0
def test_download_build_unknown_type(m_write_file, m_get_koji_session,
                                     m_assert_command):
    """Test download_build_data function for build whose type cannot be determined."""
    BUILD_INFO = {
        'id': 1,
        'source': 'http://some.url',
        'extra': {},
        'state': koji.BUILD_STATES['COMPLETE']
    }

    m_koji = mock.Mock()
    m_koji.getBuild.return_value = BUILD_INFO
    m_get_koji_session.return_value = m_koji

    with pytest.raises(BuildTypeNotFound):
        utils.download_build_data(1, '/some/path')

    # Assert that the brew calls we expect happened.
    m_koji.getBuild.assert_called_once_with(1)
Exemplo n.º 5
0
args = parser.parse_args()

# If it's a build ID, we want it typed as an integer. If it's an NVR, then keep it as a string.
try:
    build_identifier = int(args.build_identifier)
except ValueError:
    build_identifier = args.build_identifier

output_dir = args.output_dir or '.'

output_metadata_dir = os.path.join(output_dir, 'metadata')
output_files_dir = os.path.join(output_dir, 'output_files')
output_source_dir = os.path.join(output_dir, 'source')
unpacked_archives_dir = os.path.join(output_dir, 'unpacked_archives')

for directory in (output_metadata_dir, output_files_dir, unpacked_archives_dir,
                  output_source_dir):
    if not os.path.isdir(directory):
        os.mkdir(directory)

utils.download_build_data(build_identifier, output_metadata_dir)
artifacts, build_info = utils.download_build(build_identifier,
                                             output_files_dir)
utils.download_source(build_info, output_source_dir)
utils.unpack_artifacts(artifacts, unpacked_archives_dir)

log.info(f'See the downloaded brew metadata at {output_metadata_dir}')
log.info(f'See the downloaded archives at {output_files_dir}')
log.info(f'See the downloaded source at {output_source_dir}')
log.info(f'See the unpacked archives at {unpacked_archives_dir}')
Exemplo n.º 6
0
def test_download_build_data_full_data(m_write_file, m_get_koji_session,
                                       m_assert_command):
    """Test the download_build_data function with all available data."""
    # Setup for a 'full data' test. The actual values of most return values doesn't matter.
    PATH = '/some/path'
    BUILD_INFO = {
        'task_id': 2,
        'id': 1,
        'state': koji.BUILD_STATES['COMPLETE']
    }
    TASK_INFO = {'a task': 5, 'method': 'build'}
    URL = 'git+https://example.com/whatever'
    TASK_REQUEST = [URL]
    MAVEN_INFO = {'other': 'stuff'}
    RPM_INFO = [{'buildroot_id': '2'}, {'buildroot_id': '3'}]
    ARCHIVE_INFO = [{
        'buildroot_id': '3',
        'id': '1'
    }, {
        'buildroot_id': '4',
        'id': '2',
        'btype': 'image'
    }]
    BUILDROOT_LISTING = [{'rpm_id': 1}, {'rpm_id': 2}]
    BUILDROOT_INFO = [[RPM_INFO[0]], [RPM_INFO[1]]]

    m_koji = mock.Mock()
    m_koji.getBuild.return_value = BUILD_INFO
    m_koji.getTaskInfo.return_value = TASK_INFO
    m_koji.getTaskRequest.return_value = TASK_REQUEST
    m_koji.getMavenBuild.return_value = MAVEN_INFO
    m_koji.listRPMs.return_value = RPM_INFO
    m_koji.listArchives.return_value = ARCHIVE_INFO
    m_koji.getBuildrootListing.return_value = BUILDROOT_LISTING
    m_koji.multiCall.return_value = BUILDROOT_INFO
    m_get_koji_session.return_value = m_koji

    utils.download_build_data(1, PATH)

    # Assert that the brew calls we expect happened.
    m_koji.getBuild.assert_called_once_with(1)
    m_koji.getTaskInfo.assert_called_once_with(2)
    m_koji.getTaskRequest.assert_called_once_with(2)
    m_koji.getMavenBuild.assert_called_once_with(1)
    # One regular and one for the image
    assert m_koji.listRPMs.call_count == 2
    m_koji.listRPMs.assert_has_calls([
        mock.call(1),
        mock.call(imageID='2'),
    ])
    m_koji.listArchives.assert_called_once_with(1)
    assert m_koji.getBuildrootListing.call_count == 3
    m_koji.getBuildrootListing.assert_has_calls([
        mock.call('2'),
        mock.call('3'),
        mock.call('4'),
    ])

    # Now assert that the data we returned was successfully written through to the files.
    # Since the second Archive is an image we expect to call listRPMs for that image
    # and write it to IMAGE_RPM_FILE.
    IMAGE_INFO = {'2': RPM_INFO}
    # The buildroot info should be repeated for each buildroot.
    ALL_BUILDROOT_INFO = {'2': RPM_INFO, '3': RPM_INFO, '4': RPM_INFO}
    # The build type was added
    BUILD_INFO['type'] = 'build'

    assert m_write_file.call_count == 7
    m_write_file.assert_has_calls([
        mock.call(TASK_INFO, PATH, Analyzer.TASK_FILE),
        mock.call(BUILD_INFO, PATH, Analyzer.BUILD_FILE),
        mock.call(MAVEN_INFO, PATH, Analyzer.MAVEN_FILE),
        mock.call(RPM_INFO, PATH, Analyzer.RPM_FILE),
        mock.call(ARCHIVE_INFO, PATH, Analyzer.ARCHIVE_FILE),
        mock.call(IMAGE_INFO, PATH, Analyzer.IMAGE_RPM_FILE),
        mock.call(ALL_BUILDROOT_INFO, PATH, Analyzer.BUILDROOT_FILE),
    ])
Exemplo n.º 7
0
def test_download_build_data_full_data(m_write_file, m_get_koji_session,
                                       m_assert_command):
    """Test the download_build_data function with all available data."""
    # Setup for a 'full data' test. The actual values of most return values doesn't matter.
    PATH = '/some/path'
    BUILD_INFO = {'task_id': 2}
    TASK_INFO = {'a task': 5}
    MAVEN_INFO = {'other': 'stuff'}
    RPM_INFO = [{'buildroot_id': '2'}, {'buildroot_id': '3'}]
    ARCHIVE_INFO = [{
        'buildroot_id': '3',
        'id': '1'
    }, {
        'buildroot_id': '4',
        'id': '2',
        'btype': 'image'
    }]
    BUILDROOT_INFO = {'a buldroot': 'ok'}

    m_koji = mock.Mock()
    m_koji.getBuild.return_value = BUILD_INFO
    m_koji.getTaskInfo.return_value = TASK_INFO
    m_koji.getMavenBuild.return_value = MAVEN_INFO
    m_koji.listRPMs.return_value = RPM_INFO
    m_koji.listArchives.return_value = ARCHIVE_INFO
    m_koji.getBuildrootListing.return_value = BUILDROOT_INFO
    m_get_koji_session.return_value = m_koji

    utils.download_build_data(1, PATH)

    # Assert that the brew calls we expect happened.
    m_koji.getBuild.assert_called_once_with(1)
    m_koji.getTaskInfo.assert_called_once_with(2)
    m_koji.getMavenBuild.assert_called_once_with(1)
    # One regular and one for the image
    assert m_koji.listRPMs.call_count == 2
    m_koji.listRPMs.assert_has_calls([
        mock.call(1),
        mock.call(imageID='2'),
    ])
    m_koji.listArchives.assert_called_once_with(1)
    assert m_koji.getBuildrootListing.call_count == 3
    m_koji.getBuildrootListing.assert_has_calls([
        mock.call('2'),
        mock.call('3'),
        mock.call('4'),
    ])

    # Now assert that the data we returned was successfully written through to the files.
    # Since the second Archive is an image we expect to call listRPMs for that image
    # and write it to IMAGE_RPM_FILE.
    IMAGE_INFO = {'2': RPM_INFO}
    # The buildroot info should be repeated for each buildroot.
    ALL_BUILDROOT_INFO = {
        '2': BUILDROOT_INFO,
        '3': BUILDROOT_INFO,
        '4': BUILDROOT_INFO
    }

    assert m_write_file.call_count == 7
    m_write_file.assert_has_calls([
        mock.call(BUILD_INFO, PATH, Analyzer.BUILD_FILE),
        mock.call(TASK_INFO, PATH, Analyzer.TASK_FILE),
        mock.call(MAVEN_INFO, PATH, Analyzer.MAVEN_FILE),
        mock.call(RPM_INFO, PATH, Analyzer.RPM_FILE),
        mock.call(ARCHIVE_INFO, PATH, Analyzer.ARCHIVE_FILE),
        mock.call(IMAGE_INFO, PATH, Analyzer.IMAGE_RPM_FILE),
        mock.call(ALL_BUILDROOT_INFO, PATH, Analyzer.BUILDROOT_FILE),
    ])