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
6 # http://www.apache.org/licenses/LICENSE-2.0
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
14 # For those usages not covered by the Apache License, Version 2.0 please
15 # contact: alfonso.tiernosepulveda@telefonica.com
21 from asynctest
.mock
import Mock
, patch
22 from osm_common
.dbmemory
import DbMemory
23 from osm_common
.fslocal
import FsLocal
24 from n2vc
.k8s_helm3_conn
import K8sHelm3Connector
, K8sException
26 __author__
= "Isabel Lloret <illoret@indra.es>"
29 class TestK8sHelm3Conn(asynctest
.TestCase
):
30 logging
.basicConfig(level
=logging
.DEBUG
)
31 logger
= logging
.getLogger(__name__
)
32 logger
.setLevel(logging
.DEBUG
)
34 @patch("n2vc.k8s_helm_base_conn.EnvironConfig")
35 async def setUp(self
, mock_env
):
36 mock_env
.return_value
= {
37 "stablerepourl": "https://charts.helm.sh/stable"
39 self
.db
= Mock(DbMemory())
40 self
.fs
= asynctest
.Mock(FsLocal())
41 self
.fs
.path
= "./tmp/"
42 self
.namespace
= "testk8s"
43 self
.cluster_id
= "helm3_cluster_id"
44 self
.cluster_uuid
= "{}:{}".format(self
.namespace
, self
.cluster_id
)
45 # pass fake kubectl and helm commands to make sure it does not call actual commands
46 K8sHelm3Connector
._check
_file
_exists
= asynctest
.Mock(return_value
=True)
47 cluster_dir
= self
.fs
.path
+ self
.cluster_id
49 "HELM_CACHE_HOME": "{}/.cache/helm".format(cluster_dir
),
50 "HELM_CONFIG_HOME": "{}/.config/helm".format(cluster_dir
),
51 "HELM_DATA_HOME": "{}/.local/share/helm".format(cluster_dir
),
52 "KUBECONFIG": "{}/.kube/config".format(cluster_dir
),
54 self
.helm_conn
= K8sHelm3Connector(self
.fs
, self
.db
, log
=self
.logger
)
55 self
.logger
.debug("Set up executed")
57 @asynctest.fail_on(active_handles
=True)
58 async def test_init_env(self
):
59 k8s_creds
= "false_credentials_string"
60 self
.helm_conn
._get
_namespaces
= asynctest
.CoroutineMock(return_value
=[])
61 self
.helm_conn
._create
_namespace
= asynctest
.CoroutineMock()
62 self
.helm_conn
.repo_list
= asynctest
.CoroutineMock(return_value
=[])
63 self
.helm_conn
.repo_add
= asynctest
.CoroutineMock()
65 k8scluster_uuid
, installed
= await self
.helm_conn
.init_env(
66 k8s_creds
, namespace
=self
.namespace
, reuse_cluster_uuid
=self
.cluster_id
71 "{}:{}".format(self
.namespace
, self
.cluster_id
),
72 "Check cluster_uuid format: <namespace>.<cluster_id>",
74 self
.helm_conn
._get
_namespaces
.assert_called_once_with(self
.cluster_id
)
75 self
.helm_conn
._create
_namespace
.assert_called_once_with(
76 self
.cluster_id
, self
.namespace
78 self
.helm_conn
.repo_list
.assert_called_once_with(k8scluster_uuid
)
79 self
.helm_conn
.repo_add
.assert_called_once_with(
80 k8scluster_uuid
, "stable", "https://charts.helm.sh/stable"
82 self
.helm_conn
.fs
.reverse_sync
.assert_called_once_with(
83 from_path
=self
.cluster_id
85 self
.logger
.debug(f
"cluster_uuid: {k8scluster_uuid}")
87 @asynctest.fail_on(active_handles
=True)
88 async def test_repo_add(self
):
90 repo_url
= "https://charts.bitnami.com/bitnami"
91 self
.helm_conn
._local
_async
_exec
= asynctest
.CoroutineMock(return_value
=("", 0))
93 await self
.helm_conn
.repo_add(self
.cluster_uuid
, repo_name
, repo_url
)
95 self
.helm_conn
.fs
.sync
.assert_called_once_with(from_path
=self
.cluster_id
)
96 self
.helm_conn
.fs
.reverse_sync
.assert_called_once_with(
97 from_path
=self
.cluster_id
100 self
.helm_conn
._local
_async
_exec
.call_count
,
102 "local_async_exec expected 2 calls, called {}".format(
103 self
.helm_conn
._local
_async
_exec
.call_count
107 repo_update_command
= "/usr/bin/helm3 repo update"
108 repo_add_command
= "/usr/bin/helm3 repo add {} {}".format(repo_name
, repo_url
)
109 calls
= self
.helm_conn
._local
_async
_exec
.call_args_list
110 call0_kargs
= calls
[0][1]
112 call0_kargs
.get("command"),
114 "Invalid repo update command: {}".format(call0_kargs
.get("command")),
117 call0_kargs
.get("env"),
119 "Invalid env for update command: {}".format(call0_kargs
.get("env")),
121 call1_kargs
= calls
[1][1]
123 call1_kargs
.get("command"),
125 "Invalid repo add command: {}".format(call1_kargs
.get("command")),
128 call1_kargs
.get("env"),
130 "Invalid env for add command: {}".format(call1_kargs
.get("env")),
133 @asynctest.fail_on(active_handles
=True)
134 async def test_repo_list(self
):
136 self
.helm_conn
._local
_async
_exec
= asynctest
.CoroutineMock(return_value
=("", 0))
138 await self
.helm_conn
.repo_list(self
.cluster_uuid
)
140 self
.helm_conn
.fs
.sync
.assert_called_once_with(from_path
=self
.cluster_id
)
141 self
.helm_conn
.fs
.reverse_sync
.assert_called_once_with(
142 from_path
=self
.cluster_id
144 command
= "/usr/bin/helm3 repo list --output yaml"
145 self
.helm_conn
._local
_async
_exec
.assert_called_with(
146 command
=command
, env
=self
.env
, raise_exception_on_error
=False
149 @asynctest.fail_on(active_handles
=True)
150 async def test_repo_remove(self
):
152 self
.helm_conn
._local
_async
_exec
= asynctest
.CoroutineMock(return_value
=("", 0))
153 repo_name
= "bitnami"
154 await self
.helm_conn
.repo_remove(self
.cluster_uuid
, repo_name
)
156 self
.helm_conn
.fs
.sync
.assert_called_once_with(from_path
=self
.cluster_id
)
157 self
.helm_conn
.fs
.reverse_sync
.assert_called_once_with(
158 from_path
=self
.cluster_id
160 command
= "/usr/bin/helm3 repo remove {}".format(repo_name
)
161 self
.helm_conn
._local
_async
_exec
.assert_called_with(
162 command
=command
, env
=self
.env
, raise_exception_on_error
=True
165 @asynctest.fail_on(active_handles
=True)
166 async def test_install(self
):
167 kdu_model
= "stable/openldap:1.2.2"
168 kdu_instance
= "stable-openldap-0005399828"
170 self
.helm_conn
._local
_async
_exec
= asynctest
.CoroutineMock(return_value
=("", 0))
171 self
.helm_conn
._status
_kdu
= asynctest
.CoroutineMock(return_value
=None)
172 self
.helm_conn
._store
_status
= asynctest
.CoroutineMock()
173 self
.kdu_instance
= "stable-openldap-0005399828"
174 self
.helm_conn
.generate_kdu_instance_name
= Mock(return_value
=self
.kdu_instance
)
175 self
.helm_conn
._get
_namespaces
= asynctest
.CoroutineMock(return_value
=[])
176 self
.helm_conn
._namespace
_exists
= asynctest
.CoroutineMock(side_effect
=self
.helm_conn
._namespace
_exists
)
177 self
.helm_conn
._create
_namespace
= asynctest
.CoroutineMock()
179 await self
.helm_conn
.install(
184 namespace
=self
.namespace
,
188 self
.helm_conn
._namespace
_exists
.assert_called_once()
189 self
.helm_conn
._get
_namespaces
.assert_called_once()
190 self
.helm_conn
._create
_namespace
.assert_called_once_with(
191 self
.cluster_id
, self
.namespace
193 self
.helm_conn
.fs
.sync
.assert_called_once_with(from_path
=self
.cluster_id
)
194 self
.helm_conn
.fs
.reverse_sync
.assert_called_once_with(
195 from_path
=self
.cluster_id
197 self
.helm_conn
._store
_status
.assert_called_with(
198 cluster_id
=self
.cluster_id
,
199 kdu_instance
=kdu_instance
,
200 namespace
=self
.namespace
,
207 "/usr/bin/helm3 install stable-openldap-0005399828 --atomic --output yaml "
208 "--timeout 300s --namespace testk8s stable/openldap --version 1.2.2"
210 self
.helm_conn
._local
_async
_exec
.assert_called_once_with(
211 command
=command
, env
=self
.env
, raise_exception_on_error
=False
214 # Exception test if namespace could not being created for some reason
215 self
.helm_conn
._namespace
_exists
.return_value
= False
216 self
.helm_conn
._create
_namespace
.side_effect
= Exception()
218 with self
.assertRaises(K8sException
):
219 await self
.helm_conn
.install(
224 namespace
=self
.namespace
,
228 @asynctest.fail_on(active_handles
=True)
229 async def test_namespace_exists(self
):
230 self
.helm_conn
._get
_namespaces
= asynctest
.CoroutineMock()
232 self
.helm_conn
._get
_namespaces
.return_value
= ['testk8s', 'kube-system']
233 result
= await self
.helm_conn
._namespace
_exists
(self
.cluster_id
, self
.namespace
)
234 self
.helm_conn
._get
_namespaces
.assert_called_once()
235 self
.assertEqual(result
, True)
237 self
.helm_conn
._get
_namespaces
.reset_mock()
238 result
= await self
.helm_conn
._namespace
_exists
(self
.cluster_id
, 'none-exists-namespace')
239 self
.helm_conn
._get
_namespaces
.assert_called_once()
240 self
.assertEqual(result
, False)
242 @asynctest.fail_on(active_handles
=True)
243 async def test_upgrade(self
):
244 kdu_model
= "stable/openldap:1.2.3"
245 kdu_instance
= "stable-openldap-0005399828"
248 "chart": "openldap-1.2.2",
249 "name": kdu_instance
,
250 "namespace": self
.namespace
,
252 "status": "DEPLOYED",
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
260 await self
.helm_conn
.upgrade(
261 self
.cluster_uuid
, kdu_instance
, kdu_model
, atomic
=True, db_dict
=db_dict
263 self
.helm_conn
.fs
.sync
.assert_called_once_with(from_path
=self
.cluster_id
)
264 self
.helm_conn
.fs
.reverse_sync
.assert_called_once_with(
265 from_path
=self
.cluster_id
267 self
.helm_conn
._store
_status
.assert_called_with(
268 cluster_id
=self
.cluster_id
,
269 kdu_instance
=kdu_instance
,
270 namespace
=self
.namespace
,
277 "/usr/bin/helm3 upgrade stable-openldap-0005399828 stable/openldap "
278 "--namespace testk8s --atomic --output yaml --timeout 300s "
281 self
.helm_conn
._local
_async
_exec
.assert_called_once_with(
282 command
=command
, env
=self
.env
, raise_exception_on_error
=False
285 @asynctest.fail_on(active_handles
=True)
286 async def test_rollback(self
):
287 kdu_instance
= "stable-openldap-0005399828"
290 "chart": "openldap-1.2.3",
291 "name": kdu_instance
,
292 "namespace": self
.namespace
,
294 "status": "DEPLOYED",
296 self
.helm_conn
._local
_async
_exec
= asynctest
.CoroutineMock(return_value
=("", 0))
297 self
.helm_conn
._store
_status
= asynctest
.CoroutineMock()
298 self
.helm_conn
.get_instance_info
= asynctest
.CoroutineMock(
299 return_value
=instance_info
302 await self
.helm_conn
.rollback(
303 self
.cluster_uuid
, kdu_instance
=kdu_instance
, revision
=1, db_dict
=db_dict
305 self
.helm_conn
.fs
.sync
.assert_called_once_with(from_path
=self
.cluster_id
)
306 self
.helm_conn
.fs
.reverse_sync
.assert_called_once_with(
307 from_path
=self
.cluster_id
309 self
.helm_conn
._store
_status
.assert_called_with(
310 cluster_id
=self
.cluster_id
,
311 kdu_instance
=kdu_instance
,
312 namespace
=self
.namespace
,
314 operation
="rollback",
318 command
= "/usr/bin/helm3 rollback stable-openldap-0005399828 1 --namespace=testk8s --wait"
319 self
.helm_conn
._local
_async
_exec
.assert_called_once_with(
320 command
=command
, env
=self
.env
, raise_exception_on_error
=False
323 @asynctest.fail_on(active_handles
=True)
324 async def test_uninstall(self
):
325 kdu_instance
= "stable-openldap-0005399828"
327 "chart": "openldap-1.2.2",
328 "name": kdu_instance
,
329 "namespace": self
.namespace
,
331 "status": "DEPLOYED",
333 self
.helm_conn
._local
_async
_exec
= asynctest
.CoroutineMock(return_value
=("", 0))
334 self
.helm_conn
._store
_status
= asynctest
.CoroutineMock()
335 self
.helm_conn
.get_instance_info
= asynctest
.CoroutineMock(
336 return_value
=instance_info
339 await self
.helm_conn
.uninstall(self
.cluster_uuid
, kdu_instance
)
340 self
.helm_conn
.fs
.sync
.assert_called_once_with(from_path
=self
.cluster_id
)
341 self
.helm_conn
.fs
.reverse_sync
.assert_called_once_with(
342 from_path
=self
.cluster_id
344 command
= "/usr/bin/helm3 uninstall {} --namespace={}".format(
345 kdu_instance
, self
.namespace
347 self
.helm_conn
._local
_async
_exec
.assert_called_once_with(
348 command
=command
, env
=self
.env
, raise_exception_on_error
=True
351 @asynctest.fail_on(active_handles
=True)
352 async def test_get_services(self
):
353 kdu_instance
= "test_services_1"
354 service
= {"name": "testservice", "type": "LoadBalancer"}
355 self
.helm_conn
._local
_async
_exec
_pipe
= asynctest
.CoroutineMock(
358 self
.helm_conn
._parse
_services
= Mock(return_value
=["testservice"])
359 self
.helm_conn
._get
_service
= asynctest
.CoroutineMock(return_value
=service
)
361 services
= await self
.helm_conn
.get_services(
362 self
.cluster_uuid
, kdu_instance
, self
.namespace
364 self
.helm_conn
.fs
.sync
.assert_called_once_with(from_path
=self
.cluster_id
)
365 self
.helm_conn
.fs
.reverse_sync
.assert_called_once_with(
366 from_path
=self
.cluster_id
368 self
.helm_conn
._parse
_services
.assert_called_once()
369 command1
= "/usr/bin/helm3 get manifest {} --namespace=testk8s".format(
372 command2
= "/usr/bin/kubectl get --namespace={} -f -".format(self
.namespace
)
373 self
.helm_conn
._local
_async
_exec
_pipe
.assert_called_once_with(
374 command1
, command2
, env
=self
.env
, raise_exception_on_error
=True
377 services
, [service
], "Invalid service returned from get_service"
380 @asynctest.fail_on(active_handles
=True)
381 async def test_get_service(self
):
382 service_name
= "service1"
384 self
.helm_conn
._local
_async
_exec
= asynctest
.CoroutineMock(return_value
=("", 0))
385 await self
.helm_conn
.get_service(
386 self
.cluster_uuid
, service_name
, self
.namespace
389 self
.helm_conn
.fs
.sync
.assert_called_once_with(from_path
=self
.cluster_id
)
390 self
.helm_conn
.fs
.reverse_sync
.assert_called_once_with(
391 from_path
=self
.cluster_id
394 "/usr/bin/kubectl --kubeconfig=./tmp/helm3_cluster_id/.kube/config "
395 "--namespace=testk8s get service service1 -o=yaml"
397 self
.helm_conn
._local
_async
_exec
.assert_called_once_with(
398 command
=command
, env
=self
.env
, raise_exception_on_error
=True
401 @asynctest.fail_on(active_handles
=True)
402 async def test_inspect_kdu(self
):
403 self
.helm_conn
._local
_async
_exec
= asynctest
.CoroutineMock(return_value
=("", 0))
405 kdu_model
= "stable/openldap:1.2.4"
406 repo_url
= "https://kubernetes-charts.storage.googleapis.com/"
407 await self
.helm_conn
.inspect_kdu(kdu_model
, repo_url
)
410 "/usr/bin/helm3 show all openldap --repo "
411 "https://kubernetes-charts.storage.googleapis.com/ "
414 self
.helm_conn
._local
_async
_exec
.assert_called_with(
415 command
=command
, encode_utf8
=True
418 @asynctest.fail_on(active_handles
=True)
419 async def test_help_kdu(self
):
420 self
.helm_conn
._local
_async
_exec
= asynctest
.CoroutineMock(return_value
=("", 0))
422 kdu_model
= "stable/openldap:1.2.4"
423 repo_url
= "https://kubernetes-charts.storage.googleapis.com/"
424 await self
.helm_conn
.help_kdu(kdu_model
, repo_url
)
427 "/usr/bin/helm3 show readme openldap --repo "
428 "https://kubernetes-charts.storage.googleapis.com/ "
431 self
.helm_conn
._local
_async
_exec
.assert_called_with(
432 command
=command
, encode_utf8
=True
435 @asynctest.fail_on(active_handles
=True)
436 async def test_values_kdu(self
):
437 self
.helm_conn
._local
_async
_exec
= asynctest
.CoroutineMock(return_value
=("", 0))
439 kdu_model
= "stable/openldap:1.2.4"
440 repo_url
= "https://kubernetes-charts.storage.googleapis.com/"
441 await self
.helm_conn
.values_kdu(kdu_model
, repo_url
)
444 "/usr/bin/helm3 show values openldap --repo "
445 "https://kubernetes-charts.storage.googleapis.com/ "
448 self
.helm_conn
._local
_async
_exec
.assert_called_with(
449 command
=command
, encode_utf8
=True
452 @asynctest.fail_on(active_handles
=True)
453 async def test_instances_list(self
):
454 self
.helm_conn
._local
_async
_exec
= asynctest
.CoroutineMock(return_value
=("", 0))
456 await self
.helm_conn
.instances_list(self
.cluster_uuid
)
457 self
.helm_conn
.fs
.sync
.assert_called_once_with(from_path
=self
.cluster_id
)
458 self
.helm_conn
.fs
.reverse_sync
.assert_called_once_with(
459 from_path
=self
.cluster_id
461 command
= "/usr/bin/helm3 list --all-namespaces --output yaml"
462 self
.helm_conn
._local
_async
_exec
.assert_called_once_with(
463 command
=command
, env
=self
.env
, raise_exception_on_error
=True
466 @asynctest.fail_on(active_handles
=True)
467 async def test_status_kdu(self
):
468 kdu_instance
= "stable-openldap-0005399828"
469 self
.helm_conn
._local
_async
_exec
= asynctest
.CoroutineMock(return_value
=("", 0))
471 await self
.helm_conn
._status
_kdu
(
472 self
.cluster_id
, kdu_instance
, self
.namespace
, return_text
=True
474 command
= "/usr/bin/helm3 status {} --namespace={} --output yaml".format(
475 kdu_instance
, self
.namespace
477 self
.helm_conn
._local
_async
_exec
.assert_called_once_with(
480 raise_exception_on_error
=True,
481 show_error_log
=False,
484 @asynctest.fail_on(active_handles
=True)
485 async def test_store_status(self
):
486 kdu_instance
= "stable-openldap-0005399828"
490 "description": "Install complete",
493 "notes": "The openldap helm chart has been installed",
497 self
.helm_conn
._status
_kdu
= asynctest
.CoroutineMock(return_value
=status
)
498 self
.helm_conn
.write_app_status_to_db
= asynctest
.CoroutineMock(
502 await self
.helm_conn
._store
_status
(
503 cluster_id
=self
.cluster_id
,
504 kdu_instance
=kdu_instance
,
505 namespace
=self
.namespace
,
511 self
.helm_conn
._status
_kdu
.assert_called_once_with(
512 cluster_id
=self
.cluster_id
,
513 kdu_instance
=kdu_instance
,
514 namespace
=self
.namespace
,
517 self
.helm_conn
.write_app_status_to_db
.assert_called_once_with(
519 status
="Install complete",
520 detailed_status
=str(status
),
524 @asynctest.fail_on(active_handles
=True)
525 async def test_reset_uninstall_false(self
):
526 self
.helm_conn
._uninstall
_sw
= asynctest
.CoroutineMock()
528 await self
.helm_conn
.reset(self
.cluster_uuid
, force
=False, uninstall_sw
=False)
529 self
.helm_conn
.fs
.sync
.assert_called_once_with(from_path
=self
.cluster_id
)
530 self
.helm_conn
.fs
.file_delete
.assert_called_once_with(
531 self
.cluster_id
, ignore_non_exist
=True
533 self
.helm_conn
._uninstall
_sw
.assert_not_called()
535 @asynctest.fail_on(active_handles
=True)
536 async def test_reset_uninstall(self
):
537 kdu_instance
= "stable-openldap-0021099429"
540 "app_version": "2.4.48",
541 "chart": "openldap-1.2.3",
542 "name": kdu_instance
,
543 "namespace": self
.namespace
,
545 "status": "deployed",
546 "updated": "2020-10-30 11:11:20.376744191 +0000 UTC",
549 self
.helm_conn
._uninstall
_sw
= asynctest
.CoroutineMock()
550 self
.helm_conn
.instances_list
= asynctest
.CoroutineMock(return_value
=instances
)
551 self
.helm_conn
.uninstall
= asynctest
.CoroutineMock()
553 await self
.helm_conn
.reset(self
.cluster_uuid
, force
=True, uninstall_sw
=True)
554 self
.helm_conn
.fs
.sync
.assert_called_once_with(from_path
=self
.cluster_id
)
555 self
.helm_conn
.fs
.file_delete
.assert_called_once_with(
556 self
.cluster_id
, ignore_non_exist
=True
558 self
.helm_conn
.instances_list
.assert_called_once_with(
559 cluster_uuid
=self
.cluster_uuid
561 self
.helm_conn
.uninstall
.assert_called_once_with(
562 cluster_uuid
=self
.cluster_uuid
, kdu_instance
=kdu_instance
564 self
.helm_conn
._uninstall
_sw
.assert_called_once_with(
565 self
.cluster_id
, self
.namespace
568 @asynctest.fail_on(active_handles
=True)
569 async def test_sync_repos_add(self
):
573 "url": "https://kubernetes-charts.storage.googleapis.com/",
576 self
.helm_conn
.repo_list
= asynctest
.CoroutineMock(return_value
=repo_list
)
578 def get_one_result(*args
, **kwargs
):
579 if args
[0] == "k8sclusters":
582 "helm_chart_repos": ["4b5550a9-990d-4d95-8a48-1f4614d6ac9c"]
585 elif args
[0] == "k8srepos":
587 "_id": "4b5550a9-990d-4d95-8a48-1f4614d6ac9c",
588 "type": "helm-chart",
590 "url": "https://charts.bitnami.com/bitnami",
593 self
.helm_conn
.db
.get_one
= asynctest
.Mock()
594 self
.helm_conn
.db
.get_one
.side_effect
= get_one_result
596 self
.helm_conn
.repo_add
= asynctest
.CoroutineMock()
597 self
.helm_conn
.repo_remove
= asynctest
.CoroutineMock()
599 deleted_repo_list
, added_repo_dict
= await self
.helm_conn
.synchronize_repos(
602 self
.helm_conn
.repo_remove
.assert_not_called()
603 self
.helm_conn
.repo_add
.assert_called_once_with(
604 self
.cluster_uuid
, "bitnami", "https://charts.bitnami.com/bitnami"
606 self
.assertEqual(deleted_repo_list
, [], "Deleted repo list should be empty")
609 {"4b5550a9-990d-4d95-8a48-1f4614d6ac9c": "bitnami"},
610 "Repos added should include only one bitnami",
613 @asynctest.fail_on(active_handles
=True)
614 async def test_sync_repos_delete(self
):
618 "url": "https://kubernetes-charts.storage.googleapis.com/",
620 {"name": "bitnami", "url": "https://charts.bitnami.com/bitnami"},
622 self
.helm_conn
.repo_list
= asynctest
.CoroutineMock(return_value
=repo_list
)
624 def get_one_result(*args
, **kwargs
):
625 if args
[0] == "k8sclusters":
626 return {"_admin": {"helm_chart_repos": []}}
628 self
.helm_conn
.db
.get_one
= asynctest
.Mock()
629 self
.helm_conn
.db
.get_one
.side_effect
= get_one_result
631 self
.helm_conn
.repo_add
= asynctest
.CoroutineMock()
632 self
.helm_conn
.repo_remove
= asynctest
.CoroutineMock()
634 deleted_repo_list
, added_repo_dict
= await self
.helm_conn
.synchronize_repos(
637 self
.helm_conn
.repo_add
.assert_not_called()
638 self
.helm_conn
.repo_remove
.assert_called_once_with(self
.cluster_uuid
, "bitnami")
640 deleted_repo_list
, ["bitnami"], "Deleted repo list should be bitnami"
642 self
.assertEqual(added_repo_dict
, {}, "No repos should be added")