def test_get_container_data_volumes(self): options = [parse_volume_spec(v) for v in [ '/host/volume:/host/volume:ro', '/new/volume', '/existing/volume', ]] self.mock_client.inspect_image.return_value = { 'ContainerConfig': { 'Volumes': { '/mnt/image/data': {}, } } } container = Container(self.mock_client, { 'Image': 'ababab', 'Volumes': { '/host/volume': '/host/volume', '/existing/volume': '/var/lib/docker/aaaaaaaa', '/removed/volume': '/var/lib/docker/bbbbbbbb', '/mnt/image/data': '/var/lib/docker/cccccccc', }, }, has_been_inspected=True) expected = [ parse_volume_spec('/var/lib/docker/aaaaaaaa:/existing/volume:rw'), parse_volume_spec('/var/lib/docker/cccccccc:/mnt/image/data:rw'), ] volumes = get_container_data_volumes(container, options) self.assertEqual(sorted(volumes), sorted(expected))
def test_parse_volume_windows_absolute_path(self): windows_absolute_path = "c:\\Users\\me\\Documents\\shiny\\config:\\opt\\shiny\\config:ro" spec = parse_volume_spec(windows_absolute_path) self.assertEqual( spec, ("/c/Users/me/Documents/shiny/config", "/opt/shiny/config", "ro"))
def test_parse_volume_windows_absolute_path(self): windows_absolute_path = "c:\\Users\\me\\Documents\\shiny\\config:\\opt\\shiny\\config:ro" spec = parse_volume_spec(windows_absolute_path) self.assertEqual( spec, ( "/c/Users/me/Documents/shiny/config", "/opt/shiny/config", "ro" ) )
def test_parse_volume_spec_only_one_path(self): spec = parse_volume_spec('/the/volume') self.assertEqual(spec, (None, '/the/volume', 'rw'))
def test_build_volume_binding(self): binding = build_volume_binding(parse_volume_spec('/outside:/inside')) self.assertEqual( binding, ('/outside', dict(bind='/inside', ro=False)))
def test_parse_volume_bad_mode(self): with self.assertRaises(ConfigError): parse_volume_spec('one:two:notrw')
def test_building_volume_binding_with_home(self): os.environ['HOME'] = '/home/user' binding = build_volume_binding(parse_volume_spec('~:/home/user')) self.assertEqual( binding, ('/home/user', dict(bind='/home/user', ro=False)))
def test_parse_volume_spec_too_many_parts(self): with self.assertRaises(ConfigError): parse_volume_spec('one:two:three:four')
def test_build_volume_binding(self): binding = build_volume_binding(parse_volume_spec("/outside:/inside")) self.assertEqual(binding, ("/inside", "/outside:/inside:rw"))
def test_parse_volume_spec_with_mode(self): spec = parse_volume_spec("external:interval:ro") self.assertEqual(spec, ("external", "interval", "ro")) spec = parse_volume_spec("external:interval:z") self.assertEqual(spec, ("external", "interval", "z"))
def test_parse_volume_spec_internal_and_external(self): spec = parse_volume_spec("external:interval") self.assertEqual(spec, ("external", "interval", "rw"))
def test_parse_volume_spec_only_one_path(self): spec = parse_volume_spec("/the/volume") self.assertEqual(spec, (None, "/the/volume", "rw"))
def test_build_volume_binding_with_environ(self): os.environ['VOLUME_PATH'] = '/opt' binding = build_volume_binding(parse_volume_spec('${VOLUME_PATH}:/opt')) self.assertEqual(binding, ('/opt', dict(bind='/opt', ro=False)))
def test_parse_volume_spec_internal_and_external(self): spec = parse_volume_spec('external:interval') self.assertEqual(spec, ('external', 'interval', 'rw'))
def test_parse_volume_spec_with_mode(self): spec = parse_volume_spec('external:interval:ro') self.assertEqual(spec, ('external', 'interval', 'ro')) spec = parse_volume_spec('external:interval:z') self.assertEqual(spec, ('external', 'interval', 'z'))
def test_build_volume_binding(self): binding = build_volume_binding(parse_volume_spec('/outside:/inside')) self.assertEqual(binding, ('/inside', '/outside:/inside:rw'))