Exemplo n.º 1
0
def _get_metrics_fields(dir_entry):
    """Get metrics fields for the given test result directory, including board
    and milestone.

    @param dir_entry: Directory entry to offload.
    @return A dictionary for the metrics data to be uploaded.
    """
    fields = {'board': 'unknown', 'milestone': 'unknown'}
    if dir_entry:
        # There could be multiple hosts in the job directory, use the first one
        # available.
        for host in glob.glob(os.path.join(dir_entry, '*')):
            try:
                keyval = models.test.parse_job_keyval(host)
            except ValueError:
                continue
            build = keyval.get('build')
            if build:
                try:
                    cros_version = labellib.parse_cros_version(build)
                    fields['board'] = cros_version.board
                    fields['milestone'] = cros_version.milestone
                    break
                except ValueError:
                    # Ignore version parsing error so it won't crash
                    # gs_offloader.
                    pass

    return fields
Exemplo n.º 2
0
    def test_parse_cros_version_for_board(self):
        test_builds = ['lumpy-release/R27-3773.0.0-rc1',
                       'trybot-lumpy-paladin/R27-3773.0.0',
                       'lumpy-pre-cq/R27-3773.0.0-rc1',
                       'lumpy-test-ap/R27-3773.0.0-rc1',
                       'lumpy-toolchain/R27-3773.0.0-rc1',
                       ]
        for build in test_builds:
            cros_version = labellib.parse_cros_version(build)
            self.assertEqual(cros_version.board, 'lumpy')
            self.assertEqual(cros_version.milestone, 'R27')

        build = 'trybot-lumpy-a-pre-cq/R27-3773.0.0-rc1'
        cros_version = labellib.parse_cros_version(build)
        self.assertEqual(cros_version.board, 'lumpy-a')
        self.assertEqual(cros_version.milestone, 'R27')

        build = 'trybot-lumpy_a-pre-cq/R27-3773.0.0-rc1'
        cros_version = labellib.parse_cros_version(build)
        self.assertEqual(cros_version.board, 'lumpy_a')
        self.assertEqual(cros_version.milestone, 'R27')
Exemplo n.º 3
0
 def test_parse_cros_version_raises(self):
     with self.assertRaises(ValueError):
         labellib.parse_cros_version('foo')
Exemplo n.º 4
0
 def test_parse_cros_version_with_rc(self):
     got = labellib.parse_cros_version('lumpy-release/R27-3773.0.0-rc1')
     self.assertEqual(got, labellib.CrosVersion('lumpy-release', 'lumpy',
                                                'R27', '3773.0.0', 'rc1'))