'The instance ID is retrieved from the metadata service if it can\'t be
found on the config drive.'

def test_metadata_service(self):

    patch = MonkeyPatcher()
    server_compute_instance_id = unicode(uuid4())
    configdrive_label = filesystem_label_for_test(self)
    patch.addPatch(self.api, '_config_drive_label', configdrive_label)
    listening = webserver_for_test(self, url_path=('/' + '/'.join(METADATA_RELATIVE_PATH)), response_content=json.dumps({'uuid': server_compute_instance_id}))
    def set_metadata_service_endpoint(port):
        address = port.getHost()
        endpoint = (address.host, address.port)
        patch.addPatch(self.api, '_metadata_service_endpoint', endpoint)
        return port
    listening.addCallback(set_metadata_service_endpoint)
    def start_compute_instance_id(port):
        patch.patch()
        return deferToThread(self.api.compute_instance_id)
    connecting = listening.addCallback(start_compute_instance_id)
    def check(result):
        self.assertEqual(server_compute_instance_id, result)
    checking = connecting.addCallback(check)
    return checking
