def disable_feature(self, feature_name, callback=None): """ Disable the given feature by subscribing to the appropriate topics. :param callback: callback which is called when the feature is disabled :param feature_name: one of the feature name constants from constant.py :raises: ValueError if feature_name is invalid """ logger.info("disable_feature {} called".format(feature_name)) if feature_name not in self.feature_enabled: raise ValueError("Invalid feature_name") self.feature_enabled[feature_name] = False def on_complete(call): if call.error: # TODO we need error semantics on the client sys.exit(1) if callback: callback() self._pipeline.run_op( pipeline_ops_base.DisableFeatureOperation( feature_name=feature_name, callback=on_complete ) )
def disable_feature(self, feature_name, callback): """ Disable the given feature by subscribing to the appropriate topics. :param callback: callback which is called when the feature is disabled :param feature_name: one of the feature name constants from constant.py :raises: ValueError if feature_name is invalid :raises: :class:`azure.iot.device.iothub.pipeline.exceptions.PipelineNotRunning` if the pipeline has previously been shut down The following exceptions are not "raised", but rather returned via the "error" parameter when invoking "callback": :raises: :class:`azure.iot.device.iothub.pipeline.exceptions.NoConnectionError` :raises: :class:`azure.iot.device.iothub.pipeline.exceptions.ProtocolClientError` The following exceptions can be returned via the "error" parameter only if auto-connect is enabled in the pipeline configuration: :raises: :class:`azure.iot.device.iothub.pipeline.exceptions.ConnectionFailedError` :raises: :class:`azure.iot.device.iothub.pipeline.exceptions.ConnectionDroppedError` :raises: :class:`azure.iot.device.iothub.pipeline.exceptions.UnauthorizedError` """ self._verify_running() logger.debug("disable_feature {} called".format(feature_name)) if feature_name not in self.feature_enabled: raise ValueError("Invalid feature_name") # TODO: What about if the feature is already disabled? def on_complete(op, error): if error: logger.warning( "Error occurred while disabling feature. Unclear if subscription for {} is still alive or not".format( feature_name ) ) # No matter what, mark the feature as disabled, even if there was an error. # This is safer than only marking it disabled upon operation success, because an op # could fail after successfully doing the network operations to change the subscription # state, and then we would be stuck in a bad state. self.feature_enabled[feature_name] = False callback(error=error) self._pipeline.run_op( pipeline_ops_base.DisableFeatureOperation( feature_name=feature_name, callback=on_complete ) )
def disable_responses(self, callback=None): """ Disable response from the DPS service by unsubscribing from the appropriate topics. :param callback: callback which is called when the feature is disabled """ logger.debug("disable_responses called") def pipeline_callback(call): if call.error: # TODO we need error semantics on the client exit(1) if callback: callback() self._pipeline.run_op( pipeline_ops_base.DisableFeatureOperation(feature_name=None, callback=pipeline_callback) )
def disable_feature(self, feature_name, callback): """ Disable the given feature by subscribing to the appropriate topics. :param callback: callback which is called when the feature is disabled :param feature_name: one of the feature name constants from constant.py :raises: ValueError if feature_name is invalid """ logger.debug("disable_feature {} called".format(feature_name)) if feature_name not in self.feature_enabled: raise ValueError("Invalid feature_name") self.feature_enabled[feature_name] = False def on_complete(op, error): callback(error=error) self._pipeline.run_op( pipeline_ops_base.DisableFeatureOperation( feature_name=feature_name, callback=on_complete))
def op(self, mocker, iothub_pipeline_feature): return pipeline_ops_base.DisableFeatureOperation( feature_name=iothub_pipeline_feature, callback=mocker.MagicMock())
def op(self, mocker): return pipeline_ops_base.DisableFeatureOperation( feature_name=pipeline_constant.REGISTER, callback=mocker.MagicMock())