File 0002-Add-ZypperPackagerMixin-to-guestagent.patch of Package openstack-trove-doc

From 97bc56cdad3527340c1d5ff3a8997ebea2c3d81d Mon Sep 17 00:00:00 2001
From: Thomas Bechtold <tbechtold@suse.com>
Date: Tue, 6 Sep 2016 16:23:44 +0200
Subject: [PATCH 2/2] Add ZypperPackagerMixin to guestagent

SUSE uses zypper as package manager. zypper is also based on RPM so
reuse the RPMPackagerMixin for zypper.

Change-Id: Iafc5589860cdbb2575d080197b86e548a63fc23d
---
 trove/guestagent/pkg.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

Index: trove-7.0.0.0b3.dev89/trove/guestagent/pkg.py
===================================================================
--- trove-7.0.0.0b3.dev89.orig/trove/guestagent/pkg.py
+++ trove-7.0.0.0b3.dev89/trove/guestagent/pkg.py
@@ -255,6 +255,49 @@ class RedhatPackagerMixin(RPMPackagerMix
         return OK
 
 
+class ZypperPackagerMixin(RPMPackagerMixin):
+    def _install(self, packages, time_out):
+        """Attempts to install packages.
+
+        Returns OK if the packages are installed or a result code if a
+        recoverable-error occurred.
+        Raises an exception if a non-recoverable error or timeout occurs.
+
+        """
+        cmd = "sudo zypper --quiet --non-interactive --no-gpg-checks " \
+              "--auto-agree-with-licenses install %s" % " ".join(packages)
+        output_expects = [
+            '\[sudo\] password for .*:',
+            'No provider of (.*) found.'
+        ]
+        LOG.debug("Running package install command: %s" % cmd)
+        i, match = self.pexpect_run(cmd, output_expects, time_out)
+        if i == 0:
+            raise PkgPermissionError("Invalid permissions.")
+        elif i == 1:
+            raise PkgNotFoundError("Could not find pkg %s" % match.group(1))
+        return OK
+
+    def _remove(self, package_name, time_out):
+        """Removes a package.
+
+        Returns OK if the package is removed successfully or a result code if a
+        recoverable-error occurs.
+        Raises an exception if a non-recoverable error or timeout occurs.
+
+        """
+        cmd = "sudo zypper --quiet --non-interactive --no-gpg-checks " \
+              "rm %s" % package_name
+        LOG.debug("Running package remove command: %s" % cmd)
+        output_expects = [
+            '\[sudo\] password for .*:'
+        ]
+        i, match = self.pexpect_run(cmd, output_expects, time_out)
+        if i == 0:
+            raise PkgPermissionError("Invalid permissions.")
+        return OK
+
+
 class DebianPackagerMixin(BasePackagerMixin):
 
     def _fix(self, time_out):
@@ -440,6 +483,9 @@ class DebianPackagerMixin(BasePackagerMi
 if operating_system.get_os() == operating_system.REDHAT:
     class Package(RedhatPackagerMixin):
         pass
+elif operating_system.get_os() == operating_system.SUSE:
+    class Package(ZypperPackagerMixin):
+        pass
 else:
     class Package(DebianPackagerMixin):
         pass
openSUSE Build Service is sponsored by