1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
The CodeImportScheduler
=======================
The code import scheduler is an XMLRPC service that provides (ids of)
CodeImportJobs for code import slaves to run. It is available as the
codeimportscheduler attribute of our private XMLRPC instance.
>>> from lp.code.interfaces.codeimportscheduler import (
... ICodeImportSchedulerApplication)
>>> from lp.xmlrpc.interfaces import IPrivateApplication
>>> from lp.services.webapp.testing import verifyObject
>>> private_root = getUtility(IPrivateApplication)
>>> verifyObject(
... ICodeImportSchedulerApplication, private_root.codeimportscheduler)
True
The CodeImportSchedulerAPI view provides the ICodeImportScheduler
XML-RPC API:
>>> from lp.services.webapp.servers import LaunchpadTestRequest
>>> from lp.code.interfaces.codeimportscheduler import (
... ICodeImportScheduler)
>>> from lp.code.xmlrpc.codeimportscheduler import (
... CodeImportSchedulerAPI)
>>> codeimportscheduler_api = CodeImportSchedulerAPI(
... private_root.codeimportscheduler, LaunchpadTestRequest())
>>> verifyObject(ICodeImportScheduler, codeimportscheduler_api)
True
The ICodeImportScheduler interface defines a single method,
getJobForMachine(), that returns the id of the job that the code
import slave should next run.
>>> codeimportscheduler_api.getJobForMachine('bazaar-importer', 2)
1
The method just calls the 'getJobForMachine' method from the
ICodeImportJobSet interface, and tests all the details of what it does
can be found in the tests for ICodeImportJobSet.
The point of all this is for it to be accessed over XMLRPC.
>>> import xmlrpclib
>>> from lp.testing.xmlrpc import XMLRPCTestTransport
>>> codeimportscheduler = xmlrpclib.ServerProxy(
... 'http://xmlrpc-private.launchpad.dev:8087/codeimportscheduler',
... transport=XMLRPCTestTransport())
>>> codeimportscheduler.getJobForMachine('bazaar-importer', 2)
0
This includes the behaviour of auto-creating machine rows for
previously unseen hostnames.
>>> from lp.code.interfaces.codeimportmachine import (
... ICodeImportMachineSet)
>>> print getUtility(ICodeImportMachineSet).getByHostname(
... 'doesnt-exist-yet')
None
>>> codeimportscheduler.getJobForMachine('doesnt-exist-yet', 1)
0
>>> new_machine = getUtility(ICodeImportMachineSet).getByHostname(
... 'doesnt-exist-yet')
>>> new_machine.hostname
u'doesnt-exist-yet'
>>> new_machine.state.name
'ONLINE'
|