Moved skiptests cli option

This commit is contained in:
Martin Curlej
2017-11-21 09:07:26 +01:00
parent 620165964b
commit a1fd9daa73
4 changed files with 58 additions and 11 deletions

View File

@@ -317,7 +317,7 @@ def submit_module_build(scm_url, branch, server, id_provider, pyrpkg, verify=Tru
return -3, None
def do_local_build(local_builds_nsvs, log_flag=None, yaml_file=None, stream=None):
def do_local_build(local_builds_nsvs, log_flag=None, yaml_file=None, stream=None, skiptests=False):
"""
Starts the local build using `mbs-manager build_module_locally`.
"""
@@ -342,6 +342,9 @@ def do_local_build(local_builds_nsvs, log_flag=None, yaml_file=None, stream=None
if log_flag:
command.append(log_flag)
if skiptests:
command.append("--skiptests")
# Some last minute sanity checks before passing off to the other command.
if not os.path.exists(yaml_file):
logging.error("%s does not exist. Specify --file or check pwd.", yaml_file)
@@ -505,6 +508,8 @@ def main():
parser_local.add_argument('--stream', dest='stream', action='store',
help=("Name of the stream of this build."
" (builds from files only)"))
parser_local.add_argument('--skiptests', dest='skiptests', action='store_true',
help="Path to the modulemd yaml file")
parser_overview = subparsers.add_parser(
'overview', help="show overview of module builds",
@@ -550,7 +555,8 @@ def main():
else:
print("Submitted module build %r" % build_id)
elif args.cmd_name == "local":
sys.exit(do_local_build(args.local_builds_nsvs, log_flag, args.file, args.stream))
sys.exit(do_local_build(args.local_builds_nsvs, log_flag, args.file, args.stream,
args.skiptests))
elif args.cmd_name == "watch":
# Watch the module build.
try:

View File

@@ -91,8 +91,9 @@ def cleardb():
@manager.option('--stream', action='store', dest="stream")
@manager.option('--file', action='store', dest="yaml_file")
@manager.option('--skiptests', action='store_true', dest="skiptests")
@manager.option('-l', '--add-local-build', action='append', default=None, dest='local_build_nsvs')
def build_module_locally(local_build_nsvs=None, yaml_file=None, stream=None):
def build_module_locally(local_build_nsvs=None, yaml_file=None, stream=None, skiptests=False):
""" Performs local module build using Mock
"""
if 'SERVER_NAME' not in app.config or not app.config['SERVER_NAME']:
@@ -122,7 +123,7 @@ def build_module_locally(local_build_nsvs=None, yaml_file=None, stream=None):
filename = os.path.basename(yaml_file)
handle = FileStorage(fd)
handle.filename = filename
submit_module_build_from_yaml(username, handle, str(stream))
submit_module_build_from_yaml(username, handle, str(stream), skiptests)
else:
raise IOError("Provided modulemd file is not a yaml file.")
stop = module_build_service.scheduler.make_simple_stop_condition(db.session)

View File

@@ -907,7 +907,8 @@ def record_component_builds(mmd, module, initial_batch=1,
return batch
def submit_module_build_from_yaml(username, handle, stream=None, optional_params=None):
def submit_module_build_from_yaml(username, handle, stream=None, skiptests=False,
optional_params=None):
yaml = handle.read()
mmd = load_mmd(yaml)
@@ -918,10 +919,11 @@ def submit_module_build_from_yaml(username, handle, stream=None, optional_params
dt = datetime.utcfromtimestamp(int(time.time()))
def_name = str(handle.filename.split(".")[0])
def_version = int(dt.strftime("%Y%m%d%H%M%S"))
mmd.name = mmd.name or def_name
mmd.stream = mmd.stream or stream or "master"
mmd.stream = stream or mmd.stream or "master"
mmd.version = mmd.version or def_version
if skiptests:
mmd.buildopts.rpms.macros += "\n\n%__spec_check_pre exit 0\n"
return submit_module_build(username, None, mmd, None, yaml, optional_params)
@@ -930,7 +932,7 @@ _url_check_re = re.compile(r"^[^:/]+:.*$")
def submit_module_build_from_scm(username, url, branch, allow_local_url=False,
skiptests=False, optional_params=None):
optional_params=None):
# Translate local paths into file:// URL
if allow_local_url and not _url_check_re.match(url):
log.info(
@@ -938,8 +940,7 @@ def submit_module_build_from_scm(username, url, branch, allow_local_url=False,
url = os.path.abspath(url)
url = "file://" + url
mmd, scm = _fetch_mmd(url, branch, allow_local_url)
if skiptests:
mmd.buildopts.rpms.macros += "\n\n%__spec_check_pre exit 0\n"
return submit_module_build(username, url, mmd, scm, yaml, optional_params)

View File

@@ -19,16 +19,19 @@
# SOFTWARE.
import unittest
import tempfile
from os import path, mkdir
from shutil import copyfile
from shutil import copyfile, rmtree
from datetime import datetime
import vcr
import modulemd
from werkzeug.datastructures import FileStorage
from mock import patch
import module_build_service.utils
import module_build_service.scm
from module_build_service import models, conf
from module_build_service.errors import ProgrammingError, ValidationError, UnprocessableEntity
from module_build_service.utils import load_mmd
from tests import (test_reuse_component_init_data, init_data, db,
test_reuse_shared_userspace_init_data)
import mock
@@ -665,6 +668,42 @@ class TestUtils(unittest.TestCase):
except UnprocessableEntity as e:
self.assertEqual(e.message, error_msg)
@patch("module_build_service.utils.submit_module_build")
def test_submit_module_build_from_yaml_with_skiptests(self, mock_submit):
"""
Tests local module build from a yaml file with the skiptests option
Args:
mock_submit (MagickMock): mocked function submit_module_build, which we then
inspect if it was called with correct arguments
"""
test_reuse_component_init_data()
module_dir = tempfile.mkdtemp()
module = models.ModuleBuild.query.filter_by(id=2).one()
mmd = module.mmd()
modulemd_yaml = mmd.dumps()
modulemd_file_path = path.join(module_dir, "testmodule.yaml")
username = "test"
stream = "dev"
with open(modulemd_file_path, "w") as fd:
fd.write(modulemd_yaml)
with open(modulemd_file_path, "r") as fd:
handle = FileStorage(fd)
module_build_service.utils.submit_module_build_from_yaml(username, handle,
stream=stream, skiptests=True)
mock_submit_args = mock_submit.call_args[0]
username_arg = mock_submit_args[0]
mmd_arg = mock_submit_args[2]
modulemd_yaml_arg = mock_submit_args[4]
assert mmd_arg.stream == stream
assert "\n\n%__spec_check_pre exit 0\n" in mmd_arg.buildopts.rpms.macros
assert modulemd_yaml_arg == modulemd_yaml
assert username_arg == username
rmtree(module_dir)
class DummyModuleBuilder(GenericBuilder):
"""