Skip to content

Commit 4c4c73d

Browse files
committed
refactor(netapp): Restructure NetApp Manager with layered architecture
Completely restructure the NetApp integration from a monolithic manager to a layered architecture with dependency injection, improving maintainability, testability, and extensibility. - Replace single `netapp_manager.py` with modular package - Introduce 4-layer architecture: Manager → Services → Client → SDK - Implement dependency injection for all components to help with testing - Add comprehensive error handling and configuration management ```text NetAppManager ├── SvmService ──────┐ ├── VolumeService ───┼── NetAppClient ── NetApp SDK ├── LifService ──────┘ ├── NetAppConfig └── ErrorHandler ``` Note: SDK is provided by NetApp, included here for visibility. - Replace complex SDK mocking with clean service interfaces - Add integration tests for cross-service coordination - All existing NetAppManager public methods unchanged - Same method signatures and return values - Existing code continues to work without modification - Enhanced error messages with structured context (will be useful when we get Sentry or similar solution) **Maintainability**: Clear separation of concerns with single responsibility **Testability**: Each layer tested in isolation with mock-friendly interfaces (no more `@patch` 10 times for a single test) **Extensibility**: New operations easily added at appropriate layer **Reliability**: Centralized error handling and structured logging
1 parent d533b3f commit 4c4c73d

27 files changed

+6128
-687
lines changed
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
# NetApp Manager Architecture
2+
3+
## Overview
4+
5+
The NetApp Manager uses a layered architecture with dependency injection, providing maintainability, testability, and separation of concerns.
6+
7+
## Architecture Layers
8+
9+
### 1. NetAppManager (Orchestration Layer)
10+
11+
- **File**: `netapp_manager.py`
12+
- **Purpose**: Orchestrates operations across multiple services
13+
- **Key Features**:
14+
- Maintains all existing public method signatures
15+
- Delegates operations to appropriate service layers
16+
- Handles cross-service coordination (e.g., cleanup operations)
17+
- Manages dependency injection for all services
18+
19+
### 2. Service Layer
20+
21+
- **Files**: `netapp_svm_service.py`, `netapp_volume_service.py`, `netapp_lif_service.py`
22+
- **Purpose**: Implements business logic and naming conventions for specific NetApp resource types
23+
- **Key Features**:
24+
- Encapsulates business rules (e.g., SVM naming: `os-{project_id}`)
25+
- Handles resource-specific operations and validation
26+
- Provides clean interfaces for the orchestration layer
27+
- 100% test coverage with mocked dependencies
28+
29+
### 3. Client Abstraction Layer
30+
31+
- **File**: `netapp_client.py`
32+
- **Purpose**: Provides a thin abstraction over the NetApp ONTAP SDK
33+
- **Key Features**:
34+
- Converts between value objects and SDK objects
35+
- Handles low-level NetApp API interactions
36+
- Implements the NetAppClientInterface for testability
37+
- Manages SDK connection lifecycle
38+
39+
### 4. Infrastructure Components
40+
41+
#### Configuration Management
42+
43+
- **File**: `netapp_config.py`
44+
- **Purpose**: Centralized configuration parsing and validation
45+
- **Features**: Type-safe configuration with validation
46+
47+
#### Error Handling
48+
49+
- **File**: `netapp_error_handler.py`
50+
- **Purpose**: Centralized error handling and logging
51+
- **Features**: Context-aware error translation and structured logging
52+
53+
#### Value Objects
54+
55+
- **File**: `netapp_value_objects.py`
56+
- **Purpose**: Immutable data structures for NetApp operations
57+
- **Features**: Type-safe specifications and results for all operations
58+
59+
#### Custom Exceptions
60+
61+
- **File**: `netapp_exceptions.py`
62+
- **Purpose**: Domain-specific exception hierarchy
63+
- **Features**: Structured error information with context
64+
65+
## Dependency Flow
66+
67+
```text
68+
NetAppManager
69+
├── SvmService ──────┐
70+
├── VolumeService ───┼── NetAppClient ── NetApp SDK
71+
├── LifService ──────┘
72+
├── NetAppConfig
73+
└── ErrorHandler
74+
```
75+
76+
## Key Benefits
77+
78+
### 1. Maintainability
79+
80+
- Clear separation of concerns
81+
- Single responsibility principle
82+
- Dependency injection enables easy component replacement
83+
84+
### 2. Testability
85+
86+
- Each layer can be tested in isolation
87+
- Service layer has 100% test coverage
88+
- Mock-friendly interfaces reduce test complexity
89+
90+
### 3. API Stability
91+
92+
- All existing NetAppManager public methods unchanged
93+
- Same method signatures and return values
94+
- Existing code continues to work without modification
95+
96+
### 4. Extensibility
97+
98+
- New NetApp operations can be added at the appropriate layer
99+
- Business logic changes isolated to service layer
100+
- SDK changes isolated to client layer
101+
102+
## Usage Examples
103+
104+
### Basic Usage (Unchanged)
105+
106+
```python
107+
# Existing code continues to work
108+
manager = NetAppManager("/path/to/config.conf")
109+
svm_name = manager.create_svm("project-123", "aggregate1")
110+
volume_name = manager.create_volume("project-123", "1TB", "aggregate1")
111+
```
112+
113+
### Advanced Usage with Dependency Injection
114+
115+
```python
116+
# For testing or custom configurations
117+
config = NetAppConfig("/custom/config.conf")
118+
error_handler = ErrorHandler()
119+
client = NetAppClient(config, error_handler)
120+
svm_service = SvmService(client, error_handler)
121+
122+
# Use services directly if needed
123+
svm_name = svm_service.create_svm("project-123", "aggregate1")
124+
```
125+
126+
## Testing Strategy
127+
128+
### Unit Tests
129+
130+
- Each service tested with mocked NetAppClient
131+
- Value objects tested for validation and immutability
132+
- Configuration and error handling tested independently
133+
134+
### Integration Tests
135+
136+
- NetAppManager tested with mocked services
137+
- Cross-service coordination tested (e.g., cleanup operations)
138+
- API compatibility verified
139+
140+
## Potential Future Enhancements
141+
142+
The new architecture enables several future improvements:
143+
144+
1. **Async Operations**: Service layer can be enhanced with async/await
145+
2. **Caching**: Client layer can add intelligent caching
146+
3. **Metrics**: Error handler can emit metrics for monitoring
147+
4. **Multi-tenancy**: Service layer can handle multiple NetApp clusters
148+
5. **Configuration Hot-reload**: Config layer can support dynamic updates

0 commit comments

Comments
 (0)