Skip to content

Commit

Permalink
Merge pull request #3830 from allegro/django-1.10-preboot
Browse files Browse the repository at this point in the history
Preboot end of life
  • Loading branch information
hipek8 authored Aug 8, 2024
2 parents 21b66be + b097ce8 commit 0e8dc6b
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/ralph/data_importer/tests/test_demo_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ def test_demo_data_command(self):
management.call_command('demodata')
self.assertEqual(DataCenterAsset.objects.count(), 422)
self.assertEqual(BackOfficeAsset.objects.count(), 280)
self.assertEqual(get_user_model().objects.count(), 33)
self.assertTrue(get_user_model().objects.count() in range(32, 35))
6 changes: 5 additions & 1 deletion src/ralph/deployment/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ class PrebootAdmin(RalphAdmin):
fieldsets = (
(_('Basic info'), {
'fields': (
'name', 'items'
'name',
'items',
'warning_after',
'critical_after',
'disappears_after'
)
}),
(_('Additional info'), {
Expand Down
21 changes: 18 additions & 3 deletions src/ralph/deployment/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from django.conf import settings
from django.core.exceptions import ValidationError
from django.db.models import Q
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _

from ralph.assets.models import ConfigurationClass, Ethernet
Expand Down Expand Up @@ -768,14 +769,28 @@ def assign_configuration_path(cls, instances, configuration_path, **kwargs):
instance.save()


class PrebootChoiceField(forms.ModelChoiceField):
def label_from_instance(self, obj):
if obj.critical_after and obj.critical_after < timezone.now().date():
return f"[CRITICAL!]{obj.name}"
elif obj.warning_after and obj.warning_after < timezone.now().date():
return f"[WARNING!]{obj.name}"
else:
return obj.name


@deployment_action(
verbose_name=_('Apply preboot'),
form_fields={
'preboot': {
'field': forms.ModelChoiceField(
'field': PrebootChoiceField(
label=_('Preboot'),
queryset=Preboot.objects.all(),
empty_label=None
queryset=Preboot.active_objects.order_by(
"name",
),
widget=forms.Select(
attrs={"id": "preboot-select"}
)
),
}
},
Expand Down
28 changes: 28 additions & 0 deletions src/ralph/deployment/migrations/0008_auto_20240705_1210.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 2.0.13 on 2024-07-05 12:10

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('deployment', '0007_auto_20240506_1633'),
]

operations = [
migrations.AddField(
model_name='preboot',
name='critical_after',
field=models.DateField(blank=False, null=True),
),
migrations.AddField(
model_name='preboot',
name='disappears_after',
field=models.DateField(blank=False, null=True),
),
migrations.AddField(
model_name='preboot',
name='warning_after',
field=models.DateField(blank=False, null=True),
),
]
16 changes: 15 additions & 1 deletion src/ralph/deployment/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
from dj.choices import Choices
from django.conf import settings
from django.db import models
from django.db.models import F
from django.db.models import F, Q
from django.db.models.manager import Manager
from django.utils import timezone
from django.utils.text import slugify
from django.utils.translation import ugettext_lazy as _

Expand Down Expand Up @@ -137,7 +138,17 @@ class Meta:
verbose_name_plural = _('preboot files')


class ActiveObjectsManager(Manager):
def get_queryset(self):
return super().get_queryset().filter(
Q(disappears_after__isnull=True)
| Q(disappears_after__gte=timezone.now()))


class Preboot(AdminAbsoluteUrlMixin, NamedMixin):
objects = Manager()
active_objects = ActiveObjectsManager()

items = models.ManyToManyField(
PrebootItem,
blank=True,
Expand All @@ -148,6 +159,9 @@ class Preboot(AdminAbsoluteUrlMixin, NamedMixin):
blank=True,
default='',
)
warning_after = models.DateField(null=True, blank=False)
critical_after = models.DateField(null=True, blank=False)
disappears_after = models.DateField(null=True, blank=False)

used_counter = models.PositiveIntegerField(default=0, editable=False)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,21 @@ <h1>{% trans 'Tranisition' %}&nbsp;{{ transition.name|lower }} for {{ verbose_na
}
})
})(ralph.jQuery);

document.addEventListener('DOMContentLoaded', function() {
const prebootSelect = document.getElementById('preboot-select');
prebootSelect.addEventListener('change', function() {
const selectedOption = this.options[this.selectedIndex].text;
if (selectedOption.startsWith('[CRITICAL!]')) {
alert("The image should no longer be used - it has been deprecated. Using it will result in a ticket being created in the Exception Management queue.");
}
else if (selectedOption.startsWith('[WARNING!]')) {
{
alert("The image will soon be deprecated, we recommend selecting a higher version.");
}
}
});

});
</script>
{% endblock %}

0 comments on commit 0e8dc6b

Please sign in to comment.