Rather than have multiple places using the same pattern to find
a network by name using virNetworkObjFindByName, create a common
helper which will provide a consistent error message as well.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/test/test_driver.c | 57 +++++++++++++++++++++-----------------------------
1 file changed, 24 insertions(+), 33 deletions(-)
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index c2536c9..e4402cc 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -3236,6 +3236,22 @@ static virNetworkPtr testNetworkLookupByUUID(virConnectPtr conn,
return ret;
}
+
+static virNetworkObjPtr
+testNetworkObjFindByName(testDriverPtr privconn,
+ const char *name)
+{
+ virNetworkObjPtr net;
+
+ if (!(net = virNetworkObjFindByName(privconn->networks, name)))
+ virReportError(VIR_ERR_NO_NETWORK,
+ _("no network with matching name '%s'"),
+ name);
+
+ return net;
+}
+
+
static virNetworkPtr testNetworkLookupByName(virConnectPtr conn,
const char *name)
{
@@ -3243,11 +3259,8 @@ static virNetworkPtr testNetworkLookupByName(virConnectPtr conn,
virNetworkObjPtr net;
virNetworkPtr ret = NULL;
- net = virNetworkObjFindByName(privconn->networks, name);
- if (net == NULL) {
- virReportError(VIR_ERR_NO_NETWORK, NULL);
+ if (!(net = testNetworkObjFindByName(privconn, name)))
goto cleanup;
- }
ret = virGetNetwork(conn, net->def->name, net->def->uuid);
@@ -3411,12 +3424,8 @@ static int testNetworkUndefine(virNetworkPtr network)
int ret = -1;
virObjectEventPtr event = NULL;
- privnet = virNetworkObjFindByName(privconn->networks, network->name);
-
- if (privnet == NULL) {
- virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
+ if (!(privnet = testNetworkObjFindByName(privconn, network->name)))
goto cleanup;
- }
if (virNetworkObjIsActive(privnet)) {
virReportError(VIR_ERR_OPERATION_INVALID,
@@ -3490,11 +3499,8 @@ static int testNetworkCreate(virNetworkPtr network)
int ret = -1;
virObjectEventPtr event = NULL;
- privnet = virNetworkObjFindByName(privconn->networks, network->name);
- if (privnet == NULL) {
- virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
+ if (!(privnet = testNetworkObjFindByName(privconn, network->name)))
goto cleanup;
- }
if (virNetworkObjIsActive(privnet)) {
virReportError(VIR_ERR_OPERATION_INVALID,
@@ -3521,11 +3527,8 @@ static int testNetworkDestroy(virNetworkPtr network)
int ret = -1;
virObjectEventPtr event = NULL;
- privnet = virNetworkObjFindByName(privconn->networks, network->name);
- if (privnet == NULL) {
- virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
+ if (!(privnet = testNetworkObjFindByName(privconn, network->name)))
goto cleanup;
- }
privnet->active = 0;
event = virNetworkEventLifecycleNew(privnet->def->name,
privnet->def->uuid,
@@ -3551,11 +3554,8 @@ static char *testNetworkGetXMLDesc(virNetworkPtr network,
virCheckFlags(0, NULL);
- privnet = virNetworkObjFindByName(privconn->networks, network->name);
- if (privnet == NULL) {
- virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
+ if (!(privnet = testNetworkObjFindByName(privconn, network->name)))
goto cleanup;
- }
ret = virNetworkDefFormat(privnet->def, flags);
@@ -3569,11 +3569,8 @@ static char *testNetworkGetBridgeName(virNetworkPtr network) {
char *bridge = NULL;
virNetworkObjPtr privnet;
- privnet = virNetworkObjFindByName(privconn->networks, network->name);
- if (privnet == NULL) {
- virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
+ if (!(privnet = testNetworkObjFindByName(privconn, network->name)))
goto cleanup;
- }
if (!(privnet->def->bridge)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -3596,11 +3593,8 @@ static int testNetworkGetAutostart(virNetworkPtr network,
virNetworkObjPtr privnet;
int ret = -1;
- privnet = virNetworkObjFindByName(privconn->networks, network->name);
- if (privnet == NULL) {
- virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
+ if (!(privnet = testNetworkObjFindByName(privconn, network->name)))
goto cleanup;
- }
*autostart = privnet->autostart;
ret = 0;
@@ -3617,11 +3611,8 @@ static int testNetworkSetAutostart(virNetworkPtr network,
virNetworkObjPtr privnet;
int ret = -1;
- privnet = virNetworkObjFindByName(privconn->networks, network->name);
- if (privnet == NULL) {
- virReportError(VIR_ERR_INVALID_ARG, __FUNCTION__);
+ if (!(privnet = testNetworkObjFindByName(privconn, network->name)))
goto cleanup;
- }
privnet->autostart = autostart ? 1 : 0;
ret = 0;
--
2.9.3