summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/toaster/bldcontrol/tests.py
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/lib/toaster/bldcontrol/tests.py')
-rw-r--r--bitbake/lib/toaster/bldcontrol/tests.py116
1 files changed, 92 insertions, 24 deletions
diff --git a/bitbake/lib/toaster/bldcontrol/tests.py b/bitbake/lib/toaster/bldcontrol/tests.py
index ebe477d8a8..4577c3f03b 100644
--- a/bitbake/lib/toaster/bldcontrol/tests.py
+++ b/bitbake/lib/toaster/bldcontrol/tests.py
@@ -7,46 +7,114 @@ 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 10from bldcontrol.bbcontroller import BitbakeController
11from bldcontrol.localhostbecontroller import LocalhostBEController
12from bldcontrol.sshbecontroller import SSHBEController
11from bldcontrol.models import BuildEnvironment, BuildRequest 13from bldcontrol.models import BuildEnvironment, BuildRequest
12from bldcontrol.management.commands.runbuilds import Command 14from bldcontrol.management.commands.runbuilds import Command
13 15
14import socket 16import socket
15import subprocess 17import subprocess
16 18
17class LocalhostBEControllerTests(TestCase): 19# standard poky data hardcoded for testing
18 def test_StartAndStopServer(self): 20BITBAKE_LAYERS = [type('bitbake_info', (object,), { "giturl": "git://git.yoctoproject.org/poky.git", "dirpath": "", "commit": "HEAD"})]
19 obe = BuildEnvironment.objects.create(lock = BuildEnvironment.LOCK_FREE, betype = BuildEnvironment.TYPE_LOCAL) 21POKY_LAYERS = [
20 lbc = LocalhostBEController(obe) 22 type('poky_info', (object,), { "name": "meta", "giturl": "git://git.yoctoproject.org/poky.git", "dirpath": "meta", "commit": "HEAD"}),
23 type('poky_info', (object,), { "name": "meta-yocto", "giturl": "git://git.yoctoproject.org/poky.git", "dirpath": "meta-yocto", "commit": "HEAD"}),
24 type('poky_info', (object,), { "name": "meta-yocto-bsp", "giturl": "git://git.yoctoproject.org/poky.git", "dirpath": "meta-yocto-bsp", "commit": "HEAD"}),
25 ]
26
21 27
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 28
27 lbc.stopBBServer() 29# we have an abstract test class designed to ensure that the controllers use a single interface
28 self.assertTrue(socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect_ex(('localhost', 8200)), "Server not stopped") 30# specific controller tests only need to override the _getBuildEnvironment() method
29 31
30 # clean up 32class BEControllerTests(object):
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 33
34 def _serverForceStop(self, bc):
35 err = bc._shellcmd("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")
34 self.assertTrue(err == '', "bitbake server pid %s not stopped" % err) 36 self.assertTrue(err == '', "bitbake server pid %s not stopped" % err)
35 37
36 obe = BuildEnvironment.objects.create(lock = BuildEnvironment.LOCK_FREE, betype = BuildEnvironment.TYPE_LOCAL) 38 def test_serverStartAndStop(self):
37 lbc = LocalhostBEController(obe) 39 obe = self._getBuildEnvironment()
40 bc = self._getBEController(obe)
41 bc.setLayers(BITBAKE_LAYERS, POKY_LAYERS) # setting layers, skip any layer info
42
43 hostname = self.test_address.split("@")[-1]
38 44
39 bbc = lbc.getBBController() 45 # test start server and stop
46 self.assertTrue(socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect_ex((hostname, 8200)), "Port already occupied")
47 bc.startBBServer()
48 self.assertFalse(socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect_ex((hostname, 8200)), "Server not answering")
49
50 bc.stopBBServer()
51 self.assertTrue(socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect_ex((hostname, 8200)), "Server not stopped")
52
53 self._serverForceStop(bc)
54
55 def test_getBBController(self):
56 obe = self._getBuildEnvironment()
57 bc = self._getBEController(obe)
58 bc.setLayers(BITBAKE_LAYERS, POKY_LAYERS) # setting layers, skip any layer info
59
60 bbc = bc.getBBController()
40 self.assertTrue(isinstance(bbc, BitbakeController)) 61 self.assertTrue(isinstance(bbc, BitbakeController))
41 # test set variable 62 # test set variable, use no build marker -1 for BR value
42 try: 63 try:
43 bbc.setVariable 64 bbc.setVariable("TOASTER_BRBE", "%d:%d" % (-1, obe.pk))
44 except Exception as e : 65 except Exception as e :
45 self.fail("setVariable raised %s", e) 66 self.fail("setVariable raised %s", e)
46 67
47 lbc.stopBBServer() 68 bc.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() 69
49 self.assertTrue(err == '', "bitbake server pid %s not stopped" % err) 70 self._serverForceStop(bc)
71
72class LocalhostBEControllerTests(TestCase, BEControllerTests):
73 def __init__(self, *args):
74 super(LocalhostBEControllerTests, self).__init__(*args)
75 # hardcoded for Alex's machine; since the localhost BE is machine-dependent,
76 # I found no good way to abstractize this
77 self.test_sourcedir = "/home/ddalex/ssd/yocto"
78 self.test_builddir = "/home/ddalex/ssd/yocto/build"
79 self.test_address = "localhost"
80
81 def _getBuildEnvironment(self):
82 return BuildEnvironment.objects.create(
83 lock = BuildEnvironment.LOCK_FREE,
84 betype = BuildEnvironment.TYPE_LOCAL,
85 address = self.test_address,
86 sourcedir = self.test_sourcedir,
87 builddir = self.test_builddir )
88
89 def _getBEController(self, obe):
90 return LocalhostBEController(obe)
91
92class SSHBEControllerTests(TestCase, BEControllerTests):
93 def __init__(self, *args):
94 super(SSHBEControllerTests, self).__init__(*args)
95 self.test_address = "ddalex-desktop.local"
96 # hardcoded for ddalex-desktop.local machine; since the localhost BE is machine-dependent,
97 # I found no good way to abstractize this
98 self.test_sourcedir = "/home/ddalex/ssd/yocto"
99 self.test_builddir = "/home/ddalex/ssd/yocto/build"
100
101 def _getBuildEnvironment(self):
102 return BuildEnvironment.objects.create(
103 lock = BuildEnvironment.LOCK_FREE,
104 betype = BuildEnvironment.TYPE_SSH,
105 address = self.test_address,
106 sourcedir = self.test_sourcedir,
107 builddir = self.test_builddir )
108
109 def _getBEController(self, obe):
110 return SSHBEController(obe)
111
112 def test_pathExists(self):
113 obe = BuildEnvironment.objects.create(betype = BuildEnvironment.TYPE_SSH, address= self.test_address)
114 sbc = SSHBEController(obe)
115 self.assertTrue(sbc._pathexists("/"))
116 self.assertFalse(sbc._pathexists("/.deadbeef"))
117 self.assertTrue(sbc._pathexists(sbc._shellcmd("pwd")))
50 118
51 119
52class RunBuildsCommandTests(TestCase): 120class RunBuildsCommandTests(TestCase):
@@ -67,8 +135,8 @@ class RunBuildsCommandTests(TestCase):
67 self.assertRaises(IndexError, command._selectBuildEnvironment) 135 self.assertRaises(IndexError, command._selectBuildEnvironment)
68 136
69 def test_br_select(self): 137 def test_br_select(self):
70 from orm.models import Project 138 from orm.models import Project, Release, BitbakeVersion
71 p, created = Project.objects.get_or_create(pk=1) 139 p = Project.objects.create_project("test", Release.objects.get_or_create(name = "HEAD", bitbake_version = BitbakeVersion.objects.get_or_create(name="HEAD", branch="HEAD")[0])[0])
72 obr = BuildRequest.objects.create(state = BuildRequest.REQ_QUEUED, project = p) 140 obr = BuildRequest.objects.create(state = BuildRequest.REQ_QUEUED, project = p)
73 command = Command() 141 command = Command()
74 br = command._selectBuildRequest() 142 br = command._selectBuildRequest()