Add new tests for reusing components

This commit is contained in:
Matt Prahl
2017-02-15 14:46:02 -05:00
parent 8577d5f307
commit 8ca616ec57
4 changed files with 382 additions and 0 deletions

View File

@@ -28,6 +28,7 @@ from datetime import datetime, timedelta
from module_build_service import db
from module_build_service.config import init_config
from module_build_service.models import ModuleBuild, ComponentBuild
import modulemd
from module_build_service.utils import get_scm_url_re
import module_build_service.pdc
@@ -235,3 +236,157 @@ def scheduler_init_data():
db.session.add(component_one_build_one)
db.session.add(component_two_build_one)
db.session.commit()
def test_resuse_component_init_data():
db.session.remove()
db.drop_all()
db.create_all()
current_dir = os.path.dirname(__file__)
formatted_testmodule_yml_path = os.path.join(
current_dir, 'staged_data', 'formatted_testmodule.yaml')
with open(formatted_testmodule_yml_path, 'r') as f:
yaml = f.read()
build_one = module_build_service.models.ModuleBuild()
build_one.name = 'testmodule'
build_one.stream = 'master'
build_one.version = 20170109091357
build_one.state = 5
build_one.modulemd = yaml
build_one.koji_tag = 'module-testmodule-master-20170109091357'
build_one.scmurl = ('git://pkgs.stg.fedoraproject.org/modules/testmodule.'
'git?#7fea453')
build_one.batch = 3
build_one.owner = 'Tom Brady'
build_one.time_submitted = datetime(2017, 2, 15, 16, 8, 18)
build_one.time_modified = datetime(2017, 2, 15, 16, 19, 35)
build_one.time_completed = datetime(2017, 2, 15, 16, 19, 35)
component_one_build_one = module_build_service.models.ComponentBuild()
component_one_build_one.package = 'perl-Tangerine'
component_one_build_one.scmurl = \
('git://pkgs.fedoraproject.org/rpms/perl-Tangerine'
'?#4ceea43add2366d8b8c5a622a2fb563b625b9abf')
component_one_build_one.format = 'rpms'
component_one_build_one.task_id = 90276227
component_one_build_one.state = 1
component_one_build_one.nvr = \
'perl-Tangerine-0.23-1.module_testmodule_master_20170109091357'
component_one_build_one.batch = 2
component_one_build_one.module_id = 1
component_one_build_one.ref = '4ceea43add2366d8b8c5a622a2fb563b625b9abf'
component_two_build_one = module_build_service.models.ComponentBuild()
component_two_build_one.package = 'perl-List-Compare'
component_two_build_one.scmurl = \
('git://pkgs.fedoraproject.org/rpms/perl-List-Compare'
'?#76f9d8c8e87eed0aab91034b01d3d5ff6bd5b4cb')
component_two_build_one.format = 'rpms'
component_two_build_one.task_id = 90276228
component_two_build_one.state = 1
component_two_build_one.nvr = \
'perl-List-Compare-0.53-5.module_testmodule_master_20170109091357'
component_two_build_one.batch = 2
component_two_build_one.module_id = 1
component_two_build_one.ref = '76f9d8c8e87eed0aab91034b01d3d5ff6bd5b4cb'
component_three_build_one = module_build_service.models.ComponentBuild()
component_three_build_one.package = 'tangerine'
component_three_build_one.scmurl = \
('git://pkgs.fedoraproject.org/rpms/tangerine'
'?#fbed359411a1baa08d4a88e0d12d426fbf8f602c')
component_three_build_one.format = 'rpms'
component_three_build_one.task_id = 90276315
component_three_build_one.state = 1
component_three_build_one.nvr = \
'tangerine-0.22-3.module_testmodule_master_20170109091357'
component_three_build_one.batch = 3
component_three_build_one.module_id = 1
component_three_build_one.ref = 'fbed359411a1baa08d4a88e0d12d426fbf8f602c'
component_four_build_one = module_build_service.models.ComponentBuild()
component_four_build_one.package = 'module-build-macros'
component_four_build_one.scmurl = \
('/tmp/module_build_service-build-macrosqr4AWH/SRPMS/module-build-'
'macros-0.1-1.module_testmodule_master_20170109091357.src.rpm')
component_four_build_one.format = 'rpms'
component_four_build_one.task_id = 90276181
component_four_build_one.state = 1
component_four_build_one.nvr = \
'module-build-macros-0.1-1.module_testmodule_master_20170109091357'
component_four_build_one.batch = 1
component_four_build_one.module_id = 1
mmd = modulemd.ModuleMetadata()
mmd.loads(yaml)
mmd.xmd['mbs']['commit'] = '55f4a0a2e6cc255c88712a905157ab39315b8fd8'
build_two = module_build_service.models.ModuleBuild()
build_two.name = 'testmodule'
build_two.stream = 'master'
build_two.version = 20170219191323
build_two.state = 2
build_two.modulemd = mmd.dumps()
build_two.koji_tag = 'module-testmodule'
build_two.scmurl = ('git://pkgs.stg.fedoraproject.org/modules/testmodule.'
'git?#55f4a0a')
build_two.batch = 0
build_two.owner = 'Tom Brady'
build_two.time_submitted = datetime(2017, 2, 19, 16, 8, 18)
build_two.time_modified = datetime(2017, 2, 19, 16, 8, 18)
component_one_build_two = module_build_service.models.ComponentBuild()
component_one_build_two.package = 'perl-Tangerine'
component_one_build_two.scmurl = \
('git://pkgs.fedoraproject.org/rpms/perl-Tangerine'
'?#4ceea43add2366d8b8c5a622a2fb563b625b9abf')
component_one_build_two.format = 'rpms'
component_one_build_two.batch = 2
component_one_build_two.module_id = 2
component_one_build_two.ref = '4ceea43add2366d8b8c5a622a2fb563b625b9abf'
component_two_build_two = module_build_service.models.ComponentBuild()
component_two_build_two.package = 'perl-List-Compare'
component_two_build_two.scmurl = \
('git://pkgs.fedoraproject.org/rpms/perl-List-Compare'
'?#76f9d8c8e87eed0aab91034b01d3d5ff6bd5b4cb')
component_two_build_two.format = 'rpms'
component_two_build_two.batch = 2
component_two_build_two.module_id = 2
component_two_build_two.ref = '76f9d8c8e87eed0aab91034b01d3d5ff6bd5b4cb'
component_three_build_two = module_build_service.models.ComponentBuild()
component_three_build_two.package = 'tangerine'
component_three_build_two.scmurl = \
('git://pkgs.fedoraproject.org/rpms/tangerine'
'?#fbed359411a1baa08d4a88e0d12d426fbf8f602c')
component_three_build_two.format = 'rpms'
component_three_build_two.batch = 3
component_three_build_two.module_id = 2
component_three_build_two.ref = 'fbed359411a1baa08d4a88e0d12d426fbf8f602c'
component_four_build_two = module_build_service.models.ComponentBuild()
component_four_build_two.package = 'module-build-macros'
component_four_build_two.scmurl = \
('/tmp/module_build_service-build-macrosqr4AWH/SRPMS/module-build-'
'macros-0.1-1.module_testmodule_master_20170219191323.src.rpm')
component_four_build_two.format = 'rpms'
component_four_build_two.task_id = 90276186
component_four_build_two.state = 1
component_four_build_two.nvr = \
'module-build-macros-0.1-1.module_testmodule_master_20170219191323'
component_four_build_two.batch = 1
component_four_build_two.module_id = 2
db.session.add(build_one)
db.session.add(component_one_build_one)
db.session.add(component_two_build_one)
db.session.add(component_three_build_one)
db.session.add(component_four_build_one)
db.session.add(build_two)
db.session.add(component_one_build_two)
db.session.add(component_two_build_two)
db.session.add(component_three_build_two)
db.session.add(component_four_build_two)
db.session.commit()

View File

View File

@@ -0,0 +1,167 @@
# Copyright (c) 2017 Red Hat, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import unittest
from os import path
import vcr
import modulemd
from mock import patch
import module_build_service.utils
import module_build_service.scm
from module_build_service import models
from tests import test_resuse_component_init_data, db
BASE_DIR = path.abspath(path.dirname(__file__))
CASSETTES_DIR = path.join(
path.abspath(path.dirname(__file__)), '..', 'vcr-request-data')
class TestUtils(unittest.TestCase):
@vcr.use_cassette(
path.join(CASSETTES_DIR, 'tests.test_utils.TestUtils.test_format_mmd'))
@patch('module_build_service.scm.SCM')
def test_format_mmd(self, mocked_scm):
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',
'76f9d8c8e87eed0aab91034b01d3d5ff6bd5b4cb']
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')
module_build_service.utils.format_mmd(mmd, scmurl)
self.assertEqual(mmd.buildrequires, {'base-runtime': 'master'})
self.assertEqual(mmd.components.rpms['perl-Tangerine'].ref,
'4ceea43add2366d8b8c5a622a2fb563b625b9abf')
self.assertEqual(mmd.components.rpms['tangerine'].ref,
'fbed359411a1baa08d4a88e0d12d426fbf8f602c')
self.assertEqual(mmd.components.rpms['perl-List-Compare'].ref,
'76f9d8c8e87eed0aab91034b01d3d5ff6bd5b4cb')
xmd = {
'mbs': {
'commit': '620ec77321b2ea7b0d67d82992dda3e1d67055b4',
'buildrequires': {
'base-runtime': {
'ref': 'ae993ba84f4bce554471382ccba917ef16265f11',
'stream': 'master',
'version': '3'}},
'scmurl': 'git://pkgs.stg.fedoraproject.org/modules/testmodule'
'.git?#620ec77321b2ea7b0d67d82992dda3e1d67055b4',
}
}
self.assertEqual(mmd.xmd, xmd)
def test_get_reusable_component_same(self):
test_resuse_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')
self.assertEqual(rv.package, 'tangerine')
def test_get_reusable_component_different_perl_tangerine(self):
test_resuse_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)
plc_rv = module_build_service.utils.get_reusable_component(
db.session, second_module_build, 'perl-List-Compare')
self.assertEqual(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')
self.assertEqual(pt_rv, 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')
self.assertEqual(tangerine_rv, None)
def test_get_reusable_component_different_buildrequires_hash(self):
test_resuse_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'] = \
'da39a3ee5e6b4b0d3255bfef95601890afd80709'
second_module_build.modulemd = mmd.dumps()
db.session.commit()
plc_rv = module_build_service.utils.get_reusable_component(
db.session, second_module_build, 'perl-List-Compare')
self.assertEqual(plc_rv, None)
# perl-Tangerine has a different commit hash
pt_rv = module_build_service.utils.get_reusable_component(
db.session, second_module_build, 'perl-Tangerine')
self.assertEqual(pt_rv, 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')
self.assertEqual(tangerine_rv, None)
def test_get_reusable_component_different_buildrequires(self):
test_resuse_component_init_data()
second_module_build = models.ModuleBuild.query.filter_by(id=2).one()
mmd = second_module_build.mmd()
mmd.buildrequires = {'some_module': 'master'}
mmd.xmd['mbs']['buildrequires'] = {
'some_module': {
'ref': 'da39a3ee5e6b4b0d3255bfef95601890afd80709',
'stream': 'master',
'version': '20170123140147'
}
}
second_module_build.modulemd = mmd.dumps()
db.session.commit()
plc_rv = module_build_service.utils.get_reusable_component(
db.session, second_module_build, 'perl-List-Compare')
self.assertEqual(plc_rv, None)
# perl-Tangerine has a different commit hash
pt_rv = module_build_service.utils.get_reusable_component(
db.session, second_module_build, 'perl-Tangerine')
self.assertEqual(pt_rv, 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')
self.assertEqual(tangerine_rv, None)

View File

@@ -0,0 +1,60 @@
interactions:
- request:
body: null
headers:
Accept-Encoding: ['gzip, deflate']
Connection: [keep-alive]
User-Agent: [python-requests/2.10.0]
accept: [application/json]
content-type: [application/json]
method: GET
uri: http://modularity.fedorainfracloud.org:8080/rest_api/v1/unreleasedvariants?variant_version=master&page_size=-1&variant_id=base-runtime
response:
body: {string: !!python/unicode ''}
headers:
content-type: [text/html; charset=utf-8]
date: ['Thu, 16 Feb 2017 23:17:07 GMT']
location: ['http://modularity.fedorainfracloud.org:8080/rest_api/v1/unreleasedvariants/?variant_version=master&page_size=-1&variant_id=base-runtime']
server: [WSGIServer/0.1 Python/2.7.13]
x-frame-options: [SAMEORIGIN]
status: {code: 301, message: MOVED PERMANENTLY}
- request:
body: null
headers:
Accept-Encoding: ['gzip, deflate']
Connection: [keep-alive]
User-Agent: [python-requests/2.10.0]
accept: [application/json]
content-type: [application/json]
method: GET
uri: http://modularity.fedorainfracloud.org:8080/rest_api/v1/unreleasedvariants/?variant_version=master&page_size=-1&variant_id=base-runtime
response:
body: {string: !!python/unicode '[{"variant_id":"base-runtime","variant_uid":"base-runtime-master-3","variant_name":"base-runtime","variant_type":"module","variant_version":"master","variant_release":"3","koji_tag":"module-base-runtime-master-3","modulemd":"document:
modulemd\r\nversion: 1\r\ndata:\r\n name: base-runtime\r\n stream: master\r\n version:
3\r\n summary: A fake base-runtime module, used to bootstrap the infrastructure.\r\n description:
...\r\n xmd:\r\n mbs:\r\n commit: ae993ba84f4bce554471382ccba917ef16265f11\r\n buildrequires:\r\n base-runtime:\r\n ref:
ae993ba84f4bce554471382ccba917ef16265f11\r\n stream: master\r\n version:
3\r\n profiles:\r\n buildroot:\r\n rpms:\r\n -
bash\r\n - bzip2\r\n - coreutils\r\n -
cpio\r\n - diffutils\r\n - fedora-release\r\n -
findutils\r\n - gawk\r\n - gcc\r\n -
gcc-c++\r\n - grep\r\n - gzip\r\n -
info\r\n - make\r\n - patch\r\n -
redhat-rpm-config\r\n - rpm-build\r\n - sed\r\n -
shadow-utils\r\n - tar\r\n - unzip\r\n -
util-linux\r\n - which\r\n - xz\r\n srpm-buildroot:\r\n rpms:\r\n -
bash\r\n - fedora-release\r\n - fedpkg-minimal\r\n -
gnupg2\r\n - redhat-rpm-config\r\n - rpm-build\r\n -
shadow-utils","runtime_deps":[],"build_deps":[]}]'}
headers:
allow: ['GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS']
content-type: [application/json]
date: ['Thu, 16 Feb 2017 23:17:08 GMT']
server: [WSGIServer/0.1 Python/2.7.13]
set-cookie: ['csrftoken=5SgqiDsgTP85HDa38UE6keeFiRdY4iew; expires=Thu, 15-Feb-2018
23:17:08 GMT; Max-Age=31449600; Path=/', 'sessionid=7x1u3cribydavt8m6xtykl7h6w5rt3gb;
expires=Thu, 02-Mar-2017 23:17:08 GMT; httponly; Max-Age=1209600; Path=/']
vary: ['Accept, Cookie']
x-frame-options: [SAMEORIGIN]
status: {code: 200, message: OK}
version: 1