[libvirt] [PATCH 1/2] test_driver: use addr_offset for non-network infs too

Ilias Stamatis posted 2 patches 5 years, 5 months ago
[libvirt] [PATCH 1/2] test_driver: use addr_offset for non-network infs too
Posted by Ilias Stamatis 5 years, 5 months ago
The addr_offset can be used even for the hard-coded addresses in an
attempt to always return unique ips.

Signed-off-by: Ilias Stamatis <stamatis.iliass@gmail.com>
---
 src/test/test_driver.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 4b1f2724a0..d3bc6e7bce 100755
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -3508,6 +3508,8 @@ testDomainInterfaceAddresses(virDomainPtr dom,
         goto cleanup;

     for (i = 0; i < vm->def->nnets; i++) {
+        /* try using different addresses per different inf and domain */
+        const size_t addr_offset = 20 * (vm->def->id - 1) + i + 1;
         const virDomainNetDef *net = vm->def->nets[i];

         if (VIR_ALLOC(iface) < 0)
@@ -3525,18 +3527,14 @@ testDomainInterfaceAddresses(virDomainPtr dom,
         iface->naddrs = 1;

         if (net->type == VIR_DOMAIN_NET_TYPE_NETWORK) {
-            /* try using different addresses per different inf and domain */
-            const size_t addr_offset = 20 * (vm->def->id - 1) + i + 1;
-
             if (testDomainInterfaceAddressFromNet(dom->conn->privateData,
                                                   net, addr_offset, iface) < 0)
                 goto cleanup;
         } else {
             iface->addrs[0].type = VIR_IP_ADDR_TYPE_IPV4;
             iface->addrs[0].prefix = 24;
-            if (virAsprintf(&iface->addrs[0].addr, "192.168.0.%zu", 1 + i) < 0)
+            if (virAsprintf(&iface->addrs[0].addr, "192.168.0.%zu", addr_offset) < 0)
                 goto cleanup;
-
         }

         VIR_APPEND_ELEMENT_INPLACE(ifaces_ret, ifaces_count, iface);
--
2.22.0

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