Fix pylint issues
Change-Id: I2bf1a1752693f2600e0fe62e30300e04706b6546
diff --git a/src/charm.py b/src/charm.py
index d56b608..67e0f34 100755
--- a/src/charm.py
+++ b/src/charm.py
@@ -14,14 +14,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+"""A StorPool backend charm for Cinder"""
+
import dataclasses
import logging
import pathlib
-from ops_openstack.plugins.classes import CinderStoragePluginCharm
-from ops_openstack.core import charm_class, get_charm_class
from ops.main import main
from ops.model import BlockedStatus
+from ops_openstack.core import charm_class, get_charm_class
+from ops_openstack.plugins.classes import CinderStoragePluginCharm
logger = logging.getLogger(__name__)
@@ -38,18 +40,23 @@
@classmethod
def from_config(cls, data) -> "StorPoolConfItems":
+ """Create an object from an options dictionary"""
args = {
field.name: str(data[field.name.replace("_", "-")]) for field in dataclasses.fields(cls)
}
return cls(**args)
def to_ini_key_value_pairs(self) -> str:
+ """Serialize to ini-style key-value pairs"""
return "".join(
f"{name.upper()}={value}\n" for name, value in dataclasses.asdict(self).items()
)
class CinderCharmBase(CinderStoragePluginCharm):
+ """
+ Base class for the StorPool charm
+ """
PACKAGES = ["charm-cinder-storpool-deps", "cinder-common"]
MANDATORY_CONFIG = [
@@ -64,9 +71,6 @@
stateless = True
active_active = True
- def __init__(self, *args, **kwargs):
- super().__init__(*args, **kwargs)
-
def on_config(self, event):
config = dict(self.framework.model.config)
conf_error = self._check_for_config_errors(config)
@@ -83,8 +87,12 @@
self._stored.is_started = True
- def cinder_configuration(self, config):
- conf_error = self._check_for_config_errors(config)
+ def custom_status_check(self):
+ """Overriding abstract, which is not used anywhere"""
+ return BlockedStatus("Should not be here")
+
+ def cinder_configuration(self, charm_config):
+ conf_error = self._check_for_config_errors(charm_config)
if conf_error is not None:
logger.error(conf_error)
self._stored.is_started = False
@@ -92,21 +100,21 @@
return []
# Return the configuration to be set by the principal.
- backend_name = config.get("volume-backend-name", self.framework.model.app.name)
+ backend_name = charm_config.get("volume-backend-name", self.framework.model.app.name)
volume_driver = "cinder.volume.drivers.storpool.StorPoolDriver"
options = [
("volume_driver", volume_driver),
("volume_backend_name", backend_name),
- ("storpool_template", config["storpool-template"]),
- ("sp_api_http_host", config["sp-api-http-host"]),
- ("sp_api_http_port", config["sp-api-http-port"]),
- ("sp_auth_token", config["sp-auth-token"]),
+ ("storpool_template", charm_config["storpool-template"]),
+ ("sp_api_http_host", charm_config["sp-api-http-host"]),
+ ("sp_api_http_port", charm_config["sp-api-http-port"]),
+ ("sp_auth_token", charm_config["sp-auth-token"]),
("iscsi_export_to", "*"),
- ("iscsi_portal_group", config["iscsi-portal-group"]),
+ ("iscsi_portal_group", charm_config["iscsi-portal-group"]),
]
- if config.get("use-multipath"):
+ if charm_config.get("use-multipath"):
options.extend(
[
("use_multipath_for_image_xfer", True),
@@ -114,7 +122,7 @@
]
)
- create_storpool_conf(StorPoolConfItems.from_config(config))
+ create_storpool_conf(StorPoolConfItems.from_config(charm_config))
self._stored.is_started = True
@@ -138,19 +146,26 @@
if config["protocol"] == "block":
return "'protocol' value 'block' not yet supported"
- if not (0 < config["sp-api-http-port"] < 65536):
+ if not 0 < config["sp-api-http-port"] < 65536:
return (
f"""'sp-api-http-port' ('{config["sp-api-http-port"]}')"""
"is not a valid port (0-65535)"
)
+ return None
+
@charm_class
class CinderStorPoolCharm(CinderCharmBase):
+ """
+ Actual class for the StorPool charm
+ """
+
release = "yoga"
def create_storpool_conf(sp_conf_items: StorPoolConfItems):
+ """Generate a storpool.conf with the provided options"""
pathlib.Path("/etc/storpool.conf").write_text(
"# Do not edit; this file is generated by the cinder-storpool charm.\n"
+ sp_conf_items.to_ini_key_value_pairs(),