Rather than inline the dummy creation of a vHBA to add to the node devices - create a helper to do that work. Also just tidy up a couple of things while at it... Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx> --- src/test/test_driver.c | 82 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 52 insertions(+), 30 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 4dd2956..5e628b5 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -5622,39 +5622,18 @@ testNodeDeviceListCaps(virNodeDevicePtr dev, char **const names, int maxnames) return ret; } -static virNodeDevicePtr -testNodeDeviceCreateXML(virConnectPtr conn, - const char *xmlDesc, - unsigned int flags) + +static int +testNodeDeviceMockCreateVport(virConnectPtr conn, + virNodeDeviceDefPtr def, + const char *wwpn) { + int ret = -1; testDriverPtr driver = conn->privateData; - virNodeDeviceDefPtr def = NULL; - virNodeDeviceObjPtr obj = NULL; - char *wwnn = NULL, *wwpn = NULL; - int parent_host = -1; - virNodeDevicePtr dev = NULL; virNodeDevCapsDefPtr caps; + virNodeDeviceObjPtr obj = NULL; virObjectEventPtr event = NULL; - virCheckFlags(0, NULL); - - testDriverLock(driver); - - def = virNodeDeviceDefParseString(xmlDesc, CREATE_DEVICE, NULL); - if (def == NULL) - goto cleanup; - - /* We run these next two simply for validation */ - if (virNodeDeviceGetWWNs(def, &wwnn, &wwpn) == -1) - goto cleanup; - - if (virNodeDeviceGetParentHost(&driver->devs, - def->name, - def->parent, - &parent_host) == -1) { - goto cleanup; - } - /* 'name' is supposed to be filled in by the node device backend, which * we don't have. Use WWPN instead. */ VIR_FREE(def->name); @@ -5673,7 +5652,6 @@ testNodeDeviceCreateXML(virConnectPtr conn, caps = caps->next; } - if (!(obj = virNodeDeviceAssignDef(&driver->devs, def))) goto cleanup; virNodeDeviceObjUnlock(obj); @@ -5681,13 +5659,57 @@ testNodeDeviceCreateXML(virConnectPtr conn, event = virNodeDeviceEventLifecycleNew(def->name, VIR_NODE_DEVICE_EVENT_CREATED, 0); + testObjectEventQueue(driver, event); + + ret = 0; + + cleanup: + return ret; +} + + +static virNodeDevicePtr +testNodeDeviceCreateXML(virConnectPtr conn, + const char *xmlDesc, + unsigned int flags) +{ + testDriverPtr driver = conn->privateData; + virNodeDeviceDefPtr def = NULL; + char *wwnn = NULL, *wwpn = NULL; + int parent_host = -1; + virNodeDevicePtr dev = NULL; + + virCheckFlags(0, NULL); + + testDriverLock(driver); + + if (!(def = virNodeDeviceDefParseString(xmlDesc, CREATE_DEVICE, NULL))) + goto cleanup; + + /* We run these next two simply for validation - they are essentially + * 'validating' that the input XML either has a wwnn/wwpn or the + * virNodeDevCapSCSIHostParseXML generated a wwnn/wwpn and that the + * input XML has a parent host defined. */ + if (virNodeDeviceGetWWNs(def, &wwnn, &wwpn) < 0) + goto cleanup; + + if (virNodeDeviceGetParentHost(&driver->devs, def->name, + def->parent, &parent_host) < 0) + goto cleanup; + + /* In the real code, we'd call virVHBAManageVport followed by + * find_new_device, but we cannot do that here since we're not + * mocking udev. So we just mock a creation by altering the + * input XML enough to make it look like a vHBA and add it + * to the list of node devices */ + if (testNodeDeviceMockCreateVport(conn, def, wwpn) < 0) + goto cleanup; dev = virGetNodeDevice(conn, def->name); def = NULL; cleanup: testDriverUnlock(driver); virNodeDeviceDefFree(def); - testObjectEventQueue(driver, event); VIR_FREE(wwnn); VIR_FREE(wwpn); return dev; -- 2.7.4 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list