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(),
diff --git a/tests/tests.py b/tests/tests.py
index e5be7ca..20d9449 100644
--- a/tests/tests.py
+++ b/tests/tests.py
@@ -21,9 +21,10 @@
class CinderTestsStorPool(CinderTests):
+ """Subclass to skip broken tests"""
+
def test_105_volume_create_from_img(self):
self.skipTest("Skip until Glance is included in setup")
- pass
class CinderStorPoolTest(CinderBackendTest):
@@ -39,4 +40,3 @@
def test_cinder_config(self):
self.skipTest("Skip failing test")
- pass
diff --git a/unit_tests/test_cinder_storpool_charm.py b/unit_tests/test_cinder_storpool_charm.py
index 18880f5..3df5594 100644
--- a/unit_tests/test_cinder_storpool_charm.py
+++ b/unit_tests/test_cinder_storpool_charm.py
@@ -12,12 +12,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import mock
+"""Unit tests for the StorPool backend charm for Cinder"""
+
import unittest
-from src.charm import CinderCharmBase
+
+import mock
from ops.model import ActiveStatus, BlockedStatus
from ops.testing import Harness
+from src.charm import CinderCharmBase
BACKEND_NAME = "test"
STORPOOL_TEMPLATE = "test_template"
@@ -28,6 +31,12 @@
class TestCinderStorPoolCharm(unittest.TestCase):
+ """
+ Class that contains the StorPool charm unit tests
+ """
+
+ # pylint: disable=missing-function-docstring
+
def setUp(self):
self.harness = Harness(CinderCharmBase)
self.addCleanup(self.harness.cleanup)