Exemple #1
0
 def testGetBadManifest(self):
     """Tests that GetManifest failes on an unknown image."""
     dl = downloader.DockerImageDownloader('non/existing:image')
     with tempfile.TemporaryDirectory() as tmp_dir:
         dl._output_directory = tmp_dir
         with self.assertRaises(errors.DownloaderException):
             dl._GetManifest()
Exemple #2
0
    def Main(self):
        """The main method for the DockerExplorerTool class.

    It instantiates the Storage Object and Handles arguments parsing.

    Raises:
      ValueError: If the arguments couldn't be parsed.
    """
        options = self.ParseArguments()

        self._SetLogging(debug=options.debug)

        self._explorer = explorer.Explorer()

        if options.command == 'download':
            try:
                dl = downloader.DockerImageDownloader(options.image_name)
                if options.what == 'all':
                    dl.DownloadPseudoDockerfile()
                    dl.DownloadLayers()
                if options.what == 'dockerfile':
                    dl.DownloadPseudoDockerfile()
                if options.what == 'layers':
                    dl.DownloadLayers()
            except errors.DownloaderException as exc:
                logger.debug(exc.message)
                logger.debug(exc.http_message)
                logger.error(
                    'Make sure the image \'{0:s}:{1:s}\' exists in the public Docker '
                    'Hub registry: https://hub.docker.com/r/{2:s}/tags'.format(
                        dl.repository, dl.tag, dl.repository))
            return

        self._explorer.SetDockerDirectory(options.docker_directory)
        self._explorer.DetectDockerStorageVersion()

        if not options.command:
            self.ShowContainers()

        elif options.command == 'mount':
            self.Mount(options.container_id, options.mountpoint)

        elif options.command == 'history':
            self.ShowHistory(options.container_id,
                             show_empty_layers=options.show_empty)

        elif options.command == 'list':
            if options.what == 'all_containers':
                self.ShowContainers()
            elif options.what == 'running_containers':
                self.ShowContainers(only_running=True)
            elif options.what == 'repositories':
                print(self._explorer.GetRepositoriesString())
        else:
            raise ValueError('Unhandled command %s' % options.command)
Exemple #3
0
    def testSetupRepository(self):
        """Tests the DockerImageDownloader._SetupRepository() method."""

        dl = downloader.DockerImageDownloader('')
        with tempfile.TemporaryDirectory() as tmp_dir:
            dl._output_directory = tmp_dir
            dl._SetupRepository('foo')
            self.assertEqual('library/foo', dl.repository)
            self.assertEqual('latest', dl.tag)

            dl._SetupRepository('foo/bar')
            self.assertEqual('foo/bar', dl.repository)
            self.assertEqual('latest', dl.tag)

            dl._SetupRepository('foo:bar')
            self.assertEqual('library/foo', dl.repository)
            self.assertEqual('bar', dl.tag)

            dl._SetupRepository('foo/bar:baz')
            self.assertEqual('foo/bar', dl.repository)
            self.assertEqual('baz', dl.tag)
Exemple #4
0
 def setUpClass(cls):
     cls.dl_object = downloader.DockerImageDownloader(cls.TEST_REPO)