Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
6356d85d
Commit
6356d85d
authored
Jun 21, 2016
by
Jan Safranek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Cinder volume plugin attach tests.
parent
a8fecd0c
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
21 deletions
+28
-21
attacher.go
pkg/volume/cinder/attacher.go
+28
-21
attacher_test.go
pkg/volume/cinder/attacher_test.go
+0
-0
No files found.
pkg/volume/cinder/attacher.go
View file @
6356d85d
...
@@ -30,7 +30,8 @@ import (
...
@@ -30,7 +30,8 @@ import (
)
)
type
cinderDiskAttacher
struct
{
type
cinderDiskAttacher
struct
{
host
volume
.
VolumeHost
host
volume
.
VolumeHost
cinderProvider
CinderProvider
}
}
var
_
volume
.
Attacher
=
&
cinderDiskAttacher
{}
var
_
volume
.
Attacher
=
&
cinderDiskAttacher
{}
...
@@ -42,7 +43,14 @@ const (
...
@@ -42,7 +43,14 @@ const (
)
)
func
(
plugin
*
cinderPlugin
)
NewAttacher
()
(
volume
.
Attacher
,
error
)
{
func
(
plugin
*
cinderPlugin
)
NewAttacher
()
(
volume
.
Attacher
,
error
)
{
return
&
cinderDiskAttacher
{
host
:
plugin
.
host
},
nil
cinder
,
err
:=
getCloudProvider
(
plugin
.
host
.
GetCloudProvider
())
if
err
!=
nil
{
return
nil
,
err
}
return
&
cinderDiskAttacher
{
host
:
plugin
.
host
,
cinderProvider
:
cinder
,
},
nil
}
}
func
(
attacher
*
cinderDiskAttacher
)
Attach
(
spec
*
volume
.
Spec
,
hostName
string
)
(
string
,
error
)
{
func
(
attacher
*
cinderDiskAttacher
)
Attach
(
spec
*
volume
.
Spec
,
hostName
string
)
(
string
,
error
)
{
...
@@ -53,11 +61,7 @@ func (attacher *cinderDiskAttacher) Attach(spec *volume.Spec, hostName string) (
...
@@ -53,11 +61,7 @@ func (attacher *cinderDiskAttacher) Attach(spec *volume.Spec, hostName string) (
volumeID
:=
volumeSource
.
VolumeID
volumeID
:=
volumeSource
.
VolumeID
cloud
,
err
:=
getCloudProvider
(
attacher
.
host
.
GetCloudProvider
())
instances
,
res
:=
attacher
.
cinderProvider
.
Instances
()
if
err
!=
nil
{
return
""
,
err
}
instances
,
res
:=
cloud
.
Instances
()
if
!
res
{
if
!
res
{
return
""
,
fmt
.
Errorf
(
"failed to list openstack instances"
)
return
""
,
fmt
.
Errorf
(
"failed to list openstack instances"
)
}
}
...
@@ -68,7 +72,7 @@ func (attacher *cinderDiskAttacher) Attach(spec *volume.Spec, hostName string) (
...
@@ -68,7 +72,7 @@ func (attacher *cinderDiskAttacher) Attach(spec *volume.Spec, hostName string) (
if
ind
:=
strings
.
LastIndex
(
instanceid
,
"/"
);
ind
>=
0
{
if
ind
:=
strings
.
LastIndex
(
instanceid
,
"/"
);
ind
>=
0
{
instanceid
=
instanceid
[(
ind
+
1
)
:
]
instanceid
=
instanceid
[(
ind
+
1
)
:
]
}
}
attached
,
err
:=
cloud
.
DiskIsAttached
(
volumeID
,
instanceid
)
attached
,
err
:=
attacher
.
cinderProvider
.
DiskIsAttached
(
volumeID
,
instanceid
)
if
err
!=
nil
{
if
err
!=
nil
{
// Log error and continue with attach
// Log error and continue with attach
glog
.
Warningf
(
glog
.
Warningf
(
...
@@ -80,7 +84,7 @@ func (attacher *cinderDiskAttacher) Attach(spec *volume.Spec, hostName string) (
...
@@ -80,7 +84,7 @@ func (attacher *cinderDiskAttacher) Attach(spec *volume.Spec, hostName string) (
// Volume is already attached to node.
// Volume is already attached to node.
glog
.
Infof
(
"Attach operation is successful. volume %q is already attached to node %q."
,
volumeID
,
instanceid
)
glog
.
Infof
(
"Attach operation is successful. volume %q is already attached to node %q."
,
volumeID
,
instanceid
)
}
else
{
}
else
{
_
,
err
=
cloud
.
AttachDisk
(
instanceid
,
volumeID
)
_
,
err
=
attacher
.
cinderProvider
.
AttachDisk
(
instanceid
,
volumeID
)
if
err
==
nil
{
if
err
==
nil
{
glog
.
Infof
(
"Attach operation successful: volume %q attached to node %q."
,
volumeID
,
instanceid
)
glog
.
Infof
(
"Attach operation successful: volume %q attached to node %q."
,
volumeID
,
instanceid
)
}
else
{
}
else
{
...
@@ -89,7 +93,7 @@ func (attacher *cinderDiskAttacher) Attach(spec *volume.Spec, hostName string) (
...
@@ -89,7 +93,7 @@ func (attacher *cinderDiskAttacher) Attach(spec *volume.Spec, hostName string) (
}
}
}
}
devicePath
,
err
:=
cloud
.
GetAttachmentDiskPath
(
instanceid
,
volumeID
)
devicePath
,
err
:=
attacher
.
cinderProvider
.
GetAttachmentDiskPath
(
instanceid
,
volumeID
)
if
err
!=
nil
{
if
err
!=
nil
{
glog
.
Infof
(
"Attach volume %q to instance %q failed with %v"
,
volumeID
,
instanceid
,
err
)
glog
.
Infof
(
"Attach volume %q to instance %q failed with %v"
,
volumeID
,
instanceid
,
err
)
return
""
,
err
return
""
,
err
...
@@ -181,22 +185,26 @@ func (attacher *cinderDiskAttacher) MountDevice(spec *volume.Spec, devicePath st
...
@@ -181,22 +185,26 @@ func (attacher *cinderDiskAttacher) MountDevice(spec *volume.Spec, devicePath st
}
}
type
cinderDiskDetacher
struct
{
type
cinderDiskDetacher
struct
{
host
volume
.
VolumeHost
mounter
mount
.
Interface
cinderProvider
CinderProvider
}
}
var
_
volume
.
Detacher
=
&
cinderDiskDetacher
{}
var
_
volume
.
Detacher
=
&
cinderDiskDetacher
{}
func
(
plugin
*
cinderPlugin
)
NewDetacher
()
(
volume
.
Detacher
,
error
)
{
func
(
plugin
*
cinderPlugin
)
NewDetacher
()
(
volume
.
Detacher
,
error
)
{
return
&
cinderDiskDetacher
{
host
:
plugin
.
host
},
nil
cinder
,
err
:=
getCloudProvider
(
plugin
.
host
.
GetCloudProvider
())
if
err
!=
nil
{
return
nil
,
err
}
return
&
cinderDiskDetacher
{
mounter
:
plugin
.
host
.
GetMounter
(),
cinderProvider
:
cinder
,
},
nil
}
}
func
(
detacher
*
cinderDiskDetacher
)
Detach
(
deviceMountPath
string
,
hostName
string
)
error
{
func
(
detacher
*
cinderDiskDetacher
)
Detach
(
deviceMountPath
string
,
hostName
string
)
error
{
volumeID
:=
path
.
Base
(
deviceMountPath
)
volumeID
:=
path
.
Base
(
deviceMountPath
)
cloud
,
err
:=
getCloudProvider
(
detacher
.
host
.
GetCloudProvider
())
instances
,
res
:=
detacher
.
cinderProvider
.
Instances
()
if
err
!=
nil
{
return
err
}
instances
,
res
:=
cloud
.
Instances
()
if
!
res
{
if
!
res
{
return
fmt
.
Errorf
(
"failed to list openstack instances"
)
return
fmt
.
Errorf
(
"failed to list openstack instances"
)
}
}
...
@@ -205,7 +213,7 @@ func (detacher *cinderDiskDetacher) Detach(deviceMountPath string, hostName stri
...
@@ -205,7 +213,7 @@ func (detacher *cinderDiskDetacher) Detach(deviceMountPath string, hostName stri
instanceid
=
instanceid
[(
ind
+
1
)
:
]
instanceid
=
instanceid
[(
ind
+
1
)
:
]
}
}
attached
,
err
:=
cloud
.
DiskIsAttached
(
volumeID
,
instanceid
)
attached
,
err
:=
detacher
.
cinderProvider
.
DiskIsAttached
(
volumeID
,
instanceid
)
if
err
!=
nil
{
if
err
!=
nil
{
// Log error and continue with detach
// Log error and continue with detach
glog
.
Errorf
(
glog
.
Errorf
(
...
@@ -219,7 +227,7 @@ func (detacher *cinderDiskDetacher) Detach(deviceMountPath string, hostName stri
...
@@ -219,7 +227,7 @@ func (detacher *cinderDiskDetacher) Detach(deviceMountPath string, hostName stri
return
nil
return
nil
}
}
if
err
=
cloud
.
DetachDisk
(
instanceid
,
volumeID
);
err
!=
nil
{
if
err
=
detacher
.
cinderProvider
.
DetachDisk
(
instanceid
,
volumeID
);
err
!=
nil
{
glog
.
Errorf
(
"Error detaching volume %q: %v"
,
volumeID
,
err
)
glog
.
Errorf
(
"Error detaching volume %q: %v"
,
volumeID
,
err
)
return
err
return
err
}
}
...
@@ -249,9 +257,8 @@ func (detacher *cinderDiskDetacher) WaitForDetach(devicePath string, timeout tim
...
@@ -249,9 +257,8 @@ func (detacher *cinderDiskDetacher) WaitForDetach(devicePath string, timeout tim
}
}
func
(
detacher
*
cinderDiskDetacher
)
UnmountDevice
(
deviceMountPath
string
)
error
{
func
(
detacher
*
cinderDiskDetacher
)
UnmountDevice
(
deviceMountPath
string
)
error
{
mounter
:=
detacher
.
host
.
GetMounter
()
volume
:=
path
.
Base
(
deviceMountPath
)
volume
:=
path
.
Base
(
deviceMountPath
)
if
err
:=
unmountPDAndRemoveGlobalPath
(
deviceMountPath
,
mounter
);
err
!=
nil
{
if
err
:=
unmountPDAndRemoveGlobalPath
(
deviceMountPath
,
detacher
.
mounter
);
err
!=
nil
{
glog
.
Errorf
(
"Error unmounting %q: %v"
,
volume
,
err
)
glog
.
Errorf
(
"Error unmounting %q: %v"
,
volume
,
err
)
}
}
...
...
pkg/volume/cinder/attacher_test.go
0 → 100644
View file @
6356d85d
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment