feat: add various infrastructure check and automation scripts
This commit is contained in:
52
scripts/test_container_inside.py
Normal file
52
scripts/test_container_inside.py
Normal file
@@ -0,0 +1,52 @@
|
||||
import paramiko
|
||||
import sys
|
||||
|
||||
sys.stdout.reconfigure(encoding='utf-8')
|
||||
c = paramiko.SSHClient()
|
||||
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
c.connect('140.44.4.74', username='snarf', key_filename=r'C:\Users\Snarf\.ssh\id_ed25519_snarfnet', timeout=10)
|
||||
|
||||
def run(cmd):
|
||||
stdin, stdout, stderr = c.exec_command(cmd)
|
||||
return stdout.read().decode().strip(), stderr.read().decode().strip()
|
||||
|
||||
cid, _ = run("echo 'Katzir476!' | sudo -S docker ps -q -f name=peanut_peanut")
|
||||
|
||||
# Run node script inside container to test reading settings.yml and connecting to NUT server
|
||||
node_test = """
|
||||
const fs = require('fs');
|
||||
const net = require('net');
|
||||
|
||||
console.log('--- Reading /config/settings.yml ---');
|
||||
try {
|
||||
console.log(fs.readFileSync('/config/settings.yml', 'utf8'));
|
||||
} catch (e) {
|
||||
console.log('Error reading settings:', e.message);
|
||||
}
|
||||
|
||||
console.log('--- Testing TCP connection to 14.4.4.44:3493 ---');
|
||||
const sock = new net.Socket();
|
||||
sock.setTimeout(3000);
|
||||
sock.on('connect', () => {
|
||||
console.log('CONNECTED to 14.4.4.44:3493!');
|
||||
sock.write('VER\\n');
|
||||
});
|
||||
sock.on('data', (d) => {
|
||||
console.log('RECV:', d.toString());
|
||||
sock.end();
|
||||
});
|
||||
sock.on('timeout', () => {
|
||||
console.log('TIMEOUT connecting to 14.4.4.44:3493');
|
||||
sock.destroy();
|
||||
});
|
||||
sock.on('error', (e) => {
|
||||
console.log('ERROR:', e.message);
|
||||
});
|
||||
"""
|
||||
|
||||
out, err = run(f"echo 'Katzir476!' | sudo -S docker exec {cid} node -e {repr(node_test)}")
|
||||
print(out)
|
||||
if err: print("ERR:", err)
|
||||
|
||||
c.close()
|
||||
|
||||
Reference in New Issue
Block a user