提交 8729ce56 编写于 作者: J John Ferlan

tests: Create a more realistic vHBA

Modify the code to react more like a real HBA -> vHBA creation.

Currently the code would just modify the input XML definition to
set the name to a wwpn and then modify the scsi_host capability
entry for the defintion to change the scsi_host# and unique_id
before adding that into the node device.

This patch does things a bit better. It finds and copies a known
existing vHBA (scsi_host11) in the node_device database and modifies
that definition to change the name to scsi_host12 and set the wwnn/
wwpn to what the input XML would expect before adding the def to the
node device object list.

Then rather than create a returned "dev" using the (poorly) mocked
name - perform the lookup using the new device name.
上级 0869d9b3
...@@ -5626,32 +5626,59 @@ testNodeDeviceListCaps(virNodeDevicePtr dev, char **const names, int maxnames) ...@@ -5626,32 +5626,59 @@ testNodeDeviceListCaps(virNodeDevicePtr dev, char **const names, int maxnames)
} }
static int static virNodeDeviceDefPtr
testNodeDeviceMockCreateVport(virConnectPtr conn, testNodeDeviceMockCreateVport(virConnectPtr conn,
virNodeDeviceDefPtr def, const char *wwnn,
const char *wwpn) const char *wwpn)
{ {
int ret = -1;
testDriverPtr driver = conn->privateData; testDriverPtr driver = conn->privateData;
virNodeDevicePtr devcpy = NULL;
char *xml = NULL;
virNodeDeviceDefPtr def = NULL;
virNodeDevCapsDefPtr caps; virNodeDevCapsDefPtr caps;
virNodeDeviceObjPtr obj = NULL; virNodeDeviceObjPtr obj = NULL;
virObjectEventPtr event = NULL; virObjectEventPtr event = NULL;
/* 'name' is supposed to be filled in by the node device backend, which /* In the real code, we'd call virVHBAManageVport which would take the
* we don't have. Use WWPN instead. */ * wwnn/wwpn from the input XML in order to call the "vport_create"
* function for the parent. That in turn would set off a sequence of
* events resulting in the creation of a vHBA scsi_hostN in the
* node device objects list using the "next" host number with the
* wwnn/wwpn from the input XML. The following will mock this by
* using the scsi_host11 definition, changing the name and the
* scsi_host capability fields before calling virNodeDeviceAssignDef
* to add the def to the node device objects list. */
if (!(devcpy = virNodeDeviceLookupByName(conn, "scsi_host11")) ||
!(xml = virNodeDeviceGetXMLDesc(devcpy, 0)) ||
!(def = virNodeDeviceDefParseString(xml, EXISTING_DEVICE, NULL)))
goto cleanup;
VIR_FREE(def->name); VIR_FREE(def->name);
if (VIR_STRDUP(def->name, wwpn) < 0) if (VIR_STRDUP(def->name, "scsi_host12") < 0)
goto cleanup; goto cleanup;
/* Fill in a random 'host' and 'unique_id' value, /* Find the 'scsi_host' cap and alter the host # and unique_id and
* since this would also come from the backend */ * then for the 'fc_host' capability modify the wwnn/wwpn to be that
* of the input XML. */
caps = def->caps; caps = def->caps;
while (caps) { while (caps) {
if (caps->data.type != VIR_NODE_DEV_CAP_SCSI_HOST) if (caps->data.type != VIR_NODE_DEV_CAP_SCSI_HOST)
continue; continue;
caps->data.scsi_host.host = virRandomBits(10); /* For the "fc_host" cap - change the wwnn/wwpn to match the input */
caps->data.scsi_host.unique_id = 2; if (caps->data.scsi_host.flags & VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST) {
VIR_FREE(caps->data.scsi_host.wwnn);
VIR_FREE(caps->data.scsi_host.wwpn);
if (VIR_STRDUP(caps->data.scsi_host.wwnn, wwnn) < 0 ||
VIR_STRDUP(caps->data.scsi_host.wwpn, wwpn) < 0)
goto cleanup;
} else {
/* For the "scsi_host" cap, increment our host and unique_id to
* give the appearance that something new was created - then add
* that to the node device driver */
caps->data.scsi_host.host++;
caps->data.scsi_host.unique_id++;
}
caps = caps->next; caps = caps->next;
} }
...@@ -5664,10 +5691,16 @@ testNodeDeviceMockCreateVport(virConnectPtr conn, ...@@ -5664,10 +5691,16 @@ testNodeDeviceMockCreateVport(virConnectPtr conn,
0); 0);
testObjectEventQueue(driver, event); testObjectEventQueue(driver, event);
ret = 0;
cleanup: cleanup:
return ret; VIR_FREE(xml);
if (!obj) {
virNodeDeviceDefFree(def);
def = NULL;
}
if (devcpy)
virNodeDeviceFree(devcpy);
return def;
} }
...@@ -5681,6 +5714,7 @@ testNodeDeviceCreateXML(virConnectPtr conn, ...@@ -5681,6 +5714,7 @@ testNodeDeviceCreateXML(virConnectPtr conn,
char *wwnn = NULL, *wwpn = NULL; char *wwnn = NULL, *wwpn = NULL;
int parent_host = -1; int parent_host = -1;
virNodeDevicePtr dev = NULL; virNodeDevicePtr dev = NULL;
virNodeDeviceDefPtr newdef = NULL;
virCheckFlags(0, NULL); virCheckFlags(0, NULL);
...@@ -5702,15 +5736,17 @@ testNodeDeviceCreateXML(virConnectPtr conn, ...@@ -5702,15 +5736,17 @@ testNodeDeviceCreateXML(virConnectPtr conn,
/* In the real code, we'd call virVHBAManageVport followed by /* In the real code, we'd call virVHBAManageVport followed by
* find_new_device, but we cannot do that here since we're not * find_new_device, but we cannot do that here since we're not
* mocking udev. So we just mock a creation by altering the * mocking udev. The mock routine will copy an existing vHBA and
* input XML enough to make it look like a vHBA and add it * rename a few fields to mock that. So in order to allow that to
* to the list of node devices */ * work properly, we need to drop our lock */
if (testNodeDeviceMockCreateVport(conn, def, wwpn) < 0) testDriverUnlock(driver);
goto cleanup; if ((newdef = testNodeDeviceMockCreateVport(conn, wwnn, wwpn))) {
if ((dev = virNodeDeviceLookupByName(conn, newdef->name)))
ignore_value(VIR_STRDUP(dev->parent, def->parent));
}
testDriverLock(driver);
newdef = NULL;
dev = virGetNodeDevice(conn, def->name);
ignore_value(VIR_STRDUP(dev->parent, def->parent));
def = NULL;
cleanup: cleanup:
testDriverUnlock(driver); testDriverUnlock(driver);
virNodeDeviceDefFree(def); virNodeDeviceDefFree(def);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册