mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-14 02:43:36 +00:00
rbd: add validation to ToCSI() for rbdVolume and rbdSnapshot
After an unfortnate timed restart of the provisioner, a volume that got cloned did not get a `rbdVolume.VolID` set. The `.VolID` is used as the CSI Volume Handle, and is a required attribute. The `rbdVolume` and `rbdSnapshot` structs have a `.ToCSI()` function that can do the validation of required attributes. This is now added, including unit-tests. Signed-off-by: Niels de Vos <ndevos@ibm.com>
This commit is contained in:
committed by
mergify[bot]
parent
b3faa04504
commit
ac8cda5e37
@ -16,7 +16,10 @@ limitations under the License.
|
||||
|
||||
package rbd
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestValidateStriping(t *testing.T) {
|
||||
t.Parallel()
|
||||
@ -85,3 +88,81 @@ func TestValidateStriping(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestToCSIVolume(t *testing.T) {
|
||||
t.Parallel()
|
||||
tests := []struct {
|
||||
name string
|
||||
rv *rbdVolume
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "all attributes set",
|
||||
rv: &rbdVolume{
|
||||
rbdImage: rbdImage{
|
||||
VolID: "0001-unique-volume-id",
|
||||
Pool: "ecpool",
|
||||
JournalPool: "replicapool",
|
||||
RbdImageName: "csi-vol-01234-5678-90abc",
|
||||
},
|
||||
},
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "missing volume-id",
|
||||
rv: &rbdVolume{
|
||||
rbdImage: rbdImage{
|
||||
VolID: "",
|
||||
Pool: "ecpool",
|
||||
JournalPool: "replicapool",
|
||||
RbdImageName: "csi-vol-01234-5678-90abc",
|
||||
},
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "missing pool",
|
||||
rv: &rbdVolume{
|
||||
rbdImage: rbdImage{
|
||||
VolID: "0001-unique-volume-id",
|
||||
Pool: "",
|
||||
JournalPool: "replicapool",
|
||||
RbdImageName: "csi-vol-01234-5678-90abc",
|
||||
},
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "missing journal-pool",
|
||||
rv: &rbdVolume{
|
||||
rbdImage: rbdImage{
|
||||
VolID: "0001-unique-volume-id",
|
||||
Pool: "ecpool",
|
||||
JournalPool: "",
|
||||
RbdImageName: "csi-vol-01234-5678-90abc",
|
||||
},
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "missing image-name",
|
||||
rv: &rbdVolume{
|
||||
rbdImage: rbdImage{
|
||||
VolID: "0001-unique-volume-id",
|
||||
Pool: "ecpool",
|
||||
JournalPool: "",
|
||||
RbdImageName: "",
|
||||
},
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
if _, err := tt.rv.ToCSI(context.TODO()); (err != nil) != tt.wantErr {
|
||||
t.Errorf("ToCSI() error = %v, wantErr %v", err, tt.wantErr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user