Skip to content

Commit

Permalink
Merge pull request #6227 from hashicorp/b-drivers-check
Browse files Browse the repository at this point in the history
schedulers: check all drivers on node
  • Loading branch information
Mahmood Ali authored Aug 29, 2019
2 parents d4553b7 + 8a0647c commit 4320d87
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
10 changes: 10 additions & 0 deletions nomad/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 6 additions & 1 deletion scheduler/feasible.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,11 @@ func (c *DriverChecker) hasDrivers(option *structs.Node) bool {
return false
}

return driverInfo.Detected && driverInfo.Healthy
if driverInfo.Detected && driverInfo.Healthy {
continue
} else {
return false
}
}

value, ok := option.Attributes[driverStr]
Expand All @@ -245,6 +249,7 @@ func (c *DriverChecker) hasDrivers(option *structs.Node) bool {
return false
}
}

return true
}

Expand Down
55 changes: 54 additions & 1 deletion scheduler/feasible_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,66 @@ 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(),
mock.Node(),
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"
Expand Down

0 comments on commit 4320d87

Please sign in to comment.