Exemplo n.º 1
0
    def test_shell(self):
        logging.debug('')
        logging.debug('test_shell')

        testdir = 'test_shell'
        if os.path.exists(testdir):
            shutil.rmtree(testdir, onerror=onerror)
        os.mkdir(testdir)
        os.chdir(testdir)

        try:
            # Create a server.
            server = ObjServer(allow_shell=True)

            # Execute a command.
            if sys.platform == 'win32':
                cmd = 'cmd'
                args = ['/c', 'dir']
            else:
                cmd = 'ls'
                args = []
            rdesc = {
                'remote_command': cmd,
                'args': args,
                'output_path': 'cmd.out'
            }
            return_code, error_msg = server.execute_command(rdesc)
            self.assertEqual(return_code, 0)

            # Bad command, specify lots of resources.
            with open('stdin1', 'w') as out:
                out.write('z')
            rdesc = {
                'remote_command': 'no-such-command',
                'args': ['a', 'b', 'c'],
                'input_path': 'stdin1',
                'error_path': 'stderr1',
                'wallclock_time': 10
            }
            if sys.platform == 'win32':
                msg = '[Error 2] The system cannot find the file specified'
            else:
                msg = '[Errno 2] No such file or directory'
            assert_raises(self, 'server.execute_command(rdesc)', globals(),
                          locals(), OSError, msg)

            # Load a model.
            exec_comp = server.create('openmdao.test.execcomp.ExecComp')
            exec_comp.run()
            egg_info = exec_comp.save_to_egg('exec_comp', '0')
            obj = server.load_model(egg_info[0])
            obj.run()

            assert_raises(self, "server.load_model('no-such-egg')", globals(),
                          locals(), ValueError, "'no-such-egg' not found.")
        finally:
            SimulationRoot.chroot('..')
            shutil.rmtree(testdir, onerror=onerror)
    def test_shell(self):
        logging.debug('')
        logging.debug('test_shell')

        testdir = 'test_shell'
        if os.path.exists(testdir):
            shutil.rmtree(testdir, onerror=onerror)
        os.mkdir(testdir)
        os.chdir(testdir)

        try:
            # Create a server.
            server = ObjServer(allow_shell=True)

            # Execute a command.
            if sys.platform == 'win32':
                cmd = 'cmd'
                args = ['/c', 'dir']
            else:
                cmd = 'ls'
                args = []
            rdesc = {'remote_command': cmd,
                     'args': args,
                     'output_path': 'cmd.out'}
            return_code, error_msg = server.execute_command(rdesc)
            self.assertEqual(return_code, 0)

            # Bad command, specify lots of resources.
            with open('stdin1', 'w') as out:
                out.write('z')
            rdesc = {'remote_command': 'no-such-command',
                     'args': ['a', 'b', 'c'],
                     'input_path': 'stdin1',
                     'error_path': 'stderr1',
                     'wallclock_time': 10}
            if sys.platform == 'win32':
                msg = '[Error 2] The system cannot find the file specified'
            else:
                msg = '[Errno 2] No such file or directory'
            assert_raises(self, 'server.execute_command(rdesc)',
                          globals(), locals(), OSError, msg)

            # Load a model.
            exec_comp = server.create('openmdao.test.execcomp.ExecComp')
            exec_comp.run()
            egg_info = exec_comp.save_to_egg('exec_comp', '0')
            obj = server.load_model(egg_info[0])
            obj.run()

            assert_raises(self, "server.load_model('no-such-egg')",
                          globals(), locals(), ValueError,
                          "'no-such-egg' not found.")
        finally:
            SimulationRoot.chroot('..')
            shutil.rmtree(testdir, onerror=onerror)
    def test_shell(self):
        logging.debug('')
        logging.debug('test_shell')
        
        testdir = 'test_shell'
        if os.path.exists(testdir):
            shutil.rmtree(testdir)
        os.mkdir(testdir)
        os.chdir(testdir)

        try:
            # Create a server.
            server = ObjServer(allow_shell=True)

            # Execute a command.
            cmd = 'dir' if sys.platform == 'win32' else 'ls'
            return_code, error_msg = \
                server.execute_command(cmd, None, 'cmd.out', None, None, 0, 10)
            self.assertEqual(return_code, 0)

            # Non-zero return code.
            return_code, error_msg = \
                server.execute_command('no-such-command',
                                       None, 'stdout1', 'stderr1', None, 0, 10)
            self.assertNotEqual(return_code, 0)

            # Exception creating process.
# FIXME: despite the files being closed, Windows thinks they're in use :-(
            if sys.platform != 'win32':
                try:
                    server.execute_command(['no-such-command'],
                                           None, 'stdout2', 'stderr2', None, 0, 10)
                except OSError as exc:
                    msg = '[Errno 2] No such file or directory'
                    self.assertEqual(str(exc), msg)
                else:
                    self.fail('Expected OSError')

            # Load a model.
            exec_comp = server.create('openmdao.test.execcomp.ExecComp')
            exec_comp.run()
            egg_info = exec_comp.save_to_egg('exec_comp', '0')
            obj = server.load_model(egg_info[0])
            obj.run()

            assert_raises(self, "server.load_model('no-such-egg')",
                          globals(), locals(), ValueError,
                          "'no-such-egg' not found.")
        finally:
            os.chdir('..')
            shutil.rmtree(testdir)
    def test_shell(self):
        logging.debug('')
        logging.debug('test_shell')

        testdir = 'test_shell'
        if os.path.exists(testdir):
            shutil.rmtree(testdir)
        os.mkdir(testdir)
        os.chdir(testdir)

        try:
            # Create a server.
            server = ObjServer(allow_shell=True)

            # Execute a command.
            cmd = 'dir' if sys.platform == 'win32' else 'ls'
            rdesc = {
                'remote_command': cmd,
                'output_path': 'cmd.out',
                'hard_runtime_limit': 10
            }
            return_code, error_msg = server.execute_command(rdesc)
            self.assertEqual(return_code, 0)

            # Non-zero return code.
            rdesc = {
                'remote_command': 'no-such-command',
                'output_path': 'stdout1',
                'error_path': 'stderr1',
                'hard_runtime_limit': 10
            }
            return_code, error_msg = server.execute_command(rdesc)
            self.assertNotEqual(return_code, 0)

            # Load a model.
            exec_comp = server.create('openmdao.test.execcomp.ExecComp')
            exec_comp.run()
            egg_info = exec_comp.save_to_egg('exec_comp', '0')
            obj = server.load_model(egg_info[0])
            obj.run()

            assert_raises(self, "server.load_model('no-such-egg')", globals(),
                          locals(), ValueError, "'no-such-egg' not found.")
        finally:
            SimulationRoot.chroot('..')
            shutil.rmtree(testdir)
    def test_shell(self):
        logging.debug("")
        logging.debug("test_shell")

        testdir = "test_shell"
        if os.path.exists(testdir):
            shutil.rmtree(testdir)
        os.mkdir(testdir)
        os.chdir(testdir)

        try:
            # Create a server.
            server = ObjServer(allow_shell=True)

            # Execute a command.
            cmd = "dir" if sys.platform == "win32" else "ls"
            rdesc = {"remote_command": cmd, "output_path": "cmd.out", "hard_runtime_limit": 10}
            return_code, error_msg = server.execute_command(rdesc)
            self.assertEqual(return_code, 0)

            # Non-zero return code.
            rdesc = {
                "remote_command": "no-such-command",
                "output_path": "stdout1",
                "error_path": "stderr1",
                "hard_runtime_limit": 10,
            }
            return_code, error_msg = server.execute_command(rdesc)
            self.assertNotEqual(return_code, 0)

            # Load a model.
            exec_comp = server.create("openmdao.test.execcomp.ExecComp")
            exec_comp.run()
            egg_info = exec_comp.save_to_egg("exec_comp", "0")
            obj = server.load_model(egg_info[0])
            obj.run()

            assert_raises(
                self, "server.load_model('no-such-egg')", globals(), locals(), ValueError, "'no-such-egg' not found."
            )
        finally:
            SimulationRoot.chroot("..")
            shutil.rmtree(testdir)