def test_get_build_info(self): step = Box( {"uses": "popperized/bin/sh@master", "args": ["ls"], "name": "one",}, default_box=True, ) with SingularityRunner() as sr: build, img, build_sources = sr._get_build_info(step) self.assertEqual(build, True) self.assertEqual(img, "popperized/bin") self.assertTrue(f"{os.environ['HOME']}/.cache/popper" in build_sources) self.assertTrue(f"github.com/popperized/bin/sh" in build_sources) step = Box( { "uses": "docker://alpine:3.9", "runs": ["sh", "-c", "echo $FOO > hello.txt ; pwd"], "env": {"FOO": "bar"}, "name": "1", }, default_box=True, ) with SingularityRunner() as sr: build, img, build_sources = sr._get_build_info(step) self.assertEqual(build, False) self.assertEqual(img, "docker://alpine:3.9") self.assertEqual(build_sources, None)
def test_get_build_info(self): step = { 'uses': 'popperized/bin/sh@master', 'args': ['ls'], 'name': 'one', 'repo_dir': '/path/to/repo/dir', 'step_dir': 'sh' } with SingularityRunner() as sr: build, img, build_sources = sr._get_build_info(step) self.assertEqual(build, True) self.assertEqual(img, 'popperized/bin') self.assertEqual(build_sources, '/path/to/repo/dir/sh') step = { 'uses': 'docker://alpine:3.9', 'runs': ['sh', '-c', 'echo $FOO > hello.txt ; pwd'], 'env': { 'FOO': 'bar' }, 'name': '1' } with SingularityRunner() as sr: build, img, build_sources = sr._get_build_info(step) self.assertEqual(build, False) self.assertEqual(img, 'docker://alpine:3.9') self.assertEqual(build_sources, None)
def test_get_container_options(self): config_dict = { "engine": { "name": "singularity", "options": { "hostname": "popper.local", "ipc": True, "bind": ["/path/in/host:/path/in/container"], }, } } config = ConfigLoader.load(config_file=config_dict) with SingularityRunner(config=config) as sr: sr._setup_singularity_cache() options = sr._get_container_options() self.assertEqual( options, [ "--userns", "--pwd", "/workspace", "--bind", f"{os.getcwd()}:/workspace", "--bind", "/path/in/host:/path/in/container", "--hostname", "popper.local", "--ipc", ], )
def test_setup_singularity_cache(self): config = PopperConfig() config.wid = "abcd" with SingularityRunner(config=config) as sr: sr._setup_singularity_cache() self.assertEqual( f'{os.environ["HOME"]}/.cache/popper/singularity/abcd', sr._singularity_cache)
def test_setup_singularity_cache(self): config = ConfigLoader.load() with SingularityRunner(config=config) as sr: sr._setup_singularity_cache() self.assertEqual( f'{os.environ["HOME"]}/.cache/popper/singularity/{config.wid}', sr._singularity_cache, )
def test_create_container(self): config = ConfigLoader.load() step_one = Box( { "uses": "docker://*****:*****@master", "args": ["ls"], "id": "kontainer_two", }, default_box=True, ) cid_one = pu.sanitized_name(step_one.id, config.wid) cid_two = pu.sanitized_name(step_two.id, config.wid) with SingularityRunner(config=config) as sr: sr._setup_singularity_cache() sr._create_container(step_one, cid_one) self.assertEqual( os.path.exists(os.path.join(sr._singularity_cache, cid_one)), True) os.remove(os.path.join(sr._singularity_cache, cid_one)) with SingularityRunner(config=config) as sr: sr._setup_singularity_cache() sr._create_container(step_one, cid_two) self.assertEqual( os.path.exists(os.path.join(sr._singularity_cache, cid_two)), True) os.remove(os.path.join(sr._singularity_cache, cid_two))
def test_create_container(self): config = PopperConfig() config.wid = "abcd" step_one = { 'uses': 'docker://*****:*****@master', 'args': ['ls'], 'name': 'kontainer_two', 'repo_dir': f'{os.environ["HOME"]}/.cache/popper/abcd/github.com/popperized/bin', 'step_dir': 'sh' } cid_one = pu.sanitized_name(step_one['name'], config.wid) cid_two = pu.sanitized_name(step_two['name'], config.wid) with SingularityRunner(config=config) as sr: sr._setup_singularity_cache() c_one = sr._create_container(step_one, cid_one) self.assertEqual( os.path.exists(os.path.join(sr._singularity_cache, cid_one)), True) os.remove(os.path.join(sr._singularity_cache, cid_one)) with SingularityRunner(config=config) as sr: sr._setup_singularity_cache() c_two = sr._create_container(step_one, cid_two) self.assertEqual( os.path.exists(os.path.join(sr._singularity_cache, cid_two)), True) os.remove(os.path.join(sr._singularity_cache, cid_two))
def test_get_container_options(self): config_dict = { 'engine': { 'name': 'singularity', 'options': { 'hostname': 'popper.local', 'ipc': True, 'bind': ['/path/in/host:/path/in/container'] } } } config = PopperConfig(config_file=config_dict) config.wid = "abcd" with SingularityRunner(config=config) as sr: sr._setup_singularity_cache() options = sr._get_container_options() self.assertEqual(options, [ '--userns', '--pwd', '/workspace', '--bind', f'{os.getcwd()}:/workspace', '--bind', '/path/in/host:/path/in/container', '--hostname', 'popper.local', '--ipc' ])
def test_singularity_start(self): repo = self.mk_repo() conf = PopperConfig(engine_name='singularity', workspace_dir=repo.working_dir) step = { 'uses': 'docker://*****:*****@master' args: 'ls' """) wf.parse() r.run(wf) wf = YMLWorkflow(""" version: '1' steps: - uses: 'docker://alpine:3.9' runs: ['sh', '-c', 'echo $FOO > hello.txt ; pwd'] env: { FOO: bar } """) wf.parse() r.run(wf) with open(os.path.join(repo.working_dir, 'hello.txt'), 'r') as f: self.assertEqual(f.read(), 'bar\n') wf = YMLWorkflow(""" version: '1' steps: - uses: 'docker://alpine:3.9' runs: 'nocommandisnamedlikethis' """) wf.parse() self.assertRaises(SystemExit, r.run, wf) repo.close()
def test_singularity_start(self): repo = self.mk_repo() conf = ConfigLoader.load(engine_name="singularity", workspace_dir=repo.working_dir) step = Box( { "uses": "docker://*****:*****@master", "args": ["ls"], }] } r.run(WorkflowParser.parse(wf_data=wf_data)) wf_data = { "steps": [{ "uses": "docker://alpine:3.9", "args": ["sh", "-c", "echo $FOO > hello.txt ; pwd"], "env": { "FOO": "bar" }, }] } r.run(WorkflowParser.parse(wf_data=wf_data)) with open(os.path.join(repo.working_dir, "hello.txt"), "r") as f: self.assertEqual(f.read(), "bar\n") wf_data = { "steps": [{ "uses": "docker://alpine:3.9", "args": ["nocommandisnamedlikethis"], }] } self.assertRaises(SystemExit, r.run, WorkflowParser.parse(wf_data=wf_data)) repo.close()