def main(): options = common.parse_args(use_isolate_server=True, use_swarming=True) try: common.note( 'Archiving directory \'payload\' to %s' % options.isolate_server) payload_isolated_sha1 = common.capture( [ 'isolateserver.py', 'archive', '--isolate-server', options.isolate_server, 'payload', ]).split()[0] common.note( 'Archiving custom .isolated file to %s' % options.isolate_server) handle, isolated = tempfile.mkstemp( prefix=u'hello_world', suffix=u'.isolated') os.close(handle) try: data = { 'algo': 'sha-1', 'command': ['python', 'hello_world.py', 'Custom'], 'includes': [payload_isolated_sha1], 'version': '1.0', } with open(isolated, 'wb') as f: json.dump(data, f, sort_keys=True, separators=(',',':')) isolated_sha1 = common.capture( [ 'isolateserver.py', 'archive', '--isolate-server', options.isolate_server, isolated, ]).split()[0] finally: common.note('Deleting temporary file, it is not necessary anymore.') os.remove(isolated) # Now trigger as usual. You could look at run_exmaple_swarming_involved for # the involved way but use the short way here. common.note('Running %s on %s' % (isolated_sha1, options.swarming)) cmd = [ 'swarming.py', 'run', '--swarming', options.swarming, '--isolate-server', options.isolate_server, '--dimension', 'os', options.swarming_os, '--dimension', 'pool', 'default', '--task-name', options.task_name, isolated_sha1, ] if options.idempotent: cmd.append('--idempotent') if options.priority is not None: cmd.extend(('--priority', str(options.priority))) common.run(cmd, options.verbose) return 0 except subprocess.CalledProcessError as e: return e.returncode
def horovod_args(self, mode, controller, run_func=None, command=None): if mode == 'local': local_hosts = ['localhost', '127.0.0.1'] remote_hosts = [] elif mode == 'remote': local_hosts = [] remote_hosts = ['localhost', '127.0.0.1'] else: local_hosts = ['localhost'] remote_hosts = ['127.0.0.1'] hosts = local_hosts.copy() hosts.extend(remote_hosts) if remote_hosts: ssh_works = _check_all_hosts_ssh_successful(remote_hosts, fn_cache=None) if not ssh_works: self.skipTest('password-less ssh to {} is required for this test' .format(' and '.join(remote_hosts))) hargs = _HorovodArgs() hargs.np = 4 hargs.hosts = ','.join(['{}:2'.format(host) for host in hosts]) hargs.use_gloo = controller == 'gloo' hargs.use_mpi = controller == 'mpi' hargs.run_func = run_func hargs.command = [command] if command else None hargs.nics = [] hargs.verbose = 2 hargs.disable_cache = True stdout = io.StringIO() try: with capture(stdout=stdout): with mock.patch('horovod.runner.launch.network.filter_local_addresses', side_effect=lambda hosts: [host for host in hosts if host not in local_hosts]), \ mock.patch('horovod.runner.gloo_run.network.get_local_host_addresses', return_value=local_hosts), \ mock.patch('horovod.runner.gloo_run.network.resolve_host_address', side_effect=lambda host: host), \ mock.patch('horovod.runner.mpi_run.os.execve') as exec: yield hargs, exec finally: stdout = stdout.readlines() print(''.join(stdout), file=sys.stdout) if mode == 'local': self.assertIn('Remote host found: \n', stdout) self.assertIn('All hosts are local, finding the interfaces with address 127.0.0.1\n', stdout) self.assertEqual(1, len([line for line in stdout if line.startswith('Local interface found ')])) elif mode == 'mixed': self.assertIn('Remote host found: 127.0.0.1\n', stdout) elif mode == 'remote': self.assertIn('Remote host found: localhost 127.0.0.1\n', stdout) else: raise RuntimeError('unknown mode {}'.format(mode)) if mode in ['mixed', 'remote']: self.assertIn('Checking ssh on all remote hosts.\n', stdout) self.assertIn('SSH was successful into all the remote hosts.\n', stdout) self.assertIn('Testing interfaces on all the hosts.\n', stdout) self.assertIn('Launched horovod server.\n', stdout) self.assertEqual(2, len([line for line in stdout if line.startswith('Launching horovod task function: ')])) self.assertEqual(1, len([line for line in stdout if line.startswith('Launching horovod task function: ssh -o PasswordAuthentication=no -o StrictHostKeyChecking=no 127.0.0.1 ')]), stdout) if mode == 'remote': self.assertEqual(1, len([line for line in stdout if line.startswith('Launching horovod task function: ssh -o PasswordAuthentication=no -o StrictHostKeyChecking=no localhost ')])) else: self.assertEqual(1, len([line for line in stdout if line.startswith('Launching horovod task function: ') and not line.startswith('Launching horovod task function: ssh')])) self.assertIn('Attempted to launch horovod task servers.\n', stdout) self.assertIn('Waiting for the hosts to acknowledge.\n', stdout) self.assertIn('Notified all the hosts that the registration is complete.\n', stdout) self.assertIn('Waiting for hosts to perform host-to-host interface checking.\n', stdout) self.assertIn('Host-to-host interface checking successful.\n', stdout) self.assertIn('Interfaces on all the hosts were successfully checked.\n', stdout) self.assertEqual(1, len([line for line in stdout if line.startswith('Common interface found: ')]))