Code review comment for lp:~codehelp/lava-scheduler/submitting-offline

Revision history for this message
Neil Williams (codehelp) wrote :

With the ~ negation, the device_types hash always returns 1, not the number of boards with a state other than the one specified.
On playground:
arndale 2 idle, 0 offline, 0 busy
kvm 0 idle, 2 offline, 0 busy
Submitting a MultiNode job for 2 KVMs gave:
Required number of device(s) 2 ([(u'arndale', 1), (u'kvm', 1)]) unavailable.
where the exception was changed to output:
"Required number of device(s) %d (%s) unavailable." % (count, device_types))

The alternative code (which adds OFFLINE to the original filter) is more messy and would need more ongoing maintenance when new states are added, but simple negation doesn't give us the results we expected.

    device_types = DeviceType.objects.values_list('name').filter(
        models.Q(device__status=Device.IDLE) |
        models.Q(device__status=Device.RUNNING) |
        models.Q(device__status=Device.RESERVED) |
        models.Q(device__status=Device.OFFLINE)
        ).annotate(
            num_count=models.Count('name')
        ).order_by('name')

With that change and deliberately testing with a MultiNode job which asks for 3 devices instead of 2:
Required number of device(s) 3 ([(u'arndale', 2), (u'kvm', 2)]) unavailable.

The state of the boards themselves did not change between these tests.

The original MultiNode job asking for 2 KVMs was submitted correctly on playground with the more expansive change.

I'll update the branch and this MP.

« Back to merge proposal