From d8d66cf57615c8ea6f7357742fece962e46927b7 Mon Sep 17 00:00:00 2001 From: Chris MacNaughton Date: Mon, 28 Mar 2022 12:59:10 +0200 Subject: [PATCH] Update for lint and unit test errors --- .flake8 | 2 ++ src/charm.py | 3 ++- src/ganesha.py | 5 ++--- tests/nfs_ganesha.py | 1 - unit_tests/test_ceph_nfs_charm.py | 6 +++--- unit_tests/test_ganesha.py | 29 +++++++++++++++-------------- 6 files changed, 24 insertions(+), 22 deletions(-) diff --git a/.flake8 b/.flake8 index 8ef84fc..293e63b 100644 --- a/.flake8 +++ b/.flake8 @@ -7,3 +7,5 @@ exclude: build dist *.egg_info + # Excluded because it is imported almost verbatim from Manila + src/manager.py \ No newline at end of file diff --git a/src/charm.py b/src/charm.py index 7790418..126ed3a 100755 --- a/src/charm.py +++ b/src/charm.py @@ -417,7 +417,8 @@ class CephNFSCharm( name = event.params.get('name') allowed_ips = event.params.get('allowed-ips') allowed_ips = [ip.strip() for ip in allowed_ips.split(',')] - export_path = self.ganesha_client.create_share(size=share_size, name=name, access_ips=allowed_ips) + export_path = self.ganesha_client.create_share( + size=share_size, name=name, access_ips=allowed_ips) if not export_path: event.fail("Failed to create share, check the log for more details") return diff --git a/src/ganesha.py b/src/ganesha.py index f856092..9997488 100644 --- a/src/ganesha.py +++ b/src/ganesha.py @@ -93,7 +93,6 @@ class Export(object): class GaneshaNFS(object): - export_index = "ganesha-export-index" export_counter = "ganesha-export-counter" @@ -261,8 +260,8 @@ class GaneshaNFS(object): :param name: String name of the share to create """ self._ceph_subvolume_command( - 'deauthorize', 'ceph-fs', name, - 'ganesha-{name}'.format(name=name)) + 'deauthorize', 'ceph-fs', name, + 'ganesha-{name}'.format(name=name)) self._ceph_subvolume_command('rm', 'ceph-fs', name) def _create_cephfs_share(self, name: str, size_in_bytes: int = None): diff --git a/tests/nfs_ganesha.py b/tests/nfs_ganesha.py index a1bbf76..42bd962 100644 --- a/tests/nfs_ganesha.py +++ b/tests/nfs_ganesha.py @@ -17,7 +17,6 @@ import logging import subprocess import tenacity -import time from typing import Dict import unittest import yaml diff --git a/unit_tests/test_ceph_nfs_charm.py b/unit_tests/test_ceph_nfs_charm.py index c989315..6b92a60 100644 --- a/unit_tests/test_ceph_nfs_charm.py +++ b/unit_tests/test_ceph_nfs_charm.py @@ -12,7 +12,7 @@ sys.path.append('src') # noqa from unittest.mock import patch, Mock -from charm import CephNfsCharm +from charm import CephNFSCharm # from ops.model import ActiveStatus from ops.testing import Harness @@ -40,7 +40,7 @@ class CharmTestCase(unittest.TestCase): setattr(self, method, self.patch(method)) -class _CephNfsCharm(CephNfsCharm): +class _CephNFSCharm(CephNFSCharm): @staticmethod def get_bluestore_compression(): @@ -58,7 +58,7 @@ class TestCephNFSCharmBase(CharmTestCase): def setUp(self): super().setUp(charm, self.PATCHES) self.harness = Harness( - _CephNfsCharm, + _CephNFSCharm, ) self.addCleanup(self.harness.cleanup) diff --git a/unit_tests/test_ganesha.py b/unit_tests/test_ganesha.py index a1354ff..2ad4008 100644 --- a/unit_tests/test_ganesha.py +++ b/unit_tests/test_ganesha.py @@ -43,35 +43,36 @@ class ExportTest(unittest.TestCase): def test_add_client(self): export = ganesha.Export.from_export(EXAMPLE_EXPORT) - export.add_client('10.0.0.0/8', 'rw') + export.add_client('10.0.0.0/8') self.assertEqual( export.clients, [{'Access_Type': 'rw', 'Clients': '0.0.0.0, 10.0.0.0/8'}]) # adding again shouldn't duplicate export - export.add_client('10.0.0.0/8', 'rw') + export.add_client('10.0.0.0/8') self.assertEqual( export.clients, [{'Access_Type': 'rw', 'Clients': '0.0.0.0, 10.0.0.0/8'}]) - export.add_client('192.168.0.0/16', 'r') + export.add_client('192.168.0.0/16') self.assertEqual( export.clients, - [{'Access_Type': 'r', 'Clients': '192.168.0.0/16'}, - {'Access_Type': 'rw', 'Clients': '0.0.0.0, 10.0.0.0/8'}, - ]) + [{ + 'Access_Type': 'rw', 'Clients': '0.0.0.0, 10.0.0.0/8, 192.168.0.0/16' + }]) def test_remove_client(self): export = ganesha.Export.from_export(EXAMPLE_EXPORT) - export.add_client('10.0.0.0/8', 'rw') - export.add_client('192.168.0.0/16', 'r') + export.add_client('10.0.0.0/8') + export.add_client('192.168.0.0/16') self.assertEqual( export.clients, - [{'Access_Type': 'r', 'Clients': '192.168.0.0/16'}, - {'Access_Type': 'rw', 'Clients': '0.0.0.0, 10.0.0.0/8'}, - ]) + [{ + 'Access_Type': 'rw', + 'Clients': '0.0.0.0, 10.0.0.0/8, 192.168.0.0/16' + }]) export.remove_client('0.0.0.0') self.assertEqual( export.clients, - [{'Access_Type': 'r', 'Clients': '192.168.0.0/16'}, - {'Access_Type': 'rw', 'Clients': '10.0.0.0/8'}, - ]) + [ + {'Access_Type': 'rw', 'Clients': '10.0.0.0/8, 192.168.0.0/16'}, + ])