Re: [PATCHv5 3/5] domifaddr: Implement the API for qemu

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Updated tests + corrections in qemu_agent.c (Diff attached):

diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c
index 009ed77..3c0c541 100644
--- a/src/qemu/qemu_agent.c
+++ b/src/qemu/qemu_agent.c
@@ -1344,6 +1344,7 @@ qemuAgentGetInterfaces(qemuAgentPtr mon,
     size_t addrs_count = 0;
     virDomainInterfacePtr *ifaces_ret = NULL;
     virHashTablePtr ifaces_store = NULL;
+    char **ifname = NULL;

     /* Initially the bag of ifaces is empty */
     if (!(ifaces_store = virHashCreate(ifaces_count, NULL)))
@@ -1373,7 +1374,6 @@ qemuAgentGetInterfaces(qemuAgentPtr mon,
         virJSONValuePtr tmp_iface = virJSONValueArrayGet(ret_array, i);
         virJSONValuePtr ip_addr_arr = NULL;
         const char *hwaddr, *ifname_s, *name = NULL;
-        char **ifname = NULL;
         int ip_addr_arr_size;
         virDomainInterfacePtr iface = NULL;

@@ -1416,9 +1416,15 @@ qemuAgentGetInterfaces(qemuAgentPtr mon,
             if (VIR_STRDUP(iface->name, ifname_s) < 0)
                 goto error;

-            /* hwaddr might be omitted */
             hwaddr = virJSONValueObjectGetString(tmp_iface,
"hardware-address");
-            if (hwaddr && VIR_STRDUP(iface->hwaddr, hwaddr) < 0)
+            if (!hwaddr) {
+                virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                               _("qemu agent didn't provide"
+                                 "'hardware-address' field"));
+                goto error;
+            }
+
+            if (VIR_STRDUP(iface->hwaddr, hwaddr) < 0)
                 goto error;
         }

@@ -1433,7 +1439,7 @@ qemuAgentGetInterfaces(qemuAgentPtr mon,

         if ((ip_addr_arr_size = virJSONValueArraySize(ip_addr_arr)) < 0)
             /* Mmm, empty 'ip-address'? */
-            continue;
+            goto error;

         /* If current iface already exists, continue with the count */
         addrs_count = iface->naddrs;
@@ -1508,6 +1514,7 @@ error:
             virDomainInterfaceFree(ifaces_ret[i]);
     }
     VIR_FREE(ifaces_ret);
+    virStringFreeList(ifname);

     goto cleanup;
 }
diff --git a/tests/qemuagenttest.c b/tests/qemuagenttest.c
index 4014a09..ddca48c 100644
--- a/tests/qemuagenttest.c
+++ b/tests/qemuagenttest.c
@@ -579,32 +579,35 @@ cleanup:
 static const char testQemuAgentGetInterfacesResponse[] =
     "{\"return\": "
     "    ["
-    "       {\"name\":\"lo\","
+    "       {\"name\":\"eth2\","
+    "        \"hardware-address\":\"52:54:00:36:2a:e5\""
+    "       },"
+    "       {\"name\":\"eth1:0\","
     "        \"ip-addresses\":"
     "          ["
     "             {\"ip-address-type\":\"ipv4\","
-    "              \"ip-address\":\"127.0.0.1\","
-    "              \"prefix\":8"
+    "              \"ip-address\":\"192.168.10.91\","
+    "              \"prefix\":24"
     "             },"
     "             {\"ip-address-type\":\"ipv6\","
-    "              \"ip-address\":\"::1\","
-    "              \"prefix\":128"
+    "              \"ip-address\":\"fe80::fc54:ff:fefe:4c4f\","
+    "              \"prefix\":64"
     "             }"
     "          ],"
-    "        \"hardware-address\":\"00:00:00:00:00:00\""
+    "        \"hardware-address\":\"52:54:00:d3:39:ee\""
     "       },"
     "       {\"name\":\"eth0\","
     "        \"ip-addresses\":"
     "          ["
-    "             {\"ip-address-type\":\"ipv4\","
-    "              \"ip-address\":\"192.168.102.142\","
-    "              \"prefix\":24"
-    "             },"
     "             {\"ip-address-type\":\"ipv6\","
     "              \"ip-address\":\"fe80::5054:ff:fe89:ad35\","
     "              \"prefix\":64"
     "             },"
     "             {\"ip-address-type\":\"ipv4\","
+    "              \"ip-address\":\"192.168.102.142\","
+    "              \"prefix\":24"
+    "             },"
+    "             {\"ip-address-type\":\"ipv4\","
     "              \"ip-address\":\"192.168.234.152\","
     "              \"prefix\":16"
     "             },"
@@ -620,7 +623,7 @@ static const char testQemuAgentGetInterfacesResponse[] =
     "          ["
     "             {\"ip-address-type\":\"ipv4\","
     "              \"ip-address\":\"192.168.103.83\","
-    "              \"prefix\":24"
+    "              \"prefix\":32"
     "             },"
     "             {\"ip-address-type\":\"ipv6\","
     "              \"ip-address\":\"fe80::5054:ff:fed3:39ee\","
@@ -629,22 +632,19 @@ static const char testQemuAgentGetInterfacesResponse[] =
     "          ],"
     "        \"hardware-address\":\"52:54:00:d3:39:ee\""
     "       },"
-    "       {\"name\":\"eth1:0\","
+    "       {\"name\":\"lo\","
     "        \"ip-addresses\":"
     "          ["
     "             {\"ip-address-type\":\"ipv4\","
-    "              \"ip-address\":\"192.168.10.91\","
-    "              \"prefix\":24"
+    "              \"ip-address\":\"127.0.0.1\","
+    "              \"prefix\":8"
     "             },"
     "             {\"ip-address-type\":\"ipv6\","
-    "              \"ip-address\":\"fe80::fc54:ff:fefe:4c4f\","
-    "              \"prefix\":64"
+    "              \"ip-address\":\"::1\","
+    "              \"prefix\":128"
     "             }"
     "          ],"
-    "        \"hardware-address\":\"52:54:00:d3:39:ee\""
-    "       },"
-    "       {\"name\":\"eth2\","
-    "        \"hardware-address\":\"52:54:00:36:2a:e5\""
+    "        \"hardware-address\":\"00:00:00:00:00:00\""
     "       }"
     "    ]"
     "}";
@@ -679,36 +679,75 @@ testQemuAgentGetInterfaces(const void *data)
         goto cleanup;
     }

-    if (ifaces[0]->naddrs != 2 ||
+    if (STRNEQ(ifaces[0]->name, "eth2") ||
+        STRNEQ(ifaces[1]->name, "eth1") ||
+        STRNEQ(ifaces[2]->name, "eth0") ||
+        STRNEQ(ifaces[3]->name, "lo")) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       "unexpected return values for interface names");
+        goto cleanup;
+    }
+
+    if (STRNEQ(ifaces[0]->hwaddr, "52:54:00:36:2a:e5") ||
+        STRNEQ(ifaces[1]->hwaddr, "52:54:00:d3:39:ee") ||
+        STRNEQ(ifaces[2]->hwaddr, "52:54:00:89:ad:35") ||
+        STRNEQ(ifaces[3]->hwaddr, "00:00:00:00:00:00")) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       "unexpected return values for MAC addresses");
+        goto cleanup;
+    }
+
+    if (ifaces[0]->naddrs != 0 ||
         ifaces[1]->naddrs != 4 ||
         ifaces[2]->naddrs != 4 ||
-        ifaces[3]->naddrs != 0) {
+        ifaces[3]->naddrs != 2) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       "unexpected return value for number of IP addresses");
+                       "unexpected return values for number of IP addresses");
         goto cleanup;
     }

-    if (STRNEQ(ifaces[0]->name, "lo") ||
-        STRNEQ(ifaces[0]->addrs[0].addr, "127.0.0.1") ||
-        ifaces[0]->addrs[1].prefix != 128) {
+    if (ifaces[1]->addrs[0].type != VIR_IP_ADDR_TYPE_IPV4 ||
+        ifaces[1]->addrs[1].type != VIR_IP_ADDR_TYPE_IPV6 ||
+        ifaces[1]->addrs[2].type != VIR_IP_ADDR_TYPE_IPV4 ||
+        ifaces[1]->addrs[3].type != VIR_IP_ADDR_TYPE_IPV6 ||
+        ifaces[2]->addrs[0].type != VIR_IP_ADDR_TYPE_IPV6 ||
+        ifaces[2]->addrs[1].type != VIR_IP_ADDR_TYPE_IPV4 ||
+        ifaces[2]->addrs[2].type != VIR_IP_ADDR_TYPE_IPV4 ||
+        ifaces[2]->addrs[3].type != VIR_IP_ADDR_TYPE_IPV6 ||
+        ifaces[3]->addrs[0].type != VIR_IP_ADDR_TYPE_IPV4 ||
+        ifaces[3]->addrs[1].type != VIR_IP_ADDR_TYPE_IPV6) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       "unexpected return values for interface: lo");
+                       "unexpected return values for IP address types");
         goto cleanup;
     }

-    if (STRNEQ(ifaces[1]->hwaddr, "52:54:00:89:ad:35") ||
-        ifaces[1]->addrs[0].prefix != 24 ||
-        ifaces[1]->addrs[1].type != VIR_IP_ADDR_TYPE_IPV6) {
+    if (ifaces[1]->addrs[0].prefix != 24 ||
+        ifaces[1]->addrs[1].prefix != 64 ||
+        ifaces[1]->addrs[2].prefix != 32 ||
+        ifaces[1]->addrs[3].prefix != 64 ||
+        ifaces[2]->addrs[0].prefix != 64 ||
+        ifaces[2]->addrs[1].prefix != 24 ||
+        ifaces[2]->addrs[2].prefix != 16 ||
+        ifaces[2]->addrs[3].prefix != 64 ||
+        ifaces[3]->addrs[0].prefix != 8 ||
+        ifaces[3]->addrs[1].prefix != 128) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       "unexpected return values for interface: eth0");
+                       "unexpected return values for IP address prefix");
         goto cleanup;
     }

-    if (STRNEQ(ifaces[2]->name, "eth1") ||
-        ifaces[2]->addrs[0].type != VIR_IP_ADDR_TYPE_IPV4 ||
-        STRNEQ(ifaces[2]->addrs[1].addr, "fe80::5054:ff:fed3:39ee")) {
+    if (STRNEQ(ifaces[1]->addrs[0].addr, "192.168.10.91") ||
+        STRNEQ(ifaces[1]->addrs[1].addr, "fe80::fc54:ff:fefe:4c4f") ||
+        STRNEQ(ifaces[1]->addrs[2].addr, "192.168.103.83") ||
+        STRNEQ(ifaces[1]->addrs[3].addr, "fe80::5054:ff:fed3:39ee") ||
+        STRNEQ(ifaces[2]->addrs[0].addr, "fe80::5054:ff:fe89:ad35") ||
+        STRNEQ(ifaces[2]->addrs[1].addr, "192.168.102.142") ||
+        STRNEQ(ifaces[2]->addrs[2].addr, "192.168.234.152") ||
+        STRNEQ(ifaces[2]->addrs[3].addr, "fe80::5054:ff:fec3:68bb") ||
+        STRNEQ(ifaces[3]->addrs[0].addr, "127.0.0.1") ||
+        STRNEQ(ifaces[3]->addrs[1].addr, "::1")) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       "unexpected return values for interface: eth1");
+                       "unexpected return values for IP address values");
         goto cleanup;
     }


-- 
Nehal J Wani

Attachment: 3.diff
Description: Binary data

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]