Skip to content

Commit

Permalink
controller: node: add getDiskInfoHandler to fix error out in unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
yasker committed Aug 4, 2018
1 parent b814614 commit 298b65f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
8 changes: 7 additions & 1 deletion controller/node_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,12 @@ type NodeController struct {
sStoreSynced cache.InformerSynced

queue workqueue.RateLimitingInterface

getDiskInfoHandler GetDiskInfoHandler
}

type GetDiskInfoHandler func(string) (*util.DiskInfo, error)

func NewNodeController(
ds *datastore.DataStore,
scheme *runtime.Scheme,
Expand Down Expand Up @@ -79,6 +83,8 @@ func NewNodeController(
sStoreSynced: settingInformer.Informer().HasSynced,

queue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "longhorn-node"),

getDiskInfoHandler: util.GetDiskInfo,
}

nodeInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
Expand Down Expand Up @@ -316,7 +322,7 @@ func (nc *NodeController) syncDiskStatus(node *longhorn.Node) error {
delete(replicaDiskMap, diskID)
}
// get disk available size
diskInfo, err := util.GetDiskInfo(disk.Path)
diskInfo, err := nc.getDiskInfoHandler(disk.Path)
if err != nil {
logrus.Errorf("Get disk information on node %v error: %v", node.Name, err)
} else {
Expand Down
16 changes: 16 additions & 0 deletions controller/node_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/rancher/longhorn-manager/datastore"
"github.com/rancher/longhorn-manager/types"
"github.com/rancher/longhorn-manager/util"

longhorn "github.com/rancher/longhorn-manager/k8s/pkg/apis/longhorn/v1alpha1"
lhfake "github.com/rancher/longhorn-manager/k8s/pkg/client/clientset/versioned/fake"
Expand Down Expand Up @@ -52,13 +53,28 @@ func newTestNodeController(lhInformerFactory lhinformerfactory.SharedInformerFac
nc := NewNodeController(ds, scheme.Scheme, nodeInformer, settingInformer, podInformer, kubeClient, TestNamespace, controllerID)
fakeRecorder := record.NewFakeRecorder(100)
nc.eventRecorder = fakeRecorder
nc.getDiskInfoHandler = fakeGetDiskInfo

nc.nStoreSynced = alwaysReady
nc.pStoreSynced = alwaysReady

return nc
}

func fakeGetDiskInfo(directory string) (*util.DiskInfo, error) {
return &util.DiskInfo{
Fsid: "fsid",
Path: directory,
Type: "ext4",
FreeBlock: 0,
TotalBlock: 0,
BlockSize: 0,

StorageMaximum: 0,
StorageAvailable: 0,
}, nil
}

func (s *TestSuite) TestSyncNode(c *C) {
testCases := map[string]*NodeTestCase{}
MountPropagationBidirectional := v1.MountPropagationBidirectional
Expand Down

0 comments on commit 298b65f

Please sign in to comment.