Closed BelenValdivia closed 9 months ago
Wazuh_QA_environment Pipelines are not working. It is not being able to run unit tests as expected.
Running:
hm.run_python_script('manager1', '/home/akim/Desktop/query_wdb2.py')
where query_wdb2.py content is:
print("testing script")
Result is:
Traceback (most recent call last):
File "/home/akim/Desktop/trash/test2.py", line 40, in <module>
hm.run_python_script('manager1', '/home/akim/Desktop/query_wdb2.py')
File "/home/akim/Desktop/venvs/qa-system-env/lib/python3.10/site-packages/wazuh_qa_framework/system/host_manager.py", line 730, in run_python_script
raise Exception(f"Error running python script {script} on host {host}: {result}")
Exception: Error running python script /home/akim/Desktop/query_wdb2.py on host manager1: {'changed': True, 'msg': 'non-zero return code', 'rc': 2, 'stderr': 'Shared connection to 172.31.12.21 closed.\r\n', 'stderr_lines': ['Shared connection to 172.31.12.21 closed.'], 'stdout': '/home/qa/.ansible/tmp/ansible-tmp-1688636039.8908288-1528037-268069442189855/query_wdb2.py: line 1: syntax error near unexpected token `"testing script"\'\r\n/home/qa/.ansible/tmp/ansible-tmp-1688636039.8908288-1528037-268069442189855/query_wdb2.py: line 1: `print("testing script")\'\r\n', 'stdout_lines': ['/home/qa/.ansible/tmp/ansible-tmp-1688636039.8908288-1528037-268069442189855/query_wdb2.py: line 1: syntax error near unexpected token `"testing script"\'', '/home/qa/.ansible/tmp/ansible-tmp-1688636039.8908288-1528037-268069442189855/query_wdb2.py: line 1: `print("testing script")\'']}
Same response using different files and hosts
I ran the function on different hosts using a script with the same content as @pro-akim and it works.
Script:
Results:
>>> hm.run_python_script('agent1', '/home/belen/Repositories/qa-system-framework/src/wazuh_qa_framework/system/python_script.py')
{'changed': True, 'rc': 0, 'stderr': 'Shared connection to 172.31.8.115 closed.\r\n', 'stderr_lines': ['Shared connection to 172.31.8.115 closed.'], 'stdout': 'testing script\r\n', 'stdout_lines': ['testing script']}
>>>
>>> hm.run_python_script('manager1', '/home/belen/Repositories/qa-system-framework/src/wazuh_qa_framework/system/python_script.py')
{'changed': True, 'rc': 0, 'stderr': 'Shared connection to 172.31.7.53 closed.\r\n', 'stderr_lines': ['Shared connection to 172.31.7.53 closed.'], 'stdout': 'testing script\r\n', 'stdout_lines': ['testing script']
Also, I've tested it with the script I tested earlier and it works. Script:
#!/usr/bin/env python3
import json
print("testing")
cars = {
"manufacturers": [
"Acura", "Alfa-Romeo", "Aston-Martin", "Audi", "Bentley", "BMW",
"Bugatti", "Buick", "Cadillac", "Chevrolet", "Chrysler", "Citroen",
"Deus Automobiles", "Dodge", "Ferrari", "Fiat", "Ford", "Geely",
"Genesis", "GMC", "Honda", "Hyundai", "Infiniti", "Jaguar", "Jeep",
"Kia", "Koenigsegg", "Lamborghini", "Lancia", "Land Rover", "Lexus",
"Lincoln", "Lotus", "Maserati", "Maybach", "Mazda", "McLaren", "Mercedes",
"Mini", "Mitsubishi", "Nissan", "Opel", "Pagani", "Peugeot", "Pontiac",
"Porsche", "Ram", "Renault", "Rolls-Royce", "Skoda", "Smart", "Subaru",
"Suzuki", "Tesla", "Toyota", "Volkswagen", "Volvo"
]
}
print(json.dumps(cars, indent=4))
Result:
>>> hm.run_python_script('manager1', '/home/belen/Repositories/qa-system-framework/src/wazuh_qa_framework/system/python_script.py')
{'changed': True, 'rc': 0, 'stderr': 'Shared connection to 172.31.7.53 closed.\r\n', 'stderr_lines': ['Shared connection to 172.31.7.53 closed.'], 'stdout': 'testing\r\n{\r\n "manufacturers": [\r\n "Acura",\r\n "Alfa-Romeo",\r\n "Aston-Martin",\r\n "Audi",\r\n "Bentley",\r\n "BMW",\r\n "Bugatti",\r\n "Buick",\r\n "Cadillac",\r\n "Chevrolet",\r\n "Chrysler",\r\n "Citroen",\r\n "Deus Automobiles",\r\n "Dodge",\r\n "Ferrari",\r\n "Fiat",\r\n "Ford",\r\n "Geely",\r\n "Genesis",\r\n "GMC",\r\n "Honda",\r\n "Hyundai",\r\n "Infiniti",\r\n "Jaguar",\r\n "Jeep",\r\n "Kia",\r\n "Koenigsegg",\r\n "Lamborghini",\r\n "Lancia",\r\n "Land Rover",\r\n "Lexus",\r\n "Lincoln",\r\n "Lotus",\r\n "Maserati",\r\n "Maybach",\r\n "Mazda",\r\n "McLaren",\r\n "Mercedes",\r\n "Mini",\r\n "Mitsubishi",\r\n "Nissan",\r\n "Opel",\r\n "Pagani",\r\n "Peugeot",\r\n "Pontiac",\r\n "Porsche",\r\n "Ram",\r\n "Renault",\r\n "Rolls-Royce",\r\n "Skoda",\r\n "Smart",\r\n "Subaru",\r\n "Suzuki",\r\n "Tesla",\r\n "Toyota",\r\n "Volkswagen",\r\n "Volvo"\r\n ]\r\n}\r\n', 'stdout_lines': ['testing', '{', ' "manufacturers": [', ' "Acura",', ' "Alfa-Romeo",', ' "Aston-Martin",', ' "Audi",', ' "Bentley",', ' "BMW",', ' "Bugatti",', ' "Buick",', ' "Cadillac",', ' "Chevrolet",', ' "Chrysler",', ' "Citroen",', ' "Deus Automobiles",', ' "Dodge",', ' "Ferrari",', ' "Fiat",', ' "Ford",', ' "Geely",', ' "Genesis",', ' "GMC",', ' "Honda",', ' "Hyundai",', ' "Infiniti",', ' "Jaguar",', ' "Jeep",', ' "Kia",', ' "Koenigsegg",', ' "Lamborghini",', ' "Lancia",', ' "Land Rover",', ' "Lexus",', ' "Lincoln",', ' "Lotus",', ' "Maserati",', ' "Maybach",', ' "Mazda",', ' "McLaren",', ' "Mercedes",', ' "Mini",', ' "Mitsubishi",', ' "Nissan",', ' "Opel",', ' "Pagani",', ' "Peugeot",', ' "Pontiac",', ' "Porsche",', ' "Ram",', ' "Renault",', ' "Rolls-Royce",', ' "Skoda",', ' "Smart",', ' "Subaru",', ' "Suzuki",', ' "Tesla",', ' "Toyota",', ' "Volkswagen",', ' "Volvo"', ' ]', '}']}
>>>
All checks have passed, and no errors as mentioned in the comment above
Tested in a different virtual environment and it worked.
Description
Add function to run a Python script on a host
Testing
Run:
Windows agent