CIP-dev Archive on lore.kernel.org
 help / color / Atom feed
* [cip-dev] [isar-cip-core][PATCH] classes/image_uuid: Generate new uuid if a new package is added
@ 2020-09-18  8:04 Quirin Gylstorff
  2020-09-18 12:21 ` Jan Kiszka
  0 siblings, 1 reply; 2+ messages in thread
From: Quirin Gylstorff @ 2020-09-18  8:04 UTC (permalink / raw)
  To: cip-dev, Jan.Kiszka; +Cc: Quirin Gylstorff


[-- Attachment #1: Type: text/plain, Size: 1812 bytes --]

From: Quirin Gylstorff <quirin.gylstorff@siemens.com>

BB_BASEHASH only includes the task itself and its metadata.
Dependencies are not taken into account when this hash is
generated which means updating a package will not generate a new
UUID.

BB_TASKHASH takes the changes into account.

Signed-off-by: Quirin Gylstorff <quirin.gylstorff@siemens.com>
---
 classes/image_uuid.bbclass | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/classes/image_uuid.bbclass b/classes/image_uuid.bbclass
index d5337b8..873abc5 100644
--- a/classes/image_uuid.bbclass
+++ b/classes/image_uuid.bbclass
@@ -9,23 +9,23 @@
 # SPDX-License-Identifier: MIT
 #
 
-def generate_image_uuid(d):
-    import uuid
+IMAGE_UUID ?= "random"
 
-    base_hash = d.getVar("BB_BASEHASH_task-do_rootfs_install", True)
-    if base_hash is None:
-        return None
-    return str(uuid.UUID(base_hash[:32], version=4))
-
-IMAGE_UUID ?= "${@generate_image_uuid(d)}"
+IMAGE_UUID_NAMESPACE = "6090f47e-b068-475c-b125-7be7c24cdd4e"
 
 do_generate_image_uuid[vardeps] += "IMAGE_UUID"
 do_generate_image_uuid[depends] = "buildchroot-target:do_build"
+IMAGER_INSTALL += "uuid-runtime"
 do_generate_image_uuid() {
+    image_do_mounts
+    if [ "${IMAGE_UUID}" != "random" ]; then
+        IMAGE_UUID_FINAL="${IMAGE_UUID}"
+    else
+        IMAGE_UUID_FINAL="$(sudo -E chroot ${BUILDCHROOT_DIR} uuidgen -s -n "${IMAGE_UUID_NAMESPACE}" -N "${BB_TASKHASH}")"
+    fi
     sudo sed -i '/^IMAGE_UUID=.*/d' '${IMAGE_ROOTFS}/etc/os-release'
-    echo "IMAGE_UUID=\"${IMAGE_UUID}\"" | \
+    echo "IMAGE_UUID=\"${IMAGE_UUID_FINAL}\"" | \
         sudo tee -a '${IMAGE_ROOTFS}/etc/os-release'
-    image_do_mounts
 
     # update initramfs to add uuid
     sudo chroot '${IMAGE_ROOTFS}' update-initramfs -u
-- 
2.20.1


[-- Attachment #2: Type: text/plain, Size: 420 bytes --]


-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#5462): https://lists.cip-project.org/g/cip-dev/message/5462
Mute This Topic: https://lists.cip-project.org/mt/76926695/4520388
Group Owner: cip-dev+owner@lists.cip-project.org
Unsubscribe: https://lists.cip-project.org/g/cip-dev/leave/8129055/727948398/xyzzy [cip-dev@archiver.kernel.org]
-=-=-=-=-=-=-=-=-=-=-=-


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [cip-dev] [isar-cip-core][PATCH] classes/image_uuid: Generate new uuid if a new package is added
  2020-09-18  8:04 [cip-dev] [isar-cip-core][PATCH] classes/image_uuid: Generate new uuid if a new package is added Quirin Gylstorff
@ 2020-09-18 12:21 ` Jan Kiszka
  0 siblings, 0 replies; 2+ messages in thread
From: Jan Kiszka @ 2020-09-18 12:21 UTC (permalink / raw)
  To: Q. Gylstorff, cip-dev


[-- Attachment #1: Type: text/plain, Size: 2697 bytes --]

On 18.09.20 10:04, Q. Gylstorff wrote:
> From: Quirin Gylstorff <quirin.gylstorff@siemens.com>
> 
> BB_BASEHASH only includes the task itself and its metadata.
> Dependencies are not taken into account when this hash is
> generated which means updating a package will not generate a new
> UUID.
> 
> BB_TASKHASH takes the changes into account.
> 
> Signed-off-by: Quirin Gylstorff <quirin.gylstorff@siemens.com>
> ---
>   classes/image_uuid.bbclass | 20 ++++++++++----------
>   1 file changed, 10 insertions(+), 10 deletions(-)
> 
> diff --git a/classes/image_uuid.bbclass b/classes/image_uuid.bbclass
> index d5337b8..873abc5 100644
> --- a/classes/image_uuid.bbclass
> +++ b/classes/image_uuid.bbclass
> @@ -9,23 +9,23 @@
>   # SPDX-License-Identifier: MIT
>   #
>   
> -def generate_image_uuid(d):
> -    import uuid
> +IMAGE_UUID ?= "random"

Why not using an undefined or empty IMAGE_UUID as "generate me one" 
indication?

>   
> -    base_hash = d.getVar("BB_BASEHASH_task-do_rootfs_install", True)
> -    if base_hash is None:
> -        return None
> -    return str(uuid.UUID(base_hash[:32], version=4))
> -
> -IMAGE_UUID ?= "${@generate_image_uuid(d)}"
> +IMAGE_UUID_NAMESPACE = "6090f47e-b068-475c-b125-7be7c24cdd4e"

Is that namespace random, or does that have specific meaning?

>   
>   do_generate_image_uuid[vardeps] += "IMAGE_UUID"
>   do_generate_image_uuid[depends] = "buildchroot-target:do_build"
> +IMAGER_INSTALL += "uuid-runtime"

Please separate variable for job definitions be a blank line. Also the 
job specifications above should be visually separated from the code 
below that way. IOW:

IMAGER_INSTALL += "uuid-runtime"

do_generate_image_uuid[vardeps] += "IMAGE_UUID"
do_generate_image_uuid[depends] = "buildchroot-target:do_build"

do_generate_image_uuid() {

>   do_generate_image_uuid() {
> +    image_do_mounts
> +    if [ "${IMAGE_UUID}" != "random" ]; then
> +        IMAGE_UUID_FINAL="${IMAGE_UUID}"
> +    else
> +        IMAGE_UUID_FINAL="$(sudo -E chroot ${BUILDCHROOT_DIR} uuidgen -s -n "${IMAGE_UUID_NAMESPACE}" -N "${BB_TASKHASH}")"

Why do we need to switch to uuidgen from the buildchroot, rather than 
using python's uuid?

And what ensures that uuidgen is available there?

> +    fi
>       sudo sed -i '/^IMAGE_UUID=.*/d' '${IMAGE_ROOTFS}/etc/os-release'
> -    echo "IMAGE_UUID=\"${IMAGE_UUID}\"" | \
> +    echo "IMAGE_UUID=\"${IMAGE_UUID_FINAL}\"" | \
>           sudo tee -a '${IMAGE_ROOTFS}/etc/os-release'
> -    image_do_mounts
>   
>       # update initramfs to add uuid
>       sudo chroot '${IMAGE_ROOTFS}' update-initramfs -u
> 

Jan

-- 
Siemens AG, Corporate Technology, CT RDA IOT SES-DE
Corporate Competence Center Embedded Linux

[-- Attachment #2: Type: text/plain, Size: 420 bytes --]


-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#5463): https://lists.cip-project.org/g/cip-dev/message/5463
Mute This Topic: https://lists.cip-project.org/mt/76926695/4520388
Group Owner: cip-dev+owner@lists.cip-project.org
Unsubscribe: https://lists.cip-project.org/g/cip-dev/leave/8129055/727948398/xyzzy [cip-dev@archiver.kernel.org]
-=-=-=-=-=-=-=-=-=-=-=-


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-18  8:04 [cip-dev] [isar-cip-core][PATCH] classes/image_uuid: Generate new uuid if a new package is added Quirin Gylstorff
2020-09-18 12:21 ` Jan Kiszka

CIP-dev Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/cip-dev/0 cip-dev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 cip-dev cip-dev/ https://lore.kernel.org/cip-dev \
		cip-dev@lists.cip-project.org
	public-inbox-index cip-dev

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.cip-project.lists.cip-dev


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git