From 50afe9fd6e587d4d706c34c48d42e8b405015078 Mon Sep 17 00:00:00 2001 From: Ruixin Date: Tue, 25 Jul 2017 21:49:10 +0000 Subject: [PATCH 1/2] Deployment: add endoflife When commit metadata contains ostree.endoflife attribute, its information will be added to the deployment Variant, which will later be shown as a red & bold message when 'rpm-ostree status' command is called. A test is added for future regression --- src/app/rpmostree-builtin-status.c | 10 ++++++++++ src/daemon/rpmostreed-deployment-utils.c | 24 +++++++++++++++++++++++- tests/vmcheck/test-basic.sh | 12 ++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/app/rpmostree-builtin-status.c b/src/app/rpmostree-builtin-status.c index e19eb107ac..7854734166 100644 --- a/src/app/rpmostree-builtin-status.c +++ b/src/app/rpmostree-builtin-status.c @@ -563,6 +563,16 @@ status_generic (RPMOSTreeSysroot *sysroot_proxy, print_kv ("Unlocked", max_key_len, unlocked); g_print ("%s%s", bold_suffix, red_suffix); } + const char *end_of_life_string = NULL; + /* look for endoflife attribute in the deployment */ + g_variant_dict_lookup (dict, "endoflife", "&s", &end_of_life_string); + + if (end_of_life_string) + { + g_print ("%s%s", red_prefix, bold_prefix); + print_kv ("EndOfLife", max_key_len, end_of_life_string); + g_print ("%s%s", bold_suffix, red_suffix); + } } return TRUE; diff --git a/src/daemon/rpmostreed-deployment-utils.c b/src/daemon/rpmostreed-deployment-utils.c index ee8f18163a..d597e5a7a1 100644 --- a/src/daemon/rpmostreed-deployment-utils.c +++ b/src/daemon/rpmostreed-deployment-utils.c @@ -126,6 +126,23 @@ rpmostreed_deployment_generate_blank_variant (void) return g_variant_dict_end (&dict); } +static void +variant_add_metadata_attribute (GVariantDict *dict, + const gchar *attribute, + const gchar *new_attribute, + GVariant *commit) +{ + g_autofree gchar *attribute_string_value = NULL; + g_autoptr(GVariant) metadata = g_variant_get_child_value (commit, 0); + + if (metadata != NULL) + { + g_variant_lookup (metadata, attribute, "s", &attribute_string_value); + if (attribute_string_value != NULL) + g_variant_dict_insert (dict, new_attribute ?: attribute, "s", attribute_string_value); + } +} + static void variant_add_commit_details (GVariantDict *dict, const char *prefix, @@ -227,9 +244,14 @@ rpmostreed_deployment_generate_variant (OstreeSysroot *sysroot, g_variant_dict_insert (&dict, "base-checksum", "s", base_checksum); variant_add_commit_details (&dict, "base-", base_commit); + /* for layered commits, check if their base commit has end of life attribute */ + variant_add_metadata_attribute (&dict, OSTREE_COMMIT_META_KEY_ENDOFLIFE, "endoflife", base_commit); } else - base_checksum = g_strdup (csum); + { + base_checksum = g_strdup (csum); + variant_add_metadata_attribute (&dict, OSTREE_COMMIT_META_KEY_ENDOFLIFE, "endoflife", commit); + } sigs = rpmostreed_deployment_gpg_results (repo, refspec, base_checksum, &gpg_enabled); variant_add_commit_details (&dict, NULL, commit); diff --git a/tests/vmcheck/test-basic.sh b/tests/vmcheck/test-basic.sh index d4a71b222a..afe1d1a2b1 100755 --- a/tests/vmcheck/test-basic.sh +++ b/tests/vmcheck/test-basic.sh @@ -59,3 +59,15 @@ echo "ok status doesn't require root" # Also check that we can do status as non-root non-active vm_cmd runuser -u bin rpm-ostree status echo "ok status doesn't require active PAM session" + +# Add metadata string containing EnfOfLife attribtue +META_ENDOFLIFE_MESSAGE="this_is_a_test" +commit=$(vm_cmd ostree commit -b vmcheck \ + --tree=ref=vmcheck --add-metadata-string=ostree.endoflife=$META_ENDOFLIFE_MESSAGE) +vm_rpmostree upgrade +vm_assert_status_jq ".deployments[0][\"endoflife\"] == \"${META_ENDOFLIFE_MESSAGE}\"" + +# Build a layered commit and check if EndOfLife still present +vm_build_rpm foo +vm_rpmostree install foo +vm_assert_status_jq ".deployments[0][\"endoflife\"] == \"${META_ENDOFLIFE_MESSAGE}\"" From 467c40dce979ebb14cf5138afca4a33f370b1dd9 Mon Sep 17 00:00:00 2001 From: Ruixin Date: Fri, 28 Jul 2017 14:32:39 +0000 Subject: [PATCH 2/2] fixup! Deployment: add endoflife --- tests/vmcheck/test-basic.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/vmcheck/test-basic.sh b/tests/vmcheck/test-basic.sh index afe1d1a2b1..770cbe1401 100755 --- a/tests/vmcheck/test-basic.sh +++ b/tests/vmcheck/test-basic.sh @@ -61,13 +61,15 @@ vm_cmd runuser -u bin rpm-ostree status echo "ok status doesn't require active PAM session" # Add metadata string containing EnfOfLife attribtue -META_ENDOFLIFE_MESSAGE="this_is_a_test" +META_ENDOFLIFE_MESSAGE="this is a test for metadata message" commit=$(vm_cmd ostree commit -b vmcheck \ - --tree=ref=vmcheck --add-metadata-string=ostree.endoflife=$META_ENDOFLIFE_MESSAGE) + --tree=ref=vmcheck --add-metadata-string=ostree.endoflife=\"${META_ENDOFLIFE_MESSAGE}\") vm_rpmostree upgrade vm_assert_status_jq ".deployments[0][\"endoflife\"] == \"${META_ENDOFLIFE_MESSAGE}\"" +echo "ok endoflife metadata gets parsed correctly" # Build a layered commit and check if EndOfLife still present vm_build_rpm foo vm_rpmostree install foo vm_assert_status_jq ".deployments[0][\"endoflife\"] == \"${META_ENDOFLIFE_MESSAGE}\"" +echo "ok layered commit inherits the endoflife attribute"