]>
git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/cephadm/tests/test_migration.py
3 from ceph
.deployment
.service_spec
import PlacementSpec
, ServiceSpec
, HostPlacementSpec
4 from ceph
.utils
import datetime_to_str
, datetime_now
5 from cephadm
import CephadmOrchestrator
6 from cephadm
.inventory
import SPEC_STORE_PREFIX
7 from cephadm
.tests
.fixtures
import _run_cephadm
, wait
, with_host
8 from cephadm
.serve
import CephadmServe
12 @mock.patch("cephadm.serve.CephadmServe._run_cephadm", _run_cephadm('[]'))
13 def test_migrate_scheduler(cephadm_module
: CephadmOrchestrator
):
14 with
with_host(cephadm_module
, 'host1', refresh_hosts
=False):
15 with
with_host(cephadm_module
, 'host2', refresh_hosts
=False):
17 # emulate the old scheduler:
18 c
= cephadm_module
.apply_rgw(
19 ServiceSpec('rgw', 'r.z', placement
=PlacementSpec(host_pattern
='*', count
=2))
21 assert wait(cephadm_module
, c
) == 'Scheduled rgw.r.z update...'
23 # with pytest.raises(OrchestratorError, match="cephadm migration still ongoing. Please wait, until the migration is complete."):
24 CephadmServe(cephadm_module
)._apply
_all
_services
()
26 cephadm_module
.migration_current
= 0
27 cephadm_module
.migration
.migrate()
28 # assert we need all daemons.
29 assert cephadm_module
.migration_current
== 0
31 CephadmServe(cephadm_module
)._refresh
_hosts
_and
_daemons
()
32 cephadm_module
.migration
.migrate()
34 CephadmServe(cephadm_module
)._apply
_all
_services
()
36 out
= {o
.hostname
for o
in wait(cephadm_module
, cephadm_module
.list_daemons())}
37 assert out
== {'host1', 'host2'}
39 c
= cephadm_module
.apply_rgw(
40 ServiceSpec('rgw', 'r.z', placement
=PlacementSpec(host_pattern
='host1', count
=2))
42 assert wait(cephadm_module
, c
) == 'Scheduled rgw.r.z update...'
44 # Sorry, for this hack, but I need to make sure, Migration thinks,
45 # we have updated all daemons already.
46 cephadm_module
.cache
.last_daemon_update
['host1'] = datetime_now()
47 cephadm_module
.cache
.last_daemon_update
['host2'] = datetime_now()
49 cephadm_module
.migration_current
= 0
50 cephadm_module
.migration
.migrate()
51 assert cephadm_module
.migration_current
== 2
53 out
= [o
.spec
.placement
for o
in wait(
54 cephadm_module
, cephadm_module
.describe_service())]
55 assert out
== [PlacementSpec(count
=2, hosts
=[HostPlacementSpec(
56 hostname
='host1', network
='', name
=''), HostPlacementSpec(hostname
='host2', network
='', name
='')])]
59 @mock.patch("cephadm.serve.CephadmServe._run_cephadm", _run_cephadm('[]'))
60 def test_migrate_service_id_mon_one(cephadm_module
: CephadmOrchestrator
):
61 with
with_host(cephadm_module
, 'host1'):
62 cephadm_module
.set_store(SPEC_STORE_PREFIX
+ 'mon.wrong', json
.dumps({
64 'service_type': 'mon',
65 'service_id': 'wrong',
70 'created': datetime_to_str(datetime_now()),
74 cephadm_module
.spec_store
.load()
76 assert len(cephadm_module
.spec_store
.all_specs
) == 1
77 assert cephadm_module
.spec_store
.all_specs
['mon.wrong'].service_name() == 'mon'
79 cephadm_module
.migration_current
= 1
80 cephadm_module
.migration
.migrate()
81 assert cephadm_module
.migration_current
== 2
83 assert len(cephadm_module
.spec_store
.all_specs
) == 1
84 assert cephadm_module
.spec_store
.all_specs
['mon'] == ServiceSpec(
87 placement
=PlacementSpec(hosts
=['host1'])
91 @mock.patch("cephadm.serve.CephadmServe._run_cephadm", _run_cephadm('[]'))
92 def test_migrate_service_id_mon_two(cephadm_module
: CephadmOrchestrator
):
93 with
with_host(cephadm_module
, 'host1'):
94 cephadm_module
.set_store(SPEC_STORE_PREFIX
+ 'mon', json
.dumps({
96 'service_type': 'mon',
101 'created': datetime_to_str(datetime_now()),
104 cephadm_module
.set_store(SPEC_STORE_PREFIX
+ 'mon.wrong', json
.dumps({
106 'service_type': 'mon',
107 'service_id': 'wrong',
112 'created': datetime_to_str(datetime_now()),
116 cephadm_module
.spec_store
.load()
118 assert len(cephadm_module
.spec_store
.all_specs
) == 2
119 assert cephadm_module
.spec_store
.all_specs
['mon.wrong'].service_name() == 'mon'
120 assert cephadm_module
.spec_store
.all_specs
['mon'].service_name() == 'mon'
122 cephadm_module
.migration_current
= 1
123 cephadm_module
.migration
.migrate()
124 assert cephadm_module
.migration_current
== 2
126 assert len(cephadm_module
.spec_store
.all_specs
) == 1
127 assert cephadm_module
.spec_store
.all_specs
['mon'] == ServiceSpec(
130 placement
=PlacementSpec(count
=5)
134 @mock.patch("cephadm.serve.CephadmServe._run_cephadm", _run_cephadm('[]'))
135 def test_migrate_service_id_mds_one(cephadm_module
: CephadmOrchestrator
):
136 with
with_host(cephadm_module
, 'host1'):
137 cephadm_module
.set_store(SPEC_STORE_PREFIX
+ 'mds', json
.dumps({
139 'service_type': 'mds',
144 'created': datetime_to_str(datetime_now()),
148 cephadm_module
.spec_store
.load()
150 # there is nothing to migrate, as the spec is gone now.
151 assert len(cephadm_module
.spec_store
.all_specs
) == 0