summaryrefslogtreecommitdiffstats
path: root/bitbake
diff options
context:
space:
mode:
authorMichael Wood <michael.g.wood@intel.com>2016-04-06 17:46:35 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-04-06 23:10:29 +0100
commit9dcb9cb2ccf52fa846ce1462e01f045253959328 (patch)
treed8662a7bbd25f8b9dc7e8e14d54f479b838a0d27 /bitbake
parentdfa85109d6022dce47983ef8e887448b4e3dc48f (diff)
downloadpoky-9dcb9cb2ccf52fa846ce1462e01f045253959328.tar.gz
bitbake: toaster: bldcontrol models Add a cancelling state the BuildRequest
To accurately reflect the state of a build request we also need a cancelling state. This is set when we've started a build and then for whatever reason cancel it, cancelling is not instantaneous so we have this state to indicate that a cancel is in progress. Also add a state transition guard. As the state of a BuildRequest can currently be modified by three processes; Toastergui, Runbuilds/bldcontrol and the buildinofhelper we cannot say for sure which process will be running at the time of cancellation so in order to avoid one of these processes making an incorrect transition only allow transitions of state to increase. e.g. CREATED -> QUEUED -> INPROGRESS And to ignore such requested changes such as INPROGRESS -> CREATED (Bitbake rev: 449598c8e6be75bd0c9d59e7bdf859d1d6f83858) Signed-off-by: Michael Wood <michael.g.wood@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake')
-rw-r--r--bitbake/lib/toaster/bldcontrol/migrations/0003_add_cancelling_state.py19
-rw-r--r--bitbake/lib/toaster/bldcontrol/models.py27
2 files changed, 45 insertions, 1 deletions
diff --git a/bitbake/lib/toaster/bldcontrol/migrations/0003_add_cancelling_state.py b/bitbake/lib/toaster/bldcontrol/migrations/0003_add_cancelling_state.py
new file mode 100644
index 0000000000..eec9216ca3
--- /dev/null
+++ b/bitbake/lib/toaster/bldcontrol/migrations/0003_add_cancelling_state.py
@@ -0,0 +1,19 @@
1# -*- coding: utf-8 -*-
2from __future__ import unicode_literals
3
4from django.db import migrations, models
5
6
7class Migration(migrations.Migration):
8
9 dependencies = [
10 ('bldcontrol', '0002_auto_20160120_1250'),
11 ]
12
13 operations = [
14 migrations.AlterField(
15 model_name='buildrequest',
16 name='state',
17 field=models.IntegerField(default=0, choices=[(0, b'created'), (1, b'queued'), (2, b'in progress'), (3, b'completed'), (4, b'failed'), (5, b'deleted'), (6, b'cancelling'), (7, b'archive')]),
18 ),
19 ]
diff --git a/bitbake/lib/toaster/bldcontrol/models.py b/bitbake/lib/toaster/bldcontrol/models.py
index 9b2d0d0b24..cb49a58c45 100644
--- a/bitbake/lib/toaster/bldcontrol/models.py
+++ b/bitbake/lib/toaster/bldcontrol/models.py
@@ -4,6 +4,8 @@ from django.core.validators import MaxValueValidator, MinValueValidator
4from django.utils.encoding import force_bytes 4from django.utils.encoding import force_bytes
5from orm.models import Project, ProjectLayer, ProjectVariable, ProjectTarget, Build, Layer_Version 5from orm.models import Project, ProjectLayer, ProjectVariable, ProjectTarget, Build, Layer_Version
6 6
7import logging
8logger = logging.getLogger("toaster")
7# a BuildEnvironment is the equivalent of the "build/" directory on the localhost 9# a BuildEnvironment is the equivalent of the "build/" directory on the localhost
8class BuildEnvironment(models.Model): 10class BuildEnvironment(models.Model):
9 SERVER_STOPPED = 0 11 SERVER_STOPPED = 0
@@ -64,7 +66,8 @@ class BuildRequest(models.Model):
64 REQ_COMPLETED = 3 66 REQ_COMPLETED = 3
65 REQ_FAILED = 4 67 REQ_FAILED = 4
66 REQ_DELETED = 5 68 REQ_DELETED = 5
67 REQ_ARCHIVE = 6 69 REQ_CANCELLING = 6
70 REQ_ARCHIVE = 7
68 71
69 REQUEST_STATE = ( 72 REQUEST_STATE = (
70 (REQ_CREATED, "created"), 73 (REQ_CREATED, "created"),
@@ -73,6 +76,7 @@ class BuildRequest(models.Model):
73 (REQ_COMPLETED, "completed"), 76 (REQ_COMPLETED, "completed"),
74 (REQ_FAILED, "failed"), 77 (REQ_FAILED, "failed"),
75 (REQ_DELETED, "deleted"), 78 (REQ_DELETED, "deleted"),
79 (REQ_CANCELLING, "cancelling"),
76 (REQ_ARCHIVE, "archive"), 80 (REQ_ARCHIVE, "archive"),
77 ) 81 )
78 82
@@ -85,6 +89,27 @@ class BuildRequest(models.Model):
85 created = models.DateTimeField(auto_now_add = True) 89 created = models.DateTimeField(auto_now_add = True)
86 updated = models.DateTimeField(auto_now = True) 90 updated = models.DateTimeField(auto_now = True)
87 91
92 def __init__(self, *args, **kwargs):
93 super(BuildRequest, self).__init__(*args, **kwargs)
94 # Save the old state incase it's about to be modified
95 self.old_state = self.state
96
97 def save(self, *args, **kwargs):
98 # Check that the state we're trying to set is not going backwards
99 # e.g. from REQ_FAILED to REQ_INPROGRESS
100 if self.old_state != self.state and self.old_state > self.state:
101 logger.warn("Invalid state change requested: "
102 "Cannot go from %s to %s - ignoring request" %
103 (BuildRequest.REQUEST_STATE[self.old_state][1],
104 BuildRequest.REQUEST_STATE[self.state][1])
105 )
106 # Set property back to the old value
107 self.state = self.old_state
108 return
109
110 super(BuildRequest, self).save(*args, **kwargs)
111
112
88 def get_duration(self): 113 def get_duration(self):
89 return (self.updated - self.created).total_seconds() 114 return (self.updated - self.created).total_seconds()
90 115