[PATCH v2 2/3] tests/vm: Introduce get_qemu_packages_from_lcitool_json() helper

Philippe Mathieu-Daudé posted 3 patches 2 years, 5 months ago
Maintainers: "Alex Bennée" <alex.bennee@linaro.org>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Thomas Huth <thuth@redhat.com>, Wainer dos Santos Moschetta <wainersm@redhat.com>, Beraldo Leal <bleal@redhat.com>, Warner Losh <imp@bsdimp.com>, Kyle Evans <kevans@freebsd.org>, Ed Maste <emaste@freebsd.org>, Li-Wen Hsu <lwhsu@freebsd.org>
There is a newer version of this series
[PATCH v2 2/3] tests/vm: Introduce get_qemu_packages_from_lcitool_json() helper
Posted by Philippe Mathieu-Daudé 2 years, 5 months ago
Add the get_qemu_packages_from_lcitool_json() helper which return
such package list from a lcitool env var file in JSON format.

Suggested-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 tests/vm/Makefile.include | 4 ++++
 tests/vm/basevm.py        | 9 +++++++++
 2 files changed, 13 insertions(+)

diff --git a/tests/vm/Makefile.include b/tests/vm/Makefile.include
index c2a8ca1c17..b021b344b5 100644
--- a/tests/vm/Makefile.include
+++ b/tests/vm/Makefile.include
@@ -106,6 +106,10 @@ $(IMAGES_DIR)/%.img:	$(SRC_PATH)/tests/vm/% \
 		--build-image $@, \
 		"  VM-IMAGE $*")
 
+$(SRC_PATH)/tests/vm/%.json:
+	$(call quiet-command, \
+		make lcitool-refresh)
+
 # Build in VM $(IMAGE)
 vm-build-%: $(IMAGES_DIR)/%.img $(VM_VENV)
 	$(call quiet-command, \
diff --git a/tests/vm/basevm.py b/tests/vm/basevm.py
index 23229e23d1..cc4cc0a973 100644
--- a/tests/vm/basevm.py
+++ b/tests/vm/basevm.py
@@ -27,6 +27,7 @@
 import multiprocessing
 import traceback
 import shlex
+import json
 
 from qemu.machine import QEMUMachine
 from qemu.utils import get_info_usernet_hostfwd_port, kvm_available
@@ -501,6 +502,14 @@ def gen_cloud_init_iso(self):
                               stderr=self._stdout)
         return os.path.join(cidir, "cloud-init.iso")
 
+    def get_qemu_packages_from_lcitool_json(self, json_path=None):
+        """Parse a lcitool variables json file and return the PKGS list."""
+        if json_path is None:
+            json_path = os.path.join(os.path.dirname(__file__), self.name + ".json")
+        with open(json_path, "r") as fh:
+            return json.load(fh)["pkgs"]
+
+
 def get_qemu_path(arch, build_path=None):
     """Fetch the path to the qemu binary."""
     # If QEMU environment variable set, it takes precedence
-- 
2.38.1


Re: [PATCH v2 2/3] tests/vm: Introduce get_qemu_packages_from_lcitool_json() helper
Posted by Daniel P. Berrangé 2 years, 5 months ago
On Tue, Jul 11, 2023 at 04:01:42PM +0200, Philippe Mathieu-Daudé wrote:
> Add the get_qemu_packages_from_lcitool_json() helper which return
> such package list from a lcitool env var file in JSON format.
> 
> Suggested-by: Daniel P. Berrangé <berrange@redhat.com>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>  tests/vm/Makefile.include | 4 ++++
>  tests/vm/basevm.py        | 9 +++++++++
>  2 files changed, 13 insertions(+)
> 
> diff --git a/tests/vm/Makefile.include b/tests/vm/Makefile.include
> index c2a8ca1c17..b021b344b5 100644
> --- a/tests/vm/Makefile.include
> +++ b/tests/vm/Makefile.include
> @@ -106,6 +106,10 @@ $(IMAGES_DIR)/%.img:	$(SRC_PATH)/tests/vm/% \
>  		--build-image $@, \
>  		"  VM-IMAGE $*")
>  
> +$(SRC_PATH)/tests/vm/%.json:
> +	$(call quiet-command, \
> +		make lcitool-refresh)

'lcitool-refresh' is something we only run explicitly when we
change something about the lcitool, and also isn't provided
to end users running from tarballs IIRC. So we shouldn't need
to wire it up to build targets, just commit its output JSON
file.


With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|


Re: [PATCH v2 2/3] tests/vm: Introduce get_qemu_packages_from_lcitool_json() helper
Posted by Philippe Mathieu-Daudé 2 years, 5 months ago
On 11/7/23 16:08, Daniel P. Berrangé wrote:
> On Tue, Jul 11, 2023 at 04:01:42PM +0200, Philippe Mathieu-Daudé wrote:
>> Add the get_qemu_packages_from_lcitool_json() helper which return
>> such package list from a lcitool env var file in JSON format.
>>
>> Suggested-by: Daniel P. Berrangé <berrange@redhat.com>
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>> ---
>>   tests/vm/Makefile.include | 4 ++++
>>   tests/vm/basevm.py        | 9 +++++++++
>>   2 files changed, 13 insertions(+)
>>
>> diff --git a/tests/vm/Makefile.include b/tests/vm/Makefile.include
>> index c2a8ca1c17..b021b344b5 100644
>> --- a/tests/vm/Makefile.include
>> +++ b/tests/vm/Makefile.include
>> @@ -106,6 +106,10 @@ $(IMAGES_DIR)/%.img:	$(SRC_PATH)/tests/vm/% \
>>   		--build-image $@, \
>>   		"  VM-IMAGE $*")
>>   
>> +$(SRC_PATH)/tests/vm/%.json:
>> +	$(call quiet-command, \
>> +		make lcitool-refresh)
> 
> 'lcitool-refresh' is something we only run explicitly when we
> change something about the lcitool, and also isn't provided
> to end users running from tarballs IIRC. So we shouldn't need
> to wire it up to build targets, just commit its output JSON
> file.

Right, simpler. Thanks!