vantage6 5.0.0a29__py3-none-any.whl → 5.0.0a34__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of vantage6 might be problematic. Click here for more details.
- vantage6/cli/__init__.py +5 -1
- vantage6/cli/algorithm/generate_algorithm_json.py +3 -11
- vantage6/cli/algostore/new.py +24 -46
- vantage6/cli/algostore/start.py +33 -67
- vantage6/cli/algostore/stop.py +75 -40
- vantage6/cli/common/new.py +60 -0
- vantage6/cli/common/start.py +17 -223
- vantage6/cli/common/stop.py +1 -1
- vantage6/cli/common/utils.py +212 -16
- vantage6/cli/configuration_manager.py +65 -0
- vantage6/cli/configuration_wizard.py +95 -76
- vantage6/cli/context/algorithm_store.py +8 -7
- vantage6/cli/context/base_server.py +22 -30
- vantage6/cli/context/node.py +11 -2
- vantage6/cli/context/server.py +17 -8
- vantage6/cli/globals.py +12 -11
- vantage6/cli/node/common/__init__.py +1 -1
- vantage6/cli/node/create_private_key.py +9 -6
- vantage6/cli/node/set_api_key.py +7 -4
- vantage6/cli/node/start.py +1 -1
- vantage6/cli/node/stop.py +7 -7
- vantage6/cli/server/import_.py +1 -2
- vantage6/cli/server/list.py +0 -3
- vantage6/cli/server/new.py +13 -51
- vantage6/cli/server/shell.py +1 -1
- vantage6/cli/server/start.py +17 -17
- vantage6/cli/server/stop.py +64 -15
- vantage6/cli/template/algo_store_config.j2 +195 -22
- vantage6/cli/template/server_config.j2 +255 -33
- vantage6-5.0.0a34.dist-info/METADATA +54 -0
- {vantage6-5.0.0a29.dist-info → vantage6-5.0.0a34.dist-info}/RECORD +33 -42
- {vantage6-5.0.0a29.dist-info → vantage6-5.0.0a34.dist-info}/WHEEL +1 -2
- vantage6-5.0.0a34.dist-info/entry_points.txt +2 -0
- tests_cli/__init__.py +0 -0
- tests_cli/test_client_script.py +0 -23
- tests_cli/test_example.py +0 -7
- tests_cli/test_node_cli.py +0 -452
- tests_cli/test_server_cli.py +0 -180
- tests_cli/test_wizard.py +0 -141
- vantage6/cli/__build__ +0 -1
- vantage6/cli/_version.py +0 -23
- vantage6/cli/template/server_import_config.j2 +0 -31
- vantage6-5.0.0a29.dist-info/METADATA +0 -238
- vantage6-5.0.0a29.dist-info/entry_points.txt +0 -5
- vantage6-5.0.0a29.dist-info/top_level.txt +0 -2
tests_cli/test_node_cli.py
DELETED
|
@@ -1,452 +0,0 @@
|
|
|
1
|
-
import unittest
|
|
2
|
-
import logging
|
|
3
|
-
import os
|
|
4
|
-
import contextlib
|
|
5
|
-
|
|
6
|
-
from unittest.mock import MagicMock, patch
|
|
7
|
-
from pathlib import Path
|
|
8
|
-
from io import BytesIO, StringIO
|
|
9
|
-
from click.testing import CliRunner
|
|
10
|
-
from docker.errors import APIError
|
|
11
|
-
|
|
12
|
-
from vantage6.common.globals import Ports
|
|
13
|
-
from vantage6.cli.globals import APPNAME
|
|
14
|
-
from vantage6.common import STRING_ENCODING
|
|
15
|
-
from vantage6.cli.common.utils import print_log_worker
|
|
16
|
-
from vantage6.cli.node.list import cli_node_list
|
|
17
|
-
from vantage6.cli.node.new import cli_node_new_configuration
|
|
18
|
-
from vantage6.cli.node.files import cli_node_files
|
|
19
|
-
from vantage6.cli.node.start import cli_node_start
|
|
20
|
-
from vantage6.cli.node.restart import cli_node_restart
|
|
21
|
-
from vantage6.cli.node.stop import cli_node_stop
|
|
22
|
-
from vantage6.cli.node.attach import cli_node_attach
|
|
23
|
-
from vantage6.cli.node.create_private_key import cli_node_create_private_key
|
|
24
|
-
from vantage6.cli.node.clean import cli_node_clean
|
|
25
|
-
from vantage6.cli.node.common import create_client_and_authenticate
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
class NodeCLITest(unittest.TestCase):
|
|
29
|
-
@classmethod
|
|
30
|
-
def setUpClass(cls):
|
|
31
|
-
logging.getLogger("docker.utils.config").setLevel(logging.WARNING)
|
|
32
|
-
return super().setUpClass()
|
|
33
|
-
|
|
34
|
-
@patch("docker.DockerClient.ping")
|
|
35
|
-
def test_list_docker_not_running(self, docker_ping):
|
|
36
|
-
"""An error is printed when docker is not running"""
|
|
37
|
-
docker_ping.side_effect = Exception("Boom!")
|
|
38
|
-
|
|
39
|
-
runner = CliRunner()
|
|
40
|
-
result = runner.invoke(cli_node_list, [])
|
|
41
|
-
|
|
42
|
-
# check exit code
|
|
43
|
-
self.assertEqual(result.exit_code, 1)
|
|
44
|
-
|
|
45
|
-
@patch("vantage6.cli.context.node.NodeContext.available_configurations")
|
|
46
|
-
@patch("docker.DockerClient.ping")
|
|
47
|
-
@patch("docker.DockerClient.containers")
|
|
48
|
-
def test_list(self, containers, docker_ping, available_configurations):
|
|
49
|
-
"""A container list and their current status."""
|
|
50
|
-
# https://docs.python.org/3/library/unittest.mock.html#mock-names-and-the-name-attribute
|
|
51
|
-
|
|
52
|
-
# mock that docker-deamon is running
|
|
53
|
-
docker_ping.return_value = True
|
|
54
|
-
|
|
55
|
-
# docker deamon returns a list of running node-containers
|
|
56
|
-
container1 = MagicMock()
|
|
57
|
-
container1.name = f"{APPNAME}-iknl-user"
|
|
58
|
-
containers.list.return_value = [container1]
|
|
59
|
-
|
|
60
|
-
# returns a list of configurations and failed inports
|
|
61
|
-
def side_effect(system_folders):
|
|
62
|
-
config = MagicMock()
|
|
63
|
-
config.name = "iknl"
|
|
64
|
-
if not system_folders:
|
|
65
|
-
return [[config], []]
|
|
66
|
-
else:
|
|
67
|
-
return [[config], []]
|
|
68
|
-
|
|
69
|
-
available_configurations.side_effect = side_effect
|
|
70
|
-
|
|
71
|
-
# invoke CLI method
|
|
72
|
-
runner = CliRunner()
|
|
73
|
-
result = runner.invoke(cli_node_list, [])
|
|
74
|
-
|
|
75
|
-
# validate exit code
|
|
76
|
-
self.assertEqual(result.exit_code, 0)
|
|
77
|
-
|
|
78
|
-
# check printed lines
|
|
79
|
-
self.assertEqual(
|
|
80
|
-
result.output,
|
|
81
|
-
"\nName Status System/User\n"
|
|
82
|
-
"-----------------------------------------------------\n"
|
|
83
|
-
"iknl Not running System \n"
|
|
84
|
-
"iknl Running User \n"
|
|
85
|
-
"-----------------------------------------------------\n",
|
|
86
|
-
)
|
|
87
|
-
|
|
88
|
-
@patch("vantage6.cli.node.new.configuration_wizard")
|
|
89
|
-
@patch("vantage6.cli.node.new.ensure_config_dir_writable")
|
|
90
|
-
@patch("vantage6.cli.node.common.NodeContext")
|
|
91
|
-
def test_new_config(self, context, permissions, wizard):
|
|
92
|
-
"""No error produced when creating new configuration."""
|
|
93
|
-
context.config_exists.return_value = False
|
|
94
|
-
permissions.return_value = True
|
|
95
|
-
wizard.return_value = "/some/file/path"
|
|
96
|
-
|
|
97
|
-
runner = CliRunner()
|
|
98
|
-
result = runner.invoke(
|
|
99
|
-
cli_node_new_configuration,
|
|
100
|
-
[
|
|
101
|
-
"--name",
|
|
102
|
-
"some-name",
|
|
103
|
-
],
|
|
104
|
-
)
|
|
105
|
-
|
|
106
|
-
# check that info message is produced
|
|
107
|
-
self.assertEqual(result.output[:7], "[info ]")
|
|
108
|
-
|
|
109
|
-
# check OK exit code
|
|
110
|
-
self.assertEqual(result.exit_code, 0)
|
|
111
|
-
|
|
112
|
-
@patch("vantage6.cli.node.new.configuration_wizard")
|
|
113
|
-
def test_new_config_replace_whitespace_in_name(self, _):
|
|
114
|
-
"""Whitespaces are replaced in the name."""
|
|
115
|
-
|
|
116
|
-
runner = CliRunner()
|
|
117
|
-
result = runner.invoke(
|
|
118
|
-
cli_node_new_configuration,
|
|
119
|
-
[
|
|
120
|
-
"--name",
|
|
121
|
-
"some name",
|
|
122
|
-
],
|
|
123
|
-
)
|
|
124
|
-
|
|
125
|
-
self.assertEqual(
|
|
126
|
-
result.output[:60],
|
|
127
|
-
"[info ] - Replaced spaces from configuration name: some-name",
|
|
128
|
-
)
|
|
129
|
-
|
|
130
|
-
@patch("vantage6.cli.node.new.NodeContext")
|
|
131
|
-
def test_new_config_already_exists(self, context):
|
|
132
|
-
"""No duplicate configurations are allowed."""
|
|
133
|
-
|
|
134
|
-
context.config_exists.return_value = True
|
|
135
|
-
|
|
136
|
-
runner = CliRunner()
|
|
137
|
-
result = runner.invoke(
|
|
138
|
-
cli_node_new_configuration,
|
|
139
|
-
[
|
|
140
|
-
"--name",
|
|
141
|
-
"some-name",
|
|
142
|
-
],
|
|
143
|
-
)
|
|
144
|
-
|
|
145
|
-
# check that error is produced
|
|
146
|
-
self.assertEqual(result.output[:7], "[error]")
|
|
147
|
-
|
|
148
|
-
# check non-zero exit code
|
|
149
|
-
self.assertEqual(result.exit_code, 1)
|
|
150
|
-
|
|
151
|
-
@patch("vantage6.cli.node.new.ensure_config_dir_writable")
|
|
152
|
-
@patch("vantage6.cli.node.common.NodeContext")
|
|
153
|
-
def test_new_write_permissions(self, context, permissions):
|
|
154
|
-
"""User needs write permissions."""
|
|
155
|
-
|
|
156
|
-
context.config_exists.return_value = False
|
|
157
|
-
permissions.return_value = False
|
|
158
|
-
|
|
159
|
-
runner = CliRunner()
|
|
160
|
-
result = runner.invoke(
|
|
161
|
-
cli_node_new_configuration,
|
|
162
|
-
[
|
|
163
|
-
"--name",
|
|
164
|
-
"some-name",
|
|
165
|
-
],
|
|
166
|
-
)
|
|
167
|
-
|
|
168
|
-
# check that error is produced
|
|
169
|
-
self.assertEqual(result.output[:7], "[error]")
|
|
170
|
-
|
|
171
|
-
# check non-zero exit code
|
|
172
|
-
self.assertEqual(result.exit_code, 1)
|
|
173
|
-
|
|
174
|
-
@patch("vantage6.cli.node.common.NodeContext")
|
|
175
|
-
@patch("vantage6.cli.node.files.NodeContext")
|
|
176
|
-
@patch("vantage6.cli.node.common.select_configuration_questionaire")
|
|
177
|
-
def test_files(self, select_config, context, common_context):
|
|
178
|
-
"""No errors produced when retrieving filepaths."""
|
|
179
|
-
|
|
180
|
-
common_context.config_exists.return_value = True
|
|
181
|
-
context.return_value = MagicMock(
|
|
182
|
-
config_file="/file.yaml", log_file="/log.log", data_dir="/dir"
|
|
183
|
-
)
|
|
184
|
-
context.return_value.databases.items.return_value = [["label", "/file.db"]]
|
|
185
|
-
select_config.return_value = "iknl"
|
|
186
|
-
|
|
187
|
-
runner = CliRunner()
|
|
188
|
-
result = runner.invoke(cli_node_files, [])
|
|
189
|
-
|
|
190
|
-
# we check that no warnings have been produced
|
|
191
|
-
self.assertEqual(result.output[:7], "[info ]")
|
|
192
|
-
|
|
193
|
-
# check status code is OK
|
|
194
|
-
self.assertEqual(result.exit_code, 0)
|
|
195
|
-
|
|
196
|
-
@patch("vantage6.cli.node.common.NodeContext")
|
|
197
|
-
def test_files_non_existing_config(self, context):
|
|
198
|
-
"""An error is produced when a non existing config is used."""
|
|
199
|
-
|
|
200
|
-
context.config_exists.return_value = False
|
|
201
|
-
|
|
202
|
-
runner = CliRunner()
|
|
203
|
-
result = runner.invoke(cli_node_files, ["--name", "non-existing"])
|
|
204
|
-
|
|
205
|
-
# Check that error is produced
|
|
206
|
-
self.assertEqual(result.output[:7], "[error]")
|
|
207
|
-
|
|
208
|
-
# check for non zero exit-code
|
|
209
|
-
self.assertNotEqual(result.exit_code, 0)
|
|
210
|
-
|
|
211
|
-
@patch("docker.DockerClient.volumes")
|
|
212
|
-
@patch("vantage6.cli.node.start.pull_infra_image")
|
|
213
|
-
@patch("vantage6.cli.common.decorator.get_context")
|
|
214
|
-
@patch("docker.DockerClient.containers")
|
|
215
|
-
@patch("vantage6.cli.node.start.check_docker_running", return_value=True)
|
|
216
|
-
def test_start(self, check_docker, client, context, pull, volumes):
|
|
217
|
-
# client.containers = MagicMock(name="docker.DockerClient.containers")
|
|
218
|
-
client.list.return_value = []
|
|
219
|
-
volume = MagicMock()
|
|
220
|
-
volume.name = "data-vol-name"
|
|
221
|
-
volumes.create.return_value = volume
|
|
222
|
-
context.config_exists.return_value = True
|
|
223
|
-
|
|
224
|
-
ctx = MagicMock(
|
|
225
|
-
data_dir=Path("data"),
|
|
226
|
-
log_dir=Path("logs"),
|
|
227
|
-
config_dir=Path("configs"),
|
|
228
|
-
databases=[{"label": "some_label", "uri": "data.csv", "type": "csv"}],
|
|
229
|
-
)
|
|
230
|
-
|
|
231
|
-
# cli_node_start() tests for truth value of a set-like object derived
|
|
232
|
-
# from ctx.config.get('node_extra_env', {}). Default MagicMock() will
|
|
233
|
-
# evaluate to True, empty dict to False. False signifies no overwritten
|
|
234
|
-
# env vars, hence no error.
|
|
235
|
-
def config_get_side_effect(key, default=None):
|
|
236
|
-
if key == "node_extra_env":
|
|
237
|
-
return {}
|
|
238
|
-
return MagicMock()
|
|
239
|
-
|
|
240
|
-
ctx.config.get.side_effect = config_get_side_effect
|
|
241
|
-
ctx.get_data_file.return_value = "data.csv"
|
|
242
|
-
ctx.name = "some-name"
|
|
243
|
-
context.return_value = ctx
|
|
244
|
-
|
|
245
|
-
runner = CliRunner()
|
|
246
|
-
|
|
247
|
-
# Should fail when starting node with non-existing database CSV file
|
|
248
|
-
with runner.isolated_filesystem():
|
|
249
|
-
result = runner.invoke(cli_node_start, ["--name", "some-name"])
|
|
250
|
-
self.assertEqual(result.exit_code, 1)
|
|
251
|
-
|
|
252
|
-
# now do it with a SQL database which doesn't have to be an existing file
|
|
253
|
-
ctx.databases = [{"label": "some_label", "uri": "data.db", "type": "sql"}]
|
|
254
|
-
with runner.isolated_filesystem():
|
|
255
|
-
result = runner.invoke(cli_node_start, ["--name", "some-name"])
|
|
256
|
-
self.assertEqual(result.exit_code, 0)
|
|
257
|
-
|
|
258
|
-
def _setup_stop_test(self, containers):
|
|
259
|
-
container1 = MagicMock()
|
|
260
|
-
container1.name = f"{APPNAME}-iknl-user"
|
|
261
|
-
containers.list.return_value = [container1]
|
|
262
|
-
|
|
263
|
-
@patch("docker.DockerClient.containers")
|
|
264
|
-
@patch("vantage6.cli.node.stop.check_docker_running", return_value=True)
|
|
265
|
-
@patch("vantage6.cli.node.stop.NodeContext")
|
|
266
|
-
@patch("vantage6.cli.node.stop.delete_volume_if_exists")
|
|
267
|
-
def test_stop(self, delete_volume, node_context, check_docker, containers):
|
|
268
|
-
self._setup_stop_test(containers)
|
|
269
|
-
|
|
270
|
-
runner = CliRunner()
|
|
271
|
-
|
|
272
|
-
result = runner.invoke(cli_node_stop, ["--name", "iknl"])
|
|
273
|
-
|
|
274
|
-
self.assertEqual(
|
|
275
|
-
result.output, "[info ] - Stopped the vantage6-iknl-user Node.\n"
|
|
276
|
-
)
|
|
277
|
-
|
|
278
|
-
self.assertEqual(result.exit_code, 0)
|
|
279
|
-
|
|
280
|
-
@patch("docker.DockerClient.containers")
|
|
281
|
-
@patch("vantage6.cli.node.stop.check_docker_running", return_value=True)
|
|
282
|
-
@patch("vantage6.cli.node.stop.NodeContext")
|
|
283
|
-
@patch("vantage6.cli.node.stop.delete_volume_if_exists")
|
|
284
|
-
@patch("vantage6.cli.node.restart.subprocess.run")
|
|
285
|
-
def test_restart(
|
|
286
|
-
self, subprocess_run, delete_volume, node_context, check_docker, containers
|
|
287
|
-
):
|
|
288
|
-
"""Restart a node without errors."""
|
|
289
|
-
self._setup_stop_test(containers)
|
|
290
|
-
# The subprocess.run() function is called with the command to start the node.
|
|
291
|
-
# Unfortunately it is hard to test this, so we just return a successful run
|
|
292
|
-
subprocess_run.return_value = MagicMock(returncode=0)
|
|
293
|
-
runner = CliRunner()
|
|
294
|
-
with runner.isolated_filesystem():
|
|
295
|
-
result = runner.invoke(cli_node_restart, ["--name", "iknl"])
|
|
296
|
-
self.assertEqual(result.exit_code, 0)
|
|
297
|
-
|
|
298
|
-
@patch("vantage6.cli.node.attach.attach_logs")
|
|
299
|
-
def test_attach(self, attach_logs):
|
|
300
|
-
"""Attach docker logs without errors."""
|
|
301
|
-
runner = CliRunner()
|
|
302
|
-
runner.invoke(cli_node_attach)
|
|
303
|
-
attach_logs.assert_called_once_with("app=node")
|
|
304
|
-
|
|
305
|
-
@patch("vantage6.cli.node.clean.q")
|
|
306
|
-
@patch("docker.DockerClient.volumes")
|
|
307
|
-
@patch("vantage6.cli.node.clean.check_docker_running", return_value=True)
|
|
308
|
-
def test_clean(self, check_docker, volumes, q):
|
|
309
|
-
"""Clean Docker volumes without errors."""
|
|
310
|
-
volume1 = MagicMock()
|
|
311
|
-
volume1.name = "some-name-tmpvol"
|
|
312
|
-
volumes.list.return_value = [volume1]
|
|
313
|
-
|
|
314
|
-
question = MagicMock(name="pop-the-question")
|
|
315
|
-
question.ask.return_value = True
|
|
316
|
-
q.confirm.return_value = question
|
|
317
|
-
|
|
318
|
-
runner = CliRunner()
|
|
319
|
-
result = runner.invoke(cli_node_clean)
|
|
320
|
-
|
|
321
|
-
# check exit code
|
|
322
|
-
self.assertEqual(result.exit_code, 0)
|
|
323
|
-
|
|
324
|
-
@patch("vantage6.cli.node.create_private_key.create_client_and_authenticate")
|
|
325
|
-
@patch("vantage6.cli.node.common.NodeContext")
|
|
326
|
-
@patch("vantage6.cli.node.create_private_key.NodeContext")
|
|
327
|
-
def test_create_private_key(self, context, common_context, client):
|
|
328
|
-
common_context.config_exists.return_value = True
|
|
329
|
-
context.return_value.type_data_folder.return_value = Path(".")
|
|
330
|
-
client.return_value = MagicMock(whoami=MagicMock(organization_name="Test"))
|
|
331
|
-
# client.whoami.organization_name = "Test"
|
|
332
|
-
runner = CliRunner()
|
|
333
|
-
|
|
334
|
-
result = runner.invoke(cli_node_create_private_key, ["--name", "application"])
|
|
335
|
-
|
|
336
|
-
self.assertEqual(result.exit_code, 0)
|
|
337
|
-
|
|
338
|
-
# remove the private key file again
|
|
339
|
-
os.remove("privkey_Test.pem")
|
|
340
|
-
|
|
341
|
-
@patch("vantage6.cli.node.create_private_key.RSACryptor")
|
|
342
|
-
@patch("vantage6.cli.node.create_private_key.create_client_and_authenticate")
|
|
343
|
-
@patch("vantage6.cli.node.common.NodeContext")
|
|
344
|
-
@patch("vantage6.cli.node.create_private_key.NodeContext")
|
|
345
|
-
def test_create_private_key_overwite(
|
|
346
|
-
self, context, common_context, client, cryptor
|
|
347
|
-
):
|
|
348
|
-
common_context.config_exists.return_value = True
|
|
349
|
-
context.return_value.type_data_folder.return_value = Path(".")
|
|
350
|
-
client.return_value = MagicMock(whoami=MagicMock(organization_name="Test"))
|
|
351
|
-
cryptor.create_public_key_bytes.return_value = b""
|
|
352
|
-
# client.whoami.organization_name = "Test"
|
|
353
|
-
|
|
354
|
-
runner = CliRunner()
|
|
355
|
-
|
|
356
|
-
# overwrite
|
|
357
|
-
with runner.isolated_filesystem():
|
|
358
|
-
with open("privkey_iknl.pem", "w") as f:
|
|
359
|
-
f.write("does-not-matter")
|
|
360
|
-
|
|
361
|
-
result = runner.invoke(
|
|
362
|
-
cli_node_create_private_key,
|
|
363
|
-
["--name", "application", "--overwrite", "--organization-name", "iknl"],
|
|
364
|
-
)
|
|
365
|
-
self.assertEqual(result.exit_code, 0)
|
|
366
|
-
|
|
367
|
-
# do not overwrite
|
|
368
|
-
with runner.isolated_filesystem():
|
|
369
|
-
with open("privkey_iknl.pem", "w") as f:
|
|
370
|
-
f.write("does-not-matter")
|
|
371
|
-
|
|
372
|
-
result = runner.invoke(
|
|
373
|
-
cli_node_create_private_key,
|
|
374
|
-
["--name", "application", "--organization-name", "iknl"],
|
|
375
|
-
)
|
|
376
|
-
|
|
377
|
-
# print(result.output)
|
|
378
|
-
|
|
379
|
-
self.assertEqual(result.exit_code, 0)
|
|
380
|
-
|
|
381
|
-
@patch("vantage6.cli.node.common.NodeContext")
|
|
382
|
-
def test_create_private_key_config_not_found(self, context):
|
|
383
|
-
context.config_exists.return_value = False
|
|
384
|
-
|
|
385
|
-
runner = CliRunner()
|
|
386
|
-
result = runner.invoke(cli_node_create_private_key, ["--name", "application"])
|
|
387
|
-
|
|
388
|
-
self.assertEqual(result.exit_code, 1)
|
|
389
|
-
|
|
390
|
-
@patch("vantage6.cli.node.clean.q")
|
|
391
|
-
@patch("docker.DockerClient.volumes")
|
|
392
|
-
@patch("vantage6.common.docker.addons.check_docker_running")
|
|
393
|
-
def test_clean_docker_error(self, check_docker, volumes, q):
|
|
394
|
-
volume1 = MagicMock()
|
|
395
|
-
volume1.name = "some-name-tmpvol"
|
|
396
|
-
volume1.remove.side_effect = APIError("Testing")
|
|
397
|
-
volumes.list.return_value = [volume1]
|
|
398
|
-
question = MagicMock(name="pop-the-question")
|
|
399
|
-
question.ask.return_value = True
|
|
400
|
-
q.confirm.return_value = question
|
|
401
|
-
|
|
402
|
-
runner = CliRunner()
|
|
403
|
-
result = runner.invoke(cli_node_clean)
|
|
404
|
-
|
|
405
|
-
# check exit code
|
|
406
|
-
self.assertEqual(result.exit_code, 1)
|
|
407
|
-
|
|
408
|
-
def test_print_log_worker(self):
|
|
409
|
-
stream = BytesIO("Hello!".encode(STRING_ENCODING))
|
|
410
|
-
temp_stdout = StringIO()
|
|
411
|
-
with contextlib.redirect_stdout(temp_stdout):
|
|
412
|
-
print_log_worker(stream)
|
|
413
|
-
output = temp_stdout.getvalue().strip()
|
|
414
|
-
self.assertEqual(output, "Hello!")
|
|
415
|
-
|
|
416
|
-
@patch("vantage6.cli.node.common.info")
|
|
417
|
-
@patch("vantage6.cli.node.common.debug")
|
|
418
|
-
@patch("vantage6.cli.node.common.error")
|
|
419
|
-
@patch("vantage6.cli.node.common.UserClient")
|
|
420
|
-
def test_client(self, client, error, debug, info):
|
|
421
|
-
ctx = MagicMock(
|
|
422
|
-
config={
|
|
423
|
-
"server_url": "localhost",
|
|
424
|
-
"port": Ports.DEV_SERVER.value,
|
|
425
|
-
"api_path": "",
|
|
426
|
-
}
|
|
427
|
-
)
|
|
428
|
-
|
|
429
|
-
# should not trigger an exception
|
|
430
|
-
try:
|
|
431
|
-
create_client_and_authenticate(ctx)
|
|
432
|
-
except Exception:
|
|
433
|
-
self.fail("Raised an exception!")
|
|
434
|
-
|
|
435
|
-
# client raises exception
|
|
436
|
-
client.side_effect = Exception("Boom!")
|
|
437
|
-
with self.assertRaises(Exception):
|
|
438
|
-
create_client_and_authenticate(ctx)
|
|
439
|
-
|
|
440
|
-
# TODO this function has been moved to the common package. A test should
|
|
441
|
-
# be added there instead of here
|
|
442
|
-
# @patch("vantage6.cli.node.error")
|
|
443
|
-
# def test_check_docker(self, error):
|
|
444
|
-
# docker = MagicMock()
|
|
445
|
-
# try:
|
|
446
|
-
# check_docker_running()
|
|
447
|
-
# except Exception:
|
|
448
|
-
# self.fail("Exception raised!")
|
|
449
|
-
|
|
450
|
-
# docker.ping.side_effect = Exception("Boom!")
|
|
451
|
-
# with self.assertRaises(SystemExit):
|
|
452
|
-
# check_docker_running()
|
tests_cli/test_server_cli.py
DELETED
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
import unittest
|
|
2
|
-
from pathlib import Path
|
|
3
|
-
from unittest.mock import MagicMock, patch
|
|
4
|
-
|
|
5
|
-
from click.testing import CliRunner
|
|
6
|
-
|
|
7
|
-
from vantage6.common.globals import APPNAME, InstanceType
|
|
8
|
-
|
|
9
|
-
from vantage6.cli.common.utils import attach_logs
|
|
10
|
-
from vantage6.cli.server.attach import cli_server_attach
|
|
11
|
-
from vantage6.cli.server.files import cli_server_files
|
|
12
|
-
from vantage6.cli.server.import_ import cli_server_import
|
|
13
|
-
from vantage6.cli.server.list import cli_server_configuration_list
|
|
14
|
-
from vantage6.cli.server.new import cli_server_new
|
|
15
|
-
from vantage6.cli.server.start import cli_server_start
|
|
16
|
-
from vantage6.cli.server.stop import cli_server_stop
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
class ServerCLITest(unittest.TestCase):
|
|
20
|
-
@patch("vantage6.cli.server.start.NetworkManager")
|
|
21
|
-
@patch("vantage6.cli.server.start.docker.types.Mount")
|
|
22
|
-
@patch("os.makedirs")
|
|
23
|
-
@patch("vantage6.cli.server.start.pull_infra_image")
|
|
24
|
-
@patch("vantage6.cli.common.decorator.get_context")
|
|
25
|
-
@patch("vantage6.cli.server.start.docker.from_env")
|
|
26
|
-
@patch("vantage6.cli.common.start.check_docker_running", return_value=True)
|
|
27
|
-
def test_start(
|
|
28
|
-
self,
|
|
29
|
-
docker_check,
|
|
30
|
-
containers,
|
|
31
|
-
context,
|
|
32
|
-
pull,
|
|
33
|
-
os_makedirs,
|
|
34
|
-
mount,
|
|
35
|
-
network_manager,
|
|
36
|
-
):
|
|
37
|
-
"""Start server without errors"""
|
|
38
|
-
container1 = MagicMock()
|
|
39
|
-
container1.containers.name = f"{APPNAME}-iknl-system"
|
|
40
|
-
containers.containers.list.return_value = [container1]
|
|
41
|
-
containers.containers.run.return_value = True
|
|
42
|
-
|
|
43
|
-
# mount.types.Mount.return_value = MagicMock()
|
|
44
|
-
|
|
45
|
-
ctx = MagicMock(
|
|
46
|
-
config={"uri": "sqlite:///file.db", "port": 9999},
|
|
47
|
-
config_file="/config.yaml",
|
|
48
|
-
data_dir=Path("."),
|
|
49
|
-
)
|
|
50
|
-
ctx.config_exists.return_value = True
|
|
51
|
-
ctx.name = "not-running"
|
|
52
|
-
context.return_value = ctx
|
|
53
|
-
|
|
54
|
-
runner = CliRunner()
|
|
55
|
-
result = runner.invoke(cli_server_start, ["--name", "not-running"])
|
|
56
|
-
|
|
57
|
-
self.assertEqual(result.exit_code, 0)
|
|
58
|
-
|
|
59
|
-
@patch("vantage6.cli.server.common.ServerContext")
|
|
60
|
-
@patch("docker.DockerClient.containers")
|
|
61
|
-
@patch("vantage6.cli.server.list.check_docker_running", return_value=True)
|
|
62
|
-
def test_configuration_list(self, docker_check, containers, context):
|
|
63
|
-
"""Configuration list without errors."""
|
|
64
|
-
container1 = MagicMock()
|
|
65
|
-
container1.name = f"{APPNAME}-iknl-system"
|
|
66
|
-
containers.list.return_value = [container1]
|
|
67
|
-
|
|
68
|
-
config = MagicMock()
|
|
69
|
-
config.name = "iknl"
|
|
70
|
-
context.available_configurations.return_value = ([config], [])
|
|
71
|
-
|
|
72
|
-
runner = CliRunner()
|
|
73
|
-
result = runner.invoke(cli_server_configuration_list)
|
|
74
|
-
|
|
75
|
-
self.assertEqual(result.exit_code, 0)
|
|
76
|
-
self.assertIsNone(result.exception)
|
|
77
|
-
|
|
78
|
-
@patch("vantage6.cli.common.decorator.get_context")
|
|
79
|
-
def test_files(self, context):
|
|
80
|
-
"""Configuration files without errors."""
|
|
81
|
-
|
|
82
|
-
ctx = context.return_value = MagicMock(
|
|
83
|
-
log_file="/log_file.log", config_file="/iknl.yaml"
|
|
84
|
-
)
|
|
85
|
-
ctx.get_database_uri.return_value = "sqlite:///test.db"
|
|
86
|
-
|
|
87
|
-
runner = CliRunner()
|
|
88
|
-
result = runner.invoke(cli_server_files, ["--name", "iknl"])
|
|
89
|
-
|
|
90
|
-
self.assertIsNone(result.exception)
|
|
91
|
-
self.assertEqual(result.exit_code, 0)
|
|
92
|
-
|
|
93
|
-
@patch("docker.DockerClient.containers")
|
|
94
|
-
@patch("vantage6.cli.server.import_.print_log_worker")
|
|
95
|
-
@patch("vantage6.cli.server.import_.click.Path")
|
|
96
|
-
@patch("vantage6.cli.server.import_.pull_image")
|
|
97
|
-
@patch("vantage6.cli.server.import_.check_docker_running", return_value=True)
|
|
98
|
-
@patch("vantage6.cli.common.decorator.get_context")
|
|
99
|
-
def test_import(self, context, docker_check, pull, click_path, log, containers):
|
|
100
|
-
"""Import entities without errors."""
|
|
101
|
-
click_path.return_value = MagicMock()
|
|
102
|
-
|
|
103
|
-
ctx = MagicMock()
|
|
104
|
-
ctx.name = "some-name"
|
|
105
|
-
context.return_value = ctx
|
|
106
|
-
|
|
107
|
-
runner = CliRunner()
|
|
108
|
-
with runner.isolated_filesystem():
|
|
109
|
-
with open("some.yaml", "w") as fp:
|
|
110
|
-
fp.write("does-not-matter")
|
|
111
|
-
result = runner.invoke(cli_server_import, ["--name", "iknl", "some.yaml"])
|
|
112
|
-
|
|
113
|
-
self.assertIsNone(result.exception)
|
|
114
|
-
self.assertEqual(result.exit_code, 0)
|
|
115
|
-
|
|
116
|
-
@patch("vantage6.cli.server.new.configuration_wizard")
|
|
117
|
-
@patch("vantage6.cli.server.new.ensure_config_dir_writable")
|
|
118
|
-
@patch("vantage6.cli.server.new.ServerContext")
|
|
119
|
-
def test_new(self, context, permissions, wizard):
|
|
120
|
-
"""New configuration without errors."""
|
|
121
|
-
|
|
122
|
-
context.config_exists.return_value = False
|
|
123
|
-
permissions.return_value = True
|
|
124
|
-
wizard.return_value = "/some/file.yaml"
|
|
125
|
-
|
|
126
|
-
runner = CliRunner()
|
|
127
|
-
result = runner.invoke(cli_server_new, ["--name", "iknl"])
|
|
128
|
-
|
|
129
|
-
self.assertIsNone(result.exception)
|
|
130
|
-
self.assertEqual(result.exit_code, 0)
|
|
131
|
-
|
|
132
|
-
@patch("vantage6.cli.server.stop.docker.from_env")
|
|
133
|
-
def test_stop(self, containers):
|
|
134
|
-
"""Stop server without errors."""
|
|
135
|
-
|
|
136
|
-
container1 = MagicMock()
|
|
137
|
-
container1.name = f"{APPNAME}-iknl-system-{InstanceType.SERVER}"
|
|
138
|
-
containers.containers.list.return_value = [container1]
|
|
139
|
-
|
|
140
|
-
runner = CliRunner()
|
|
141
|
-
result = runner.invoke(cli_server_stop, ["--name", "iknl"])
|
|
142
|
-
|
|
143
|
-
self.assertIsNone(result.exception)
|
|
144
|
-
self.assertEqual(result.exit_code, 0)
|
|
145
|
-
|
|
146
|
-
@patch("vantage6.cli.server.attach.attach_logs")
|
|
147
|
-
def test_attach(self, attach_logs):
|
|
148
|
-
"""Attach logs to the console without errors."""
|
|
149
|
-
runner = CliRunner()
|
|
150
|
-
result = runner.invoke(cli_server_attach)
|
|
151
|
-
|
|
152
|
-
self.assertIsNone(result.exception)
|
|
153
|
-
self.assertEqual(result.exit_code, 0)
|
|
154
|
-
attach_logs.assert_called_once_with(
|
|
155
|
-
"app=vantage6-server", "component=vantage6-server"
|
|
156
|
-
)
|
|
157
|
-
|
|
158
|
-
@patch("vantage6.cli.common.utils.Popen")
|
|
159
|
-
def test_attach_logs(self, mock_popen):
|
|
160
|
-
# Mock the Popen instance and its methods
|
|
161
|
-
mock_process = mock_popen.return_value
|
|
162
|
-
mock_process.wait.return_value = None
|
|
163
|
-
|
|
164
|
-
# Call the function with a sample label
|
|
165
|
-
attach_logs("app=node", "env=dev")
|
|
166
|
-
|
|
167
|
-
# Construct the expected command
|
|
168
|
-
expected_command = [
|
|
169
|
-
"devspace",
|
|
170
|
-
"logs",
|
|
171
|
-
"--follow",
|
|
172
|
-
"--label-selector",
|
|
173
|
-
"app=node,env=dev",
|
|
174
|
-
]
|
|
175
|
-
|
|
176
|
-
# Verify that Popen was called with the expected command
|
|
177
|
-
mock_popen.assert_called_once_with(expected_command, stdout=None, stderr=None)
|
|
178
|
-
|
|
179
|
-
# Verify that wait was called on the process
|
|
180
|
-
mock_process.wait.assert_called_once()
|