neil / rpms / anaconda

Forked from rpms/anaconda a year ago
Clone
6e5b62
diff -uNrp anaconda-21.48.22.121.orig/pyanaconda/packaging/rpmostreepayload.py anaconda-21.48.22.121/pyanaconda/packaging/rpmostreepayload.py
6e5b62
--- anaconda-21.48.22.121.orig/pyanaconda/packaging/rpmostreepayload.py	2017-06-21 12:44:34.000000000 +0000
6e5b62
+++ anaconda-21.48.22.121/pyanaconda/packaging/rpmostreepayload.py	2017-08-23 02:28:23.121006339 +0000
6e5b62
@@ -142,24 +142,25 @@ class RPMOSTreePayload(ArchivePayload):
6e5b62
             ["admin", "--sysroot=" + iutil.getTargetPhysicalRoot(),
6e5b62
              "init-fs", iutil.getTargetPhysicalRoot()])
6e5b62
 
6e5b62
-        repo_arg = "--repo=" + iutil.getTargetPhysicalRoot() + '/ostree/repo'
6e5b62
+        self._sysroot_path = Gio.File.new_for_path(iutil.getTargetPhysicalRoot())
6e5b62
+        sysroot = OSTree.Sysroot.new(self._sysroot_path)
6e5b62
+        sysroot.load(cancellable)
6e5b62
+        repo = sysroot.get_repo(None)[1]
6e5b62
+        # We don't support resuming from interrupted installs
6e5b62
+        repo.set_disable_fsync(True)
6e5b62
+
6e5b62
+        self._remoteOptions = {}
6e5b62
 
6e5b62
-        # Store this for use in postInstall too, where we need to
6e5b62
-        # undo/redo this step.
6e5b62
-        self._base_remote_args = ["remote", "add"]
6e5b62
+        # Handle variations in pykickstart
6e5b62
         if ((hasattr(ostreesetup, 'noGpg') and ostreesetup.noGpg) or
6e5b62
             (hasattr(ostreesetup, 'nogpg') and ostreesetup.nogpg)):
6e5b62
-            self._base_remote_args.append("--set=gpg-verify=false")
6e5b62
-        self._base_remote_args.extend([ostreesetup.remote,
6e5b62
-                                     ostreesetup.url])
6e5b62
-        self._safeExecWithRedirect("ostree", [repo_arg] + self._base_remote_args)
6e5b62
+            self._remoteOptions['gpg-verify'] = GLib.Variant('b', False)
6e5b62
 
6e5b62
-        self._sysroot_path = sysroot_path = Gio.File.new_for_path(iutil.getTargetPhysicalRoot())
6e5b62
-        sysroot = OSTree.Sysroot.new(sysroot_path)
6e5b62
-        sysroot.load(cancellable)
6e5b62
+        repo.remote_change(None, OSTree.RepoRemoteChange.ADD_IF_NOT_EXISTS,
6e5b62
+                           ostreesetup.remote, ostreesetup.url,
6e5b62
+                           GLib.Variant('a{sv}', self._remoteOptions),
6e5b62
+                           cancellable)
6e5b62
 
6e5b62
-        repo = sysroot.get_repo(None)[1]
6e5b62
-        repo.set_disable_fsync(True)
6e5b62
         progressQ.send_message(_("Starting pull of %(branchName)s from %(source)s") % \
6e5b62
                                {"branchName": ostreesetup.ref, "source": ostreesetup.remote})
6e5b62
 
6e5b62
@@ -192,6 +193,14 @@ class RPMOSTreePayload(ArchivePayload):
6e5b62
         log.info("ostree pull: " + (progress.get_status() or ""))
6e5b62
         progressQ.send_message(_("Preparing deployment of %s") % (ostreesetup.ref, ))
6e5b62
 
6e5b62
+        # Now that we have the data pulled, delete the remote for now.
6e5b62
+        # This will allow a remote configuration defined in the tree
6e5b62
+        # (if any) to override what's in the kickstart.  Otherwise,
6e5b62
+        # we'll re-add it in post.  Ideally, ostree would support a
6e5b62
+        # pull without adding a remote, but that would get quite
6e5b62
+        # complex.
6e5b62
+        repo.remote_delete(self.data.ostreesetup.remote, None)
6e5b62
+
6e5b62
         self._safeExecWithRedirect("ostree",
6e5b62
             ["admin", "--sysroot=" + iutil.getTargetPhysicalRoot(),
6e5b62
              "os-init", ostreesetup.osname])
6e5b62
@@ -348,20 +357,30 @@ class RPMOSTreePayload(ArchivePayload):
6e5b62
         from gi.repository import OSTree
6e5b62
         cancellable = None
6e5b62
 
6e5b62
-        # Reload this data - we couldn't keep it open across
6e5b62
-        # the remounts happening.
6e5b62
         sysroot = OSTree.Sysroot.new(self._sysroot_path)
6e5b62
         sysroot.load(cancellable)
6e5b62
         repo = sysroot.get_repo(None)[1]
6e5b62
 
6e5b62
-        # This is an ugly hack - we didn't have /etc/ostree/remotes.d,
6e5b62
-        # so the remote went into /ostree/repo/config.  But we want it
6e5b62
-        # in /etc, so delete that remote, then re-add it to
6e5b62
-        # /etc/ostree/remotes.d, executing ostree inside the sysroot
6e5b62
-        # so that it understands it's a "system repository" and should
6e5b62
-        # modify /etc.
6e5b62
-        repo.remote_delete(self.data.ostreesetup.remote, None)
6e5b62
-        self._safeExecWithRedirect("ostree", self._base_remote_args, root=iutil.getSysroot())
6e5b62
+        # CentOS specific patch (for now) - pull the remote config from usr/etc if it exists.
6e5b62
+        # The OSTree handling here was buggy in that it wasn't looking in the sysroot
6e5b62
+        # for existing remotes.
6e5b62
+        default_remote_path = iutil.getSysroot() + '/usr/etc/ostree/remotes.d/' + self.data.ostreesetup.osname + '.conf'
6e5b62
+        if os.path.isfile(default_remote_path):
6e5b62
+            destpath = iutil.getSysroot() + '/etc/ostree/remotes.d/' + os.path.basename(default_remote_path)
6e5b62
+            self._safeExecWithRedirect('cp', ['-r', '-p', default_remote_path, destpath])
6e5b62
+        else:
6e5b62
+            # Following up on the "remote delete" above, we removed the
6e5b62
+            # remote from /ostree/repo/config.  But we want it in /etc, so
6e5b62
+            # re-add it to /etc/ostree/remotes.d, using the sysroot path.
6e5b62
+            #
6e5b62
+            # However, we ignore the case where the remote already exists,
6e5b62
+            # which occurs when the content itself provides the remote
6e5b62
+            # config file.
6e5b62
+            repo.remote_change(Gio.File.new_for_path(iutil.getSysroot()),
6e5b62
+                               OSTree.RepoRemoteChange.ADD_IF_NOT_EXISTS,
6e5b62
+                               self.data.ostreesetup.remote, self.data.ostreesetup.url,
6e5b62
+                               GLib.Variant('a{sv}', self._remoteOptions),
6e5b62
+                               cancellable)
6e5b62
 
6e5b62
         boot = iutil.getSysroot() + '/boot'
6e5b62