diff --git a/.gitignore b/.gitignore index 60186579..f1f27dc0 100644 --- a/.gitignore +++ b/.gitignore @@ -15,7 +15,6 @@ module_build_service.db server.crt server.key test_module_build_service.db -tests/vcr-request-data .vscode .ropeproject tests/test_module_build_service.db-journal diff --git a/MANIFEST.in b/MANIFEST.in index 98c05e46..e81de03f 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -8,5 +8,4 @@ recursive-include docs *.txt *.rst *.md recursive-include module_build_service * recursive-include fedmsg.d * recursive-include tests *.yaml *.json -recursive-include tests/vcr-request-data * recursive-include tests/scm_data * diff --git a/module_build_service/scheduler/handlers/modules.py b/module_build_service/scheduler/handlers/modules.py index 9d54b07e..3d4b1313 100644 --- a/module_build_service/scheduler/handlers/modules.py +++ b/module_build_service/scheduler/handlers/modules.py @@ -213,8 +213,7 @@ def wait(config, session, msg): on failure. """ cg_build_koji_tag = conf.koji_cg_default_build_tag - - if conf.system != "koji": + if conf.system not in ['koji', 'test']: # In case of non-koji backend, we want to get the dependencies # of the local module build based on ModuleMetadata, because the # local build is not stored in PDC and therefore we cannot query diff --git a/test-requirements.txt b/test-requirements.txt index 0f6e5d48..cee7b025 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -3,6 +3,5 @@ copr mock pytest -vcrpy flake8 tox diff --git a/tests/__init__.py b/tests/__init__.py index 9a5dbd46..b47914d3 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -21,16 +21,16 @@ # Written by Matt Prahl +import os +import math +import copy + +import six +import pytest +import mock +import pdc_client.test_helpers +import modulemd + + +BASE_DIR = os.path.dirname(__file__) +STAGED_DATA_DIR = os.path.join(BASE_DIR, 'staged_data') +with open(os.path.join(STAGED_DATA_DIR, 'platform.yaml')) as f: + PLATFORM_MODULEMD = f.read() +with open(os.path.join(STAGED_DATA_DIR, 'formatted_testmodule.yaml')) as f: + TESTMODULE_MODULEMD = f.read() + + +class MockPDCFilterAPI(pdc_client.test_helpers.MockAPI): + """ A modified pdc_client.test_helpers.MockAPI that supports basic filtering on GET requests + """ + def _handle_get(self, filters): + # Code taken from pdc_client/test_helpers.py + data = self.endpoints[self.will_call]['GET'] + if callable(data): + data = data() + self.calls.setdefault(self.will_call, []).append(('GET', filters)) + page_size = filters.get('page_size', 20) + # End of code taken from pdc_client/test_helpers.py + + if not (isinstance(data, list) and page_size > 0): + return data + + # Keep track of indexes to pop since we can't pop them during the loop + indexes_to_pop = [] + for index, result in enumerate(data): + for filter_key, filter_value in filters.items(): + if filter_key in ('page', 'page_size'): + continue + if filter_key not in result: + raise ValueError('An unsupported filter was specified') + # If it's a string, do a case insensitive match like the API does + if isinstance(filter_value, six.string_types) and \ + isinstance(result[filter_key], six.string_types): + if result[filter_key].lower() != filter_value.lower(): + indexes_to_pop.append(index) + break + else: + if result[filter_key] != filter_value: + indexes_to_pop.append(index) + break + # Only copy the data if we need to modify it based on the filters + if indexes_to_pop: + rv_data = copy.deepcopy(data) + else: + rv_data = data + # Remove all the results that didn't match the filter. This is reversed so the index + # values remain valid as we pop them. + for index in sorted(indexes_to_pop, reverse=True): + rv_data.pop(index) + + # Code taken from pdc_client/test_helpers.py + page = filters.get('page', 1) + pages = int(math.ceil(float(len(rv_data)) / page_size)) + rv_data = rv_data[(page - 1) * page_size:(page - 1) * page_size + page_size] + return { + 'count': len(rv_data), + 'next': None if (page == pages or not pages) else self._fmt_url(page + 1), + 'previous': None if (page == 1 or not pages) else self._fmt_url(page - 1), + 'results': rv_data + } + # End of code taken from pdc_client/test_helpers.py + + +# This is scoped to the function in case certain tests must alter PDC +@pytest.fixture +def pdc(): + # Mock the PDC client + pdc = MockPDCFilterAPI() + # TODO: change this to the modules API when PDC > 1.9.0 is released + pdc.add_endpoint('unreleasedvariants', 'GET', [{ + 'variant_id': 'platform', + 'variant_uid': 'platform-f28-3', + 'variant_name': 'platform', + 'variant_type': 'module', + 'variant_version': 'f28', + 'variant_release': '3', + 'variant_context': '00000000', + 'koji_tag': 'module-f28-build', + 'modulemd': PLATFORM_MODULEMD, + 'runtime_deps': [], + 'build_deps': [], + 'active': True, + 'rpms': [] + }]) + pdc_patcher = mock.patch('pdc_client.PDCClient', return_value=pdc) + pdc_patcher.start() + yield pdc + pdc_patcher.stop() + + +@pytest.fixture(scope='function') +def pdc_module_inactive(pdc): + pdc.endpoints['unreleasedvariants']['GET'].append({ + 'variant_id': 'testmodule', + 'variant_uid': 'testmodule:master:20180205135154', + 'variant_name': 'testmodule', + 'variant_type': 'module', + 'variant_version': 'master', + 'variant_release': '20180205135154', + 'koji_tag': 'module-95b214a704c984be', + 'modulemd': TESTMODULE_MODULEMD, + 'runtime_deps': [ + { + 'dependency': 'platform', + 'stream': 'f28' + } + ], + 'build_deps': [ + { + 'dependency': 'platform', + 'stream': 'f28' + } + ], + 'rpms': [], + 'active': False, + }) + return pdc + + +@pytest.fixture(scope='function') +def pdc_module_active(pdc_module_inactive): + # Rename it for clarity + pdc_module_active = pdc_module_inactive + pdc_module_active.endpoints['unreleasedvariants']['GET'][-1].update({ + 'active': True, + 'rpms': [ + 'tangerine-0:0.22-6.module+0+814cfa39.noarch.rpm', + 'tangerine-0:0.22-6.module+0+814cfa39.src.rpm', + 'perl-Tangerine-0:0.22-2.module+0+814cfa39.noarch.rpm', + 'perl-Tangerine-0:0.22-2.module+0+814cfa39.src.rpm', + 'perl-List-Compare-0:0.53-8.module+0+814cfa39.noarch.rpm', + 'perl-List-Compare-0:0.53-8.module+0+814cfa39.src.rpm' + ] + }) + return pdc_module_active + + +@pytest.fixture(scope='function') +def pdc_module_reuse(pdc_module_active): + # Rename it for clarity + pdc_module_reuse = pdc_module_active + mmd = modulemd.ModuleMetadata() + mmd.loads(TESTMODULE_MODULEMD) + mmd.version = 20170219191323 + mmd.xmd['mbs']['scmurl'] = 'git://pkgs.stg.fedoraproject.org/modules/testmodule.git?#ff1ea79' + mmd.xmd['mbs']['commit'] = 'ff1ea79fc952143efeed1851aa0aa006559239ba' + pdc_module_reuse.endpoints['unreleasedvariants']['GET'].append( + copy.deepcopy(pdc_module_reuse.endpoints['unreleasedvariants']['GET'][-1])) + pdc_module_reuse.endpoints['unreleasedvariants']['GET'][-1].update({ + 'variant_uid': 'testmodule:master:{0}'.format(mmd.version), + 'variant_release': str(mmd.version), + 'modulemd': mmd.dumps(), + 'koji_tag': 'module-de3adf79caf3e1b8' + }) + mmd.version = 20180205135154 + mmd.xmd['mbs']['scmurl'] = 'git://pkgs.stg.fedoraproject.org/modules/testmodule.git?#55f4a0a' + mmd.xmd['mbs']['commit'] = '55f4a0a2e6cc255c88712a905157ab39315b8fd8' + pdc_module_reuse.endpoints['unreleasedvariants']['GET'].append( + copy.deepcopy(pdc_module_reuse.endpoints['unreleasedvariants']['GET'][-1])) + pdc_module_reuse.endpoints['unreleasedvariants']['GET'][-1].update({ + 'variant_uid': 'testmodule:master:{0}'.format(mmd.version), + 'variant_release': str(mmd.version), + 'modulemd': mmd.dumps(), + 'koji_tag': 'module-fe3adf73caf3e1b7', + 'rpms': [], + 'active': False + }) + return pdc_module_reuse diff --git a/tests/staged_data/base-runtime.yaml b/tests/staged_data/base-runtime.yaml deleted file mode 100644 index a1ef7124..00000000 --- a/tests/staged_data/base-runtime.yaml +++ /dev/null @@ -1,181 +0,0 @@ -document: modulemd -version: 1 -data: - name: base-runtime - stream: "0.25" - version: 1 - summary: The base application runtime and hardware enablement layer - description: > - A project closely linked to the Modularity Initiative, base-runtime - is about the defining the common shared package and feature set of - the operating system, providing both the hardware enablement layer - and the minimal application runtime environment other modules can - build upon. - license: - module: [ MIT ] - dependencies: - # Build-require self for now. - # TODO: Don't forget to update this once we're no longer self-hosted - buildrequires: - base-runtime: "0.25" - references: - community: https://fedoraproject.org/wiki/BaseRuntime - documentation: https://pagure.io/base-runtime - tracker: https://pagure.io/base-runtime/issues - profiles: - # The default profile currently consists of the Linux kernel, the - # systemd init system and all the POSIX userspace utilities that - # are available in Fedora. - default: - rpms: - # at, batch - - at - # sh - - bash - # bc - - bc - # ar, nm, strings, strip - - binutils - # yacc - - byacc - # cflow - - cflow - # basename, cat, chgrp, chmod, chown, cksum, comm, cp, csplit, - # cut, date, dd, df, dirname, du, echo, env, expand, expr, - # false, fold, head, id, join, link, ln, logname, ls, mkdir, - # mkfifo, mv, nice, nl, nohup, od, paste, pathchk, pr, printf, - # pwd, rm, rmdir, sleep, sort, split, stty, talk, tee, test, - # touch, tr, true, tsort, tty, uname, unexpand, uniq, unlink, - # wc, who - - coreutils - # crontab - - cronie - # ctags - - ctags - # lp - - cups-client - # cmp, diff - - diffutils - # ed - - ed - # file - - file - # flex - - flex - # find, xargs - - findutils - # awk - - gawk - # cc, c89, c99 - - gcc - # f95, gfortran - - gcc-gfortran - # gencat, getconf, iconv, locale, localedef - - glibc-common - # grep - - grep - # zcat - - gzip - # the Linux kernel - - kernel - # m4 - - m4 - # mailx - - mailx - # make - - make - # man - - man-db - # compress, uncompress - - ncompress - # tabs, tput - - ncurses - # patch - - patch - # fuser - - psmisc - # ps - - procps-ng - # sed - - sed - # newgrp - - shadow-utils - # uudecode, uuencode - - sharutils - # pax - - spax - # the chosen init system - - systemd - # talk - - talk - # time - - time - # qmove, qmsg, qrerun, qsig - - torque-client - # cal, ipcrm, ipcs, kill, logger, mesg, more, renice, write - - util-linux - # uucp, uustat, uux - - uucp - # ex, vi - - vim-minimal - api: - rpms: - - at - - bash - - bc - - binutils - - byacc - - cflow - - coreutils - - cronie - - ctags - - cups-client - - diffutils - - ed - - file - - flex - - findutils - - gawk - - gcc - - gcc-gfortran - - glibc-common - - grep - - gzip - - kernel - - m4 - - mailx - - make - - man-db - - ncompress - - ncurses - - patch - - psmisc - - procps-ng - - sed - - shadow-utils - - sharutils - - spax - - systemd - - talk - - time - - torque-client - - util-linux - - uucp - - vim-minimal - components: - rpms: - CUnit2: - rationale: Part of the first base-runtime prototype. - ref: 2fb6e8f0529a1196a4bd0897e9bfcd93719e686c - Canna: - rationale: Part of the first base-runtime prototype. - ref: 8d636177ba858cfabf02df029b2089cf192d683e - Cython: - rationale: Part of the first base-runtime prototype. - ref: 6c9d7cad8ac0a840b18b495c4fe152967d808600 - DevIL: - rationale: Part of the first base-runtime prototype. - ref: de58614c0febb5032b710739f34f7344679668f6 - GConf2: - rationale: Part of the first base-runtime prototype. - ref: a13087720a27b17b61bd0a1cbd6042a1d0ab98b7 diff --git a/tests/staged_data/formatted_python3-no-components.yaml b/tests/staged_data/formatted_python3-no-components.yaml new file mode 100644 index 00000000..104d63cc --- /dev/null +++ b/tests/staged_data/formatted_python3-no-components.yaml @@ -0,0 +1,53 @@ +# This module is left empty because python3 is contained in the +# Platform module. + +# Other modules can depend on this empty one so that, when the +# implementation of python3 is moved out of the Platform module, +# other modules should not be affected. + +document: modulemd +version: 1 +data: + summary: Python programming language, version 3 + description: >- + Python is an interpreted, interactive, object-oriented programming + language often compared to Tcl, Perl, Scheme or Java. Python includes + modules, classes, exceptions, very high level dynamic data types + and dynamic typing. Python supports interfaces to many system calls and + libraries, as well as to various windowing systems (X11, Motif, Tk, + Mac and MFC). + + Programmers can write new built-in modules for Python in C or C++. + Python can be used as an extension language for applications that + need a programmable interface. + license: + module: + - MIT + dependencies: + buildrequires: + platform: f28 + requires: + platform: f28 + references: + community: https://www.python.org/ + documentation: https://docs.python.org/3/ + tracker: https://src.fedoraproject.org/modules/python3 + xmd: + mbs: + buildrequires: + platform: + filtered_rpms: [] + ref: virtual + stream: f28 + version: '3' + commit: 620ec77321b2ea7b0d67d82992dda3e1d67055b4 + requires: + platform: + filtered_rpms: [] + ref: virtual + stream: f28 + version: '3' + rpms: + ed: + ref: 51f529a5cde2b843ed9c7870689d707eaab3a9d1 + scmurl: https://src.fedoraproject.org/modules/testmodule.git?#620ec77321b2ea7b0d67d82992dda3e1d67055b4 diff --git a/tests/staged_data/formatted_starcommand.yaml b/tests/staged_data/formatted_starcommand.yaml deleted file mode 100644 index 59c3dbc4..00000000 --- a/tests/staged_data/formatted_starcommand.yaml +++ /dev/null @@ -1,38 +0,0 @@ -document: modulemd -version: 1 -data: - summary: Buzz Lightyear's Star Command Communicator - description: Buzz Lightyear's Star Command Communicator - name: starcommand - stream: teststream - version: 1 - license: - module: [ MIT ] - dependencies: - buildrequires: - base-runtime: master - requires: - base-runtime: master - xmd: - mbs: - buildrequires: {base-runtime: {ref: ae993ba84f4bce554471382ccba917ef16265f11, stream: master, version: '20170315134803', 'filtered_rpms': []}} - requires: {base-runtime: {ref: ae993ba84f4bce554471382ccba917ef16265f11, stream: master, version: '20170315134803', 'filtered_rpms': []}} - commit: 7fea453bc362cc8e5aa41e129e689baea853653d - scmurl: git://pkgs.stg.fedoraproject.org/modules/starcommand.git?#7fea453 - references: - community: https://fedoraproject.org/wiki/Modularity - documentation: https://fedoraproject.org/wiki/Fedora_Packaging_Guidelines_for_Modules - tracker: https://taiga.fedorainfracloud.org/project/modularity - profiles: - default: - rpms: - - communicator - api: - rpms: - - communicator - components: - rpms: - communicator: - rationale: Provides the API for this module. - buildorder: 10 - ref: f25 diff --git a/tests/staged_data/formatted_testmodule-more-components.yaml b/tests/staged_data/formatted_testmodule-more-components.yaml new file mode 100644 index 00000000..0256f36c --- /dev/null +++ b/tests/staged_data/formatted_testmodule-more-components.yaml @@ -0,0 +1,60 @@ +document: modulemd +version: 1 +data: + name: testmodule-more-components + stream: master + version: 20180205135154 + context: c2c572ec + summary: A test module in all its beautiful beauty + description: This module demonstrates how to write simple modulemd files And can + be used for testing the build and release pipeline. + license: + module: + - MIT + dependencies: + buildrequires: + platform: f28 + requires: + platform: f28 + references: + community: https://docs.pagure.org/modularity/ + documentation: https://fedoraproject.org/wiki/Fedora_Packaging_Guidelines_for_Modules + xmd: + mbs: + buildrequires: + platform: + filtered_rpms: [] + ref: virtual + stream: f28 + version: '3' + commit: 620ec77321b2ea7b0d67d82992dda3e1d67055b4 + requires: + platform: + filtered_rpms: [] + ref: virtual + stream: f28 + version: '3' + rpms: + ed: + ref: 51f529a5cde2b843ed9c7870689d707eaab3a9d1 + mksh: + ref: c7df9926cbe7bd8ffbd0ed35108814d7e037d1e3 + ed2: + ref: 61f529a5cde2b843ed9c7870689d707eaab3a9d1 + mksh2: + ref: d7df9926cbe7bd8ffbd0ed35108814d7e037d1e3 + scmurl: https://src.fedoraproject.org/modules/testmodule.git?#620ec77321b2ea7b0d67d82992dda3e1d67055b4 + components: + rpms: + perl-List-Compare: + rationale: A dependency of tangerine. + ref: f25 + perl-Tangerine: + rationale: Provides API for this module and is a dependency of tangerine. + ref: f25 + perl-List-Compare1: + rationale: A dependency of tangerine. + ref: f25 + perl-Tangerine1: + rationale: Provides API for this module and is a dependency of tangerine. + ref: f25 diff --git a/tests/staged_data/formatted_testmodule.yaml b/tests/staged_data/formatted_testmodule.yaml index 69da9f83..34dbc153 100644 --- a/tests/staged_data/formatted_testmodule.yaml +++ b/tests/staged_data/formatted_testmodule.yaml @@ -1,39 +1,70 @@ -data: - api: - rpms: [tangerine, perl-Tangerine] - components: - rpms: - perl-List-Compare: {cache: 'http://pkgs.fedoraproject.org/repo/pkgs/perl-List-Compare', - rationale: A dependency of tangerine., ref: 76f9d8c8e87eed0aab91034b01d3d5ff6bd5b4cb, - repository: 'git://pkgs.fedoraproject.org/rpms/perl-List-Compare'} - perl-Tangerine: {cache: 'http://pkgs.fedoraproject.org/repo/pkgs/perl-Tangerine', - rationale: Provides API for this module and is a dependency of tangerine., - ref: 4ceea43add2366d8b8c5a622a2fb563b625b9abf, repository: 'git://pkgs.fedoraproject.org/rpms/perl-Tangerine'} - tangerine: {buildorder: 10, cache: 'http://pkgs.fedoraproject.org/repo/pkgs/tangerine', - rationale: Provides API for this module., ref: fbed359411a1baa08d4a88e0d12d426fbf8f602c, - repository: 'git://pkgs.fedoraproject.org/rpms/tangerine'} - dependencies: - buildrequires: {base-runtime: master} - requires: {base-runtime: master} - description: This module demonstrates how to write simple modulemd files And can - be used for testing the build and release pipeline. - filter: {} - license: - module: [MIT] - name: testmodule - profiles: - default: - rpms: [tangerine] - references: {community: 'https://fedoraproject.org/wiki/Modularity', documentation: 'https://fedoraproject.org/wiki/Fedora_Packaging_Guidelines_for_Modules', - tracker: 'https://taiga.fedorainfracloud.org/project/modularity'} - stream: master - summary: A test module in all its beautiful beauty - version: 20170109091357 - xmd: - mbs: - buildrequires: {base-runtime: {ref: ae993ba84f4bce554471382ccba917ef16265f11, stream: master, version: 20170315134803, 'filtered_rpms': []}} - requires: {base-runtime: {ref: ae993ba84f4bce554471382ccba917ef16265f11, stream: master, version: 20170315134803, 'filtered_rpms': []}} - commit: 7fea453bc362cc8e5aa41e129e689baea853653d - scmurl: git://pkgs.stg.fedoraproject.org/modules/testmodule.git?#7fea453 document: modulemd version: 1 +data: + name: testmodule + stream: master + version: 20180205135154 + context: c2c572ec + summary: A test module in all its beautiful beauty + description: This module demonstrates how to write simple modulemd files And can + be used for testing the build and release pipeline. + license: + module: + - MIT + dependencies: + buildrequires: + platform: f28 + requires: + platform: f28 + references: + community: https://docs.pagure.org/modularity/ + documentation: https://fedoraproject.org/wiki/Fedora_Packaging_Guidelines_for_Modules + xmd: + mbs: + buildrequires: + platform: + filtered_rpms: [] + ref: virtual + stream: f28 + version: '3' + commit: 65a7721ee4eff44d2a63fb8f3a8da6e944ab7f4d + requires: + platform: + filtered_rpms: [] + ref: virtual + stream: f28 + version: '3' + rpms: + perl-List-Compare: + ref: ac0f3bccca9dcb8465c434ac4c38974bf6205c28 + perl-Tangerine: + ref: 7e96446223f1ad84a26c7cf23d6591cd9f6326c6 + tangerine: + ref: c0f9a7dbd8cf823a2bdc19eeeed20d22b0aa52bf + scmurl: https://src.fedoraproject.org/modules/testmodule.git?#65a7721ee4eff44d2a63fb8f3a8da6e944ab7f4d + profiles: + default: + rpms: + - tangerine + api: + rpms: + - perl-Tangerine + - tangerine + components: + rpms: + perl-List-Compare: + rationale: A dependency of tangerine. + repository: git://pkgs.fedoraproject.org/rpms/perl-List-Compare + ref: master + cache: http://pkgs.fedoraproject.org/repo/pkgs/perl-List-Compare + tangerine: + rationale: Provides API for this module. + buildorder: 10 + repository: git://pkgs.fedoraproject.org/rpms/tangerine + ref: master + cache: http://pkgs.fedoraproject.org/repo/pkgs/tangerine + perl-Tangerine: + rationale: Provides API for this module and is a dependency of tangerine. + repository: git://pkgs.fedoraproject.org/rpms/perl-Tangerine + ref: master + cache: http://pkgs.fedoraproject.org/repo/pkgs/perl-Tangerine diff --git a/tests/staged_data/includedmodules.yaml b/tests/staged_data/includedmodules.yaml index 5d270a25..e0f79e25 100644 --- a/tests/staged_data/includedmodules.yaml +++ b/tests/staged_data/includedmodules.yaml @@ -21,12 +21,12 @@ data: components: rpms: file: - rationale: It's here to test the whole thing! + rationale: file ref: 70fa7516b83768595a4f3280ae890a7ac957e0c7 buildorder: 10 - ed: - rationale: ed - ref: 123 + foo: + rationale: foo + ref: 80fa7516b83768595b4f3280ae890a7ac957e0c8 modules: fakemodule: rationale: foobar diff --git a/tests/staged_data/local_builds/module-base-runtime-master-20170816080815/results/modules.yaml b/tests/staged_data/local_builds/module-base-runtime-master-20170816080815/results/modules.yaml deleted file mode 100644 index 47364194..00000000 --- a/tests/staged_data/local_builds/module-base-runtime-master-20170816080815/results/modules.yaml +++ /dev/null @@ -1,44 +0,0 @@ ---- -data: - api: - rpms: [ed, mksh] - artifacts: - rpms: [ed-debuginfo-1.14.1-4.module_92fc48de.x86_64, ed-1.14.1-4.module_92fc48de.x86_64, - module-build-macros-0.1-1.module_92fc48de.src, module-build-macros-0.1-1.module_92fc48de.noarch, - ed-1.14.1-4.module_92fc48de.src] - components: - rpms: - ed: {cache: 'http://pkgs.fedoraproject.org/repo/pkgs/ed', rationale: A build - dependency of mksh., ref: master, repository: 'git://pkgs.fedoraproject.org/rpms/ed'} - dependencies: - buildrequires: {base-runtime: master} - requires: {base-runtime: master} - description: This module demonstrates how to write simple modulemd files And can - be used for testing the build and release pipeline. - license: - module: [MIT] - name: base-runtime - profiles: - default: - rpms: [mksh] - buildroot: - rpms: - - foo - srpm-buildroot: - rpms: - - bar - references: {community: 'https://docs.pagure.org/modularity/', documentation: 'https://fedoraproject.org/wiki/Fedora_Packaging_Guidelines_for_Modules'} - stream: master - summary: A test module in all its beautiful beauty - version: 20170816080815 - xmd: - mbs: - buildrequires: - base-runtime: {ref: 147dca4ca65aa9a1ac51f71b7e687f9178ffa5df, stream: master, - version: '20170616125652'} - commit: 722fd739fd6cf66faf29f6fb95dd64f60ba3e39a - rpms: - ed: {ref: 01bf8330812fea798671925cc537f2f29b0bd216} - scmurl: file:///home/hanzz/modules/testmodule/ -document: modulemd -version: 1 diff --git a/tests/staged_data/local_builds/module-parent-master-20170816080815/results/modules.yaml b/tests/staged_data/local_builds/module-parent-master-20170816080815/results/modules.yaml index 8ff55921..8a8dabd5 100644 --- a/tests/staged_data/local_builds/module-parent-master-20170816080815/results/modules.yaml +++ b/tests/staged_data/local_builds/module-parent-master-20170816080815/results/modules.yaml @@ -12,7 +12,7 @@ data: dependency of mksh., ref: master, repository: 'git://pkgs.fedoraproject.org/rpms/ed'} dependencies: buildrequires: {testmodule: master} - requires: {base-runtime: master} + requires: {platform: f28} description: This module demonstrates how to write simple modulemd files And can be used for testing the build and release pipeline. license: @@ -31,8 +31,7 @@ data: testmodule: {ref: 147dca4ca65aa9a1ac51f71b7e687f9178ffa5df, stream: master, version: '20170616125652'} requires: - base-runtime: {ref: 147dca4ca65aa9a1ac51f71b7e687f9178ffa5df, stream: master, - version: '20170616125652'} + platform: {ref: virtual, stream: f28, version: '3'} commit: 722fd739fd6cf66faf29f6fb95dd64f60ba3e39a rpms: ed: {ref: 01bf8330812fea798671925cc537f2f29b0bd216} diff --git a/tests/staged_data/local_builds/module-platform-f28-3/results/modules.yaml b/tests/staged_data/local_builds/module-platform-f28-3/results/modules.yaml new file mode 100644 index 00000000..309e65ab --- /dev/null +++ b/tests/staged_data/local_builds/module-platform-f28-3/results/modules.yaml @@ -0,0 +1,53 @@ +--- +data: + api: + rpms: [ed, mksh] + artifacts: + rpms: ['ed-debuginfo-0:1.14.2-1.module_1+df67fa84.x86_64', 'ed-0:1.14.2-1.module_1+df67fa84.x86_64', + 'ed-debugsource-0:1.14.2-1.module_1+df67fa84.x86_64', 'ed-0:1.14.2-1.module_1+df67fa84.src', + 'mksh-debugsource-0:56c-1.module_1+df67fa84.x86_64', 'mksh-0:56c-1.module_1+df67fa84.x86_64', + 'mksh-debuginfo-0:56c-1.module_1+df67fa84.x86_64', 'mksh-0:56c-1.module_1+df67fa84.src', + 'module-build-macros-0.1-1.module_1+df67fa84.src', 'module-build-macros-0.1-1.module_1+df67fa84.noarch'] + components: + rpms: + ed: + rationale: A build dependency of mksh, to test buildorder. + repository: git://pkgs.fedoraproject.org/rpms/ed + ref: master + cache: http://pkgs.fedoraproject.org/repo/pkgs/ed + mksh: + rationale: The main component of this module. + buildorder: 1 + repository: git://pkgs.fedoraproject.org/rpms/mksh + ref: master + cache: http://pkgs.fedoraproject.org/repo/pkgs/mksh + dependencies: + buildrequires: {} + requires: {} + description: Fedora 28 traditional base + license: + module: [MIT] + name: platform + profiles: + default: + rpms: [mksh] + buildroot: + rpms: + - foo + srpm-buildroot: + rpms: + - bar + references: {community: 'https://docs.pagure.org/modularity/', documentation: 'https://fedoraproject.org/wiki/Fedora_Packaging_Guidelines_for_Modules'} + stream: f28 + summary: A test module in all its beautiful beauty + version: 3 + xmd: + mbs: + buildrequires: + platform: {} + commit: virtual + rpms: + ed: {} + scmurl: file:///home/hanzz/modules/testmodule/ +document: modulemd +version: 1 diff --git a/tests/staged_data/local_builds/module-testmodule-master-20170816080815/results/modules.yaml b/tests/staged_data/local_builds/module-testmodule-master-20170816080815/results/modules.yaml index 5de93ebd..3d21a268 100644 --- a/tests/staged_data/local_builds/module-testmodule-master-20170816080815/results/modules.yaml +++ b/tests/staged_data/local_builds/module-testmodule-master-20170816080815/results/modules.yaml @@ -11,8 +11,8 @@ data: ed: {cache: 'http://pkgs.fedoraproject.org/repo/pkgs/ed', rationale: A build dependency of mksh., ref: master, repository: 'git://pkgs.fedoraproject.org/rpms/ed'} dependencies: - buildrequires: {base-runtime: master} - requires: {base-runtime: master} + buildrequires: {platform: f28} + requires: {platform: f28} description: This module demonstrates how to write simple modulemd files And can be used for testing the build and release pipeline. license: @@ -28,8 +28,7 @@ data: xmd: mbs: buildrequires: - base-runtime: {ref: 147dca4ca65aa9a1ac51f71b7e687f9178ffa5df, stream: master, - version: '20170616125652'} + platform: {ref: virtual, stream: f28, version: '3'} commit: 722fd739fd6cf66faf29f6fb95dd64f60ba3e39a rpms: ed: {ref: 01bf8330812fea798671925cc537f2f29b0bd216} diff --git a/tests/staged_data/local_builds/module-testmodule-master-20170816080816/results/modules.yaml b/tests/staged_data/local_builds/module-testmodule-master-20170816080816/results/modules.yaml index 65d395ec..55b95d10 100644 --- a/tests/staged_data/local_builds/module-testmodule-master-20170816080816/results/modules.yaml +++ b/tests/staged_data/local_builds/module-testmodule-master-20170816080816/results/modules.yaml @@ -11,8 +11,8 @@ data: ed: {cache: 'http://pkgs.fedoraproject.org/repo/pkgs/ed', rationale: A build dependency of mksh., ref: master, repository: 'git://pkgs.fedoraproject.org/rpms/ed'} dependencies: - buildrequires: {base-runtime: master} - requires: {base-runtime: master} + buildrequires: {platform: f28} + requires: {platform: f28} description: This module demonstrates how to write simple modulemd files And can be used for testing the build and release pipeline. license: @@ -28,8 +28,7 @@ data: xmd: mbs: buildrequires: - base-runtime: {ref: 147dca4ca65aa9a1ac51f71b7e687f9178ffa5df, stream: master, - version: '20170616125652'} + platform: {ref: virtual, stream: f28, version: '3'} commit: 722fd739fd6cf66faf29f6fb95dd64f60ba3e39a rpms: ed: {ref: 01bf8330812fea798671925cc537f2f29b0bd216} diff --git a/tests/staged_data/local_builds/module-testmodule2-master-20170816093656/results/modules.yaml b/tests/staged_data/local_builds/module-testmodule2-master-20170816093656/results/modules.yaml index 09878920..598e7326 100644 --- a/tests/staged_data/local_builds/module-testmodule2-master-20170816093656/results/modules.yaml +++ b/tests/staged_data/local_builds/module-testmodule2-master-20170816093656/results/modules.yaml @@ -18,8 +18,8 @@ data: mksh: {cache: 'http://pkgs.fedoraproject.org/repo/pkgs/mksh', rationale: A build dependency of mksh., ref: master, repository: 'git://pkgs.fedoraproject.org/rpms/mksh'} dependencies: - buildrequires: {base-runtime: master, testmodule: master} - requires: {base-runtime: master} + buildrequires: {platform: f28, testmodule: master} + requires: {platform: f28} description: This module demonstrates how to write simple modulemd files And can be used for testing the build and release pipeline. license: @@ -35,8 +35,7 @@ data: xmd: mbs: buildrequires: - base-runtime: {ref: 147dca4ca65aa9a1ac51f71b7e687f9178ffa5df, stream: master, - version: '20170616125652'} + platform: {ref: virtual, stream: f28, version: '3'} testmodule: {stream: master, version: '20170816080815'} commit: null rpms: diff --git a/tests/staged_data/platform.yaml b/tests/staged_data/platform.yaml new file mode 100644 index 00000000..048889b5 --- /dev/null +++ b/tests/staged_data/platform.yaml @@ -0,0 +1,21 @@ +data: + description: Fedora 28 traditional base + name: platform + profiles: + buildroot: + rpms: [bash, bzip2, coreutils, cpio, diffutils, fedora-release, findutils, gawk, + gcc, gcc-c++, grep, gzip, info, make, patch, redhat-rpm-config, rpm-build, + sed, shadow-utils, tar, unzip, util-linux, which, xz] + srpm-buildroot: + rpms: [bash, fedora-release, fedpkg-minimal, gnupg2, redhat-rpm-config, rpm-build, + shadow-utils] + stream: f28 + summary: Fedora 28 traditional base + version: 3 + xmd: + mbs: + buildrequires: {} + commit: virtual + requires: {} +document: modulemd +version: 1 diff --git a/tests/staged_data/python3-no-components.yaml b/tests/staged_data/python3-no-components.yaml index 5395a068..ab354be5 100644 --- a/tests/staged_data/python3-no-components.yaml +++ b/tests/staged_data/python3-no-components.yaml @@ -1,5 +1,5 @@ # This module is left empty because python3 is contained in the -# Platform module of Fedora 27 Modular Server edition. +# Platform module. # Other modules can depend on this empty one so that, when the # implementation of python3 is moved out of the Platform module, @@ -25,9 +25,9 @@ data: - MIT dependencies: buildrequires: - bootstrap: master + platform: f28 requires: - platform: master + platform: f28 references: community: https://www.python.org/ documentation: https://docs.python.org/3/ diff --git a/tests/staged_data/testmodule-bootstrap.yaml b/tests/staged_data/testmodule-bootstrap.yaml deleted file mode 100644 index b30c8bc2..00000000 --- a/tests/staged_data/testmodule-bootstrap.yaml +++ /dev/null @@ -1,36 +0,0 @@ -document: modulemd -version: 1 -data: - summary: A test module in all its beauty - description: This module demonstrates how to write simple modulemd files And can be used for testing the build and release pipeline. - license: - module: [ MIT ] - dependencies: - buildrequires: - bootstrap: master - requires: - bootstrap: master - references: - community: https://fedoraproject.org/wiki/Modularity - documentation: https://fedoraproject.org/wiki/Fedora_Packaging_Guidelines_for_Modules - tracker: https://taiga.fedorainfracloud.org/project/modularity - profiles: - default: - rpms: - - tangerine - api: - rpms: - - perl-Tangerine - - tangerine - components: - rpms: - perl-List-Compare: - rationale: A dependency of tangerine. - ref: f25 - perl-Tangerine: - rationale: Provides API for this module and is a dependency of tangerine. - ref: f25 - tangerine: - rationale: Provides API for this module. - buildorder: 10 - ref: f25 diff --git a/tests/staged_data/testmodule-more-components.yaml b/tests/staged_data/testmodule-more-components.yaml index 0dc35cbd..60980990 100644 --- a/tests/staged_data/testmodule-more-components.yaml +++ b/tests/staged_data/testmodule-more-components.yaml @@ -1,38 +1,31 @@ document: modulemd version: 1 data: - summary: A test module in all its beauty - description: This module demonstrates how to write simple modulemd files And can be used for testing the build and release pipeline. + summary: A test module in all its beautiful beauty + description: >- + This module demonstrates how to write simple modulemd files And + can be used for testing the build and release pipeline. license: module: [ MIT ] dependencies: buildrequires: - bootstrap: master + platform: f28 requires: - bootstrap: master + platform: f28 references: - community: https://fedoraproject.org/wiki/Modularity + community: https://docs.pagure.org/modularity/ documentation: https://fedoraproject.org/wiki/Fedora_Packaging_Guidelines_for_Modules - tracker: https://taiga.fedorainfracloud.org/project/modularity - profiles: - default: - rpms: - - tangerine - api: - rpms: - - perl-Tangerine - - tangerine components: rpms: perl-List-Compare: rationale: A dependency of tangerine. - ref: f25 + ref: master perl-Tangerine: rationale: Provides API for this module and is a dependency of tangerine. - ref: f25 + ref: master perl-List-Compare1: rationale: A dependency of tangerine. - ref: f25 + ref: master perl-Tangerine1: rationale: Provides API for this module and is a dependency of tangerine. - ref: f25 + ref: master diff --git a/tests/staged_data/testmodule-variant.yaml b/tests/staged_data/testmodule-variant.yaml deleted file mode 100644 index 8a3ff3b0..00000000 --- a/tests/staged_data/testmodule-variant.yaml +++ /dev/null @@ -1,32 +0,0 @@ -document: modulemd -version: 1 -data: - name: testmodule-variant - summary: A test module in all its whackiness - description: This module demonstrates how to write simple modulemd files And can be used for testing the build and release pipeline. - license: - module: [ MIT ] - dependencies: - buildrequires: - base-runtime: master - requires: - base-runtime: master - references: - community: https://fedoraproject.org/wiki/Modularity - documentation: https://fedoraproject.org/wiki/Fedora_Packaging_Guidelines_for_Modules - tracker: https://taiga.fedorainfracloud.org/project/modularity - profiles: - default: - rpms: - - python - api: - rpms: - - python - components: - rpms: - perl-List-Compare: - rationale: A dependency of tangerine. - ref: f25 - python: - rationale: This is irrational - ref: f24 diff --git a/tests/staged_data/testmodule-wrong-name.yaml b/tests/staged_data/testmodule-wrong-name.yaml deleted file mode 100644 index abdb9094..00000000 --- a/tests/staged_data/testmodule-wrong-name.yaml +++ /dev/null @@ -1,37 +0,0 @@ -document: modulemd -version: 1 -data: - name: wrong_name - summary: A test module in all its beauty - description: This module demonstrates how to write simple modulemd files And can be used for testing the build and release pipeline. - license: - module: [ MIT ] - dependencies: - buildrequires: - base-runtime: master - requires: - base-runtime: master - references: - community: https://fedoraproject.org/wiki/Modularity - documentation: https://fedoraproject.org/wiki/Fedora_Packaging_Guidelines_for_Modules - tracker: https://taiga.fedorainfracloud.org/project/modularity - profiles: - default: - rpms: - - tangerine - api: - rpms: - - perl-Tangerine - - tangerine - components: - rpms: - perl-List-Compare: - rationale: A dependency of tangerine. - ref: f25 - perl-Tangerine: - rationale: Provides API for this module and is a dependency of tangerine. - ref: f25 - tangerine: - rationale: Provides API for this module. - buildorder: 10 - ref: f25 diff --git a/tests/staged_data/testmodule.yaml b/tests/staged_data/testmodule.yaml index f7ebf5cb..aef4b997 100644 --- a/tests/staged_data/testmodule.yaml +++ b/tests/staged_data/testmodule.yaml @@ -1,36 +1,37 @@ document: modulemd version: 1 data: - summary: A test module in all its beauty - description: This module demonstrates how to write simple modulemd files And can be used for testing the build and release pipeline. + summary: A test module in all its beautiful beauty + description: >- + This module demonstrates how to write simple modulemd files And + can be used for testing the build and release pipeline. license: module: [ MIT ] dependencies: buildrequires: - base-runtime: master + platform: f28 requires: - base-runtime: master + platform: f28 references: - community: https://fedoraproject.org/wiki/Modularity + community: https://docs.pagure.org/modularity/ documentation: https://fedoraproject.org/wiki/Fedora_Packaging_Guidelines_for_Modules - tracker: https://taiga.fedorainfracloud.org/project/modularity profiles: default: rpms: - - tangerine + - tangerine api: rpms: - - perl-Tangerine - - tangerine + - perl-Tangerine + - tangerine components: rpms: perl-List-Compare: rationale: A dependency of tangerine. - ref: f25 + ref: master perl-Tangerine: rationale: Provides API for this module and is a dependency of tangerine. - ref: f24 + ref: master tangerine: rationale: Provides API for this module. buildorder: 10 - ref: f23 + ref: master diff --git a/tests/test_build/test_build.py b/tests/test_build/test_build.py index d1ec7e66..1d06bd43 100644 --- a/tests/test_build/test_build.py +++ b/tests/test_build/test_build.py @@ -21,7 +21,6 @@ # Written by Jan Kaluza import koji -import vcr import os from os import path, mkdir from os.path import dirname @@ -34,7 +33,6 @@ import module_build_service.scheduler.handlers.repos import module_build_service.utils from module_build_service.errors import Forbidden from module_build_service import db, models, conf, build_logs -from tests import get_vcr_path from mock import patch, PropertyMock, Mock from werkzeug.datastructures import FileStorage @@ -55,10 +53,11 @@ user = ('Homer J. Simpson', set(['packager'])) class FakeSCM(object): - def __init__(self, mocked_scm, name, mmd_filename, commit=None): + def __init__(self, mocked_scm, name, mmd_filename, commit=None, version=20180205135154): self.mocked_scm = mocked_scm self.name = name self.commit = commit + self.version = version self.mmd_filename = mmd_filename self.sourcedir = None @@ -67,6 +66,7 @@ class FakeSCM(object): self.mocked_scm.return_value.branch = 'master' self.mocked_scm.return_value.get_latest = self.get_latest self.mocked_scm.return_value.commit = self.commit + self.mocked_scm.return_value.version = self.version self.mocked_scm.return_value.repository_root = "git://pkgs.stg.fedoraproject.org/modules/" self.mocked_scm.return_value.sourcedir = self.sourcedir self.mocked_scm.return_value.get_module_yaml = self.get_module_yaml @@ -305,13 +305,9 @@ class TestBuild: self.client = app.test_client() clean_database() - self.vcr = vcr.use_cassette(get_vcr_path(__file__, test_method)) - self.vcr.__enter__() - def teardown_method(self, test_method): FakeModuleBuilder.reset() cleanup_moksha() - self.vcr.__exit__() for i in range(20): try: os.remove(build_logs.path(i)) @@ -320,7 +316,8 @@ class TestBuild: @patch('module_build_service.auth.get_user', return_value=user) @patch('module_build_service.scm.SCM') - def test_submit_build(self, mocked_scm, mocked_get_user, conf_system, dbg): + def test_submit_build(self, mocked_scm, mocked_get_user, conf_system, dbg, + pdc_module_inactive): """ Tests the build of testmodule.yaml using FakeModuleBuilder which succeeds everytime. @@ -330,7 +327,7 @@ class TestBuild: rv = self.client.post('/module-build-service/1/module-builds/', data=json.dumps( {'branch': 'master', 'scmurl': 'git://pkgs.stg.fedoraproject.org/modules/' - 'testmodule.git?#68932c90de214d9d13feefbd35246a81b6cb8d49'})) + 'testmodule.git?#620ec77321b2ea7b0d67d82992dda3e1d67055b4'})) data = json.loads(rv.data) module_build_id = data['id'] @@ -381,19 +378,47 @@ class TestBuild: @patch('module_build_service.auth.get_user', return_value=user) @patch('module_build_service.scm.SCM') - def test_submit_build_no_components(self, mocked_scm, mocked_get_user, conf_system, dbg): + def test_submit_build_no_components(self, mocked_scm, mocked_get_user, conf_system, dbg, pdc): """ Tests the build of a module with no components """ FakeSCM(mocked_scm, 'python3', 'python3-no-components.yaml', '620ec77321b2ea7b0d67d82992dda3e1d67055b4') + python3_yaml_path = os.path.join( + base_dir, 'staged_data', 'formatted_python3-no-components.yaml') + with open(python3_yaml_path) as f: + python3_yaml = f.read() rv = self.client.post('/module-build-service/1/module-builds/', data=json.dumps( {'branch': 'master', 'scmurl': 'git://pkgs.stg.fedoraproject.org/modules/' - 'testmodule.git?#68932c90de214d9d13feefbd35246a81b6cb8d49'})) + 'testmodule.git?#620ec77321b2ea7b0d67d82992dda3e1d67055b4'})) data = json.loads(rv.data) module_build_id = data['id'] + pdc.endpoints['unreleasedvariants']['GET'].append({ + 'variant_id': 'python3', + 'variant_uid': 'python3:master:20180205135154', + 'variant_name': 'python3', + 'variant_type': 'module', + 'variant_version': 'master', + 'variant_release': '20180205135154', + 'koji_tag': 'module-95b214a704c984be', + 'modulemd': python3_yaml, + 'runtime_deps': [ + { + 'dependency': 'platform', + 'stream': 'f28' + } + ], + 'build_deps': [ + { + 'dependency': 'platform', + 'stream': 'f28' + } + ], + 'rpms': [], + 'active': False, + }) msgs = [] stop = module_build_service.scheduler.make_simple_stop_condition(db.session) @@ -426,8 +451,10 @@ class TestBuild: @patch('module_build_service.auth.get_user', return_value=user) @patch('module_build_service.scm.SCM') - def test_submit_build_from_yaml_allowed(self, mocked_scm, mocked_get_user, conf_system, dbg): - FakeSCM(mocked_scm, "testmodule", "testmodule.yaml") + def test_submit_build_from_yaml_allowed(self, mocked_scm, mocked_get_user, conf_system, dbg, + pdc_module_inactive): + FakeSCM(mocked_scm, 'testmodule', 'testmodule.yaml', + '620ec77321b2ea7b0d67d82992dda3e1d67055b4') testmodule = os.path.join(base_dir, 'staged_data', 'testmodule.yaml') with patch.object(module_build_service.config.Config, 'yaml_submit_allowed', @@ -440,14 +467,23 @@ class TestBuild: data = json.loads(rv.data) assert data['id'] == 1 + # Since the module's version is derived a submission for direct yaml submissions, we must + # alter PDC with the correct version that MBS generated + version = models.ModuleBuild.query.first().version + pdc_module_inactive.endpoints['unreleasedvariants']['GET'][1]['variant_release'] = version + uid = pdc_module_inactive.endpoints['unreleasedvariants']['GET'][1]['variant_uid'] + new_uid = ':'.join([uid.rsplit(':', 1)[0], version]) + pdc_module_inactive.endpoints['unreleasedvariants']['GET'][1]['variant_uid'] = new_uid + msgs = [] stop = module_build_service.scheduler.make_simple_stop_condition(db.session) module_build_service.scheduler.main(msgs, stop) + assert models.ModuleBuild.query.first().state == models.BUILD_STATES['ready'] @patch('module_build_service.auth.get_user', return_value=user) def test_submit_build_with_optional_params(self, mocked_get_user, conf_system, dbg): params = {'branch': 'master', 'scmurl': 'git://pkgs.stg.fedoraproject.org/modules/' - 'testmodule.git?#68932c90de214d9d13feefbd35246a81b6cb8d49'} + 'testmodule.git?#620ec77321b2ea7b0d67d82992dda3e1d67055b4'} def submit(data): rv = self.client.post('/module-build-service/1/module-builds/', data=json.dumps(data)) @@ -463,7 +499,8 @@ class TestBuild: @patch('module_build_service.auth.get_user', return_value=user) @patch('module_build_service.scm.SCM') - def test_submit_build_cancel(self, mocked_scm, mocked_get_user, conf_system, dbg): + def test_submit_build_cancel(self, mocked_scm, mocked_get_user, conf_system, dbg, + pdc_module_inactive): """ Submit all builds for a module and cancel the module build later. """ @@ -472,7 +509,7 @@ class TestBuild: rv = self.client.post('/module-build-service/1/module-builds/', data=json.dumps( {'branch': 'master', 'scmurl': 'git://pkgs.stg.fedoraproject.org/modules/' - 'testmodule.git?#68932c90de214d9d13feefbd35246a81b6cb8d49'})) + 'testmodule.git?#620ec77321b2ea7b0d67d82992dda3e1d67055b4'})) data = json.loads(rv.data) module_build_id = data['id'] @@ -514,7 +551,8 @@ class TestBuild: @patch('module_build_service.auth.get_user', return_value=user) @patch('module_build_service.scm.SCM') - def test_submit_build_instant_complete(self, mocked_scm, mocked_get_user, conf_system, dbg): + def test_submit_build_instant_complete(self, mocked_scm, mocked_get_user, conf_system, dbg, + pdc_module_inactive): """ Tests the build of testmodule.yaml using FakeModuleBuilder which succeeds everytime. @@ -524,7 +562,7 @@ class TestBuild: rv = self.client.post('/module-build-service/1/module-builds/', data=json.dumps( {'branch': 'master', 'scmurl': 'git://pkgs.stg.fedoraproject.org/modules/' - 'testmodule.git?#68932c90de214d9d13feefbd35246a81b6cb8d49'})) + 'testmodule.git?#620ec77321b2ea7b0d67d82992dda3e1d67055b4'})) data = json.loads(rv.data) module_build_id = data['id'] @@ -547,7 +585,7 @@ class TestBuild: new_callable=PropertyMock, return_value=1) def test_submit_build_concurrent_threshold(self, conf_num_concurrent_builds, mocked_scm, mocked_get_user, - conf_system, dbg): + conf_system, dbg, pdc_module_inactive): """ Tests the build of testmodule.yaml using FakeModuleBuilder with num_concurrent_builds set to 1. @@ -557,7 +595,7 @@ class TestBuild: rv = self.client.post('/module-build-service/1/module-builds/', data=json.dumps( {'branch': 'master', 'scmurl': 'git://pkgs.stg.fedoraproject.org/modules/' - 'testmodule.git?#68932c90de214d9d13feefbd35246a81b6cb8d49'})) + 'testmodule.git?#620ec77321b2ea7b0d67d82992dda3e1d67055b4'})) data = json.loads(rv.data) module_build_id = data['id'] @@ -591,7 +629,7 @@ class TestBuild: new_callable=PropertyMock, return_value=2) def test_try_to_reach_concurrent_threshold(self, conf_num_concurrent_builds, mocked_scm, mocked_get_user, - conf_system, dbg): + conf_system, dbg, pdc_module_inactive): """ Tests that we try to submit new component build right after the previous one finished without waiting for all @@ -599,10 +637,21 @@ class TestBuild: """ FakeSCM(mocked_scm, 'testmodule-more-components', 'testmodule-more-components.yaml', '620ec77321b2ea7b0d67d82992dda3e1d67055b4') + # Modify the modulemd in PDC + current_dir = os.path.dirname(__file__) + formatted_yml_path = os.path.join( + current_dir, '..', 'staged_data', 'formatted_testmodule-more-components.yaml') + with open(formatted_yml_path) as f: + yaml = f.read() + pdc_module_inactive.endpoints['unreleasedvariants']['GET'][-1].update({ + 'variant_id': 'testmodule-more-components', + 'variant_name': 'testmodule-more-components', + 'modulemd': yaml + }) self.client.post('/module-build-service/1/module-builds/', data=json.dumps( {'branch': 'master', 'scmurl': 'git://pkgs.stg.fedoraproject.org/modules/' - 'testmodule.git?#68932c90de214d9d13feefbd35246a81b6cb8d49'})) + 'testmodule.git?#620ec77321b2ea7b0d67d82992dda3e1d67055b4'})) # Holds the number of concurrent component builds during # the module build. @@ -641,7 +690,7 @@ class TestBuild: @patch("module_build_service.config.Config.num_concurrent_builds", new_callable=PropertyMock, return_value=1) def test_build_in_batch_fails(self, conf_num_concurrent_builds, mocked_scm, - mocked_get_user, conf_system, dbg): + mocked_get_user, conf_system, dbg, pdc_module_inactive): """ Tests that if the build in batch fails, other components in a batch are still build, but next batch is not started. @@ -651,7 +700,7 @@ class TestBuild: rv = self.client.post('/module-build-service/1/module-builds/', data=json.dumps( {'branch': 'master', 'scmurl': 'git://pkgs.stg.fedoraproject.org/modules/' - 'testmodule.git?#68932c90de214d9d13feefbd35246a81b6cb8d49'})) + 'testmodule.git?#620ec77321b2ea7b0d67d82992dda3e1d67055b4'})) data = json.loads(rv.data) module_build_id = data['id'] @@ -700,7 +749,7 @@ class TestBuild: @patch("module_build_service.config.Config.num_concurrent_builds", new_callable=PropertyMock, return_value=1) def test_all_builds_in_batch_fail(self, conf_num_concurrent_builds, mocked_scm, - mocked_get_user, conf_system, dbg): + mocked_get_user, conf_system, dbg, pdc_module_inactive): """ Tests that if the build in batch fails, other components in a batch are still build, but next batch is not started. @@ -710,7 +759,7 @@ class TestBuild: rv = self.client.post('/module-build-service/1/module-builds/', data=json.dumps( {'branch': 'master', 'scmurl': 'git://pkgs.stg.fedoraproject.org/modules/' - 'testmodule.git?#68932c90de214d9d13feefbd35246a81b6cb8d49'})) + 'testmodule.git?#620ec77321b2ea7b0d67d82992dda3e1d67055b4'})) data = json.loads(rv.data) module_build_id = data['id'] @@ -744,8 +793,8 @@ class TestBuild: @patch('module_build_service.auth.get_user', return_value=user) @patch('module_build_service.scm.SCM') - def test_submit_build_reuse_all(self, mocked_scm, mocked_get_user, - conf_system, dbg): + def test_submit_build_reuse_all(self, mocked_scm, mocked_get_user, conf_system, dbg, + pdc_module_reuse): """ Tests that we do not try building module-build-macros when reusing all components in a module build. @@ -796,7 +845,7 @@ class TestBuild: @patch('module_build_service.auth.get_user', return_value=user) @patch('module_build_service.scm.SCM') def test_submit_build_reuse_all_without_build_macros(self, mocked_scm, mocked_get_user, - conf_system, dbg): + conf_system, dbg, pdc_module_reuse): """ Tests that we can reuse components even when the reused module does not have module-build-macros component. @@ -848,7 +897,8 @@ class TestBuild: @patch('module_build_service.auth.get_user', return_value=user) @patch('module_build_service.scm.SCM') - def test_submit_build_resume(self, mocked_scm, mocked_get_user, conf_system, dbg): + def test_submit_build_resume(self, mocked_scm, mocked_get_user, conf_system, dbg, + pdc_module_inactive): """ Tests that resuming the build works even when previous batches are already built. @@ -859,7 +909,7 @@ class TestBuild: build_one = models.ModuleBuild() build_one.name = 'testmodule' build_one.stream = 'master' - build_one.version = 1 + build_one.version = 20180205135154 build_one.build_context = 'ac4de1c346dcf09ce77d38cd4e75094ec1c08eb0' build_one.runtime_context = 'ac4de1c346dcf09ce77d38cd4e75094ec1c08eb0' build_one.state = models.BUILD_STATES['failed'] @@ -868,7 +918,7 @@ class TestBuild: current_dir, '..', 'staged_data', 'formatted_testmodule.yaml') with open(formatted_testmodule_yml_path, 'r') as f: build_one.modulemd = f.read() - build_one.koji_tag = 'module-testmodule-master-1' + build_one.koji_tag = 'module-95b214a704c984be' build_one.scmurl = 'git://pkgs.stg.fedoraproject.org/modules/testmodule.git?#7fea453' build_one.batch = 2 build_one.owner = 'Homer J. Simpson' @@ -891,19 +941,20 @@ class TestBuild: component_one = models.ComponentBuild() component_one.package = 'perl-Tangerine' component_one.format = 'rpms' - component_one.scmurl = 'git://pkgs.stg.fedoraproject.org/rpms/perl-Tangerine.git?#f24' + component_one.scmurl = 'git://pkgs.stg.fedoraproject.org/rpms/perl-Tangerine.git?#master' component_one.state = koji.BUILD_STATES['COMPLETE'] - component_one.nvr = 'perl-Tangerine-0.23-1.module_testmodule_master_1' + component_one.nvr = 'perl-Tangerine-0:0.22-2.module+0+814cfa39' component_one.batch = 2 component_one.module_id = 1 - component_one.ref = '4ceea43add2366d8b8c5a622a2fb563b625b9abf' + component_one.ref = '7e96446223f1ad84a26c7cf23d6591cd9f6326c6' component_one.tagged = True component_one.tagged_in_final = True # Failed component component_two = models.ComponentBuild() component_two.package = 'perl-List-Compare' component_two.format = 'rpms' - component_two.scmurl = 'git://pkgs.stg.fedoraproject.org/rpms/perl-List-Compare.git?#f24' + component_two.scmurl = \ + 'git://pkgs.stg.fedoraproject.org/rpms/perl-List-Compare.git?#master' component_two.state = koji.BUILD_STATES['FAILED'] component_two.batch = 2 component_two.module_id = 1 @@ -911,7 +962,7 @@ class TestBuild: component_three = models.ComponentBuild() component_three.package = 'tangerine' component_three.format = 'rpms' - component_three.scmurl = 'git://pkgs.stg.fedoraproject.org/rpms/tangerine.git?#f24' + component_three.scmurl = 'git://pkgs.stg.fedoraproject.org/rpms/tangerine.git?#master' component_three.batch = 3 component_three.module_id = 1 # module-build-macros @@ -935,11 +986,12 @@ class TestBuild: db.session.commit() db.session.expire_all() - FakeSCM(mocked_scm, 'testmodule', 'testmodule.yaml', '7fea453') + FakeSCM(mocked_scm, 'testmodule', 'testmodule.yaml', + '620ec77321b2ea7b0d67d82992dda3e1d67055b4') # Resubmit the failed module rv = self.client.post('/module-build-service/1/module-builds/', data=json.dumps( {'branch': 'master', 'scmurl': 'git://pkgs.stg.fedoraproject.org/modules/' - 'testmodule.git?#7fea453'})) + 'testmodule.git?#620ec77321b2ea7b0d67d82992dda3e1d67055b4'})) data = json.loads(rv.data) module_build_id = data['id'] @@ -980,7 +1032,7 @@ class TestBuild: build_one = models.ModuleBuild() build_one.name = 'testmodule' build_one.stream = 'master' - build_one.version = 1 + build_one.version = 20180205135154 build_one.build_context = 'ac4de1c346dcf09ce77d38cd4e75094ec1c08eb0' build_one.runtime_context = 'ac4de1c346dcf09ce77d38cd4e75094ec1c08eb0' build_one.state = models.BUILD_STATES['failed'] @@ -989,7 +1041,7 @@ class TestBuild: current_dir, '..', 'staged_data', 'formatted_testmodule.yaml') with open(formatted_testmodule_yml_path, 'r') as f: build_one.modulemd = f.read() - build_one.koji_tag = 'module-testmodule-master-1' + build_one.koji_tag = 'module-95b214a704c984be' build_one.scmurl = 'git://pkgs.stg.fedoraproject.org/modules/testmodule.git?#7fea453' build_one.batch = 2 build_one.owner = 'Homer J. Simpson' @@ -1012,19 +1064,20 @@ class TestBuild: component_one = models.ComponentBuild() component_one.package = 'perl-Tangerine' component_one.format = 'rpms' - component_one.scmurl = 'git://pkgs.stg.fedoraproject.org/rpms/perl-Tangerine.git?#f24' + component_one.scmurl = 'git://pkgs.stg.fedoraproject.org/rpms/perl-Tangerine.git?#master' component_one.batch = 2 component_one.module_id = 1 component_two = models.ComponentBuild() component_two.package = 'perl-List-Compare' component_two.format = 'rpms' - component_two.scmurl = 'git://pkgs.stg.fedoraproject.org/rpms/perl-List-Compare.git?#f24' + component_two.scmurl = \ + 'git://pkgs.stg.fedoraproject.org/rpms/perl-List-Compare.git?#master' component_two.batch = 2 component_two.module_id = 1 component_three = models.ComponentBuild() component_three.package = 'tangerine' component_three.format = 'rpms' - component_three.scmurl = 'git://pkgs.stg.fedoraproject.org/rpms/tangerine.git?#f24' + component_three.scmurl = 'git://pkgs.stg.fedoraproject.org/rpms/tangerine.git?#master' component_three.batch = 3 component_three.module_id = 1 # Failed module-build-macros @@ -1034,7 +1087,7 @@ class TestBuild: component_four.state = koji.BUILD_STATES['FAILED'] component_four.scmurl = ( '/tmp/module_build_service-build-macrosqr4AWH/SRPMS/module-build-macros-0.1-1.' - 'module_testmodule_master_20170109091357.src.rpm') + 'module_testmodule_master_20180205135154.src.rpm') component_four.batch = 1 component_four.module_id = 1 component_four.build_time_only = True @@ -1078,11 +1131,13 @@ class TestBuild: @patch('module_build_service.auth.get_user', return_value=user) @patch('module_build_service.scm.SCM') - def test_submit_build_resume_failed_init(self, mocked_scm, mocked_get_user, conf_system, dbg): + def test_submit_build_resume_failed_init(self, mocked_scm, mocked_get_user, conf_system, dbg, + pdc_module_inactive): """ Tests that resuming the build works when the build failed during the init step """ - FakeSCM(mocked_scm, 'testmodule', 'testmodule.yaml', '7fea453') + FakeSCM(mocked_scm, 'testmodule', 'testmodule.yaml', + '620ec77321b2ea7b0d67d82992dda3e1d67055b4') stop = module_build_service.scheduler.make_simple_stop_condition(db.session) with patch('module_build_service.utils.format_mmd') as mock_format_mmd: @@ -1090,7 +1145,7 @@ class TestBuild: 'Custom component repositories aren\'t allowed.') rv = self.client.post('/module-build-service/1/module-builds/', data=json.dumps( {'branch': 'master', 'scmurl': 'git://pkgs.stg.fedoraproject.org/modules/' - 'testmodule.git?#7fea453'})) + 'testmodule.git?#620ec77321b2ea7b0d67d82992dda3e1d67055b4'})) # Run the backend so that it fails in the "init" handler module_build_service.scheduler.main([], stop) cleanup_moksha() @@ -1105,8 +1160,9 @@ class TestBuild: # Resubmit the failed module rv = self.client.post('/module-build-service/1/module-builds/', data=json.dumps( - {'branch': 'master', 'scmurl': ('git://pkgs.stg.fedoraproject.org/modules/' - 'testmodule.git?#7fea453')})) + {'branch': 'master', + 'scmurl': ('git://pkgs.stg.fedoraproject.org/modules/testmodule.git?' + '#620ec77321b2ea7b0d67d82992dda3e1d67055b4')})) module_build = models.ModuleBuild.query.filter_by(id=module_build_id).one() components = models.ComponentBuild.query.filter_by( @@ -1130,7 +1186,8 @@ class TestBuild: @patch('module_build_service.auth.get_user', return_value=user) @patch('module_build_service.scm.SCM') - def test_submit_build_resume_init_fail(self, mocked_scm, mocked_get_user, conf_system, dbg): + def test_submit_build_resume_init_fail(self, mocked_scm, mocked_get_user, conf_system, dbg, + pdc_module_inactive): """ Tests that resuming the build fails when the build is in init state """ @@ -1139,7 +1196,7 @@ class TestBuild: # Post so a module is in the init phase rv = self.client.post('/module-build-service/1/module-builds/', data=json.dumps( {'branch': 'master', 'scmurl': 'git://pkgs.stg.fedoraproject.org/modules/' - 'testmodule.git?#68932c90de214d9d13feefbd35246a81b6cb8d49'})) + 'testmodule.git?#620ec77321b2ea7b0d67d82992dda3e1d67055b4'})) assert rv.status_code == 201 # Run the backend stop = module_build_service.scheduler.make_simple_stop_condition(db.session) @@ -1147,7 +1204,7 @@ class TestBuild: # Post again and make sure it fails rv2 = self.client.post('/module-build-service/1/module-builds/', data=json.dumps( {'branch': 'master', 'scmurl': 'git://pkgs.stg.fedoraproject.org/modules/' - 'testmodule.git?#68932c90de214d9d13feefbd35246a81b6cb8d49'})) + 'testmodule.git?#620ec77321b2ea7b0d67d82992dda3e1d67055b4'})) data = json.loads(rv2.data) expected = { 'error': 'Conflict', @@ -1169,13 +1226,9 @@ class TestLocalBuild: self.client = app.test_client() clean_database() - self.vcr = vcr.use_cassette(get_vcr_path(__file__, test_method)) - self.vcr.__enter__() - def teardown_method(self, test_method): FakeModuleBuilder.reset() cleanup_moksha() - self.vcr.__exit__() for i in range(20): try: os.remove(build_logs.path(i)) @@ -1193,7 +1246,7 @@ class TestLocalBuild: Tests local module build dependency. """ with app.app_context(): - module_build_service.utils.load_local_builds(["base-runtime"]) + module_build_service.utils.load_local_builds(["platform"]) FakeSCM(mocked_scm, 'testmodule', 'testmodule.yaml', '620ec77321b2ea7b0d67d82992dda3e1d67055b4') @@ -1201,7 +1254,7 @@ class TestLocalBuild: '/module-build-service/1/module-builds/', data=json.dumps( {'branch': 'master', 'scmurl': 'git://pkgs.stg.fedoraproject.org/modules/' - 'testmodule.git?#68932c90de214d9d13feefbd35246a81b6cb8d49'})) + 'testmodule.git?#620ec77321b2ea7b0d67d82992dda3e1d67055b4'})) data = json.loads(rv.data) module_build_id = data['id'] diff --git a/tests/test_content_generator.py b/tests/test_content_generator.py index 273a1d9e..c08da1f6 100644 --- a/tests/test_content_generator.py +++ b/tests/test_content_generator.py @@ -21,7 +21,6 @@ # Written by Stanislav Ochotnicky import json -import vcr import os from os import path @@ -32,7 +31,7 @@ from module_build_service import models, conf, build_logs from mock import patch, Mock, MagicMock, call -from tests import init_data, get_vcr_path +from tests import init_data from module_build_service.builder.KojiContentGenerator import KojiContentGenerator @@ -53,9 +52,6 @@ class TestBuild: module.cg_build_koji_tag = "f27-module-candidate" self.cg = KojiContentGenerator(module, conf) - self.vcr = vcr.use_cassette(get_vcr_path(__file__, test_method)) - self.vcr.__enter__() - # Ensure that there is no build log from other tests try: file_path = build_logs.path(self.cg.module) @@ -70,7 +66,6 @@ class TestBuild: del sys.modules['moksha.hub.reactor'] del sys.modules['moksha.hub'] import moksha.hub.reactor # noqa - self.vcr.__exit__() try: file_path = build_logs.path(self.cg.module) os.remove(file_path) diff --git a/tests/test_resolver/test_pdc.py b/tests/test_resolver/test_pdc.py index a0b93c8d..a2e89769 100644 --- a/tests/test_resolver/test_pdc.py +++ b/tests/test_resolver/test_pdc.py @@ -21,15 +21,14 @@ # Written by Ralph Bean import os +import copy from mock import patch, PropertyMock -import vcr import module_build_service.resolver as mbs_resolver import module_build_service.utils import module_build_service.models from module_build_service import app, db -from tests import get_vcr_path import tests import modulemd @@ -40,15 +39,6 @@ base_dir = os.path.join(os.path.dirname(__file__), "..") class TestPDCModule: - def setup_method(self, test_method): - self.vcr = vcr.use_cassette(get_vcr_path(__file__, test_method)) - self.vcr.__enter__() - - self.resolver = mbs_resolver.GenericResolver.create(tests.conf, backend='pdc') - - def teardown_method(self, test_method): - self.vcr.__exit__() - def test_get_variant_dict_module_dict_active(self): """ Tests that "active" is honored by get_variant_dict(...). @@ -64,48 +54,66 @@ class TestPDCModule: 'variant_version': 'master' } - variant_dict = self.resolver._get_variant_dict(dep) + resolver = mbs_resolver.GenericResolver.create(tests.conf, backend='pdc') + variant_dict = resolver._get_variant_dict(dep) assert variant_dict == expected - def test_get_module_simple_as_dict(self): + def test_get_module_simple_as_dict(self, pdc_module_active): query = {'name': 'testmodule', 'version': 'master'} - result = self.resolver._get_module(query) + resolver = mbs_resolver.GenericResolver.create(tests.conf, backend='pdc') + result = resolver._get_module(query) assert result['variant_name'] == 'testmodule' assert result['variant_version'] == 'master' assert 'build_deps' in result - def test_get_module_build_dependencies(self): - """ - Tests that we return proper koji_tags with base-runtime - build-time dependencies. - """ - query = { - 'name': 'base-runtime', - 'version': 'master', - 'release': '20170315134803', - } - result = self.resolver.get_module_build_dependencies(query).keys() - expected = [ - u'module-bootstrap-rawhide', - ] - assert set(result) == set(expected) - - def test_get_module_build_dependencies_single_level(self): + def test_get_module_build_dependencies(self, pdc_module_active): """ Tests that we return just direct build-time dependencies of testmodule. - It means just testmodule itself and base-runtime, but no f26-modularity - (koji tag of bootstrap module which is build-require of base-runtime). """ query = { 'name': 'testmodule', 'version': 'master', - 'release': '20170322155247' + 'release': '20180205135154', } - result = self.resolver.get_module_build_dependencies(query).keys() - expected = [ - u'module-base-runtime-master-20170315134803', - ] - assert set(result) == set(expected) + resolver = mbs_resolver.GenericResolver.create(tests.conf, backend='pdc') + result = resolver.get_module_build_dependencies(query).keys() + assert set(result) == set(['module-f28-build']) + + def test_get_module_build_dependencies_recursive(self, pdc_module_active): + """ + Tests that we return just direct build-time dependencies of testmodule. + """ + # Add testmodule2 that requires testmodule + pdc_module_active.endpoints['unreleasedvariants']['GET'].append( + copy.deepcopy(pdc_module_active.endpoints['unreleasedvariants']['GET'][-1])) + pdc_item = pdc_module_active.endpoints['unreleasedvariants']['GET'][-1] + mmd = modulemd.ModuleMetadata() + mmd.loads(pdc_item['modulemd']) + mmd.name = 'testmodule2' + mmd.version = 20180123171545 + mmd.requires['testmodule'] = 'master' + mmd.xmd['mbs']['requires']['testmodule'] = { + 'filtered_rpms': [], + 'ref': '620ec77321b2ea7b0d67d82992dda3e1d67055b4', + 'stream': 'master', + 'version': '20180205135154' + } + pdc_item.update({ + 'variant_id': 'testmodule2', + 'variant_name': 'testmodule2', + 'variant_release': str(mmd.version), + 'koji_tag': 'module-ae2adf69caf0e1b6', + 'modulemd': mmd.dumps() + }) + + query = { + 'name': 'testmodule2', + 'version': 'master', + 'release': '20180123171545', + } + resolver = mbs_resolver.GenericResolver.create(tests.conf, backend='pdc') + result = resolver.get_module_build_dependencies(query).keys() + assert set(result) == set(['module-f28-build']) @patch("module_build_service.config.Config.system", new_callable=PropertyMock, return_value="test") @@ -120,40 +128,42 @@ class TestPDCModule: """ with app.app_context(): module_build_service.utils.load_local_builds( - ["base-runtime", "parent", "child", "testmodule"]) + ["platform", "parent", "child", "testmodule"]) build = module_build_service.models.ModuleBuild.local_modules( db.session, "child", "master") - result = self.resolver.get_module_build_dependencies(build[0].mmd()).keys() + resolver = mbs_resolver.GenericResolver.create(tests.conf, backend='pdc') + result = resolver.get_module_build_dependencies(build[0].mmd()).keys() local_path = os.path.join(base_dir, 'staged_data', "local_builds") expected = [ os.path.join( local_path, - 'module-base-runtime-master-20170816080815/results'), + 'module-platform-f28-3/results'), os.path.join( local_path, 'module-parent-master-20170816080815/results'), ] assert set(result) == set(expected) - def test_resolve_profiles(self): + def test_resolve_profiles(self, pdc_module_active): yaml_path = os.path.join( base_dir, 'staged_data', 'formatted_testmodule.yaml') mmd = modulemd.ModuleMetadata() mmd.load(yaml_path) - result = self.resolver.resolve_profiles(mmd, ('buildroot', 'srpm-buildroot')) + resolver = mbs_resolver.GenericResolver.create(tests.conf, backend='pdc') + result = resolver.resolve_profiles(mmd, ('buildroot', 'srpm-buildroot')) expected = { 'buildroot': set(['unzip', 'tar', 'cpio', 'gawk', 'gcc', 'xz', 'sed', 'findutils', 'util-linux', 'bash', 'info', 'bzip2', - 'grep', 'redhat-rpm-config', 'fedora-modular-release', + 'grep', 'redhat-rpm-config', 'fedora-release', 'diffutils', 'make', 'patch', 'shadow-utils', 'coreutils', 'which', 'rpm-build', 'gzip', 'gcc-c++']), 'srpm-buildroot': set(['shadow-utils', 'redhat-rpm-config', 'rpm-build', - 'fedora-modular-release', 'fedpkg-minimal', 'gnupg2', + 'fedora-release', 'fedpkg-minimal', 'gnupg2', 'bash']) } assert result == expected @@ -165,13 +175,14 @@ class TestPDCModule: return_value=os.path.join(base_dir, 'staged_data', "local_builds")) def test_resolve_profiles_local_module(self, local_builds, conf_system): with app.app_context(): - module_build_service.utils.load_local_builds(["base-runtime"]) + module_build_service.utils.load_local_builds(['platform']) yaml_path = os.path.join( base_dir, 'staged_data', 'formatted_testmodule.yaml') mmd = modulemd.ModuleMetadata() mmd.load(yaml_path) - result = self.resolver.resolve_profiles(mmd, ('buildroot', 'srpm-buildroot')) + resolver = mbs_resolver.GenericResolver.create(tests.conf, backend='pdc') + result = resolver.resolve_profiles(mmd, ('buildroot', 'srpm-buildroot')) expected = { 'buildroot': set(['foo']), diff --git a/tests/test_scheduler/test_module_init.py b/tests/test_scheduler/test_module_init.py index 086024dd..fe940fe6 100644 --- a/tests/test_scheduler/test_module_init.py +++ b/tests/test_scheduler/test_module_init.py @@ -22,9 +22,8 @@ import os from mock import patch, PropertyMock -import vcr -from tests import conf, clean_database, get_vcr_path +from tests import conf, clean_database from tests.test_views.test_views import FakeSCM import module_build_service.messaging import module_build_service.scheduler.handlers.modules @@ -42,17 +41,13 @@ class TestModuleInit: self.staged_data_dir, 'testmodule.yaml') with open(testmodule_yml_path, 'r') as f: yaml = f.read() - scmurl = ('git://pkgs.domain.local/modules/testmodule?#da95886') + scmurl = 'git://pkgs.domain.local/modules/testmodule?#620ec77' clean_database() with make_session(conf) as session: ModuleBuild.create( session, conf, 'testmodule', '1', 3, yaml, scmurl, 'mprahl') - self.vcr = vcr.use_cassette(get_vcr_path(__file__, test_method)) - self.vcr.__enter__() - def teardown_method(self, test_method): - self.vcr.__exit__() try: path = build_logs.path(1) os.remove(path) @@ -60,7 +55,7 @@ class TestModuleInit: pass @patch('module_build_service.scm.SCM') - def test_init_basic(self, mocked_scm): + def test_init_basic(self, mocked_scm, pdc): FakeSCM(mocked_scm, 'testmodule', 'testmodule.yaml', '620ec77321b2ea7b0d67d82992dda3e1d67055b4') msg = module_build_service.messaging.MBSModule( @@ -74,7 +69,7 @@ class TestModuleInit: assert type(build.mmd().xmd['mbs']) is dict @patch('module_build_service.scm.SCM') - def test_init_scm_not_available(self, mocked_scm): + def test_init_scm_not_available(self, mocked_scm, pdc): def mocked_scm_get_latest(): raise RuntimeError("Failed in mocked_scm_get_latest") @@ -93,13 +88,13 @@ class TestModuleInit: @patch("module_build_service.config.Config.modules_allow_repository", new_callable=PropertyMock, return_value=True) @patch('module_build_service.scm.SCM') - def test_init_includedmodule(self, mocked_scm, mocked_mod_allow_repo): + def test_init_includedmodule(self, mocked_scm, mocked_mod_allow_repo, pdc): FakeSCM(mocked_scm, "includedmodules", ['testmodule.yaml']) includedmodules_yml_path = os.path.join( self.staged_data_dir, 'includedmodules.yaml') with open(includedmodules_yml_path, 'r') as f: yaml = f.read() - scmurl = ('git://pkgs.domain.local/modules/includedmodule?#da95886') + scmurl = 'git://pkgs.domain.local/modules/includedmodule?#da95886' with make_session(conf) as session: ModuleBuild.create( session, conf, 'includemodule', '1', 3, yaml, scmurl, 'mprahl') @@ -112,24 +107,24 @@ class TestModuleInit: batches = {} for comp_build in ComponentBuild.query.filter_by(module_id=2).all(): batches[comp_build.package] = comp_build.batch - assert batches['ed'] == 2 assert batches['perl-List-Compare'] == 2 assert batches['perl-Tangerine'] == 2 + assert batches['foo'] == 2 assert batches['tangerine'] == 3 assert batches['file'] == 4 # Test that the RPMs are properly merged in xmd xmd_rpms = { - 'ed': {'ref': '40bd001563'}, - 'perl-List-Compare': {'ref': '2ee8474e44'}, - 'tangerine': {'ref': 'd29d5c24b8'}, + 'perl-List-Compare': {'ref': '4f26aeafdb'}, + 'perl-Tangerine': {'ref': '4f26aeafdb'}, + 'tangerine': {'ref': '4f26aeafdb'}, + 'foo': {'ref': '93dea37599'}, 'file': {'ref': 'a2740663f8'}, - 'perl-Tangerine': {'ref': '27785f9f05'} } assert build.mmd().xmd['mbs']['rpms'] == xmd_rpms @patch('module_build_service.models.ModuleBuild.from_module_event') @patch('module_build_service.scm.SCM') - def test_init_when_get_latest_raises(self, mocked_scm, mocked_from_module_event): + def test_init_when_get_latest_raises(self, mocked_scm, mocked_from_module_event, pdc): FakeSCM(mocked_scm, 'testmodule', 'testmodule.yaml', '7035bd33614972ac66559ac1fdd019ff6027ad22', get_latest_raise=True) diff --git a/tests/test_scheduler/test_module_wait.py b/tests/test_scheduler/test_module_wait.py index 574ab526..badd7744 100644 --- a/tests/test_scheduler/test_module_wait.py +++ b/tests/test_scheduler/test_module_wait.py @@ -26,9 +26,8 @@ import module_build_service.messaging import module_build_service.scheduler.handlers.modules import modulemd as _modulemd import os -import vcr import koji -from tests import conf, db, app, scheduler_init_data, get_vcr_path +from tests import conf, db, app, scheduler_init_data from module_build_service import build_logs from module_build_service.models import ComponentBuild, ModuleBuild @@ -41,11 +40,7 @@ class TestModuleWait: self.session = mock.Mock() self.fn = module_build_service.scheduler.handlers.modules.wait - self.vcr = vcr.use_cassette(get_vcr_path(__file__, test_method)) - self.vcr.__enter__() - def teardown_method(self, test_method): - self.vcr.__exit__() try: path = build_logs.path(1) os.remove(path) diff --git a/tests/test_scheduler/test_poller.py b/tests/test_scheduler/test_poller.py index dc5df932..a69362c8 100644 --- a/tests/test_scheduler/test_poller.py +++ b/tests/test_scheduler/test_poller.py @@ -18,7 +18,6 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -from os import path from mock import patch from module_build_service import models, conf from tests import test_reuse_component_init_data, init_data, db @@ -28,10 +27,6 @@ from module_build_service.scheduler.producer import MBSProducer import six.moves.queue as queue from datetime import datetime, timedelta -BASE_DIR = path.abspath(path.dirname(__file__)) -CASSETTES_DIR = path.join( - path.abspath(path.dirname(__file__)), '..', 'vcr-request-data') - @patch("module_build_service.builder.GenericBuilder.default_buildroot_groups", return_value={'build': [], 'srpm-build': []}) @@ -115,7 +110,7 @@ class TestPoller: poller = MBSProducer(hub) poller.poll() - koji_session.newRepo.assert_called_once_with("module-testmodule-build") + koji_session.newRepo.assert_called_once_with("module-fe3adf73caf3e1b7-build") def test_trigger_new_repo_when_succeded(self, create_builder, koji_get_session, global_consumer, diff --git a/tests/test_scheduler/test_repo_done.py b/tests/test_scheduler/test_repo_done.py index 3ce8649b..2ae681bd 100644 --- a/tests/test_scheduler/test_repo_done.py +++ b/tests/test_scheduler/test_repo_done.py @@ -20,16 +20,12 @@ # # Written by Ralph Bean -from os.path import dirname import mock -import vcr import module_build_service.messaging import module_build_service.scheduler.handlers.repos import module_build_service.models -from tests import conf, db, app, scheduler_init_data, get_vcr_path - -base_dir = dirname(dirname(__file__)) +from tests import conf, db, app, scheduler_init_data class TestRepoDone: @@ -37,12 +33,6 @@ class TestRepoDone: def setup_method(self, test_method): scheduler_init_data() - self.vcr = vcr.use_cassette(get_vcr_path(__file__, test_method)) - self.vcr.__enter__() - - def teardown_method(self, test_method): - self.vcr.__exit__() - @mock.patch('module_build_service.models.ModuleBuild.from_repo_done_event') def test_no_match(self, from_repo_done_event): """ Test that when a repo msg hits us and we have no match, @@ -71,20 +61,20 @@ class TestRepoDone: @mock.patch('module_build_service.builder.KojiModuleBuilder.' 'KojiModuleBuilder.buildroot_connect') def test_a_single_match(self, connect, build_fn, get_session, ready, list_tasks_fn, mock_gabt, - mock_uea): + mock_uea, pdc): """ Test that when a repo msg hits us and we have a single match. """ get_session.return_value = mock.Mock(), 'development' build_fn.return_value = 1234, 1, '', None msg = module_build_service.messaging.KojiRepoChange( - 'some_msg_id', 'module-starcommand-1.3-build') + 'some_msg_id', 'module-95b214a704c984be-build') module_build_service.scheduler.handlers.repos.done( config=conf, session=db.session, msg=msg) build_fn.assert_called_once_with( - artifact_name='communicator', - source=('git://pkgs.domain.local/rpms/communicator' - '?#da95886c8a443b36a9ce31abda1f9bed22f2f9c2')) + artifact_name='tangerine', + source=('git://pkgs.fedoraproject.org/rpms/tangerine?' + '#fbed359411a1baa08d4a88e0d12d426fbf8f602c')) @mock.patch('module_build_service.builder.KojiModuleBuilder.' 'KojiModuleBuilder.recover_orphaned_artifact', return_value=[]) @@ -103,24 +93,24 @@ class TestRepoDone: @mock.patch('module_build_service.builder.KojiModuleBuilder.' 'KojiModuleBuilder.buildroot_connect') def test_a_single_match_build_fail(self, connect, build_fn, config, ready, list_tasks_fn, - mock_gabt, mock_uea): + mock_gabt, mock_uea, pdc): """ Test that when a KojiModuleBuilder.build fails, the build is marked as failed with proper state_reason. """ config.return_value = mock.Mock(), 'development' - build_fn.return_value = None, 4, 'Failed to submit artifact communicator to Koji', None + build_fn.return_value = None, 4, 'Failed to submit artifact tangerine to Koji', None msg = module_build_service.messaging.KojiRepoChange( - 'some_msg_id', 'module-starcommand-1.3-build') + 'some_msg_id', 'module-95b214a704c984be-build') module_build_service.scheduler.handlers.repos.done( config=conf, session=db.session, msg=msg) build_fn.assert_called_once_with( - artifact_name='communicator', - source=('git://pkgs.domain.local/rpms/communicator' - '?#da95886c8a443b36a9ce31abda1f9bed22f2f9c2')) + artifact_name='tangerine', + source=('git://pkgs.fedoraproject.org/rpms/tangerine?' + '#fbed359411a1baa08d4a88e0d12d426fbf8f602c')) component_build = module_build_service.models.ComponentBuild.query\ - .filter_by(package='communicator').one() - assert component_build.state_reason == 'Failed to submit artifact communicator to Koji' + .filter_by(package='tangerine').one() + assert component_build.state_reason == 'Failed to submit artifact tangerine to Koji' @mock.patch('module_build_service.scheduler.handlers.repos.log.info') def test_erroneous_regen_repo_received(self, mock_log_info): @@ -129,9 +119,9 @@ class TestRepoDone: """ scheduler_init_data(1) msg = module_build_service.messaging.KojiRepoChange( - 'some_msg_id', 'module-starcommand-1.3-build') + 'some_msg_id', 'module-95b214a704c984be-build') component_build = module_build_service.models.ComponentBuild.query\ - .filter_by(package='communicator').one() + .filter_by(package='tangerine').one() component_build.tagged = False db.session.add(component_build) db.session.commit() @@ -166,10 +156,9 @@ class TestRepoDone: build_fn.return_value = None, 4, 'Failed to submit artifact communicator to Koji', None msg = module_build_service.messaging.KojiRepoChange( - 'some_msg_id', 'module-starcommand-1.3-build') + 'some_msg_id', 'module-95b214a704c984be-build') module_build_service.scheduler.handlers.repos.done( config=conf, session=db.session, msg=msg) - module_build = module_build_service.models.ModuleBuild.query\ - .filter_by(name='starcommand').one() + module_build = module_build_service.models.ModuleBuild.query.first() assert module_build.state == module_build_service.models.BUILD_STATES["failed"] diff --git a/tests/test_scheduler/test_tag_tagged.py b/tests/test_scheduler/test_tag_tagged.py index ec25b549..5a0ea3eb 100644 --- a/tests/test_scheduler/test_tag_tagged.py +++ b/tests/test_scheduler/test_tag_tagged.py @@ -54,7 +54,7 @@ class TestTagTagged: that we do nothing gracefully. """ msg = module_build_service.messaging.KojiTagChange( - 'id', 'module-testmodule-build', "artifact") + 'id', 'module-fe3adf73caf3e1b7-build', "artifact") module_build_service.scheduler.handlers.tags.tagged( config=conf, session=db.session, msg=msg) @@ -75,7 +75,7 @@ class TestTagTagged: builder = mock.MagicMock() builder.koji_session = koji_session builder.buildroot_ready.return_value = False - builder.module_build_tag = {"name": "module-testmodule-build"} + builder.module_build_tag = {"name": "module-fe3adf73caf3e1b7-build"} create_builder.return_value = builder module_build = module_build_service.models.ModuleBuild.query.filter_by(id=2).one() @@ -94,12 +94,12 @@ class TestTagTagged: # Tag the first component to the buildroot. msg = module_build_service.messaging.KojiTagChange( - 'id', 'module-testmodule-build', "perl-Tangerine") + 'id', 'module-fe3adf73caf3e1b7-build', "perl-Tangerine") module_build_service.scheduler.handlers.tags.tagged( config=conf, session=db.session, msg=msg) # Tag the first component to the final tag. msg = module_build_service.messaging.KojiTagChange( - 'id', 'module-testmodule', "perl-Tangerine") + 'id', 'module-fe3adf73caf3e1b7', "perl-Tangerine") module_build_service.scheduler.handlers.tags.tagged( config=conf, session=db.session, msg=msg) @@ -109,7 +109,7 @@ class TestTagTagged: # Tag the second component to the buildroot. msg = module_build_service.messaging.KojiTagChange( - 'id', 'module-testmodule-build', "perl-List-Compare") + 'id', 'module-fe3adf73caf3e1b7-build', "perl-List-Compare") module_build_service.scheduler.handlers.tags.tagged( config=conf, session=db.session, msg=msg) @@ -119,12 +119,12 @@ class TestTagTagged: # Tag the first component to the final tag. msg = module_build_service.messaging.KojiTagChange( - 'id', 'module-testmodule', "perl-List-Compare") + 'id', 'module-fe3adf73caf3e1b7', "perl-List-Compare") module_build_service.scheduler.handlers.tags.tagged( config=conf, session=db.session, msg=msg) # newRepo should be called now - all components have been tagged. - koji_session.newRepo.assert_called_once_with("module-testmodule-build") + koji_session.newRepo.assert_called_once_with("module-fe3adf73caf3e1b7-build") # Refresh our module_build object. db.session.expunge(module_build) @@ -151,7 +151,7 @@ class TestTagTagged: builder = mock.MagicMock() builder.koji_session = koji_session builder.buildroot_ready.return_value = False - builder.module_build_tag = {"name": "module-testmodule-build"} + builder.module_build_tag = {"name": "module-fe3adf73caf3e1b7-build"} create_builder.return_value = builder module_build = module_build_service.models.ModuleBuild.query.filter_by(id=2).one() @@ -163,12 +163,12 @@ class TestTagTagged: # Tag the perl-List-Compare component to the buildroot. msg = module_build_service.messaging.KojiTagChange( - 'id', 'module-testmodule-build', "perl-Tangerine") + 'id', 'module-fe3adf73caf3e1b7-build', "perl-Tangerine") module_build_service.scheduler.handlers.tags.tagged( config=conf, session=db.session, msg=msg) # Tag the perl-List-Compare component to final tag. msg = module_build_service.messaging.KojiTagChange( - 'id', 'module-testmodule', "perl-Tangerine") + 'id', 'module-fe3adf73caf3e1b7', "perl-Tangerine") module_build_service.scheduler.handlers.tags.tagged( config=conf, session=db.session, msg=msg) @@ -193,7 +193,7 @@ class TestTagTagged: builder = mock.MagicMock() builder.koji_session = koji_session builder.buildroot_ready.return_value = False - builder.module_build_tag = {"name": "module-testmodule-build"} + builder.module_build_tag = {"name": "module-fe3adf73caf3e1b7-build"} create_builder.return_value = builder module_build = module_build_service.models.ModuleBuild.query.filter_by(id=2).one() @@ -216,18 +216,18 @@ class TestTagTagged: # Tag the perl-List-Compare component to the buildroot. msg = module_build_service.messaging.KojiTagChange( - 'id', 'module-testmodule-build', "perl-List-Compare") + 'id', 'module-fe3adf73caf3e1b7-build', "perl-List-Compare") module_build_service.scheduler.handlers.tags.tagged( config=conf, session=db.session, msg=msg) # Tag the perl-List-Compare component to final tag. msg = module_build_service.messaging.KojiTagChange( - 'id', 'module-testmodule', "perl-List-Compare") + 'id', 'module-fe3adf73caf3e1b7', "perl-List-Compare") module_build_service.scheduler.handlers.tags.tagged( config=conf, session=db.session, msg=msg) # newRepo should be called now - all successfully built # components have been tagged. - koji_session.newRepo.assert_called_once_with("module-testmodule-build") + koji_session.newRepo.assert_called_once_with("module-fe3adf73caf3e1b7-build") # Refresh our module_build object. db.session.expunge(module_build) @@ -257,7 +257,7 @@ class TestTagTagged: builder = mock.MagicMock() builder.koji_session = koji_session builder.buildroot_ready.return_value = False - builder.module_build_tag = {"name": "module-testmodule-build"} + builder.module_build_tag = {"name": "module-fe3adf73caf3e1b7-build"} create_builder.return_value = builder module_build = module_build_service.models.ModuleBuild.query.filter_by(id=2).one() @@ -272,12 +272,12 @@ class TestTagTagged: # Tag the first component to the buildroot. msg = module_build_service.messaging.KojiTagChange( - 'id', 'module-testmodule-build', "perl-Tangerine") + 'id', 'module-fe3adf73caf3e1b7-build', "perl-Tangerine") module_build_service.scheduler.handlers.tags.tagged( config=conf, session=db.session, msg=msg) # Tag the first component to the final tag. msg = module_build_service.messaging.KojiTagChange( - 'id', 'module-testmodule', "perl-Tangerine") + 'id', 'module-fe3adf73caf3e1b7', "perl-Tangerine") module_build_service.scheduler.handlers.tags.tagged( config=conf, session=db.session, msg=msg) @@ -287,12 +287,12 @@ class TestTagTagged: # Tag the second component to the buildroot. msg = module_build_service.messaging.KojiTagChange( - 'id', 'module-testmodule-build', "perl-List-Compare") + 'id', 'module-fe3adf73caf3e1b7-build', "perl-List-Compare") module_build_service.scheduler.handlers.tags.tagged( config=conf, session=db.session, msg=msg) # Tag the second component to final tag. msg = module_build_service.messaging.KojiTagChange( - 'id', 'module-testmodule', "perl-List-Compare") + 'id', 'module-fe3adf73caf3e1b7', "perl-List-Compare") module_build_service.scheduler.handlers.tags.tagged( config=conf, session=db.session, msg=msg) @@ -302,17 +302,17 @@ class TestTagTagged: # Tag the component from first batch to final tag. msg = module_build_service.messaging.KojiTagChange( - 'id', 'module-testmodule', "module-build-macros") + 'id', 'module-fe3adf73caf3e1b7', "module-build-macros") module_build_service.scheduler.handlers.tags.tagged( config=conf, session=db.session, msg=msg) # Tag the component from first batch to the buildroot. msg = module_build_service.messaging.KojiTagChange( - 'id', 'module-testmodule-build', "module-build-macros") + 'id', 'module-fe3adf73caf3e1b7-build', "module-build-macros") module_build_service.scheduler.handlers.tags.tagged( config=conf, session=db.session, msg=msg) # newRepo should be called now - all components have been tagged. - koji_session.newRepo.assert_called_once_with("module-testmodule-build") + koji_session.newRepo.assert_called_once_with("module-fe3adf73caf3e1b7-build") # Refresh our module_build object. db.session.expunge(module_build) @@ -340,7 +340,7 @@ class TestTagTagged: builder = mock.MagicMock() builder.koji_session = koji_session builder.buildroot_ready.return_value = False - builder.module_build_tag = {"name": "module-testmodule-build"} + builder.module_build_tag = {"name": "module-fe3adf73caf3e1b7-build"} create_builder.return_value = builder module_build = module_build_service.models.ModuleBuild.query.filter_by(id=2).one() @@ -366,24 +366,24 @@ class TestTagTagged: # Tag the perl-Tangerine component to the buildroot. msg = module_build_service.messaging.KojiTagChange( - 'id', 'module-testmodule-build', "perl-Tangerine") + 'id', 'module-fe3adf73caf3e1b7-build', "perl-Tangerine") module_build_service.scheduler.handlers.tags.tagged( config=conf, session=db.session, msg=msg) assert not koji_session.newRepo.called # Tag the perl-List-Compare component to the buildroot. msg = module_build_service.messaging.KojiTagChange( - 'id', 'module-testmodule-build', "perl-List-Compare") + 'id', 'module-fe3adf73caf3e1b7-build', "perl-List-Compare") module_build_service.scheduler.handlers.tags.tagged( config=conf, session=db.session, msg=msg) # Tag the perl-List-Compare component to final tag. msg = module_build_service.messaging.KojiTagChange( - 'id', 'module-testmodule', "perl-List-Compare") + 'id', 'module-fe3adf73caf3e1b7', "perl-List-Compare") module_build_service.scheduler.handlers.tags.tagged( config=conf, session=db.session, msg=msg) # newRepo should be called now - all successfully built # components have been tagged. - koji_session.newRepo.assert_called_once_with("module-testmodule-build") + koji_session.newRepo.assert_called_once_with("module-fe3adf73caf3e1b7-build") # Refresh our module_build object. db.session.expunge(module_build) diff --git a/tests/test_utils/test_utils.py b/tests/test_utils/test_utils.py index 634f0bd9..3532bf67 100644 --- a/tests/test_utils/test_utils.py +++ b/tests/test_utils/test_utils.py @@ -22,7 +22,6 @@ import tempfile from os import path, mkdir from shutil import copyfile, rmtree from datetime import datetime -import vcr import modulemd from werkzeug.datastructures import FileStorage from mock import patch @@ -42,8 +41,6 @@ from module_build_service.builder.KojiModuleBuilder import KojiModuleBuilder from tests import app BASE_DIR = path.abspath(path.dirname(__file__)) -CASSETTES_DIR = path.join( - path.abspath(path.dirname(__file__)), '..', 'vcr-request-data') class FakeSCM(object): @@ -82,290 +79,117 @@ class FakeSCM(object): class TestUtils: def setup_method(self, test_method): - self.filtered_rpms = [ - u'sqlite-tcl-0:3.17.0-2.module_5ccf9229', - u'sqlite-analyzer-0:3.17.0-2.module_5ccf9229', - u'emacs-gettext-0:0.19.8.1-8.module_5ccf9229', - u'msghack-0:0.19.8.1-8.module_5ccf9229', - u'modeline2fb-0:2.1-40.module_5ccf9229', - u'audit-libs-python-0:2.7.3-1.module_5ccf9229', - u'audit-libs-python3-0:2.7.3-1.module_5ccf9229', - u'audispd-plugins-zos-0:2.7.3-1.module_5ccf9229', - u'audit-0:2.7.3-1.module_5ccf9229', - u'audispd-plugins-0:2.7.3-1.module_5ccf9229', - u'librepo-devel-0:1.7.20-3.module_5ccf9229', - u'python2-librepo-0:1.7.20-3.module_5ccf9229', - u'libcap-ng-python-0:0.7.8-3.module_5ccf9229', - u'iptables-compat-0:1.6.1-2.module_5ccf9229', - u'gobject-introspection-devel-0:1.52.0-1.module_5ccf9229', - u'ntsysv-0:1.9-1.module_5ccf9229', - u'pyparsing-0:2.1.10-3.module_5ccf9229', - u'python2-pyparsing-0:2.1.10-3.module_5ccf9229', - u'python2-appdirs-0:1.4.0-10.module_5ccf9229', - u'krb5-server-ldap-0:1.15-9.module_5ccf9229', - u'krb5-server-0:1.15-9.module_5ccf9229', - u'python-libxml2-0:2.9.4-2.module_5ccf9229', - u'libsemanage-python-0:2.6-2.module_5ccf9229', - u'python2-setuptools-0:34.3.0-1.module_5ccf9229', - u'libpeas-loader-python-0:1.20.0-5.module_5ccf9229', - u'libpeas-devel-0:1.20.0-5.module_5ccf9229', - u'libpeas-loader-python3-0:1.20.0-5.module_5ccf9229', - u'libpeas-gtk-0:1.20.0-5.module_5ccf9229', - u'python2-six-0:1.10.0-8.module_5ccf9229', - u'libtool-0:2.4.6-17.module_5ccf9229', - u'libverto-tevent-0:0.2.6-7.module_5ccf9229', - u'libverto-libevent-devel-0:0.2.6-7.module_5ccf9229', - u'libverto-tevent-devel-0:0.2.6-7.module_5ccf9229', - u'libverto-libevent-0:0.2.6-7.module_5ccf9229', - u'emacs-nox-1:25.2-0.1.rc2.module_5ccf9229', - u'emacs-common-1:25.2-0.1.rc2.module_5ccf9229', - u'emacs-1:25.2-0.1.rc2.module_5ccf9229', - u'emacs-terminal-1:25.2-0.1.rc2.module_5ccf9229', - u'python2-rpm-0:4.13.0.1-3.module_5ccf9229', - u'rpm-cron-0:4.13.0.1-3.module_5ccf9229', - u'cryptsetup-python-0:1.7.3-3.module_5ccf9229', - u'kernel-rpm-macros-0:63-1.module_5ccf9229', - u'cracklib-python-0:2.9.6-5.module_5ccf9229', - u'gnupg2-smime-0:2.1.18-2.module_5ccf9229', - u'qt5-rpm-macros-0:5.8.0-2.module_5ccf9229', - u'qt5-devel-0:5.8.0-2.module_5ccf9229', - u'qt5-0:5.8.0-2.module_5ccf9229', - u'texinfo-0:6.3-2.module_5ccf9229', - u'texinfo-tex-0:6.3-2.module_5ccf9229', - u'python-magic-0:5.30-5.module_5ccf9229', - u'lvm2-dbusd-0:2.02.168-4.module_5ccf9229', - u'cmirror-standalone-0:2.02.168-4.module_5ccf9229', - u'lvm2-python-libs-0:2.02.168-4.module_5ccf9229', - u'lvm2-cluster-0:2.02.168-4.module_5ccf9229', - u'cmirror-0:2.02.168-4.module_5ccf9229', - u'lvm2-cluster-standalone-0:2.02.168-4.module_5ccf9229', - u'lvm2-lockd-0:2.02.168-4.module_5ccf9229', - u'libselinux-ruby-0:2.6-2.module_5ccf9229', - u'libselinux-python-0:2.6-2.module_5ccf9229', - u'hfsutils-x11-0:3.2.6-31.module_5ccf9229', - u'glib2-fam-0:2.52.0-1.module_5ccf9229', - u'glib2-static-0:2.52.0-1.module_5ccf9229', - u'glib2-devel-0:2.52.0-1.module_5ccf9229', - u'syslinux-perl-0:6.04-0.2.module_5ccf9229', - u'perl-solv-0:0.6.26-1.module_5ccf9229', - u'python2-solv-0:0.6.26-1.module_5ccf9229', - u'cyrus-sasl-sql-0:2.1.26-30.module_5ccf9229', - u'openssl-perl-1:1.1.0e-1.module_5ccf9229', - u'libidn-java-0:1.33-2.module_5ccf9229', - u'libidn-javadoc-0:1.33-2.module_5ccf9229', - u'libbabeltrace-devel-0:1.5.2-2.module_5ccf9229', - u'grub2-starfield-theme-1:2.02-0.38.module_5ccf9229', - u'util-linux-user-0:2.29.1-2.module_5ccf9229', - u'freetype-demos-0:2.7.1-2.module_5ccf9229', - u'python2-packaging-0:16.8-4.module_5ccf9229', - u'python-pwquality-0:1.3.0-8.module_5ccf9229', - u'python2-pip-0:9.0.1-7.module_5ccf9229', - u'gnutls-devel-0:3.5.10-1.module_5ccf9229', - u'gnutls-guile-0:3.5.10-1.module_5ccf9229', - u'gnutls-utils-0:3.5.10-1.module_5ccf9229', - u'gnutls-dane-0:3.5.10-1.module_5ccf9229', - u'python3-tkinter-0:3.6.0-21.module_5ccf9229', - u'python3-tools-0:3.6.0-21.module_5ccf9229', - u'python3-debug-0:3.6.0-21.module_5ccf9229', - u'python3-test-0:3.6.0-21.module_5ccf9229', - u'libssh2-devel-0:1.8.0-2.module_5ccf9229', - u'python2-gpg-0:1.9.0-1.module_5ccf9229', - u'qgpgme-devel-0:1.9.0-1.module_5ccf9229', - u'qgpgme-0:1.9.0-1.module_5ccf9229', - u'dbus-x11-1:1.11.10-2.module_5ccf9229', - u'libcroco-devel-0:0.6.11-3.module_5ccf9229', - u'kernel-devel-0:4.11.0-0.rc7.git0.1.module_5ccf9229', - u'python-perf-0:4.11.0-0.rc7.git0.1.module_5ccf9229', - u'perf-0:4.11.0-0.rc7.git0.1.module_5ccf9229', - u'kernel-tools-libs-devel-0:4.11.0-0.rc7.git0.1.module_5ccf9229', - u'kernel-lpae-devel-0:4.11.0-0.rc7.git0.1.module_5ccf9229', - u'kernel-tools-0:4.11.0-0.rc7.git0.1.module_5ccf9229', - u'kernel-PAEdebug-devel-0:4.11.0-0.rc7.git0.1.module_5ccf9229', - u'kernel-PAE-devel-0:4.11.0-0.rc7.git0.1.module_5ccf9229', - u'kernel-debug-devel-0:4.11.0-0.rc7.git0.1.module_5ccf9229', - u'openldap-servers-0:2.4.44-8.module_5ccf9229', - u'systemd-journal-remote-0:233-3.module_5ccf9229', - u'glibc-utils-0:2.25-4.module_5ccf9229', - u'glibc-benchtests-0:2.25-4.module_5ccf9229', - u'libdnf-devel-0:0.8.2-1.module_987f08f4', - u'python2-hawkey-0:0.8.2-1.module_987f08f4', - u'sssd-nfs-idmap-0:1.15.2-4.module_47fecbcd', - u'python3-libipa_hbac-0:1.15.2-4.module_47fecbcd', - u'sssd-ipa-0:1.15.2-4.module_47fecbcd', - u'libsss_simpleifp-devel-0:1.15.2-4.module_47fecbcd', - u'python2-libipa_hbac-0:1.15.2-4.module_47fecbcd', - u'sssd-libwbclient-0:1.15.2-4.module_47fecbcd', - u'python3-sss-murmur-0:1.15.2-4.module_47fecbcd', - u'libsss_nss_idmap-devel-0:1.15.2-4.module_47fecbcd', - u'python2-sss-0:1.15.2-4.module_47fecbcd', - u'libsss_simpleifp-0:1.15.2-4.module_47fecbcd', - u'sssd-ldap-0:1.15.2-4.module_47fecbcd', - u'python3-sss-0:1.15.2-4.module_47fecbcd', - u'sssd-common-0:1.15.2-4.module_47fecbcd', - u'sssd-krb5-0:1.15.2-4.module_47fecbcd', - u'sssd-libwbclient-devel-0:1.15.2-4.module_47fecbcd', - u'libipa_hbac-0:1.15.2-4.module_47fecbcd', - u'sssd-winbind-idmap-0:1.15.2-4.module_47fecbcd', - u'python2-sss-murmur-0:1.15.2-4.module_47fecbcd', - u'sssd-tools-0:1.15.2-4.module_47fecbcd', - u'sssd-dbus-0:1.15.2-4.module_47fecbcd', - u'sssd-ad-0:1.15.2-4.module_47fecbcd', - u'sssd-krb5-common-0:1.15.2-4.module_47fecbcd', - u'libsss_autofs-0:1.15.2-4.module_47fecbcd', - u'python2-libsss_nss_idmap-0:1.15.2-4.module_47fecbcd', - u'libsss_idmap-devel-0:1.15.2-4.module_47fecbcd', - u'sssd-common-pac-0:1.15.2-4.module_47fecbcd', - u'sssd-0:1.15.2-4.module_47fecbcd', - u'sssd-proxy-0:1.15.2-4.module_47fecbcd', - u'libsss_sudo-0:1.15.2-4.module_47fecbcd', - u'libipa_hbac-devel-0:1.15.2-4.module_47fecbcd', - u'python3-sssdconfig-0:1.15.2-4.module_47fecbcd', - u'python2-sssdconfig-0:1.15.2-4.module_47fecbcd', - u'dracut-live-0:044-182.module_bd7491c8', - u'dracut-fips-aesni-0:044-182.module_bd7491c8', - u'dracut-network-0:044-182.module_bd7491c8', - u'dracut-fips-0:044-182.module_bd7491c8', - u'iproute-tc-0:4.11.0-1.module_d6de39f1' - ] + init_data() def teardown_method(self, test_method): init_data() - @vcr.use_cassette( - path.join(CASSETTES_DIR, 'tests.test_utils.TestUtils.test_format_mmd')) + @pytest.mark.parametrize('scmurl', [ + ('git://pkgs.stg.fedoraproject.org/modules/testmodule.git' + '?#620ec77321b2ea7b0d67d82992dda3e1d67055b4'), + None + ]) @patch('module_build_service.scm.SCM') - def test_format_mmd(self, mocked_scm): + def test_format_mmd(self, mocked_scm, scmurl, pdc): mocked_scm.return_value.commit = \ '620ec77321b2ea7b0d67d82992dda3e1d67055b4' # For all the RPMs in testmodule, get_latest is called + mocked_scm.return_value.get_latest.side_effect = [ + '4ceea43add2366d8b8c5a622a2fb563b625b9abf', + 'fbed359411a1baa08d4a88e0d12d426fbf8f602c'] hashes_returned = { - 'f24': '4ceea43add2366d8b8c5a622a2fb563b625b9abf', - 'f23': 'fbed359411a1baa08d4a88e0d12d426fbf8f602c', - 'f25': '76f9d8c8e87eed0aab91034b01d3d5ff6bd5b4cb'} - original_refs = ["f23", "f24", "f25"] + 'master': 'fbed359411a1baa08d4a88e0d12d426fbf8f602c', + 'f28': '4ceea43add2366d8b8c5a622a2fb563b625b9abf', + 'f27': '5deef23acd2367d8b8d5a621a2fc568b695bc3bd'} def mocked_get_latest(ref="master"): return hashes_returned[ref] mocked_scm.return_value.get_latest = mocked_get_latest mmd = modulemd.ModuleMetadata() - with open(path.join(BASE_DIR, '..', 'staged_data', 'testmodule.yaml')) \ - as mmd_file: - mmd.loads(mmd_file) - scmurl = \ - ('git://pkgs.stg.fedoraproject.org/modules/testmodule.git' - '?#620ec77321b2ea7b0d67d82992dda3e1d67055b4') + mmd.load(path.join(BASE_DIR, '..', 'staged_data', 'testmodule.yaml')) + # Modify the component branches so we can identify them later on + mmd.components.rpms['perl-Tangerine'].ref = 'f28' + mmd.components.rpms['tangerine'].ref = 'f27' module_build_service.utils.format_mmd(mmd, scmurl) # Make sure that original refs are not changed. mmd_pkg_refs = [pkg.ref for pkg in mmd.components.rpms.values()] - assert set(mmd_pkg_refs) == set(original_refs) + assert set(mmd_pkg_refs) == set(hashes_returned.keys()) - assert mmd.buildrequires == {'base-runtime': 'master'} - xmd = { - 'mbs': { - 'commit': '620ec77321b2ea7b0d67d82992dda3e1d67055b4', - 'buildrequires': { - 'base-runtime': { - 'ref': '147dca4ca65aa9a1ac51f71b7e687f9178ffa5df', - 'stream': 'master', - 'version': '20170616125652', - 'filtered_rpms': self.filtered_rpms}}, - 'requires': { - 'base-runtime': { - 'version': '20170616125652', - 'ref': '147dca4ca65aa9a1ac51f71b7e687f9178ffa5df', - 'stream': 'master', - 'filtered_rpms': self.filtered_rpms}}, - 'rpms': {'perl-List-Compare': {'ref': '76f9d8c8e87eed0aab91034b01d3d5ff6bd5b4cb'}, - 'perl-Tangerine': {'ref': '4ceea43add2366d8b8c5a622a2fb563b625b9abf'}, - 'tangerine': {'ref': 'fbed359411a1baa08d4a88e0d12d426fbf8f602c'}}, - 'scmurl': 'git://pkgs.stg.fedoraproject.org/modules/testmodule' - '.git?#620ec77321b2ea7b0d67d82992dda3e1d67055b4', - } - } - - assert mmd.xmd == xmd - - @vcr.use_cassette( - path.join(CASSETTES_DIR, 'tests.test_utils.TestUtils.test_format_mmd')) - @patch('module_build_service.scm.SCM') - def test_format_mmd_empty_scmurl(self, mocked_scm): - # For all the RPMs in testmodule, get_latest is called - hashes_returned = { - 'f24': '4ceea43add2366d8b8c5a622a2fb563b625b9abf', - 'f23': 'fbed359411a1baa08d4a88e0d12d426fbf8f602c', - 'f25': '76f9d8c8e87eed0aab91034b01d3d5ff6bd5b4cb'} - - def mocked_get_latest(branch="master"): - return hashes_returned[branch] - mocked_scm.return_value.get_latest = mocked_get_latest - - mmd = modulemd.ModuleMetadata() - with open(path.join(BASE_DIR, '..', 'staged_data', 'testmodule.yaml')) \ - as mmd_file: - mmd.loads(mmd_file) - - module_build_service.utils.format_mmd(mmd, scmurl=None) + assert mmd.buildrequires == {'platform': 'f28'} xmd = { 'mbs': { 'commit': None, 'buildrequires': { - 'base-runtime': { - 'ref': '147dca4ca65aa9a1ac51f71b7e687f9178ffa5df', - 'stream': 'master', - 'version': '20170616125652', - 'filtered_rpms': self.filtered_rpms}}, + 'platform': { + 'ref': 'virtual', + 'stream': 'f28', + 'version': '3', + 'filtered_rpms': []}}, 'requires': { - 'base-runtime': { - 'version': '20170616125652', - 'ref': '147dca4ca65aa9a1ac51f71b7e687f9178ffa5df', - 'stream': 'master', - 'filtered_rpms': self.filtered_rpms}}, - 'rpms': {'perl-List-Compare': {'ref': '76f9d8c8e87eed0aab91034b01d3d5ff6bd5b4cb'}, - 'perl-Tangerine': {'ref': '4ceea43add2366d8b8c5a622a2fb563b625b9abf'}, - 'tangerine': {'ref': 'fbed359411a1baa08d4a88e0d12d426fbf8f602c'}}, - 'scmurl': None, + 'platform': { + 'version': '3', + 'ref': 'virtual', + 'stream': 'f28', + 'filtered_rpms': []}}, + 'rpms': { + 'perl-List-Compare': {'ref': 'fbed359411a1baa08d4a88e0d12d426fbf8f602c'}, + 'perl-Tangerine': {'ref': '4ceea43add2366d8b8c5a622a2fb563b625b9abf'}, + 'tangerine': {'ref': '5deef23acd2367d8b8d5a621a2fc568b695bc3bd'}}, + 'scmurl': None } } + if scmurl: + xmd['mbs']['commit'] = '620ec77321b2ea7b0d67d82992dda3e1d67055b4' + xmd['mbs']['scmurl'] = scmurl + assert mmd.xmd == xmd - def test_get_reusable_component_same(self): - test_reuse_component_init_data() - new_module = models.ModuleBuild.query.filter_by(id=2).one() - rv = module_build_service.utils.get_reusable_component( - db.session, new_module, 'tangerine') - assert rv.package == 'tangerine' - - def test_get_reusable_component_different_perl_tangerine(self): + @pytest.mark.parametrize('changed_component', [ + 'perl-List-Compare', 'perl-Tangerine', 'tangerine', None + ]) + def test_get_reusable_component_different_component(self, changed_component): test_reuse_component_init_data() second_module_build = models.ModuleBuild.query.filter_by(id=2).one() - mmd = second_module_build.mmd() - mmd.components.rpms['perl-Tangerine'].ref = \ - '00ea1da4192a2030f9ae023de3b3143ed647bbab' - second_module_build.modulemd = mmd.dumps() - second_module_perl_tangerine = models.ComponentBuild.query.filter_by( - package='perl-Tangerine', module_id=2).one() - second_module_perl_tangerine.ref = \ - '00ea1da4192a2030f9ae023de3b3143ed647bbab' - db.session.commit() - # Shares the same build order as the changed perl-Tangerine, but none - # of the build orders before it are different (in this case there are - # none) + if changed_component: + mmd = second_module_build.mmd() + mmd.components.rpms[changed_component].ref = '00ea1da4192a2030f9ae023de3b3143ed647bbab' + second_module_build.modulemd = mmd.dumps() + second_module_changed_component = models.ComponentBuild.query.filter_by( + package=changed_component, module_id=2).one() + second_module_changed_component.ref = '00ea1da4192a2030f9ae023de3b3143ed647bbab' + db.session.add(second_module_changed_component) + db.session.commit() + plc_rv = module_build_service.utils.get_reusable_component( db.session, second_module_build, 'perl-List-Compare') - assert plc_rv.package == 'perl-List-Compare' - - # perl-Tangerine has a different commit hash pt_rv = module_build_service.utils.get_reusable_component( db.session, second_module_build, 'perl-Tangerine') - assert pt_rv is None - - # tangerine is the same but its in a build order that is after the - # different perl-Tangerine, so it can't be reused tangerine_rv = module_build_service.utils.get_reusable_component( db.session, second_module_build, 'tangerine') - assert tangerine_rv is None + + if changed_component == 'perl-List-Compare': + # perl-Tangerine can be reused even though a component in its batch has changed + assert plc_rv is None + assert pt_rv.package == 'perl-Tangerine' + assert tangerine_rv is None + elif changed_component == 'perl-Tangerine': + # perl-List-Compare can be reused even though a component in its batch has changed + assert plc_rv.package == 'perl-List-Compare' + assert pt_rv is None + assert tangerine_rv is None + elif changed_component == 'tangerine': + # perl-List-Compare and perl-Tangerine can be reused since they are in an earlier + # buildorder than tangerine + assert plc_rv.package == 'perl-List-Compare' + assert pt_rv.package == 'perl-Tangerine' + assert tangerine_rv is None + elif changed_component is None: + # Nothing has changed so everthing can be used + assert plc_rv.package == 'perl-List-Compare' + assert pt_rv.package == 'perl-Tangerine' + assert tangerine_rv.package == 'tangerine' def test_get_reusable_component_different_rpm_macros(self): test_reuse_component_init_data() @@ -379,7 +203,6 @@ class TestUtils: db.session, second_module_build, 'perl-List-Compare') assert plc_rv is None - # perl-Tangerine has a different commit hash pt_rv = module_build_service.utils.get_reusable_component( db.session, second_module_build, 'perl-Tangerine') assert pt_rv is None @@ -388,7 +211,7 @@ class TestUtils: test_reuse_component_init_data() second_module_build = models.ModuleBuild.query.filter_by(id=2).one() mmd = second_module_build.mmd() - mmd.xmd['mbs']['buildrequires']['base-runtime']['ref'] = \ + mmd.xmd['mbs']['buildrequires']['platform']['ref'] = \ 'da39a3ee5e6b4b0d3255bfef95601890afd80709' second_module_build.modulemd = mmd.dumps() second_module_build.build_context = '37c6c57bedf4305ef41249c1794760b5cb8fad17' @@ -398,13 +221,10 @@ class TestUtils: db.session, second_module_build, 'perl-List-Compare') assert plc_rv is None - # perl-Tangerine has a different commit hash pt_rv = module_build_service.utils.get_reusable_component( db.session, second_module_build, 'perl-Tangerine') assert pt_rv is None - # tangerine is the same but its in a build order that is after the - # different perl-Tangerine, so it can't be reused tangerine_rv = module_build_service.utils.get_reusable_component( db.session, second_module_build, 'tangerine') assert tangerine_rv is None @@ -429,13 +249,10 @@ class TestUtils: db.session, second_module_build, 'perl-List-Compare') assert plc_rv is None - # perl-Tangerine has a different commit hash pt_rv = module_build_service.utils.get_reusable_component( db.session, second_module_build, 'perl-Tangerine') assert pt_rv is None - # tangerine is the same but its in a build order that is after the - # different perl-Tangerine, so it can't be reused tangerine_rv = module_build_service.utils.get_reusable_component( db.session, second_module_build, 'tangerine') assert tangerine_rv is None @@ -558,42 +375,49 @@ class TestUtils: validate_koji_tag_is_None(None) assert str(cm.value).endswith(' No value provided.') is True - @vcr.use_cassette( - path.join(CASSETTES_DIR, ('tests.test_utils.TestUtils.' - 'test_record_component_builds_duplicate_components'))) @patch('module_build_service.scm.SCM') - def test_record_component_builds_duplicate_components(self, mocked_scm): + def test_record_component_builds_duplicate_components(self, mocked_scm, pdc_module_inactive): with app.app_context(): - test_reuse_component_init_data() + clean_database() mocked_scm.return_value.commit = \ '620ec77321b2ea7b0d67d82992dda3e1d67055b4' - # For all the RPMs in testmodule, get_latest is called - hashes_returned = { - 'f25': '4ceea43add2366d8b8c5a622a2fb563b625b9abf', - 'f24': 'fbed359411a1baa08d4a88e0d12d426fbf8f602c'} + mocked_scm.return_value.get_latest.side_effect = [ + '4ceea43add2366d8b8c5a622a2fb563b625b9abf', + 'fbed359411a1baa08d4a88e0d12d426fbf8f602c'] - def mocked_get_latest(ref="master"): - return hashes_returned[ref] - - mocked_scm.return_value.get_latest = mocked_get_latest - - testmodule_variant_mmd_path = path.join( - BASE_DIR, '..', 'staged_data', 'testmodule-variant.yaml') - testmodule_variant_mmd = modulemd.ModuleMetadata() - with open(testmodule_variant_mmd_path) as mmd_file: - testmodule_variant_mmd.loads(mmd_file) - - module_build = \ - db.session.query(models.ModuleBuild).filter_by(id=1).one() - mmd = module_build.mmd() + testmodule_mmd_path = path.join(BASE_DIR, '..', 'staged_data', 'testmodule.yaml') + mmd = modulemd.ModuleMetadata() + mmd.load(testmodule_mmd_path) + mmd.name = 'testmodule-variant' + module_build = module_build_service.models.ModuleBuild() + module_build.name = 'testmodule-variant' + module_build.stream = 'master' + module_build.version = 20170109091357 + module_build.state = models.BUILD_STATES['init'] + module_build.scmurl = 'git://pkgs.stg.fedoraproject.org/modules/testmodule.git?#ff1ea79' + module_build.batch = 1 + module_build.owner = 'Tom Brady' + module_build.time_submitted = datetime(2017, 2, 15, 16, 8, 18) + module_build.time_modified = datetime(2017, 2, 15, 16, 19, 35) + module_build.rebuild_strategy = 'changed-and-after' + module_build.modulemd = mmd.dumps() + db.session.add(module_build) + db.session.commit() + # Rename the the modulemd to include + mmd.name = 'testmodule' + # Remove perl-Tangerine and tangerine from the modulemd to include so only one + # component conflicts + mmd.components.rpms.pop('perl-Tangerine') + mmd.components.rpms.pop('tangerine') error_msg = ( - 'The included module "testmodule-variant" in "testmodule" have ' + 'The included module "testmodule" in "testmodule-variant" have ' 'the following conflicting components: perl-List-Compare') with pytest.raises(UnprocessableEntity) as e: module_build_service.utils.record_component_builds( - testmodule_variant_mmd, module_build, main_mmd=mmd) - assert str(e.value) == error_msg + mmd, module_build, main_mmd=module_build.mmd()) + + assert str(e.value) == error_msg @patch("module_build_service.utils.submit_module_build") def test_submit_module_build_from_yaml_with_skiptests(self, mock_submit): @@ -630,37 +454,38 @@ class TestUtils: assert username_arg == username rmtree(module_dir) - @vcr.use_cassette( - path.join(CASSETTES_DIR, ('tests.test_utils.TestUtils.' - 'test_record_component_builds_set_weight'))) @patch('module_build_service.scm.SCM') - def test_record_component_builds_set_weight(self, mocked_scm): + def test_record_component_builds_set_weight(self, mocked_scm, pdc_module_inactive): with app.app_context(): clean_database() mocked_scm.return_value.commit = \ '620ec77321b2ea7b0d67d82992dda3e1d67055b4' - # For all the RPMs in testmodule, get_latest is called - hashes_returned = { - 'f25': '4ceea43add2366d8b8c5a622a2fb563b625b9abf', - 'f24': 'fbed359411a1baa08d4a88e0d12d426fbf8f602c'} + mocked_scm.return_value.get_latest.side_effect = [ + '4ceea43add2366d8b8c5a622a2fb563b625b9abf', + 'fbed359411a1baa08d4a88e0d12d426fbf8f602c', + 'dbed259411a1baa08d4a88e0d12d426fbf8f6037'] - def mocked_get_latest(branch="master"): - return hashes_returned[branch] + testmodule_mmd_path = path.join( + BASE_DIR, '..', 'staged_data', 'testmodule.yaml') + mmd = modulemd.ModuleMetadata() + mmd.load(testmodule_mmd_path) + module_build = module_build_service.models.ModuleBuild() + module_build.name = 'testmodule' + module_build.stream = 'master' + module_build.version = 20170109091357 + module_build.state = models.BUILD_STATES['init'] + module_build.scmurl = \ + 'git://pkgs.stg.fedoraproject.org/modules/testmodule.git?#ff1ea79' + module_build.batch = 1 + module_build.owner = 'Tom Brady' + module_build.time_submitted = datetime(2017, 2, 15, 16, 8, 18) + module_build.time_modified = datetime(2017, 2, 15, 16, 19, 35) + module_build.rebuild_strategy = 'changed-and-after' + module_build.modulemd = mmd.dumps() + db.session.add(module_build) + db.session.commit() - mocked_scm.return_value.get_latest = mocked_get_latest - - testmodule_variant_mmd_path = path.join( - BASE_DIR, '..', 'staged_data', 'testmodule-variant.yaml') - testmodule_variant_mmd = modulemd.ModuleMetadata() - with open(testmodule_variant_mmd_path) as mmd_file: - testmodule_variant_mmd.loads(mmd_file) - - mmd = testmodule_variant_mmd - module_build = models.ModuleBuild.create( - db.session, conf, "test", "stream", "1", mmd.dumps(), "scmurl", "owner") - - module_build_service.utils.record_component_builds( - mmd, module_build) + module_build_service.utils.record_component_builds(mmd, module_build) assert module_build.state == models.BUILD_STATES['init'] db.session.refresh(module_build) @@ -954,6 +779,7 @@ class TestBatches: assert pt_component.reused_component_id is None assert plc_component.state == koji.BUILD_STATES['BUILDING'] assert plc_component.reused_component_id is None + # Test the order of the scheduling expected_calls = [mock.call(builder, plc_component), mock.call(builder, pt_component)] assert mock_sbc.mock_calls == expected_calls @@ -1056,22 +882,22 @@ class TestLocalBuilds: module_build_service.utils.load_local_builds("testmodule:master:123") models.ModuleBuild.local_modules(db.session) - def test_load_local_builds_base_runtime( + def test_load_local_builds_platform( self, conf_system, conf_resultsdir): with app.app_context(): - module_build_service.utils.load_local_builds("base-runtime") + module_build_service.utils.load_local_builds("platform") local_modules = models.ModuleBuild.local_modules(db.session) assert len(local_modules) == 1 assert local_modules[0].koji_tag.endswith( - "/module-base-runtime-master-20170816080815/results") + "/module-platform-f28-3/results") - def test_load_local_builds_base_runtime_master( + def test_load_local_builds_platform_f28( self, conf_system, conf_resultsdir): with app.app_context(): - module_build_service.utils.load_local_builds("base-runtime:master") + module_build_service.utils.load_local_builds("platform:f28") local_modules = models.ModuleBuild.local_modules(db.session) assert len(local_modules) == 1 assert local_modules[0].koji_tag.endswith( - "/module-base-runtime-master-20170816080815/results") + "/module-platform-f28-3/results") diff --git a/tests/test_views/test_views.py b/tests/test_views/test_views.py index 759b3b52..5f91c6a7 100644 --- a/tests/test_views/test_views.py +++ b/tests/test_views/test_views.py @@ -21,7 +21,6 @@ # Written by Matt Prahl import json -import vcr import modulemd as _modulemd import module_build_service.scm @@ -44,7 +43,6 @@ user = ('Homer J. Simpson', set(['packager'])) other_user = ('some_other_user', set(['packager'])) anonymous_user = ('anonymous', set(['packager'])) base_dir = dirname(dirname(__file__)) -cassette_dir = base_dir + '/vcr-request-data/' class FakeSCM(object): @@ -116,16 +114,6 @@ class TestViews: self.client = app.test_client() init_data() - filename = '.'.join([ - path.splitext(path.basename(__file__))[0], - test_method.im_class.__name__, - test_method.im_func.__name__]) - self.vcr = vcr.use_cassette(path.join(cassette_dir, filename)) - self.vcr.__enter__() - - def teardown_method(self, test_method): - self.vcr.__exit__() - def test_query_build(self): rv = self.client.get('/module-build-service/1/module-builds/1') data = json.loads(rv.data) @@ -518,7 +506,7 @@ class TestViews: @patch('module_build_service.auth.get_user', return_value=user) @patch('module_build_service.scm.SCM') - def test_submit_build(self, mocked_scm, mocked_get_user): + def test_submit_build(self, mocked_scm, mocked_get_user, pdc): FakeSCM(mocked_scm, 'testmodule', 'testmodule.yaml', '620ec77321b2ea7b0d67d82992dda3e1d67055b4') @@ -835,7 +823,7 @@ class TestViews: @patch('module_build_service.scm.SCM') @patch("module_build_service.config.Config.no_auth", new_callable=PropertyMock, return_value=True) - def test_submit_build_no_auth_set_owner(self, mocked_conf, mocked_scm, mocked_get_user): + def test_submit_build_no_auth_set_owner(self, mocked_conf, mocked_scm, mocked_get_user, pdc): FakeSCM(mocked_scm, 'testmodule', 'testmodule.yaml', '620ec77321b2ea7b0d67d82992dda3e1d67055b4') @@ -854,7 +842,7 @@ class TestViews: @patch('module_build_service.auth.get_user', return_value=anonymous_user) @patch('module_build_service.scm.SCM') @patch("module_build_service.config.Config.no_auth", new_callable=PropertyMock) - def test_patch_set_different_owner(self, mocked_no_auth, mocked_scm, mocked_get_user): + def test_patch_set_different_owner(self, mocked_no_auth, mocked_scm, mocked_get_user, pdc): FakeSCM(mocked_scm, 'testmodule', 'testmodule.yaml', '620ec77321b2ea7b0d67d82992dda3e1d67055b4') @@ -898,7 +886,7 @@ class TestViews: @patch('module_build_service.auth.get_user', return_value=user) @patch('module_build_service.scm.SCM') @patch("module_build_service.config.Config.allow_custom_scmurls", new_callable=PropertyMock) - def test_submit_custom_scmurl(self, allow_custom_scmurls, mocked_scm, mocked_get_user): + def test_submit_custom_scmurl(self, allow_custom_scmurls, mocked_scm, mocked_get_user, pdc): FakeSCM(mocked_scm, 'testmodule', 'testmodule.yaml', '620ec77321b2ea7b0d67d82992dda3e1d67055b4') diff --git a/tests/vcr-request-data.tar.gz b/tests/vcr-request-data.tar.gz deleted file mode 100644 index ea4d82d5..00000000 Binary files a/tests/vcr-request-data.tar.gz and /dev/null differ