def setUp(self): self.orig_dir = os.getcwd() os.chdir(TestCase.directory) try: # Force use of fake 'ssh' and 'scp'. ssh = ('python', os.path.join(_TST_ROOT, 'ssh.py'), _DMZ_ROOT) scp = ('python', os.path.join(_TST_ROOT, 'scp.py'), _DMZ_ROOT) self.orig_ssh = protocol.configure_ssh(ssh) self.orig_scp = protocol.configure_scp(scp) # Avoid lots of polling log entries. if logging.getLogger().getEffectiveLevel() < logging.DEBUG: logging.getLogger().setLevel(logging.DEBUG) # Start RJE server. hostname = socket.gethostname() self.proc = start_server(hostname) # Create NAS_Allocator referring to server. logging.debug('create allocator') self.allocator = NAS_Allocator() parser = ConfigParser.ConfigParser() section = self.allocator.name parser.add_section(section) parser.set(section, 'dmz_host', hostname) parser.set(section, 'server_host', hostname) self.allocator.configure(parser) # Add allocator to RAM. RAM.add_allocator(self.allocator) except Exception: os.chdir(self.orig_dir) raise
print 'Job Complete ...' # ----------------------------- # --- Execute the component --- # ----------------------------- super(MeshComp, self).execute() # --- Copy files to local directories shutil.copy2( Path('OpenMDAO') + '/patran.out', Path('Patran') + '\Config' + self.config) shutil.copy2( Path('OpenMDAO') + '/Config' + self.config + '.cub', Path('Cubit')) if __name__ == "__main__": enable_console() logging.getLogger().setLevel(logging.DEBUG) # --- Create 4 allocators (redundancy for reliability) adding each to the manager --- allocator1 = NAS_Allocator(name='PFE20_DMZ1', dmz_host='dmzfs1.nas.nasa.gov', server_host='pfe20') RAM.add_allocator(allocator1) Remote_Mesh_Comp = MeshComp() Remote_Mesh_Comp.run()
def test_errors(self): logging.debug('') logging.debug('test_errors') logging.debug('allocate server') server, server_info = RAM.allocate(dict(allocator=self.allocator.name)) try: logging.debug('execute bad command') code = "server.execute_command(dict(remote_command='no-such-command'))" if sys.platform == 'win32': msg = "WindowsError: [Error 2] The system cannot find the file specified" else: msg = "OSError: [Errno 2] No such file or directory" try: server.execute_command(dict(remote_command='no-such-command')) except protocol.RemoteError as exc: exc_msg = str(exc) if msg not in exc_msg: self.fail('%s not in %s' % (msg, exc_msg)) else: self.fail('Expecting protocol.RemoteError') logging.debug('open bad file') msg = "Can\\'t open \\'../../illegal-access\\', not within root" msg = 'RuntimeError: %s' % msg try: server.open('../../illegal-access', 'r') except protocol.RemoteError as exc: exc_msg = str(exc) if msg not in exc_msg: self.fail('%s not in %s' % (msg, exc_msg)) else: self.fail('Expecting protocol.RemoteError') logging.debug('open missing file') msg = "[Errno 2] No such file or directory: \\'no-such-file\\'" msg = 'IOError: %s' % msg try: server.open('no-such-file', 'r') except protocol.RemoteError as exc: exc_msg = str(exc) if msg not in exc_msg: self.fail('%s not in %s' % (msg, exc_msg)) else: self.fail('Expecting protocol.RemoteError') finally: logging.debug('release') RAM.release(server) # Test for exited or never started server. logging.debug('dead server') self.proc.terminate() self.proc = None time.sleep(2) hostname = socket.gethostname() if sys.platform == 'win32': # Server doesn't clean up. root = protocol._server_root(hostname) mapped_root = os.path.join(_DMZ_ROOT, protocol._map_dir(root)) for name in glob.glob('%s*' % mapped_root): os.remove(name) code = 'NAS_Allocator(dmz_host=hostname, server_host=hostname)' assert_raises(self, code, globals(), locals(), RuntimeError, "NAS_Allocator: can't connect: server root 'RJE-%s='" " on '%s' not found" % (hostname, hostname)) # Test for missing heartbeat. logging.debug('no heartbeat') with open(os.path.join(_DMZ_ROOT, 'RJE-%s=' % hostname), 'w') as out: out.write('empty\n') try: NAS_Allocator(dmz_host=hostname, server_host=hostname) except RuntimeError as exc: msg = "IOError: [Errno 2] No such file or directory:" \ " 'RJE-%s=heartbeat'\n" % hostname logging.debug(str(exc)) self.assertTrue(str(exc).endswith(msg)) else: self.fail('Expected RuntimeError') # Test for stale heartbeat. logging.debug('stale heartbeat') protocol.server_heartbeat(hostname, 1, logging.getLogger()) time.sleep(5) assert_raises(self, code, globals(), locals(), RuntimeError, "NAS_Allocator: can't connect: server heartbeat" " hasn't been updated in 0:00:0")