From fc1ba31b427157b22dd84e022e36b9cb6a5e093e Mon Sep 17 00:00:00 2001 From: Craig Vyvial Date: Wed, 2 Jul 2014 03:08:51 -0500 Subject: [PATCH] guestagent contract for packages should be a list the guestagent contract on the prepare call sends the packages to install as a long space delimited string and this should be a list. The other parameters are lists like users and databases. The packages should be a list as well. Closes-Bug: #1341966 Change-Id: I05233bfce6d4b81351b797a30d3a55313edf277e --- trove/guestagent/api.py | 1 + trove/guestagent/pkg.py | 10 +++++----- trove/tests/unittests/guestagent/test_pkg.py | 12 ++++++------ 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/trove/guestagent/api.py b/trove/guestagent/api.py index 8b82079444..feb17df771 100644 --- a/trove/guestagent/api.py +++ b/trove/guestagent/api.py @@ -230,6 +230,7 @@ class API(proxy.RpcProxy): as a database container optionally includes a backup id for restores """ LOG.debug("Sending the call to prepare the Guest") + packages = packages.split() self._cast_with_consumer( "prepare", packages=packages, databases=databases, memory_mb=memory_mb, users=users, device_path=device_path, diff --git a/trove/guestagent/pkg.py b/trove/guestagent/pkg.py index 846dc8b24c..53040d7da7 100644 --- a/trove/guestagent/pkg.py +++ b/trove/guestagent/pkg.py @@ -178,11 +178,11 @@ class RedhatPackagerMixin(BasePackagerMixin): raise PkgPackageStateError("Cannot install packages.") def pkg_is_installed(self, packages): - pkg_list = packages.split() + packages = packages if isinstance(packages, list) else packages.split() cmd = "rpm -qa" p = commands.getstatusoutput(cmd) std_out = p[1] - for pkg in pkg_list: + for pkg in packages: found = False for line in std_out.split("\n"): if line.find(pkg) != -1: @@ -271,7 +271,7 @@ class DebianPackagerMixin(BasePackagerMixin): cmd = "sudo -E DEBIAN_FRONTEND=noninteractive apt-get -y " \ "--force-yes --allow-unauthenticated -o " \ "DPkg::options::=--force-confmiss --reinstall " \ - "install %s" % packages + "install %s" % " ".join(packages) output_expects = ['.*password*', 'E: Unable to locate package (.*)', "Couldn't find package (.*)", @@ -361,8 +361,8 @@ class DebianPackagerMixin(BasePackagerMixin): return version def pkg_is_installed(self, packages): - pkg_list = packages.split() - for pkg in pkg_list: + packages = packages if isinstance(packages, list) else packages.split() + for pkg in packages: m = re.match('(.+)=(.+)', pkg) if m: package_name = m.group(1) diff --git a/trove/tests/unittests/guestagent/test_pkg.py b/trove/tests/unittests/guestagent/test_pkg.py index 1bfe75cdf4..0bce04c2be 100644 --- a/trove/tests/unittests/guestagent/test_pkg.py +++ b/trove/tests/unittests/guestagent/test_pkg.py @@ -52,16 +52,16 @@ class PkgDEBInstallTestCase(testtools.TestCase): self.pkg._fix_package_selections = self.pkg_fix_package_selections def test_pkg_is_instaled_no_packages(self): - packages = "" + packages = [] self.assertTrue(self.pkg.pkg_is_installed(packages)) def test_pkg_is_instaled_yes(self): - packages = "package1=1.0 package2" + packages = ["package1=1.0", "package2"] self.pkg.pkg_version = MagicMock(side_effect=["1.0", "2.0"]) self.assertTrue(self.pkg.pkg_is_installed(packages)) def test_pkg_is_instaled_no(self): - packages = "package1=1.0 package2 package3=3.1" + packages = ["package1=1.0", "package2", "package3=3.1"] self.pkg.pkg_version = MagicMock(side_effect=["1.0", "2.0", "3.0"]) self.assertFalse(self.pkg.pkg_is_installed(packages)) @@ -302,17 +302,17 @@ class PkgRPMInstallTestCase(testtools.TestCase): pexpect.spawn.close = self.pexpect_spawn_closed def test_pkg_is_instaled_no_packages(self): - packages = "" + packages = [] self.assertTrue(self.pkg.pkg_is_installed(packages)) def test_pkg_is_instaled_yes(self): - packages = "package1=1.0 package2" + packages = ["package1=1.0", "package2"] commands.getstatusoutput = MagicMock(return_value={1: "package1=1.0\n" "package2=2.0"}) self.assertTrue(self.pkg.pkg_is_installed(packages)) def test_pkg_is_instaled_no(self): - packages = "package1=1.0 package2 package3=3.0" + packages = ["package1=1.0", "package2", "package3=3.0"] commands.getstatusoutput = MagicMock(return_value={1: "package1=1.0\n" "package2=2.0"}) self.assertFalse(self.pkg.pkg_is_installed(packages))