def setUp(self): self.image = 'docker://ubuntu:latest' self.tmpdir = tempfile.mkdtemp() os.environ['SINGULARITY_ROOTFS'] = self.tmpdir os.mkdir('%s/.singularity.d' % self.tmpdir) from docker.api import DockerApiConnection self.client = DockerApiConnection(image=self.image) print("\n---START----------------------------------------")
def test_create_runscript(self): '''test_create_runscript should ensure that a runscript is generated with some command ''' from docker.api import DockerApiConnection print('Testing creation of runscript') from docker.tasks import extract_runscript manifest = self.client.get_manifest(old_version=True) print("Case 1: Asking for CMD when none defined") default_cmd = 'exec /bin/bash "$@"' runscript = extract_runscript(manifest=manifest, includecmd=True) # Commands are always in format exec [] "$@" # 'exec echo \'Hello World\' "$@"' self.assertTrue(default_cmd in runscript) print("Case 2: Asking for ENTRYPOINT when none defined") runscript = extract_runscript(manifest=manifest) self.assertTrue(default_cmd in runscript) client = DockerApiConnection(image="docker://bids/mriqc:0.0.2") manifest = client.get_manifest(old_version=True) print("Case 3: Asking for ENTRYPOINT when defined") runscript = extract_runscript(manifest=manifest) self.assertTrue('exec /run_mriqc "$@"' in runscript) print("Case 4: Asking for CMD when defined") runscript = extract_runscript(manifest=manifest, includecmd=True) self.assertTrue('exec --help "$@"' in runscript) print("Case 5: Asking for ENTRYPOINT when None, should return CMD") from docker.tasks import get_configs client = DockerApiConnection(image="tensorflow/tensorflow:1.0.0") manifest = client.get_manifest(old_version=True) configs = get_configs(manifest, ['Cmd', 'Entrypoint']) self.assertEqual(configs['Entrypoint'], None) runscript = extract_runscript(manifest=manifest) self.assertTrue(configs['Cmd'] in runscript)
def test_get_token(self): '''test_get_token will obtain a token from the Docker registry for a namepspace and repo. ''' from docker.api import DockerApiConnection client = DockerApiConnection( image="gcr.io/tensorflow/tensorflow:1.0.0") print("Case 1: Ask when we don't need token returns None") token = client.update_token() self.assertEqual(token, None)
def test_get_manifest(self): '''test_get_manifest will obtain a library/repo manifest ''' from docker.api import DockerApiConnection print("Case 1: Obtain manifest for %s/%s" % (self.client.namespace, self.client.repo_name)) manifest = self.client.get_manifest(old_version=True) # Default tag should be latest self.assertTrue("fsLayers" in manifest) # Giving a bad tag sould return error print("Case 3: Bad tag should print valid tags and exit") client = DockerApiConnection(image="ubuntu:mmm.avocado") # Should work for custom registries print("Case 4: Obtain manifest from custom registry") client = DockerApiConnection(image="gcr.io/tensorflow/tensorflow") manifest = client.get_manifest(old_version=True) self.assertTrue("fsLayers" in manifest or "layers" in manifest)
def test_get_images(self): '''test_get_images will obtain a list of images ''' from docker.api import DockerApiConnection print("Case 1: Ask for images") images = self.client.get_images() self.assertTrue(isinstance(images, list)) self.assertTrue(len(images) > 1) print("Case 2: Ask for images from custom registry") client = DockerApiConnection(image="gcr.io/tensorflow/tensorflow") images = client.get_images() self.assertTrue(isinstance(images, list)) self.assertTrue(len(images) > 1)
def test_get_manifest(self): '''test_get_manifest will obtain a library/repo manifest ''' from docker.api import DockerApiConnection print("Case 1: Obtain manifest for %s" % self.client.repo_name) manifest = self.client.get_manifest(old_version=True) # Default tag should be latest self.assertTrue("fsLayers" in manifest) # Giving a bad tag sould return error print("Case 3: Bad tag should print valid tags and exit") client = DockerApiConnection(image="ubuntu:mmm.avocado")
def test_get_tags(self): '''test_get_tags will obtain a list of tags ''' from docker.api import DockerApiConnection full_name = "%s/%s" % (self.client.namespace, self.client.repo_name) print("Case 1: Ask for tags from standard %s" % full_name) tags = self.client.get_tags() self.assertTrue(isinstance(tags, list)) self.assertTrue(len(tags) > 1) ubuntu_tags = ['xenial', 'latest', 'trusty', 'yakkety'] [self.assertTrue(x in tags) for x in ubuntu_tags] print("Case 2: Ask for tags from custom registry") client = DockerApiConnection(image="gcr.io/tensorflow/tensorflow") tags = client.get_tags() self.assertTrue(isinstance(tags, list)) self.assertTrue(len(tags) > 1) [self.assertTrue(x in tags) for x in ['latest', 'latest-gpu']]