def __call__(self, context, value): """Implements ValuePredicate interface.""" if not isinstance(value, CliAgentRunError): return jp.JsonError('Expected program to fail, but it did not') ok = value.match_regex(self.__error_regex) return jp.PredicateResult(ok is not None)
def collect_observation(self, context, observation, trace=True): args = context.eval(self.__args) dcos_response = self.__dcoscli.run(args, trace=trace) if not dcos_response.ok(): observation.add_error( cli_agent.CliAgentRunError(self.__dcoscli, dcos_response)) return [] decoder = json.JSONDecoder() try: doc = decoder.decode(dcos_response.output) if not isinstance(doc, list): doc = [doc] self.filter_all_objects_to_observation(context, doc, observation) except ValueError as vex: error = 'Invalid JSON in response: %s' % str(dcos_response) logging.getLogger(__name__).info('%s\n%s\n----------------\n', error, traceback.format_exc()) observation.add_error(jp.JsonError(error, vex)) return [] return observation.objects