示例#1
0
def SetMode(mode):
    """Set the execution mode.

    Valid modes are 'master', 'slave', 'simulation' and 'maintenance'.

    * 'master' mode is for normal operation.  Only one copy of the instrument
      software can be in master mode at the same time.

    * 'slave' mode is for secondary copies of the software.  They can only read
      the instrument status, but not move devices or set parameters.

    * 'simulation' mode is for complete simulation of the instrument.  When
      switching to dry-run/simulation mode, the current state of the instrument
      is taken as the basis of the run.  No hardware communication is possible
      in this mode.

      'simulation' does a non-physical emulation by running all the instrument
      specific code with virtualized devices.  Any problems which would appear
      runnig the same commands in 'master' mode (with ideal hardware) can be
      spotted by the user, such as devices moving out of limits, failing
      calculations, or invalid parameters.

      Furthermore, the ranges of all devices which are moved are recorded and
      the required time to run a command or script is estimated from device
      properties ('speed', 'ramp', 'accel').

      It is currently not implemented to switch back: use the `sim()` command
      for doing one-off dry runs.

    * 'maintenance' mode is for instrument scientists only.

    Example:

    >>> SetMode('slave')    # e.g. to let another master take over
    ...
    >>> SetMode('master')   # switch back to master in this copy
    """
    if mode == 'sim':
        mode = SIMULATION
    elif mode == 'maint':
        mode = MAINTENANCE
    if mode == MAINTENANCE:
        # switching to maintenance mode is dangerous since two parallel
        # sessions can execute active commands
        session.checkAccess({'level': ADMIN})
    try:
        session.setMode(mode)
    except ModeError:
        session.log.exception()
示例#2
0
def session(request):
    """Test session fixture"""

    nicos_session.__class__ = TestSession
    nicos_session.__init__(request.module.__name__)
    # override the sessionid: test module, and a finer resolved timestamp
    nicos_session.sessionid = '%s-%s' % (request.module.__name__, time.time())
    nicos_session.setMode(getattr(request.module, 'session_mode', MASTER))
    if request.module.session_setup:
        nicos_session.unloadSetup()
        nicos_session.loadSetup(
            request.module.session_setup,
            **getattr(request.module, 'session_load_kw', {}))
    if getattr(request.module, 'session_spmode', False):
        nicos_session.setSPMode(True)
    yield nicos_session
    nicos_session.setSPMode(False)
    nicos_session.shutdown()
示例#3
0
def NewSetup(*setupnames):
    """Load the given setups instead of the current one.

    Example:

    >>> NewSetup('tas', 'psd')

    will clear the current setup and load the "tas" and "psd" setups at the
    same time.

    Without arguments, the current setups are reloaded.  Example:

    >>> NewSetup()

    You can use `ListSetups()` to find out which setups are available.

    see also: `AddSetup`, `RemoveSetup`, `ListSetups`
    """
    current_mode = session.mode
    # reload current setups if none given
    update_aliases = True
    if not setupnames:
        update_aliases = False
        setupnames = session.explicit_setups
    # refresh setup files first
    session.readSetups()
    session.checkSetupCompatibility(setupnames, set())
    session.unloadSetup()
    try:
        session.startMultiCreate()
        try:
            session.loadSetup(setupnames, update_aliases=update_aliases)
        finally:
            session.endMultiCreate()
    except Exception:
        session.log.warning(
            'could not load new setup, falling back to '
            'startup setup',
            exc=1)
        session.unloadSetup()
        session.loadSetup('startup')
    if current_mode == MASTER:
        # need to refresh master status
        session.setMode(MASTER)