]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: rename test_enclosure to test_host_facts 58542/head
authorJohn Mulligan <jmulligan@redhat.com>
Mon, 10 Jun 2024 18:36:33 +0000 (14:36 -0400)
committerKonstantin Shalygin <k0ste@k0ste.ru>
Thu, 11 Jul 2024 16:33:37 +0000 (23:33 +0700)
There was a whole file dedicated to the enclosure class from host_facts,
but no other tests for host facts. Rename the enclosure test file to
cover all of host_facts module (for the future).

Signed-off-by: John Mulligan <jmulligan@redhat.com>
(cherry picked from commit 576f6cf93cab600f5b9744dab60f715ce4fe08e3)

src/cephadm/tests/test_enclosure.py [deleted file]
src/cephadm/tests/test_host_facts.py [new file with mode: 0644]

diff --git a/src/cephadm/tests/test_enclosure.py b/src/cephadm/tests/test_enclosure.py
deleted file mode 100644 (file)
index a48089f..0000000
+++ /dev/null
@@ -1,117 +0,0 @@
-import pytest
-
-from unittest import mock
-from tests.fixtures import host_sysfs, import_cephadm, cephadm_fs
-
-from cephadmlib.host_facts import Enclosure
-
-_cephadm = import_cephadm()
-
-
-@pytest.fixture
-def enclosure(host_sysfs):
-    e = Enclosure(
-        enc_id='1',
-        enc_path='/sys/class/scsi_generic/sg2/device/enclosure/0:0:1:0',
-        dev_path='/sys/class/scsi_generic/sg2',
-    )
-    yield e
-
-
-class TestEnclosure:
-
-    def test_enc_metadata(self, enclosure):
-        """Check metadata for the enclosure e.g. vendor and model"""
-
-        assert enclosure.vendor == "EnclosuresInc"
-        assert enclosure.components == '12'
-        assert enclosure.model == "D12"
-        assert enclosure.enc_id == '1'
-
-        assert enclosure.ses_paths == ['sg2']
-        assert enclosure.path_count == 1
-
-    def test_enc_slots(self, enclosure):
-        """Check slot count"""
-
-        assert len(enclosure.slot_map) == 12
-
-    def test_enc_slot_format(self, enclosure):
-        """Check the attributes of a slot are as expected"""
-
-        assert all(
-            k in ['fault', 'locate', 'serial', 'status']
-            for k, _v in enclosure.slot_map['0'].items()
-        )
-
-    def test_enc_slot_status(self, enclosure):
-        """Check the number of occupied slots is correct"""
-
-        occupied_slots = [
-            slot_id
-            for slot_id in enclosure.slot_map
-            if enclosure.slot_map[slot_id].get('status').upper() == 'OK'
-        ]
-
-        assert len(occupied_slots) == 6
-
-    def test_enc_disk_count(self, enclosure):
-        """Check the disks found matches the slot info"""
-
-        assert len(enclosure.device_lookup) == 6
-        assert enclosure.device_count == 6
-
-    def test_enc_device_serial(self, enclosure):
-        """Check the device serial numbers are as expected"""
-
-        assert all(
-            fake_serial in enclosure.device_lookup.keys()
-            for fake_serial in [
-                'fake000',
-                'fake001',
-                'fake002',
-                'fake003',
-                'fake004',
-                'fake005',
-            ]
-        )
-
-    def test_enc_slot_to_serial(self, enclosure):
-        """Check serial number to slot matches across slot_map and device_lookup"""
-
-        for serial, slot in enclosure.device_lookup.items():
-            assert enclosure.slot_map[slot].get('serial') == serial
-
-
-def test_host_facts_security(cephadm_fs):
-    cephadm_fs.create_file('/sys/kernel/security/lsm', contents='apparmor\n')
-    cephadm_fs.create_file('/etc/apparmor', contents='foo\n')
-    # List from https://tracker.ceph.com/issues/66389
-    profiles_lines = [
-        'foo (complain)',
-        '/usr/bin/man (enforce)',
-        '1password (unconfined)',
-        'Discord (unconfined)',
-        'MongoDB Compass (unconfined)',
-        'profile name with spaces (enforce)',
-    ]
-    cephadm_fs.create_file(
-        '/sys/kernel/security/apparmor/profiles',
-        contents='\n'.join(profiles_lines),
-    )
-
-    from cephadmlib.host_facts import HostFacts
-
-    class TestHostFacts(HostFacts):
-        def _populate_sysctl_options(self):
-            return {}
-
-    ctx = mock.MagicMock()
-    hfacts = TestHostFacts(ctx)
-    ksec = hfacts.kernel_security
-    assert ksec
-    assert ksec['type'] == 'AppArmor'
-    assert ksec['type'] == 'AppArmor'
-    assert ksec['complain'] == 0
-    assert ksec['enforce'] == 1
-    assert ksec['unconfined'] == 2
diff --git a/src/cephadm/tests/test_host_facts.py b/src/cephadm/tests/test_host_facts.py
new file mode 100644 (file)
index 0000000..a48089f
--- /dev/null
@@ -0,0 +1,117 @@
+import pytest
+
+from unittest import mock
+from tests.fixtures import host_sysfs, import_cephadm, cephadm_fs
+
+from cephadmlib.host_facts import Enclosure
+
+_cephadm = import_cephadm()
+
+
+@pytest.fixture
+def enclosure(host_sysfs):
+    e = Enclosure(
+        enc_id='1',
+        enc_path='/sys/class/scsi_generic/sg2/device/enclosure/0:0:1:0',
+        dev_path='/sys/class/scsi_generic/sg2',
+    )
+    yield e
+
+
+class TestEnclosure:
+
+    def test_enc_metadata(self, enclosure):
+        """Check metadata for the enclosure e.g. vendor and model"""
+
+        assert enclosure.vendor == "EnclosuresInc"
+        assert enclosure.components == '12'
+        assert enclosure.model == "D12"
+        assert enclosure.enc_id == '1'
+
+        assert enclosure.ses_paths == ['sg2']
+        assert enclosure.path_count == 1
+
+    def test_enc_slots(self, enclosure):
+        """Check slot count"""
+
+        assert len(enclosure.slot_map) == 12
+
+    def test_enc_slot_format(self, enclosure):
+        """Check the attributes of a slot are as expected"""
+
+        assert all(
+            k in ['fault', 'locate', 'serial', 'status']
+            for k, _v in enclosure.slot_map['0'].items()
+        )
+
+    def test_enc_slot_status(self, enclosure):
+        """Check the number of occupied slots is correct"""
+
+        occupied_slots = [
+            slot_id
+            for slot_id in enclosure.slot_map
+            if enclosure.slot_map[slot_id].get('status').upper() == 'OK'
+        ]
+
+        assert len(occupied_slots) == 6
+
+    def test_enc_disk_count(self, enclosure):
+        """Check the disks found matches the slot info"""
+
+        assert len(enclosure.device_lookup) == 6
+        assert enclosure.device_count == 6
+
+    def test_enc_device_serial(self, enclosure):
+        """Check the device serial numbers are as expected"""
+
+        assert all(
+            fake_serial in enclosure.device_lookup.keys()
+            for fake_serial in [
+                'fake000',
+                'fake001',
+                'fake002',
+                'fake003',
+                'fake004',
+                'fake005',
+            ]
+        )
+
+    def test_enc_slot_to_serial(self, enclosure):
+        """Check serial number to slot matches across slot_map and device_lookup"""
+
+        for serial, slot in enclosure.device_lookup.items():
+            assert enclosure.slot_map[slot].get('serial') == serial
+
+
+def test_host_facts_security(cephadm_fs):
+    cephadm_fs.create_file('/sys/kernel/security/lsm', contents='apparmor\n')
+    cephadm_fs.create_file('/etc/apparmor', contents='foo\n')
+    # List from https://tracker.ceph.com/issues/66389
+    profiles_lines = [
+        'foo (complain)',
+        '/usr/bin/man (enforce)',
+        '1password (unconfined)',
+        'Discord (unconfined)',
+        'MongoDB Compass (unconfined)',
+        'profile name with spaces (enforce)',
+    ]
+    cephadm_fs.create_file(
+        '/sys/kernel/security/apparmor/profiles',
+        contents='\n'.join(profiles_lines),
+    )
+
+    from cephadmlib.host_facts import HostFacts
+
+    class TestHostFacts(HostFacts):
+        def _populate_sysctl_options(self):
+            return {}
+
+    ctx = mock.MagicMock()
+    hfacts = TestHostFacts(ctx)
+    ksec = hfacts.kernel_security
+    assert ksec
+    assert ksec['type'] == 'AppArmor'
+    assert ksec['type'] == 'AppArmor'
+    assert ksec['complain'] == 0
+    assert ksec['enforce'] == 1
+    assert ksec['unconfined'] == 2