Merge pull request #11951 from hashicorp/b-cgroups-broken-part1-oss

client: change test to not poke cgroupv2 edge case
This commit is contained in:
Seth Hoenig 2022-01-27 10:06:03 -06:00 committed by GitHub
commit 56bf1e4e7b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -57,27 +57,31 @@ func TestCpusetManager_Init(t *testing.T) {
require.DirExists(t, filepath.Join(manager.cgroupParentPath, ReservedCpusetCgroupName))
}
func TestCpusetManager_AddAlloc(t *testing.T) {
func TestCpusetManager_AddAlloc_single(t *testing.T) {
manager, cleanup := tmpCpusetManager(t)
defer cleanup()
require.NoError(t, manager.Init())
alloc := mock.Alloc()
alloc.AllocatedResources.Tasks["web"].Cpu.ReservedCores = manager.parentCpuset.ToSlice()
// reserve just one core (the 0th core, which probably exists)
alloc.AllocatedResources.Tasks["web"].Cpu.ReservedCores = cpuset.New(0).ToSlice()
manager.AddAlloc(alloc)
// force reconcile
manager.reconcileCpusets()
// check that no more cores exist in the shared cgroup
// check that the 0th core is no longer available in the shared group
// actual contents of shared group depends on machine core count
require.DirExists(t, filepath.Join(manager.cgroupParentPath, SharedCpusetCgroupName))
require.FileExists(t, filepath.Join(manager.cgroupParentPath, SharedCpusetCgroupName, "cpuset.cpus"))
sharedCpusRaw, err := ioutil.ReadFile(filepath.Join(manager.cgroupParentPath, SharedCpusetCgroupName, "cpuset.cpus"))
require.NoError(t, err)
sharedCpus, err := cpuset.Parse(string(sharedCpusRaw))
require.NoError(t, err)
require.Empty(t, sharedCpus.ToSlice())
require.NotEmpty(t, sharedCpus.ToSlice())
require.NotContains(t, sharedCpus.ToSlice(), uint16(0))
// check that all cores are allocated to reserved cgroup
// check that the 0th core is allocated to reserved cgroup
require.DirExists(t, filepath.Join(manager.cgroupParentPath, ReservedCpusetCgroupName))
reservedCpusRaw, err := ioutil.ReadFile(filepath.Join(manager.cgroupParentPath, ReservedCpusetCgroupName, "cpuset.cpus"))
require.NoError(t, err)
@ -100,6 +104,17 @@ func TestCpusetManager_AddAlloc(t *testing.T) {
require.Exactly(t, alloc.AllocatedResources.Tasks["web"].Cpu.ReservedCores, taskCpus.ToSlice())
}
func TestCpusetManager_AddAlloc_subset(t *testing.T) {
t.Skip("todo: add test for #11933")
}
func TestCpusetManager_AddAlloc_all(t *testing.T) {
// cgroupsv2 changes behavior of writing empty cpuset.cpu, which is what
// happens to the /shared group when one or more allocs consume all available
// cores.
t.Skip("todo: add test for #11933")
}
func TestCpusetManager_RemoveAlloc(t *testing.T) {
manager, cleanup := tmpCpusetManager(t)
defer cleanup()