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