Skip to content

Commit

Permalink
Merge 9d3a9e7 into 2b47638
Browse files Browse the repository at this point in the history
  • Loading branch information
maya-r committed Feb 18, 2021
2 parents 2b47638 + 9d3a9e7 commit 894fcca
Show file tree
Hide file tree
Showing 9 changed files with 221 additions and 1 deletion.
24 changes: 24 additions & 0 deletions pkg/image/filefmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,30 @@ var knownHeaders = Headers{
SizeOff: 0,
SizeLen: 0,
},
"vmdk": Header{
Format: "vmdk",
magicNumber: []byte{0x4B, 0x44, 0x4D, 0x56},
SizeOff: 0,
SizeLen: 0,
},
"vdi": Header{
Format: "vdi",
magicNumber: []byte{0x3C, 0x3C, 0x3C, 0x20},
SizeOff: 0,
SizeLen: 0,
},
"vhd": Header{
Format: "vhd",
magicNumber: []byte{0x63, 0x6F, 0x6E, 0x6E, 0x65, 0x63, 0x74, 0x69, 0x78},
SizeOff: 0,
SizeLen: 0,
},
"vhdx": Header{
Format: "vhdx",
magicNumber: []byte{0x76, 0x68, 0x64, 0x78, 0x66, 0x69, 0x6C, 0x65},
SizeOff: 0,
SizeLen: 0,
},
}

// Header represents our parameters for a file format header
Expand Down
8 changes: 8 additions & 0 deletions pkg/image/filefmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ var _ = Describe("File format tests", func() {
fields{"gz", []byte{0x1F, 0x8B}, 0, 0, 0},
[]byte{'Q', 'F', 'I', 0xfb},
false),
table.Entry("match vmdk",
fields{"vmdk", []byte{0x4B, 0x44, 0x4D, 0x56}, 0, 24, 8},
[]byte{0x4B, 0x44, 0x4D, 0x56},
true),
table.Entry("match vdi",
fields{"vdi", []byte{0x3C, 0x3C, 0x3C, 0x20}, 0, 24, 8},
[]byte{0x3C, 0x3C, 0x3C, 0x20},
true),
)

tokenQcow := make([]byte, 20)
Expand Down
2 changes: 1 addition & 1 deletion pkg/image/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func (o *qemuOperations) Info(url *url.URL) (*ImgInfo, error) {

func isSupportedFormat(value string) bool {
switch value {
case "raw", "qcow2":
case "raw", "qcow2", "vmdk", "vdi", "vpc", "vhdx":
return true
default:
return false
Expand Down
8 changes: 8 additions & 0 deletions pkg/image/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ const (
ExtGz = ".gz"
// ExtQcow2 is a constant for the .qcow2 extenstion
ExtQcow2 = ".qcow2"
// ExtVmdk is a constant for the .vmdk VMware extenstion
ExtVmdk = ".vmdk"
// ExtVdi is a constant for the .vdi VirtualBox extenstion
ExtVdi = ".vdi"
// ExtVhd is a constant for the .vhd Microsoft Virtual Server Virtual Hard Disk extenstion
ExtVhd = ".vhd"
// ExtVhdx is a constant for the .vhd Hyper-V Virtual Hard Disk V.2 extenstion
ExtVhdx = ".vhdx"
// ExtTar is a constant for the .tar extenstion
ExtTar = ".tar"
// ExtXz is a constant for the .xz extenstion
Expand Down
12 changes: 12 additions & 0 deletions pkg/importer/format-readers.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,18 @@ func (fr *FormatReaders) fileFormatSelector(hdr *image.Header) {
fr.Archived = true
fr.ArchiveXz = true
}
case "vmdk":
r = nil
fr.Convert = true
case "vdi":
r = nil
fr.Convert = true
case "vhd":
r = nil
fr.Convert = true
case "vhdx":
r = nil
fr.Convert = true
}
if err == nil && r != nil {
fr.appendReader(rdrTypM[fFmt], r)
Expand Down
108 changes: 108 additions & 0 deletions tests/datavolume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ var _ = Describe("[vendor:cnv-qe@redhat.com][level:component]DataVolume tests",
httpsTinyCoreQcow2URL := func() string {
return fmt.Sprintf(utils.HTTPSTinyCoreQcow2URL, f.CdiInstallNs)
}
httpsTinyCoreVmdkURL := func() string {
return fmt.Sprintf(utils.HTTPSTinyCoreVmdkURL, f.CdiInstallNs)
}
httpsTinyCoreVdiURL := func() string {
return fmt.Sprintf(utils.HTTPSTinyCoreVdiURL, f.CdiInstallNs)
}
httpsTinyCoreVhdURL := func() string {
return fmt.Sprintf(utils.HTTPSTinyCoreVhdURL, f.CdiInstallNs)
}
httpsTinyCoreVhdxURL := func() string {
return fmt.Sprintf(utils.HTTPSTinyCoreVhdxURL, f.CdiInstallNs)
}
tinyCoreQcow2URL := func() string {
return fmt.Sprintf(utils.TinyCoreQcow2URL+".gz", f.CdiInstallNs)
}
Expand Down Expand Up @@ -572,6 +584,102 @@ var _ = Describe("[vendor:cnv-qe@redhat.com][level:component]DataVolume tests",
Message: "Import Complete",
Reason: "Completed",
}}),
table.Entry("succeed creating import dv with given valid vmdk url (https)", dataVolumeTestArguments{
name: "dv-https-import-vmdk",
size: "1Gi",
url: httpsTinyCoreVmdkURL,
dvFunc: createHTTPSDataVolume,
eventReason: controller.ImportSucceeded,
phase: cdiv1.Succeeded,
checkPermissions: true,
readyCondition: &cdiv1.DataVolumeCondition{
Type: cdiv1.DataVolumeReady,
Status: v1.ConditionTrue,
},
boundCondition: &cdiv1.DataVolumeCondition{
Type: cdiv1.DataVolumeBound,
Status: v1.ConditionTrue,
Message: "PVC dv-https-import-vmdk Bound",
Reason: "Bound",
},
runningCondition: &cdiv1.DataVolumeCondition{
Type: cdiv1.DataVolumeRunning,
Status: v1.ConditionFalse,
Message: "Import Complete",
Reason: "Completed",
}}),
table.Entry("succeed creating import dv with given valid vdi url (https)", dataVolumeTestArguments{
name: "dv-https-import-vdi",
size: "1Gi",
url: httpsTinyCoreVdiURL,
dvFunc: createHTTPSDataVolume,
eventReason: controller.ImportSucceeded,
phase: cdiv1.Succeeded,
checkPermissions: true,
readyCondition: &cdiv1.DataVolumeCondition{
Type: cdiv1.DataVolumeReady,
Status: v1.ConditionTrue,
},
boundCondition: &cdiv1.DataVolumeCondition{
Type: cdiv1.DataVolumeBound,
Status: v1.ConditionTrue,
Message: "PVC dv-https-import-vdi Bound",
Reason: "Bound",
},
runningCondition: &cdiv1.DataVolumeCondition{
Type: cdiv1.DataVolumeRunning,
Status: v1.ConditionFalse,
Message: "Import Complete",
Reason: "Completed",
}}),
table.Entry("succeed creating import dv with given valid vhd url (https)", dataVolumeTestArguments{
name: "dv-https-import-vhd",
size: "1Gi",
url: httpsTinyCoreVhdURL,
dvFunc: createHTTPSDataVolume,
eventReason: controller.ImportSucceeded,
phase: cdiv1.Succeeded,
checkPermissions: true,
readyCondition: &cdiv1.DataVolumeCondition{
Type: cdiv1.DataVolumeReady,
Status: v1.ConditionTrue,
},
boundCondition: &cdiv1.DataVolumeCondition{
Type: cdiv1.DataVolumeBound,
Status: v1.ConditionTrue,
Message: "PVC dv-https-import-vhd Bound",
Reason: "Bound",
},
runningCondition: &cdiv1.DataVolumeCondition{
Type: cdiv1.DataVolumeRunning,
Status: v1.ConditionFalse,
Message: "Import Complete",
Reason: "Completed",
}}),
table.Entry("succeed creating import dv with given valid vhdx url (https)", dataVolumeTestArguments{
name: "dv-https-import-vhdx",
size: "1Gi",
url: httpsTinyCoreVhdxURL,
dvFunc: createHTTPSDataVolume,
eventReason: controller.ImportSucceeded,
phase: cdiv1.Succeeded,
checkPermissions: true,
readyCondition: &cdiv1.DataVolumeCondition{
Type: cdiv1.DataVolumeReady,
Status: v1.ConditionTrue,
},
boundCondition: &cdiv1.DataVolumeCondition{
Type: cdiv1.DataVolumeBound,
Status: v1.ConditionTrue,
Message: "PVC dv-https-import-vhdx Bound",
Reason: "Bound",
},
runningCondition: &cdiv1.DataVolumeCondition{
Type: cdiv1.DataVolumeRunning,
Status: v1.ConditionFalse,
Message: "Import Complete",
Reason: "Completed",
}}),
table.Entry("[rfe_id:1111][crit:high][test_id:1361]succeed creating blank image dv", dataVolumeTestArguments{
name: "blank-image-dv",
size: "1Gi",
Expand Down
8 changes: 8 additions & 0 deletions tests/utils/datavolume.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ const (
HTTPSTinyCoreQcow2URL = "https://cdi-file-host.%s/tinyCore.qcow2"
// TinyCoreQcow2URLRateLimit provides a test url for the tineyCore qcow2 image via rate-limiting proxy
TinyCoreQcow2URLRateLimit = "http://cdi-file-host.%s:82/tinyCore.qcow2"
// HTTPSTinyCoreVmdkURL provides a test url for the tineyCore qcow2 image
HTTPSTinyCoreVmdkURL = "https://cdi-file-host.%s/tinyCore.vmdk"
// HTTPSTinyCoreVdiURL provides a test url for the tineyCore qcow2 image
HTTPSTinyCoreVdiURL = "https://cdi-file-host.%s/tinyCore.vdi"
// HTTPSTinyCoreVhdURL provides a test url for the tineyCore qcow2 image
HTTPSTinyCoreVhdURL = "https://cdi-file-host.%s/tinyCore.vhd"
// HTTPSTinyCoreVhdxURL provides a test url for the tineyCore qcow2 image
HTTPSTinyCoreVhdxURL = "https://cdi-file-host.%s/tinyCore.vhdx"
// InvalidQcowImagesURL provides a test url for invalid qcow images
InvalidQcowImagesURL = "http://cdi-file-host.%s/invalid_qcow_images/"
// LargeVirtualDiskQcow provides a test url for a cirros image with a large virtual size, in qcow2 format
Expand Down
48 changes: 48 additions & 0 deletions tests/utils/fileConversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ var formatTable = map[string]func(string, string) (string, error){
image.ExtXz: toXz,
image.ExtTar: toTar,
image.ExtQcow2: toQcow2,
image.ExtVmdk: toVmdk,
image.ExtVdi: toVdi,
image.ExtVhd: toVhd,
image.ExtVhdx: toVhdx,
"": toNoop,
}

Expand Down Expand Up @@ -141,6 +145,50 @@ func toQcow2(srcfile, tgtDir string) (string, error) {
return tgt, nil
}

func toVmdk(srcfile, tgtDir string) (string, error) {
base := strings.TrimSuffix(filepath.Base(srcfile), ".iso")
tgt := filepath.Join(tgtDir, base+image.ExtVmdk)
args := []string{"convert", "-f", "raw", "-O", "vmdk", srcfile, tgt}

if err := doCmdAndVerifyFile(tgt, "qemu-img", args...); err != nil {
return "", err
}
return tgt, nil
}

func toVdi(srcfile, tgtDir string) (string, error) {
base := strings.TrimSuffix(filepath.Base(srcfile), ".iso")
tgt := filepath.Join(tgtDir, base+image.ExtVdi)
args := []string{"convert", "-f", "raw", "-O", "vdi", srcfile, tgt}

if err := doCmdAndVerifyFile(tgt, "qemu-img", args...); err != nil {
return "", err
}
return tgt, nil
}

func toVhd(srcfile, tgtDir string) (string, error) {
base := strings.TrimSuffix(filepath.Base(srcfile), ".iso")
tgt := filepath.Join(tgtDir, base+image.ExtVhd)
args := []string{"convert", "-f", "raw", "-O", "vpc", srcfile, tgt}

if err := doCmdAndVerifyFile(tgt, "qemu-img", args...); err != nil {
return "", err
}
return tgt, nil
}

func toVhdx(srcfile, tgtDir string) (string, error) {
base := strings.TrimSuffix(filepath.Base(srcfile), ".iso")
tgt := filepath.Join(tgtDir, base+image.ExtVhdx)
args := []string{"convert", "-f", "raw", "-O", "vhdx", srcfile, tgt}

if err := doCmdAndVerifyFile(tgt, "qemu-img", args...); err != nil {
return "", err
}
return tgt, nil
}

func toNoop(src, tgtDir string) (string, error) {
return copyIfNotPresent(src, tgtDir)
}
Expand Down
4 changes: 4 additions & 0 deletions tools/cdi-func-test-file-host-init/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ func main() {
[]string{".gz"},
[]string{".xz"},
[]string{".qcow2"},
[]string{".vmdk"},
[]string{".vdi"},
[]string{".vhd"},
[]string{".vhdx"},
[]string{".qcow2", ".gz"},
[]string{".qcow2", ".xz"},
}
Expand Down

0 comments on commit 894fcca

Please sign in to comment.