Exemplo n.º 1
0
static int
testCompareXMLToXMLFiles(const char *inxml, const char *outxml,
                         unsigned int flags,
                         testCompareNetXML2XMLResult expectResult)
{
    char *actual = NULL;
    int ret;
    testCompareNetXML2XMLResult result = TEST_COMPARE_NET_XML2XML_RESULT_SUCCESS;
    virNetworkDefPtr dev = NULL;

    if (!(dev = virNetworkDefParseFile(inxml))) {
        result = TEST_COMPARE_NET_XML2XML_RESULT_FAIL_PARSE;
        goto cleanup;
    }
    if (expectResult == TEST_COMPARE_NET_XML2XML_RESULT_FAIL_PARSE)
        goto cleanup;

    if (!(actual = virNetworkDefFormat(dev, flags))) {
        result = TEST_COMPARE_NET_XML2XML_RESULT_FAIL_FORMAT;
        goto cleanup;
    }
    if (expectResult == TEST_COMPARE_NET_XML2XML_RESULT_FAIL_FORMAT)
        goto cleanup;

    if (virTestCompareToFile(actual, outxml) < 0) {
        result = TEST_COMPARE_NET_XML2XML_RESULT_FAIL_COMPARE;
        goto cleanup;
    }
    if (expectResult == TEST_COMPARE_NET_XML2XML_RESULT_FAIL_COMPARE)
        goto cleanup;

 cleanup:
    if (result == expectResult) {
        ret = 0;
        if (expectResult != TEST_COMPARE_NET_XML2XML_RESULT_SUCCESS) {
            VIR_TEST_DEBUG("Got expected failure code=%d msg=%s",
                           result, virGetLastErrorMessage());
        }
    } else {
        ret = -1;
        VIR_TEST_DEBUG("Expected result code=%d but received code=%d",
                       expectResult, result);
    }
    virResetLastError();

    VIR_FREE(actual);
    virNetworkDefFree(dev);
    return ret;
}
Exemplo n.º 2
0
static int
testCompareXMLToXMLFiles(const char *netxml, const char *updatexml,
                         const char *outxml, unsigned int flags,
                         unsigned int command, unsigned int section,
                         int parentIndex, bool expectFailure)
{
    char *updateXmlData = NULL;
    char *actual = NULL;
    int ret = -1;
    virNetworkDefPtr def = NULL;

    if (virTestLoadFile(updatexml, &updateXmlData) < 0)
        goto error;

    if (!(def = virNetworkDefParseFile(netxml)))
        goto fail;

    if (virNetworkDefUpdateSection(def, command, section, parentIndex,
                                   updateXmlData, 0) < 0)
        goto fail;

    if (!(actual = virNetworkDefFormat(def, flags)))
        goto fail;

    if (!expectFailure) {
        if (virTestCompareToFile(actual, outxml) < 0)
            goto error;
    }

    ret = 0;

 fail:
    if (expectFailure) {
        if (ret == 0) {
            virReportError(VIR_ERR_INTERNAL_ERROR, "%s", "Failed to fail.");
            ret = -1;
        } else {
            virResetLastError();
            ret = 0;
        }
    }
 error:
    VIR_FREE(updateXmlData);
    VIR_FREE(actual);
    virNetworkDefFree(def);
    return ret;
}
Exemplo n.º 3
0
static int
testCompareXMLToConfFiles(const char *inxml, const char *outconf, dnsmasqCapsPtr caps)
{
    char *actual = NULL;
    int ret = -1;
    virNetworkDefPtr dev = NULL;
    virNetworkObjPtr obj = NULL;
    virCommandPtr cmd = NULL;
    char *pidfile = NULL;
    dnsmasqContext *dctx = NULL;

    if (!(dev = virNetworkDefParseFile(inxml)))
        goto fail;

    if (!(obj = virNetworkObjNew()))
        goto fail;

    obj->def = dev;
    dctx = dnsmasqContextNew(dev->name, "/var/lib/libvirt/dnsmasq");

    if (dctx == NULL)
        goto fail;

    if (networkDnsmasqConfContents(obj, pidfile, &actual,
                        dctx, caps) < 0)
        goto fail;

    if (virTestCompareToFile(actual, outconf) < 0)
        goto fail;

    ret = 0;

 fail:
    VIR_FREE(actual);
    VIR_FREE(pidfile);
    virCommandFree(cmd);
    virObjectUnref(obj);
    dnsmasqContextFree(dctx);
    return ret;
}
Exemplo n.º 4
0
static int
testCompareXMLToXMLFiles(const char *inxml, const char *outxml,
                         unsigned int flags)
{
    char *actual = NULL;
    int ret = -1;
    virNetworkDefPtr dev = NULL;

    if (!(dev = virNetworkDefParseFile(inxml)))
        goto fail;

    if (!(actual = virNetworkDefFormat(dev, flags)))
        goto fail;

    if (virtTestCompareToFile(actual, outxml) < 0)
        goto fail;

    ret = 0;

 fail:
    VIR_FREE(actual);
    virNetworkDefFree(dev);
    return ret;
}
Exemplo n.º 5
0
static int testCompareXMLToArgvFiles(const char *xml,
                                     const char *cmdline)
{
    char *expectargv = NULL;
    char *actualargv = NULL;
    virBuffer buf = VIR_BUFFER_INITIALIZER;
    virNetworkDefPtr def = NULL;
    int ret = -1;

    virCommandSetDryRun(&buf, NULL, NULL);

    if (!(def = virNetworkDefParseFile(xml)))
        goto cleanup;

    if (networkAddFirewallRules(def) < 0)
        goto cleanup;

    if (virBufferError(&buf))
        goto cleanup;

    actualargv = virBufferContentAndReset(&buf);
    virTestClearCommandPath(actualargv);
    virCommandSetDryRun(NULL, NULL, NULL);

    if (virTestCompareToFile(actualargv, cmdline) < 0)
        goto cleanup;

    ret = 0;

 cleanup:
    virBufferFreeAndReset(&buf);
    VIR_FREE(expectargv);
    VIR_FREE(actualargv);
    virNetworkDefFree(def);
    return ret;
}