[libvirt] [PATCH v2 4/4] test_driver: implement testDomainGetInterfaceParameters

Ilias Stamatis posted 4 patches 5 years, 4 months ago
[libvirt] [PATCH v2 4/4] test_driver: implement testDomainGetInterfaceParameters
Posted by Ilias Stamatis 5 years, 4 months ago
Signed-off-by: Ilias Stamatis <stamatis.iliass@gmail.com>
---
 src/test/test_driver.c | 58 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 58 insertions(+)

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 15894d98ad..d2a7d2f840 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -2935,6 +2935,63 @@ testDomainGetNumaParameters(virDomainPtr dom,
 }


+static int
+testDomainGetInterfaceParameters(virDomainPtr dom,
+                                 const char *device,
+                                 virTypedParameterPtr params,
+                                 int *nparams,
+                                 unsigned int flags)
+{
+    virNetDevBandwidthRate in = {0};
+    virNetDevBandwidthRate out = {0};
+    virDomainObjPtr vm = NULL;
+    virDomainDefPtr def = NULL;
+    virDomainNetDefPtr net = NULL;
+    int ret = -1;
+
+    virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
+                  VIR_DOMAIN_AFFECT_CONFIG |
+                  VIR_TYPED_PARAM_STRING_OKAY, -1);
+
+    if ((*nparams) == 0) {
+        *nparams = 7;
+        return 0;
+    }
+
+    if (!(vm = testDomObjFromDomain(dom)))
+        return -1;
+
+    if (!(def = virDomainObjGetOneDef(vm, flags)))
+        goto cleanup;
+
+    if (!(net = virDomainNetFind(def, device)))
+        goto cleanup;
+
+    if (net->bandwidth) {
+        if (net->bandwidth->in)
+            in = *net->bandwidth->in;
+        if (net->bandwidth->out)
+            out = *net->bandwidth->out;
+    }
+
+    TEST_SET_PARAM(0, VIR_DOMAIN_BANDWIDTH_IN_AVERAGE, VIR_TYPED_PARAM_UINT, in.average);
+    TEST_SET_PARAM(1, VIR_DOMAIN_BANDWIDTH_IN_PEAK, VIR_TYPED_PARAM_UINT, in.peak);
+    TEST_SET_PARAM(2, VIR_DOMAIN_BANDWIDTH_IN_BURST, VIR_TYPED_PARAM_UINT, in.burst);
+    TEST_SET_PARAM(3, VIR_DOMAIN_BANDWIDTH_IN_FLOOR, VIR_TYPED_PARAM_UINT, in.floor);
+    TEST_SET_PARAM(4, VIR_DOMAIN_BANDWIDTH_OUT_AVERAGE, VIR_TYPED_PARAM_UINT, out.average);
+    TEST_SET_PARAM(5, VIR_DOMAIN_BANDWIDTH_OUT_PEAK, VIR_TYPED_PARAM_UINT, out.peak);
+    TEST_SET_PARAM(6, VIR_DOMAIN_BANDWIDTH_OUT_BURST, VIR_TYPED_PARAM_UINT, out.burst);
+
+    if (*nparams > 7)
+        *nparams = 7;
+
+    ret = 0;
+ cleanup:
+    virDomainObjEndAPI(&vm);
+    return ret;
+}
+
+
 #undef TEST_SET_PARAM


@@ -7372,6 +7429,7 @@ static virHypervisorDriver testHypervisorDriver = {
     .domainGetXMLDesc = testDomainGetXMLDesc, /* 0.1.4 */
     .domainGetMemoryParameters = testDomainGetMemoryParameters, /* 5.6.0 */
     .domainGetNumaParameters = testDomainGetNumaParameters, /* 5.6.0 */
+    .domainGetInterfaceParameters = testDomainGetInterfaceParameters, /* 5.6.0 */
     .connectListDefinedDomains = testConnectListDefinedDomains, /* 0.1.11 */
     .connectNumOfDefinedDomains = testConnectNumOfDefinedDomains, /* 0.1.11 */
     .domainCreate = testDomainCreate, /* 0.1.11 */
--
2.22.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v2 4/4] test_driver: implement testDomainGetInterfaceParameters
Posted by Erik Skultety 5 years, 4 months ago
On Tue, Jul 02, 2019 at 03:49:44PM +0200, Ilias Stamatis wrote:
> Signed-off-by: Ilias Stamatis <stamatis.iliass@gmail.com>
> ---
>  src/test/test_driver.c | 58 ++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 58 insertions(+)
>
> diff --git a/src/test/test_driver.c b/src/test/test_driver.c
> index 15894d98ad..d2a7d2f840 100644
> --- a/src/test/test_driver.c
> +++ b/src/test/test_driver.c
> @@ -2935,6 +2935,63 @@ testDomainGetNumaParameters(virDomainPtr dom,
>  }
>
>
> +static int
> +testDomainGetInterfaceParameters(virDomainPtr dom,
> +                                 const char *device,
> +                                 virTypedParameterPtr params,
> +                                 int *nparams,
> +                                 unsigned int flags)
> +{
> +    virNetDevBandwidthRate in = {0};
> +    virNetDevBandwidthRate out = {0};
> +    virDomainObjPtr vm = NULL;
> +    virDomainDefPtr def = NULL;
> +    virDomainNetDefPtr net = NULL;
> +    int ret = -1;
> +
> +    virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
> +                  VIR_DOMAIN_AFFECT_CONFIG |
> +                  VIR_TYPED_PARAM_STRING_OKAY, -1);
> +
> +    if ((*nparams) == 0) {
> +        *nparams = 7;
> +        return 0;
> +    }
> +
> +    if (!(vm = testDomObjFromDomain(dom)))
> +        return -1;
> +
> +    if (!(def = virDomainObjGetOneDef(vm, flags)))
> +        goto cleanup;
> +
> +    if (!(net = virDomainNetFind(def, device)))
> +        goto cleanup;
> +
> +    if (net->bandwidth) {
> +        if (net->bandwidth->in)
> +            in = *net->bandwidth->in;
> +        if (net->bandwidth->out)
> +            out = *net->bandwidth->out;
> +    }
> +
> +    TEST_SET_PARAM(0, VIR_DOMAIN_BANDWIDTH_IN_AVERAGE, VIR_TYPED_PARAM_UINT, in.average);
> +    TEST_SET_PARAM(1, VIR_DOMAIN_BANDWIDTH_IN_PEAK, VIR_TYPED_PARAM_UINT, in.peak);
> +    TEST_SET_PARAM(2, VIR_DOMAIN_BANDWIDTH_IN_BURST, VIR_TYPED_PARAM_UINT, in.burst);
> +    TEST_SET_PARAM(3, VIR_DOMAIN_BANDWIDTH_IN_FLOOR, VIR_TYPED_PARAM_UINT, in.floor);
> +    TEST_SET_PARAM(4, VIR_DOMAIN_BANDWIDTH_OUT_AVERAGE, VIR_TYPED_PARAM_UINT, out.average);
> +    TEST_SET_PARAM(5, VIR_DOMAIN_BANDWIDTH_OUT_PEAK, VIR_TYPED_PARAM_UINT, out.peak);
> +    TEST_SET_PARAM(6, VIR_DOMAIN_BANDWIDTH_OUT_BURST, VIR_TYPED_PARAM_UINT, out.burst);

Elegant.

> +
> +    if (*nparams > 7)
> +        *nparams = 7;
> +
> +    ret = 0;
> + cleanup:
> +    virDomainObjEndAPI(&vm);
> +    return ret;
> +}
> +
> +
>  #undef TEST_SET_PARAM

Reviewed-by: Erik Skultety <eskultet@redhat.com>

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