Skip to content

feat(storage): Add external storage backend integration via Sunbeam CLI#544

Open
happyhackerhour wants to merge 8 commits into
canonical:mainfrom
happyhackerhour:feat/storage-cli
Open

feat(storage): Add external storage backend integration via Sunbeam CLI#544
happyhackerhour wants to merge 8 commits into
canonical:mainfrom
happyhackerhour:feat/storage-cli

Conversation

@happyhackerhour
Copy link
Copy Markdown

@happyhackerhour happyhackerhour commented Jul 22, 2025

Sunbeam Storage Backend Management

Summary

This PR introduces a comprehensive storage backend management system for Sunbeam with full unit testing coverage. It provides a clean, maintainable framework for managing Cinder storage backends, starting with Hitachi VSP support, featuring separated CLI architecture, dynamic configuration management, and 1029+ tests ensuring reliability.

Context & Related Work

Builds on:

Key Changes

1. Storage Backend Framework (sunbeam/storage/)

  • base.py - Core service layer with StorageBackendService and proper CLI registration hooks
  • registry.py - Dynamic backend discovery and CLI registration with plugin architecture
  • service.py - Centralized Terraform state management and backend existence checking
  • steps.py - Deployment workflow with comprehensive error handling
  • Exception hierarchy for robust error handling and user feedback

2. Hitachi VSP Backend (sunbeam/storage/backends/hitachi/)

  • backend.py - Core deployment and management logic with HitachiConfig Pydantic model
  • cli.py - Dedicated CLI commands with proper separation of concerns
  • 6 essential deployment fields with comprehensive validation
  • IP/FQDN validation with proper error handling
  • Protocol selection (FC/iSCSI) with validation
  • Configuration filtering logic to prevent sensitive data exposure

3. Dynamic Configuration Management

  • get_backend_config() - Retrieve current configuration with filtering
  • CLI-based configuration management with rich console integration
  • Sensitive value masking for security (passwords, secrets)
  • Service layer delegation for all Terraform state operations
  • Validation and error handling for configuration updates

CLI Commands

Backend Management

# Deploy backend
sunbeam storage add <backend>                              # Interactive deployment
sunbeam storage add <backend> --name <name> [options]     # Non-interactive deployment
sunbeam storage remove <backend> <name>                   # Remove existing backend  
sunbeam storage list all                                # List all backends

Configuration Management

# Configuration operations
sunbeam storage config show <backend> <name>              # View current configuration
sunbeam storage config set <backend> <name> [options]           # Update configuration
sunbeam storage config reset <backend> <name> [keys]     # Reset specific keys
sunbeam storage config options <backend>                 # List available options

Example Usage

Deploy Backend

Interactive deployment:

$ sunbeam storage add hitachi
SAN Management IP: 192.168.1.100
SAN Username: maintenance  
Storage Pools: pool1,pool2
Protocol: FC

✅ Successfully deployed Hitachi backend 'production-hitachi'

Direct deployment with parameters:

$ sunbeam storage add hitachi --name vsp350 \
    --san-ip=192.168.1.100 \
    --san-username=maintenance \
    --san-password=12345 \
    --hitachi-pools=pool1,pool2 \
    --protocol=FC \
    --hitachi-storage-id=123123123

Manage Configuration

View configuration:

$ sunbeam storage config show hitachi vsp350
┏━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━┓
┃ Configuration Key  ┃ Value              ┃
┡━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━┩
│ san-ip             │ 192.168.1.100      │
│ san-login          │ maintenance        │
│ hitachi-pools      │ pool1,pool2        │
│ protocol           │ FC                 │
│ san-password       │ ********           │
└────────────────────┴────────────────────┘

Update configuration:

$ sunbeam storage config set hitachi vsp350 --hitachi-copy-speed=3
✅ Configuration updated successfully

List available options:

$ sunbeam storage config options hitachi
Available configuration options for Hitachi VSP Storage:
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ Option                       ┃ Description                                       ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ san-ip                       │ SAN management IP address or FQDN                │
│ san-login                    │ SAN management username                          │
│ san-password                 │ SAN management password                          │
│ hitachi-pools                │ Comma-separated list of storage pools            │
│ protocol                     │ Storage protocol (FC or iSCSI)                   │
│ hitachi-copy-speed           │ Copy speed for volume operations (1-15)          │
└──────────────────────────────┴───────────────────────────────────────────────────┘

@happyhackerhour happyhackerhour force-pushed the feat/storage-cli branch 4 times, most recently from a79d504 to 73f7b79 Compare July 23, 2025 21:45
@happyhackerhour happyhackerhour changed the title feat(commands): add storage CLI (Hitachi & default Ceph) feat(storage): Add Hitachi VSP backend integration via Sunbeam CLI Jul 23, 2025
@happyhackerhour happyhackerhour force-pushed the feat/storage-cli branch 14 times, most recently from 3288a99 to a4161b5 Compare July 28, 2025 19:29
@happyhackerhour happyhackerhour marked this pull request as ready for review July 28, 2025 20:06
Copy link
Copy Markdown
Collaborator

@wolsen wolsen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm currently making some inflight comments. I have not had a chance to perform an exhaustive review.

Comment thread sunbeam-python/sunbeam/commands/storage.py Outdated
Comment thread sunbeam-python/sunbeam/commands/storage.py Outdated
Comment thread sunbeam-python/tests/unit/sunbeam/storage/test_storage_simple.py Outdated
Comment thread sunbeam-python/sunbeam/storage/base.py Outdated
Comment thread sunbeam-python/sunbeam/storage/backends/hitachi/backend.py
Comment thread sunbeam-python/sunbeam/storage/registry.py Outdated
Comment thread sunbeam-python/sunbeam/commands/storage.py Outdated
Comment thread sunbeam-python/sunbeam/storage/registry.py Outdated
Comment thread sunbeam-python/sunbeam/storage/steps.py Outdated
Comment thread sunbeam-python/sunbeam/storage/steps.py Outdated
Comment thread sunbeam-python/sunbeam/storage/base.py Outdated
Comment thread sunbeam-python/sunbeam/storage/steps.py Outdated
@gboutry
Copy link
Copy Markdown
Collaborator

gboutry commented Aug 1, 2025

My main comment was lost with that whole shebang of pending review...

This is overall a nice work, and thank you very much for your contribution.

Can you ensure this is inline with the rest of the code base?
Can you reduce the use of emojis?
Can you format the code? There are a lot of trailing whitespaces.

@wolsen wolsen requested a review from Copilot August 1, 2025 15:39
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a comprehensive storage backend management system for Sunbeam, featuring Terraform-managed Hitachi VSP support, dynamic backend discovery via a pluggable registry, and robust unit testing coverage with 109 tests. The implementation provides CLI commands for storage backend deployment, configuration management, and lifecycle operations.

Key changes:

  • Storage backend framework with base classes, service layer, and registry system for dynamic backend discovery
  • Hitachi VSP backend implementation with complete Terraform deployment and credential management via Juju secrets
  • CLI integration providing commands for add, remove, list, and config operations with both interactive and inline configuration modes

Reviewed Changes

Copilot reviewed 24 out of 26 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
sunbeam/storage/base.py Base classes and interfaces for storage backend implementations with Terraform integration
sunbeam/storage/backends/hitachi/backend.py Complete Hitachi VSP backend implementation with configuration model and deployment steps
sunbeam/storage/backends/hitachi/deploy-hitachi-backend/main.tf Terraform configuration for Hitachi backend deployment with Juju secrets management
sunbeam/storage/registry.py Dynamic backend discovery and CLI command registration system
sunbeam/storage/service.py Service layer for backend operations and configuration management
sunbeam/storage/steps.py Base step classes for deployment, destruction, and configuration update workflows
sunbeam/commands/storage.py CLI commands for storage backend management
tests/unit/sunbeam/storage/ Comprehensive unit test suite with 109 tests covering all modules
Comments suppressed due to low confidence (2)

sunbeam-python/sunbeam/storage/steps.py:24

  • Import error: BackendNotFoundException is imported from .models but according to the models.py file, this exception should be imported from .models which is correct. However, there's also an import from sunbeam.storage.models on line 25 which creates a redundant import structure. The imports should be consolidated.
from sunbeam.storage.models import BackendNotFoundException

sunbeam-python/sunbeam/storage/backends/hitachi/deploy-hitachi-backend/main.tf:8

  • The Juju Terraform provider version "= 0.20.0" may not exist or may be outdated. Consider using a more recent or verified version, or use a version constraint like "~> 0.20" to allow patch updates.
      version = "= 0.20.0"

Comment thread sunbeam-python/sunbeam/storage/steps.py Outdated
Comment thread sunbeam-python/sunbeam/storage/backends/hitachi/backend.py Outdated
Comment thread sunbeam-python/sunbeam/storage/backends/hitachi/backend.py Outdated
Comment thread sunbeam-python/tests/unit/sunbeam/storage/test_basestorage.py Outdated
@happyhackerhour happyhackerhour force-pushed the feat/storage-cli branch 2 times, most recently from 061e4a2 to 9d2e7ed Compare August 1, 2025 23:39
@happyhackerhour
Copy link
Copy Markdown
Author

happyhackerhour commented Aug 11, 2025

Hi team,

I’ve finished the requested fixes and rewrites, doing my best to align with the current style and patterns across the project.

I appreciate your time and effort in reviewing this work!

@happyhackerhour happyhackerhour force-pushed the feat/storage-cli branch 3 times, most recently from 6841354 to 0bce6e1 Compare August 13, 2025 13:37
@happyhackerhour happyhackerhour marked this pull request as draft August 13, 2025 16:27
reimplement Unit testing to conform to new signatures and changes to use terraform
- Fix partial removal regression: write updated Terraform variables before apply
- Remove global registry instance, follow Provider pattern for CLI registration
- Add Juju application name validation to prevent invalid backend names
- Implement atomic removal operations with proper rollback on failure
- Add cleanup-config command to resolve invalid backend configurations
- Improve error handling and logging throughout storage backend system
- Update deprecated Pydantic __fields__ usage for v2 compatibility
- Consolidate imports and reduce emoji usage in console output
@happyhackerhour happyhackerhour force-pushed the feat/storage-cli branch 3 times, most recently from d245143 to 42f3917 Compare August 14, 2025 13:55
- Move CLI code to dedicated module (hitachi/cli.py) with proper separation
- Remove duplicate backend_exists() methods, consolidate in service layer
- Eliminate unused service methods (set/reset_backend_config) and tests
- Refactor duplicate config filtering logic into reusable internal function
- Clean up storage backend __init__.py files to match provider pattern
- Update all CLI and backend code to use service layer properly
- Fix missing abstract method implementations in test mocks
- Update test mocking to reflect architectural changes

All tests pass (1029/1029) with clean, maintainable, well-structured codebase.

Signed-off-by: Hugo Vinicius Garcia Razera <root@happyhackerhour.net>
@happyhackerhour happyhackerhour marked this pull request as ready for review August 14, 2025 18:50
- Shows friendly error messege on state locks
- Verify juju login status, before add and remove.

Signed-off-by: Hugo Vinicius Garcia Razera <root@happyhackerhour.net>
@happyhackerhour happyhackerhour changed the title feat(storage): Add Hitachi VSP backend integration via Sunbeam CLI feat(storage): Add backend integration via Sunbeam CLI Aug 20, 2025
@happyhackerhour happyhackerhour changed the title feat(storage): Add backend integration via Sunbeam CLI feat(storage): Add external storage backend integration via Sunbeam CLI Aug 21, 2025
@happyhackerhour happyhackerhour force-pushed the feat/storage-cli branch 2 times, most recently from dd845cc to f2e54aa Compare August 25, 2025 14:14
- Implement PureStorage Backend
- separate terraforms-key for each backend
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants