예제 #1
0
  def testGenerateBindMountPoints(self):
    """Tests generating command to mount 'bind' MountPoints."""
    self.maxDiff = None
    de_object = de.DockerExplorerTool()
    de_object._explorer = self.explorer_object
    container_obj = de_object._explorer.GetContainer(
        '8b6e90cc742bd63f6acb7ecd40ddadb4e5dee27d8db2b739963f7cd2c7bcff4a')

    commands = container_obj.storage_object._MakeVolumeMountCommands(
        container_obj, '/mnt')
    commands = [' '.join(x) for x in commands]
    expected_commands = [
        ('/bin/mount --bind -o ro {0:s}/opt/vols/bind'
         ' /mnt/opt').format(os.path.abspath('test_data'))]
    self.assertEqual(expected_commands, commands)
예제 #2
0
  def testGenerateVolumesMountpoints(self):
    """Tests generating command to mount 'volumes' MountPoints."""
    self.maxDiff = None
    de_object = de.DockerExplorerTool()
    de_object._explorer = self.explorer_object
    container_obj = de_object._explorer.GetContainer(
        '712909b5ab80d8785841f12e361c218a2faf5365f9ed525f2a0d6b6590ba89cb')

    commands = container_obj.storage_object._MakeVolumeMountCommands(
        container_obj, '/mnt')
    commands = [' '.join(x) for x in commands]
    expected_commands = [
        ('/bin/mount --bind -o ro {0:s}/volumes/'
         'f5479c534bbc6e2b9861973c2fbb4863ff5b7b5843c098d7fb1a027fe730a4dc/'
         '_data /mnt/opt/vols/volume').format(os.path.abspath('test_data'))]
    self.assertEqual(expected_commands, commands)
예제 #3
0
    def testParseArguments(self):
        """Tests the DockerExplorerTool.ParseArguments function."""
        de_object = de.DockerExplorerTool()

        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_object.ParseArguments()
        usage_string = de_object._argument_parser.format_usage()
        expected_usage = ('[-h] [-d] [-r DOCKER_DIRECTORY] [-V]\n'
                          '                {download,mount,list,history}')
        self.assertTrue(expected_usage in usage_string)
        self.assertEqual(expected_docker_root, options.docker_directory)
예제 #4
0
    def testGenerateBindMountPoints(self):
        """Tests generating command to mount 'bind' MountPoints."""
        self.maxDiff = None
        de_object = de.DockerExplorerTool()
        de_object._explorer = self.explorer_object
        container_obj = de_object._explorer.GetContainer(
            '8b6e90cc742bd63f6acb7ecd40ddadb4e5dee27d8db2b739963f7cd2c7bcff4a')

        commands = container_obj.storage_object._MakeVolumeMountCommands(
            container_obj, '/mnt')
        commands = [' '.join(x) for x in commands]
        expected_commands = [(
            '/bin/mount --bind -o ro '
            'test_data/docker/volumes/eda9ee495beccf988d963bf91de0276847e838b9531ab9118caef38a33894bb4/_data '
            '/mnt/var/jenkins_home'
        ), '/bin/mount --bind -o ro test_data/docker/opt/vols/bind /mnt/opt']
        self.assertEqual(expected_commands, commands)
예제 #5
0
  def testShowHistory(self):
    """Tests that ShowHistory shows history."""
    self.maxDiff = None
    de_object = de.DockerExplorerTool()
    de_object._explorer = self.explorer_object
    # We pick one of the container IDs.
    container_id = container.GetAllContainersIDs(self.docker_directory_path)[0]
    with unittest.mock.patch('sys.stdout', new=StringIO()) as fake_output:
      de_object.docker_directory = self.docker_directory_path
      de_object.ShowHistory(container_id)
      expected_string = """{
    "sha256:8ac48589692a53a9b8c2d1ceaa6b402665aa7fe667ba51ccc03002300856d8c7": {
        "created_at": "2018-04-05T10:41:28.876407", 
        "container_cmd": "/bin/sh -c #(nop)  CMD [\\"sh\\"]", 
        "size": 0
    }
}

"""

      self.assertEqual(expected_string, fake_output.getvalue())