Coverage for ocp_resources/exceptions.py: 53%

51 statements  

« prev     ^ index     » next       coverage.py v7.10.1, created at 2025-07-29 12:31 +0300

1from typing import Any 

2from warnings import warn 

3 

4 

5class MissingRequiredArgumentError(Exception): 

6 def __init__(self, argument: str) -> None: 

7 self.argument = argument 

8 

9 def __str__(self) -> str: 

10 return f"Missing required argument/s. Either provide yaml_file, kind_dict or pass {self.argument}" 

11 

12 

13class MissingResourceError(Exception): 

14 def __init__(self, name: str) -> None: 

15 self.resource_name = name 

16 

17 def __str__(self) -> str: 

18 return f"Failed to generate resource: {self.resource_name}" 

19 

20 

21class MissingResourceResError(Exception): 

22 def __init__(self, name: str) -> None: 

23 warn( 

24 "MissingResourceResError is deprecated and will be removed in the future. Use MissingResourceError instead.", 

25 DeprecationWarning, 

26 stacklevel=2, 

27 ) 

28 self.resource_name = name 

29 

30 def __str__(self) -> str: 

31 return f"Failed to generate resource: {self.resource_name}" 

32 

33 

34class MissingTemplateVariables(Exception): 

35 def __init__(self, var: str, template: str) -> None: 

36 self.var = var 

37 self.template = template 

38 

39 def __str__(self): 

40 return f"Missing variables {self.var} for template {self.template}" 

41 

42 

43class ExecOnPodError(Exception): 

44 def __init__(self, command: list[str], rc: int, out: str, err: Any) -> None: 

45 self.cmd = command 

46 self.rc = rc 

47 self.out = out 

48 self.err = err 

49 

50 def __str__(self): 

51 return f"Command execution failure: {self.cmd}, RC: {self.rc}, OUT: {self.out}, ERR: {self.err}" 

52 

53 

54class NNCPConfigurationFailed(Exception): 

55 pass 

56 

57 

58class ResourceTeardownError(Exception): 

59 def __init__(self, resource: Any): 

60 self.resource = resource 

61 

62 def __str__(self): 

63 return f"Failed to execute teardown for resource {self.resource}" 

64 

65 

66class ClientWithBasicAuthError(Exception): 

67 pass 

68 

69 

70class ValidationError(Exception): 

71 """Raised when resource validation against OpenAPI schema fails.""" 

72 

73 def __init__(self, message: str, path: str = "", schema_error: Any = None) -> None: 

74 """ 

75 Initialize ValidationError. 

76 

77 Args: 

78 message: Human-readable error message 

79 path: JSONPath to the invalid field (e.g., "spec.containers[0].image") 

80 schema_error: Original jsonschema validation error for debugging 

81 """ 

82 self.message = message 

83 self.path = path 

84 self.schema_error = schema_error 

85 super().__init__(message) 

86 

87 def __str__(self) -> str: 

88 if self.path: 

89 return f"Validation error at '{self.path}': {self.message}" 

90 return f"Validation error: {self.message}"