From 7cb54c8cc6d39b925a06d6fa6f4d0675da94587142d6df8288bfbbf0f9cf9464 Mon Sep 17 00:00:00 2001
From: Robert Schweikert <rjschwei@suse.com>
Date: Fri, 3 Feb 2023 22:04:01 +0000
Subject: [PATCH] - Add cloud-init-transact-up.patch to support
 transactional-updates

OBS-URL: https://build.opensuse.org/package/show/Cloud:Tools/cloud-init?expand=0&rev=201
---
 cloud-init-transact-up.patch | 65 ++++++++++++++++++++++++++++++++++++
 cloud-init.changes           |  5 +++
 cloud-init.spec              |  5 ++-
 3 files changed, 74 insertions(+), 1 deletion(-)
 create mode 100644 cloud-init-transact-up.patch

diff --git a/cloud-init-transact-up.patch b/cloud-init-transact-up.patch
new file mode 100644
index 0000000..f435124
--- /dev/null
+++ b/cloud-init-transact-up.patch
@@ -0,0 +1,65 @@
+--- cloudinit/distros/opensuse.py.orig
++++ cloudinit/distros/opensuse.py
+@@ -9,6 +9,7 @@
+ # This file is part of cloud-init. See LICENSE file for license information.
+ 
+ import logging
++import os
+ 
+ from cloudinit import distros, helpers, subp, util
+ from cloudinit.distros import rhel_util as rhutil
+@@ -49,6 +50,7 @@ class Distro(distros.Distro):
+         distros.Distro.__init__(self, name, cfg, paths)
+         self._runner = helpers.Runners(paths)
+         self.osfamily = "suse"
++        self.update_method = None
+         cfg["ssh_svcname"] = "sshd"
+         if self.uses_systemd():
+             self.init_cmd = ["systemctl"]
+@@ -74,12 +76,45 @@ class Distro(distros.Distro):
+         if pkgs is None:
+             pkgs = []
+ 
++        if self.update_method == None:
++            result = util.get_mount_info("/")
++            fs_type = ""
++            if result:
++                (devpth, fs_type, mount_point) = result
++                if (
++                        fs_type.lower() == 'btrfs' and
++                        os.path.exists("/usr/sbin/transactional-update")
++                ):
++                    self.update_method = 'transactional'
++                else:
++                    self.update_method = 'zypper' 
++            else:
++                LOG.info(
++                    "Could not determine filesystem type of '/' using zypper"
++                )
++                self.update_method = 'zypper'
++
+         # No user interaction possible, enable non-interactive mode
+-        cmd = ["zypper", "--non-interactive"]
++        if self.update_method == 'zypper':
++            cmd = ["zypper", "--non-interactive"]
++        else:
++            cmd = [
++                "transactional-update",
++                "--non-interactive",
++                "--drop-if-no-change",
++                "pkg"
++            ]
+ 
+         # Command is the operation, such as install
+         if command == "upgrade":
+             command = "update"
++            if self.update_method == 'transactional' and not pkgs:
++                command = "up"
++                cmd = [
++                    "transactional-update",
++                    "--non-interactive",
++                    "--drop-if-no-change"
++                ]
+         cmd.append(command)
+ 
+         # args are the arguments to the command, not global options
diff --git a/cloud-init.changes b/cloud-init.changes
index 6586d63..9e66cef 100644
--- a/cloud-init.changes
+++ b/cloud-init.changes
@@ -1,3 +1,8 @@
+-------------------------------------------------------------------
+Fri Feb  3 22:02:32 UTC 2023 - Robert Schweikert <rjschwei@suse.com>
+
+- Add cloud-init-transact-up.patch to support transactional-updates
+
 -------------------------------------------------------------------
 Tue Jan 31 19:47:23 UTC 2023 - Robert Schweikert <rjschwei@suse.com>
 
diff --git a/cloud-init.spec b/cloud-init.spec
index 83a8030..7c53e9d 100644
--- a/cloud-init.spec
+++ b/cloud-init.spec
@@ -1,7 +1,7 @@
 #
 # spec file for package cloud-init
 #
-# Copyright (c) 2021 SUSE LINUX Products GmbH, Nuernberg, Germany.
+# Copyright (c) 2023 SUSE LINUX Products GmbH, Nuernberg, Germany.
 #
 # All modifications and additions to the file contributed by third parties
 # remain the property of their copyright owners, unless otherwise agreed
@@ -43,6 +43,8 @@ Patch7:        cloud-init-micro-is-suse.patch
 Patch8:        cloud-init-suse-afternm.patch
 # FIXME: https://github.com/canonical/cloud-init/pull/1435
 Patch9:        cloud-init-prefer-nm.patch
+# FIXME:
+Patch10:       cloud-init-transact-up.patch
 BuildRequires:  fdupes
 BuildRequires:  filesystem
 # pkg-config is needed to find correct systemd unit dir
@@ -152,6 +154,7 @@ Documentation and examples for cloud-init tools
 %patch7
 %patch8
 %patch9
+%patch10
 
 
 # patch in the full version to version.py