]>
git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/cephadm/tests/test_migration.py
2 from datetime
import datetime
6 from ceph
.deployment
.service_spec
import PlacementSpec
, ServiceSpec
, HostPlacementSpec
7 from cephadm
import CephadmOrchestrator
8 from cephadm
.inventory
import SPEC_STORE_PREFIX
9 from cephadm
.utils
import DATEFMT
10 from cephadm
.tests
.fixtures
import _run_cephadm
, cephadm_module
, wait
, with_host
11 from orchestrator
import OrchestratorError
12 from cephadm
.serve
import CephadmServe
13 from tests
import mock
16 @mock.patch("cephadm.module.CephadmOrchestrator._run_cephadm", _run_cephadm('[]'))
17 @mock.patch("cephadm.services.cephadmservice.RgwService.create_realm_zonegroup_zone", lambda _
, __
, ___
: None)
18 def test_migrate_scheduler(cephadm_module
: CephadmOrchestrator
):
19 with
with_host(cephadm_module
, 'host1', refresh_hosts
=False):
20 with
with_host(cephadm_module
, 'host2', refresh_hosts
=False):
22 # emulate the old scheduler:
23 c
= cephadm_module
.apply_rgw(
24 ServiceSpec('rgw', 'r.z', placement
=PlacementSpec(host_pattern
='*', count
=2))
26 assert wait(cephadm_module
, c
) == 'Scheduled rgw.r.z update...'
28 # with pytest.raises(OrchestratorError, match="cephadm migration still ongoing. Please wait, until the migration is complete."):
29 CephadmServe(cephadm_module
)._apply
_all
_services
()
31 cephadm_module
.migration_current
= 0
32 cephadm_module
.migration
.migrate()
33 # assert we need all daemons.
34 assert cephadm_module
.migration_current
== 0
36 CephadmServe(cephadm_module
)._refresh
_hosts
_and
_daemons
()
37 cephadm_module
.migration
.migrate()
39 CephadmServe(cephadm_module
)._apply
_all
_services
()
41 out
= {o
.hostname
for o
in wait(cephadm_module
, cephadm_module
.list_daemons())}
42 assert out
== {'host1', 'host2'}
44 c
= cephadm_module
.apply_rgw(
45 ServiceSpec('rgw', 'r.z', placement
=PlacementSpec(host_pattern
='host1', count
=2))
47 assert wait(cephadm_module
, c
) == 'Scheduled rgw.r.z update...'
49 # Sorry, for this hack, but I need to make sure, Migration thinks,
50 # we have updated all daemons already.
51 cephadm_module
.cache
.last_daemon_update
['host1'] = datetime
.now()
52 cephadm_module
.cache
.last_daemon_update
['host2'] = datetime
.now()
54 cephadm_module
.migration_current
= 0
55 cephadm_module
.migration
.migrate()
56 assert cephadm_module
.migration_current
== 2
58 out
= [o
.spec
.placement
for o
in wait(
59 cephadm_module
, cephadm_module
.describe_service())]
60 assert out
== [PlacementSpec(count
=2, hosts
=[HostPlacementSpec(
61 hostname
='host1', network
='', name
=''), HostPlacementSpec(hostname
='host2', network
='', name
='')])]
64 @mock.patch("cephadm.module.CephadmOrchestrator._run_cephadm", _run_cephadm('[]'))
65 def test_migrate_service_id_mon_one(cephadm_module
: CephadmOrchestrator
):
66 with
with_host(cephadm_module
, 'host1'):
67 cephadm_module
.set_store(SPEC_STORE_PREFIX
+ 'mon.wrong', json
.dumps({
69 'service_type': 'mon',
70 'service_id': 'wrong',
75 'created': datetime
.utcnow().strftime(DATEFMT
),
79 cephadm_module
.spec_store
.load()
81 assert len(cephadm_module
.spec_store
.specs
) == 1
82 assert cephadm_module
.spec_store
.specs
['mon.wrong'].service_name() == 'mon'
84 cephadm_module
.migration_current
= 1
85 cephadm_module
.migration
.migrate()
86 assert cephadm_module
.migration_current
== 2
88 assert len(cephadm_module
.spec_store
.specs
) == 1
89 assert cephadm_module
.spec_store
.specs
['mon'] == ServiceSpec(
92 placement
=PlacementSpec(hosts
=['host1'])
96 @mock.patch("cephadm.module.CephadmOrchestrator._run_cephadm", _run_cephadm('[]'))
97 def test_migrate_service_id_mon_two(cephadm_module
: CephadmOrchestrator
):
98 with
with_host(cephadm_module
, 'host1'):
99 cephadm_module
.set_store(SPEC_STORE_PREFIX
+ 'mon', json
.dumps({
101 'service_type': 'mon',
106 'created': datetime
.utcnow().strftime(DATEFMT
),
109 cephadm_module
.set_store(SPEC_STORE_PREFIX
+ 'mon.wrong', json
.dumps({
111 'service_type': 'mon',
112 'service_id': 'wrong',
117 'created': datetime
.utcnow().strftime(DATEFMT
),
121 cephadm_module
.spec_store
.load()
123 assert len(cephadm_module
.spec_store
.specs
) == 2
124 assert cephadm_module
.spec_store
.specs
['mon.wrong'].service_name() == 'mon'
125 assert cephadm_module
.spec_store
.specs
['mon'].service_name() == 'mon'
127 cephadm_module
.migration_current
= 1
128 cephadm_module
.migration
.migrate()
129 assert cephadm_module
.migration_current
== 2
131 assert len(cephadm_module
.spec_store
.specs
) == 1
132 assert cephadm_module
.spec_store
.specs
['mon'] == ServiceSpec(
135 placement
=PlacementSpec(count
=5)
139 @mock.patch("cephadm.module.CephadmOrchestrator._run_cephadm", _run_cephadm('[]'))
140 def test_migrate_service_id_mds_one(cephadm_module
: CephadmOrchestrator
):
141 with
with_host(cephadm_module
, 'host1'):
142 cephadm_module
.set_store(SPEC_STORE_PREFIX
+ 'mds', json
.dumps({
144 'service_type': 'mds',
149 'created': datetime
.utcnow().strftime(DATEFMT
),
153 cephadm_module
.spec_store
.load()
155 # there is nothing to migrate, as the spec is gone now.
156 assert len(cephadm_module
.spec_store
.specs
) == 0