-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Admin actions to run user helm charts (#1471)
Adds admin actions that will let us upgrade user helm charts. Initially this is the bootstrap user chart and the reset home directory chart, but could be expanded in future.
- Loading branch information
1 parent
2ab77a0
commit c5ad8fc
Showing
7 changed files
with
126 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Third-party | ||
from celery import shared_task | ||
|
||
# First-party/Local | ||
from controlpanel.api import cluster | ||
from controlpanel.utils import _get_model | ||
|
||
|
||
@shared_task(acks_on_failure_or_timeout=False) | ||
def upgrade_user_helm_chart(username, chart_name): | ||
User = _get_model("User") | ||
try: | ||
user = User.objects.get(username=username) | ||
except User.DoesNotExist: | ||
return | ||
cluster_user = cluster.User(user) | ||
chart = cluster_user.get_helm_chart(chart_name) | ||
cluster_user._run_helm_install_command(chart) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Standard library | ||
from unittest.mock import MagicMock, patch | ||
|
||
# Third-party | ||
import pytest | ||
|
||
# First-party/Local | ||
from controlpanel.api.models import User | ||
from controlpanel.api.tasks.user import upgrade_user_helm_chart | ||
|
||
|
||
@pytest.fixture() | ||
def mock_get_user_model(): | ||
with patch("controlpanel.api.tasks.user._get_model") as mock_get_model: | ||
mock_get_model.return_value = User | ||
yield mock_get_model | ||
|
||
|
||
@patch("controlpanel.api.tasks.user.cluster.User") | ||
def test_upgrade_user_helm_chart_user_does_not_exist(mock_cluster_user, mock_get_user_model): | ||
with patch.object(User.objects, "get") as mock_get: | ||
mock_get.side_effect = User.DoesNotExist | ||
upgrade_user_helm_chart("nonexistent_user", "chart_name") | ||
|
||
mock_get_user_model.assert_called_once_with("User") | ||
mock_cluster_user.assert_not_called() | ||
|
||
|
||
@patch("controlpanel.api.tasks.user.cluster.User") | ||
def test_upgrade_user_helm_chart_success(mock_cluster_user, mock_get_user_model): | ||
cluster_user_instance = MagicMock() | ||
mock_cluster_user.return_value = cluster_user_instance | ||
|
||
chart = MagicMock() | ||
cluster_user_instance.get_helm_chart.return_value = chart | ||
|
||
user_instance = MagicMock() | ||
|
||
with patch.object(User.objects, "get") as mock_get: | ||
mock_get.return_value = user_instance | ||
upgrade_user_helm_chart("existing_user", "chart_name") | ||
|
||
mock_get_user_model.assert_called_once_with("User") | ||
mock_cluster_user.assert_called_once_with(user_instance) | ||
cluster_user_instance.get_helm_chart.assert_called_once_with("chart_name") | ||
cluster_user_instance._run_helm_install_command.assert_called_once_with(chart) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters