From 2b7d9636b303ad212d1a446ab59636c5cd75dd4a Mon Sep 17 00:00:00 2001
From: MostafaTarek124eru
 <48182100+MostafaTarek124eru@users.noreply.github.com>
Date: Tue, 11 Feb 2025 00:54:01 +0200
Subject: [PATCH] fix: typing for rsyslog, ubuntu_pro, power_state_change
 (#5985)

Reference:https://github.com/canonical/cloud-init/commit/2b7d9636b303ad212d1a446ab59636c5cd75dd4a
Conflict:not change cloudinit/config/cc_ubuntu_pro.py, pyproject.toml and tests/unittests/config/test_cc_ubuntu_pro.py
---
 cloudinit/config/cc_power_state_change.py            | 5 ++++-
 cloudinit/config/cc_rsyslog.py                       | 5 +----
 tests/unittests/config/test_cc_power_state_change.py | 2 +-
 tests/unittests/config/test_cc_rsyslog.py            | 4 ++--
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/cloudinit/config/cc_power_state_change.py b/cloudinit/config/cc_power_state_change.py
index 72e6634..90534ed 100644
--- a/cloudinit/config/cc_power_state_change.py
+++ b/cloudinit/config/cc_power_state_change.py
@@ -93,7 +93,10 @@ def givecmdline(pid):
             (output, _err) = subp.subp(["procstat", "-c", str(pid)])
             line = output.splitlines()[1]
             m = re.search(r"\d+ (\w|\.|-)+\s+(/\w.+)", line)
-            return m.group(2)
+            if m:
+                return m.group(2)
+            else:
+                return None
         else:
             return util.load_file("/proc/%s/cmdline" % pid)
     except IOError:
diff --git a/cloudinit/config/cc_rsyslog.py b/cloudinit/config/cc_rsyslog.py
index a04595b..0087a16 100644
--- a/cloudinit/config/cc_rsyslog.py
+++ b/cloudinit/config/cc_rsyslog.py
@@ -307,10 +307,7 @@ class SyslogRemotesLine:
         self.proto = proto
 
         self.addr = addr
-        if port:
-            self.port = int(port)
-        else:
-            self.port = None
+        self.port = int(port) if port is not None else None
 
     def validate(self):
         if self.port:
diff --git a/tests/unittests/config/test_cc_power_state_change.py b/tests/unittests/config/test_cc_power_state_change.py
index 8a1886c..ce8d74b 100644
--- a/tests/unittests/config/test_cc_power_state_change.py
+++ b/tests/unittests/config/test_cc_power_state_change.py
@@ -47,7 +47,7 @@ class TestLoadPowerState(t_help.TestCase):
         self.assertRaises(TypeError, psc.load_power_state, cfg, self.dist)
 
     def test_valid_modes(self):
-        cfg = {"power_state": {}}
+        cfg: dict = {"power_state": {}}
         for mode in ("halt", "poweroff", "reboot"):
             cfg["power_state"]["mode"] = mode
             check_lps_ret(psc.load_power_state(cfg, self.dist), mode=mode)
diff --git a/tests/unittests/config/test_cc_rsyslog.py b/tests/unittests/config/test_cc_rsyslog.py
index b69f602..6e67668 100644
--- a/tests/unittests/config/test_cc_rsyslog.py
+++ b/tests/unittests/config/test_cc_rsyslog.py
@@ -340,7 +340,7 @@ class TestInstallRsyslog(TestCase):
             with mock.patch.object(
                 cloud.distro, "install_packages"
             ) as m_install:
-                handle("rsyslog", {"rsyslog": config}, cloud, None)
+                handle("rsyslog", {"rsyslog": config}, cloud, [])
             m_which.assert_called_with(config["check_exe"])
             m_install.assert_called_with(config["packages"])
 
@@ -356,6 +356,6 @@ class TestInstallRsyslog(TestCase):
         m_isbsd.return_value = False
         m_which.return_value = "/usr/sbin/rsyslogd"
         with mock.patch.object(cloud.distro, "install_packages") as m_install:
-            handle("rsyslog", {"rsyslog": config}, cloud, None)
+            handle("rsyslog", {"rsyslog": config}, cloud, [])
         m_which.assert_called_with(config["check_exe"])
         m_install.assert_not_called()
-- 
2.33.0


