summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/toaster/bldcontrol/tests.py
diff options
context:
space:
mode:
authorAlexandru DAMIAN <alexandru.damian@intel.com>2014-06-12 12:57:22 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2014-06-13 11:55:34 +0100
commite16352220572835ff2185cf992518fb4f3b2de0e (patch)
tree34ed801e6883d1ebd8e00d4431785dd5e7255039 /bitbake/lib/toaster/bldcontrol/tests.py
parent87b99274e9c90101ec9d4c49ce0874bcb85f7746 (diff)
downloadpoky-e16352220572835ff2185cf992518fb4f3b2de0e.tar.gz
bitbake: toaster: build control functionality
We add the build control functionality to toaster. * The bldcontrol application gains bbcontroller classes that know how to manage a localhost build environment. * The toaster UI now detects it is running under build environment controller, and update the build controller database and will shut down the bitbake server once the build is complete. * The toaster script can now run in standalone mode, launching the build controller and the web interface instead of just monitoring the build, as in the interactive mode. * A fixture with the default build controller entry for localhost is provided. [YOCTO #5490] [YOCTO #5491] [YOCTO #5492] [YOCTO #5493] [YOCTO #5494] [YOCTO #5537] (Bitbake rev: 10988bd77c8c7cefad3b88744bc5d8a7e3c1f4cf) Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/toaster/bldcontrol/tests.py')
-rw-r--r--bitbake/lib/toaster/bldcontrol/tests.py73
1 files changed, 69 insertions, 4 deletions
diff --git a/bitbake/lib/toaster/bldcontrol/tests.py b/bitbake/lib/toaster/bldcontrol/tests.py
index 501deb776c..ebe477d8a8 100644
--- a/bitbake/lib/toaster/bldcontrol/tests.py
+++ b/bitbake/lib/toaster/bldcontrol/tests.py
@@ -7,10 +7,75 @@ Replace this with more appropriate tests for your application.
7 7
8from django.test import TestCase 8from django.test import TestCase
9 9
10from bldcontrol.bbcontroller import LocalhostBEController, BitbakeController
11from bldcontrol.models import BuildEnvironment, BuildRequest
12from bldcontrol.management.commands.runbuilds import Command
10 13
11class SimpleTest(TestCase): 14import socket
12 def test_basic_addition(self): 15import subprocess
16
17class LocalhostBEControllerTests(TestCase):
18 def test_StartAndStopServer(self):
19 obe = BuildEnvironment.objects.create(lock = BuildEnvironment.LOCK_FREE, betype = BuildEnvironment.TYPE_LOCAL)
20 lbc = LocalhostBEController(obe)
21
22 # test start server and stop
23 self.assertTrue(socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect_ex(('localhost', 8200)), "Port already occupied")
24 lbc.startBBServer()
25 self.assertFalse(socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect_ex(('localhost', 8200)), "Server not answering")
26
27 lbc.stopBBServer()
28 self.assertTrue(socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect_ex(('localhost', 8200)), "Server not stopped")
29
30 # clean up
31 import subprocess
32 out, err = subprocess.Popen("netstat -tapn 2>/dev/null | grep 8200 | awk '{print $7}' | sort -fu | cut -d \"/\" -f 1 | grep -v -- - | tee /dev/fd/2 | xargs -r kill", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
33
34 self.assertTrue(err == '', "bitbake server pid %s not stopped" % err)
35
36 obe = BuildEnvironment.objects.create(lock = BuildEnvironment.LOCK_FREE, betype = BuildEnvironment.TYPE_LOCAL)
37 lbc = LocalhostBEController(obe)
38
39 bbc = lbc.getBBController()
40 self.assertTrue(isinstance(bbc, BitbakeController))
41 # test set variable
42 try:
43 bbc.setVariable
44 except Exception as e :
45 self.fail("setVariable raised %s", e)
46
47 lbc.stopBBServer()
48 out, err = subprocess.Popen("netstat -tapn 2>/dev/null | grep 8200 | awk '{print $7}' | sort -fu | cut -d \"/\" -f 1 | grep -v -- - | tee /dev/fd/2 | xargs -r kill", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
49 self.assertTrue(err == '', "bitbake server pid %s not stopped" % err)
50
51
52class RunBuildsCommandTests(TestCase):
53 def test_bec_select(self):
13 """ 54 """
14 Tests that 1 + 1 always equals 2. 55 Tests that we can find and lock a build environment
15 """ 56 """
16 self.assertEqual(1 + 1, 2) 57
58 obe = BuildEnvironment.objects.create(lock = BuildEnvironment.LOCK_FREE, betype = BuildEnvironment.TYPE_LOCAL)
59 command = Command()
60 bec = command._selectBuildEnvironment()
61
62 # make sure we select the object we've just built
63 self.assertTrue(bec.be.id == obe.id, "Environment is not properly selected")
64 # we have a locked environment
65 self.assertTrue(bec.be.lock == BuildEnvironment.LOCK_LOCK, "Environment is not locked")
66 # no more selections possible here
67 self.assertRaises(IndexError, command._selectBuildEnvironment)
68
69 def test_br_select(self):
70 from orm.models import Project
71 p, created = Project.objects.get_or_create(pk=1)
72 obr = BuildRequest.objects.create(state = BuildRequest.REQ_QUEUED, project = p)
73 command = Command()
74 br = command._selectBuildRequest()
75
76 # make sure we select the object we've just built
77 self.assertTrue(obr.id == br.id, "Request is not properly selected")
78 # we have a locked environment
79 self.assertTrue(br.state == BuildRequest.REQ_INPROGRESS, "Request is not updated")
80 # no more selections possible here
81 self.assertRaises(IndexError, command._selectBuildRequest)