]>
Commit | Line | Data |
---|---|---|
f67539c2 TL |
1 | import pytest |
2 | from unittest import mock | |
3 | ||
4 | from ceph.deployment.service_spec import ServiceSpec, PlacementSpec | |
5 | from orchestrator import DaemonDescription, OrchResult, ServiceDescription | |
6 | ||
7 | try: | |
8 | from typing import Any, List | |
9 | except ImportError: | |
10 | pass | |
11 | ||
12 | from mds_autoscaler.module import MDSAutoscaler | |
13 | ||
14 | ||
15 | @pytest.fixture() | |
16 | def mds_autoscaler_module(): | |
17 | ||
18 | yield MDSAutoscaler('mds_autoscaler', 0, 0) | |
19 | ||
20 | ||
21 | class TestCephadm(object): | |
22 | ||
23 | @mock.patch("mds_autoscaler.module.MDSAutoscaler.get") | |
24 | @mock.patch("mds_autoscaler.module.MDSAutoscaler.list_daemons") | |
25 | @mock.patch("mds_autoscaler.module.MDSAutoscaler.describe_service") | |
26 | @mock.patch("mds_autoscaler.module.MDSAutoscaler.apply_mds") | |
27 | def test_scale_up(self, _apply_mds, _describe_service, _list_daemons, _get, mds_autoscaler_module: MDSAutoscaler): | |
28 | daemons = OrchResult(result=[ | |
29 | DaemonDescription( | |
30 | hostname='myhost', | |
31 | daemon_type='mds', | |
32 | daemon_id='fs_name.myhost.a' | |
33 | ), | |
34 | DaemonDescription( | |
35 | hostname='myhost', | |
36 | daemon_type='mds', | |
37 | daemon_id='fs_name.myhost.b' | |
38 | ), | |
39 | ]) | |
40 | _list_daemons.return_value = daemons | |
41 | ||
42 | services = OrchResult(result=[ | |
43 | ServiceDescription( | |
44 | spec=ServiceSpec( | |
45 | service_type='mds', | |
46 | service_id='fs_name', | |
47 | placement=PlacementSpec( | |
48 | count=2 | |
49 | ) | |
50 | ) | |
51 | ) | |
52 | ]) | |
53 | _describe_service.return_value = services | |
54 | ||
55 | apply = OrchResult(result='') | |
56 | _apply_mds.return_value = apply | |
57 | ||
58 | _get.return_value = { | |
59 | 'filesystems': [ | |
60 | { | |
61 | 'mdsmap': { | |
62 | 'fs_name': 'fs_name', | |
63 | 'in': [ | |
64 | { | |
65 | 'name': 'mds.fs_name.myhost.a', | |
66 | } | |
67 | ], | |
68 | 'standby_count_wanted': 2, | |
69 | 'max_mds': 1 | |
70 | } | |
71 | } | |
72 | ], | |
73 | 'standbys': [ | |
74 | { | |
75 | 'name': 'mds.fs_name.myhost.b', | |
76 | } | |
77 | ], | |
78 | ||
79 | } | |
80 | mds_autoscaler_module.notify('fs_map', None) | |
81 | ||
82 | _apply_mds.assert_called_with(ServiceSpec( | |
83 | service_type='mds', | |
84 | service_id='fs_name', | |
85 | placement=PlacementSpec( | |
86 | count=3 | |
87 | ) | |
88 | )) |