diff --git a/cmd/plugins/topology-aware/policy/hint_test.go b/cmd/plugins/topology-aware/policy/hint_test.go index b5fc03823..d111613fc 100644 --- a/cmd/plugins/topology-aware/policy/hint_test.go +++ b/cmd/plugins/topology-aware/policy/hint_test.go @@ -213,56 +213,3 @@ func TestHintCpus(t *testing.T) { }) } } - -func TestString(t *testing.T) { - tcases := []struct { - name string - fh fakehints - // maps are unordered, so there might be different legitimate results - expected1 string - expected2 string - }{ - { - name: "Empty", - }, - { - name: "non-empty CPUs", - fh: fakehints{ - "key1": topology.Hints{ - "testkey3": topology.Hint{ // TODO(rojkov): this is bug - this value gets ignored - CPUs: "2", - NUMAs: "2", - Sockets: "2", - }, - "testkey2": topology.Hint{ - CPUs: "2", - NUMAs: "2", - Sockets: "2", - }, - }, - "key2": topology.Hints{ - "testkey3": topology.Hint{ // TODO(rojkov): this is bug - this value gets ignored - CPUs: "2", - NUMAs: "2", - Sockets: "2", - }, - "testkey2": topology.Hint{ - CPUs: "2", - NUMAs: "2", - Sockets: "2", - }, - }, - }, - expected1: "key1=cpus:2/nodes:2/sockets:2;key2=cpus:2/nodes:2/sockets:2", - expected2: "key2=cpus:2/nodes:2/sockets:2;key1=cpus:2/nodes:2/sockets:2", - }, - } - for _, tc := range tcases { - t.Run(tc.name, func(t *testing.T) { - actual := tc.fh.String() - if actual != tc.expected1 && actual != tc.expected2 { - t.Errorf("Expected %q, but got %q", tc.expected1, actual) - } - }) - } -} diff --git a/cmd/plugins/topology-aware/policy/mocks_test.go b/cmd/plugins/topology-aware/policy/mocks_test.go index 3e189e347..2333286a4 100644 --- a/cmd/plugins/topology-aware/policy/mocks_test.go +++ b/cmd/plugins/topology-aware/policy/mocks_test.go @@ -378,6 +378,9 @@ func (m *mockContainer) SetCpusetMems(string) { func (m *mockContainer) SetMemoryLimit(int64) { panic("unimplemented") } +func (m *mockContainer) SetMemorySwap(int64) { + panic("unimplemented") +} func (m *mockContainer) GetPendingAdjustment() *nri.ContainerAdjustment { panic("unimplemented") } @@ -426,6 +429,36 @@ func (m *mockContainer) GetProcesses() ([]string, error) { func (m *mockContainer) GetTasks() ([]string, error) { panic("unimplemented") } +func (m *mockContainer) GetCPUShares() int64 { + panic("unimplemented") +} +func (m *mockContainer) GetCPUQuota() int64 { + panic("unimplemented") +} +func (m *mockContainer) GetCPUPeriod() int64 { + panic("unimplemented") +} +func (m *mockContainer) GetCpusetCpus() string { + panic("unimplemented") +} +func (m *mockContainer) GetCpusetMems() string { + panic("unimplemented") +} +func (m *mockContainer) GetMemoryLimit() int64 { + panic("unimplemented") +} +func (m *mockContainer) GetMemorySwap() int64 { + panic("unimplemented") +} +func (m *mockContainer) GetCtime() time.Time { + panic("unimplemented") +} +func (m *mockContainer) PreserveCpuResources() bool { + return false +} +func (m *mockContainer) PreserveMemoryResources() bool { + return false +} type mockPod struct { name string @@ -510,6 +543,9 @@ func (m *mockPod) GetProcesses(bool) ([]string, error) { func (m *mockPod) GetTasks(bool) ([]string, error) { panic("unimplemented") } +func (m *mockPod) GetCtime() time.Time { + panic("unimplemented") +} type mockCache struct { returnValueForGetPolicyEntry bool diff --git a/cmd/plugins/topology-aware/policy/pools_test.go b/cmd/plugins/topology-aware/policy/pools_test.go index 8314c545f..c1d425dfd 100644 --- a/cmd/plugins/topology-aware/policy/pools_test.go +++ b/cmd/plugins/topology-aware/policy/pools_test.go @@ -21,6 +21,7 @@ import ( "path" "testing" + cfgapi "github.com/containers/nri-plugins/pkg/apis/config/v1alpha1/resmgr/policy/topologyaware" "github.com/containers/nri-plugins/pkg/resmgr/cache" policyapi "github.com/containers/nri-plugins/pkg/resmgr/policy" @@ -373,17 +374,19 @@ func TestPoolCreation(t *testing.T) { panic(err) } - reserved, _ := resapi.ParseQuantity("750m") policyOptions := &policyapi.BackendOptions{ Cache: &mockCache{}, System: sys, - Reserved: policyapi.ConstraintSet{ - policyapi.DomainCPU: reserved, + Config: &cfgapi.Config{ + ReservedResources: cfgapi.Constraints{ + cfgapi.CPU: "750m", + }, }, } log.EnableDebug(true) - policy := CreateTopologyAwarePolicy(policyOptions).(*policy) + policy := New().(*policy) + policy.Setup(policyOptions) log.EnableDebug(false) if policy.root.GetSupply().SharableCPUs().Size()+policy.root.GetSupply().IsolatedCPUs().Size()+policy.root.GetSupply().ReservedCPUs().Size() != tc.expectedRootNodeCPUs { @@ -508,17 +511,19 @@ func TestWorkloadPlacement(t *testing.T) { panic(err) } - reserved, _ := resapi.ParseQuantity("750m") policyOptions := &policyapi.BackendOptions{ Cache: &mockCache{}, System: sys, - Reserved: policyapi.ConstraintSet{ - policyapi.DomainCPU: reserved, + Config: &cfgapi.Config{ + ReservedResources: cfgapi.Constraints{ + cfgapi.CPU: "750m", + }, }, } log.EnableDebug(true) - policy := CreateTopologyAwarePolicy(policyOptions).(*policy) + policy := New().(*policy) + policy.Setup(policyOptions) log.EnableDebug(false) scores, filteredPools := policy.sortPoolsByScore(tc.req, tc.affinities) @@ -660,17 +665,19 @@ func TestContainerMove(t *testing.T) { panic(err) } - reserved, _ := resapi.ParseQuantity("750m") policyOptions := &policyapi.BackendOptions{ Cache: &mockCache{}, System: sys, - Reserved: policyapi.ConstraintSet{ - policyapi.DomainCPU: reserved, + Config: &cfgapi.Config{ + ReservedResources: cfgapi.Constraints{ + cfgapi.CPU: "750m", + }, }, } log.EnableDebug(true) - policy := CreateTopologyAwarePolicy(policyOptions).(*policy) + policy := New().(*policy) + policy.Setup(policyOptions) log.EnableDebug(false) grant1, err := policy.allocatePool(tc.container1, "") @@ -931,17 +938,19 @@ func TestAffinities(t *testing.T) { panic(err) } - reserved, _ := resapi.ParseQuantity("750m") policyOptions := &policyapi.BackendOptions{ Cache: &mockCache{}, System: sys, - Reserved: policyapi.ConstraintSet{ - policyapi.DomainCPU: reserved, + Config: &cfgapi.Config{ + ReservedResources: cfgapi.Constraints{ + cfgapi.CPU: "750m", + }, }, } log.EnableDebug(true) - policy := CreateTopologyAwarePolicy(policyOptions).(*policy) + policy := New().(*policy) + policy.Setup(policyOptions) log.EnableDebug(false) affinities := map[int]int32{}