Update policy_none removing canAdmitPodResult

Update unit tests for none_policy
Add Name test for policy_restricted
This commit is contained in:
Adrian Chiris 2019-12-05 06:15:20 +00:00 committed by nolancon
parent cf8b098dda
commit dc36924c37
3 changed files with 52 additions and 23 deletions

View File

@ -36,12 +36,6 @@ func (p *nonePolicy) Name() string {
return PolicyNone
}
func (p *nonePolicy) canAdmitPodResult(hint *TopologyHint) lifecycle.PodAdmitResult {
return lifecycle.PodAdmitResult{
Admit: true,
}
}
func (p *nonePolicy) Merge(providersHints []map[string][]TopologyHint) (TopologyHint, lifecycle.PodAdmitResult) {
return TopologyHint{}, p.canAdmitPodResult(nil)
return TopologyHint{}, lifecycle.PodAdmitResult{Admit: true}
}

View File

@ -17,10 +17,11 @@ limitations under the License.
package topologymanager
import (
"k8s.io/kubernetes/pkg/kubelet/lifecycle"
"testing"
)
func TestName(t *testing.T) {
func TestPolicyNoneName(t *testing.T) {
tcases := []struct {
name string
expected string
@ -38,30 +39,46 @@ func TestName(t *testing.T) {
}
}
func TestPolicyNoneCanAdmitPodResult(t *testing.T) {
func TestPolicyNoneMerge(t *testing.T) {
tcases := []struct {
name string
hint TopologyHint
expected bool
name string
providersHints []map[string][]TopologyHint
expectedHint TopologyHint
expectedAdmit lifecycle.PodAdmitResult
}{
{
name: "Preferred is set to false in topology hints",
hint: TopologyHint{nil, false},
expected: true,
name: "merged empty providers hints",
providersHints: []map[string][]TopologyHint{},
expectedHint: TopologyHint{},
expectedAdmit: lifecycle.PodAdmitResult{Admit: true},
},
{
name: "Preferred is set to true in topology hints",
hint: TopologyHint{nil, true},
expected: true,
name: "merge with a single provider with a single preferred resource",
providersHints: []map[string][]TopologyHint{
{
"resource": {{NUMANodeAffinity: NewTestBitMask(0, 1), Preferred: true}},
},
},
expectedHint: TopologyHint{},
expectedAdmit: lifecycle.PodAdmitResult{Admit: true},
},
{
name: "merge with a single provider with a single non-preferred resource",
providersHints: []map[string][]TopologyHint{
{
"resource": {{NUMANodeAffinity: NewTestBitMask(0, 1), Preferred: false}},
},
},
expectedHint: TopologyHint{},
expectedAdmit: lifecycle.PodAdmitResult{Admit: true},
},
}
for _, tc := range tcases {
policy := NewNonePolicy()
result := policy.(*nonePolicy).canAdmitPodResult(&tc.hint)
if result.Admit != tc.expected {
t.Errorf("Expected Admit field in result to be %t, got %t", tc.expected, result.Admit)
result, admit := policy.Merge(tc.providersHints)
if !result.IsEqual(tc.expectedHint) || admit.Admit != tc.expectedAdmit.Admit {
t.Errorf("Test Case: %s: Expected merge hint to be %v, got %v", tc.name, tc.expectedHint, result)
}
}
}

View File

@ -20,6 +20,24 @@ import (
"testing"
)
func TestPolicyRestrictedName(t *testing.T) {
tcases := []struct {
name string
expected string
}{
{
name: "New Restricted Policy",
expected: "restricted",
},
}
for _, tc := range tcases {
policy := NewRestrictedPolicy([]int{0, 1})
if policy.Name() != tc.expected {
t.Errorf("Expected Policy Name to be %s, got %s", tc.expected, policy.Name())
}
}
}
func TestPolicyRestrictedCanAdmitPodResult(t *testing.T) {
tcases := []struct {
name string
@ -58,7 +76,7 @@ func TestPolicyRestrictedCanAdmitPodResult(t *testing.T) {
}
}
func TestRestrictedPolicyMerge(t *testing.T) {
func TestPolicyRestrictedMerge(t *testing.T) {
numaNodes := []int{0, 1}
policy := NewRestrictedPolicy(numaNodes)