]>
git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/progress/test_progress.py
ef4e7e166180571faf51bda6ff191e3e238cea94
9 os
.environ
['UNITTEST'] = "1"
10 sys
.path
.insert(0, "../../pybind/mgr")
11 from progress
import module
13 class TestPgRecoveryEvent(object):
14 # Testing PgRecoveryEvent class
17 # Creating the class and Mocking
18 # a bunch of attributes for testing
19 module
._module
= mock
.Mock() # just so Event._refresh() works
20 self
.test_event
= module
.PgRecoveryEvent(None, None, [module
.PgId(1,i
) for i
in range(3)], [0], 30, False)
22 def test_pg_update(self
):
23 # Test for a completed event when the pg states show active+clean
27 "state": "active+clean",
29 "num_bytes_recovered": 10,
33 "state": "active+clean",
35 "num_bytes_recovered": 10,
39 "state": "active+clean",
41 "num_bytes_recovered": 10,
47 self
.test_event
.pg_update(pg_progress
, mock
.Mock())
48 assert self
.test_event
._progress
== 1.0
53 # This is an artificial class to help
54 # _osd_in_out function have all the
55 # necessary characteristics, some
56 # of the funcitons are copied from
59 def __init__(self
, dump
, pg_stats
):
61 self
._pg
_stats
= pg_stats
63 def _pg_to_up_acting_osds(self
, pool_id
, ps
):
64 pg_id
= str(pool_id
) + "." + str(ps
)
65 for pg
in self
._pg
_stats
["pg_stats"]:
66 if pg
["pg_id"] == pg_id
:
68 "up_primary": pg
["up_primary"],
69 "acting_primary": pg
["acting_primary"],
71 "acting": pg
["acting"]
80 return dict([(p
['pool'], p
) for p
in d
['pools']])
82 def get_pools_by_name(self
):
84 return dict([(p
['pool_name'], p
) for p
in d
['pools']])
86 def pg_to_up_acting_osds(self
, pool_id
, ps
):
87 return self
._pg
_to
_up
_acting
_osds
(pool_id
, ps
)
90 class TestModule(object):
91 # Testing Module Class
94 # Creating the class and Mocking a
95 # bunch of attributes for testing
97 module
.PgRecoveryEvent
.pg_update
= mock
.Mock()
98 module
.Module
._ceph
_get
_option
= mock
.Mock() # .__init__
99 module
.Module
._configure
_logging
= lambda *args
: ... # .__init__
100 self
.test_module
= module
.Module('module_name', 0, 0) # so we can see if an event gets created
101 self
.test_module
.get
= mock
.Mock() # so we can call pg_update
102 self
.test_module
._complete
= mock
.Mock() # we want just to see if this event gets called
103 self
.test_module
.get_osdmap
= mock
.Mock() # so that self.get_osdmap().get_epoch() works
104 module
._module
= mock
.Mock() # so that Event.refresh() works
106 def test_osd_in_out(self
):
107 # test for the correct event being
108 # triggered and completed.
165 new_map
= OSDMap(new_dump
, new_pg_stats
)
166 old_map
= OSDMap(old_dump
, old_pg_stats
)
167 self
.test_module
._osd
_in
_out
(old_map
, old_dump
, new_map
, 3, "out")
168 # check if only one event is created
169 assert len(self
.test_module
._events
) == 1
170 self
.test_module
._osd
_in
_out
(old_map
, old_dump
, new_map
, 3, "in")
171 # check if complete function is called
172 assert self
.test_module
._complete
.call_count
== 1
173 # check if a PgRecovery Event was created and pg_update gets triggered
174 assert module
.PgRecoveryEvent
.pg_update
.call_count
== 2