scheduler: tests for multiple drivers in TG

This commit is contained in:
Mahmood Ali 2019-08-29 08:41:32 -04:00
parent f5792635ca
commit 3da10b5cb3
3 changed files with 65 additions and 1 deletions

View File

@ -15,6 +15,16 @@ func Node() *structs.Node {
SecretID: uuid.Generate(),
Datacenter: "dc1",
Name: "foobar",
Drivers: map[string]*structs.DriverInfo{
"exec": {
Detected: true,
Healthy: true,
},
"mock_driver": {
Detected: true,
Healthy: true,
},
},
Attributes: map[string]string{
"kernel.name": "linux",
"arch": "x86",

View File

@ -245,6 +245,7 @@ func (c *DriverChecker) hasDrivers(option *structs.Node) bool {
return false
}
}
return true
}

View File

@ -236,7 +236,56 @@ func TestHostVolumeChecker_ReadOnly(t *testing.T) {
}
}
func TestDriverChecker(t *testing.T) {
func TestDriverChecker_DriverInfo(t *testing.T) {
_, ctx := testContext(t)
nodes := []*structs.Node{
mock.Node(),
mock.Node(),
mock.Node(),
}
nodes[0].Drivers["foo"] = &structs.DriverInfo{
Detected: true,
Healthy: true,
}
nodes[1].Drivers["foo"] = &structs.DriverInfo{
Detected: true,
Healthy: false,
}
nodes[2].Drivers["foo"] = &structs.DriverInfo{
Detected: false,
Healthy: false,
}
drivers := map[string]struct{}{
"exec": {},
"foo": {},
}
checker := NewDriverChecker(ctx, drivers)
cases := []struct {
Node *structs.Node
Result bool
}{
{
Node: nodes[0],
Result: true,
},
{
Node: nodes[1],
Result: false,
},
{
Node: nodes[2],
Result: false,
},
}
for i, c := range cases {
if act := checker.Feasible(c.Node); act != c.Result {
t.Fatalf("case(%d) failed: got %v; want %v", i, act, c.Result)
}
}
}
func TestDriverChecker_Compatibility(t *testing.T) {
_, ctx := testContext(t)
nodes := []*structs.Node{
mock.Node(),
@ -244,6 +293,10 @@ func TestDriverChecker(t *testing.T) {
mock.Node(),
mock.Node(),
}
for _, n := range nodes {
// force compatibility mode
n.Drivers = nil
}
nodes[0].Attributes["driver.foo"] = "1"
nodes[1].Attributes["driver.foo"] = "0"
nodes[2].Attributes["driver.foo"] = "true"