Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
Add unittests for k8s-keystone-auth config
Browse files Browse the repository at this point in the history
  • Loading branch information
Travis Holton committed Dec 5, 2023
1 parent dbd05b3 commit 84e5623
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 2 deletions.
5 changes: 4 additions & 1 deletion magnum_capi_helm/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
import re

from magnum.api import utils as api_utils
from magnum.common import clients, exception, neutron, short_id
from magnum.common import clients
from magnum.common import exception
from magnum.common import neutron
from magnum.common import short_id
from magnum.drivers.common import driver
from magnum.drivers.common import k8s_monitor
from magnum.objects import fields
Expand Down
73 changes: 72 additions & 1 deletion magnum_capi_helm/tests/test_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from magnum_capi_helm import helm
from magnum_capi_helm import kubernetes


CONF = conf.CONF


Expand Down Expand Up @@ -1733,6 +1732,78 @@ def test_delete_nodegroup(self, mock_update):
mock_update.call_args.args[2][0].as_dict(),
)

@mock.patch.object(neutron, "get_network", autospec=True)
@mock.patch.object(
driver.Driver, "_ensure_certificate_secrets", autospec=True
)
@mock.patch.object(driver.Driver, "_create_appcred_secret", autospec=True)
@mock.patch.object(kubernetes.Client, "load", autospec=True)
@mock.patch.object(driver.Driver, "_get_image_details", autospec=True)
@mock.patch.object(helm.Client, "install_or_upgrade", autospec=True)
def test_k8s_keystone_auth_not_enabled(
self,
mock_install,
mock_image,
mock_load,
mock_appcred,
mock_certs,
mock_get_net,
):
CONF.capi_helm.k8s_keystone_auth_enabled = False
mock_image.return_value = (
"imageid1",
"1.27.4",
"ubuntu",
)
mock_client = mock.MagicMock(spec=kubernetes.Client)
mock_load.return_value = mock_client
mock_get_net.side_effect = (
lambda c, net, source, target, external: f"{net}-{external}"
)
self.driver._update_helm_release(self.context, self.cluster_obj)
mock_install.assert_called()
values = mock_install.call_args.args[3]
# self.assertIn("kubernetesVersion", values)
# print("values: %s" % values["kubernetesVersion"])
self.assertNotIn("authWebhook", values)

@mock.patch.object(neutron, "get_network", autospec=True)
@mock.patch.object(
driver.Driver, "_ensure_certificate_secrets", autospec=True
)
@mock.patch.object(driver.Driver, "_create_appcred_secret", autospec=True)
@mock.patch.object(kubernetes.Client, "load", autospec=True)
@mock.patch.object(driver.Driver, "_get_image_details", autospec=True)
@mock.patch.object(helm.Client, "install_or_upgrade", autospec=True)
def test_k8s_keystone_auth_enabled(
self,
mock_install,
mock_image,
mock_load,
mock_appcred,
mock_certs,
mock_get_net,
):
CONF.capi_helm.k8s_keystone_auth_enabled = True
mock_image.return_value = (
"imageid1",
"1.27.4",
"ubuntu",
)
mock_client = mock.MagicMock(spec=kubernetes.Client)
mock_load.return_value = mock_client
mock_get_net.side_effect = (
lambda c, net, source, target, external: f"{net}-{external}"
)
self.driver._update_helm_release(self.context, self.cluster_obj)
mock_install.assert_called()
values = mock_install.call_args.args[3]
# self.assertIn("kubernetesVersion", values)
# print("values: %s" % values["kubernetesVersion"])
self.assertIn("authWebhook", values)
k8s_keystone_auth_conf = values["openstack"]["k8sKeystoneAuth"]
self.assertEqual(k8s_keystone_auth_conf["enabled"], True)

def test_create_federation(self):
self.assertRaises(
NotImplementedError,
Expand Down

0 comments on commit 84e5623

Please sign in to comment.