Adding ostree feed vs sysroot comparison

This is a check of ostree log output (commit and checksum)
for determining if a patch is currently installed or not.

The ostree commands are being moved to their own file.

Additional ostree commands will be refactored in later
commits.

Test Plan:
  Verify controller-0 is Patch current when no patches
installed.
  Verify controller-0 is Patch current when patches
uploaded, but not applied.
  Verify controller-0 is NOT Patch current when a patch is
 applied.

Story: 2009969
Task: 45323
Co-Authored-By: Jessica Castelino <jessica.castelino@windriver.com>
Signed-off-by: Al Bailey <al.bailey@windriver.com>
Change-Id: I84b238868badf1159c6312575704441bd996f741
This commit is contained in:
Al Bailey
2022-05-09 17:30:54 +00:00
parent fe74de5def
commit f6e9622083
4 changed files with 86 additions and 16 deletions

View File

@@ -44,6 +44,7 @@ CLI_OPT_RELEASE = '--release'
OSTREE_REF = "starlingx"
FEED_OSTREE_BASE_DIR = "/var/www/pages/feed"
SYSROOT_OSTREE = "/sysroot/ostree/repo"
ENABLE_DEV_CERTIFICATE_PATCH_IDENTIFIER = 'ENABLE_DEV_CERTIFICATE'

View File

@@ -0,0 +1,73 @@
"""
Copyright (c) 2022 Wind River Systems, Inc.
SPDX-License-Identifier: Apache-2.0
"""
import subprocess
from cgcs_patch import constants
def get_ostree_latest_commit(ostree_ref, repo_path):
"""
Query ostree using ostree log <ref> --repo=<path>
:param ostree_ref: the ostree ref.
example: starlingx
:param repo_path: the path to the ostree repo:
example: /var/www/pages/feed/rel-22.06/ostree_repo
:return: a tuple of the most recent commit and checksum
"""
# Sample command and output that is parsed to get the commit and checksum
#
# Command: ostree log starlingx --repo=/var/www/pages/feed/rel-22.02/ostree_repo
#
# Output:
#
# commit 478bc21c1702b9b667b5a75fac62a3ef9203cc1767cbe95e89dface6dc7f205e
# ContentChecksum: 61fc5bb4398d73027595a4d839daeb404200d0899f6e7cdb24bb8fb6549912ba
# Date: 2022-04-28 18:58:57 +0000
#
# Commit-id: starlingx-intel-x86-64-20220428185802
#
# commit ad7057a94a1d06e38eaedee2ce3fe56826ae817497469bce5d5ac05bc506aaa7
# ContentChecksum: dc42a42427a4f9e4de1210327c12b12ea3ad6a5d232497a903cc6478ca381e8b
# Date: 2022-04-28 18:05:43 +0000
#
# Commit-id: starlingx-intel-x86-64-20220428180512
cmd = "ostree log %s --repo=%s" % (ostree_ref, repo_path)
output = subprocess.run(cmd, shell=True, check=True, capture_output=True)
# Store the output of the above command in a string
output_string = output.stdout.decode('utf-8')
# Parse the string to get the latest commit and checksum for that ostree
split_output_string = output_string.split()
latest_commit = split_output_string[1]
latest_checksum = split_output_string[3]
return (latest_commit, latest_checksum)
def get_feed_latest_commit(patch_sw_version):
"""
Query ostree feed using ostree log <ref> --repo=<path>
:param patch_sw_version: software version for the feed
example: 22.06
:return: a tuple of the most recent commit and checksum
for that feed
"""
repo_path = "%s/rel-%s/ostree_repo" % (constants.FEED_OSTREE_BASE_DIR,
patch_sw_version)
return get_ostree_latest_commit(constants.OSTREE_REF, repo_path)
def get_sysroot_latest_commit():
"""
Query ostree sysroot to determine the currently active commit
:return: a tuple of the commit and checksum for sysroot
"""
return get_ostree_latest_commit(constants.OSTREE_REF, constants.SYSROOT_OSTREE)

View File

@@ -15,6 +15,7 @@ import subprocess
import sys
import time
from cgcs_patch import ostree_utils
from cgcs_patch.patch_functions import configure_logging
from cgcs_patch.patch_functions import LOG
import cgcs_patch.config as cfg
@@ -368,25 +369,19 @@ class PatchAgent(PatchService):
# Generate a unique query id
self.query_id = random.random()
# determine OSTREE state of the system and the patches
self.changes = False
self.installed = {}
self.to_remove = []
self.missing_pkgs = []
# todo(jcasteli): Can a patch contain commit SHAs from an easlier patch
active_commit, active_checksum = ostree_utils.get_sysroot_latest_commit()
patch_commit, patch_checksum = ostree_utils.get_feed_latest_commit(SW_VERSION)
# There are three possible actions:
# 1. If installed pkg is not in a repo, remove it.
# 2. If installed pkg version does not match newest repo version, update it.
# 3. If a package in the grouplist is not installed, install it.
if active_commit != patch_commit:
LOG.info("Active Commit:%s does not match Patch Commit %s", active_commit, patch_commit)
self.changes = True
LOG.info("Patch state query returns %s", self.changes)
LOG.info("Installed: %s", self.installed)
LOG.info("To install: %s", self.to_install)
LOG.info("To remove: %s", self.to_remove)
LOG.info("Missing: %s", self.missing_pkgs)
if len(self.duplicated_pkgs) > 0:
LOG.info("Duplicated: %s", self.duplicated_pkgs)
if active_checksum != patch_checksum:
LOG.info("Active Checksum:%s does not match Patch Checksum%s", active_checksum, patch_checksum)
self.changes = True
return True

View File

@@ -765,6 +765,7 @@ class PatchController(PatchService):
if not self.hosts[ip].out_of_date:
continue
# todo(jcasteli): the patch contents checks can be revisited
for pkg in list(self.hosts[ip].installed):
for patch_id in list(self.patch_data.contents):
@@ -801,7 +802,7 @@ class PatchController(PatchService):
if self.patch_data.metadata[patch_id].get("reboot_required") != "N":
self.allow_insvc_patching = False
continue
# todo(jcasteli): patching no longer needs to verify personality
if self.hosts[ip].sw_version == "14.10":
# For Release 1
personality = "personality-%s" % self.hosts[ip].nodetype