blob: 064c8cc0926a3d82f37d1997440c507d25cf0a54 [file] [log] [blame]
From 346f46d882416c45b9c3b12b4da85da2cbd5cdbb Mon Sep 17 00:00:00 2001
From: Sam Kunz <samkunz@google.com>
Date: Thu, 23 Sep 2021 23:35:02 +0000
Subject: [PATCH] [policies] Add package manager for COS.
---
sos/policies/distros/cos.py | 4 +++
sos/policies/package_managers/cos.py | 39 ++++++++++++++++++++++++++++
2 files changed, 43 insertions(+)
create mode 100644 sos/policies/package_managers/cos.py
diff --git a/sos/policies/distros/cos.py b/sos/policies/distros/cos.py
index 7b03b9d9..b17aa444 100644
--- a/sos/policies/distros/cos.py
+++ b/sos/policies/distros/cos.py
@@ -10,6 +10,7 @@
from sos.report.plugins import CosPlugin
from sos.policies.distros import LinuxPolicy
+from sos.policies.package_managers.cos import CosPackageManager
def _blank_or_comment(line):
@@ -42,6 +43,9 @@ class CosPolicy(LinuxPolicy):
probe_runtime=probe_runtime)
self.valid_subclasses += [CosPlugin]
+ self.package_manager = CosPackageManager(chroot=sysroot,
+ remote_exec=remote_exec)
+
@classmethod
def check(cls, remote=''):
if remote:
diff --git a/sos/policies/package_managers/cos.py b/sos/policies/package_managers/cos.py
new file mode 100644
index 00000000..664e77c6
--- /dev/null
+++ b/sos/policies/package_managers/cos.py
@@ -0,0 +1,39 @@
+# This file is part of the sos project: https://github.com/sosreport/sos
+#
+# This copyrighted material is made available to anyone wishing to use,
+# modify, copy, or redistribute it subject to the terms and conditions of
+# version 2 of the GNU General Public License.
+#
+# See the LICENSE file in the source distribution for further information.
+
+import json
+
+from sos.policies.package_managers import PackageManager
+
+
+class CosPackageManager(PackageManager):
+ """Subclass for Container-Optimized OS (COS).
+
+ By design, COS does not have a package manager. However, package
+ information can be aquired by parsing the contents of the file
+ '/etc/cos-package-info.json'.
+ """
+
+ def get_pkg_list(self):
+ """Returns dictionary of packages.
+
+ This COS specific method only returns packages installed on the root
+ file system.
+ """
+ if len(self.packages):
+ return self.packages
+
+ with open("/etc/cos-package-info.json") as f:
+ data = json.load(f)
+ for p in data["installedPackages"]:
+ self.packages[p["name"]] = {
+ "name": p["name"],
+ "version": p['ebuild_version'].split('-')[0],
+ }
+
+ return self.packages
--
2.31.0