'If a container with a volume is created with a restart policy of
"always", the container will restart with the same volume attached
after the Docker daemon is restarted.'

@require_cluster(1)
def test_volume_persists_restart(self, cluster):

    data = random_name(self).encode('utf-8')
    node = cluster.nodes[0]
    Message.new(message_type=u'acceptance:test_volume_persists_restart', node=node.public_address).write()
    client = get_docker_client(cluster, node.public_address)
    http_port = 8080
    volume_name = random_name(self)
    container_identifier = self.run_python_container(cluster, node.public_address, {'host_config': client.create_host_config(binds=['{}:/data'.format(volume_name)], port_bindings={http_port: 0}, restart_policy={'Name': 'always'}), 'ports': [http_port]}, SCRIPTS.child('datahttp.py'), [u'/data'], client=client)
    host_port = extract_external_port(client, container_identifier, http_port)
    d = post_http_server(self, node.public_address, host_port, {'data': data})
    d.addCallback((lambda _: assert_http_server(self, node.public_address, host_port, expected_response=data)))
    d.addCallback((lambda _: self.docker_service(node.public_address, 'stop')))
    def poll_http_server_stopped(_):
        def http_closed():
            ds = check_http_server(node.public_address, host_port)
            ds.addCallback((lambda succeeded: (not succeeded)))
            return ds
        looping = loop_until(reactor, http_closed)
        return looping
    d.addCallback(poll_http_server_stopped)
    d.addCallback((lambda _: self.docker_service(node.public_address, 'start')))
    d.addCallback((lambda _: extract_external_port(client, container_identifier, http_port)))
    def poll_http_server(host_port):
        ds = verify_socket(node.public_address, host_port)
        ds.addCallback((lambda _: assert_http_server(self, node.public_address, host_port, expected_response=data)))
        return ds
    d.addCallback(poll_http_server)
    return d
