Skip to content
This repository was archived by the owner on Mar 22, 2018. It is now read-only.

Commit 900020b

Browse files
Add some unit tests & improve logging
1 parent 00d4753 commit 900020b

4 files changed

Lines changed: 23 additions & 13 deletions

File tree

app/cinderplugin/main.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package main
1818

1919
import (
20+
"flag"
2021
"fmt"
2122
"os"
2223

@@ -30,7 +31,14 @@ var (
3031
cloudconfig string
3132
)
3233

34+
func init() {
35+
flag.Set("logtostderr", "true")
36+
}
37+
3338
func main() {
39+
40+
flag.CommandLine.Parse([]string{})
41+
3442
cmd := &cobra.Command{
3543
Use: "Cinder",
3644
Short: "CSI based Cinder driver",
@@ -39,6 +47,8 @@ func main() {
3947
},
4048
}
4149

50+
cmd.Flags().AddGoFlagSet(flag.CommandLine)
51+
4252
cmd.PersistentFlags().StringVar(&nodeID, "nodeid", "", "node id")
4353
cmd.MarkPersistentFlagRequired("nodeid")
4454

pkg/cinder/mount/mount.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ import (
2525
"k8s.io/kubernetes/pkg/util/mount"
2626
"k8s.io/kubernetes/pkg/volume/util"
2727
utilexec "k8s.io/utils/exec"
28-
28+
2929
"github.com/golang/glog"
3030
)
3131

3232
const (
33-
probeVolumeDuration = 1 * time.Second
34-
probeVolumeTimeout = 60 * time.Second
33+
probeVolumeDuration = 1 * time.Second
34+
probeVolumeTimeout = 60 * time.Second
3535
)
3636

3737
type IMount interface {
@@ -129,11 +129,11 @@ func (m *Mount) IsLikelyNotMountPointDetach(targetpath string) (bool, error) {
129129
notMnt, err := mount.New("").IsLikelyNotMountPoint(targetpath)
130130
if err != nil {
131131
if os.IsNotExist(err) {
132-
return notMnt,fmt.Errorf("targetpath not found")
133-
} else {
134-
return notMnt, err
135-
}
136-
}
132+
return notMnt, fmt.Errorf("targetpath not found")
133+
} else {
134+
return notMnt, err
135+
}
136+
}
137137
return notMnt, nil
138138
}
139139

pkg/cinder/nodeserver.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
3636
targetPath := req.GetTargetPath()
3737
fsType := req.GetVolumeCapability().GetMount().GetFsType()
3838
devicePath := req.GetPublishVolumeInfo()["DevicePath"]
39-
39+
4040
// Get Mount Provider
4141
m, err := mount.GetMountProvider()
4242
if err != nil {
4343
glog.V(3).Infof("Failed to GetMountProvider: %v", err)
4444
return nil, err
4545
}
46-
46+
4747
// Device Scan
4848
err = m.ScanForAttach(devicePath)
4949
if err != nil {
@@ -68,7 +68,7 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
6868
}
6969
mountFlags := req.GetVolumeCapability().GetMount().GetMountFlags()
7070
options = append(options, mountFlags...)
71-
71+
7272
// Mount
7373
err = m.FormatAndMount(devicePath, targetPath, fsType, options)
7474
if err != nil {
@@ -82,7 +82,7 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
8282
func (ns *nodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpublishVolumeRequest) (*csi.NodeUnpublishVolumeResponse, error) {
8383

8484
targetPath := req.GetTargetPath()
85-
85+
8686
// Get Mount Provider
8787
m, err := mount.GetMountProvider()
8888
if err != nil {

pkg/cinder/openstack/openstack.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func GetConfigFromEnv() (gophercloud.AuthOptions, gophercloud.EndpointOpts, erro
105105
glog.V(3).Infof("Failed to read OpenStack configuration from env: %v", err)
106106
return authOpts, epOpts, err
107107
}
108-
108+
109109
epOpts = gophercloud.EndpointOpts{
110110
Region: os.Getenv("OS_REGION_NAME"),
111111
}

0 commit comments

Comments
 (0)