Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replaced Daphne with uvicorn and enabled multiple workers for perform…
Browse files Browse the repository at this point in the history
…ance optimization (#132)

Fixed broken kioscadmin url
stolpeo committed Jan 28, 2022
1 parent f9e88aa commit 0b93175
Showing 29 changed files with 196 additions and 470 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -5,6 +5,20 @@ Changelog for the **Kiosc** Django app package.
Loosely follows the `Keep a Changelog <http://keepachangelog.com/en/1.0.0/>`_ guidelines.


HEAD (unreleased)
=================

General
-------

- Replaced Daphne with uvicorn and enabled multiple workers for performance optimization (#132)

Kioscadmin
----------

- Fixed broken kioscadmin url (#132)


v0.4.0 (2021-11-08)
===================

4 changes: 2 additions & 2 deletions config/urls.py
Original file line number Diff line number Diff line change
@@ -18,6 +18,8 @@
TemplateView.as_view(template_name="pages/about.html"),
name="about",
),
# Admin URLs - most occur before Django Admin, otherwise urls will be matched by that.
url(r"^kioscadmin/", include("kioscadmin.urls")),
# Django Admin, use {% url 'admin:index' %}
url(settings.ADMIN_URL, admin.site.urls),
# Login and logout
@@ -52,8 +54,6 @@
url(r"^containers/", include("containers.urls")),
# Containertemplates URLs
url(r"^containertemplates/", include("containertemplates.urls")),
# Admin URLs
url(r"^kioscadmin/", include("kioscadmin.urls")),
# Iconify icon URLs
url(r"^icons/", include("dj_iconify.urls")),
# These are the SAML2 related URLs. You can change "^saml2_auth/" regex to
15 changes: 4 additions & 11 deletions containers/models.py
Original file line number Diff line number Diff line change
@@ -207,10 +207,7 @@ class Meta:
)

#: The "tag" of the image.
tag = models.CharField(
max_length=128,
help_text="The tag of the image.",
)
tag = models.CharField(max_length=128, help_text="The tag of the image.",)

#: UUID of the container.
sodar_uuid = models.UUIDField(
@@ -339,15 +336,12 @@ class Meta:

#: Title of the container
title = models.CharField(
max_length=512,
help_text="Title of the container.",
max_length=512, help_text="Title of the container.",
)

#: Description of the container
description = models.TextField(
help_text="Description of the container.",
blank=True,
null=True,
help_text="Description of the container.", blank=True, null=True,
)

#: Number of days the container can run without proxy access
@@ -433,8 +427,7 @@ class ContainerBackgroundJob(JobModelMessageContextManagerMixin, models.Model):

#: Retry count
retries = models.IntegerField(
help_text="Number of retries for the action.",
default=0,
help_text="Number of retries for the action.", default=0,
)

#: The background job that is specialized.
3 changes: 1 addition & 2 deletions containers/plugins.py
Original file line number Diff line number Diff line change
@@ -169,8 +169,7 @@ def get_object_link(self, model_str, uuid):
elif obj.__class__ == Container:
return {
"url": reverse(
"containers:detail",
kwargs={"container": obj.sodar_uuid},
"containers:detail", kwargs={"container": obj.sodar_uuid},
),
"label": obj.get_display_name(),
"blank": True,
26 changes: 7 additions & 19 deletions containers/statemachines.py
Original file line number Diff line number Diff line change
@@ -356,9 +356,7 @@ def on_pull(self):
f"Pulling image {self.container.get_repos_full()} ..."
)
self.container.log_entries.create(
text="Pulling image ...",
process=PROCESS_TASK,
user=self.user,
text="Pulling image ...", process=PROCESS_TASK, user=self.user,
)
self.container.state = STATE_PULLING
self.container.save()
@@ -423,7 +421,7 @@ def on_pull(self):
)

for key, value in environment.items():
if "__KIOSC_URL_PREFIX__" in value:
if isinstance(value, str) and "__KIOSC_URL_PREFIX__" in value:
environment[key] = value.replace(
"__KIOSC_URL_PREFIX__", url_prefix
)
@@ -477,9 +475,7 @@ def on_start_pulled(self):
self._update_status()
self.job.add_log_entry("Starting container succeeded")
self.container.log_entries.create(
text="Starting succeeded",
process=PROCESS_TASK,
user=self.user,
text="Starting succeeded", process=PROCESS_TASK, user=self.user,
)

def on_start_created(self):
@@ -497,9 +493,7 @@ def on_pause(self):
self._update_status()
self.job.add_log_entry("Pausing container succeeded")
self.container.log_entries.create(
text="Pausing succeeded",
process=PROCESS_TASK,
user=self.user,
text="Pausing succeeded", process=PROCESS_TASK, user=self.user,
)

def on_unpause(self):
@@ -511,9 +505,7 @@ def on_unpause(self):
self._update_status()
self.job.add_log_entry("Unpausing container succeeded")
self.container.log_entries.create(
text="Unpausing succeeded",
process=PROCESS_TASK,
user=self.user,
text="Unpausing succeeded", process=PROCESS_TASK, user=self.user,
)

def on_stop_running(self):
@@ -527,9 +519,7 @@ def on_stop_running(self):
self._update_status()

self.container.log_entries.create(
text="Stopping succeeded",
process=PROCESS_TASK,
user=self.user,
text="Stopping succeeded", process=PROCESS_TASK, user=self.user,
)
self.job.add_log_entry("Stopping container succeeded")

@@ -580,8 +570,6 @@ def on_delete_success(self):
self.container.save()

self.container.log_entries.create(
text="Deleting succeeded",
process=PROCESS_TASK,
user=self.user,
text="Deleting succeeded", process=PROCESS_TASK, user=self.user,
)
self.job.add_log_entry("Deleting container succeeded")
4 changes: 1 addition & 3 deletions containers/tasks.py
Original file line number Diff line number Diff line change
@@ -76,9 +76,7 @@ def container_task(_self, job_id):
name=job.container.get_display_name(),
)
tl_event.add_object(
obj=job,
label="action",
name=job.action,
obj=job, label="action", name=job.action,
)

acs = ActionSwitch(cm, job, tl_event)
37 changes: 18 additions & 19 deletions containers/tests/helpers.py
Original file line number Diff line number Diff line change
@@ -74,8 +74,11 @@ def setUp(self):
def log_entry1():
"""First log entry."""
dt = dateutil.parser.parse("2021-01-01 01:01:01.000001+00:00")
return dt, "{} 2021/01/01 10:00:00 [info] Log entry 1".format(
dateformat.format(dt.replace(tzinfo=None), "c") + "000Z"
return (
dt,
"{} 2021/01/01 10:00:00 [info] Log entry 1".format(
dateformat.format(dt.replace(tzinfo=None), "c") + "000Z"
),
)


@@ -87,16 +90,22 @@ def log_entry1_no_date():
def log_entry2():
"""Second log entry, same second but different millisecond."""
dt = dateutil.parser.parse("2021-01-01 01:01:01.500001+00:00")
return dt, "{} 2021/01/01 10:00:00 [info] Log entry 2".format(
dateformat.format(dt.replace(tzinfo=None), "c") + "000Z"
return (
dt,
"{} 2021/01/01 10:00:00 [info] Log entry 2".format(
dateformat.format(dt.replace(tzinfo=None), "c") + "000Z"
),
)


def log_entry3():
"""Third log entry happening the next second"""
dt = dateutil.parser.parse("2021-01-01 01:01:02.000001+00:00")
return dt, "{} 2021/01/01 10:00:01 [info] Log entry 3".format(
dateformat.format(dt.replace(tzinfo=None), "c") + "000Z"
return (
dt,
"{} 2021/01/01 10:00:01 [info] Log entry 3".format(
dateformat.format(dt.replace(tzinfo=None), "c") + "000Z"
),
)


@@ -126,11 +135,7 @@ class DockerMock:
logs_no_date = log_entry1_no_date().encode("utf-8")
logs_since = "\n".join([log_entry2()[1], log_entry3()[1]]).encode("utf-8")

networks = [
{
"Id": "abcdef",
}
]
networks = [{"Id": "abcdef"}]
inspect_network = {
"Name": "network1",
"Id": "abcdef",
@@ -139,10 +144,7 @@ class DockerMock:
"Config": [{"Subnet": "172.17.0.0/16", "Gateway": "172.17.0.1"}]
},
"Containers": {
"9": {
"Name": "container1",
"IPv4Address": "172.17.0.5/16",
},
"9": {"Name": "container1", "IPv4Address": "172.17.0.5/16"},
},
}
images = [
@@ -153,10 +155,7 @@ class DockerMock:
]
volumes = {
"Volumes": [
{
"Mountpoint": "/var/lib/docker/volumes/volume1",
"Name": "abcdef",
}
{"Mountpoint": "/var/lib/docker/volumes/volume1", "Name": "abcdef"}
]
}
containers = [
18 changes: 4 additions & 14 deletions containers/tests/test_forms.py
Original file line number Diff line number Diff line change
@@ -144,28 +144,18 @@ def test_environment_secret_keys_mismatching(self):

@override_settings(KIOSC_NETWORK_MODE="host")
def test_environment_no_json(self):
self.form_data_all.update(
{
"environment": "abc",
}
)
self.form_data_all.update({"environment": "abc"})
form = ContainerForm(self.form_data_all)
self.assertEqual(
form.errors["environment"],
["Enter a valid JSON."],
form.errors["environment"], ["Enter a valid JSON."],
)

@override_settings(KIOSC_NETWORK_MODE="host")
def test_environment_no_dict(self):
self.form_data_all.update(
{
"environment": '["some", "list"]',
}
)
self.form_data_all.update({"environment": '["some", "list"]'})
form = ContainerForm(self.form_data_all)
self.assertEqual(
form.errors["environment"],
["Environment must be a dictionary!"],
form.errors["environment"], ["Environment must be a dictionary!"],
)

@override_settings(KIOSC_NETWORK_MODE="host")
16 changes: 4 additions & 12 deletions containers/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -172,36 +172,28 @@ def test_initialization_with_containertemplatesite_and_containertemplateproject(
def test___str__(self):
self.assertEqual(
str(self.container1),
"{} [{}]".format(
self.container1.title,
self.container1.state,
),
"{} [{}]".format(self.container1.title, self.container1.state,),
)

def test___repr__(self):
self.assertEqual(
repr(self.container1),
"Container({}, {})".format(
self.container1.title,
self.container1.state,
self.container1.title, self.container1.state,
),
)

def test_get_repos_full(self):
self.assertEqual(
self.container1.get_repos_full(),
"{}:{}".format(
self.container1.repository,
self.container1.tag,
),
"{}:{}".format(self.container1.repository, self.container1.tag,),
)

def test_get_repos_full_no_tag(self):
self.container1.tag = ""
self.container1.save()
self.assertEqual(
self.container1.get_repos_full(),
self.container1.repository,
self.container1.get_repos_full(), self.container1.repository,
)

def test_get_display_name(self):
15 changes: 5 additions & 10 deletions containers/tests/test_permissions.py
Original file line number Diff line number Diff line change
@@ -22,8 +22,7 @@ def setUp(self):
def test_container_list(self):
"""Test permissions for the ``list`` view."""
url = reverse(
"containers:list",
kwargs={"project": self.project.sodar_uuid},
"containers:list", kwargs={"project": self.project.sodar_uuid},
)
good_users = [
self.superuser,
@@ -39,8 +38,7 @@ def test_container_list(self):
def test_container_create(self):
"""Test permissions for the ``create`` view."""
url = reverse(
"containers:create",
kwargs={"project": self.project.sodar_uuid},
"containers:create", kwargs={"project": self.project.sodar_uuid},
)
good_users = [
self.superuser,
@@ -105,8 +103,7 @@ def test_container_delete(self):
def test_container_start(self, mock):
"""Test permissions for the ``start`` view."""
url = reverse(
"containers:start",
kwargs={"container": self.container.sodar_uuid},
"containers:start", kwargs={"container": self.container.sodar_uuid},
)
good_users = [
self.superuser,
@@ -131,8 +128,7 @@ def test_container_start(self, mock):
def test_container_stop(self, mock):
"""Test permissions for the ``stop`` view."""
url = reverse(
"containers:stop",
kwargs={"container": self.container.sodar_uuid},
"containers:stop", kwargs={"container": self.container.sodar_uuid},
)
good_users = [
self.superuser,
@@ -183,8 +179,7 @@ def test_container_restart(self, mock):
def test_container_pause(self, mock):
"""Test permissions for the ``pause`` view."""
url = reverse(
"containers:pause",
kwargs={"container": self.container.sodar_uuid},
"containers:pause", kwargs={"container": self.container.sodar_uuid},
)
good_users = [
self.superuser,
8 changes: 2 additions & 6 deletions containers/tests/test_permissions_api.py
Original file line number Diff line number Diff line change
@@ -25,8 +25,7 @@ def setUp(self):
def test_container_list(self):
"""Test permissions for the ``api-list`` view."""
url = reverse(
"containers:api-list",
kwargs={"project": self.project.sodar_uuid},
"containers:api-list", kwargs={"project": self.project.sodar_uuid},
)
good_users = [
self.superuser,
@@ -154,10 +153,7 @@ def _cleanup():
knox=True,
)
self.assert_response_api(
url,
self.anonymous,
status.HTTP_401_UNAUTHORIZED,
method="DELETE",
url, self.anonymous, status.HTTP_401_UNAUTHORIZED, method="DELETE",
)

@patch("containers.tasks.container_task.apply_async")
Loading

0 comments on commit 0b93175

Please sign in to comment.