forked from vmware/govmomi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
guest.bats
executable file
·183 lines (126 loc) · 3.54 KB
/
guest.bats
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/usr/bin/env bats
load test_helper
vcsim_guest() {
require_docker
vcsim_env -autostart=false
vm=DC0_H0_VM0
name=$(docker_name $vm)
if docker inspect "$name" ; then
flunk "$vm container still exists"
fi
export GOVC_VM=$vm GOVC_GUEST_LOGIN=user:pass
run govc object.collect -s vm/$vm guest.toolsStatus
assert_success toolsNotInstalled
run govc object.collect -s vm/$vm guest.toolsRunningStatus
assert_success guestToolsNotRunning
govc vm.change -vm $vm -e "RUN.container=--tmpfs /tmp nginx"
govc vm.power -on $vm
if ! docker inspect "$name" ; then
flunk "$vm container does not exist"
fi
run govc object.collect -s vm/$vm guest.toolsStatus
assert_success toolsOk
run govc object.collect -s vm/$vm guest.toolsRunningStatus
assert_success guestToolsRunning
}
@test "guest file manager" {
vcsim_guest
run govc guest.mkdir /tmp/foo
assert_success
run govc guest.mkdir /tmp/foo/bar/baz
assert_failure
run govc guest.mkdir -p /tmp/foo/bar/baz
assert_success
run govc guest.rmdir /tmp/foo
assert_failure # not empty
run govc guest.rmdir -r /tmp/foo
assert_success
run govc guest.mktemp -d
assert_success
tmp="$output"
run govc guest.rmdir "$tmp"
assert_success
run govc guest.rmdir "$tmp"
assert_failure # does not exist
run govc guest.mktemp
assert_success
tmp="$output"
run govc guest.ls
assert_failure # InvalidArgument
run govc guest.ls /enoent
assert_failure # InvalidArgument
run govc guest.ls "$tmp"
assert_success
assert_matches "$tmp"
assert_matches "rw-------" # 0600
run govc guest.chmod 0644 "$tmp"
assert_success
run govc guest.chown 0:0 "$tmp"
assert_success
run govc guest.ls "$tmp"
assert_success
assert_matches "$tmp"
assert_matches "rw-r--r--" # 0644
run govc guest.ls "$(dirname "$tmp")"
assert_success
assert_matches "$tmp"
run govc guest.mv "$tmp" "$tmp-new"
assert_success
run govc guest.ls "$tmp"
assert_failure
run govc guest.ls "$tmp-new"
assert_success
run govc guest.upload -l '' README.md "$tmp"
assert_failure # unauthenticated
run govc guest.upload README.md "$tmp"
assert_success
run govc guest.download "$tmp" -
assert_success "$(cat README.md)"
run govc guest.rmdir "$tmp"
assert_failure # not a directory
run govc guest.rm "$tmp"
assert_success
run govc guest.rm "$tmp"
assert_failure # does not exist
}
@test "guest process manager" {
vcsim_guest
run govc guest.kill -p 123456
assert_failure # process does not exist
run govc guest.start -l '' /bin/df
assert_failure # unauthenticated
run govc guest.start /bin/df -h
assert_success
pid="$output"
run govc guest.ps -p "$pid"
assert_success
assert_matches /bin/df
run govc guest.ps -x
assert_success
run govc guest.kill -p "$pid"
assert_success
run govc guest.run uname -a
assert_success
assert_matches Linux
run govc guest.run -e FOO=bar -C /tmp env
assert_success
assert_matches FOO=bar
assert_matches PWD=/tmp
}
@test "guest tools status" {
vcsim_guest
run govc vm.power -r $GOVC_VM
assert_success
run govc object.collect -s vm/$vm guest.toolsStatus
assert_success toolsOk
run govc object.collect -s vm/$vm guest.toolsRunningStatus
assert_success guestToolsRunning
run govc vm.power -off $GOVC_VM
assert_success
run govc object.collect -s vm/$vm guest.toolsStatus
assert_success toolsNotRunning
run govc object.collect -s vm/$vm guest.toolsRunningStatus
assert_success guestToolsNotRunning
run govc guest.run uname -a
assert_failure # powered off
}