Skip to content

Commit 7840024

Browse files
committed
feat(kc-compat): add --report flag to output system info before status
1 parent 6e26983 commit 7840024

File tree

3 files changed

+69
-2
lines changed

3 files changed

+69
-2
lines changed

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ else if needs_update == False {
7171
Checks if server is running kernel compatible with KernelCare.
7272
Usage:
7373
```bash
74-
python kc-compat.py [--silent|-q]
74+
python kc-compat.py [--silent|-q|--report]
7575
```
7676

7777
Outputs:
@@ -82,6 +82,26 @@ Outputs:
8282
- `SYSTEM ERROR; <error>` for file system issues
8383
- `UNEXPECTED ERROR; <error>` for other errors
8484

85+
### Flags:
86+
- `--silent` or `-q`: Silent mode - no output, only exit codes
87+
- `--report`: Generate system information report for support team
88+
89+
### Report Mode:
90+
When using `--report`, the script outputs detailed system information followed by the compatibility status:
91+
92+
```
93+
=== KernelCare Compatibility Report ===
94+
Kernel Hash: abcdef1234567890abcdef1234567890abcdef12
95+
Distribution: centos
96+
Version: 7
97+
Kernel: Linux version 5.4.0-74-generic (buildd@lcy01-amd64-023) (gcc version 9.3.0)
98+
Environment: Physical/Virtual Machine
99+
=====================================
100+
COMPATIBLE
101+
```
102+
103+
This information can be easily shared with the support team for troubleshooting.
104+
85105
If --silent flag is provided -- doesn't print anything
86106

87107
Exit codes:

kc-compat.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,21 +111,44 @@ def myprint(silent, message):
111111
def main():
112112
"""
113113
if --silent or -q argument provided, don't print anything, just use exit code
114+
if --report provided, show system information for support
114115
otherwise print results (COMPATIBLE or support contact messages)
115116
else exit with 0 if COMPATIBLE, 1 or more otherwise
116117
"""
117118
silent = len(sys.argv) > 1 and (sys.argv[1] == '--silent' or sys.argv[1] == '-q')
119+
report = len(sys.argv) > 1 and sys.argv[1] == '--report'
120+
118121
if inside_vz_container() or inside_lxc_container():
119122
myprint(silent, "UNSUPPORTED; INSIDE CONTAINER")
120123
return 2
124+
125+
# Get system information once for both report and compatibility checking
126+
kernel_hash = get_kernel_hash()
127+
distro_name = get_distro_info()
128+
129+
# Show system information for support if --report flag is used
130+
if report:
131+
print("=== KernelCare Compatibility Report ===")
132+
print(f"Kernel Hash: {kernel_hash}")
133+
print(f"Distribution: {distro_name or 'Unknown'}")
134+
print(f"Version: Not available")
135+
136+
# Get kernel version from /proc/version
137+
try:
138+
with open('/proc/version', 'r') as f:
139+
kernel_version = f.read().strip()
140+
print(f"Kernel: {kernel_version}")
141+
except (IOError, OSError):
142+
print("Kernel: Unable to read /proc/version")
143+
144+
print("=====================================")
121145

122146
try:
123147
if is_compat():
124148
myprint(silent, "COMPATIBLE")
125149
return 0
126150
else:
127151
# Handle 404 case - check if distro is supported
128-
distro_name = get_distro_info()
129152
if distro_name and is_distro_supported(distro_name):
130153
myprint(silent, "NEEDS REVIEW")
131154
myprint(silent, "We support your distribution, but we're having trouble detecting your precise kernel configuration. Please, contact CloudLinux Inc. support by email at [email protected] or by request form at https://www.cloudlinux.com/index.php/support")

test_kc_compat.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,30 @@ def test_main_silent_mode(self, mock_print, mock_compat, mock_lxc, mock_vz):
200200
assert result == 0
201201
mock_print.assert_not_called()
202202

203+
@patch('sys.argv', ['kc-compat.py', '--report'])
204+
@patch.object(kc_compat, 'get_kernel_hash', return_value='abcdef123456')
205+
@patch.object(kc_compat, 'get_distro_info', return_value='centos')
206+
@patch.object(kc_compat, 'inside_vz_container', return_value=False)
207+
@patch.object(kc_compat, 'inside_lxc_container', return_value=False)
208+
@patch.object(kc_compat, 'is_compat', return_value=True)
209+
@patch('builtins.open', new_callable=mock_open, read_data='Linux version 5.4.0-test')
210+
@patch('builtins.print')
211+
def test_main_report_mode(self, mock_print, mock_file, mock_compat, mock_lxc, mock_vz, mock_distro, mock_hash):
212+
result = kc_compat.main()
213+
assert result == 0
214+
# Check that report header and information are printed, followed by COMPATIBLE
215+
expected_calls = [
216+
(("=== KernelCare Compatibility Report ===",),),
217+
(("Kernel Hash: abcdef123456",),),
218+
(("Distribution: centos",),),
219+
(("Version: Not available",),),
220+
(("Kernel: Linux version 5.4.0-test",),),
221+
(("=====================================",),),
222+
(("COMPATIBLE",),)
223+
]
224+
mock_print.assert_has_calls(expected_calls)
225+
226+
203227
@patch('sys.argv', ['kc-compat.py'])
204228
@patch.object(kc_compat, 'inside_vz_container', return_value=False)
205229
@patch.object(kc_compat, 'inside_lxc_container', return_value=False)

0 commit comments

Comments
 (0)