def setUpClass(cls): base.BaseLmiTestCase.setUpClass.im_func(cls) LMIUtil.lmi_set_use_exceptions(cls.USE_EXCEPTIONS) if cls.needs_indications(): cls.indication_port = random.randint(12000, 13000) cls.indication_queue = Queue.Queue() cls.listener = LMIIndicationListener( "0.0.0.0", cls.indication_port)
def _wrapper(*args, **kwargs): """ Enable exceptions in wrapped function. """ original = LMIUtil.lmi_get_use_exceptions() LMIUtil.lmi_set_use_exceptions(True) try: retval = method(*args, **kwargs) finally: LMIUtil.lmi_set_use_exceptions(original) return retval
def __init__(self): # allow exceptions in lmi shell LMIUtil.lmi_set_use_exceptions(True) # instance of CommandManager, created when first needed self._command_manager = None self.stdout = sys.stdout self.stderr = sys.stderr self.stdin = sys.stdin # instance of Session, created when needed self._session = None # instance of Configuration, created in setup() self.config = None # dictionary of not yet processed options, it's created in setup() self._options = None
def execute_on_connection(self, connection, *args, **kwargs): """ Wraps the :py:meth:`~.endpoint.LmiEndPointCommand.execute` method with connection adjustments. Connection object is not usually passed directly to associated function. Mostly it's the namespace object that is expected. This method checks, whether the namespace object is desired and modifies connection accordingly. :param connection: Connection to single host. :type connection: :py:class:`lmi.shell.LMIConnection` :param list args: Arguments handed over to associated function. :param dictionary kwargs: Keyword arguments handed over to associated function. """ if not isinstance(connection, LMIConnection): raise TypeError("expected an instance of LMIConnection for" " connection argument, not %s" % repr(connection)) namespace = self.cim_namespace() timeout = self.connection_timeout() if timeout is not None: conn = getattr(connection, "connection", connection) if hasattr(conn, "timeout"): LOG().debug("Set connection timeout to %d seconds.", timeout) conn.timeout = timeout * 1000 else: LOG().debug("Could not set connection timeout.") if namespace is not None: connection = LMIUtil.lmi_wrap_cim_namespace( connection, namespace) return self.execute(connection, *args, **kwargs)
def set_repository_enabled(ns, repository, enable=True): """ Enable or disable repository. :param repository: Instance of ``LMI_SoftwareIdentityResource``. :type repository: :py:class:`lmi.shell.LMIInstance` or :py:class:`lmi.shell.LMIInstanceName` :param boolean enable: New value of ``EnabledState`` property. :returns: Previous value of repository's ``EnabledState``. :rtype: boolean """ if not isinstance(repository, (LMIInstance, LMIInstanceName)): raise TypeError("repository must be an LMIInstance") cls = ns.LMI_SoftwareIdentityResource if not LMIUtil.lmi_isinstance(repository, cls): raise ValueError("repository must be an instance of" " LMI_SoftwareIdentityResource") requested_state = cls.EnabledStateValues.Enabled if enable else \ cls.EnabledStateValues.Disabled if repository.EnabledState != requested_state: results = repository.RequestStateChange(RequestedState=requested_state) if results.rval != 0: msg = 'Failed to enable repository "%s" (rval=%d).' % ( repository.Name, results.rval) if results.errorstr: msg += ': ' + results.errorstr raise LmiFailed(msg) LOG().info('Repository "%s" %s.', repository.Name, "enabled" if enable else "disabled") else: LOG().info('Repository "%s" is already %s.', repository.Name, "enabled" if enable else "disabled") return repository.EnabledState
def set_repository_enabled(ns, repository, enable=True): """ Enable or disable repository. :param repository: Instance of ``LMI_SoftwareIdentityResource``. :type repository: :py:class:`lmi.shell.LMIInstance` or :py:class:`lmi.shell.LMIInstanceName` :param boolean enable: New value of ``EnabledState`` property. :returns: Previous value of repository's ``EnabledState``. :rtype: boolean """ if not isinstance(repository, (LMIInstance, LMIInstanceName)): raise TypeError("repository must be an LMIInstance") cls = ns.LMI_SoftwareIdentityResource if not LMIUtil.lmi_isinstance(repository, cls): raise ValueError("repository must be an instance of" " LMI_SoftwareIdentityResource") requested_state = cls.EnabledStateValues.Enabled if enable else \ cls.EnabledStateValues.Disabled if repository.EnabledState != requested_state: results = repository.RequestStateChange(RequestedState=requested_state) if results.rval != 0: msg = 'Failed to enable repository "%s" (rval=%d).' % ( repository.Name, results.rval) if results.errorstr: msg += ': ' + results.errorstr raise LmiFailed(msg) return repository.EnabledState
def execute_on_connection(self, connection, *args, **kwargs): if not isinstance(connection, LMIConnection): raise TypeError("expected an instance of LMIConnection for" " connection argument, not %s" % repr(connection)) namespace = self.cim_namespace() if namespace is not None: connection = LMIUtil.lmi_wrap_cim_namespace(connection, namespace) return self.execute(connection, *args, **kwargs)
def execute_on_connection(self, connection, *args, **kwargs): if not isinstance(connection, LMIConnection): raise TypeError("expected an instance of LMIConnection for" " connection argument, not %s" % repr(connection)) namespace = self.cim_namespace() if namespace is not None: connection = LMIUtil.lmi_wrap_cim_namespace( connection, namespace) return self.execute(connection, *args, **kwargs)