def test_translate_result_type(self): if hasattr(self, 'exception'): with self.assertRaisesRegex(ValidationError, self.exception): translate_result_type(self.value) else: self.assertEquals(self.return_value, translate_result_type(self.value))
def read(self, request, system_id): """Return a list of script results grouped by run. :param type: Only return scripts with the given type. This can be commissioning, testing, or installion. Defaults to showing all. :type type: unicode :param hardware_type: Only return scripts for the given hardware type. Can be node, cpu, memory, or storage. Defaults to all. :type script_type: unicode :param include_output: Include base64 encoded output from the script. :type include_output: bool :param filters: A comma seperated list to show only results with a script name or tag. :type filters: unicode """ node = Node.objects.get_node_or_404(system_id=system_id, user=request.user, perm=NODE_PERMISSION.VIEW) result_type = get_optional_param(request.GET, 'type') include_output = get_optional_param(request.GET, 'include_output', False, Bool) filters = get_optional_param(request.GET, 'filters', None, String) if filters is not None: filters = filters.split(',') if result_type is not None: try: result_type = translate_result_type(result_type) except ValidationError as e: raise MAASAPIValidationError(e) else: qs = ScriptSet.objects.filter(node=node, result_type=result_type) else: qs = ScriptSet.objects.filter(node=node) hardware_type = get_optional_param(request.GET, 'hardware_type') if hardware_type is not None: try: hardware_type = translate_hardware_type(hardware_type) except ValidationError as e: raise MAASAPIValidationError(e) ret = [] for script_set in qs: script_set.include_output = include_output script_set.filters = filters script_set.hardware_type = hardware_type ret.append(script_set) return ret
def read(self, request, system_id): """@description-title Return script results @description Return a list of script results grouped by run for the given system_id. @param (string) "{system_id}" [required=true] The machine's system_id. @param (string) "type" [required=false] Only return scripts with the given type. This can be ``commissioning``, ``testing``, or ``installion``. Defaults to showing all. @param (string) "hardware_type" [required=false] Only return scripts for the given hardware type. Can be ``node``, ``cpu``, ``memory``, or ``storage``. Defaults to all. @param (string) "include_output" [required=false] Include base64 encoded output from the script. Note that any value of include_output will include the encoded output from the script. @param (string) "filters" [required=false] A comma seperated list to show only results with a script name or tag. @success (http-status-code) "server-success" 200 @success (json) "success-json" A JSON object containing a list of script result objects. @success-example "success-json" [exkey=script-results-read] placeholder text @error (http-status-code) "404" 404 @error (content) "not-found" The requested machine is not found. @error-example "not-found" Not Found """ node = Node.objects.get_node_or_404(system_id=system_id, user=request.user, perm=NodePermission.view) result_type = get_optional_param(request.GET, "type") include_output = get_optional_param(request.GET, "include_output", False, Bool) filters = get_optional_param(request.GET, "filters", None, String) if filters is not None: filters = filters.split(",") if result_type is not None: try: result_type = translate_result_type(result_type) except ValidationError as e: raise MAASAPIValidationError(e) else: qs = ScriptSet.objects.filter(node=node, result_type=result_type) else: qs = ScriptSet.objects.filter(node=node) hardware_type = get_optional_param(request.GET, "hardware_type") if hardware_type is not None: try: hardware_type = translate_hardware_type(hardware_type) except ValidationError as e: raise MAASAPIValidationError(e) ret = [] for script_set in qs: script_set.include_output = include_output script_set.filters = filters script_set.hardware_type = hardware_type ret.append(script_set) return ret