Exemple #1
0
    def test_rsh(self):
        logging.debug('')
        logging.debug('test_rsh')

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

        factory = None
        try:
            # Try to set command line on remote ExternalCode instance.
            typname = 'openmdao.lib.components.external_code.ExternalCode'
            factory = ObjServerFactory(allowed_types=[typname])
            exec_comp = factory.create(typname)
            try:
                exec_comp.command = ['this-should-fail']
            except RemoteError as exc:
                msg = "RoleError: No __setattr__ access to 'command'"
                logging.debug('msg: %s', msg)
                logging.debug('exc: %s', exc)
                self.assertTrue(msg in str(exc))
            else:
                self.fail('Expected RemoteError')

            exec_comp.set('command', ['this-should-pass'])

            # Try to set via remote-looking access.
            creds = get_credentials()
            creds.client_creds = Credentials()
            logging.debug('    using %s', creds)
            try:
                exec_comp.set('command', ['this-should-fail'])
            except RemoteError as exc:
                fragment = ": 'command' may not be set() remotely"
                if fragment not in str(exc):
                    self.fail('%s not in %s' % (fragment, exc))
            finally:
                creds.client_creds = None

        finally:
            if factory is not None:
                factory.cleanup()
            os.chdir('..')
            if sys.platform == 'win32':
                time.sleep(2)  # Wait for process shutdown.
            keep_dirs = int(os.environ.get('OPENMDAO_KEEPDIRS', '0'))
            if not keep_dirs:
                shutil.rmtree(testdir, onerror=onerror)
    def test_rsh(self):
        logging.debug("")
        logging.debug("test_rsh")

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

        factory = None
        try:
            # Try to set command line on remote ExternalCode instance.
            typname = "openmdao.lib.components.external_code.ExternalCode"
            factory = ObjServerFactory(allowed_types=[typname])
            exec_comp = factory.create(typname)
            cmd = exec_comp.command

            try:
                exec_comp.command = ["this-should-fail"]
            except RemoteError as exc:
                msg = "RoleError: No __setattr__ access to 'command'"
                logging.debug("msg: %s", msg)
                logging.debug("exc: %s", exc)
                self.assertTrue(msg in str(exc))
            else:
                self.fail("Expected RemoteError")

            exec_comp.set("command", ["this-should-pass"])

            # Try to set via remote-looking access.
            creds = get_credentials()
            creds.client_creds = Credentials()
            logging.debug("    using %s", creds)
            try:
                code = "exec_comp.set('command', ['this-should-fail'])"
                assert_raises(self, code, globals(), locals(), RuntimeError, ": 'command' may not be set() remotely")
            finally:
                creds.client_creds = None

        finally:
            if factory is not None:
                factory.cleanup()
            os.chdir("..")
            if sys.platform == "win32":
                time.sleep(2)  # Wait for process shutdown.
            keep_dirs = int(os.environ.get("OPENMDAO_KEEPDIRS", "0"))
            if not keep_dirs:
                shutil.rmtree(testdir)
    def test_factory(self):
        logging.debug("")
        logging.debug("test_factory")

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

        factory = None
        try:
            # Create a factory.
            factory = ObjServerFactory()

            # Echo some arguments.
            args = factory.echo("Hello", "world!")
            self.assertEqual(args[0], "Hello")
            self.assertEqual(args[1], "world!")

            # List types.
            types = factory.get_available_types()
            names = [name for name, version in types]
            self.assertTrue("openmdao.test.execcomp.ExecComp" in names)

            # Create a component.
            exec_comp = factory.create("openmdao.test.execcomp.ExecComp")
            exec_comp.run()

            # Force failed factory server startup via invalid port.
            assert_raises(
                self, "start_server(port='xyzzy')", globals(), locals(), RuntimeError, "Server startup failed"
            )

            # Try to release a server that doesn't exist (release takes an
            # OpenMDAO_Proxy as argument, string here is easier).
            assert_raises(
                self,
                "factory.release('xyzzy')",
                globals(),
                locals(),
                ValueError,
                "can't identify server at 'not-a-proxy'",
            )
        finally:
            if factory is not None:
                factory.cleanup()
            SimulationRoot.chroot("..")
            if sys.platform == "win32":
                time.sleep(2)  # Wait for process shutdown.
            keep_dirs = int(os.environ.get("OPENMDAO_KEEPDIRS", "0"))
            if not keep_dirs:
                shutil.rmtree(testdir)
    def test_factory(self):
        logging.debug('')
        logging.debug('test_factory')

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

        factory = None
        try:
            # Create a factory.
            factory = ObjServerFactory()

            # Echo some arguments.
            args = factory.echo('Hello', 'world!')
            self.assertEqual(args[0], 'Hello')
            self.assertEqual(args[1], 'world!')

            # List types.
            types = factory.get_available_types()
            names = [name for name, version in types]
            self.assertTrue('openmdao.test.execcomp.ExecComp' in names)

            # Create a component.
            exec_comp = factory.create('openmdao.test.execcomp.ExecComp')
            exec_comp.run()

            # Force failed factory server startup via invalid port.
            assert_raises(self, "start_server(port='xyzzy')", globals(),
                          locals(), RuntimeError, 'Server startup failed')

            # Try to release a server that doesn't exist (release takes an
            # OpenMDAO_Proxy as argument, string here is easier).
            assert_raises(self, "factory.release('xyzzy')", globals(),
                          locals(), ValueError,
                          "can't identify server at 'not-a-proxy'")
        finally:
            if factory is not None:
                factory.cleanup()
            SimulationRoot.chroot('..')
            if sys.platform == 'win32':
                time.sleep(2)  # Wait for process shutdown.
            keep_dirs = int(os.environ.get('OPENMDAO_KEEPDIRS', '0'))
            if not keep_dirs:
                shutil.rmtree(testdir)
Exemple #5
0
    def test_factory(self):
        logging.debug('')
        logging.debug('test_factory')

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

        factory = None
        try:
            # Create a factory.
            factory = ObjServerFactory()

            # Echo some arguments.
            args = factory.echo('Hello', 'world!')
            self.assertEqual(args[0], 'Hello')
            self.assertEqual(args[1], 'world!')

            # List types.
            types = factory.get_available_types()
            names = [name for name, version in types]
            self.assertTrue('openmdao.test.execcomp.ExecComp' in names)

            # Create a component.
            exec_comp = factory.create('openmdao.test.execcomp.ExecComp')
            exec_comp.run()
            directory = 'Server_1' + os.sep
            if sys.platform == 'win32':
                directory = directory.lower()
            self.assertTrue(exec_comp.get_abs_directory().endswith(directory))

            # Create another in specified directory.
            exec_comp = factory.create('openmdao.test.execcomp.ExecComp',
                                       res_desc={'working_directory': 'floyd'})
            exec_comp.run()
            directory = 'floyd' + os.sep
            if sys.platform == 'win32':
                directory = directory.lower()
            self.assertTrue(exec_comp.get_abs_directory().endswith(directory))

            # Start server, connect, stop.
            server, cfg = start_server()
            proxy = connect_to_server(cfg)
            shutil.copy(cfg, 'saved_cfg')
            stop_server(server, cfg)

            _PROXIES.clear()
            assert_raises(self, "connect_to_server('saved_cfg')", globals(),
                          locals(), RuntimeError,
                          "Can't connect to server at ")

            # Force failed factory server startup via invalid port.
            address = socket.gethostbyname(socket.gethostname())
            code = "start_server(address=address, port='xyzzy'," \
                   " allow_shell=True, tunnel=True, resources='')"
            assert_raises(self, code, globals(), locals(), RuntimeError,
                          'Server startup failed')

            # Try to release a server that doesn't exist (release takes an
            # OpenMDAO_Proxy as argument, string here is easier).
            assert_raises(self, "factory.release('xyzzy')", globals(),
                          locals(), ValueError,
                          "can't identify server at 'not-a-proxy'")

            # get_ram() is used by RAM.add_remotes().
            ram = factory.get_ram()
            self.assertTrue(ram is RAM._get_instance())

        finally:
            if factory is not None:
                factory.cleanup()
            SimulationRoot.chroot('..')
            if sys.platform == 'win32':
                time.sleep(2)  # Wait for process shutdown.
            keep_dirs = int(os.environ.get('OPENMDAO_KEEPDIRS', '0'))
            if not keep_dirs:
                shutil.rmtree(testdir, onerror=onerror)
    def test_factory(self):
        logging.debug('')
        logging.debug('test_factory')

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

        factory = None
        try:
            # Create a factory.
            factory = ObjServerFactory()

            # Echo some arguments.
            args = factory.echo('Hello', 'world!')
            self.assertEqual(args[0], 'Hello')
            self.assertEqual(args[1], 'world!')

            # List types.
            types = factory.get_available_types()
            names = [name for name, version in types]
            self.assertTrue('openmdao.test.execcomp.ExecComp' in names)

            # Create a component.
            exec_comp = factory.create('openmdao.test.execcomp.ExecComp')
            exec_comp.run()

            # Start server, connect, stop.
            server, cfg = start_server()
            proxy = connect_to_server(cfg)
            shutil.copy(cfg, 'saved_cfg')
            stop_server(server, cfg)

            _PROXIES.clear()
            assert_raises(self, "connect_to_server('saved_cfg')",
                          globals(), locals(), RuntimeError,
                          "Can't connect to server at ")

            # Force failed factory server startup via invalid port.
            address = socket.gethostbyname(socket.gethostname())
            code = "start_server(address=address, port='xyzzy'," \
                                 " allow_shell=True, tunnel=True, resources='')"
            assert_raises(self, code, globals(), locals(), RuntimeError,
                          'Server startup failed')

            # Try to release a server that doesn't exist (release takes an
            # OpenMDAO_Proxy as argument, string here is easier).
            assert_raises(self, "factory.release('xyzzy')",
                          globals(), locals(), ValueError,
                          "can't identify server at 'not-a-proxy'")

            # get_ram() is used by RAM.add_remotes().
            ram = factory.get_ram()
            self.assertTrue(ram is RAM._get_instance())

        finally:
            if factory is not None:
                factory.cleanup()
            SimulationRoot.chroot('..')
            if sys.platform == 'win32':
                time.sleep(2)  # Wait for process shutdown.
            keep_dirs = int(os.environ.get('OPENMDAO_KEEPDIRS', '0'))
            if not keep_dirs:
                shutil.rmtree(testdir, onerror=onerror)