forked from kubevirt/kubevirt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvirtmanifest_test.go
117 lines (94 loc) · 3.38 KB
/
virtmanifest_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
* This file is part of the kubevirt project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Copyright 2017 Red Hat, Inc.
*
*/
package tests_test
import (
"flag"
"fmt"
"net/url"
"strings"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"k8s.io/apimachinery/pkg/util/json"
"k8s.io/client-go/rest"
"kubevirt.io/kubevirt/pkg/api/v1"
"kubevirt.io/kubevirt/pkg/kubecli"
"kubevirt.io/kubevirt/pkg/virt-manifest"
"kubevirt.io/kubevirt/tests"
)
var _ = Describe("Virtmanifest", func() {
Context("Manifest Service", func() {
flag.Parse()
var manifestClient *rest.RESTClient
var vm *v1.VM
BeforeEach(func() {
tests.BeforeTestCleanup()
var err error
var masterUrl *url.URL
masterUrl, err = url.Parse(flag.Lookup("master").Value.String())
Expect(err).ToNot(HaveOccurred())
hostParts := strings.Split(masterUrl.Host, ":")
Expect(len(hostParts)).To(Equal(2))
manifestClient, err = kubecli.GetRESTClientFromFlags(fmt.Sprintf("http://%s:8186", hostParts[0]), "")
Expect(err).ToNot(HaveOccurred())
vm = tests.NewRandomVM()
})
It("Should report server status", func() {
ref := map[string]string{"status": "ok"}
data := map[string]string{}
res, err := manifestClient.Get().RequestURI("/api/v1/status").DoRaw()
Expect(err).ToNot(HaveOccurred())
err = json.Unmarshal(res, &data)
Expect(err).ToNot(HaveOccurred())
Expect(data).To(Equal(ref))
})
It("Should return YAML if requested", func() {
ref := "status: ok\n"
res, err := manifestClient.Get().RequestURI("/api/v1/status").SetHeader("Accept", "application/yaml").DoRaw()
Expect(err).ToNot(HaveOccurred())
Expect(string(res)).To(Equal(ref))
})
It("Should map a VM manifest", func() {
vmName := vm.ObjectMeta.Name
mappedVm := v1.VM{}
request, err := json.Marshal(vm)
Expect(err).ToNot(HaveOccurred())
res, err := manifestClient.Post().SetHeader("Content-type", "application/json").Resource("manifest").Body(request).DoRaw()
Expect(err).ToNot(HaveOccurred())
err = json.Unmarshal(res, &mappedVm)
Expect(mappedVm.ObjectMeta.Name).To(Equal(vmName))
Expect(mappedVm.Spec.Domain.Type).To(Equal("qemu"))
})
It("Should map PersistentVolumeClaims", func() {
mappedVm := v1.VM{}
vm.Spec.Domain.Devices.Disks = []v1.Disk{v1.Disk{
Device: "disk",
Type: virt_manifest.Type_PersistentVolumeClaim,
Source: v1.DiskSource{Name: "test"},
Target: v1.DiskTarget{Bus: "scsi", Device: "vda"},
}}
request, err := json.Marshal(vm)
Expect(err).ToNot(HaveOccurred())
res, err := manifestClient.Post().SetHeader("Content-type", "application/json").Resource("manifest").Body(request).DoRaw()
Expect(err).ToNot(HaveOccurred())
err = json.Unmarshal(res, &mappedVm)
Expect(len(mappedVm.Spec.Domain.Devices.Disks)).To(Equal(1))
Expect(mappedVm.Spec.Domain.Devices.Disks[0].Type).To(Equal(virt_manifest.Type_PersistentVolumeClaim))
})
})
})