| Server IP : 127.0.1.1 / Your IP : 216.73.216.173 Web Server : Apache/2.4.52 (Ubuntu) System : Linux bahcrestlinepropertiesllc 5.15.0-181-generic #191-Ubuntu SMP Fri May 22 19:09:02 UTC 2026 x86_64 User : www-data ( 33) PHP Version : 7.4.33 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /snap/lxd/current/lib/python3/dist-packages/ceph/tests/ |
Upload File : |
import datetime
import json
import os
import pytest
from ceph.deployment.inventory import Devices, Device
from ceph.utils import datetime_now
@pytest.mark.parametrize("filename",
[
os.path.dirname(__file__) + '/c-v-inventory.json',
os.path.dirname(__file__) + '/../../../pybind/mgr/test_orchestrator/du'
'mmy_data.json',
])
def test_from_json(filename):
with open(filename) as f:
data = json.load(f)
if 'inventory' in data:
data = data['inventory']
ds = Devices.from_json(data)
assert len(ds.devices) == len(data)
assert Devices.from_json(ds.to_json()) == ds
class TestDevicesEquality():
created_time1 = datetime_now()
created_time2 = created_time1 + datetime.timedelta(seconds=30)
@pytest.mark.parametrize(
"old_devices, new_devices, expected_equal",
[
( # identical list should be equal
Devices([Device('/dev/sdb', available=True, created=created_time1),
Device('/dev/sdc', available=True, created=created_time1)]),
Devices([Device('/dev/sdb', available=True, created=created_time1),
Device('/dev/sdc', available=True, created=created_time1)]),
True,
),
( # differing only in created time should still be equal
Devices([Device('/dev/sdb', available=True, created=created_time1),
Device('/dev/sdc', available=True, created=created_time1)]),
Devices([Device('/dev/sdb', available=True, created=created_time2),
Device('/dev/sdc', available=True, created=created_time2)]),
True,
),
( # differing in some other field should make them not equal
Devices([Device('/dev/sdb', available=True, created=created_time1),
Device('/dev/sdc', available=True, created=created_time1)]),
Devices([Device('/dev/sdb', available=False, created=created_time1),
Device('/dev/sdc', available=True, created=created_time1)]),
False,
),
( # different amount of devices should not pass equality
Devices([Device('/dev/sdb', available=True, created=created_time1),
Device('/dev/sdc', available=True, created=created_time1)]),
Devices([Device('/dev/sdb', available=True, created=created_time1),
Device('/dev/sdc', available=True, created=created_time1),
Device('/dev/sdd', available=True, created=created_time1)]),
False,
),
( # differing order should not affect equality
Devices([Device('/dev/sdb', available=True, created=created_time1),
Device('/dev/sdc', available=True, created=created_time1)]),
Devices([Device('/dev/sdc', available=True, created=created_time1),
Device('/dev/sdb', available=True, created=created_time1)]),
True,
),
])
def test_equality(self, old_devices, new_devices, expected_equal):
assert (old_devices == new_devices) == expected_equal