...

Source file src/k8s.io/kubernetes/pkg/kubelet/cm/cpumanager/policy_none_test.go

Documentation: k8s.io/kubernetes/pkg/kubelet/cm/cpumanager

     1  /*
     2  Copyright 2017 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package cpumanager
    18  
    19  import (
    20  	"testing"
    21  
    22  	"k8s.io/kubernetes/pkg/kubelet/cm/cpumanager/state"
    23  	"k8s.io/utils/cpuset"
    24  )
    25  
    26  func TestNonePolicyName(t *testing.T) {
    27  	policy := &nonePolicy{}
    28  
    29  	policyName := policy.Name()
    30  	if policyName != "none" {
    31  		t.Errorf("NonePolicy Name() error. expected: none, returned: %v", policyName)
    32  	}
    33  }
    34  
    35  func TestNonePolicyAllocate(t *testing.T) {
    36  	policy := &nonePolicy{}
    37  
    38  	st := &mockState{
    39  		assignments:   state.ContainerCPUAssignments{},
    40  		defaultCPUSet: cpuset.New(1, 2, 3, 4, 5, 6, 7),
    41  	}
    42  
    43  	testPod := makePod("fakePod", "fakeContainer", "1000m", "1000m")
    44  
    45  	container := &testPod.Spec.Containers[0]
    46  	err := policy.Allocate(st, testPod, container)
    47  	if err != nil {
    48  		t.Errorf("NonePolicy Allocate() error. expected no error but got: %v", err)
    49  	}
    50  }
    51  
    52  func TestNonePolicyRemove(t *testing.T) {
    53  	policy := &nonePolicy{}
    54  
    55  	st := &mockState{
    56  		assignments:   state.ContainerCPUAssignments{},
    57  		defaultCPUSet: cpuset.New(1, 2, 3, 4, 5, 6, 7),
    58  	}
    59  
    60  	testPod := makePod("fakePod", "fakeContainer", "1000m", "1000m")
    61  
    62  	container := &testPod.Spec.Containers[0]
    63  	err := policy.RemoveContainer(st, string(testPod.UID), container.Name)
    64  	if err != nil {
    65  		t.Errorf("NonePolicy RemoveContainer() error. expected no error but got %v", err)
    66  	}
    67  }
    68  
    69  func TestNonePolicyGetAllocatableCPUs(t *testing.T) {
    70  	// any random topology is fine
    71  
    72  	var cpuIDs []int
    73  	for cpuID := range topoSingleSocketHT.CPUDetails {
    74  		cpuIDs = append(cpuIDs, cpuID)
    75  	}
    76  
    77  	policy := &nonePolicy{}
    78  
    79  	st := &mockState{
    80  		assignments:   state.ContainerCPUAssignments{},
    81  		defaultCPUSet: cpuset.New(cpuIDs...),
    82  	}
    83  
    84  	cpus := policy.GetAllocatableCPUs(st)
    85  	if cpus.Size() != 0 {
    86  		t.Errorf("NonePolicy GetAllocatableCPUs() error. expected empty set, returned: %v", cpus)
    87  	}
    88  }
    89  
    90  func TestNonePolicyOptions(t *testing.T) {
    91  	var err error
    92  
    93  	_, err = NewNonePolicy(nil)
    94  	if err != nil {
    95  		t.Errorf("NewNonePolicy with nil options failure. expected no error but got: %v", err)
    96  	}
    97  
    98  	opts := map[string]string{
    99  		FullPCPUsOnlyOption: "true",
   100  	}
   101  	_, err = NewNonePolicy(opts)
   102  	if err == nil {
   103  		t.Errorf("NewNonePolicy with (any) options failure. expected error but got none")
   104  	}
   105  }
   106  

View as plain text