I’m slowly rewriting a script that installs a war file for a UI. I haven’t worked on it in probably a year and have been needed to fix some of the script so it doesn’t turn into a mess.
Before it was a few if statements to check for a kernel version and distro version, which worked just fine. I’m trying to clean it up so I can just look at a list and pull the distro/kernel from stdout. If anyone can point out where my stupidity is you’ll save me a ton of time and help clear out whatever garbage clogging up my thinker.
distro_type = [
('CentOS release 6'),
('CentOS Linux release 7.5.1804 (Core) '),
('CentOS Linux release 7.5.1804'),
]
kernel_version = [
("2.6.32-573.el6.x86_64"),
("4.18.7-1.el7.x86_64"),
("4.18.7-1.1.el7.centos.x86_64"),
]
class LinuxValidator(AbstractValidator):
def validate(self):
print("Validating Linux Configuration....")
validate_distro()
validate_kernel()
def validate_distro():
print("validating distro..")
result = executor.run(["cat", "/etc/issue"])
local_ver = result.stdout
print (local_ver)
if local_ver not in distro_type :
result = executor.run(["cat", "/etc/centos-release"])
local_ver = result.stdout
print (local_ver)
if local_ver not in distro_type :
raise error.LiqidLinuxConfigurationError("Invalid Linux distribution!")
def validate_kernel():
print("validating kernel..")
result = executor.run(["uname", "-r"])
local_ver = result.stdout
if local_ver not in kernel_version:
raise error.LiqidLinuxConfigurationError("Invalid kernel version!")
This dumps out
[root@ackbar ~]# python3.6 /scripts/install/devops/updateprops.py
Validating Linux Configuration....
validating distro..
\S
Kernel \r on an \m
CentOS Linux release 7.5.1804 (Core)
Traceback (most recent call last):
File "/scripts/install/devops/updateprops.py", line 19, in <module>
execute_validator(LinuxValidator())
File "/scripts/install/devops/updateprops.py", line 12, in execute_validator
validator.validate()
File "/scripts/install/devops/validator/LinuxValidator.py", line 22, in validate
validate_distro()
File "/scripts/install/devops/validator/LinuxValidator.py", line 35, in validate_distro
raise error.LinuxConfigurationError("Invalid Linux distribution!")
validator.error.LinuxConfigurationError: Invalid Linux distribution!
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/scripts/install/devops/updateprops.py", line 21, in <module>
raise error.LinuxConfigurationError(str(e))
validator.error.LinuxConfigurationError: Invalid Linux distribution!
[mark@ackbar ~]#
oh I was saving result.stdout to local_ver because I thought it may be barfing on the string dumped out from the executor.runs