storagepoolxml2argvtest.c 6.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
#include <config.h>

#include "internal.h"
#include "testutils.h"
#include "datatypes.h"
#include "storage/storage_util.h"
#include "testutilsqemu.h"
#include "virstring.h"

#define VIR_FROM_THIS VIR_FROM_NONE

12 13 14 15 16 17 18
#ifndef MOUNT
# define MOUNT "/usr/bin/mount"
#endif

#ifndef VGCHANGE
# define VGCHANGE "/usr/sbin/vgchange"
#endif
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49

static int
testCompareXMLToArgvFiles(bool shouldFail,
                          const char *poolxml,
                          const char *cmdline)
{
    VIR_AUTOFREE(char *) actualCmdline = NULL;
    VIR_AUTOFREE(char *) src = NULL;
    int ret = -1;
    virCommandPtr cmd = NULL;
    virStoragePoolDefPtr def = NULL;
    virStoragePoolObjPtr pool = NULL;

    if (!(def = virStoragePoolDefParseFile(poolxml)))
        goto cleanup;

    switch ((virStoragePoolType)def->type) {
    case VIR_STORAGE_POOL_FS:
    case VIR_STORAGE_POOL_NETFS:
        if (!(pool = virStoragePoolObjNew())) {
            VIR_TEST_DEBUG("pool type %d alloc pool obj fails\n", def->type);
            virStoragePoolDefFree(def);
            goto cleanup;
        }
        virStoragePoolObjSetDef(pool, def);

        if (!(src = virStorageBackendFileSystemGetPoolSource(pool))) {
            VIR_TEST_DEBUG("pool type %d has no pool source\n", def->type);
            goto cleanup;
        }

50
        cmd = virStorageBackendFileSystemMountCmd(MOUNT, def, src);
51 52 53
        break;

    case VIR_STORAGE_POOL_LOGICAL:
54
        cmd = virStorageBackendLogicalChangeCmd(VGCHANGE, def, true);
55 56 57
        break;

    case VIR_STORAGE_POOL_DIR:
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
    case VIR_STORAGE_POOL_DISK:
    case VIR_STORAGE_POOL_ISCSI:
    case VIR_STORAGE_POOL_ISCSI_DIRECT:
    case VIR_STORAGE_POOL_SCSI:
    case VIR_STORAGE_POOL_MPATH:
    case VIR_STORAGE_POOL_RBD:
    case VIR_STORAGE_POOL_SHEEPDOG:
    case VIR_STORAGE_POOL_GLUSTER:
    case VIR_STORAGE_POOL_ZFS:
    case VIR_STORAGE_POOL_VSTORAGE:
    case VIR_STORAGE_POOL_LAST:
    default:
        VIR_TEST_DEBUG("pool type %d has no xml2argv test\n", def->type);
        goto cleanup;
    };

74
    if (!(actualCmdline = virCommandToString(cmd, false))) {
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
        VIR_TEST_DEBUG("pool type %d failed to get commandline\n", def->type);
        goto cleanup;
    }

    virTestClearCommandPath(actualCmdline);
    if (virTestCompareToFile(actualCmdline, cmdline) < 0)
        goto cleanup;

    ret = 0;

 cleanup:
    virCommandFree(cmd);
    VIR_FREE(actualCmdline);
    virStoragePoolObjEndAPI(&pool);
    if (shouldFail) {
        virResetLastError();
        ret = 0;
    }
    return ret;
}

struct testInfo {
    bool shouldFail;
    const char *pool;
99 100
    bool linuxOut;
    bool freebsdOut;
101 102 103 104 105 106 107 108 109 110 111 112 113 114
};

static int
testCompareXMLToArgvHelper(const void *data)
{
    int result = -1;
    const struct testInfo *info = data;
    char *poolxml = NULL;
    char *cmdline = NULL;

    if (virAsprintf(&poolxml, "%s/storagepoolxml2xmlin/%s.xml",
                    abs_srcdir, info->pool) < 0)
        goto cleanup;

115 116 117 118 119 120 121 122 123 124 125 126 127
    if (info->linuxOut) {
        if (virAsprintf(&cmdline, "%s/storagepoolxml2argvdata/%s-linux.argv",
                        abs_srcdir, info->pool) < 0 && !info->shouldFail)
            goto cleanup;
    } else if (info->freebsdOut) {
        if (virAsprintf(&cmdline, "%s/storagepoolxml2argvdata/%s-freebsd.argv",
                        abs_srcdir, info->pool) < 0 && !info->shouldFail)
            goto cleanup;
    } else {
        if (virAsprintf(&cmdline, "%s/storagepoolxml2argvdata/%s.argv",
                        abs_srcdir, info->pool) < 0 && !info->shouldFail)
            goto cleanup;
    }
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143

    result = testCompareXMLToArgvFiles(info->shouldFail, poolxml, cmdline);

 cleanup:
    VIR_FREE(poolxml);
    VIR_FREE(cmdline);

    return result;
}


static int
mymain(void)
{
    int ret = 0;

144
#define DO_TEST_FULL(shouldFail, pool, linuxOut, freebsdOut) \
145
    do { \
146
        struct testInfo info = { shouldFail, pool, linuxOut, freebsdOut }; \
147 148 149 150 151 152 153
        if (virTestRun("Storage Pool XML-2-argv " pool, \
                       testCompareXMLToArgvHelper, &info) < 0) \
            ret = -1; \
       } \
    while (0);

#define DO_TEST(pool, ...) \
154
    DO_TEST_FULL(false, pool, false, false)
155 156

#define DO_TEST_FAIL(pool, ...) \
157 158 159 160 161 162 163
    DO_TEST_FULL(true, pool, false, false)

#define DO_TEST_LINUX(pool, ...) \
    DO_TEST_FULL(false, pool, true, false)

#define DO_TEST_FREEBSD(pool, ...) \
    DO_TEST_FULL(false, pool, false, true)
164

165 166 167
    if (storageRegisterAll() < 0)
       return EXIT_FAILURE;

168 169
    DO_TEST_FAIL("pool-dir");
    DO_TEST_FAIL("pool-dir-naming");
170 171 172 173
    DO_TEST("pool-logical");
    DO_TEST("pool-logical-nopath");
    DO_TEST("pool-logical-create");
    DO_TEST("pool-logical-noname");
174 175 176 177
    DO_TEST_FAIL("pool-disk");
    DO_TEST_FAIL("pool-disk-device-nopartsep");
    DO_TEST_FAIL("pool-iscsi");
    DO_TEST_FAIL("pool-iscsi-auth");
178 179 180 181
#ifdef __linux__
    DO_TEST_LINUX("pool-fs");
    DO_TEST_LINUX("pool-netfs");
    DO_TEST_LINUX("pool-netfs-auto");
182
    DO_TEST_LINUX("pool-netfs-protocol-ver");
183
    DO_TEST_LINUX("pool-netfs-ns-mountopts");
184 185 186 187 188 189
    DO_TEST_LINUX("pool-netfs-gluster");
    DO_TEST_LINUX("pool-netfs-cifs");
#elif defined(__FreeBSD__)
    DO_TEST_FREEBSD("pool-fs");
    DO_TEST_FREEBSD("pool-netfs");
    DO_TEST_FREEBSD("pool-netfs-auto");
190
    DO_TEST_FREEBSD("pool-netfs-protocol-ver");
191
    DO_TEST_FREEBSD("pool-netfs-ns-mountopts");
192 193 194 195
    DO_TEST_FREEBSD("pool-netfs-gluster");
    DO_TEST_FREEBSD("pool-netfs-cifs");
#else
    DO_TEST("pool-fs");
196
    DO_TEST("pool-netfs");
197
    DO_TEST("pool-netfs-auto");
198
    DO_TEST("pool-netfs-protocol-ver");
199
    DO_TEST("pool-netfs-ns-mountopts");
200 201
    DO_TEST("pool-netfs-gluster");
    DO_TEST("pool-netfs-cifs");
202
#endif
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
    DO_TEST_FAIL("pool-scsi");
    DO_TEST_FAIL("pool-scsi-type-scsi-host");
    DO_TEST_FAIL("pool-scsi-type-fc-host");
    DO_TEST_FAIL("pool-scsi-type-fc-host-managed");
    DO_TEST_FAIL("pool-mpath");
    DO_TEST_FAIL("pool-iscsi-multiiqn");
    DO_TEST_FAIL("pool-iscsi-vendor-product");
    DO_TEST_FAIL("pool-sheepdog");
    DO_TEST_FAIL("pool-gluster");
    DO_TEST_FAIL("pool-gluster-sub");
    DO_TEST_FAIL("pool-scsi-type-scsi-host-stable");
    DO_TEST_FAIL("pool-zfs");
    DO_TEST_FAIL("pool-zfs-sourcedev");
    DO_TEST_FAIL("pool-rbd");
    DO_TEST_FAIL("pool-vstorage");
    DO_TEST_FAIL("pool-iscsi-direct-auth");
    DO_TEST_FAIL("pool-iscsi-direct");

    return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}

VIR_TEST_MAIN(mymain)