def setUpModule(): global WARNING_CONTEXT global PROVIDER global TEMPDIR global KEYPATH WARNING_CONTEXT = warnings.catch_warnings() WARNING_CONTEXT.__enter__() warnings.simplefilter('ignore', ResourceWarning) PROVIDER = DummySlurmBackend(n_workers=5, staging_dir=STAGING_DIR) PROVIDER.__enter__() TEMPDIR = tempfile.TemporaryDirectory() KEYPATH = os.path.join(TEMPDIR.name, 'id_rsa') subprocess.check_call( 'ssh-keygen -q -b 2048 -t rsa -f {} -N ""'.format(KEYPATH), shell=True) subprocess.check_call('docker exec {} mkdir -p -m 600 /root/.shh'.format( PROVIDER.controller.short_id), shell=True) subprocess.check_call('docker cp {}.pub {}:/root/tmpkey'.format( KEYPATH, PROVIDER.controller.short_id), shell=True) subprocess.check_call( 'docker exec {} bash -c "cat /root/tmpkey >> /root/.ssh/authorized_keys"' .format(PROVIDER.controller.short_id), shell=True) subprocess.check_call( 'docker exec {} chown root:root /root/.ssh/authorized_keys'.format( PROVIDER.controller.short_id), shell=True)
def setUpModule(): global WARNING_CONTEXT global BACKEND WARNING_CONTEXT = warnings.catch_warnings() WARNING_CONTEXT.__enter__() warnings.simplefilter('ignore', ResourceWarning) BACKEND = DummySlurmBackend(n_workers=1, staging_dir=STAGING_DIR) BACKEND.__enter__()
def setUpModule(): global WARNING_CONTEXT global BACKEND WARNING_CONTEXT = warnings.catch_warnings() WARNING_CONTEXT.__enter__() warnings.simplefilter('ignore', ResourceWarning) BACKEND = DummySlurmBackend(n_workers=1, staging_dir=STAGING_DIR) BACKEND.__enter__() with BACKEND.transport() as transport: if not transport.isdir(BACKEND.bind_path.name): if not transport.isdir(os.path.dirname(BACKEND.bind_path.name)): transport.makedirs(os.path.dirname(BACKEND.bind_path.name)) transport.mklink('/mnt/nfs', BACKEND.bind_path.name)
def test_container_invokation(self): """ Tests that commands can be invoked in a container """ container = self.dkr.containers.run('gcr.io/broad-cga-aarong-gtex/slurmind', '/bin/bash', detach=True, tty=True) self.assertIsInstance(container, docker.models.containers.Container) callback = DummySlurmBackend.exec_run(container, 'ls') self.assertTrue(callable(callback)) result = callback() self.assertEqual(result.exit_code, 0) self.assertEqual( result.output, b'bin\nboot\nconf_templates\ncontroller.py\ndev\netc\ngcsdk\nhome' b'\nlib\nlib32\nlib64\nlibx32\nmedia\nmnt\nopt\nproc\nroot\nrun' b'\nsbin\nsrv\nsys\ntmp\nusr\nvar\nworker.sh\n' ) container.stop(timeout=1)
def test_xargs(self): """ Runs a quick test of the xargs orchestrator """ with DummySlurmBackend(n_workers=1, staging_dir=STAGING_DIR) as backend: with backend.transport() as transport: transport.sendtree( os.path.dirname(os.path.dirname( os.path.dirname(__file__))), '/opt/canine') rc, stdout, stderr = backend.invoke( "bash -c 'pip3 install -e /opt/canine && pip3 install pyopenssl; echo foo | canine-xargs -d /mnt/nfs echo @'" ) self.assertFalse(rc) time.sleep(5) sacct = backend.sacct() self.assertIn('2_0', sacct.index.values) self.assertTrue((sacct['ExitCode'] == '0:0').all()) with backend.transport() as transport: self.assertTrue(transport.isfile('/mnt/nfs/2.0.stdout')) with transport.open('/mnt/nfs/2.0.stdout', 'r') as r: self.assertEqual(r.read().strip(), 'foo')
def setUpClass(cls): cls.backend = DummySlurmBackend(n_workers=5, staging_dir=STAGING_DIR) cls.backend.__enter__()