-
Notifications
You must be signed in to change notification settings - Fork 204
/
Copy pathtoy_build.py
3991 lines (3331 loc) · 191 KB
/
toy_build.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
##
# Copyright 2013-2024 Ghent University
#
# This file is part of EasyBuild,
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),
# with support of Ghent University (http://ugent.be/hpc),
# the Flemish Supercomputer Centre (VSC) (https://www.vscentrum.be),
# Flemish Research Foundation (FWO) (http://www.fwo.be/en)
# and the Department of Economy, Science and Innovation (EWI) (http://www.ewi-vlaanderen.be/en).
#
# https://github.com/easybuilders/easybuild
#
# EasyBuild is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation v2.
#
# EasyBuild is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with EasyBuild. If not, see <http://www.gnu.org/licenses/>.
# #
"""
Toy build unit test
@author: Kenneth Hoste (Ghent University)
@author: Damian Alvarez (Forschungszentrum Juelich GmbH)
"""
import copy
import glob
import grp
import os
import re
import shutil
import signal
import stat
import sys
import tempfile
import textwrap
from easybuild.tools import LooseVersion
from test.framework.utilities import EnhancedTestCase, TestLoaderFiltered
from test.framework.package import mock_fpm
from unittest import TextTestRunner
import easybuild.tools.hooks # so we can reset cached hooks
import easybuild.tools.module_naming_scheme # required to dynamically load test module naming scheme(s)
from easybuild.framework.easyconfig.easyconfig import EasyConfig
from easybuild.framework.easyconfig.parser import EasyConfigParser
from easybuild.tools.build_log import EasyBuildError
from easybuild.tools.config import get_module_syntax, get_repositorypath
from easybuild.tools.environment import modify_env
from easybuild.tools.filetools import adjust_permissions, change_dir, copy_file, mkdir, move_file
from easybuild.tools.filetools import read_file, remove_dir, remove_file, which, write_file
from easybuild.tools.module_generator import ModuleGeneratorTcl
from easybuild.tools.modules import Lmod
from easybuild.tools.py2vs3 import reload, string_type
from easybuild.tools.run import run_cmd
from easybuild.tools.utilities import nub
from easybuild.tools.systemtools import get_shared_lib_ext
from easybuild.tools.version import VERSION as EASYBUILD_VERSION
class ToyBuildTest(EnhancedTestCase):
"""Toy build unit test."""
def setUp(self):
"""Test setup."""
super(ToyBuildTest, self).setUp()
fd, self.dummylogfn = tempfile.mkstemp(prefix='easybuild-dummy', suffix='.log')
os.close(fd)
# clear log
write_file(self.logfile, '')
def tearDown(self):
"""Cleanup."""
# kick out any paths for included easyblocks from sys.path,
# to avoid infected any other tests
for path in sys.path[:]:
if '/included-easyblocks' in path:
sys.path.remove(path)
# reload toy easyblock (and generic toy_extension easyblock that imports it) after cleaning up sys.path,
# to avoid trouble in other tests due to included toy easyblock that is cached somewhere
# (despite the cleanup in sys.modules);
# important for tests that include a customised copy of the toy easyblock
# (like test_toy_build_enhanced_sanity_check)
import easybuild.easyblocks.toy
reload(easybuild.easyblocks.toy)
import easybuild.easyblocks.toytoy
reload(easybuild.easyblocks.toytoy)
import easybuild.easyblocks.generic.toy_extension
reload(easybuild.easyblocks.generic.toy_extension)
del sys.modules['easybuild.easyblocks.toy']
del sys.modules['easybuild.easyblocks.toytoy']
del sys.modules['easybuild.easyblocks.generic.toy_extension']
# reset cached hooks
easybuild.tools.hooks._cached_hooks.clear()
super(ToyBuildTest, self).tearDown()
# remove logs
if os.path.exists(self.dummylogfn):
os.remove(self.dummylogfn)
def check_toy(self, installpath, outtxt, name='toy', version='0.0', versionprefix='', versionsuffix='', error=None):
"""Check whether toy build succeeded."""
full_version = ''.join([versionprefix, version, versionsuffix])
if error is not None:
error_msg = '\nNote: Caught error: %s' % error
else:
error_msg = ''
# check for success
success = re.compile(r"COMPLETED: Installation (ended|STOPPED) successfully \(took .* secs?\)")
self.assertTrue(success.search(outtxt), "COMPLETED message found in '%s'%s" % (outtxt, error_msg))
# if the module exists, it should be fine
toy_module = os.path.join(installpath, 'modules', 'all', name, full_version)
msg = "module for toy build toy/%s found (path %s)" % (full_version, toy_module)
if get_module_syntax() == 'Lua':
toy_module += '.lua'
self.assertExists(toy_module, msg + error_msg)
# module file is symlinked according to moduleclass
toy_module_symlink = os.path.join(installpath, 'modules', 'tools', name, full_version)
if get_module_syntax() == 'Lua':
toy_module_symlink += '.lua'
self.assertTrue(os.path.islink(toy_module_symlink))
self.assertExists(toy_module_symlink)
# make sure installation log file and easyconfig file are copied to install dir
software_path = os.path.join(installpath, 'software', name, full_version)
install_log_path_pattern = os.path.join(software_path, 'easybuild', 'easybuild-%s-%s*.log' % (name, version))
self.assertTrue(len(glob.glob(install_log_path_pattern)) >= 1,
"Found at least 1 file at %s" % install_log_path_pattern)
# make sure test report is available
report_name = 'easybuild-%s-%s*test_report.md' % (name, version)
test_report_path_pattern = os.path.join(software_path, 'easybuild', report_name)
self.assertTrue(len(glob.glob(test_report_path_pattern)) >= 1,
"Found at least 1 file at %s" % test_report_path_pattern)
ec_file_path = os.path.join(software_path, 'easybuild', '%s-%s.eb' % (name, full_version))
self.assertExists(ec_file_path)
devel_module_path = os.path.join(software_path, 'easybuild', '%s-%s-easybuild-devel' % (name, full_version))
self.assertExists(devel_module_path)
def test_toy_build(self, extra_args=None, ec_file=None, tmpdir=None, verify=True, fails=False, verbose=True,
raise_error=False, test_report=None, name='toy', versionsuffix='', testing=True,
raise_systemexit=False, force=True, test_report_regexs=None, debug=True):
"""Perform a toy build."""
if extra_args is None:
extra_args = []
test_readme = False
if ec_file is None:
ec_file = os.path.join(os.path.dirname(__file__), 'easyconfigs', 'test_ecs', 't', 'toy', 'toy-0.0.eb')
test_readme = True
full_ver = '0.0%s' % versionsuffix
args = [
ec_file,
'--sourcepath=%s' % self.test_sourcepath,
'--buildpath=%s' % self.test_buildpath,
'--installpath=%s' % self.test_installpath,
'--unittest-file=%s' % self.logfile,
'--robot=%s' % os.pathsep.join([self.test_buildpath, os.path.dirname(__file__)]),
]
if debug:
args.append('--debug')
if force:
args.append('--force')
if tmpdir is not None:
args.append('--tmpdir=%s' % tmpdir)
if test_report is not None:
args.append('--dump-test-report=%s' % test_report)
args.extend(extra_args)
myerr = None
try:
outtxt = self.eb_main(args, logfile=self.dummylogfn, do_build=True, verbose=verbose,
raise_error=raise_error, testing=testing, raise_systemexit=raise_systemexit)
except Exception as err:
myerr = err
if raise_error:
raise myerr
if verify:
self.check_toy(self.test_installpath, outtxt, name=name, versionsuffix=versionsuffix, error=myerr)
if test_readme:
# make sure postinstallcmds were used
toy_install_path = os.path.join(self.test_installpath, 'software', 'toy', full_ver)
self.assertEqual(read_file(os.path.join(toy_install_path, 'README')), "TOY\n")
# make sure full test report was dumped, and contains sensible information
if test_report is not None:
self.assertExists(test_report)
if test_report_regexs:
regex_patterns = test_report_regexs
else:
if fails:
test_result = 'FAIL'
else:
test_result = 'SUCCESS'
regex_patterns = [
r"Test result[\S\s]*Build succeeded for %d out of 1" % (not fails),
r"Overview of tested easyconfig[\S\s]*%s[\S\s]*%s" % (test_result, os.path.basename(ec_file)),
]
regex_patterns.extend([
r"Time info[\S\s]*start:[\S\s]*end:",
r"EasyBuild info[\S\s]*framework version:[\S\s]*easyblocks ver[\S\s]*command line[\S\s]*configuration",
r"System info[\S\s]*cpu model[\S\s]*os name[\S\s]*os version[\S\s]*python version",
r"List of loaded modules",
r"Environment",
])
test_report_txt = read_file(test_report)
for regex_pattern in regex_patterns:
regex = re.compile(regex_pattern, re.M)
msg = "Pattern %s found in full test report: %s" % (regex.pattern, test_report_txt)
self.assertTrue(regex.search(test_report_txt), msg)
return outtxt
def run_test_toy_build_with_output(self, *args, **kwargs):
"""Run test_toy_build with specified arguments, catch stdout/stderr and return it."""
self.mock_stderr(True)
self.mock_stdout(True)
self.test_toy_build(*args, **kwargs)
stderr = self.get_stderr()
stdout = self.get_stdout()
self.mock_stderr(False)
self.mock_stdout(False)
return stdout, stderr
def test_toy_broken(self):
"""Test deliberately broken toy build."""
tmpdir = tempfile.mkdtemp()
broken_toy_ec = os.path.join(tmpdir, "toy-broken.eb")
toy_ec_file = os.path.join(os.path.dirname(__file__), 'easyconfigs', 'test_ecs', 't', 'toy', 'toy-0.0.eb')
broken_toy_ec_txt = read_file(toy_ec_file)
broken_toy_ec_txt += "checksums = ['clearywrongMD5checksumoflength32']"
write_file(broken_toy_ec, broken_toy_ec_txt)
error_regex = "Checksum verification .* failed"
self.assertErrorRegex(EasyBuildError, error_regex, self.test_toy_build, ec_file=broken_toy_ec, tmpdir=tmpdir,
verify=False, fails=True, verbose=False, raise_error=True)
# make sure log file is retained, also for failed build
log_path_pattern = os.path.join(tmpdir, 'eb-*', 'easybuild-toy-0.0*.log')
self.assertTrue(len(glob.glob(log_path_pattern)) == 1, "Log file found at %s" % log_path_pattern)
# make sure individual test report is retained, also for failed build
test_report_fp_pattern = os.path.join(tmpdir, 'eb-*', 'easybuild-toy-0.0*test_report.md')
self.assertTrue(len(glob.glob(test_report_fp_pattern)) == 1, "Test report %s found" % test_report_fp_pattern)
# test dumping full test report (doesn't raise an exception)
test_report_fp = os.path.join(self.test_buildpath, 'full_test_report.md')
self.test_toy_build(ec_file=broken_toy_ec, tmpdir=tmpdir, verify=False, fails=True, verbose=False,
raise_error=True, test_report=test_report_fp)
# cleanup
shutil.rmtree(tmpdir)
def test_toy_tweaked(self):
"""Test toy build with tweaked easyconfig, for testing extra easyconfig parameters."""
test_ecs_dir = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'easyconfigs')
ec_file = os.path.join(self.test_buildpath, 'toy-0.0-tweaked.eb')
shutil.copy2(os.path.join(test_ecs_dir, 'test_ecs', 't', 'toy', 'toy-0.0.eb'), ec_file)
modloadmsg = 'THANKS FOR LOADING ME\\nI AM %(name)s v%(version)s'
modloadmsg_regex_tcl = r'THANKS.*\n\s*I AM toy v0.0\n\s*"'
modloadmsg_regex_lua = r'\[==\[THANKS.*\n\s*I AM toy v0.0\n\s*\]==\]'
# tweak easyconfig by appending to it
ec_extra = '\n'.join([
"versionsuffix = '-tweaked'",
"modextrapaths = {'SOMEPATH': ['foo/bar', 'baz', '']}",
"modextrapaths_append = {'SOMEPATH_APPEND': ['qux/fred', 'thud', '']}",
"modextravars = {'FOO': 'bar'}",
"modloadmsg = '%s'" % modloadmsg,
"modtclfooter = 'puts stderr \"oh hai!\"'", # ignored when module syntax is Lua
"modluafooter = 'io.stderr:write(\"oh hai!\")'", # ignored when module syntax is Tcl
"usage = 'This toy is easy to use, 100%!'",
"examples = 'No example available, 0% complete'",
"citing = 'If you use this package, please cite our paper https://ieeexplore.ieee.org/document/6495863'",
"docpaths = ['share/doc/toy/readme.txt', 'share/doc/toy/html/index.html']",
"docurls = ['https://easybuilders.github.io/easybuild/toy/docs.html']",
"upstream_contacts = 'support@toy.org'",
"site_contacts = ['Jim Admin', 'Jane Admin']",
])
write_file(ec_file, ec_extra, append=True)
args = [
ec_file,
'--sourcepath=%s' % self.test_sourcepath,
'--buildpath=%s' % self.test_buildpath,
'--installpath=%s' % self.test_installpath,
'--debug',
'--force',
]
outtxt = self.eb_main(args, do_build=True, verbose=True, raise_error=True)
self.check_toy(self.test_installpath, outtxt, versionsuffix='-tweaked')
toy_module = os.path.join(self.test_installpath, 'modules', 'all', 'toy', '0.0-tweaked')
if get_module_syntax() == 'Lua':
toy_module += '.lua'
toy_module_txt = read_file(toy_module)
if get_module_syntax() == 'Tcl':
self.assertTrue(re.search(r'^setenv\s*FOO\s*"bar"$', toy_module_txt, re.M))
self.assertTrue(re.search(r'^prepend-path\s*SOMEPATH\s*\$root/foo/bar$', toy_module_txt, re.M))
self.assertTrue(re.search(r'^prepend-path\s*SOMEPATH\s*\$root/baz$', toy_module_txt, re.M))
self.assertTrue(re.search(r'^prepend-path\s*SOMEPATH\s*\$root$', toy_module_txt, re.M))
self.assertTrue(re.search(r'^append-path\s*SOMEPATH_APPEND\s*\$root/qux/fred$', toy_module_txt, re.M))
self.assertTrue(re.search(r'^append-path\s*SOMEPATH_APPEND\s*\$root/thud$', toy_module_txt, re.M))
self.assertTrue(re.search(r'^append-path\s*SOMEPATH_APPEND\s*\$root$', toy_module_txt, re.M))
mod_load_msg = r'module-info mode load.*\n\s*puts stderr\s*.*%s$' % modloadmsg_regex_tcl
self.assertTrue(re.search(mod_load_msg, toy_module_txt, re.M))
self.assertTrue(re.search(r'^puts stderr "oh hai!"$', toy_module_txt, re.M))
elif get_module_syntax() == 'Lua':
self.assertTrue(re.search(r'^setenv\("FOO", "bar"\)', toy_module_txt, re.M))
pattern = r'^prepend_path\("SOMEPATH", pathJoin\(root, "foo/bar"\)\)$'
self.assertTrue(re.search(pattern, toy_module_txt, re.M))
pattern = r'^append_path\("SOMEPATH_APPEND", pathJoin\(root, "qux/fred"\)\)$'
self.assertTrue(re.search(pattern, toy_module_txt, re.M))
pattern = r'^append_path\("SOMEPATH_APPEND", pathJoin\(root, "thud"\)\)$'
self.assertTrue(re.search(pattern, toy_module_txt, re.M))
self.assertTrue(re.search(r'^append_path\("SOMEPATH_APPEND", root\)$', toy_module_txt, re.M))
self.assertTrue(re.search(r'^prepend_path\("SOMEPATH", pathJoin\(root, "baz"\)\)$', toy_module_txt, re.M))
self.assertTrue(re.search(r'^prepend_path\("SOMEPATH", root\)$', toy_module_txt, re.M))
mod_load_msg = r'^if mode\(\) == "load" then\n\s*io.stderr:write\(%s\)$' % modloadmsg_regex_lua
regex = re.compile(mod_load_msg, re.M)
self.assertTrue(regex.search(toy_module_txt), "Pattern '%s' found in: %s" % (regex.pattern, toy_module_txt))
else:
self.fail("Unknown module syntax: %s" % get_module_syntax())
# newline between "I AM toy v0.0" (modloadmsg) and "oh hai!" (mod*footer) is added automatically
expected = "\nTHANKS FOR LOADING ME\nI AM toy v0.0\n"
# with module files in Tcl syntax, a newline is added automatically
if get_module_syntax() == 'Tcl':
expected += "\n"
expected += "oh hai!"
# setting $LMOD_QUIET results in suppression of printed message with Lmod & module files in Tcl syntax
os.environ.pop('LMOD_QUIET', None)
self.modtool.use(os.path.join(self.test_installpath, 'modules', 'all'))
out = self.modtool.run_module('load', 'toy/0.0-tweaked', return_output=True)
self.assertTrue(out.strip().endswith(expected))
def test_toy_buggy_easyblock(self):
"""Test build using a buggy/broken easyblock, make sure a traceback is reported."""
ec_file = os.path.join(os.path.dirname(__file__), 'easyconfigs', 'test_ecs', 't', 'toy', 'toy-0.0.eb')
kwargs = {
'ec_file': ec_file,
'extra_args': ['--easyblock=EB_toy_buggy'],
'raise_error': True,
'verify': False,
'verbose': False,
}
err_regex = r"Traceback[\S\s]*toy_buggy.py.*build_step[\S\s]*name 'run_cmd' is not defined"
self.assertErrorRegex(EasyBuildError, err_regex, self.test_toy_build, **kwargs)
def test_toy_build_formatv2(self):
"""Perform a toy build (format v2)."""
# set $MODULEPATH such that modules for specified dependencies are found
modulepath = os.environ.get('MODULEPATH')
os.environ['MODULEPATH'] = os.path.abspath(os.path.join(os.path.dirname(__file__), 'modules'))
args = [
os.path.join(os.path.dirname(__file__), 'easyconfigs', 'v2.0', 'toy.eb'),
'--sourcepath=%s' % self.test_sourcepath,
'--buildpath=%s' % self.test_buildpath,
'--installpath=%s' % self.test_installpath,
'--debug',
'--unittest-file=%s' % self.logfile,
'--force',
'--robot=%s' % os.pathsep.join([self.test_buildpath, os.path.dirname(__file__)]),
'--software-version=0.0',
'--toolchain=system,system',
'--experimental',
]
outtxt = self.eb_main(args, logfile=self.dummylogfn, do_build=True, verbose=True)
self.check_toy(self.test_installpath, outtxt)
# restore
if modulepath is not None:
os.environ['MODULEPATH'] = modulepath
else:
del os.environ['MODULEPATH']
def test_toy_build_with_blocks(self):
"""Test a toy build with multiple blocks."""
orig_sys_path = sys.path[:]
# add directory in which easyconfig file can be found to Python search path,
# since we're not specifying it full path below
tmpdir = tempfile.mkdtemp()
# note get_paths_for expects easybuild/easyconfigs subdir
ecs_path = os.path.join(tmpdir, "easybuild", "easyconfigs")
os.makedirs(ecs_path)
test_ecs = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'easyconfigs', 'test_ecs')
shutil.copy2(os.path.join(test_ecs, 't', 'toy', 'toy-0.0-multiple.eb'), ecs_path)
sys.path.append(tmpdir)
args = [
'toy-0.0-multiple.eb',
'--sourcepath=%s' % self.test_sourcepath,
'--buildpath=%s' % self.test_buildpath,
'--installpath=%s' % self.test_installpath,
'--debug',
'--unittest-file=%s' % self.logfile,
'--force',
]
outtxt = self.eb_main(args, logfile=self.dummylogfn, do_build=True, verbose=True)
for toy_prefix, toy_version, toy_suffix in [
('', '0.0', '-somesuffix'),
('someprefix-', '0.0', '-somesuffix')
]:
self.check_toy(self.test_installpath, outtxt, version=toy_version,
versionprefix=toy_prefix, versionsuffix=toy_suffix)
# cleanup
shutil.rmtree(tmpdir)
sys.path[:] = orig_sys_path
def test_toy_build_formatv2_sections(self):
"""Perform a toy build (format v2, using sections)."""
versions = {
'0.0': {'versionprefix': '', 'versionsuffix': ''},
'1.0': {'versionprefix': '', 'versionsuffix': ''},
'1.1': {'versionprefix': 'stable-', 'versionsuffix': ''},
'1.5': {'versionprefix': 'stable-', 'versionsuffix': '-early'},
'1.6': {'versionprefix': 'stable-', 'versionsuffix': '-early'},
'2.0': {'versionprefix': 'stable-', 'versionsuffix': '-early'},
'3.0': {'versionprefix': 'stable-', 'versionsuffix': '-mature'},
}
for version, specs in versions.items():
args = [
os.path.join(os.path.dirname(__file__), 'easyconfigs', 'v2.0', 'toy-with-sections.eb'),
'--sourcepath=%s' % self.test_sourcepath,
'--buildpath=%s' % self.test_buildpath,
'--installpath=%s' % self.test_installpath,
'--debug',
'--unittest-file=%s' % self.logfile,
'--force',
'--robot=%s' % os.pathsep.join([self.test_buildpath, os.path.dirname(__file__)]),
'--software-version=%s' % version,
'--toolchain=system,system',
'--experimental',
]
outtxt = self.eb_main(args, logfile=self.dummylogfn, do_build=True, verbose=True, raise_error=True)
specs['version'] = version
self.check_toy(self.test_installpath, outtxt, **specs)
def test_toy_download_sources(self):
"""Test toy build with sources that still need to be 'downloaded'."""
tmpdir = tempfile.mkdtemp()
# copy toy easyconfig file, and append source_urls to it
topdir = os.path.dirname(os.path.abspath(__file__))
shutil.copy2(os.path.join(topdir, 'easyconfigs', 'test_ecs', 't', 'toy', 'toy-0.0.eb'), tmpdir)
source_url = os.path.join(topdir, 'sandbox', 'sources', 'toy')
ec_file = os.path.join(tmpdir, 'toy-0.0.eb')
write_file(ec_file, '\nsource_urls = ["file://%s"]\n' % source_url, append=True)
# unset $EASYBUILD_XPATH env vars, to make sure --prefix is picked up
for cfg_opt in ['build', 'install', 'source']:
del os.environ['EASYBUILD_%sPATH' % cfg_opt.upper()]
sourcepath = os.path.join(tmpdir, 'mysources')
args = [
ec_file,
'--prefix=%s' % tmpdir,
'--sourcepath=%s' % ':'.join([sourcepath, '/bar']), # include senseless path which should be ignored
'--debug',
'--unittest-file=%s' % self.logfile,
'--force',
]
outtxt = self.eb_main(args, logfile=self.dummylogfn, do_build=True, verbose=True)
self.check_toy(tmpdir, outtxt)
self.assertExists(os.path.join(sourcepath, 't', 'toy', 'toy-0.0.tar.gz'))
shutil.rmtree(tmpdir)
def test_toy_permissions(self):
"""Test toy build with custom umask settings."""
toy_ec_file = os.path.join(os.path.dirname(__file__), 'easyconfigs', 'test_ecs', 't', 'toy', 'toy-0.0.eb')
test_ec_txt = read_file(toy_ec_file)
# remove exec perms on bin subdirectory for others, to check whether correct dir permissions are set
test_ec_txt += "\npostinstallcmds += ['chmod o-x %(installdir)s/bin']"
test_ec = os.path.join(self.test_prefix, 'test.eb')
write_file(test_ec, test_ec_txt)
args = [
'--sourcepath=%s' % self.test_sourcepath,
'--buildpath=%s' % self.test_buildpath,
'--installpath=%s' % self.test_installpath,
'--debug',
'--unittest-file=%s' % self.logfile,
'--force',
]
# set umask hard to verify default reliably
orig_umask = os.umask(0o022)
# test specifying a non-existing group
allargs = [test_ec] + args + ['--group=thisgroupdoesnotexist']
outtxt, err = self.eb_main(allargs, logfile=self.dummylogfn, do_build=True, return_error=True)
err_regex = re.compile("Failed to get group ID .* group does not exist")
self.assertTrue(err_regex.search(outtxt), "Pattern '%s' found in '%s'" % (err_regex.pattern, outtxt))
# determine current group name (at least we can use that)
gid = os.getgid()
curr_grp = grp.getgrgid(gid).gr_name
for umask, cfg_group, ec_group, dir_perms, fil_perms, bin_perms in [
(None, None, None, 0o755, 0o644, 0o755), # default: inherit session umask
(None, None, curr_grp, 0o750, 0o640, 0o750), # default umask, but with specified group in ec
(None, curr_grp, None, 0o750, 0o640, 0o750), # default umask, but with specified group in cfg
(None, 'notagrp', curr_grp, 0o750, 0o640, 0o750), # default umask, but with specified group in cfg/ec
('000', None, None, 0o777, 0o666, 0o777), # stupid empty umask
('032', None, None, 0o745, 0o644, 0o745), # no write/execute for group, no write for other
('030', None, curr_grp, 0o740, 0o640, 0o740), # no write for group, with specified group
('077', None, None, 0o700, 0o600, 0o700), # no access for other/group
]:
# empty the install directory, to ensure any created directories adher to the permissions
shutil.rmtree(self.test_installpath)
if cfg_group is None and ec_group is None:
allargs = [test_ec]
elif ec_group is not None:
shutil.copy2(test_ec, self.test_buildpath)
tmp_ec_file = os.path.join(self.test_buildpath, os.path.basename(test_ec))
write_file(tmp_ec_file, "\ngroup = '%s'" % ec_group, append=True)
allargs = [tmp_ec_file]
allargs.extend(args)
if umask is not None:
allargs.append("--umask=%s" % umask)
if cfg_group is not None:
allargs.append("--group=%s" % cfg_group)
outtxt = self.eb_main(allargs, logfile=self.dummylogfn, do_build=True, verbose=True)
# verify that installation was correct
self.check_toy(self.test_installpath, outtxt)
# group specified in easyconfig overrules configured group
group = cfg_group
if ec_group is not None:
group = ec_group
# verify permissions
paths_perms = [
# no write permissions for group/other, regardless of umask
(('software', 'toy', '0.0'), dir_perms & ~ 0o022),
(('software', 'toy', '0.0', 'bin'), dir_perms & ~ 0o022),
(('software', 'toy', '0.0', 'bin', 'toy'), bin_perms & ~ 0o022),
]
# only software subdirs are chmod'ed for 'protected' installs, so don't check those if a group is specified
if group is None:
paths_perms.extend([
(('software', ), dir_perms),
(('software', 'toy'), dir_perms),
(('software', 'toy', '0.0', 'easybuild', '*.log'), fil_perms),
(('modules', ), dir_perms),
(('modules', 'all'), dir_perms),
(('modules', 'all', 'toy'), dir_perms),
])
if get_module_syntax() == 'Tcl':
paths_perms.append((('modules', 'all', 'toy', '0.0'), fil_perms))
elif get_module_syntax() == 'Lua':
paths_perms.append((('modules', 'all', 'toy', '0.0.lua'), fil_perms))
for path, correct_perms in paths_perms:
fullpath = glob.glob(os.path.join(self.test_installpath, *path))[0]
perms = os.stat(fullpath).st_mode & 0o777
tup = (fullpath, oct(correct_perms), oct(perms), umask, cfg_group, ec_group)
msg = "Path %s has %s permissions: %s (umask: %s, group: %s - %s)" % tup
self.assertEqual(oct(perms), oct(correct_perms), msg)
if group is not None:
path_gid = os.stat(fullpath).st_gid
self.assertEqual(path_gid, grp.getgrnam(group).gr_gid)
# restore original umask
os.umask(orig_umask)
def test_toy_permissions_installdir(self):
"""Test --read-only-installdir and --group-write-installdir."""
# Avoid picking up the already prepared fake module
try:
del os.environ['MODULEPATH']
except KeyError:
pass
# set umask hard to verify default reliably
orig_umask = os.umask(0o022)
toy_ec = os.path.join(os.path.dirname(__file__), 'easyconfigs', 'test_ecs', 't', 'toy', 'toy-0.0.eb')
test_ec_txt = read_file(toy_ec)
# take away read permissions, to check whether they are correctly restored by EasyBuild after installation
test_ec_txt += "\npostinstallcmds += ['chmod -R og-r %(installdir)s']"
test_ec = os.path.join(self.test_prefix, 'test.eb')
write_file(test_ec, test_ec_txt)
# first check default behaviour
self.test_toy_build(ec_file=test_ec)
toy_install_dir = os.path.join(self.test_installpath, 'software', 'toy', '0.0')
toy_bin = os.path.join(toy_install_dir, 'bin', 'toy')
installdir_perms = os.stat(toy_install_dir).st_mode & 0o777
self.assertEqual(installdir_perms, 0o755, "%s has default permissions" % toy_install_dir)
toy_bin_perms = os.stat(toy_bin).st_mode & 0o777
self.assertEqual(toy_bin_perms, 0o755, "%s has default permissions" % toy_bin_perms)
shutil.rmtree(self.test_installpath)
# check whether --read-only-installdir works as intended
# Tested 5 times:
# 1. Non existing build -> Install and set read-only
# 2. Existing build with --rebuild -> Reinstall and set read-only
# 3. Existing build with --force -> Reinstall and set read-only
# 4-5: Same as 2-3 but with --skip
# 6. Existing build with --fetch -> Test that logs can be written
test_cases = (
[],
['--rebuild'],
['--force'],
['--skip', '--rebuild'],
['--skip', '--force'],
['--rebuild', '--fetch'],
)
for extra_args in test_cases:
self.mock_stdout(True)
self.test_toy_build(ec_file=test_ec, extra_args=['--read-only-installdir'] + extra_args, force=False)
self.mock_stdout(False)
installdir_perms = os.stat(os.path.dirname(toy_install_dir)).st_mode & 0o777
self.assertEqual(installdir_perms, 0o755, "%s has default permissions" % os.path.dirname(toy_install_dir))
installdir_perms = os.stat(toy_install_dir).st_mode & 0o777
self.assertEqual(installdir_perms, 0o555, "%s has read-only permissions" % toy_install_dir)
toy_bin_perms = os.stat(toy_bin).st_mode & 0o777
self.assertEqual(toy_bin_perms, 0o555, "%s has read-only permissions" % toy_bin_perms)
toy_bin_perms = os.stat(os.path.join(toy_install_dir, 'README')).st_mode & 0o777
self.assertEqual(toy_bin_perms, 0o444, "%s has read-only permissions" % toy_bin_perms)
# also log file copied into install dir should be read-only (not just the 'easybuild/' subdir itself)
log_path = glob.glob(os.path.join(toy_install_dir, 'easybuild', '*log'))[0]
log_perms = os.stat(log_path).st_mode & 0o777
self.assertEqual(log_perms, 0o444, "%s has read-only permissions" % log_path)
adjust_permissions(toy_install_dir, stat.S_IWUSR, add=True)
shutil.rmtree(self.test_installpath)
# also check --group-writable-installdir
self.test_toy_build(ec_file=test_ec, extra_args=['--group-writable-installdir'])
installdir_perms = os.stat(toy_install_dir).st_mode & 0o777
self.assertEqual(installdir_perms, 0o775, "%s has group write permissions" % self.test_installpath)
toy_bin_perms = os.stat(toy_bin).st_mode & 0o777
self.assertEqual(toy_bin_perms, 0o775, "%s has group write permissions" % toy_bin_perms)
# make sure --read-only-installdir is robust against not having the 'easybuild/' subdir after installation
# this happens when for example using ModuleRC easyblock (because no devel module is created)
test_ec_txt += "\nmake_module = False"
write_file(test_ec, test_ec_txt)
self.test_toy_build(ec_file=test_ec, extra_args=['--read-only-installdir'], verify=False, raise_error=True)
# restore original umask
os.umask(orig_umask)
def test_toy_gid_sticky_bits(self):
"""Test setting gid and sticky bits."""
subdirs = [
(('',), False),
(('software',), False),
(('software', 'toy'), False),
(('software', 'toy', '0.0'), True),
(('modules', 'all'), False),
(('modules', 'all', 'toy'), False),
]
# no gid/sticky bits by default
self.test_toy_build()
for subdir, _ in subdirs:
fullpath = os.path.join(self.test_installpath, *subdir)
perms = os.stat(fullpath).st_mode
self.assertFalse(perms & stat.S_ISGID, "no gid bit on %s" % fullpath)
self.assertFalse(perms & stat.S_ISVTX, "no sticky bit on %s" % fullpath)
# git/sticky bits are set, but only on (re)created directories
self.test_toy_build(extra_args=['--set-gid-bit', '--sticky-bit'])
for subdir, bits_set in subdirs:
fullpath = os.path.join(self.test_installpath, *subdir)
perms = os.stat(fullpath).st_mode
if bits_set:
self.assertTrue(perms & stat.S_ISGID, "gid bit set on %s" % fullpath)
self.assertTrue(perms & stat.S_ISVTX, "sticky bit set on %s" % fullpath)
else:
self.assertFalse(perms & stat.S_ISGID, "no gid bit on %s" % fullpath)
self.assertFalse(perms & stat.S_ISVTX, "no sticky bit on %s" % fullpath)
# start with a clean slate, now gid/sticky bits should be set on everything
shutil.rmtree(self.test_installpath)
self.test_toy_build(extra_args=['--set-gid-bit', '--sticky-bit'])
for subdir, _ in subdirs:
fullpath = os.path.join(self.test_installpath, *subdir)
perms = os.stat(fullpath).st_mode
self.assertTrue(perms & stat.S_ISGID, "gid bit set on %s" % fullpath)
self.assertTrue(perms & stat.S_ISVTX, "sticky bit set on %s" % fullpath)
def test_toy_group_check(self):
"""Test presence of group check in generated (Lua) modules"""
fd, dummylogfn = tempfile.mkstemp(prefix='easybuild-dummy', suffix='.log')
os.close(fd)
# figure out a group that we're a member of to use in the test
out, ec = run_cmd('groups', simple=False)
self.assertEqual(ec, 0, "Failed to select group to use in test")
group_name = out.split(' ')[0].strip()
toy_ec = os.path.join(os.path.dirname(__file__), 'easyconfigs', 'test_ecs', 't', 'toy', 'toy-0.0.eb')
test_ec = os.path.join(self.test_prefix, 'test.eb')
args = [
test_ec,
'--force',
'--module-only',
]
for group in [group_name, (group_name, "Hey, you're not in the '%s' group!" % group_name)]:
if isinstance(group, string_type):
write_file(test_ec, read_file(toy_ec) + "\ngroup = '%s'\n" % group)
else:
write_file(test_ec, read_file(toy_ec) + "\ngroup = %s\n" % str(group))
self.mock_stdout(True)
outtxt = self.eb_main(args, logfile=dummylogfn, do_build=True, raise_error=True, raise_systemexit=True)
self.mock_stdout(False)
if get_module_syntax() == 'Tcl':
pattern = "Can't generate robust check in TCL modules for users belonging to group %s." % group_name
regex = re.compile(pattern, re.M)
self.assertTrue(regex.search(outtxt), "Pattern '%s' found in: %s" % (regex.pattern, outtxt))
elif get_module_syntax() == 'Lua':
lmod_version = os.getenv('LMOD_VERSION', 'NOT_FOUND')
if LooseVersion(lmod_version) >= LooseVersion('6.0.8'):
toy_mod = os.path.join(self.test_installpath, 'modules', 'all', 'toy', '0.0.lua')
toy_mod_txt = read_file(toy_mod)
if isinstance(group, tuple):
group_name = group[0]
error_msg_pattern = "Hey, you're not in the '%s' group!" % group_name
else:
group_name = group
error_msg_pattern = "You are not part of '%s' group of users" % group_name
pattern = '\n'.join([
r'^if not \( userInGroup\("%s"\) \) then' % group_name,
r' LmodError\("%s[^"]*"\)' % error_msg_pattern,
r'end$',
])
regex = re.compile(pattern, re.M)
self.assertTrue(regex.search(outtxt), "Pattern '%s' found in: %s" % (regex.pattern, toy_mod_txt))
else:
pattern = r"Can't generate robust check in Lua modules for users belonging to group %s. "
pattern += r"Lmod version not recent enough \(%s\), should be >= 6.0.8" % lmod_version
regex = re.compile(pattern % group_name, re.M)
self.assertTrue(regex.search(outtxt), "Pattern '%s' found in: %s" % (regex.pattern, outtxt))
else:
self.fail("Unknown module syntax: %s" % get_module_syntax())
write_file(test_ec, read_file(toy_ec) + "\ngroup = ('%s', 'custom message', 'extra item')\n" % group_name)
self.assertErrorRegex(SystemExit, '.*', self.eb_main, args, do_build=True,
raise_error=True, raise_systemexit=True)
def test_allow_system_deps(self):
"""Test allow_system_deps easyconfig parameter."""
tmpdir = tempfile.mkdtemp()
# copy toy easyconfig file, and append source_urls to it
topdir = os.path.dirname(os.path.abspath(__file__))
shutil.copy2(os.path.join(topdir, 'easyconfigs', 'test_ecs', 't', 'toy', 'toy-0.0.eb'), tmpdir)
ec_file = os.path.join(tmpdir, 'toy-0.0.eb')
write_file(ec_file, "\nallow_system_deps = [('Python', SYS_PYTHON_VERSION)]\n", append=True)
self.test_toy_build(ec_file=ec_file)
shutil.rmtree(tmpdir)
def test_toy_hierarchical(self):
"""Test toy build under example hierarchical module naming scheme."""
test_easyconfigs = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'easyconfigs', 'test_ecs')
self.setup_hierarchical_modules()
mod_prefix = os.path.join(self.test_installpath, 'modules', 'all')
args = [
os.path.join(test_easyconfigs, 't', 'toy', 'toy-0.0.eb'),
'--sourcepath=%s' % self.test_sourcepath,
'--buildpath=%s' % self.test_buildpath,
'--installpath=%s' % self.test_installpath,
'--debug',
'--unittest-file=%s' % self.logfile,
'--force',
'--robot=%s' % test_easyconfigs,
'--module-naming-scheme=HierarchicalMNS',
]
# test module paths/contents with foss build
extra_args = [
'--try-toolchain=foss,2018a',
# This test was created for the regex substitution of toolchains, to trigger this (rather than subtoolchain
# resolution) we must add an additional build option
'--disable-map-toolchains',
]
self.eb_main(args + extra_args, logfile=self.dummylogfn, do_build=True, verbose=True, raise_error=True)
# make sure module file is installed in correct path
toy_module_path = os.path.join(mod_prefix, 'MPI', 'GCC', '6.4.0-2.28', 'OpenMPI', '2.1.2', 'toy', '0.0')
if get_module_syntax() == 'Lua':
toy_module_path += '.lua'
self.assertExists(toy_module_path)
# check that toolchain load is expanded to loads for toolchain dependencies,
# except for the ones that extend $MODULEPATH to make the toy module available
if get_module_syntax() == 'Tcl':
load_regex_template = "load %s"
elif get_module_syntax() == 'Lua':
load_regex_template = r'load\("%s/.*"\)'
else:
self.fail("Unknown module syntax: %s" % get_module_syntax())
modtxt = read_file(toy_module_path)
for dep in ['foss', 'GCC', 'OpenMPI']:
load_regex = re.compile(load_regex_template % dep)
self.assertFalse(load_regex.search(modtxt), "Pattern '%s' not found in %s" % (load_regex.pattern, modtxt))
for dep in ['OpenBLAS', 'FFTW', 'ScaLAPACK']:
load_regex = re.compile(load_regex_template % dep)
self.assertTrue(load_regex.search(modtxt), "Pattern '%s' found in %s" % (load_regex.pattern, modtxt))
os.remove(toy_module_path)
# test module path with GCC/6.4.0-2.28 build
extra_args = [
'--try-toolchain=GCC,6.4.0-2.28',
]
self.eb_main(args + extra_args, logfile=self.dummylogfn, do_build=True, verbose=True, raise_error=True)
# make sure module file is installed in correct path
toy_module_path = os.path.join(mod_prefix, 'Compiler', 'GCC', '6.4.0-2.28', 'toy', '0.0')
if get_module_syntax() == 'Lua':
toy_module_path += '.lua'
self.assertExists(toy_module_path)
# no dependencies or toolchain => no module load statements in module file
modtxt = read_file(toy_module_path)
self.assertFalse(re.search("module load", modtxt))
os.remove(toy_module_path)
# test module path with GCC/6.4.0-2.28 build, pretend to be an MPI lib by setting moduleclass
extra_args = [
'--try-toolchain=GCC,6.4.0-2.28',
'--try-amend=moduleclass=mpi',
]
self.eb_main(args + extra_args, logfile=self.dummylogfn, do_build=True, verbose=True, raise_error=True)
# make sure module file is installed in correct path
toy_module_path = os.path.join(mod_prefix, 'Compiler', 'GCC', '6.4.0-2.28', 'toy', '0.0')
if get_module_syntax() == 'Lua':
toy_module_path += '.lua'
self.assertExists(toy_module_path)
# 'module use' statements to extend $MODULEPATH are present
modtxt = read_file(toy_module_path)
modpath_extension = os.path.join(mod_prefix, 'MPI', 'GCC', '6.4.0-2.28', 'toy', '0.0')
if get_module_syntax() == 'Tcl':
self.assertTrue(re.search(r'^module\s*use\s*"%s"' % modpath_extension, modtxt, re.M))
elif get_module_syntax() == 'Lua':
fullmodpath_extension = os.path.join(self.test_installpath, modpath_extension)
regex = re.compile(r'^prepend_path\("MODULEPATH", "%s"\)' % fullmodpath_extension, re.M)
self.assertTrue(regex.search(modtxt), "Pattern '%s' found in %s" % (regex.pattern, modtxt))
else:
self.fail("Unknown module syntax: %s" % get_module_syntax())
os.remove(toy_module_path)
# ... unless they shouldn't be
extra_args.append('--try-amend=include_modpath_extensions=') # pass empty string as equivalent to False
self.eb_main(args + extra_args, logfile=self.dummylogfn, do_build=True, verbose=True, raise_error=True)
modtxt = read_file(toy_module_path)
modpath_extension = os.path.join(mod_prefix, 'MPI', 'GCC', '6.4.0-2.28', 'toy', '0.0')
if get_module_syntax() == 'Tcl':
self.assertFalse(re.search(r'^module\s*use\s*"%s"' % modpath_extension, modtxt, re.M))
elif get_module_syntax() == 'Lua':
fullmodpath_extension = os.path.join(self.test_installpath, modpath_extension)
regex = re.compile(r'^prepend_path\("MODULEPATH", "%s"\)' % fullmodpath_extension, re.M)
self.assertFalse(regex.search(modtxt), "Pattern '%s' found in %s" % (regex.pattern, modtxt))
else:
self.fail("Unknown module syntax: %s" % get_module_syntax())
os.remove(toy_module_path)
# test module path with system/system build
extra_args = [
'--try-toolchain=system,system',
]
self.eb_main(args + extra_args, logfile=self.dummylogfn, do_build=True, verbose=True, raise_error=True)
# make sure module file is installed in correct path
toy_module_path = os.path.join(mod_prefix, 'Core', 'toy', '0.0')
if get_module_syntax() == 'Lua':
toy_module_path += '.lua'
self.assertExists(toy_module_path)
# no dependencies or toolchain => no module load statements in module file
modtxt = read_file(toy_module_path)
self.assertFalse(re.search("module load", modtxt))
os.remove(toy_module_path)
# test module path with system/system build, pretend to be a compiler by setting moduleclass
extra_args = [
'--try-toolchain=system,system',
'--try-amend=moduleclass=compiler',
]
self.eb_main(args + extra_args, logfile=self.dummylogfn, do_build=True, verbose=True, raise_error=True)
# make sure module file is installed in correct path
toy_module_path = os.path.join(mod_prefix, 'Core', 'toy', '0.0')
if get_module_syntax() == 'Lua':
toy_module_path += '.lua'
self.assertExists(toy_module_path)
# no dependencies or toolchain => no module load statements in module file
modtxt = read_file(toy_module_path)
modpath_extension = os.path.join(mod_prefix, 'Compiler', 'toy', '0.0')
if get_module_syntax() == 'Tcl':
self.assertTrue(re.search(r'^module\s*use\s*"%s"' % modpath_extension, modtxt, re.M))
elif get_module_syntax() == 'Lua':
fullmodpath_extension = os.path.join(self.test_installpath, modpath_extension)
regex = re.compile(r'^prepend_path\("MODULEPATH", "%s"\)' % fullmodpath_extension, re.M)
self.assertTrue(regex.search(modtxt), "Pattern '%s' found in %s" % (regex.pattern, modtxt))
else:
self.fail("Unknown module syntax: %s" % get_module_syntax())
os.remove(toy_module_path)
# building a toolchain module should also work
gompi_module_path = os.path.join(mod_prefix, 'Core', 'gompi', '2018a')
# make sure Core/gompi/2018a module that may already be there is removed (both Tcl/Lua variants)
for modfile in glob.glob(gompi_module_path + '*'):
os.remove(modfile)
if get_module_syntax() == 'Lua':
gompi_module_path += '.lua'
args[0] = os.path.join(test_easyconfigs, 'g', 'gompi', 'gompi-2018a.eb')
self.modtool.purge()
self.eb_main(args, logfile=self.dummylogfn, do_build=True, verbose=True, raise_error=True)
self.assertExists(gompi_module_path)
def test_toy_hierarchical_subdir_user_modules(self):
"""
Test toy build under example hierarchical module naming scheme that was created using --subidr-user-modules
"""
# redefine $HOME to a temporary location we can fiddle with
home = os.path.join(self.test_prefix, 'HOME')
mkdir(home)
os.environ['HOME'] = home
test_easyconfigs = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'easyconfigs', 'test_ecs')
self.setup_hierarchical_modules()
mod_prefix = os.path.join(self.test_installpath, 'modules', 'all')
gcc_mod_subdir = os.path.join('Compiler', 'GCC', '6.4.0-2.28')
openmpi_mod_subdir = os.path.join('MPI', 'GCC', '6.4.0-2.28', 'OpenMPI', '2.1.2')
# include guarded 'module use' statement in GCC & OpenMPI modules,
# like there would be when --subdir-user-modules=modules/all is used
extra_modtxt = '\n'.join([
'if { [ file isdirectory [ file join $env(HOME) "modules/all/%s" ] ] } {' % gcc_mod_subdir,
' module use [ file join $env(HOME) "modules/all/%s" ]' % gcc_mod_subdir,
'}',
])
gcc_mod = os.path.join(mod_prefix, 'Core', 'GCC', '6.4.0-2.28')
write_file(gcc_mod, extra_modtxt, append=True)