def test_beacon(run_beacon): nodes = [] count = 0 while not nodes and count < 5: nodes = get_nodes_from_beacons(multicast_port=MULTICAST_PORT) count += 1 assert len(nodes) == 1 assert nodes[0]['job_slots'] == run_beacon[0] assert nodes[0]['port'] == run_beacon[1] assert nodes[0]['hostname'] == socket.getfqdn() assert nodes[0]['address'] in (x[4][0] for x in socket.getaddrinfo( family=socket.AF_INET, host='', port=0))
def __call__(self): def get_node_info(node): node_id = '{}:{}'.format(node['hostname'], node['port']) node_info = self.all_node_infos.get(node_id) if not node_info: node_info = self.all_node_infos[node_id] = NodeInfo(node) return node_info nodes = [get_node_info(node) for node in get_nodes_from_beacons()] nodes_disappeared = [] for old_node in self.current_working_set: if old_node not in nodes: if self.current_working_set[old_node] > self.allowed_missed_replies: nodes_disappeared.append(old_node) else: self.current_working_set[old_node] += 1 for node in nodes_disappeared: del self.current_working_set[old_node] for node in nodes: self.current_working_set[node] = 0 return self.current_working_set.keys()
import sys import subprocess from tempfile import mkstemp import signal import socket import time import statistics from pprint import pprint from buildpal.common.beacon import get_nodes_from_beacons from buildpal.common import msg_to_bytes repetitions = 1 if len(sys.argv) < 2 else int(sys.argv[1]) nodes = get_nodes_from_beacons() if not nodes: raise Exception("No nodes detected.") ini_handle, ini_file = mkstemp(suffix='.ini') with os.fdopen(ini_handle, 'wt') as ini: ini.write('[distributed]\n') for index, node in enumerate(nodes): ini.write('node[{}]={}:{}:{}\n'.format(index, node['address'], node['port'], node['job_slots'])) def reset_nodes(): for node in nodes: with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock: sock.connect((node['address'], node['port'])) for buffer in msg_to_bytes([b'RESET']):