Ejemplo n.º 1
0
    def testDetectStorageFail(self):
        """Tests that the DockerExplorer.DetectStorage function fails on
    Docker directory."""
        de_object = de.DockerExplorer()
        de_object.docker_directory = 'this_dir_shouldnt_exist'

        expected_error_message = (
            'this_dir_shouldnt_exist is not a Docker directory')
        with self.assertRaises(errors.BadStorageException) as err:
            de_object._SetDockerDirectory('this_dir_shouldnt_exist')
        self.assertEqual(expected_error_message, err.exception.message)
Ejemplo n.º 2
0
    def _setup(cls, driver, driver_class):
        """Internal method to set up the TestCase on a specific storate."""
        cls.driver = driver
        docker_directory_path = os.path.join('test_data', 'docker')
        if not os.path.isdir(docker_directory_path):
            docker_tar = os.path.join('test_data', cls.driver + '.tgz')
            tar = tarfile.open(docker_tar, 'r:gz')
            tar.extractall('test_data')
            tar.close()
        cls.de_object = de.DockerExplorer()
        cls.de_object._SetDockerDirectory(docker_directory_path)

        cls.driver_class = driver_class
Ejemplo n.º 3
0
    def testDetectStorageFail(self):
        """Tests that the DockerExplorer.DetectStorage function fails on
    non-existing Docker directory."""
        de_object = de.DockerExplorer()
        de_object.docker_directory = 'this_dir_shouldnt_exist'

        expected_error_message = (
            'this_dir_shouldnt_exist is not a Docker directory\n'
            'Please specify the Docker\'s directory path.\n'
            'hint: de.py -r /var/lib/docker')

        with self.assertRaises(errors.BadStorageException) as err:
            de_object._SetDockerDirectory('this_dir_shouldnt_exist')
        self.assertEqual(expected_error_message, err.exception.message)
Ejemplo n.º 4
0
    def setUpClass(cls):
        docker_directory_path = os.path.join('test_data', 'docker')
        if not os.path.isdir(docker_directory_path):
            docker_tar = os.path.join('test_data', 'aufs.tgz')
            tar = tarfile.open(docker_tar, 'r:gz')
            tar.extractall('test_data')
            tar.close()

        de_test_object = de.DockerExplorer()
        de_test_object.docker_directory = docker_directory_path
        cls.storage = de_test_object.DetectStorage()
        cls.container_id = (
            '7b02fb3e8a665a63e32b909af5babb7d6ba0b64e10003b2d9534c7d5f2af8966')
        cls.image_id = (
            '7968321274dc6b6171697c33df7815310468e694ac5be0ec03ff053bb135e768')
Ejemplo n.º 5
0
    def setUpClass(cls):
        docker_directory_path = os.path.join('test_data', 'docker')
        if not os.path.isdir(docker_directory_path):
            docker_tar = os.path.join('test_data', 'overlay2.tgz')
            tar = tarfile.open(docker_tar, 'r:gz')
            tar.extractall('test_data')
            tar.close()

        de_test_object = de.DockerExplorer()
        de_test_object.docker_directory = docker_directory_path
        cls.storage = de_test_object.DetectStorage()
        cls.container_id = (
            '8e8b7f23eb7cbd4dfe7e91646ddd0e0f524218e25d50113559f078dfb2690206')
        cls.image_id = (
            '8ac48589692a53a9b8c2d1ceaa6b402665aa7fe667ba51ccc03002300856d8c7')
Ejemplo n.º 6
0
    def setUpClass(cls):
        docker_directory_path = os.path.join('test_data', 'docker')
        if not os.path.isdir(docker_directory_path):
            docker_tar = os.path.join('test_data', 'overlay.tgz')
            tar = tarfile.open(docker_tar, 'r:gz')
            tar.extractall('test_data')
            tar.close()

        de_test_object = de.DockerExplorer()
        de_test_object.docker_directory = docker_directory_path
        cls.storage = de_test_object.DetectStorage()
        cls.container_id = (
            '5dc287aa80b460652a5584e80a5c8c1233b0c0691972d75424cf5250b917600a')
        cls.image_id = (
            '5b0d59026729b68570d99bc4f3f7c31a2e4f2a5736435641565d93e7c25bd2c3')
Ejemplo n.º 7
0
    def _setup(cls, driver, driver_class, storage_version=2):
        """Internal method to set up the TestCase on a specific storage."""
        cls.driver = driver
        docker_directory_path = os.path.join('test_data', 'docker')
        if not os.path.isdir(docker_directory_path):
            docker_tar = os.path.join(
                'test_data', '{0:s}.v{1:d}.tgz'.format(driver,
                                                       storage_version))
            tar = tarfile.open(docker_tar, 'r:gz')
            tar.extractall('test_data')
            tar.close()
        cls.de_object = de.DockerExplorer()
        cls.de_object._SetDockerDirectory(docker_directory_path)
        cls.de_object._DetectDockerStorageVersion()

        cls.driver_class = driver_class
        cls.storage_version = storage_version
Ejemplo n.º 8
0
  def testParseArguments(self):
    """Tests the DockerExplorer.ParseArguments function."""
    de_test_object = de.DockerExplorer()

    prog = sys.argv[0]

    expected_docker_root = os.path.join('test_data', 'docker')

    args = [prog, '-r', expected_docker_root, 'list', 'repositories']
    sys.argv = args

    options = de_test_object.ParseArguments()
    usage_string = de_test_object._argument_parser.format_usage()
    expected_usage = '[-h] [-r DOCKER_DIRECTORY] {mount,list,history} ...\n'
    self.assertTrue(expected_usage in usage_string)

    de_test_object.ParseOptions(options)
    self.assertEqual(expected_docker_root, options.docker_directory)
Ejemplo n.º 9
0
    def testDetectStorage(self):
        """Tests the DockerExplorer.DetectStorage function on a Overlay2 storage."""
        de_test_object = de.DockerExplorer()
        de_test_object.docker_directory = 'this_dir_shouldnt_exist'

        expected_error_message = (
            'this_dir_shouldnt_exist is not a Docker directory\n'
            'Please specify the Docker\'s directory path.\n'
            'hint: de.py -r /var/lib/docker')

        with self.assertRaises(de.BadStorageException) as err:
            de_test_object.DetectStorage()
        self.assertEqual(expected_error_message, err.exception.message)

        de_test_object.docker_directory = os.path.join('test_data', 'docker')
        storage_object = de_test_object.DetectStorage()
        self.assertIsNotNone(storage_object)
        self.assertIsInstance(storage_object, overlay.OverlayStorage)
        self.assertEqual(storage_object.STORAGE_METHOD, 'overlay2')

        self.assertEqual(2, storage_object.docker_version)
        self.assertEqual('config.v2.json',
                         storage_object.container_config_filename)