aboutsummaryrefslogtreecommitdiffstats
path: root/lib/python2.7/site-packages/autobuilder/buildsteps/DaftGetDevices.py
blob: a6e87e7f9e23fe4a9b05be116990bce444995069 (plain)
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
import os
from buildbot.steps.transfer import FileUpload
from buildbot.process.buildstep import BuildStep

from lib.daft import DeployScanner
from autobuilder.config import DAFT_WORKER_DEVICES_CFG

class DaftGetDevices(FileUpload):
    haltOnFailure = True

    name = "DaftGetDevices"

    def __init__(self, factory, argdict=None, **kwargs):
        self.tests = None
        self.factory = factory
        for k, v in argdict.iteritems():
            setattr(self, k, v)
        self.description = "Getting devices configuration"
        self.timeout = 100000
        kwargs['timeout']=self.timeout

        super(DaftGetDevices, self).__init__(DAFT_WORKER_DEVICES_CFG,
                os.path.join('/tmp', 'devices.cfg'))

    def finished(self, result):
        if self.cmd:
            ds = DeployScanner(devsconf_file = self.masterdest)
            devices = ds.getDevices()

            found = False
            dut_label = self.getProperty('custom_dut')
            for d in devices:
                if d['dut_label'] == dut_label:
                    self.setProperty('dut_name', d['dut_label'], 'DaftGetDevices')
                    self.setProperty('server_ip', d['server_address'], 'DaftGetDevices')
                    target_ip = "%s:%s" % (d['ctrl_address'], d['dut_sshport'])
                    self.setProperty('target_ip', target_ip, 'DaftGetDevices')

                    found = True

            if not found:
                 return BuildStep.finished(self, FAILURE)

        return super(DaftGetDevices, self).finished(result)