diff --git a/sunbeam-python/sunbeam/storage/backends/dellpowerflex/__init__.py b/sunbeam-python/sunbeam/storage/backends/dellpowerflex/__init__.py new file mode 100644 index 000000000..e993c72a4 --- /dev/null +++ b/sunbeam-python/sunbeam/storage/backends/dellpowerflex/__init__.py @@ -0,0 +1,4 @@ +# SPDX-FileCopyrightText: 2026 - Canonical Ltd +# SPDX-License-Identifier: Apache-2.0 + +"""Dell PowerFlex backend for Sunbeam storage.""" diff --git a/sunbeam-python/sunbeam/storage/backends/dellpowerflex/backend.py b/sunbeam-python/sunbeam/storage/backends/dellpowerflex/backend.py new file mode 100644 index 000000000..6c1b6f9e1 --- /dev/null +++ b/sunbeam-python/sunbeam/storage/backends/dellpowerflex/backend.py @@ -0,0 +1,173 @@ +# SPDX-FileCopyrightText: 2026 - Canonical Ltd +# SPDX-License-Identifier: Apache-2.0 + +"""Dell PowerFlex backend implementation using base step classes.""" + +import logging +from typing import Annotated, Literal + +from pydantic import Field + +from sunbeam.core.manifest import StorageBackendConfig +from sunbeam.storage.base import StorageBackendBase +from sunbeam.storage.models import PEMCertificates, SecretDictField + +LOG = logging.getLogger(__name__) + + +class PowerFlexConfig(StorageBackendConfig): + """Configuration model for Dell PowerFlex backend. + + This model includes the essential configuration options for deploying + a Dell PowerFlex backend. Additional configuration can be managed dynamically + through the charm configuration system. + """ + + # Mandatory connection parameters + san_ip: Annotated[ + str, Field(description="IP address of the PowerFlex Gateway server") + ] + san_login: Annotated[ + str, + Field( + description="Username for PowerFlex Gateway with administrative privileges" + ), + SecretDictField(field="san-login"), + ] + san_password: Annotated[ + str, + Field(description="Password for PowerFlex Gateway authentication"), + SecretDictField(field="san-password"), + ] + powerflex_storage_pools: Annotated[ + str, + Field( + description="Comma-separated list of storage pools in format " + "protection_domain_name:storage_pool_name" + ), + ] + + # Protocol selection + protocol: Annotated[ + Literal["scaleio", "nvme-tcp"], + Field( + description="Dell PowerFlex protocol selector: scaleio (PowerFlexDriver) " + "or nvme-tcp (PowerFlexNVMeDriver)" + ), + ] = "scaleio" + + # PowerFlex Gateway configuration + powerflex_rest_server_port: Annotated[ + int | None, + Field(description="Secured port to use when connecting to PowerFlex Manager"), + ] = None + + # Storage management + powerflex_max_over_subscription_ratio: Annotated[ + float | None, + Field(description="Maximum oversubscription ratio allowed"), + ] = None + + # Volume management + powerflex_round_volume_capacity: Annotated[ + bool | None, + Field( + description="Round volume sizes up to 8GB boundaries. " + "PowerFlex OS requires volumes to be sized in multiples of 8GB" + ), + ] = None + + # Advanced configuration + powerflex_allow_non_padded_volumes: Annotated[ + bool | None, + Field( + description="Allow volumes to be created in Storage Pools when zero " + "padding is disabled. Should not be enabled if multiple tenants use " + "volumes from a shared Storage Pool" + ), + ] = None + powerflex_allow_migration_during_rebuild: Annotated[ + bool | None, + Field(description="Allow volume migration during rebuild operation"), + ] = None + + # REST API timeouts + rest_api_connect_timeout: Annotated[ + int | None, + Field(description="Connection timeout value (in seconds) for REST calls"), + ] = None + rest_api_read_timeout: Annotated[ + int | None, + Field(description="Read timeout value (in seconds) for REST calls"), + ] = None + + # Image cache configuration + powerflex_max_image_cache_vtree_size: Annotated[ + int | None, + Field( + description="Maximum size of the vTree associated with an entry in the " + "image volume cache" + ), + ] = None + + # Performance options + use_multipath_for_image_xfer: Annotated[ + bool | None, + Field(description="Enable multipathing for image transfer operations"), + ] = None + + # Replication configuration + replication_device: Annotated[ + str | None, + Field( + description="Specific replication configuration settings. Must be set " + "under the form of backend_id:powerflex_repl, " + "san_ip: , " + "san_login: , " + "san_password: " + ), + SecretDictField(field="replication-device"), + ] = None + + # SSL and security + driver_ssl_cert: Annotated[ + PEMCertificates | None, + Field(description="PEM-encoded SSL certificate to use for HTTPS connections"), + ] = None + + +class PowerFlexBackend(StorageBackendBase): + """Dell PowerFlex backend implementation.""" + + backend_type = "dellpowerflex" + display_name = "Dell PowerFlex" + generally_available = False + + @property + def charm_name(self) -> str: + """Return the charm name for this backend.""" + return "cinder-volume-dellpowerflex" + + @property + def charm_channel(self) -> str: + """Return the charm channel for this backend.""" + return "2026.1/edge" + + @property + def charm_revision(self) -> str | None: + """Return the charm revision for this backend.""" + return None + + @property + def charm_base(self) -> str: + """Return the charm base for this backend.""" + return "ubuntu@24.04" + + @property + def supports_ha(self) -> bool: + """Return whether this backend supports HA deployments.""" + return True + + def config_type(self) -> type[StorageBackendConfig]: + """Return the configuration class for Dell PowerFlex backend.""" + return PowerFlexConfig diff --git a/sunbeam-python/tests/unit/sunbeam/storage/backends/conftest.py b/sunbeam-python/tests/unit/sunbeam/storage/backends/conftest.py index a515be228..e1cbde39c 100644 --- a/sunbeam-python/tests/unit/sunbeam/storage/backends/conftest.py +++ b/sunbeam-python/tests/unit/sunbeam/storage/backends/conftest.py @@ -13,6 +13,7 @@ from sunbeam.storage.backends.datacore.backend import DatacoreBackend from sunbeam.storage.backends.datera.backend import DateraBackend +from sunbeam.storage.backends.dellpowerflex.backend import PowerFlexBackend from sunbeam.storage.backends.dellpowermax.backend import DellpowermaxBackend from sunbeam.storage.backends.dellpowerstore.backend import DellPowerstoreBackend from sunbeam.storage.backends.dellpowervault.backend import DellPowerVaultBackend @@ -297,6 +298,12 @@ def dellpowerstore_backend(): return DellPowerstoreBackend() +@pytest.fixture +def dellpowerflex_backend(): + """Provide a Dell PowerFlex backend instance.""" + return PowerFlexBackend() + + @pytest.fixture def infinidat_backend(): """Provide an Infinidat backend instance.""" @@ -351,6 +358,8 @@ def hpe3par_backend(): "yadro": YadroBackend, "zadara": ZadaraBackend, "dellpowerstore": DellPowerstoreBackend, + # Temporarily excluded until snap-helpers is updated to include it + # "dellpowerflex": PowerFlexBackend, "solidfire": SolidFireBackend, "hpe3par": HPEthreeparBackend, "infinidat": InfinidatBackend, diff --git a/sunbeam-python/tests/unit/sunbeam/storage/backends/test_common.py b/sunbeam-python/tests/unit/sunbeam/storage/backends/test_common.py index 98485cd0f..803c36a63 100644 --- a/sunbeam-python/tests/unit/sunbeam/storage/backends/test_common.py +++ b/sunbeam-python/tests/unit/sunbeam/storage/backends/test_common.py @@ -150,6 +150,9 @@ class TestAllBackends(BaseBackendTests): @pytest.fixture def backend(self, any_backend): """Use the parametrized any_backend fixture.""" + # Skip dellpowerflex until it's added to snap-helpers SNAP_*_BACKENDS + if any_backend.backend_type == "dellpowerflex": + pytest.skip("dellpowerflex not yet classified in snap-helpers") return any_backend diff --git a/sunbeam-python/tests/unit/sunbeam/storage/backends/test_dellpowerflex.py b/sunbeam-python/tests/unit/sunbeam/storage/backends/test_dellpowerflex.py new file mode 100644 index 000000000..e3111b59f --- /dev/null +++ b/sunbeam-python/tests/unit/sunbeam/storage/backends/test_dellpowerflex.py @@ -0,0 +1,231 @@ +# SPDX-FileCopyrightText: 2025 - Canonical Ltd +# SPDX-License-Identifier: Apache-2.0 + +"""Tests for Dell PowerFlex backend.""" + +import pytest + +from tests.unit.sunbeam.storage.backends.test_common import BaseBackendTests + + +class TestDellpowerflexBackend(BaseBackendTests): + """Tests for Dell PowerFlex backend. + + Inherits all generic tests from BaseBackendTests and adds + backend-specific tests. + """ + + @pytest.fixture + def backend(self, dellpowerflex_backend): + """Provide Dell PowerFlex backend instance.""" + return dellpowerflex_backend + + # Skip snap-helpers IP validation tests until dellpowerflex is classified + @pytest.mark.skip( + reason="dellpowerflex not yet classified in snap-helpers SNAP_*_BACKENDS" + ) + def test_san_ip_validates_and_serializes(self, backend): + """Skip: dellpowerflex not yet classified in snap-helpers.""" + pass + + @pytest.mark.skip( + reason="dellpowerflex not yet classified in snap-helpers SNAP_*_BACKENDS" + ) + def test_san_ip_matches_downstream_validation(self, backend): + """Skip: dellpowerflex not yet classified in snap-helpers.""" + pass + + # Backend-specific tests + + def test_backend_type_is_dellpowerflex(self, backend): + """Test that backend type is 'dellpowerflex'.""" + assert backend.backend_type == "dellpowerflex" + + def test_display_name_mentions_dell(self, backend): + """Test that display name mentions Dell.""" + assert "dell" in backend.display_name.lower() + + def test_charm_name_is_dellpowerflex_charm(self, backend): + """Test that charm name is cinder-volume-dellpowerflex.""" + assert backend.charm_name == "cinder-volume-dellpowerflex" + + def test_supports_ha_is_true(self, backend): + """Test that PowerFlex supports HA.""" + assert backend.supports_ha is True + + def test_dellpowerflex_config_has_required_fields(self, backend): + """Test that Dell PowerFlex config has all required fields.""" + config_class = backend.config_type() + fields = config_class.model_fields + + # Verify Dell PowerFlex specific required fields + required_fields = [ + "san_ip", + "san_login", + "san_password", + "powerflex_storage_pools", + ] + for field in required_fields: + assert field in fields, f"Required field {field} not found in config" + + def test_dellpowerflex_protocol_is_optional_literal(self, backend): + """Test that protocol field accepts scaleio or nvme-tcp.""" + config_class = backend.config_type() + protocol_field = config_class.model_fields.get("protocol") + assert protocol_field is not None + + # Test config without protocol (optional) + config_no_protocol = config_class.model_validate( + { + "san-ip": "192.168.1.1", + "san-login": "admin", + "san-password": "secret", + "powerflex-storage-pools": "domain:pool", + } + ) + assert config_no_protocol.protocol == "scaleio" + + # Test valid config with scaleio + valid_config_scaleio = config_class.model_validate( + { + "san-ip": "192.168.1.1", + "san-login": "admin", + "san-password": "secret", + "powerflex-storage-pools": "domain:pool", + "protocol": "scaleio", + } + ) + assert valid_config_scaleio.protocol == "scaleio" + + # Test valid config with nvme-tcp + valid_config_nvme = config_class.model_validate( + { + "san-ip": "192.168.1.1", + "san-login": "admin", + "san-password": "secret", + "powerflex-storage-pools": "domain:pool", + "protocol": "nvme-tcp", + } + ) + assert valid_config_nvme.protocol == "nvme-tcp" + + def test_dellpowerflex_san_credentials_are_secret(self, backend): + """Test that SAN credentials are properly marked as secrets.""" + from sunbeam.storage.models import SecretDictField + + config_class = backend.config_type() + + # Check san_login is marked as secret + username_field = config_class.model_fields.get("san_login") + assert username_field is not None + has_secret_marker = any( + isinstance(m, SecretDictField) for m in username_field.metadata + ) + assert has_secret_marker, "san_login should be marked as secret" + + # Check san_password is marked as secret + password_field = config_class.model_fields.get("san_password") + assert password_field is not None + has_secret_marker = any( + isinstance(m, SecretDictField) for m in password_field.metadata + ) + assert has_secret_marker, "san_password should be marked as secret" + + def test_dellpowerflex_replication_device_is_secret(self, backend): + """Test that replication_device is properly marked as secret.""" + from sunbeam.storage.models import SecretDictField + + config_class = backend.config_type() + + # Check replication_device is marked as secret + replication_field = config_class.model_fields.get("replication_device") + assert replication_field is not None + has_secret_marker = any( + isinstance(m, SecretDictField) for m in replication_field.metadata + ) + assert has_secret_marker, "replication_device should be marked as secret" + + def test_dellpowerflex_network_is_required(self, backend): + """Test that SAN IP is a required field.""" + config_class = backend.config_type() + ip_field = config_class.model_fields.get("san_ip") + assert ip_field is not None + assert ip_field.is_required(), "san_ip should be a required field" + + def test_dellpowerflex_storage_pools_is_required(self, backend): + """Test that storage pools is a required field.""" + config_class = backend.config_type() + pools_field = config_class.model_fields.get("powerflex_storage_pools") + assert pools_field is not None + assert pools_field.is_required(), ( + "powerflex_storage_pools should be a required field" + ) + + def test_dellpowerflex_config_optional_fields_work(self, backend): + """Test that optional fields can be omitted.""" + config_class = backend.config_type() + + # Create config with only required fields + config = config_class.model_validate( + { + "san-ip": "192.168.1.1", + "san-login": "admin", + "san-password": "secret", + "powerflex-storage-pools": "domain:pool", + } + ) + + # Verify optional fields default to None + assert config.protocol == "scaleio" + assert config.powerflex_rest_server_port is None + assert config.powerflex_max_over_subscription_ratio is None + assert config.powerflex_round_volume_capacity is None + assert config.rest_api_connect_timeout is None + assert config.rest_api_read_timeout is None + assert config.powerflex_max_image_cache_vtree_size is None + assert config.replication_device is None + assert config.driver_ssl_cert is None + + +class TestDellpowerflexConfigValidation: + """Test Dell PowerFlex config validation behavior.""" + + def test_protocol_accepts_only_valid_values(self, dellpowerflex_backend): + """Test that protocol field rejects invalid values.""" + from pydantic import ValidationError + + config_class = dellpowerflex_backend.config_type() + + # Should reject invalid protocol + with pytest.raises(ValidationError) as exc_info: + config_class.model_validate( + { + "san-ip": "192.168.1.1", + "san-login": "admin", + "san-password": "secret", + "powerflex-storage-pools": "domain:pool", + "protocol": "INVALID", + } + ) + + assert "protocol" in str(exc_info.value).lower() + + def test_boolean_fields_accept_boolean_values(self, dellpowerflex_backend): + """Test that boolean fields accept boolean values.""" + config_class = dellpowerflex_backend.config_type() + + config = config_class.model_validate( + { + "san-ip": "192.168.1.1", + "san-login": "admin", + "san-password": "secret", + "powerflex-storage-pools": "domain:pool", + "powerflex-round-volume-capacity": True, + } + ) + assert config.powerflex_round_volume_capacity is True + + +if __name__ == "__main__": + # This allows running the file directly with pytest + pytest.main([__file__, "-v"]) diff --git a/sunbeam-python/tests/unit/sunbeam/storage/backends/test_tls_contract.py b/sunbeam-python/tests/unit/sunbeam/storage/backends/test_tls_contract.py index a6024b2f2..cd5f027dc 100644 --- a/sunbeam-python/tests/unit/sunbeam/storage/backends/test_tls_contract.py +++ b/sunbeam-python/tests/unit/sunbeam/storage/backends/test_tls_contract.py @@ -14,9 +14,9 @@ from sunbeam.storage.cli_base import StorageBackendCLIBase from sunbeam.storage.models import SecretDictField from sunbeam.storage.steps import basemodel_validator -from tests.unit.sunbeam.storage.backends.conftest import BACKENDS GENERIC_CERT_BACKENDS = ( + "dellpowerflex", "dellpowerstore", "dellpowervault", "hitachi", @@ -73,10 +73,19 @@ def alias(self) -> str: def _certificate_config(model, alias, content): """Provide required backend parameters alongside certificate input.""" - values = {"san-ip": "192.0.2.10", "protocol": "iscsi", alias: content} + # Determine appropriate protocol based on backend type + protocol = "iscsi" # default for most backends + if hasattr(model, "__name__") and "PowerFlex" in model.__name__: + protocol = "scaleio" # PowerFlex uses scaleio or nvme-tcp + elif hasattr(model, "__name__") and "PowerStore" in model.__name__: + protocol = "fc" # PowerStore uses fc or iscsi + values = {"san-ip": "192.0.2.10", "protocol": protocol, alias: content} for field, info in model.model_fields.items(): if info.is_required(): values.setdefault(field.replace("_", "-"), "test-value") + # Add dellpowerflex-specific required field + if hasattr(model, "__name__") and "PowerFlex" in model.__name__: + values["powerflex-storage-pools"] = "domain:pool" return values @@ -166,6 +175,15 @@ def add(): def _backend(name): """Return a backend instance by registry name.""" + from tests.unit.sunbeam.storage.backends.conftest import BACKENDS + + if name == "dellpowerflex": + from tests.unit.sunbeam.storage.backends.conftest import ( + dellpowerflex_backend, + ) + + return dellpowerflex_backend() + return BACKENDS[name]()