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_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)
class TestApi(TestCase): 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 tearDown(self): shutil.rmtree(self.tmpdir) print("---END------------------------------------------") 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 docker_image = "gcr.io/tensorflow/tensorflow:1.0.0" client = DockerApiConnection(image=docker_image) 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") def test_get_images(self): '''test_get_images will obtain a list of images ''' from docker.api import DockerApiConnection images = self.client.get_images() self.assertTrue(isinstance(images, list)) self.assertTrue(len(images) > 1) 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] def test_get_layer(self): '''test_get_layer will download docker layers ''' from docker.api import DockerApiConnection images = self.client.get_images() print("Case 1: Download an existing layer, should succeed") layer_file = self.client.get_layer(image_id=images[0], download_folder=self.tmpdir) self.assertTrue(os.path.exists(layer_file))
class TestApi(TestCase): 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 tearDown(self): shutil.rmtree(self.tmpdir) print("---END------------------------------------------") 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() # Default tag should be latest self.assertTrue("fsLayers" in manifest or "layers" 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() 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_tags(self): '''test_get_tags will obtain a list of tags ''' from docker.api import DockerApiConnection print("Case 1: Ask for tags from standard %s/%s" %(self.client.namespace, self.client.repo_name)) tags = self.client.get_tags() self.assertTrue(isinstance(tags,list)) self.assertTrue(len(tags)>1) [self.assertTrue(x in tags) for x in ['xenial','latest','trusty','yakkety']] 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']] def test_get_layer(self): '''test_get_layer will download docker layers ''' from docker.api import DockerApiConnection images = self.client.get_images() print("Case 1: Download an existing layer, should succeed") layer_file = self.client.get_layer(image_id=images[0], download_folder = self.tmpdir) self.assertTrue(os.path.exists(layer_file))
class TestApi(TestCase): 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 tearDown(self): shutil.rmtree(self.tmpdir) print("---END------------------------------------------") 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 docker_image = "gcr.io/tensorflow/tensorflow:1.0.0" client = DockerApiConnection(image=docker_image) print("Case 1: Ask when we don't need token returns None") token = client.update_token() self.assertEqual(token, None) def test_get_token_url(self): ''' test_get_token_url tests token url generation from a bearer auth challenge ''' realm = 'https://some-registry.io/auth' service = "some-service" scope = "some-scope" expires_in = 9000 cases = ( [("realm", realm), ("service", service), ("scope", scope)], [("service", service), ("scope", scope), ("realm", realm)], [("scope", scope), ("realm", realm)], [("realm", realm), ("service", service)], [("realm", realm)], ) for case in cases: challenge = 'Bearer %s' % ','.join( ['%s="%s"' % (k, v) for k, v in case]) target_params = [(k, v) for k, v in case if k != 'realm'] target_params.append(('expires_in', expires_in)) target_params.sort() target_url = "{realm}?{query}".format( realm=realm, query='&'.join(['%s=%s' % (k, v) for k, v in target_params])) token_url = self.client.get_token_url(challenge, expires_in, sort_query_params=True) self.assertEqual(token_url, target_url) 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_images(self): '''test_get_images will obtain a list of images ''' from docker.api import DockerApiConnection images = self.client.get_images() self.assertTrue(isinstance(images, list)) self.assertTrue(len(images) > 1) def test_get_tags(self): '''test_get_tags will obtain a list of tags ''' from docker.api import DockerApiConnection print("Case 1: Ask for tags from standard %s" % self.client.repo_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] def test_get_layer(self): '''test_get_layer will download docker layers ''' from docker.api import DockerApiConnection images = self.client.get_images() print("Case 1: Download an existing layer, should succeed") layer_file = self.client.get_layer(image_id=images[0], download_folder=self.tmpdir) self.assertTrue(os.path.exists(layer_file))