neil / rpms / anaconda

Forked from rpms/anaconda a year ago
Clone
629de0
From c72f979499f5af3091ad8f2017442b3728cdff2f Mon Sep 17 00:00:00 2001
629de0
From: Colin Walters <walters@verbum.org>
629de0
Date: Tue, 16 Jun 2015 11:24:20 -0400
629de0
Subject: [PATCH] Rebase
629de0
629de0
---
629de0
 pyanaconda/packaging/rpmostreepayload.py | 67 ++++++++++++++++++++------------
629de0
 1 file changed, 43 insertions(+), 24 deletions(-)
629de0
629de0
diff --git a/pyanaconda/packaging/rpmostreepayload.py b/pyanaconda/packaging/rpmostreepayload.py
629de0
index 5eacd9f..f979c3e 100644
629de0
--- a/pyanaconda/packaging/rpmostreepayload.py
629de0
+++ b/pyanaconda/packaging/rpmostreepayload.py
629de0
@@ -138,24 +138,25 @@ class RPMOSTreePayload(ArchivePayload):
629de0
             ["admin", "--sysroot=" + iutil.getTargetPhysicalRoot(),
629de0
              "init-fs", iutil.getTargetPhysicalRoot()])
629de0
 
629de0
-        repo_arg = "--repo=" + iutil.getTargetPhysicalRoot() + '/ostree/repo'
629de0
+        self._sysroot_path = Gio.File.new_for_path(iutil.getTargetPhysicalRoot())
629de0
+        sysroot = OSTree.Sysroot.new(self._sysroot_path)
629de0
+        sysroot.load(cancellable)
629de0
+        repo = sysroot.get_repo(None)[1]
629de0
+        # We don't support resuming from interrupted installs
629de0
+        repo.set_disable_fsync(True)
629de0
 
629de0
-        # Store this for use in postInstall too, where we need to
629de0
-        # undo/redo this step.
629de0
-        self._base_remote_args = ["remote", "add"]
629de0
+        self._remoteOptions = {}
629de0
+
629de0
+        # Handle variations in pykickstart
629de0
         if ((hasattr(ostreesetup, 'noGpg') and ostreesetup.noGpg) or
629de0
             (hasattr(ostreesetup, 'nogpg') and ostreesetup.nogpg)):
629de0
-            self._base_remote_args.append("--set=gpg-verify=false")
629de0
-        self._base_remote_args.extend([ostreesetup.remote,
629de0
-                                     ostreesetup.url])
629de0
-        self._safeExecWithRedirect("ostree", [repo_arg] + self._base_remote_args)
629de0
+            self._remoteOptions['gpg-verify'] = GLib.Variant('b', False)
629de0
 
629de0
-        self._sysroot_path = sysroot_path = Gio.File.new_for_path(iutil.getTargetPhysicalRoot())
629de0
-        sysroot = OSTree.Sysroot.new(sysroot_path)
629de0
-        sysroot.load(cancellable)
629de0
+        repo.remote_change(None, OSTree.RepoRemoteChange.ADD_IF_NOT_EXISTS,
629de0
+                           ostreesetup.remote, ostreesetup.url,
629de0
+                           GLib.Variant('a{sv}', self._remoteOptions),
629de0
+                           cancellable)
629de0
 
629de0
-        repo = sysroot.get_repo(None)[1]
629de0
-        repo.set_disable_fsync(True)
629de0
         progressQ.send_message(_("Starting pull of %(branchName)s from %(source)s") % \
629de0
                                {"branchName": ostreesetup.ref, "source": ostreesetup.remote})
629de0
 
629de0
@@ -174,6 +175,14 @@ class RPMOSTreePayload(ArchivePayload):
629de0
 
629de0
         progressQ.send_message(_("Preparing deployment of %s") % (ostreesetup.ref, ))
629de0
 
629de0
+        # Now that we have the data pulled, delete the remote for now.
629de0
+        # This will allow a remote configuration defined in the tree
629de0
+        # (if any) to override what's in the kickstart.  Otherwise,
629de0
+        # we'll re-add it in post.  Ideally, ostree would support a
629de0
+        # pull without adding a remote, but that would get quite
629de0
+        # complex.
629de0
+        repo.remote_delete(self.data.ostreesetup.remote, None)
629de0
+
629de0
         self._safeExecWithRedirect("ostree",
629de0
             ["admin", "--sysroot=" + iutil.getTargetPhysicalRoot(),
629de0
              "os-init", ostreesetup.osname])
629de0
@@ -250,24 +259,34 @@ class RPMOSTreePayload(ArchivePayload):
629de0
 
629de0
     def postInstall(self):
629de0
         super(RPMOSTreePayload, self).postInstall()
629de0
-
629de0
+        
629de0
         from gi.repository import OSTree
629de0
         cancellable = None
629de0
 
629de0
-        # Reload this data - we couldn't keep it open across
629de0
-        # the remounts happening.
629de0
         sysroot = OSTree.Sysroot.new(self._sysroot_path)
629de0
         sysroot.load(cancellable)
629de0
         repo = sysroot.get_repo(None)[1]
629de0
 
629de0
-        # This is an ugly hack - we didn't have /etc/ostree/remotes.d,
629de0
-        # so the remote went into /ostree/repo/config.  But we want it
629de0
-        # in /etc, so delete that remote, then re-add it to
629de0
-        # /etc/ostree/remotes.d, executing ostree inside the sysroot
629de0
-        # so that it understands it's a "system repository" and should
629de0
-        # modify /etc.
629de0
-        repo.remote_delete(self.data.ostreesetup.remote, None)
629de0
-        self._safeExecWithRedirect("ostree", self._base_remote_args, root=iutil.getSysroot())
629de0
+        # CentOS specific patch (for now) - pull the remote config from usr/etc if it exists.
629de0
+        # The OSTree handling here was buggy in that it wasn't looking in the sysroot
629de0
+        # for existing remotes.
629de0
+        default_remote_path = iutil.getSysroot() + '/usr/etc/ostree/remotes.d/' + self.data.ostreesetup.osname + '.conf'
629de0
+        if os.path.isfile(default_remote_path):
629de0
+            destpath = iutil.getSysroot() + '/etc/ostree/remotes.d/' + os.path.basename(default_remote_path)
629de0
+            self._safeExecWithRedirect('cp', ['-r', '-p', default_remote_path, destpath])
629de0
+        else:
629de0
+            # Following up on the "remote delete" above, we removed the
629de0
+            # remote from /ostree/repo/config.  But we want it in /etc, so
629de0
+            # re-add it to /etc/ostree/remotes.d, using the sysroot path.
629de0
+            #
629de0
+            # However, we ignore the case where the remote already exists,
629de0
+            # which occurs when the content itself provides the remote
629de0
+            # config file.
629de0
+            repo.remote_change(Gio.File.new_for_path(iutil.getSysroot()),
629de0
+                               OSTree.RepoRemoteChange.ADD_IF_NOT_EXISTS,
629de0
+                               self.data.ostreesetup.remote, self.data.ostreesetup.url,
629de0
+                               GLib.Variant('a{sv}', self._remoteOptions),
629de0
+                               cancellable)
629de0
 
629de0
         boot = iutil.getSysroot() + '/boot'
629de0
 
629de0
-- 
629de0
1.8.3.1
629de0