Pull from a remote repo during host install
During the host-install step, the sysroot repo pulls from the remote defined inside /sysroot/ostree/repo/config file. This is a better approach than doing pull-local and it allows the sysroot repo to be a mirror of the feed repo. Test: Running host-install after sw-patch remove <PATCH-ID> should get rid of the commits associated with the patch in the sysroot repo. Story: 2009969 Task: 45435 Depends-On: https://review.opendev.org/c/starlingx/metal/+/842568 Signed-off-by: Jessica Castelino <jessica.castelino@windriver.com> Change-Id: If3e7db2a47f085bbc4abd59eb34565261e30c061
This commit is contained in:
parent
6b13d7e539
commit
d5e5c8453c
|
@ -43,6 +43,7 @@ CLI_OPT_RECURSIVE = '--recursive'
|
||||||
CLI_OPT_RELEASE = '--release'
|
CLI_OPT_RELEASE = '--release'
|
||||||
|
|
||||||
OSTREE_REF = "starlingx"
|
OSTREE_REF = "starlingx"
|
||||||
|
OSTREE_REMOTE = "debian"
|
||||||
FEED_OSTREE_BASE_DIR = "/var/www/pages/feed"
|
FEED_OSTREE_BASE_DIR = "/var/www/pages/feed"
|
||||||
SYSROOT_OSTREE = "/sysroot/ostree/repo"
|
SYSROOT_OSTREE = "/sysroot/ostree/repo"
|
||||||
|
|
||||||
|
|
|
@ -159,6 +159,23 @@ def reset_ostree_repo_head(commit, repo_path):
|
||||||
raise OSTreeCommandFail(msg)
|
raise OSTreeCommandFail(msg)
|
||||||
|
|
||||||
|
|
||||||
|
def pull_ostree_from_remote():
|
||||||
|
"""
|
||||||
|
Pull from remote ostree to sysroot ostree
|
||||||
|
"""
|
||||||
|
|
||||||
|
cmd = "ostree pull %s --depth=-1" % constants.OSTREE_REMOTE
|
||||||
|
|
||||||
|
try:
|
||||||
|
subprocess.run(cmd, shell=True, check=True, capture_output=True)
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
msg = "Failed to pull from %s remote into sysroot ostree" % constants.OSTREE_REMOTE
|
||||||
|
info_msg = "OSTree Pull Error: return code: %s , Output: %s" \
|
||||||
|
% (e.returncode, e.stderr.decode("utf-8"))
|
||||||
|
LOG.info(info_msg)
|
||||||
|
raise OSTreeCommandFail(msg)
|
||||||
|
|
||||||
|
|
||||||
def delete_ostree_repo_commit(commit, repo_path):
|
def delete_ostree_repo_commit(commit, repo_path):
|
||||||
"""
|
"""
|
||||||
Delete the specified commit from the ostree repo
|
Delete the specified commit from the ostree repo
|
||||||
|
@ -177,3 +194,19 @@ def delete_ostree_repo_commit(commit, repo_path):
|
||||||
% (e.returncode, e.stderr.decode("utf-8"))
|
% (e.returncode, e.stderr.decode("utf-8"))
|
||||||
LOG.info(info_msg)
|
LOG.info(info_msg)
|
||||||
raise OSTreeCommandFail(msg)
|
raise OSTreeCommandFail(msg)
|
||||||
|
|
||||||
|
|
||||||
|
def create_deployment():
|
||||||
|
"""
|
||||||
|
Create a new deployment while retaining the previous ones
|
||||||
|
"""
|
||||||
|
|
||||||
|
cmd = "ostree admin deploy %s --no-prune --retain" % constants.OSTREE_REF
|
||||||
|
try:
|
||||||
|
subprocess.run(cmd, shell=True, check=True, capture_output=True)
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
msg = "Failed to create an ostree deployment for sysroot ref %s." % constants.OSTREE_REF
|
||||||
|
info_msg = "OSTree Deployment Error: return code: %s , Output: %s" \
|
||||||
|
% (e.returncode, e.stderr.decode("utf-8"))
|
||||||
|
LOG.info(info_msg)
|
||||||
|
raise OSTreeCommandFail(msg)
|
||||||
|
|
|
@ -20,6 +20,7 @@ from cgcs_patch.patch_functions import configure_logging
|
||||||
from cgcs_patch.patch_functions import LOG
|
from cgcs_patch.patch_functions import LOG
|
||||||
import cgcs_patch.config as cfg
|
import cgcs_patch.config as cfg
|
||||||
from cgcs_patch.base import PatchService
|
from cgcs_patch.base import PatchService
|
||||||
|
from cgcs_patch.exceptions import OSTreeCommandFail
|
||||||
import cgcs_patch.utils as utils
|
import cgcs_patch.utils as utils
|
||||||
import cgcs_patch.messages as messages
|
import cgcs_patch.messages as messages
|
||||||
import cgcs_patch.constants as constants
|
import cgcs_patch.constants as constants
|
||||||
|
@ -360,15 +361,6 @@ class PatchAgent(PatchService):
|
||||||
"active controller's Feed Repo Commit: %s",
|
"active controller's Feed Repo Commit: %s",
|
||||||
active_sysroot_commit, self.latest_feed_commit)
|
active_sysroot_commit, self.latest_feed_commit)
|
||||||
self.changes = True
|
self.changes = True
|
||||||
active_deployment_commit = ostree_utils.get_latest_deployment_commit()
|
|
||||||
# strip off anything after a period. ex: 1234.1 becomes 1234
|
|
||||||
active_deployment_commit = active_deployment_commit.split(".")[0]
|
|
||||||
|
|
||||||
if active_sysroot_commit != active_deployment_commit:
|
|
||||||
LOG.info("Active Sysroot Commit:%s does not match "
|
|
||||||
"Active Deployment Commit: %s",
|
|
||||||
active_sysroot_commit, active_deployment_commit)
|
|
||||||
self.changes = True
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -427,27 +419,21 @@ class PatchAgent(PatchService):
|
||||||
changed = False
|
changed = False
|
||||||
success = True
|
success = True
|
||||||
|
|
||||||
sysroot_ostree = constants.SYSROOT_OSTREE
|
|
||||||
feed_ostree = "%s/rel-%s/ostree_repo" % (constants.FEED_OSTREE_BASE_DIR, SW_VERSION)
|
|
||||||
if self.changes:
|
if self.changes:
|
||||||
cmd = "ostree --repo=%s pull-local %s %s --depth=-1" % (sysroot_ostree, feed_ostree, constants.OSTREE_REF)
|
|
||||||
try:
|
try:
|
||||||
subprocess.run(cmd, shell=True, check=True, capture_output=True)
|
# Pull changes from remote to the sysroot ostree
|
||||||
except subprocess.CalledProcessError as e:
|
# The remote value is configured inside
|
||||||
LOG.exception("Failed to pull feed ostree in to the sysroot ostree.")
|
# "/sysroot/ostree/repo/config" file
|
||||||
info_msg = "OSTree Pull Local Error: return code: %s , Output: %s" % (e.returncode, e.stderr.decode("utf-8"))
|
ostree_utils.pull_ostree_from_remote()
|
||||||
LOG.info(info_msg)
|
|
||||||
success = False
|
# Create a new deployment once the changes are pulled
|
||||||
|
ostree_utils.create_deployment()
|
||||||
|
|
||||||
# todo(jcasteli): Should we skip the deploy if pull-local fails
|
|
||||||
deployment_cmd = "ostree admin deploy %s" % constants.OSTREE_REF
|
|
||||||
try:
|
|
||||||
subprocess.run(deployment_cmd, shell=True, check=True, capture_output=True)
|
|
||||||
changed = True
|
changed = True
|
||||||
except subprocess.CalledProcessError as e:
|
|
||||||
LOG.exception("Failed to create an ostree deployment.")
|
except OSTreeCommandFail:
|
||||||
info_msg = "OSTree Deployment Error: return code: %s , Output: %s" % (e.returncode, e.stderr.decode("utf-8"))
|
LOG.exception("Failed to pull changes and create deployment"
|
||||||
LOG.info(info_msg)
|
"during host-install.")
|
||||||
success = False
|
success = False
|
||||||
|
|
||||||
if changed:
|
if changed:
|
||||||
|
|
|
@ -470,7 +470,11 @@ class PatchMessageQueryDetailedResp(messages.PatchMessage):
|
||||||
if len(pc.interim_state[patch_id]) == 0:
|
if len(pc.interim_state[patch_id]) == 0:
|
||||||
del pc.interim_state[patch_id]
|
del pc.interim_state[patch_id]
|
||||||
pc.hosts_lock.release()
|
pc.hosts_lock.release()
|
||||||
pc.check_patch_states()
|
# CentOS code has an additional call here for
|
||||||
|
# check_patch_states which was removed in Debian
|
||||||
|
# The call had to be removed since it was mangling
|
||||||
|
# pc.allow_insvc_patching value and making all
|
||||||
|
# patches treat like an in-service patch.
|
||||||
else:
|
else:
|
||||||
pc.hosts_lock.release()
|
pc.hosts_lock.release()
|
||||||
|
|
||||||
|
@ -1101,7 +1105,7 @@ class PatchController(PatchService):
|
||||||
|
|
||||||
# Commit1 in patch metadata.xml file represents the latest commit
|
# Commit1 in patch metadata.xml file represents the latest commit
|
||||||
# after this patch has been applied to the feed repo
|
# after this patch has been applied to the feed repo
|
||||||
self.latest_feed_commit = self.patch_data.contents[patch_id]["commit1"]
|
self.latest_feed_commit = self.patch_data.contents[patch_id]["commit1"]["commit"]
|
||||||
|
|
||||||
self.hosts_lock.acquire()
|
self.hosts_lock.acquire()
|
||||||
self.interim_state[patch_id] = list(self.hosts)
|
self.interim_state[patch_id] = list(self.hosts)
|
||||||
|
|
Loading…
Reference in New Issue