-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrappedcmds_internal_test.go
161 lines (130 loc) · 3.39 KB
/
wrappedcmds_internal_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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// Copyright 2016 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package kvm
import (
"errors"
"io/ioutil"
"path/filepath"
"github.com/juju/testing"
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
"github.com/juju/juju/container/kvm/libvirt"
)
type libvirtInternalSuite struct {
testing.IsolationSuite
}
var _ = gc.Suite(&libvirtInternalSuite{})
func (libvirtInternalSuite) TestWriteMetadata(c *gc.C) {
d := c.MkDir()
err := writeMetadata(d)
c.Check(err, jc.ErrorIsNil)
b, err := ioutil.ReadFile(filepath.Join(d, metadata))
c.Check(err, jc.ErrorIsNil)
c.Assert(string(b), gc.Matches, `{"instance-id": ".*-.*-.*-.*"}`)
}
func (libvirtInternalSuite) TestWriteDomainXMLSucceeds(c *gc.C) {
d := c.MkDir()
stub := &runStub{}
p := CreateMachineParams{
Hostname: "host00",
runCmd: stub.Run,
disks: []libvirt.DiskInfo{
diskInfo{
source: "/path-ds",
driver: "raw"},
diskInfo{
source: "/path",
driver: "qcow2"},
},
}
got, err := writeDomainXML(d, p)
c.Assert(err, jc.ErrorIsNil)
c.Assert(got, gc.Matches, `/tmp/check-.*/\d+/host00.xml`)
}
func (libvirtInternalSuite) TestWriteDomainXMLMissingValidSystemDisk(c *gc.C) {
d := c.MkDir()
stub := &runStub{}
p := CreateMachineParams{
Hostname: "host00",
runCmd: stub.Run,
disks: []libvirt.DiskInfo{
diskInfo{
source: "/path-ds",
driver: "raw"},
diskInfo{
source: "/path",
driver: "raw"},
},
}
got, err := writeDomainXML(d, p)
c.Assert(err, gc.ErrorMatches, "missing system disk")
c.Assert(got, gc.Matches, "")
}
func (libvirtInternalSuite) TestWriteDomainXMLMissingOneDisk(c *gc.C) {
d := c.MkDir()
stub := &runStub{}
p := CreateMachineParams{
Hostname: "host00",
runCmd: stub.Run,
disks: []libvirt.DiskInfo{
diskInfo{
source: "/path-ds",
driver: "raw"},
},
}
got, err := writeDomainXML(d, p)
c.Assert(err, gc.ErrorMatches, "got 1 disks, need at least 2")
c.Assert(got, gc.Matches, "")
}
func (libvirtInternalSuite) TestWriteDomainXMLMissingBothDisk(c *gc.C) {
d := c.MkDir()
stub := &runStub{}
p := CreateMachineParams{
Hostname: "host00",
runCmd: stub.Run,
disks: []libvirt.DiskInfo{},
}
got, err := writeDomainXML(d, p)
c.Assert(err, gc.ErrorMatches, "got 0 disks, need at least 2")
c.Assert(got, gc.Matches, "")
}
func (libvirtInternalSuite) TestWriteDomainXMLNoHostname(c *gc.C) {
d := c.MkDir()
stub := &runStub{}
p := CreateMachineParams{
runCmd: stub.Run,
disks: []libvirt.DiskInfo{
diskInfo{
source: "/path-ds",
driver: "raw"},
diskInfo{
source: "/path",
driver: "qcow"},
},
}
got, err := writeDomainXML(d, p)
c.Assert(err, gc.ErrorMatches, "missing required hostname")
c.Assert(got, gc.Matches, "")
}
func (libvirtInternalSuite) TestPoolInfoSuccess(c *gc.C) {
output := `
Name: juju-pool
UUID: 06ebee2d-6bd0-4f47-a7dc-dea555fdaa3b
State: running
Persistent: yes
Autostart: yes
Capacity: 35.31 GiB
Allocation: 3.54 GiB
Available: 31.77 GiB
`
stub := runStub{output: output}
got, err := poolInfo(stub.Run)
c.Check(err, jc.ErrorIsNil)
c.Assert(got, jc.DeepEquals, &libvirtPool{Name: "juju-pool", Autostart: "yes", State: "running"})
}
func (libvirtInternalSuite) TestPoolInfoNoPool(c *gc.C) {
stub := runStub{err: errors.New("boom")}
got, err := poolInfo(stub.Run)
c.Assert(err, jc.ErrorIsNil)
c.Assert(got, gc.IsNil)
}