'A Flocker cluster, built using the CloudFormation template, has a
client node. That node has ``docker-compose`` and templates. The first
template creates a PostgreSQL server on one node. The second template
moves the PostgreSQL server to the second node.'

def test_docker_compose_up_postgres(self):

    client_username = 'ubuntu'
    client_home = FilePath('/home').child(client_username)
    remote_compose_directory = client_home.child(random_name(self))
    self.compose_node1 = remote_compose_directory.child('docker-compose-node1.yml')
    self.compose_node2 = remote_compose_directory.child('docker-compose-node2.yml')
    def upload_docker_compose_files():
        return upload(reactor=reactor, username=client_username, host=self.client_node_ip.encode('ascii'), local_path=FilePath(__file__).parent().descendant(['installer', 'postgres']), remote_path=remote_compose_directory)
    d = retry_failure(reactor=reactor, function=upload_docker_compose_files, expected=(SCPConnectionError,), steps=repeat(1, 60))
    def cleanup_container(ignored):
        self.addCleanup(remote_docker_compose, self.client_node_ip, self.docker_host, self.compose_node1.path, 'down')
    d.addCallback(cleanup_container)
    def pull_postgres():
        return remote_docker_compose(self.client_node_ip, self.docker_host, self.compose_node1.path, 'pull')
    d.addCallback((lambda ignored: retry_failure(reactor=reactor, function=pull_postgres, expected=(ProcessTerminated,), steps=repeat(1, 5))))
    d.addCallback((lambda ignored: remote_docker_compose(self.client_node_ip, self.docker_host, self.compose_node1.path, 'up', '-d')))
    d.addCallback((lambda ignored: self._wait_for_postgres(self.agent_node1_ip)))
    d.addCallback((lambda ignored: remote_postgres(self.client_node_ip, self.agent_node1_ip, (RECREATE_STATEMENT + INSERT_STATEMENT))))
    d.addCallback((lambda ignored: remote_docker_compose(self.client_node_ip, self.docker_host, self.compose_node1.path, 'down')))
    d.addCallback((lambda ignored: remote_docker_compose(self.client_node_ip, self.docker_host, self.compose_node2.path, 'up', '-d')))
    d.addCallback((lambda ignored: self._wait_for_postgres(self.agent_node2_ip)))
    d.addCallback((lambda ignored: remote_postgres(self.client_node_ip, self.agent_node2_ip, SELECT_STATEMENT)))
    d.addCallback((lambda (process_status, process_output): self.assertEqual('1', process_output[2].strip())))
    return d
