-
Notifications
You must be signed in to change notification settings - Fork 4
/
test-all-puppet.py
executable file
·48 lines (40 loc) · 1.79 KB
/
test-all-puppet.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#! /usr/bin/python3.5
import concurrent.futures
import subprocess
import sys
import time
def test_puppet(host):
start = time.time()
ret = subprocess.run('sudo -H FACTER_fqdn="{0}.dtg.cl.cam.ac.uk" FACTER_hostname="{0}" '
'puppet apply --noop --modulepath=modules --node_name_value={0}.dtg.cl.cam.ac.uk '
'manifests/nodes/'.format(host),
shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
return host, ret, time.time() - start
dig = subprocess.run("dig -t AXFR cl.cam.ac.uk @dns0.cl.cam.ac.uk | "
"grep .dtg.cl.cam.ac.uk | "
"tr -s ' \t' ' ' | "
"egrep '(CNAME)|(A)|(AAAA)' | "
"grep -v RRSIG | "
"grep -v rscfl-vguest | "
"cut -f 1,5 -d ' ' | "
"tr ' ' '\n' | "
"sort | "
"uniq | "
"grep -v '[0-9][0-9][0-9]' | "
"grep -v puppy | "
"grep -v so-22 | "
"grep -v -- '-bmc' | "
"grep dtg.cl.cam.ac.uk | "
"cut -d '.' -f 1",
shell=True, stdout=subprocess.PIPE, check=True)
hosts = dig.stdout.decode("UTF-8").strip().split("\n")
exit_code = 0
with concurrent.futures.ThreadPoolExecutor(max_workers=6) as ex:
for ftr in concurrent.futures.as_completed([ex.submit(test_puppet, host) for host in hosts]):
name, res, elapsed = ftr.result()
if res.returncode != 0:
exit_code = 1
print(res.stdout.decode("UTF-8"))
print("test-puppet ran as {} for {:.1f}s with rc={}".format(name, elapsed, res.returncode))
sys.stdout.flush()
sys.exit(exit_code)