hs-test: fix readCpus 43/42043/3
authorMatus Fabian <[email protected]>
Wed, 18 Dec 2024 13:20:31 +0000 (14:20 +0100)
committerDave Wallace <[email protected]>
Wed, 18 Dec 2024 16:09:57 +0000 (16:09 +0000)
return error otherwise hst might panic

Type: test

Change-Id: Ib3ec8a2113af4594f2c2fc54ae72e358bfadaef2
Signed-off-by: Matus Fabian <[email protected]>
extras/hs-test/infra/cpu.go

index 7a29eb4..e871c60 100644 (file)
@@ -140,8 +140,11 @@ func (c *CpuAllocatorT) readCpus() error {
 
                        // make c.cpus divisible by maxContainerCount * nCpus, so we don't have to check which numa will be used
                        // and we can use offsets
-                       count_to_remove := len(tmpCpus) % (c.maxContainerCount * *NConfiguredCpus)
-                       c.cpus = append(c.cpus, tmpCpus[:len(tmpCpus)-count_to_remove]...)
+                       countToRemove := len(tmpCpus) % (c.maxContainerCount * *NConfiguredCpus)
+                       if countToRemove >= len(tmpCpus) {
+                               return fmt.Errorf("requested too much CPUs per container (%d) should be no more than %d", *NConfiguredCpus, len(tmpCpus)/c.maxContainerCount)
+                       }
+                       c.cpus = append(c.cpus, tmpCpus[:len(tmpCpus)-countToRemove]...)
                        tmpCpus = tmpCpus[:0]
                }
        } else {