Since I could not find any information in documentation anywhere, I ended up looking in the code for Selenium grid, and finally found out what the problem was.
When starting the Appium server, you can specify a set of capabilities of this device. When running a test, you specify a set of desired capabilities. The trick here, is that these need to match for 100%, or the Grid server will still randomly distribute jobs to any random available node.
In this specific case, I have change my node config to:
"capabilities":
[
{
"browserName": "Android",
"version": "7.1.2",
"maxInstances": 1,
"platform": "ANDROID",
"platformName": "ANDROID",
"deviceName": "Android"
}
],
And:
"capabilities":
[
{
"browserName": "Android",
"version": "6.0.1",
"maxInstances": 1,
"platform": "ANDROID",
"platformName": "ANDROID",
"deviceName": "Android"
}
],
And the desired capabilities in the script to:
desired_caps['browserName'] = 'Android'
desired_caps['platformName'] = 'ANDROID'
desired_caps['version'] = '7.1.2'
desired_caps['deviceName'] = 'Android'
desired_caps['platform'] = 'ANDROID'
And:
desired_caps['browserName'] = 'Android'
desired_caps['platformName'] = 'ANDROID'
desired_caps['version'] = '6.0.1'
desired_caps['deviceName'] = 'Android'
desired_caps['platform'] = 'ANDROID'
As you can see, all the capabilities (except on the node side for the maxInstances; and on the script side for things like newCommandTimeout, appPackage, appActivity, and appWaitActivity) need to match 100% exactly. If there is one capability more on either side, the Grid matcher class will no longer match, and will send the test to a random node instead.
With this setup, I now have the ideal situation where I have two nodes with Android 6, two nodes with Android 7, and when I fire off two tests for Android 6, they will always execute on the first two nodes. When a third test is fired off, and this is for Android 7, it will execute immediately on one of the free Android 7 nodes, but when I fire off a third test and this is Android 6, it will be queued until one of the two Android 6 nodes is free again.