[libvirt] [PATCH] test_driver: implement virDomainSetLifecycleAction

Ilias Stamatis posted 1 patch 4 years, 8 months ago
Test syntax-check passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20190802095105.18190-1-stamatis.iliass@gmail.com
There is a newer version of this series
src/test/test_driver.c | 58 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 58 insertions(+)
[libvirt] [PATCH] test_driver: implement virDomainSetLifecycleAction
Posted by Ilias Stamatis 4 years, 8 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 aae9875194..71d6baa3da 100755
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -7404,6 +7404,63 @@ testDomainMemoryPeek(virDomainPtr dom,
 }


+static void
+testDomainModifyLifecycleAction(virDomainDefPtr def,
+                                virDomainLifecycle type,
+                                virDomainLifecycleAction action)
+{
+    switch (type) {
+    case VIR_DOMAIN_LIFECYCLE_POWEROFF:
+        def->onPoweroff = action;
+        break;
+    case VIR_DOMAIN_LIFECYCLE_REBOOT:
+        def->onReboot = action;
+        break;
+    case VIR_DOMAIN_LIFECYCLE_CRASH:
+        def->onCrash = action;
+        break;
+    case VIR_DOMAIN_LIFECYCLE_LAST:
+        break;
+    }
+}
+
+
+static int
+testDomainSetLifecycleAction(virDomainPtr dom,
+                             unsigned int type,
+                             unsigned int action,
+                             unsigned int flags)
+{
+    virDomainObjPtr vm = NULL;
+    virDomainDefPtr def = NULL;
+    virDomainDefPtr persistentDef = NULL;
+    int ret = -1;
+
+    virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
+                  VIR_DOMAIN_AFFECT_CONFIG, -1);
+
+    if (!virDomainDefLifecycleActionAllowed(type, action))
+        return -1;
+
+    if (!(vm = testDomObjFromDomain(dom)))
+        return -1;
+
+    if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0)
+        goto cleanup;
+
+    if (def)
+        testDomainModifyLifecycleAction(def, type, action);
+
+    if (persistentDef)
+        testDomainModifyLifecycleAction(persistentDef, type, action);
+
+    ret = 0;
+ cleanup:
+    virDomainObjEndAPI(&vm);
+    return ret;
+}
+
+
 /*
  * Snapshot APIs
  */
@@ -8698,6 +8755,7 @@ static virHypervisorDriver testHypervisorDriver = {
     .domainHasManagedSaveImage = testDomainHasManagedSaveImage, /* 1.1.4 */
     .domainManagedSaveRemove = testDomainManagedSaveRemove, /* 1.1.4 */
     .domainMemoryPeek = testDomainMemoryPeek, /* 5.4.0 */
+    .domainSetLifecycleAction = testDomainSetLifecycleAction, /* 5.7.0 */

     .domainSnapshotNum = testDomainSnapshotNum, /* 1.1.4 */
     .domainSnapshotListNames = testDomainSnapshotListNames, /* 1.1.4 */
--
2.22.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] test_driver: implement virDomainSetLifecycleAction
Posted by Erik Skultety 4 years, 8 months ago
On Fri, Aug 02, 2019 at 11:51:05AM +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 aae9875194..71d6baa3da 100755
> --- a/src/test/test_driver.c
> +++ b/src/test/test_driver.c
> @@ -7404,6 +7404,63 @@ testDomainMemoryPeek(virDomainPtr dom,
>  }
>
>
> +static void
> +testDomainModifyLifecycleAction(virDomainDefPtr def,
> +                                virDomainLifecycle type,
> +                                virDomainLifecycleAction action)
> +{
> +    switch (type) {
> +    case VIR_DOMAIN_LIFECYCLE_POWEROFF:
> +        def->onPoweroff = action;
> +        break;
> +    case VIR_DOMAIN_LIFECYCLE_REBOOT:
> +        def->onReboot = action;
> +        break;
> +    case VIR_DOMAIN_LIFECYCLE_CRASH:
> +        def->onCrash = action;
> +        break;
> +    case VIR_DOMAIN_LIFECYCLE_LAST:
> +        break;
> +    }
> +}
> +
> +
> +static int
> +testDomainSetLifecycleAction(virDomainPtr dom,
> +                             unsigned int type,
> +                             unsigned int action,
> +                             unsigned int flags)
> +{
> +    virDomainObjPtr vm = NULL;
> +    virDomainDefPtr def = NULL;
> +    virDomainDefPtr persistentDef = NULL;
> +    int ret = -1;
> +
> +    virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
> +                  VIR_DOMAIN_AFFECT_CONFIG, -1);
> +
> +    if (!virDomainDefLifecycleActionAllowed(type, action))
> +        return -1;
> +
> +    if (!(vm = testDomObjFromDomain(dom)))
> +        return -1;
> +
> +    if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0)

We should use virDomainObjGetOneDef instead.

> +        goto cleanup;
> +
> +    if (def)
> +        testDomainModifyLifecycleAction(def, type, action);
> +
> +    if (persistentDef)
> +        testDomainModifyLifecycleAction(persistentDef, type, action);

We'll need to make use of private data here too, if I set:
type=poweroff
action=restart

the test domain needs to change states accordingly, IOW running->running,
right now we merely modified the XML which is not enough.

Erik

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] test_driver: implement virDomainSetLifecycleAction
Posted by Ilias Stamatis 4 years, 8 months ago
On Fri, Aug 9, 2019 at 3:55 PM Erik Skultety <eskultet@redhat.com> wrote:
>
> On Fri, Aug 02, 2019 at 11:51:05AM +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 aae9875194..71d6baa3da 100755
> > --- a/src/test/test_driver.c
> > +++ b/src/test/test_driver.c
> > @@ -7404,6 +7404,63 @@ testDomainMemoryPeek(virDomainPtr dom,
> >  }
> >
> >
> > +static void
> > +testDomainModifyLifecycleAction(virDomainDefPtr def,
> > +                                virDomainLifecycle type,
> > +                                virDomainLifecycleAction action)
> > +{
> > +    switch (type) {
> > +    case VIR_DOMAIN_LIFECYCLE_POWEROFF:
> > +        def->onPoweroff = action;
> > +        break;
> > +    case VIR_DOMAIN_LIFECYCLE_REBOOT:
> > +        def->onReboot = action;
> > +        break;
> > +    case VIR_DOMAIN_LIFECYCLE_CRASH:
> > +        def->onCrash = action;
> > +        break;
> > +    case VIR_DOMAIN_LIFECYCLE_LAST:
> > +        break;
> > +    }
> > +}
> > +
> > +
> > +static int
> > +testDomainSetLifecycleAction(virDomainPtr dom,
> > +                             unsigned int type,
> > +                             unsigned int action,
> > +                             unsigned int flags)
> > +{
> > +    virDomainObjPtr vm = NULL;
> > +    virDomainDefPtr def = NULL;
> > +    virDomainDefPtr persistentDef = NULL;
> > +    int ret = -1;
> > +
> > +    virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
> > +                  VIR_DOMAIN_AFFECT_CONFIG, -1);
> > +
> > +    if (!virDomainDefLifecycleActionAllowed(type, action))
> > +        return -1;
> > +
> > +    if (!(vm = testDomObjFromDomain(dom)))
> > +        return -1;
> > +
> > +    if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0)
>
> We should use virDomainObjGetOneDef instead.

I think not. Because the 2 flags aren't mutually exclusive for this
API. So the user might want to affect both the persistent and the live
config at the same time with a single call.

What do you think?

>
> > +        goto cleanup;
> > +
> > +    if (def)
> > +        testDomainModifyLifecycleAction(def, type, action);
> > +
> > +    if (persistentDef)
> > +        testDomainModifyLifecycleAction(persistentDef, type, action);
>
> We'll need to make use of private data here too, if I set:
> type=poweroff
> action=restart
>
> the test domain needs to change states accordingly, IOW running->running,
> right now we merely modified the XML which is not enough.
>
> Erik

Right. A v2 is in the works.

Thanks,
Ilias

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] test_driver: implement virDomainSetLifecycleAction
Posted by Erik Skultety 4 years, 8 months ago
On Tue, Aug 13, 2019 at 03:07:50PM +0300, Ilias Stamatis wrote:
> On Fri, Aug 9, 2019 at 3:55 PM Erik Skultety <eskultet@redhat.com> wrote:
> >
> > On Fri, Aug 02, 2019 at 11:51:05AM +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 aae9875194..71d6baa3da 100755
> > > --- a/src/test/test_driver.c
> > > +++ b/src/test/test_driver.c
> > > @@ -7404,6 +7404,63 @@ testDomainMemoryPeek(virDomainPtr dom,
> > >  }
> > >
> > >
> > > +static void
> > > +testDomainModifyLifecycleAction(virDomainDefPtr def,
> > > +                                virDomainLifecycle type,
> > > +                                virDomainLifecycleAction action)
> > > +{
> > > +    switch (type) {
> > > +    case VIR_DOMAIN_LIFECYCLE_POWEROFF:
> > > +        def->onPoweroff = action;
> > > +        break;
> > > +    case VIR_DOMAIN_LIFECYCLE_REBOOT:
> > > +        def->onReboot = action;
> > > +        break;
> > > +    case VIR_DOMAIN_LIFECYCLE_CRASH:
> > > +        def->onCrash = action;
> > > +        break;
> > > +    case VIR_DOMAIN_LIFECYCLE_LAST:
> > > +        break;
> > > +    }
> > > +}
> > > +
> > > +
> > > +static int
> > > +testDomainSetLifecycleAction(virDomainPtr dom,
> > > +                             unsigned int type,
> > > +                             unsigned int action,
> > > +                             unsigned int flags)
> > > +{
> > > +    virDomainObjPtr vm = NULL;
> > > +    virDomainDefPtr def = NULL;
> > > +    virDomainDefPtr persistentDef = NULL;
> > > +    int ret = -1;
> > > +
> > > +    virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
> > > +                  VIR_DOMAIN_AFFECT_CONFIG, -1);
> > > +
> > > +    if (!virDomainDefLifecycleActionAllowed(type, action))
> > > +        return -1;
> > > +
> > > +    if (!(vm = testDomObjFromDomain(dom)))
> > > +        return -1;
> > > +
> > > +    if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0)
> >
> > We should use virDomainObjGetOneDef instead.
>
> I think not. Because the 2 flags aren't mutually exclusive for this
> API. So the user might want to affect both the persistent and the live
> config at the same time with a single call.
>
> What do you think?

Good point, it can stay then.

Regards,
Erik

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