Skip to content

Commit a6e09e1

Browse files
committed
Merge pull request #8 from boegel/feature_package_step_w_fpm
add unit tests for --package* (+ --skip)
2 parents 86c5e7e + 5c5e78b commit a6e09e1

File tree

6 files changed

+70
-16
lines changed

6 files changed

+70
-16
lines changed

easybuild/main.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
from easybuild.tools.filetools import cleanup, write_file
5757
from easybuild.tools.options import process_software_build_specs
5858
from easybuild.tools.robot import det_robot_path, dry_run, resolve_dependencies, search_easyconfigs
59+
from easybuild.tools.package.utilities import check_pkg_support
5960
from easybuild.tools.parallelbuild import submit_jobs
6061
from easybuild.tools.repository.repository import init_repository
6162
from easybuild.tools.testing import create_test_report, overall_test_report, regtest, session_module_list, session_state
@@ -210,6 +211,12 @@ def main(testing_data=(None, None, None)):
210211
config.init(options, config_options_dict)
211212
config.init_build_options(build_options=build_options, cmdline_options=options)
212213

214+
# check whether packaging is supported when it's being used
215+
if options.package:
216+
check_pkg_support()
217+
else:
218+
_log.debug("Packaging not enabled, so not check for packaging support.")
219+
213220
# update session state
214221
eb_config = eb_go.generate_cmd_line(add_default=True)
215222
modlist = session_module_list(testing=testing) # build options must be initialized first before 'module list' works

easybuild/tools/options.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
from easybuild.tools.modules import Lmod
6868
from easybuild.tools.ordereddict import OrderedDict
6969
from easybuild.tools.package.utilities import DEFAULT_PNS, PKG_TOOL_FPM, PKG_TYPE_RPM
70-
from easybuild.tools.package.utilities import avail_package_naming_schemes, check_pkg_support
70+
from easybuild.tools.package.utilities import avail_package_naming_schemes
7171
from easybuild.tools.toolchain.utilities import search_toolchain
7272
from easybuild.tools.repository.repository import avail_repositories
7373
from easybuild.tools.version import this_is_easybuild
@@ -369,8 +369,8 @@ def package_options(self):
369369

370370
opts = OrderedDict({
371371
'package': ("Enabling packaging", None, 'store_true', False),
372-
'package-tool': ("Packaging tool to use", None, 'store_or_None', PKG_TOOL_FPM),
373-
'package-type': ("Type of package to generate", None, 'store_or_None', PKG_TYPE_RPM),
372+
'package-tool': ("Packaging tool to use", None, 'store', PKG_TOOL_FPM),
373+
'package-type': ("Type of package to generate", None, 'store', PKG_TYPE_RPM),
374374
'package-release': ("Package release iteration number", None, 'store', '1'),
375375
})
376376

@@ -503,12 +503,6 @@ def postprocess(self):
503503

504504
self._postprocess_config()
505505

506-
# check whether packaging is supported when it's being used
507-
if self.options.package:
508-
check_pkg_support()
509-
else:
510-
self.log.debug("Packaging not enabled, so not check for packaging support.")
511-
512506
def _postprocess_external_modules_metadata(self):
513507
"""Parse file(s) specifying metadata for external modules."""
514508
# leave external_modules_metadata untouched if no files are provided

easybuild/tools/package/utilities.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ def package_with_fpm(easyblock):
8888
_log.info("Will be creating %s package(s) in %s", pkgtype, workdir)
8989

9090
try:
91+
origdir = os.getcwd()
9192
os.chdir(workdir)
9293
except OSError, err:
9394
raise EasyBuildError("Failed to chdir into workdir %s: %s", workdir, err)
@@ -133,12 +134,16 @@ def package_with_fpm(easyblock):
133134

134135
_log.info("Created %s package(s) in %s", pkgtype, workdir)
135136

137+
try:
138+
os.chdir(origdir)
139+
except OSError, err:
140+
raise EasyBuildError("Failed to chdir back to %s: %s", origdir, err)
141+
136142
return workdir
137143

138144

139145
def check_pkg_support():
140146
"""Check whether packaging is supported, i.e. whether the required dependencies are available."""
141-
142147
# packaging support is considered experimental for now (requires using --experimental)
143148
_log.experimental("Support for packaging installed software.")
144149

test/framework/options.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1815,6 +1815,8 @@ def test_include_toolchains(self):
18151815
logtxt = read_file(self.logfile)
18161816
self.assertTrue(tc_regex.search(logtxt), "Pattern '%s' *not* found in: %s" % (tc_regex.pattern, logtxt))
18171817

1818+
def test_package(self):
1819+
"""Test use of --package."""
18181820

18191821
def suite():
18201822
""" returns all the testcases in this module """

test/framework/package.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
from easybuild.tools.version import VERSION as EASYBUILD_VERSION
4343

4444

45-
MOCKED_FPM_RPM = """#!/bin/bash
45+
MOCKED_FPM = """#!/bin/bash
4646
# only parse what we need to spit out the expected package file, ignore the rest
4747
workdir=`echo $@ | sed 's/--workdir \([^ ]*\).*/\\1/g'`
4848
name=`echo $@ | sed 's/.* --name \([^ ]*\).*/\\1/g'`
@@ -54,6 +54,21 @@
5454
"""
5555

5656

57+
def mock_fpm(tmpdir):
58+
"""Put mocked version of fpm command in place in specified tmpdir."""
59+
# put mocked 'fpm' command in place, just for testing purposes
60+
fpm = os.path.join(tmpdir, 'fpm')
61+
write_file(fpm, MOCKED_FPM)
62+
adjust_permissions(fpm, stat.S_IXUSR, add=True)
63+
64+
# also put mocked rpmbuild in place
65+
rpmbuild = os.path.join(tmpdir, 'rpmbuild')
66+
write_file(rpmbuild, '#!/bin/bash') # only needs to be there, doesn't need to actually do something...
67+
adjust_permissions(rpmbuild, stat.S_IXUSR, add=True)
68+
69+
os.environ['PATH'] = '%s:%s' % (tmpdir, os.environ['PATH'])
70+
71+
5772
class PackageTest(EnhancedTestCase):
5873
"""Tests for packaging support."""
5974

@@ -103,11 +118,7 @@ def test_package(self):
103118
test_easyconfigs = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'easyconfigs')
104119
ec = EasyConfig(os.path.join(test_easyconfigs, 'toy-0.0-gompi-1.3.12-test.eb'), validate=False)
105120

106-
# put mocked 'fpm' command in place, just for testing purposes
107-
fpm = os.path.join(self.test_prefix, 'fpm')
108-
write_file(fpm, MOCKED_FPM_RPM)
109-
adjust_permissions(fpm, stat.S_IXUSR, add=True)
110-
os.environ['PATH'] = '%s:%s' % (self.test_prefix, os.environ['PATH'])
121+
mock_fpm(self.test_prefix)
111122

112123
# import needs to be done here, since test easyblocks are only included later
113124
from easybuild.easyblocks.toy import EB_toy

test/framework/toy_build.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import sys
3737
import tempfile
3838
from test.framework.utilities import EnhancedTestCase
39+
from test.framework.package import mock_fpm
3940
from unittest import TestLoader
4041
from unittest import main as unittestmain
4142
from vsc.utils.fancylogger import setLogLevelDebug, logToScreen
@@ -46,6 +47,7 @@
4647
from easybuild.tools.config import get_module_syntax
4748
from easybuild.tools.filetools import mkdir, read_file, which, write_file
4849
from easybuild.tools.modules import modules_tool
50+
from easybuild.tools.version import VERSION as EASYBUILD_VERSION
4951

5052

5153
class ToyBuildTest(EnhancedTestCase):
@@ -970,6 +972,39 @@ def test_module_only(self):
970972
modtxt = read_file(toy_mod + '.lua')
971973
self.assertTrue(re.search('load.*ictce/4.1.13', modtxt), "load statement for ictce/4.1.13 found in module")
972974

975+
def test_package(self):
976+
"""Test use of --package and accompanying package configuration settings."""
977+
mock_fpm(self.test_prefix)
978+
pkgpath = os.path.join(self.test_prefix, 'pkgs')
979+
980+
extra_args = [
981+
'--experimental',
982+
'--package',
983+
'--package-release=321',
984+
'--package-tool=fpm',
985+
'--package-type=foo',
986+
'--packagepath=%s' % pkgpath,
987+
]
988+
989+
self.test_toy_build(extra_args=extra_args)
990+
991+
toypkg = os.path.join(pkgpath, 'toy-0.0-eb-%s.321.foo' % EASYBUILD_VERSION)
992+
self.assertTrue(os.path.exists(toypkg), "%s is there" % toypkg)
993+
994+
def test_package_skip(self):
995+
"""Test use of --package with --skip."""
996+
mock_fpm(self.test_prefix)
997+
pkgpath = os.path.join(self.test_prefix, 'packages') # default path
998+
999+
self.test_toy_build(['--packagepath=%s' % pkgpath])
1000+
self.assertFalse(os.path.exists(pkgpath), "%s is not created without use of --package" % pkgpath)
1001+
1002+
self.test_toy_build(extra_args=['--experimental', '--package', '--skip'], verify=False)
1003+
1004+
toypkg = os.path.join(pkgpath, 'toy-0.0-eb-%s.1.rpm' % EASYBUILD_VERSION)
1005+
self.assertTrue(os.path.exists(toypkg), "%s is there" % toypkg)
1006+
1007+
9731008
def suite():
9741009
""" return all the tests in this file """
9751010
return TestLoader().loadTestsFromTestCase(ToyBuildTest)

0 commit comments

Comments
 (0)