'The Docker image is pulled if it is unavailable locally.'

@flaky(u'FLOC-3875')
def test_pull_image_if_necessary(self):

    client = dockerpy_client()
    path = FilePath(self.mktemp())
    path.makedirs()
    path.child('Dockerfile.in').setContent('FROM    busybox\nCMD    /bin/true\n')
    builder = DockerImageBuilder(test=self, source_dir=path, cleanup=False)
    building = builder.build()
    registry_listening = self.run_registry()
    def create_container((image_name, registry)):
        registry_image = self.push_to_registry(image_name, registry)
        self.addCleanup(client.remove_image, image=registry_image.full_name)
        name = random_name(self)
        docker_client = self.make_client()
        self.addCleanup(docker_client.remove, name)
        d = docker_client.add(name, registry_image.full_name)
        d.addCallback((lambda _: self.assertTrue(client.inspect_image(registry_image.full_name))))
        return d
    d = gatherResults((building, registry_listening))
    d.addCallback(create_container)
    return d
