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)

Conflict: (1) not change
cloudinit/config/cc_ubuntu_pro.py,pyproject.toml,tests/unittests/config/test_cc_rsyslog.py
and tests/unittests/config/test_cc_ubuntu_pro.py
(2) change test_handler/test_handler_power_state.py not
config/test_cc_power_state_change.py

---
 cloudinit/config/cc_power_state_change.py                | 5 ++++-
 cloudinit/config/cc_rsyslog.py                           | 5 +----
 tests/unittests/test_handler/test_handler_power_state.py | 2 +-
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/cloudinit/config/cc_power_state_change.py b/cloudinit/config/cc_power_state_change.py
index 5780a7e..9665e9a 100644
--- a/cloudinit/config/cc_power_state_change.py
+++ b/cloudinit/config/cc_power_state_change.py
@@ -78,7 +78,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 dd2bbd0..b27a54c 100644
--- a/cloudinit/config/cc_rsyslog.py
+++ b/cloudinit/config/cc_rsyslog.py
@@ -333,10 +333,7 @@ class SyslogRemotesLine(object):
         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/test_handler/test_handler_power_state.py b/tests/unittests/test_handler/test_handler_power_state.py
index 4ac4942..ed953d0 100644
--- a/tests/unittests/test_handler/test_handler_power_state.py
+++ b/tests/unittests/test_handler/test_handler_power_state.py
@@ -42,7 +42,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)
-- 
2.33.0

