]>
git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/cephadm/tests/test_completion.py
085ea6c0a803b374570e26f2aa22bff0dcf13b62
13 from tests
import mock
14 from .fixtures
import cephadm_module
, wait
15 from ..module
import trivial_completion
, async_completion
, async_map_completion
18 class TestCompletion(object):
20 def test_trivial(self
, cephadm_module
):
24 assert wait(cephadm_module
, run(1)) == 2
26 @pytest.mark
.parametrize("input", [
32 def test_async(self
, input, cephadm_module
):
37 assert wait(cephadm_module
, run(*input)) == str(input)
39 @pytest.mark
.parametrize("input,expected", [
42 (["hallo"], ["('hallo',)"]),
43 ("hi", ["('h',)", "('i',)"]),
44 (list(range(5)), [str((x
, )) for x
in range(5)]),
45 ([(1, 2), (3, 4)], ["(1, 2)", "(3, 4)"]),
47 def test_async_map(self
, input, expected
, cephadm_module
):
53 wait(cephadm_module
, c
)
54 assert c
.result
== expected
56 def test_async_self(self
, cephadm_module
):
66 assert wait(cephadm_module
, Run().run(1)) == 2
68 @pytest.mark
.parametrize("input,expected", [
71 (["hallo"], ["('hallo',)"]),
72 ("hi", ["('h',)", "('i',)"]),
73 (list(range(5)), [str((x
, )) for x
in range(5)]),
74 ([(1, 2), (3, 4)], ["(1, 2)", "(3, 4)"]),
76 def test_async_map_self(self
, input, expected
, cephadm_module
):
87 wait(cephadm_module
, c
)
88 assert c
.result
== expected
90 def test_then1(self
, cephadm_module
):
95 assert wait(cephadm_module
, run([1,2]).then(str)) == '[2, 3]'
97 def test_then2(self
, cephadm_module
):
104 def async_str(results
):
107 c
= run([1,2]).then(async_str
)
109 wait(cephadm_module
, c
)
110 assert c
.result
== '[2, 3]'
112 def test_then3(self
, cephadm_module
):
113 @async_map_completion
118 def async_str(results
):
119 return async_completion(str)(results
)
121 c
= run([1,2]).then(async_str
)
123 wait(cephadm_module
, c
)
124 assert c
.result
== '[2, 3]'
126 def test_then4(self
, cephadm_module
):
127 @async_map_completion
132 def async_str(results
):
133 return async_completion(str)(results
).then(lambda x
: x
+ "hello")
135 c
= run([1,2]).then(async_str
)
137 wait(cephadm_module
, c
)
138 assert c
.result
== '[2, 3]hello'
140 @pytest.mark
.skip(reason
="see limitation of async_map_completion")
141 def test_then5(self
, cephadm_module
):
142 @async_map_completion
145 return async_completion(str)(x
+1)
149 wait(cephadm_module
, c
)
150 assert c
.result
== "['2', '3']"
152 def test_raise(self
, cephadm_module
):
155 raise ZeroDivisionError()
157 with pytest
.raises(ZeroDivisionError):
158 wait(cephadm_module
, run(1))
160 def test_progress(self
, cephadm_module
):
161 @async_map_completion
165 c
= run(list(range(2)))
166 c
.update_progress
= True
169 message
="my progress"
171 wait(cephadm_module
, c
)
172 assert c
.result
== [str((x
,)) for x
in range(2)]
173 assert cephadm_module
.remote
.mock_calls
== [
174 mock
.call('progress', 'update', mock
.ANY
, 'my progress', float(i
) / 2, [('origin', 'orchestrator')])
175 for i
in range(2+1)] + [
176 mock
.call('progress', 'update', mock
.ANY
, 'my progress', 1.0, [('origin', 'orchestrator')]),
177 mock
.call('progress', 'complete', mock
.ANY
),