def setUp(self): self.schema = mtrotator.CONFIG_SCHEMA self.validator = salobj.DefaultingValidator(schema=self.schema) self.default = dict( max_ccw_following_error=2.2, num_ccw_following_errors=3, )
def setUp(self): self.schema = ATDome.CONFIG_SCHEMA self.validator = salobj.DefaultingValidator(schema=self.schema) self.default = dict(host="192.168.223.14", port=17310, connection_timeout=10, read_timeout=10)
def _get_validated_telemetry_stream(self, telemetry_stream: List[Dict]) -> Dict: """Get validate telemetry stream. Parameters ---------- telemetry_stream : `list` of `dict` Input telemetry stream. Returns ------- validated_telemetry_stream : `dict` Reformated telemetry stream with validated entries. Raises ------ ValidationError: If one (or more) stream is invalid. """ schema_validator = salobj.DefaultingValidator(self.telemetry_stream_schema) self.log.debug("Validating telemetry stream schema.") validated_telemetry_stream = dict() for stream in telemetry_stream: validated_stream = schema_validator.validate(stream) validated_telemetry_stream[validated_stream["name"]] = validated_stream return validated_telemetry_stream
def test_contained_object(self) -> None: schemapath = self.schemadir / "contained_object_schema.yaml" with open(schemapath, "r") as f: rawschema = f.read() self.schema = yaml.safe_load(rawschema) self.validator = salobj.DefaultingValidator(schema=self.schema) default_values = self.validator.validate({}) print(f"default_values={default_values}") assert default_values["number1"] == 1 assert default_values["subobject"]["subnumber1"] == 2 import types print(types.SimpleNamespace(**default_values))
def make_config(self, name): """Make a config for the Enabled rule. Parameters ---------- name : `str` CSC name and index in the form `name` or `name:index`. The default index is 0. """ schema = watcher.rules.Enabled.get_schema() validator = salobj.DefaultingValidator(schema) config_dict = dict(name=name) full_config_dict = validator.validate(config_dict) config = types.SimpleNamespace(**full_config_dict) for key in config_dict: self.assertEqual(getattr(config, key), config_dict[key]) return config
def make_config(self, name, threshold): """Make a config for the Clock rule. Parameters ---------- name : `str` CSC name and index in the form `name` or `name:index`. The default index is 0. threshold : `float` Maximum allowed time between heartbeat events (sec). """ schema = watcher.rules.Clock.get_schema() validator = salobj.DefaultingValidator(schema) config_dict = dict(name=name, threshold=threshold) full_config_dict = validator.validate(config_dict) config = types.SimpleNamespace(**full_config_dict) for key in config_dict: self.assertEqual(getattr(config, key), config_dict[key]) return config
def make_config(self, name, interval, severities, **kwargs): """Make a config for the TestConfiguredSeverities rule. Parameters ---------- name : `str` Rule name (one field in a longer name). interval : `float` Interval between severities (seconds). severities : `list` [`lsst.ts.idl.enums.Watcher.AlarmSeverity`] A list of severities. **kwargs : `dict` Optional config parameters. """ schema = watcher.rules.test.ConfiguredSeverities.get_schema() validator = salobj.DefaultingValidator(schema) config_dict = dict(name=name, interval=interval, severities=severities) config_dict.update(kwargs) full_config_dict = validator.validate(config_dict) config = types.SimpleNamespace(**full_config_dict) for key in config_dict: self.assertEqual(getattr(config, key), config_dict[key]) return config
def setUp(self) -> None: # A version of the CONFIG_SCHEMA with added defaults self.schema: typing.Dict[str, typing.Any] = yaml.safe_load(""" description: A schema with defaults type: object properties: string0: type: string default: default value for string0 bool0: type: boolean default: true int0: type: integer default: 5 float0: type: number default: 3.14 intarr0: type: array default: [-1, 1] items: type: integer multi_type: anyOf: - type: integer minimum: 1 - type: string - type: "null" default: null required: [string0, bool0, int0, float0, intarr0, multi_type] additionalProperties: false """) self.validator = salobj.DefaultingValidator(schema=self.schema)
def setUp(self): self.schema = watcher.CONFIG_SCHEMA self.validator = salobj.DefaultingValidator(schema=self.schema) self.configpath = pathlib.Path( __file__).resolve().parent / "data" / "config"
def setUp(self): self.schema = CONFIG_SCHEMA self.validator = salobj.DefaultingValidator(schema=self.schema)
def __init__(self, domain, config, alarm_callback=None): self.domain = domain self.alarm_callback = alarm_callback self._enabled = False self.enable_task = salobj.make_done_future() # Dict of (sal_component_name, sal_index): lsst.ts.salobj.Remote self.remotes = dict() # Dict of rule_name: Rule self.rules = dict() # Convert the name of each disabled sal component from a string # in the form ``name`` or ``name:index`` to a tuple ``(name, index)``. config.disabled_sal_components = [ salobj.name_to_name_index(name) for name in config.disabled_sal_components ] self.config = config # Make the rules. for ruledata in self.config.rules: ruleclassname = ruledata["classname"] ruleclass = get_rule_class(ruleclassname) try: ruleschema = ruleclass.get_schema() if ruleschema is None: validator = None else: validator = salobj.DefaultingValidator(ruleschema) except Exception as e: raise ValueError( f"Schema for rule class {ruleclassname} not valid") from e for i, ruleconfig_dict in enumerate(ruledata["configs"]): try: if validator is None: if ruleconfig_dict: raise ValueError("Rule config dict must be empty") full_ruleconfig_dict = dict() else: full_ruleconfig_dict = validator.validate( ruleconfig_dict) ruleconfig = types.SimpleNamespace(**full_ruleconfig_dict) except Exception as e: raise ValueError( f"Config {i+1} for rule class {ruleclassname} not valid: " f"config={ruleconfig_dict}") from e rule = ruleclass(config=ruleconfig) if rule.is_usable(disabled_sal_components=config. disabled_sal_components): self.add_rule(rule) # Accumulate a list of topics that have callback functions. self._topics_with_callbacks = list() for remote in self.remotes.values(): for name in dir(remote): if name[0:4] in ("evt_", "tel_"): topic = getattr(remote, name) if topic.callback is not None: self._topics_with_callbacks.append(topic) # Set escalation information in the alarms. remaining_names = set(self.rules) for escalation_item in config.escalation: for name_glob in escalation_item["alarms"]: name_regex = fnmatch.translate(name_glob) compiled_name_regex = re.compile(name_regex, re.IGNORECASE) matched_names = [ name for name in remaining_names if compiled_name_regex.match(name) ] remaining_names = remaining_names.difference(matched_names) for name in matched_names: alarm = self.rules[name].alarm alarm.escalate_to = escalation_item["to"] alarm.escalate_delay = escalation_item["delay"] self.start_task = asyncio.ensure_future(self.start())