def _validate_edit_config_target(self, target: str) -> None: """ Validate edit-config/lock/unlock target is acceptable Args: target: configuration source to edit/lock; typically one of running|startup|candidate Returns: None Raises: ScrapliValueError: if an invalid source was selected """ if target not in self.writeable_datastores: msg = f"'target' should be one of {self.writeable_datastores}, got '{target}'" self.logger.warning(msg) if self.strict_datastores is True: raise ScrapliValueError(msg) user_warning(title="Invalid datastore target!", message=msg)
def _validate_get_config_target(self, source: str) -> None: """ Validate get-config source is acceptable Args: source: configuration source to get; typically one of running|startup|candidate Returns: None Raises: ScrapliValueError: if an invalid source was selected and strict_datastores is True """ if source not in self.readable_datastores: msg = f"'source' should be one of {self.readable_datastores}, got '{source}'" self.logger.warning(msg) if self.strict_datastores is True: raise ScrapliValueError(msg) user_warning(title="Invalid datastore source!", message=msg)
def _pre_escalate(self, escalate_priv: PrivilegeLevel) -> None: """ Handle pre "_escalate" tasks for consistency between sync/async versions Args: escalate_priv: privilege level to escalate to Returns: None Raises: N/A """ if escalate_priv.escalate_auth is True and not self.auth_secondary: title = "Authentication Warning!" message = ( "scrapli will try to escalate privilege without entering a password but may " "fail.\nSet an 'auth_secondary' password if your device requires a password to " "increase privilege, otherwise ignore this message.") user_warning(title=title, message=message)
def test_user_warning(): with pytest.warns(UserWarning): user_warning(title="blah", message="something")