[3/3] qmp: Add deprecation information to query-machines
diff mbox series

Message ID 20190423212246.3542-4-ehabkost@redhat.com
State New
Headers show
Series
  • Export machine type deprecation info through QMP
Related show

Commit Message

Eduardo Habkost April 23, 2019, 9:22 p.m. UTC
Export machine type deprecation information through the
query-machines QMP command.  With this, libvirt and management
software will be able to show this information to users and/or
suggest changes to VM configuration to avoid deprecated machines.

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 qapi/misc.json                     |  5 ++++-
 vl.c                               |  6 ++++++
 tests/acceptance/query_machines.py | 27 +++++++++++++++++++++++++++
 3 files changed, 37 insertions(+), 1 deletion(-)
 create mode 100644 tests/acceptance/query_machines.py

Comments

Daniel P. Berrangé April 24, 2019, 8:28 a.m. UTC | #1
On Tue, Apr 23, 2019 at 06:22:46PM -0300, Eduardo Habkost wrote:
> Export machine type deprecation information through the
> query-machines QMP command.  With this, libvirt and management
> software will be able to show this information to users and/or
> suggest changes to VM configuration to avoid deprecated machines.
> 
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
>  qapi/misc.json                     |  5 ++++-
>  vl.c                               |  6 ++++++
>  tests/acceptance/query_machines.py | 27 +++++++++++++++++++++++++++
>  3 files changed, 37 insertions(+), 1 deletion(-)
>  create mode 100644 tests/acceptance/query_machines.py
> 
> diff --git a/qapi/misc.json b/qapi/misc.json
> index 8b3ca4fdd3..941d251d17 100644
> --- a/qapi/misc.json
> +++ b/qapi/misc.json
> @@ -2018,12 +2018,15 @@
>  #
>  # @hotpluggable-cpus: cpu hotplug via -device is supported (since 2.7.0)
>  #
> +# @support-status: Support/deprecation status information (since 4.1.0)
> +#
>  # Since: 1.2.0
>  ##
>  { 'struct': 'MachineInfo',
>    'data': { 'name': 'str', '*alias': 'str',
>              '*is-default': 'bool', 'cpu-max': 'int',
> -            'hotpluggable-cpus': 'bool'} }
> +            'hotpluggable-cpus': 'bool',
> +            'support-status': 'SupportStatusInfo' } }

With my comment on the first patch this would become

    "deprecation-info": "*DeprecationInfo"

> diff --git a/vl.c b/vl.c
> index 99b857ed2a..ca23d2a404 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -1530,6 +1530,12 @@ MachineInfoList *qmp_query_machines(Error **errp)
>          info->name = g_strdup(mc->name);
>          info->cpu_max = !mc->max_cpus ? 1 : mc->max_cpus;
>          info->hotpluggable_cpus = mc->has_hotpluggable_cpus;
> +        assert(!mc->support_status.status_message ||
> +               mc->support_status.has_status_message);
> +        assert(!mc->support_status.suggested_alternative ||
> +               mc->support_status.has_suggested_alternative);
> +        info->support_status =
> +            QAPI_CLONE(SupportStatusInfo, &mc->support_status);
>  
>          entry = g_malloc0(sizeof(*entry));
>          entry->value = info;
> diff --git a/tests/acceptance/query_machines.py b/tests/acceptance/query_machines.py
> new file mode 100644
> index 0000000000..23a56ea617
> --- /dev/null
> +++ b/tests/acceptance/query_machines.py
> @@ -0,0 +1,27 @@
> +# Sanity check query-machines QMP command results
> +#
> +# Copyright (c) 2019 Red Hat, Inc.
> +#
> +# Author:
> +#  Eduardo Habkost <ehabkost@redhat.com>
> +#
> +# This work is licensed under the terms of the GNU GPL, version 2 or
> +# later.  See the COPYING file in the top-level directory.
> +
> +from avocado_qemu import Test
> +
> +class QueryMachines(Test):
> +    def test(self):
> +        self.vm.launch()
> +        machines = self.vm.command('query-machines')
> +        machinesdict = dict((m['name'], m) for m in machines)
> +        machinesdict.update((m['alias'], m) for m in machines if 'alias' in m)
> +        for machine in machines:
> +            status = machine['support-status']
> +            if status['deprecated']:
> +                self.assertTrue(status.get('status-message') or \
> +                                status.get('suggested-alternative'),
> +                                "Deprecated machine (%s) must have status-message or suggested-alternative" % (machine['name']))
> +            if 'suggested-alternative' in status:
> +                self.assertTrue(status['suggested-alternative'] in machinesdict,
> +                                "suggested-alternative of %s must point to a valid machine type" % (machine['name']))
> -- 
> 2.18.0.rc1.1.g3f1ff2140
> 
> 

Regards,
Daniel
Wainer dos Santos Moschetta April 25, 2019, 2:54 p.m. UTC | #2
Hi Eduardo,

On 04/23/2019 06:22 PM, Eduardo Habkost wrote:
> Export machine type deprecation information through the
> query-machines QMP command.  With this, libvirt and management
> software will be able to show this information to users and/or
> suggest changes to VM configuration to avoid deprecated machines.
>
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
>   qapi/misc.json                     |  5 ++++-
>   vl.c                               |  6 ++++++
>   tests/acceptance/query_machines.py | 27 +++++++++++++++++++++++++++
>   3 files changed, 37 insertions(+), 1 deletion(-)
>   create mode 100644 tests/acceptance/query_machines.py
>
> diff --git a/qapi/misc.json b/qapi/misc.json
> index 8b3ca4fdd3..941d251d17 100644
> --- a/qapi/misc.json
> +++ b/qapi/misc.json
> @@ -2018,12 +2018,15 @@
>   #
>   # @hotpluggable-cpus: cpu hotplug via -device is supported (since 2.7.0)
>   #
> +# @support-status: Support/deprecation status information (since 4.1.0)
> +#
>   # Since: 1.2.0
>   ##
>   { 'struct': 'MachineInfo',
>     'data': { 'name': 'str', '*alias': 'str',
>               '*is-default': 'bool', 'cpu-max': 'int',
> -            'hotpluggable-cpus': 'bool'} }
> +            'hotpluggable-cpus': 'bool',
> +            'support-status': 'SupportStatusInfo' } }
>   
>   ##
>   # @query-machines:
> diff --git a/vl.c b/vl.c
> index 99b857ed2a..ca23d2a404 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -1530,6 +1530,12 @@ MachineInfoList *qmp_query_machines(Error **errp)
>           info->name = g_strdup(mc->name);
>           info->cpu_max = !mc->max_cpus ? 1 : mc->max_cpus;
>           info->hotpluggable_cpus = mc->has_hotpluggable_cpus;
> +        assert(!mc->support_status.status_message ||
> +               mc->support_status.has_status_message);
> +        assert(!mc->support_status.suggested_alternative ||
> +               mc->support_status.has_suggested_alternative);
> +        info->support_status =
> +            QAPI_CLONE(SupportStatusInfo, &mc->support_status);
>   
>           entry = g_malloc0(sizeof(*entry));
>           entry->value = info;
> diff --git a/tests/acceptance/query_machines.py b/tests/acceptance/query_machines.py
> new file mode 100644
> index 0000000000..23a56ea617
> --- /dev/null
> +++ b/tests/acceptance/query_machines.py
> @@ -0,0 +1,27 @@
> +# Sanity check query-machines QMP command results
> +#
> +# Copyright (c) 2019 Red Hat, Inc.
> +#
> +# Author:
> +#  Eduardo Habkost <ehabkost@redhat.com>
> +#
> +# This work is licensed under the terms of the GNU GPL, version 2 or
> +# later.  See the COPYING file in the top-level directory.
> +
> +from avocado_qemu import Test
> +
> +class QueryMachines(Test):
> +    def test(self):

I suggest to use a meaning test case name as it will be displayed with 
Avocado output. Something like 'test_status_information'.

> +        self.vm.launch()
> +        machines = self.vm.command('query-machines')

Also I suggest to assert you got at least on machine, so ensure 
'query-machines' returning nothing doesn't pass unnoticed.

- Wainer

> +        machinesdict = dict((m['name'], m) for m in machines)
> +        machinesdict.update((m['alias'], m) for m in machines if 'alias' in m)
> +        for machine in machines:
> +            status = machine['support-status']
> +            if status['deprecated']:
> +                self.assertTrue(status.get('status-message') or \
> +                                status.get('suggested-alternative'),
> +                                "Deprecated machine (%s) must have status-message or suggested-alternative" % (machine['name']))
> +            if 'suggested-alternative' in status:
> +                self.assertTrue(status['suggested-alternative'] in machinesdict,
> +                                "suggested-alternative of %s must point to a valid machine type" % (machine['name']))
Eduardo Habkost April 25, 2019, 5:43 p.m. UTC | #3
On Thu, Apr 25, 2019 at 11:54:34AM -0300, Wainer dos Santos Moschetta wrote:
> Hi Eduardo,
> 
> On 04/23/2019 06:22 PM, Eduardo Habkost wrote:
[...]
> > +class QueryMachines(Test):
> > +    def test(self):
> 
> I suggest to use a meaning test case name as it will be displayed with
> Avocado output. Something like 'test_status_information'.

This is a generic test case for query-machines, and I don't
expect it to be specific for validating support-status.

> 
> > +        self.vm.launch()
> > +        machines = self.vm.command('query-machines')
> 
> Also I suggest to assert you got at least on machine, so ensure
> 'query-machines' returning nothing doesn't pass unnoticed.

Good idea.  I will send this in v2 or as a follow up patch.
Thanks!

Patch
diff mbox series

diff --git a/qapi/misc.json b/qapi/misc.json
index 8b3ca4fdd3..941d251d17 100644
--- a/qapi/misc.json
+++ b/qapi/misc.json
@@ -2018,12 +2018,15 @@ 
 #
 # @hotpluggable-cpus: cpu hotplug via -device is supported (since 2.7.0)
 #
+# @support-status: Support/deprecation status information (since 4.1.0)
+#
 # Since: 1.2.0
 ##
 { 'struct': 'MachineInfo',
   'data': { 'name': 'str', '*alias': 'str',
             '*is-default': 'bool', 'cpu-max': 'int',
-            'hotpluggable-cpus': 'bool'} }
+            'hotpluggable-cpus': 'bool',
+            'support-status': 'SupportStatusInfo' } }
 
 ##
 # @query-machines:
diff --git a/vl.c b/vl.c
index 99b857ed2a..ca23d2a404 100644
--- a/vl.c
+++ b/vl.c
@@ -1530,6 +1530,12 @@  MachineInfoList *qmp_query_machines(Error **errp)
         info->name = g_strdup(mc->name);
         info->cpu_max = !mc->max_cpus ? 1 : mc->max_cpus;
         info->hotpluggable_cpus = mc->has_hotpluggable_cpus;
+        assert(!mc->support_status.status_message ||
+               mc->support_status.has_status_message);
+        assert(!mc->support_status.suggested_alternative ||
+               mc->support_status.has_suggested_alternative);
+        info->support_status =
+            QAPI_CLONE(SupportStatusInfo, &mc->support_status);
 
         entry = g_malloc0(sizeof(*entry));
         entry->value = info;
diff --git a/tests/acceptance/query_machines.py b/tests/acceptance/query_machines.py
new file mode 100644
index 0000000000..23a56ea617
--- /dev/null
+++ b/tests/acceptance/query_machines.py
@@ -0,0 +1,27 @@ 
+# Sanity check query-machines QMP command results
+#
+# Copyright (c) 2019 Red Hat, Inc.
+#
+# Author:
+#  Eduardo Habkost <ehabkost@redhat.com>
+#
+# This work is licensed under the terms of the GNU GPL, version 2 or
+# later.  See the COPYING file in the top-level directory.
+
+from avocado_qemu import Test
+
+class QueryMachines(Test):
+    def test(self):
+        self.vm.launch()
+        machines = self.vm.command('query-machines')
+        machinesdict = dict((m['name'], m) for m in machines)
+        machinesdict.update((m['alias'], m) for m in machines if 'alias' in m)
+        for machine in machines:
+            status = machine['support-status']
+            if status['deprecated']:
+                self.assertTrue(status.get('status-message') or \
+                                status.get('suggested-alternative'),
+                                "Deprecated machine (%s) must have status-message or suggested-alternative" % (machine['name']))
+            if 'suggested-alternative' in status:
+                self.assertTrue(status['suggested-alternative'] in machinesdict,
+                                "suggested-alternative of %s must point to a valid machine type" % (machine['name']))