Merge ~ack/maas:test-results-limits into maas:master

Proposed by Alberto Donato
Status: Merged
Approved by: Andres Rodriguez
Approved revision: b4315528b23313de21c2d4c6e99343bb94068513
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~ack/maas:test-results-limits
Merge into: maas:master
Diff against target: 477 lines (+231/-108)
4 files modified
src/maasserver/forms/settings.py (+1/-1)
src/maasserver/models/config.py (+1/-1)
src/metadataserver/models/scriptset.py (+24/-23)
src/metadataserver/models/tests/test_scriptset.py (+205/-83)
Reviewer Review Type Date Requested Status
Lee Trager (community) Approve
MAAS Lander Needs Fixing
Blake Rouse (community) Approve
Review via email: mp+333202@code.launchpad.net

Commit message

LP: #1722665 - apply limits to ScriptResults (per script), not ScriptSets

To post a comment you must log in.
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b test-results-limits lp:~ack/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci-jenkins.internal:8080/job/maas/job/branch-tester/626/console
COMMIT: b738cd0a82d541a9a9cace7d93430963077d9685

review: Needs Fixing
Revision history for this message
Blake Rouse (blake-rouse) :
review: Needs Fixing
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b test-results-limits lp:~ack/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci-jenkins.internal:8080/job/maas/job/branch-tester/627/console
COMMIT: 490405b946f610ca0d1aabd56b06e9ac2470b233

review: Needs Fixing
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b test-results-limits lp:~ack/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci-jenkins.internal:8080/job/maas/job/branch-tester/628/console
COMMIT: ed2ce6761e75475bd91eb308a17be4fc1c05c56e

review: Needs Fixing
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b test-results-limits lp:~ack/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: e41e34772f152ba4c98c7b59a839c99ad505b2e3

review: Approve
Revision history for this message
Blake Rouse (blake-rouse) wrote :

I think you can do it removing an unneeded query.

review: Needs Fixing
Revision history for this message
Lee Trager (ltrager) wrote :

This branch doesn't account for Physical block devices. As I describe below this means systems with more then 10 disks will be broken.

While we've agreed to keep storage limits for now I think we should give the user an option to store unlimited results. I would say if max_node_commissioning_results, max_node_testing_results, or max_node_installation_results are set to 0 keep unlimited results.

review: Needs Fixing
Revision history for this message
Lee Trager (ltrager) wrote :

I forgot that we already have code written to property list a scripts full history, accounting for storage devices. You should be able to do something like this

for script_result in new_script_set:
    if len(script_result.history) > limit:
        script_result.history[limit:].delete()

review: Needs Fixing
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b test-results-limits lp:~ack/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci-jenkins.internal:8080/job/maas/job/branch-tester/639/console
COMMIT: a9e4c84da57f22b7030db252baaf84e1b05900c3

review: Needs Fixing
Revision history for this message
Alberto Donato (ack) wrote :

@Lee updated code to use ScriptResult.history and added a test with block devices

Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b test-results-limits lp:~ack/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci-jenkins.internal:8080/job/maas/job/branch-tester/652/console
COMMIT: 217ca2dcea0716b392068d62c26e497c41411904

review: Needs Fixing
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b test-results-limits lp:~ack/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci-jenkins.internal:8080/job/maas/job/branch-tester/653/console
COMMIT: fa8dbb5bbd2b2ce553b74c049f34cc6fda5e811f

review: Needs Fixing
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b test-results-limits lp:~ack/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci-jenkins.internal:8080/job/maas/job/branch-tester/654/console
COMMIT: a0f101176e116234a245c9a677dab17e1e45d2f4

review: Needs Fixing
Revision history for this message
Blake Rouse (blake-rouse) wrote :

Looks good. I think @ltrager should also take another look before this lands.

review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b test-results-limits lp:~ack/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci-jenkins.internal:8080/job/maas/job/branch-tester/656/console
COMMIT: b4315528b23313de21c2d4c6e99343bb94068513

review: Needs Fixing
Revision history for this message
Lee Trager (ltrager) wrote :

LGTM!

review: Approve

There was an error fetching revisions from git servers. Please try again in a few minutes. If the problem persists, contact Launchpad support.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/maasserver/forms/settings.py b/src/maasserver/forms/settings.py
2index 6673000..e659d0b 100644
3--- a/src/maasserver/forms/settings.py
4+++ b/src/maasserver/forms/settings.py
5@@ -516,7 +516,7 @@ CONFIG_ITEMS = {
6 },
7 },
8 'max_node_installation_results': {
9- 'default': 1,
10+ 'default': 3,
11 'form': forms.IntegerField,
12 'form_kwargs': {
13 'required': False,
14diff --git a/src/maasserver/models/config.py b/src/maasserver/models/config.py
15index c0a7c28..756b17b 100644
16--- a/src/maasserver/models/config.py
17+++ b/src/maasserver/models/config.py
18@@ -100,7 +100,7 @@ def get_default_config():
19 'completed_intro': False,
20 'max_node_commissioning_results': 10,
21 'max_node_testing_results': 10,
22- 'max_node_installation_results': 1,
23+ 'max_node_installation_results': 3,
24 # Notifications.
25 'subnet_ip_exhaustion_threshold_count': 16,
26 'http_boot': True,
27diff --git a/src/metadataserver/models/scriptset.py b/src/metadataserver/models/scriptset.py
28index 493165f..4987e83 100644
29--- a/src/metadataserver/models/scriptset.py
30+++ b/src/metadataserver/models/scriptset.py
31@@ -15,6 +15,7 @@ from django.core.exceptions import (
32 from django.db.models import (
33 CASCADE,
34 CharField,
35+ Count,
36 DateTimeField,
37 ForeignKey,
38 IntegerField,
39@@ -104,28 +105,6 @@ def translate_result_type(result_type):
40
41 class ScriptSetManager(Manager):
42
43- def _clean_old(self, node, result_type, new_script_set):
44- # Gather the list of existing script results of the given type for this
45- # node.
46- script_sets = self.filter(node=node, result_type=result_type)
47- # Exclude the newly created script_set so we don't try to remove it.
48- # This can happen when multiple script_sets have last_ping = None.
49- script_sets = script_sets.exclude(id=new_script_set.id)
50- # Sort by last_ping in reverse order so we only remove older entrees.
51- script_sets = script_sets.order_by('last_ping').reverse()
52- config_var = {
53- RESULT_TYPE.COMMISSIONING: 'max_node_commissioning_results',
54- RESULT_TYPE.TESTING: 'max_node_testing_results',
55- RESULT_TYPE.INSTALLATION: 'max_node_installation_results',
56- }
57- script_set_limit = Config.objects.get_config(config_var[result_type])
58- # Remove one from the script_set_limit to account for the newly created
59- # script_set.
60- script_set_limit -= 1
61- if script_sets.count() > script_set_limit:
62- for script_set in script_sets[script_set_limit:]:
63- script_set.delete(force=True)
64-
65 def create_commissioning_script_set(self, node, scripts=[], input={}):
66 """Create a new commissioning ScriptSet with ScriptResults
67
68@@ -140,7 +119,6 @@ class ScriptSetManager(Manager):
69 script_set = self.create(
70 node=node, result_type=RESULT_TYPE.COMMISSIONING,
71 power_state_before_transition=node.power_state)
72- self._clean_old(node, RESULT_TYPE.COMMISSIONING, script_set)
73
74 for script_name, data in NODE_INFO_SCRIPTS.items():
75 if node.is_controller and not data['run_on_controller']:
76@@ -149,6 +127,8 @@ class ScriptSetManager(Manager):
77 script_set=script_set, status=SCRIPT_STATUS.PENDING,
78 script_name=script_name)
79
80+ self._clean_old(node, RESULT_TYPE.COMMISSIONING, script_set)
81+
82 # MAAS doesn't run custom commissioning scripts during controller
83 # refresh.
84 if node.is_controller:
85@@ -242,6 +222,27 @@ class ScriptSetManager(Manager):
86 self._clean_old(node, RESULT_TYPE.INSTALLATION, script_set)
87 return script_set
88
89+ def _clean_old(self, node, result_type, new_script_set):
90+ config_var = {
91+ RESULT_TYPE.COMMISSIONING: 'max_node_commissioning_results',
92+ RESULT_TYPE.TESTING: 'max_node_testing_results',
93+ RESULT_TYPE.INSTALLATION: 'max_node_installation_results',
94+ }
95+ limit = Config.objects.get_config(config_var[result_type])
96+
97+ for script_result in new_script_set.scriptresult_set.all():
98+ first_to_delete = script_result.history.order_by(
99+ '-id')[limit:limit + 1].first()
100+ if first_to_delete is not None:
101+ script_result.history.filter(
102+ pk__lte=first_to_delete.pk).delete()
103+
104+ # delete empty ScriptSets
105+ empty_scriptsets = ScriptSet.objects.annotate(
106+ results_count=Count('scriptresult')).filter(
107+ node=node, results_count=0)
108+ empty_scriptsets.delete()
109+
110
111 class ScriptSet(CleanSave, Model):
112
113diff --git a/src/metadataserver/models/tests/test_scriptset.py b/src/metadataserver/models/tests/test_scriptset.py
114index 80b3918..fff2430 100644
115--- a/src/metadataserver/models/tests/test_scriptset.py
116+++ b/src/metadataserver/models/tests/test_scriptset.py
117@@ -28,6 +28,7 @@ from metadataserver.enum import (
118 SCRIPT_TYPE,
119 )
120 from metadataserver.models import (
121+ ScriptResult,
122 ScriptSet,
123 scriptset as scriptset_module,
124 )
125@@ -110,28 +111,6 @@ class TestTranslateResultType(MAASServerTestCase):
126 class TestScriptSetManager(MAASServerTestCase):
127 """Test the ScriptSet manager."""
128
129- def test_clean_old_ignores_new_script_set(self):
130- # Make sure the created script_set isn't cleaned up. This can happen
131- # when multiple script_sets last_ping are set to None.
132- script_set_limit = Config.objects.get_config(
133- 'max_node_installation_results')
134- node = factory.make_Node()
135- for _ in range(script_set_limit * 2):
136- ScriptSet.objects.create(
137- node=node, result_type=RESULT_TYPE.INSTALLATION,
138- last_ping=None)
139-
140- script_set = ScriptSet.objects.create_installation_script_set(node)
141- # If the new script_set was cleaned up this will fail.
142- node.current_installation_script_set = script_set
143- node.save()
144-
145- self.assertEquals(
146- script_set_limit,
147- ScriptSet.objects.filter(
148- node=node,
149- result_type=RESULT_TYPE.INSTALLATION).count())
150-
151 def test_create_commissioning_script_set(self):
152 custom_scripts = [
153 factory.make_Script(script_type=SCRIPT_TYPE.COMMISSIONING)
154@@ -220,36 +199,79 @@ class TestScriptSetManager(MAASServerTestCase):
155 node.power_state, script_set.power_state_before_transition)
156
157 def test_create_commissioning_script_set_cleans_up_past_limit(self):
158- script_set_limit = Config.objects.get_config(
159- 'max_node_commissioning_results')
160+ limit = Config.objects.get_config('max_node_commissioning_results')
161 node = factory.make_Node()
162- for _ in range(script_set_limit * 2):
163- factory.make_ScriptSet(
164- node=node, result_type=RESULT_TYPE.COMMISSIONING)
165-
166- ScriptSet.objects.create_commissioning_script_set(node)
167-
168- self.assertEquals(
169- script_set_limit,
170- ScriptSet.objects.filter(
171- node=node,
172- result_type=RESULT_TYPE.COMMISSIONING).count())
173+ for i in range(limit + 2):
174+ ScriptSet.objects.create_commissioning_script_set(node)
175+
176+ for script_name in NODE_INFO_SCRIPTS:
177+ self.assertEqual(
178+ limit,
179+ ScriptResult.objects.filter(script_name=script_name).count())
180+
181+ def test_create_commissioning_script_set_cleans_up_by_node(self):
182+ limit = Config.objects.get_config('max_node_commissioning_results')
183+ node1 = factory.make_Node()
184+ node2 = factory.make_Node()
185+ for i in range(limit + 2):
186+ ScriptSet.objects.create_commissioning_script_set(node1)
187+ ScriptSet.objects.create_commissioning_script_set(node2)
188+
189+ for script_name in NODE_INFO_SCRIPTS:
190+ self.assertEqual(
191+ limit,
192+ ScriptResult.objects.filter(
193+ script_name=script_name,
194+ script_set__in=ScriptSet.objects.filter(
195+ node=node1)).count())
196+ self.assertEqual(
197+ limit,
198+ ScriptResult.objects.filter(
199+ script_name=script_name,
200+ script_set__in=ScriptSet.objects.filter(
201+ node=node2)).count())
202
203 def test_create_commissioning_script_set_cleans_up_current(self):
204 Config.objects.set_config('max_node_commissioning_results', 1)
205 node = factory.make_Node()
206- script_set = factory.make_ScriptSet(
207- node=node, result_type=RESULT_TYPE.COMMISSIONING)
208- node.current_commissioning_script_set = script_set
209+
210+ node.current_commissioning_script_set = (
211+ ScriptSet.objects.create_commissioning_script_set(node))
212 node.save()
213
214 ScriptSet.objects.create_commissioning_script_set(node)
215
216- self.assertEquals(
217- 1,
218+ for script_name in NODE_INFO_SCRIPTS:
219+ self.assertEqual(
220+ 1,
221+ ScriptResult.objects.filter(script_name=script_name).count())
222+
223+ def test_create_commissioning_script_set_cleans_up_empty_sets(self):
224+ Config.objects.set_config('max_node_commissioning_results', 1)
225+ node = factory.make_Node()
226+ ScriptSet.objects.create_commissioning_script_set(node)
227+ script_set = ScriptSet.objects.create_commissioning_script_set(node)
228+
229+ # the first set is removed since it's empty
230+ self.assertCountEqual(
231+ [script_set],
232 ScriptSet.objects.filter(
233- node=node,
234- result_type=RESULT_TYPE.COMMISSIONING).count())
235+ result_type=RESULT_TYPE.COMMISSIONING).all())
236+
237+ def test_create_commissioning_script_set_cleans_up_per_node(self):
238+ Config.objects.set_config('max_node_commissioning_results', 1)
239+ node1 = factory.make_Node()
240+ node2 = factory.make_Node()
241+ ScriptSet.objects.create_commissioning_script_set(node1)
242+ script_set1 = ScriptSet.objects.create_commissioning_script_set(node1)
243+ ScriptSet.objects.create_commissioning_script_set(node2)
244+ script_set2 = ScriptSet.objects.create_commissioning_script_set(node2)
245+
246+ # older sets for each node are removed
247+ self.assertCountEqual(
248+ [script_set1, script_set2],
249+ ScriptSet.objects.filter(
250+ result_type=RESULT_TYPE.COMMISSIONING).all())
251
252 def test_create_commissioning_script_set_accepts_params(self):
253 script = factory.make_Script(
254@@ -337,40 +359,102 @@ class TestScriptSetManager(MAASServerTestCase):
255 ScriptSet.objects.create_testing_script_set, node)
256
257 def test_create_testing_script_set_cleans_up_past_limit(self):
258- script_set_limit = Config.objects.get_config(
259- 'max_node_testing_results')
260+ limit = Config.objects.get_config('max_node_testing_results')
261 node = factory.make_Node()
262- for _ in range(script_set_limit * 2):
263- factory.make_ScriptSet(
264- node=node, result_type=RESULT_TYPE.TESTING)
265-
266 script = factory.make_Script(script_type=SCRIPT_TYPE.TESTING)
267+ for _ in range(limit + 2):
268+ ScriptSet.objects.create_testing_script_set(
269+ node, scripts=[script.name])
270+ self.assertEqual(
271+ limit,
272+ ScriptResult.objects.filter(script_name=script.name).count())
273+
274+ def test_create_testing_script_set_cleans_up_by_node(self):
275+ limit = Config.objects.get_config('max_node_testing_results')
276+ node1 = factory.make_Node()
277+ node2 = factory.make_Node()
278+ script = factory.make_Script(script_type=SCRIPT_TYPE.TESTING)
279+ for _ in range(limit + 2):
280+ ScriptSet.objects.create_testing_script_set(
281+ node1, scripts=[script.name])
282+ ScriptSet.objects.create_testing_script_set(
283+ node2, scripts=[script.name])
284+
285+ self.assertEqual(
286+ limit,
287+ ScriptResult.objects.filter(
288+ script_set__in=ScriptSet.objects.filter(node=node1)).count())
289+ self.assertEqual(
290+ limit,
291+ ScriptResult.objects.filter(
292+ script_set__in=ScriptSet.objects.filter(node=node2)).count())
293+
294+ def test_create_testing_script_set_cleans_up_by_blockdevice(self):
295+ Config.objects.set_config('max_node_testing_results', 1)
296+ node = factory.make_Node()
297+ for _ in range(2):
298+ factory.make_PhysicalBlockDevice(node=node)
299+
300+ script = factory.make_Script(
301+ script_type=SCRIPT_TYPE.TESTING, parameters={
302+ 'storage': {'type': 'storage'}})
303 ScriptSet.objects.create_testing_script_set(
304- node, scripts=[script.name])
305+ node, [script.name], {script.name: {'storage': 'all'}})
306+ ScriptSet.objects.create_testing_script_set(
307+ node, [script.name], {script.name: {'storage': 'all'}})
308
309- self.assertEquals(
310- script_set_limit,
311- ScriptSet.objects.filter(
312- node=node,
313- result_type=RESULT_TYPE.TESTING).count())
314+ # one result is kept for each block device
315+ self.assertEqual(
316+ 3,
317+ ScriptResult.objects.filter(
318+ script_set__in=ScriptSet.objects.filter(node=node)).count())
319
320 def test_create_testing_script_set_cleans_up_current(self):
321 Config.objects.set_config('max_node_testing_results', 1)
322+ script = factory.make_Script(script_type=SCRIPT_TYPE.TESTING)
323 node = factory.make_Node()
324- script_set = factory.make_ScriptSet(
325- node=node, result_type=RESULT_TYPE.TESTING)
326- node.current_testing_script_set = script_set
327+ node.current_testing_script_set = (
328+ ScriptSet.objects.create_testing_script_set(
329+ node, scripts=[script.name]))
330 node.save()
331
332- script = factory.make_Script(script_type=SCRIPT_TYPE.TESTING)
333 ScriptSet.objects.create_testing_script_set(
334 node, scripts=[script.name])
335
336- self.assertEquals(
337+ self.assertEqual(
338 1,
339- ScriptSet.objects.filter(
340- node=node,
341- result_type=RESULT_TYPE.TESTING).count())
342+ ScriptResult.objects.filter(script_name=script.name).count())
343+
344+ def test_create_testing_script_set_cleans_up_empty_sets(self):
345+ Config.objects.set_config('max_node_testing_results', 1)
346+ script = factory.make_Script(script_type=SCRIPT_TYPE.TESTING)
347+ node = factory.make_Node()
348+ ScriptSet.objects.create_testing_script_set(
349+ node, scripts=[script.name])
350+ script_set = ScriptSet.objects.create_testing_script_set(
351+ node, scripts=[script.name])
352+ # the first set is removed since it's empty
353+ self.assertCountEqual(
354+ [script_set],
355+ ScriptSet.objects.filter(result_type=RESULT_TYPE.TESTING).all())
356+
357+ def test_create_testing_script_set_cleans_up_per_node(self):
358+ Config.objects.set_config('max_node_testing_results', 1)
359+ script = factory.make_Script(script_type=SCRIPT_TYPE.TESTING)
360+ node1 = factory.make_Node()
361+ node2 = factory.make_Node()
362+ ScriptSet.objects.create_testing_script_set(
363+ node1, scripts=[script.name])
364+ script_set1 = ScriptSet.objects.create_testing_script_set(
365+ node1, scripts=[script.name])
366+ ScriptSet.objects.create_testing_script_set(
367+ node2, scripts=[script.name])
368+ script_set2 = ScriptSet.objects.create_testing_script_set(
369+ node2, scripts=[script.name])
370+ # older sets are removed for each node
371+ self.assertCountEqual(
372+ [script_set1, script_set2],
373+ ScriptSet.objects.filter(result_type=RESULT_TYPE.TESTING).all())
374
375 def test_create_testing_script_set_accepts_params(self):
376 script = factory.make_Script(
377@@ -410,41 +494,79 @@ class TestScriptSetManager(MAASServerTestCase):
378 self.assertItemsEqual(
379 [CURTIN_INSTALL_LOG],
380 [script_result.name for script_result in script_set])
381- self.assertEquals(RESULT_TYPE.INSTALLATION, script_set.result_type)
382+ self.assertEquals(
383+ RESULT_TYPE.INSTALLATION, script_set.result_type)
384 self.assertEquals(
385 node.power_state, script_set.power_state_before_transition)
386
387 def test_create_installation_script_set_cleans_up_past_limit(self):
388- script_set_limit = Config.objects.get_config(
389- 'max_node_installation_results')
390+ limit = Config.objects.get_config('max_node_installation_results')
391 node = factory.make_Node()
392- for _ in range(script_set_limit * 2):
393- factory.make_ScriptSet(
394- node=node, result_type=RESULT_TYPE.INSTALLATION)
395-
396- ScriptSet.objects.create_installation_script_set(node)
397-
398- self.assertEquals(
399- script_set_limit,
400- ScriptSet.objects.filter(
401- node=node,
402- result_type=RESULT_TYPE.INSTALLATION).count())
403+ for _ in range(limit + 2):
404+ ScriptSet.objects.create_installation_script_set(node)
405+
406+ self.assertEqual(
407+ limit,
408+ ScriptResult.objects.filter(
409+ script_name=CURTIN_INSTALL_LOG).count())
410+
411+ def test_create_installation_script_set_cleans_up_by_node(self):
412+ limit = Config.objects.get_config('max_node_installation_results')
413+ node1 = factory.make_Node()
414+ node2 = factory.make_Node()
415+ for _ in range(limit + 2):
416+ ScriptSet.objects.create_installation_script_set(node1)
417+ ScriptSet.objects.create_installation_script_set(node2)
418+
419+ self.assertEqual(
420+ limit,
421+ ScriptResult.objects.filter(
422+ script_name=CURTIN_INSTALL_LOG,
423+ script_set__in=ScriptSet.objects.filter(node=node1)).count())
424+ self.assertEqual(
425+ limit,
426+ ScriptResult.objects.filter(
427+ script_name=CURTIN_INSTALL_LOG,
428+ script_set__in=ScriptSet.objects.filter(node=node2)).count())
429
430 def test_create_installation_script_set_cleans_up_current(self):
431- Config.objects.get_config('max_node_installation_results', 1)
432+ Config.objects.set_config('max_node_installation_results', 1)
433 node = factory.make_Node()
434- script_set = factory.make_ScriptSet(
435- node=node, result_type=RESULT_TYPE.INSTALLATION)
436- node.current_installation_script_set = script_set
437+ node.current_installation_script_set = (
438+ ScriptSet.objects.create_installation_script_set(node))
439 node.save()
440
441 ScriptSet.objects.create_installation_script_set(node)
442
443- self.assertEquals(
444+ self.assertEqual(
445 1,
446+ ScriptResult.objects.filter(
447+ script_name=CURTIN_INSTALL_LOG).count())
448+
449+ def test_create_installation_script_set_cleans_up_empty_sets(self):
450+ Config.objects.set_config('max_node_installation_results', 1)
451+ node = factory.make_Node()
452+ ScriptSet.objects.create_installation_script_set(node)
453+ script_set = ScriptSet.objects.create_installation_script_set(node)
454+ # the first set is removed since it's empty
455+ self.assertCountEqual(
456+ [script_set],
457+ ScriptSet.objects.filter(
458+ result_type=RESULT_TYPE.INSTALLATION).all())
459+
460+ def test_create_installation_script_set_cleans_up_per_node(self):
461+ Config.objects.set_config('max_node_installation_results', 1)
462+ node1 = factory.make_Node()
463+ node2 = factory.make_Node()
464+ ScriptSet.objects.create_installation_script_set(node1)
465+ script_set1 = ScriptSet.objects.create_installation_script_set(node1)
466+ ScriptSet.objects.create_installation_script_set(node2)
467+ script_set2 = ScriptSet.objects.create_installation_script_set(node2)
468+ # older results are deleted by node
469+ self.assertCountEqual(
470+ [script_set1, script_set2],
471 ScriptSet.objects.filter(
472- node=node,
473- result_type=RESULT_TYPE.INSTALLATION).count())
474+ result_type=RESULT_TYPE.INSTALLATION).all())
475
476
477 class TestScriptSet(MAASServerTestCase):

Subscribers

People subscribed via source and target branches