]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/cephadm/tests/test_migration.py
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / pybind / mgr / cephadm / tests / test_migration.py
1 import json
2
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
9 from tests import mock
10
11
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):
16
17 # emulate the old scheduler:
18 c = cephadm_module.apply_rgw(
19 ServiceSpec('rgw', 'r.z', placement=PlacementSpec(host_pattern='*', count=2))
20 )
21 assert wait(cephadm_module, c) == 'Scheduled rgw.r.z update...'
22
23 # with pytest.raises(OrchestratorError, match="cephadm migration still ongoing. Please wait, until the migration is complete."):
24 CephadmServe(cephadm_module)._apply_all_services()
25
26 cephadm_module.migration_current = 0
27 cephadm_module.migration.migrate()
28 # assert we need all daemons.
29 assert cephadm_module.migration_current == 0
30
31 CephadmServe(cephadm_module)._refresh_hosts_and_daemons()
32 cephadm_module.migration.migrate()
33
34 CephadmServe(cephadm_module)._apply_all_services()
35
36 out = {o.hostname for o in wait(cephadm_module, cephadm_module.list_daemons())}
37 assert out == {'host1', 'host2'}
38
39 c = cephadm_module.apply_rgw(
40 ServiceSpec('rgw', 'r.z', placement=PlacementSpec(host_pattern='host1', count=2))
41 )
42 assert wait(cephadm_module, c) == 'Scheduled rgw.r.z update...'
43
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()
48
49 cephadm_module.migration_current = 0
50 cephadm_module.migration.migrate()
51 assert cephadm_module.migration_current == 2
52
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='')])]
57
58
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({
63 'spec': {
64 'service_type': 'mon',
65 'service_id': 'wrong',
66 'placement': {
67 'hosts': ['host1']
68 }
69 },
70 'created': datetime_to_str(datetime_now()),
71 }, sort_keys=True),
72 )
73
74 cephadm_module.spec_store.load()
75
76 assert len(cephadm_module.spec_store.all_specs) == 1
77 assert cephadm_module.spec_store.all_specs['mon.wrong'].service_name() == 'mon'
78
79 cephadm_module.migration_current = 1
80 cephadm_module.migration.migrate()
81 assert cephadm_module.migration_current == 2
82
83 assert len(cephadm_module.spec_store.all_specs) == 1
84 assert cephadm_module.spec_store.all_specs['mon'] == ServiceSpec(
85 service_type='mon',
86 unmanaged=True,
87 placement=PlacementSpec(hosts=['host1'])
88 )
89
90
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({
95 'spec': {
96 'service_type': 'mon',
97 'placement': {
98 'count': 5,
99 }
100 },
101 'created': datetime_to_str(datetime_now()),
102 }, sort_keys=True),
103 )
104 cephadm_module.set_store(SPEC_STORE_PREFIX + 'mon.wrong', json.dumps({
105 'spec': {
106 'service_type': 'mon',
107 'service_id': 'wrong',
108 'placement': {
109 'hosts': ['host1']
110 }
111 },
112 'created': datetime_to_str(datetime_now()),
113 }, sort_keys=True),
114 )
115
116 cephadm_module.spec_store.load()
117
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'
121
122 cephadm_module.migration_current = 1
123 cephadm_module.migration.migrate()
124 assert cephadm_module.migration_current == 2
125
126 assert len(cephadm_module.spec_store.all_specs) == 1
127 assert cephadm_module.spec_store.all_specs['mon'] == ServiceSpec(
128 service_type='mon',
129 unmanaged=True,
130 placement=PlacementSpec(count=5)
131 )
132
133
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({
138 'spec': {
139 'service_type': 'mds',
140 'placement': {
141 'hosts': ['host1']
142 }
143 },
144 'created': datetime_to_str(datetime_now()),
145 }, sort_keys=True),
146 )
147
148 cephadm_module.spec_store.load()
149
150 # there is nothing to migrate, as the spec is gone now.
151 assert len(cephadm_module.spec_store.all_specs) == 0