def test_thread_group_handles_child_exception(self): try: with context.ThreadGroup() as tg: tg.spawn('raiser1', self._raise_test_exc, 'exc1') except exceptions.ThreadException as te: self.assertIn('exc1', te.message) self.assertIn('raiser1', te.message)
def _await_networks(self, cluster, instances): if not instances: return ips_assigned = set() while len(ips_assigned) != len(instances): if not g.check_cluster_exists(instances[0].node_group.cluster): return for instance in instances: if instance.id not in ips_assigned: if networks.init_instances_ips(instance): ips_assigned.add(instance.id) context.sleep(1) LOG.info("Cluster '%s': all instances have IPs assigned" % cluster.id) ctx = context.ctx() cluster = conductor.cluster_get(ctx, instances[0].node_group.cluster) instances = g.get_instances(cluster, ips_assigned) with context.ThreadGroup() as tg: for instance in instances: tg.spawn("wait-for-ssh-%s" % instance.instance_name, self._wait_until_accessible, instance) LOG.info("Cluster '%s': all instances are accessible" % cluster.id)
def attach_to_instances(instances): with context.ThreadGroup() as tg: for instance in instances: tg.spawn('attach-volumes-for-instance-%s' % instance.instance_name, _attach_volumes_to_node, instance.node_group, instance) mount_to_instances(instances)
def _start_tt_dn_processes(self, instances): tt_dn_names = ["datanode", "tasktracker"] with context.ThreadGroup() as tg: for i in instances: processes = set(i.node_group.node_processes) tt_dn_procs = processes.intersection(tt_dn_names) if tt_dn_procs: tg.spawn('vanilla-start-tt-dn-%s' % i.instance_name, self._start_tt_dn, i, list(tt_dn_procs))
def test_thread_group_waits_threads_if_child_exception(self): lst = [] with self.assertRaises(Exception): with context.ThreadGroup() as tg: tg.spawn('raiser', self._raise_test_exc, 'exc') for i in range(400): tg.spawn('add %i' % i, self._add_element, lst, i) self.assertEqual(len(lst), 400)
def test_thread_group_waits_threads_if_spawning_exception(self): lst = [] with self.assertRaises(Exception): with context.ThreadGroup() as tg: for i in range(400): tg.spawn('add %i' % i, self._add_element, lst, i) raise RuntimeError() self.assertEqual(len(lst), 400)
def _push_configs_to_nodes(self, cluster, extra, new_instances): all_instances = utils.get_instances(cluster) with context.ThreadGroup() as tg: for instance in all_instances: if instance in new_instances: tg.spawn('vanilla-configure-%s' % instance.instance_name, self._push_configs_to_new_node, cluster, extra, instance) else: tg.spawn('vanilla-reconfigure-%s' % instance.instance_name, self._push_configs_to_existing_node, cluster, extra, instance)
def test_thread_group_waits_threads(self): # That can fail with some probability, so making 5 attempts # Actually it takes around 1 second, so maybe we should # just remove it for _ in range(5): lst = [] with context.ThreadGroup() as tg: for i in range(400): tg.spawn('add %i' % i, self._add_element, lst, i) self.assertEqual(len(lst), 400)
def _configure_instances(self, cluster): """Configure active instances. * generate /etc/hosts * setup passwordless login * etc. """ hosts_file = g.generate_etc_hosts(cluster) with context.ThreadGroup() as tg: for node_group in cluster.node_groups: for instance in node_group.instances: tg.spawn("configure-instance-%s" % instance.instance_name, self._configure_instance, instance, hosts_file)
def test_thread_group_prefers_spawning_exception(self): with self.assertRaises(RuntimeError): with context.ThreadGroup() as tg: tg.spawn('raiser1', self._raise_test_exc, 'exc1') raise RuntimeError()
def test_thread_group_handles_spawning_exception(self): with self.assertRaises(TestException): with context.ThreadGroup(): raise TestException()
def attach(cluster): with context.ThreadGroup() as tg: for node_group in cluster.node_groups: tg.spawn('attach-volumes-for-ng-%s' % node_group.name, attach_to_instances, node_group.instances)
def mount_to_instances(instances): with context.ThreadGroup() as tg: for instance in instances: tg.spawn('mount-volumes-to-node-%s' % instance.instance_name, _mount_volumes_to_node, instance)