]>
git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/cephadm/tests/test_migration.py
2 from datetime
import datetime
4 from ceph
.deployment
.service_spec
import PlacementSpec
, ServiceSpec
, HostPlacementSpec
5 from cephadm
import CephadmOrchestrator
6 from cephadm
.inventory
import SPEC_STORE_PREFIX
, DATEFMT
7 from cephadm
.tests
.fixtures
import _run_cephadm
, cephadm_module
, wait
, with_host
10 @mock.patch("cephadm.module.CephadmOrchestrator._run_cephadm", _run_cephadm('[]'))
11 @mock.patch("cephadm.services.cephadmservice.RgwService.create_realm_zonegroup_zone", lambda _
,__
,___
: None)
12 def test_migrate_scheduler(cephadm_module
: CephadmOrchestrator
):
13 with
with_host(cephadm_module
, 'host1'):
14 with
with_host(cephadm_module
, 'host2'):
16 # emulate the old scheduler:
17 c
= cephadm_module
.apply_rgw(
18 ServiceSpec('rgw', 'r.z', placement
=PlacementSpec(host_pattern
='*', count
=2))
20 assert wait(cephadm_module
, c
) == 'Scheduled rgw.r.z update...'
22 cephadm_module
._apply
_all
_services
()
23 out
= {o
.hostname
for o
in wait(cephadm_module
, cephadm_module
.list_daemons())}
24 assert out
== {'host1', 'host2'}
26 c
= cephadm_module
.apply_rgw(
27 ServiceSpec('rgw', 'r.z', placement
=PlacementSpec(host_pattern
='host1', count
=2))
29 assert wait(cephadm_module
, c
) == 'Scheduled rgw.r.z update...'
31 cephadm_module
.migration_current
= 0
32 cephadm_module
.migration
.migrate()
34 # assert we need all daemons.
35 assert cephadm_module
.migration_current
== 0
37 # Sorry, for this hack, but I need to make sure, Migration thinks,
38 # we have updated all daemons already.
39 cephadm_module
.cache
.last_daemon_update
['host1'] = datetime
.now()
40 cephadm_module
.cache
.last_daemon_update
['host2'] = datetime
.now()
42 cephadm_module
.migration
.migrate()
43 assert cephadm_module
.migration_current
== 2
45 out
= [o
.spec
.placement
for o
in wait(cephadm_module
, cephadm_module
.describe_service())]
46 assert out
== [PlacementSpec(count
=2, hosts
=[HostPlacementSpec(hostname
='host1', network
='', name
=''), HostPlacementSpec(hostname
='host2', network
='', name
='')])]
49 @mock.patch("cephadm.module.CephadmOrchestrator._run_cephadm", _run_cephadm('[]'))
50 def test_migrate_service_id_mon_one(cephadm_module
: CephadmOrchestrator
):
51 with
with_host(cephadm_module
, 'host1'):
52 cephadm_module
.set_store(SPEC_STORE_PREFIX
+ 'mon.wrong',
55 'service_type': 'mon',
56 'service_id': 'wrong',
61 'created': datetime
.utcnow().strftime(DATEFMT
),
65 cephadm_module
.spec_store
.load()
67 assert len(cephadm_module
.spec_store
.specs
) == 1
68 assert cephadm_module
.spec_store
.specs
['mon.wrong'].service_name() == 'mon'
70 cephadm_module
.migration_current
= 1
71 cephadm_module
.migration
.migrate()
72 assert cephadm_module
.migration_current
== 2
74 assert len(cephadm_module
.spec_store
.specs
) == 1
75 assert cephadm_module
.spec_store
.specs
['mon'] == ServiceSpec(
78 placement
=PlacementSpec(hosts
=['host1'])
81 @mock.patch("cephadm.module.CephadmOrchestrator._run_cephadm", _run_cephadm('[]'))
82 def test_migrate_service_id_mon_two(cephadm_module
: CephadmOrchestrator
):
83 with
with_host(cephadm_module
, 'host1'):
84 cephadm_module
.set_store(SPEC_STORE_PREFIX
+ 'mon',
87 'service_type': 'mon',
92 'created': datetime
.utcnow().strftime(DATEFMT
),
95 cephadm_module
.set_store(SPEC_STORE_PREFIX
+ 'mon.wrong',
98 'service_type': 'mon',
99 'service_id': 'wrong',
104 'created': datetime
.utcnow().strftime(DATEFMT
),
108 cephadm_module
.spec_store
.load()
110 assert len(cephadm_module
.spec_store
.specs
) == 2
111 assert cephadm_module
.spec_store
.specs
['mon.wrong'].service_name() == 'mon'
112 assert cephadm_module
.spec_store
.specs
['mon'].service_name() == 'mon'
114 cephadm_module
.migration_current
= 1
115 cephadm_module
.migration
.migrate()
116 assert cephadm_module
.migration_current
== 2
118 assert len(cephadm_module
.spec_store
.specs
) == 1
119 assert cephadm_module
.spec_store
.specs
['mon'] == ServiceSpec(
122 placement
=PlacementSpec(count
=5)
125 @mock.patch("cephadm.module.CephadmOrchestrator._run_cephadm", _run_cephadm('[]'))
126 def test_migrate_service_id_mds_one(cephadm_module
: CephadmOrchestrator
):
127 with
with_host(cephadm_module
, 'host1'):
128 cephadm_module
.set_store(SPEC_STORE_PREFIX
+ 'mds',
131 'service_type': 'mds',
136 'created': datetime
.utcnow().strftime(DATEFMT
),
140 cephadm_module
.spec_store
.load()
142 # there is nothing to migrate, as the spec is gone now.
143 assert len(cephadm_module
.spec_store
.specs
) == 0