907ff404e357291c21ba5289f42dcdfacf45b37d
[osm/N2VC.git] / n2vc / tests / unit / test_k8s_helm_conn.py
1 ##
2 # Licensed under the Apache License, Version 2.0 (the "License"); you may
3 # not use this file except in compliance with the License. You may obtain
4 # a copy of the License at
5 #
6 # http://www.apache.org/licenses/LICENSE-2.0
7 #
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11 # License for the specific language governing permissions and limitations
12 # under the License.
13 #
14 # For those usages not covered by the Apache License, Version 2.0 please
15 # contact: alfonso.tiernosepulveda@telefonica.com
16 ##
17
18 import asynctest
19 import logging
20
21 from asynctest.mock import Mock
22 from osm_common.dbmemory import DbMemory
23 from osm_common.fslocal import FsLocal
24 from n2vc.k8s_helm_conn import K8sHelmConnector
25
26 __author__ = "Isabel Lloret <illoret@indra.es>"
27
28
29 class TestK8sHelmConn(asynctest.TestCase):
30 logging.basicConfig(level=logging.DEBUG)
31 logger = logging.getLogger(__name__)
32 logger.setLevel(logging.DEBUG)
33
34 async def setUp(self):
35 self.db = Mock(DbMemory())
36 self.fs = asynctest.Mock(FsLocal())
37 self.fs.path = "./tmp/"
38 self.namespace = "testk8s"
39 self.service_account = "osm"
40 self.cluster_id = "helm_cluster_id"
41 self.cluster_uuid = self.cluster_id
42 # pass fake kubectl and helm commands to make sure it does not call actual commands
43 K8sHelmConnector._check_file_exists = asynctest.Mock(return_value=True)
44 K8sHelmConnector._local_async_exec = asynctest.CoroutineMock(
45 return_value=(0, "")
46 )
47 cluster_dir = self.fs.path + self.cluster_id
48 self.kube_config = self.fs.path + self.cluster_id + "/.kube/config"
49 self.helm_home = self.fs.path + self.cluster_id + "/.helm"
50 self.env = {
51 "HELM_HOME": "{}/.helm".format(cluster_dir),
52 "KUBECONFIG": "{}/.kube/config".format(cluster_dir),
53 }
54 self.helm_conn = K8sHelmConnector(self.fs, self.db, log=self.logger)
55 self.logger.debug("Set up executed")
56
57 @asynctest.fail_on(active_handles=True)
58 async def test_init_env(self):
59 # TODO
60 pass
61
62 @asynctest.fail_on(active_handles=True)
63 async def test_repo_add(self):
64 repo_name = "bitnami"
65 repo_url = "https://charts.bitnami.com/bitnami"
66 self.helm_conn._local_async_exec = asynctest.CoroutineMock(return_value=("", 0))
67
68 await self.helm_conn.repo_add(self.cluster_uuid, repo_name, repo_url)
69
70 self.helm_conn.fs.sync.assert_called_once_with(from_path=self.cluster_id)
71 self.helm_conn.fs.reverse_sync.assert_called_once_with(
72 from_path=self.cluster_id
73 )
74 self.assertEqual(
75 self.helm_conn._local_async_exec.call_count,
76 2,
77 "local_async_exec expected 2 calls, called {}".format(
78 self.helm_conn._local_async_exec.call_count
79 ),
80 )
81
82 repo_update_command = (
83 "env KUBECONFIG=./tmp/helm_cluster_id/.kube/config /usr/bin/helm repo update {}"
84 ).format(repo_name)
85 repo_add_command = (
86 "env KUBECONFIG=./tmp/helm_cluster_id/.kube/config /usr/bin/helm repo add {} {}"
87 ).format(repo_name, repo_url)
88 calls = self.helm_conn._local_async_exec.call_args_list
89 call0_kargs = calls[0][1]
90 self.assertEqual(
91 call0_kargs.get("command"),
92 repo_add_command,
93 "Invalid repo add command: {}".format(call0_kargs.get("command")),
94 )
95 self.assertEqual(
96 call0_kargs.get("env"),
97 self.env,
98 "Invalid env for add command: {}".format(call0_kargs.get("env")),
99 )
100 call1_kargs = calls[1][1]
101 self.assertEqual(
102 call1_kargs.get("command"),
103 repo_update_command,
104 "Invalid repo update command: {}".format(call1_kargs.get("command")),
105 )
106 self.assertEqual(
107 call1_kargs.get("env"),
108 self.env,
109 "Invalid env for update command: {}".format(call1_kargs.get("env")),
110 )
111
112 @asynctest.fail_on(active_handles=True)
113 async def test_repo_list(self):
114 self.helm_conn._local_async_exec = asynctest.CoroutineMock(return_value=("", 0))
115
116 await self.helm_conn.repo_list(self.cluster_uuid)
117
118 self.helm_conn.fs.sync.assert_called_once_with(from_path=self.cluster_id)
119 self.helm_conn.fs.reverse_sync.assert_called_once_with(
120 from_path=self.cluster_id
121 )
122 command = "env KUBECONFIG=./tmp/helm_cluster_id/.kube/config /usr/bin/helm repo list --output yaml"
123 self.helm_conn._local_async_exec.assert_called_with(
124 command=command, env=self.env, raise_exception_on_error=False
125 )
126
127 @asynctest.fail_on(active_handles=True)
128 async def test_repo_remove(self):
129 self.helm_conn._local_async_exec = asynctest.CoroutineMock(return_value=("", 0))
130 repo_name = "bitnami"
131 await self.helm_conn.repo_remove(self.cluster_uuid, repo_name)
132
133 self.helm_conn.fs.sync.assert_called_once_with(from_path=self.cluster_id)
134 self.helm_conn.fs.reverse_sync.assert_called_once_with(
135 from_path=self.cluster_id
136 )
137 command = "env KUBECONFIG=./tmp/helm_cluster_id/.kube/config /usr/bin/helm repo remove {}".format(
138 repo_name
139 )
140 self.helm_conn._local_async_exec.assert_called_once_with(
141 command=command, env=self.env, raise_exception_on_error=True
142 )
143
144 @asynctest.fail_on(active_handles=True)
145 async def test_install(self):
146 kdu_model = "stable/openldap:1.2.2"
147 kdu_instance = "stable-openldap-0005399828"
148 db_dict = {}
149 self.helm_conn._local_async_exec = asynctest.CoroutineMock(return_value=("", 0))
150 self.helm_conn._status_kdu = asynctest.CoroutineMock(return_value=None)
151 self.helm_conn._store_status = asynctest.CoroutineMock()
152 self.helm_conn.generate_kdu_instance_name = Mock(return_value=kdu_instance)
153
154 await self.helm_conn.install(
155 self.cluster_uuid,
156 kdu_model,
157 kdu_instance,
158 atomic=True,
159 namespace=self.namespace,
160 db_dict=db_dict,
161 )
162
163 self.helm_conn.fs.sync.assert_called_once_with(from_path=self.cluster_id)
164 self.helm_conn.fs.reverse_sync.assert_called_once_with(
165 from_path=self.cluster_id
166 )
167 self.helm_conn._store_status.assert_called_with(
168 cluster_id=self.cluster_id,
169 kdu_instance=kdu_instance,
170 namespace=self.namespace,
171 db_dict=db_dict,
172 operation="install",
173 )
174 command = (
175 "env KUBECONFIG=./tmp/helm_cluster_id/.kube/config /usr/bin/helm install "
176 "--atomic --output yaml --timeout 300 "
177 "--name=stable-openldap-0005399828 --namespace testk8s stable/openldap "
178 "--version 1.2.2"
179 )
180 self.helm_conn._local_async_exec.assert_called_once_with(
181 command=command, env=self.env, raise_exception_on_error=False
182 )
183
184 @asynctest.fail_on(active_handles=True)
185 async def test_upgrade(self):
186 kdu_model = "stable/openldap:1.2.3"
187 kdu_instance = "stable-openldap-0005399828"
188 db_dict = {}
189 instance_info = {
190 "chart": "openldap-1.2.2",
191 "name": kdu_instance,
192 "namespace": self.namespace,
193 "revision": 1,
194 "status": "DEPLOYED",
195 }
196 self.helm_conn._local_async_exec = asynctest.CoroutineMock(return_value=("", 0))
197 self.helm_conn._store_status = asynctest.CoroutineMock()
198 self.helm_conn.get_instance_info = asynctest.CoroutineMock(
199 return_value=instance_info
200 )
201
202 await self.helm_conn.upgrade(
203 self.cluster_uuid, kdu_instance, kdu_model, atomic=True, db_dict=db_dict
204 )
205 self.helm_conn.fs.sync.assert_called_with(from_path=self.cluster_id)
206 self.helm_conn.fs.reverse_sync.assert_called_once_with(
207 from_path=self.cluster_id
208 )
209 self.helm_conn._store_status.assert_called_with(
210 cluster_id=self.cluster_id,
211 kdu_instance=kdu_instance,
212 namespace=self.namespace,
213 db_dict=db_dict,
214 operation="upgrade",
215 )
216 command = (
217 "env KUBECONFIG=./tmp/helm_cluster_id/.kube/config /usr/bin/helm upgrade "
218 "--atomic --output yaml --timeout 300 stable-openldap-0005399828 stable/openldap --version 1.2.3"
219 )
220 self.helm_conn._local_async_exec.assert_called_once_with(
221 command=command, env=self.env, raise_exception_on_error=False
222 )
223
224 @asynctest.fail_on(active_handles=True)
225 async def test_scale(self):
226 kdu_model = "stable/openldap:1.2.3"
227 kdu_instance = "stable-openldap-0005399828"
228 db_dict = {}
229 instance_info = {
230 "chart": "openldap-1.2.3",
231 "name": kdu_instance,
232 "namespace": self.namespace,
233 "revision": 1,
234 "status": "DEPLOYED",
235 }
236 repo_list = [
237 {
238 "name": "stable",
239 "url": "https://kubernetes-charts.storage.googleapis.com/",
240 }
241 ]
242 kdu_values = """
243 # Default values for openldap.
244 # This is a YAML-formatted file.
245 # Declare variables to be passed into your templates.
246
247 replicaCount: 1
248 dummy-app:
249 replicas: 2
250 """
251
252 self.helm_conn.repo_list = asynctest.CoroutineMock(return_value=repo_list)
253 self.helm_conn.values_kdu = asynctest.CoroutineMock(return_value=kdu_values)
254 self.helm_conn._local_async_exec = asynctest.CoroutineMock(return_value=("", 0))
255 self.helm_conn._store_status = asynctest.CoroutineMock()
256 self.helm_conn.get_instance_info = asynctest.CoroutineMock(
257 return_value=instance_info
258 )
259
260 # TEST-1
261 await self.helm_conn.scale(
262 kdu_instance,
263 2,
264 "",
265 kdu_model=kdu_model,
266 cluster_uuid=self.cluster_uuid,
267 atomic=True,
268 db_dict=db_dict,
269 )
270 command = (
271 "env KUBECONFIG=./tmp/helm_cluster_id/.kube/config "
272 "/usr/bin/helm upgrade --atomic --output yaml --set replicaCount=2 "
273 "--timeout 1800s stable-openldap-0005399828 stable/openldap "
274 "--version 1.2.3"
275 )
276 self.helm_conn._local_async_exec.assert_called_once_with(
277 command=command, env=self.env, raise_exception_on_error=False
278 )
279
280 # TEST-2
281 await self.helm_conn.scale(
282 kdu_instance,
283 3,
284 "dummy-app",
285 kdu_model=kdu_model,
286 cluster_uuid=self.cluster_uuid,
287 atomic=True,
288 db_dict=db_dict,
289 )
290 command = (
291 "env KUBECONFIG=./tmp/helm_cluster_id/.kube/config "
292 "/usr/bin/helm upgrade --atomic --output yaml --set dummy-app.replicas=3 "
293 "--timeout 1800s stable-openldap-0005399828 stable/openldap "
294 "--version 1.2.3"
295 )
296 self.helm_conn._local_async_exec.assert_called_with(
297 command=command, env=self.env, raise_exception_on_error=False
298 )
299 self.helm_conn.fs.reverse_sync.assert_called_with(from_path=self.cluster_id)
300 self.helm_conn._store_status.assert_called_with(
301 cluster_id=self.cluster_id,
302 kdu_instance=kdu_instance,
303 namespace=self.namespace,
304 db_dict=db_dict,
305 operation="scale",
306 )
307
308 @asynctest.fail_on(active_handles=True)
309 async def test_rollback(self):
310 kdu_instance = "stable-openldap-0005399828"
311 db_dict = {}
312 instance_info = {
313 "chart": "openldap-1.2.3",
314 "name": kdu_instance,
315 "namespace": self.namespace,
316 "revision": 2,
317 "status": "DEPLOYED",
318 }
319 self.helm_conn._local_async_exec = asynctest.CoroutineMock(return_value=("", 0))
320 self.helm_conn._store_status = asynctest.CoroutineMock()
321 self.helm_conn.get_instance_info = asynctest.CoroutineMock(
322 return_value=instance_info
323 )
324
325 await self.helm_conn.rollback(
326 self.cluster_uuid, kdu_instance=kdu_instance, revision=1, db_dict=db_dict
327 )
328 self.helm_conn.fs.sync.assert_called_with(from_path=self.cluster_id)
329 self.helm_conn.fs.reverse_sync.assert_called_once_with(
330 from_path=self.cluster_id
331 )
332 self.helm_conn._store_status.assert_called_with(
333 cluster_id=self.cluster_id,
334 kdu_instance=kdu_instance,
335 namespace=self.namespace,
336 db_dict=db_dict,
337 operation="rollback",
338 )
339 command = (
340 "env KUBECONFIG=./tmp/helm_cluster_id/.kube/config "
341 "/usr/bin/helm rollback stable-openldap-0005399828 1 --wait"
342 )
343 self.helm_conn._local_async_exec.assert_called_once_with(
344 command=command, env=self.env, raise_exception_on_error=False
345 )
346
347 @asynctest.fail_on(active_handles=True)
348 async def test_uninstall(self):
349 kdu_instance = "stable-openldap-0005399828"
350 instance_info = {
351 "chart": "openldap-1.2.2",
352 "name": kdu_instance,
353 "namespace": self.namespace,
354 "revision": 3,
355 "status": "DEPLOYED",
356 }
357 self.helm_conn._local_async_exec = asynctest.CoroutineMock(return_value=("", 0))
358 self.helm_conn._store_status = asynctest.CoroutineMock()
359 self.helm_conn.get_instance_info = asynctest.CoroutineMock(
360 return_value=instance_info
361 )
362
363 await self.helm_conn.uninstall(self.cluster_uuid, kdu_instance)
364 self.helm_conn.fs.sync.assert_called_with(from_path=self.cluster_id)
365 self.helm_conn.fs.reverse_sync.assert_called_once_with(
366 from_path=self.cluster_id
367 )
368 command = "env KUBECONFIG=./tmp/helm_cluster_id/.kube/config /usr/bin/helm delete --purge {}".format(
369 kdu_instance
370 )
371 self.helm_conn._local_async_exec.assert_called_once_with(
372 command=command, env=self.env, raise_exception_on_error=True
373 )
374
375 @asynctest.fail_on(active_handles=True)
376 async def test_get_services(self):
377 kdu_instance = "test_services_1"
378 service = {"name": "testservice", "type": "LoadBalancer"}
379 self.helm_conn._local_async_exec_pipe = asynctest.CoroutineMock(
380 return_value=("", 0)
381 )
382 self.helm_conn._parse_services = Mock(return_value=["testservice"])
383 self.helm_conn._get_service = asynctest.CoroutineMock(return_value=service)
384
385 services = await self.helm_conn.get_services(
386 self.cluster_uuid, kdu_instance, self.namespace
387 )
388 self.helm_conn.fs.sync.assert_called_once_with(from_path=self.cluster_id)
389 self.helm_conn.fs.reverse_sync.assert_called_once_with(
390 from_path=self.cluster_id
391 )
392 self.helm_conn._parse_services.assert_called_once()
393 command1 = "env KUBECONFIG=./tmp/helm_cluster_id/.kube/config /usr/bin/helm get manifest {} ".format(
394 kdu_instance
395 )
396 command2 = "/usr/bin/kubectl get --namespace={} -f -".format(self.namespace)
397 self.helm_conn._local_async_exec_pipe.assert_called_once_with(
398 command1, command2, env=self.env, raise_exception_on_error=True
399 )
400 self.assertEqual(
401 services, [service], "Invalid service returned from get_service"
402 )
403
404 @asynctest.fail_on(active_handles=True)
405 async def test_get_service(self):
406 service_name = "service1"
407
408 self.helm_conn._local_async_exec = asynctest.CoroutineMock(return_value=("", 0))
409 await self.helm_conn.get_service(
410 self.cluster_uuid, service_name, self.namespace
411 )
412
413 self.helm_conn.fs.sync.assert_called_once_with(from_path=self.cluster_id)
414 self.helm_conn.fs.reverse_sync.assert_called_once_with(
415 from_path=self.cluster_id
416 )
417 command = (
418 "/usr/bin/kubectl --kubeconfig=./tmp/helm_cluster_id/.kube/config "
419 "--namespace=testk8s get service service1 -o=yaml"
420 )
421 self.helm_conn._local_async_exec.assert_called_once_with(
422 command=command, env=self.env, raise_exception_on_error=True
423 )
424
425 @asynctest.fail_on(active_handles=True)
426 async def test_inspect_kdu(self):
427 self.helm_conn._local_async_exec = asynctest.CoroutineMock(return_value=("", 0))
428
429 kdu_model = "stable/openldap:1.2.4"
430 repo_url = "https://kubernetes-charts.storage.googleapis.com/"
431 await self.helm_conn.inspect_kdu(kdu_model, repo_url)
432
433 command = (
434 "/usr/bin/helm inspect openldap --repo "
435 "https://kubernetes-charts.storage.googleapis.com/ "
436 "--version 1.2.4"
437 )
438 self.helm_conn._local_async_exec.assert_called_with(command=command)
439
440 @asynctest.fail_on(active_handles=True)
441 async def test_help_kdu(self):
442 self.helm_conn._local_async_exec = asynctest.CoroutineMock(return_value=("", 0))
443
444 kdu_model = "stable/openldap:1.2.4"
445 repo_url = "https://kubernetes-charts.storage.googleapis.com/"
446 await self.helm_conn.help_kdu(kdu_model, repo_url)
447
448 command = (
449 "/usr/bin/helm inspect readme openldap --repo "
450 "https://kubernetes-charts.storage.googleapis.com/ "
451 "--version 1.2.4"
452 )
453 self.helm_conn._local_async_exec.assert_called_with(command=command)
454
455 @asynctest.fail_on(active_handles=True)
456 async def test_values_kdu(self):
457 self.helm_conn._local_async_exec = asynctest.CoroutineMock(return_value=("", 0))
458
459 kdu_model = "stable/openldap:1.2.4"
460 repo_url = "https://kubernetes-charts.storage.googleapis.com/"
461 await self.helm_conn.values_kdu(kdu_model, repo_url)
462
463 command = (
464 "/usr/bin/helm inspect values openldap --repo "
465 "https://kubernetes-charts.storage.googleapis.com/ "
466 "--version 1.2.4"
467 )
468 self.helm_conn._local_async_exec.assert_called_with(command=command)
469
470 @asynctest.fail_on(active_handles=True)
471 async def test_get_values_kdu(self):
472 self.helm_conn._local_async_exec = asynctest.CoroutineMock(return_value=("", 0))
473
474 kdu_instance = "stable-openldap-0005399828"
475 await self.helm_conn.get_values_kdu(
476 kdu_instance, self.namespace, self.env["KUBECONFIG"]
477 )
478
479 command = (
480 "env KUBECONFIG=./tmp/helm_cluster_id/.kube/config /usr/bin/helm get values "
481 "stable-openldap-0005399828 --output yaml"
482 )
483 self.helm_conn._local_async_exec.assert_called_with(command=command)
484
485 @asynctest.fail_on(active_handles=True)
486 async def test_instances_list(self):
487 self.helm_conn._local_async_exec = asynctest.CoroutineMock(return_value=("", 0))
488
489 await self.helm_conn.instances_list(self.cluster_uuid)
490 self.helm_conn.fs.sync.assert_called_once_with(from_path=self.cluster_id)
491 self.helm_conn.fs.reverse_sync.assert_called_once_with(
492 from_path=self.cluster_id
493 )
494 command = "/usr/bin/helm list --output yaml"
495 self.helm_conn._local_async_exec.assert_called_once_with(
496 command=command, env=self.env, raise_exception_on_error=True
497 )
498
499 @asynctest.fail_on(active_handles=True)
500 async def test_status_kdu(self):
501 kdu_instance = "stable-openldap-0005399828"
502 self.helm_conn._local_async_exec = asynctest.CoroutineMock(return_value=("", 0))
503
504 await self.helm_conn._status_kdu(
505 self.cluster_id, kdu_instance, self.namespace, yaml_format=True
506 )
507 command = (
508 "env KUBECONFIG=./tmp/helm_cluster_id/.kube/config /usr/bin/helm status {} --output yaml"
509 ).format(kdu_instance)
510 self.helm_conn._local_async_exec.assert_called_once_with(
511 command=command,
512 env=self.env,
513 raise_exception_on_error=True,
514 show_error_log=False,
515 )
516
517 @asynctest.fail_on(active_handles=True)
518 async def test_store_status(self):
519 kdu_instance = "stable-openldap-0005399828"
520 db_dict = {}
521 status = {
522 "info": {
523 "description": "Install complete",
524 "status": {
525 "code": "1",
526 "notes": "The openldap helm chart has been installed",
527 },
528 }
529 }
530 self.helm_conn._status_kdu = asynctest.CoroutineMock(return_value=status)
531 self.helm_conn.write_app_status_to_db = asynctest.CoroutineMock(
532 return_value=status
533 )
534
535 await self.helm_conn._store_status(
536 cluster_id=self.cluster_id,
537 kdu_instance=kdu_instance,
538 namespace=self.namespace,
539 db_dict=db_dict,
540 operation="install",
541 )
542 self.helm_conn._status_kdu.assert_called_once_with(
543 cluster_id=self.cluster_id,
544 kdu_instance=kdu_instance,
545 namespace=self.namespace,
546 yaml_format=False,
547 )
548 self.helm_conn.write_app_status_to_db.assert_called_once_with(
549 db_dict=db_dict,
550 status="Install complete",
551 detailed_status=str(status),
552 operation="install",
553 )
554
555 @asynctest.fail_on(active_handles=True)
556 async def test_reset_uninstall_false(self):
557 self.helm_conn._uninstall_sw = asynctest.CoroutineMock()
558
559 await self.helm_conn.reset(self.cluster_uuid, force=False, uninstall_sw=False)
560 self.helm_conn.fs.sync.assert_called_once_with(from_path=self.cluster_id)
561 self.helm_conn.fs.file_delete.assert_called_once_with(
562 self.cluster_id, ignore_non_exist=True
563 )
564 self.helm_conn._uninstall_sw.assert_not_called()
565
566 @asynctest.fail_on(active_handles=True)
567 async def test_reset_uninstall(self):
568 kdu_instance = "stable-openldap-0021099429"
569 instances = [
570 {
571 "app_version": "2.4.48",
572 "chart": "openldap-1.2.3",
573 "name": kdu_instance,
574 "namespace": self.namespace,
575 "revision": "1",
576 "status": "deployed",
577 "updated": "2020-10-30 11:11:20.376744191 +0000 UTC",
578 }
579 ]
580 self.helm_conn._get_namespace = Mock(return_value=self.namespace)
581 self.helm_conn._uninstall_sw = asynctest.CoroutineMock()
582 self.helm_conn.instances_list = asynctest.CoroutineMock(return_value=instances)
583 self.helm_conn.uninstall = asynctest.CoroutineMock()
584
585 await self.helm_conn.reset(self.cluster_uuid, force=True, uninstall_sw=True)
586 self.helm_conn.fs.sync.assert_called_once_with(from_path=self.cluster_id)
587 self.helm_conn.fs.file_delete.assert_called_once_with(
588 self.cluster_id, ignore_non_exist=True
589 )
590 self.helm_conn._get_namespace.assert_called_once_with(
591 cluster_uuid=self.cluster_uuid
592 )
593 self.helm_conn.instances_list.assert_called_once_with(
594 cluster_uuid=self.cluster_uuid
595 )
596 self.helm_conn.uninstall.assert_called_once_with(
597 cluster_uuid=self.cluster_uuid, kdu_instance=kdu_instance
598 )
599 self.helm_conn._uninstall_sw.assert_called_once_with(
600 cluster_id=self.cluster_id, namespace=self.namespace
601 )
602
603 @asynctest.fail_on(active_handles=True)
604 async def test_uninstall_sw_namespace(self):
605 self.helm_conn._local_async_exec = asynctest.CoroutineMock(return_value=("", 0))
606
607 await self.helm_conn._uninstall_sw(self.cluster_id, self.namespace)
608 calls = self.helm_conn._local_async_exec.call_args_list
609 self.assertEqual(
610 len(calls), 3, "To uninstall should have executed three commands"
611 )
612 call0_kargs = calls[0][1]
613 command_0 = "/usr/bin/helm --kubeconfig={} --home={} reset".format(
614 self.kube_config, self.helm_home
615 )
616 self.assertEqual(
617 call0_kargs,
618 {"command": command_0, "raise_exception_on_error": True, "env": self.env},
619 "Invalid args for first call to local_exec",
620 )
621 call1_kargs = calls[1][1]
622 command_1 = (
623 "/usr/bin/kubectl --kubeconfig={} delete "
624 "clusterrolebinding.rbac.authorization.k8s.io/osm-tiller-cluster-rule".format(
625 self.kube_config
626 )
627 )
628 self.assertEqual(
629 call1_kargs,
630 {"command": command_1, "raise_exception_on_error": False, "env": self.env},
631 "Invalid args for second call to local_exec",
632 )
633 call2_kargs = calls[2][1]
634 command_2 = (
635 "/usr/bin/kubectl --kubeconfig={} --namespace {} delete "
636 "serviceaccount/{}".format(
637 self.kube_config, self.namespace, self.service_account
638 )
639 )
640 self.assertEqual(
641 call2_kargs,
642 {"command": command_2, "raise_exception_on_error": False, "env": self.env},
643 "Invalid args for third call to local_exec",
644 )