Skip to content

Commit 44bb6dd

Browse files
author
Chris Townsend
committed
[tests] Add testing for LXD backend driver
1 parent f2ef259 commit 44bb6dd

File tree

4 files changed

+540
-0
lines changed

4 files changed

+540
-0
lines changed

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,5 @@ target_include_directories(multipass_tests
145145
)
146146
add_subdirectory(linux)
147147
add_subdirectory(qemu)
148+
add_subdirectory(lxd)
148149
include(libvirt/CMakeLists.txt) # with add_subdirectory it's not possible to target_link_libraries

tests/lxd/CMakeLists.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright © 2020 Canonical Ltd.
2+
#
3+
# This program is free software: you can redistribute it and/or modify
4+
# it under the terms of the GNU General Public License version 3 as
5+
# published by the Free Software Foundation.
6+
#
7+
# This program is distributed in the hope that it will be useful,
8+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
9+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+
# GNU General Public License for more details.
11+
#
12+
# You should have received a copy of the GNU General Public License
13+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
14+
#
15+
16+
target_sources(multipass_tests
17+
PRIVATE
18+
${CMAKE_CURRENT_LIST_DIR}/test_lxd_backend.cpp)
Lines changed: 325 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,325 @@
1+
/*
2+
* Copyright (C) 2020 Canonical, Ltd.
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; version 3.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* GNU General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU General Public License
14+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
15+
*
16+
*/
17+
18+
#ifndef MULTIPASS_MOCK_LXD_SERVER_RESPONSES_H
19+
#define MULTIPASS_MOCK_LXD_SERVER_RESPONSES_H
20+
21+
#include <QByteArray>
22+
23+
namespace multipass
24+
{
25+
namespace test
26+
{
27+
const QByteArray not_found_response{"HTTP/1.1 404 Not Found\r\n"
28+
"Content-Type: application/json\r\n"
29+
"Content-Length: 55\r\n\r\n"
30+
"{\"error\": \"not found\",\"error_code\": 404,\"type\": \"error\"}"};
31+
32+
const QByteArray create_vm_response{"HTTP/1.1 202 Accepted\r\n"
33+
"Content-Type: application/json\r\n\r\n"
34+
"{"
35+
"\"type\": \"async\","
36+
"\"error\": \"\","
37+
"\"error_code\": 0,"
38+
"\"metadata\": {"
39+
" \"class\": \"task\","
40+
" \"created_at\": \"2020-05-18T15:14:21.104580212-04:00\","
41+
" \"description\": \"Creating container\","
42+
" \"err\": \"\","
43+
" \"id\": \"0020444c-2e4c-49d5-83ed-3275e3f6d005\","
44+
" \"location\": \"none\","
45+
" \"may_cancel\": false,"
46+
" \"metadata\": null,"
47+
" \"resources\": {"
48+
" \"containers\": ["
49+
" \"/1.0/containers/pied-piper-valley\""
50+
" ],"
51+
" \"instances\": ["
52+
" \"/1.0/instances/pied-piper-valley\""
53+
" ]"
54+
" },"
55+
" \"status\": \"Running\","
56+
" \"status_code\": 103,"
57+
" \"updated_at\": \"2020-05-18T15:14:21.104580212-04:00\""
58+
" },"
59+
"\"operation\": \"/1.0/operations/0020444c-2e4c-49d5-83ed-3275e3f6d005\","
60+
"\"status\": \"Operation created\","
61+
"\"status_code\": 100,"
62+
"\"type\": \"async\""
63+
"}\n"};
64+
65+
const QByteArray vm_created_response{
66+
"HTTP/1.1 200 OK\r\n"
67+
"Content-Type: application/json\r\n\r\n"
68+
"{"
69+
"\"error\": \"\","
70+
"\"error_code\": 0,"
71+
"\"metadata\": {"
72+
" \"architecture\": \"x86_64\","
73+
" \"config\": {"
74+
" \"image.architecture\": \"amd64\","
75+
" \"image.description\": \"ubuntu 18.04 LTS amd64 (release) (20200506)\","
76+
" \"image.label\": \"release\","
77+
" \"image.os\": \"ubuntu\","
78+
" \"image.release\": \"bionic\","
79+
" \"image.serial\": \"20200506\","
80+
" \"image.type\": \"disk1.img\","
81+
" \"image.version\": \"18.04\","
82+
" \"limits.cpu\": \"2\","
83+
" \"limits.memory\": \"3221225472\","
84+
" \"volatile.apply_template\": \"create\","
85+
" \"volatile.base_image\": \"016b05541bc82306d971e04c53fe4a7979f99c3d87220516c798ffa3544de347\","
86+
" \"volatile.eth0.hwaddr\": \"00:16:3e:b0:c5:f4\""
87+
" },"
88+
" \"created_at\": \"2020-05-13T15:31:46.194594923-04:00\","
89+
" \"description\": \"\","
90+
" \"devices\": {"
91+
" \"config\": {"
92+
" \"source\": \"cloud-init:config\","
93+
" \"type\": \"disk\""
94+
" },"
95+
" \"root\": {"
96+
" \"path\": \"/\","
97+
" \"pool\": \"default\","
98+
" \"size\": \"16106127360\","
99+
" \"type\": \"disk\""
100+
" }"
101+
" },"
102+
" \"ephemeral\": false,"
103+
" \"expanded_config\": {"
104+
" \"image.architecture\": \"amd64\","
105+
" \"image.description\": \"ubuntu 18.04 LTS amd64 (release) (20200506)\","
106+
" \"image.label\": \"release\","
107+
" \"image.os\": \"ubuntu\","
108+
" \"image.release\": \"bionic\","
109+
" \"image.serial\": \"20200506\","
110+
" \"image.type\": \"disk1.img\","
111+
" \"image.version\": \"18.04\","
112+
" \"limits.cpu\": \"2\","
113+
" \"limits.memory\": \"3221225472\","
114+
" \"volatile.apply_template\": \"create\","
115+
" \"volatile.base_image\": \"016b05541bc82306d971e04c53fe4a7979f99c3d87220516c798ffa3544de347\","
116+
" \"volatile.eth0.hwaddr\": \"00:16:3e:b0:c5:f4\""
117+
" },"
118+
" \"expanded_devices\": {"
119+
" \"config\": {"
120+
" \"source\": \"cloud-init:config\","
121+
" \"type\": \"disk\""
122+
" },"
123+
" \"eth0\": {"
124+
" \"name\": \"eth0\","
125+
" \"nictype\": \"bridged\","
126+
" \"parent\": \"lxdbr0\","
127+
" \"type\": \"nic\""
128+
" },"
129+
" \"root\": {"
130+
" \"path\": \"/\","
131+
" \"pool\": \"default\","
132+
" \"size\": \"16106127360\","
133+
" \"type\": \"disk\""
134+
" }"
135+
" },"
136+
" \"last_used_at\": \"2020-05-13T15:34:22.934800001-04:00\","
137+
" \"location\": \"none\","
138+
" \"name\": \"pied-piper-valley\","
139+
" \"profiles\": ["
140+
" \"default\""
141+
" ],"
142+
" \"stateful\": false,"
143+
" \"status\": \"Stopped\","
144+
" \"status_code\": 102,"
145+
" \"type\": \"virtual-machine\""
146+
" },"
147+
" \"operation\": \"\","
148+
" \"status\": \"Success\","
149+
" \"status_code\": 200,"
150+
" \"type\": \"sync\""
151+
"}\n"};
152+
153+
const QByteArray start_vm_response{"HTTP/1.1 202 Accepted\r\n"
154+
"Content-Type: application/json\r\n\r\n"
155+
"{"
156+
"\"error\": \"\","
157+
"\"error_code\": 0,"
158+
"\"metadata\": {"
159+
" \"class\": \"task\","
160+
" \"created_at\": \"2020-05-19T11:17:20.979902453-04:00\","
161+
" \"description\": \"Starting container\","
162+
" \"err\": \"\","
163+
" \"id\": \"b043d632-5c48-44b3-983c-a25660d61164\","
164+
" \"location\": \"none\","
165+
" \"may_cancel\": false,"
166+
" \"metadata\": null,"
167+
" \"resources\": {"
168+
" \"containers\": ["
169+
" \"/1.0/containers/pied-piper-valley\""
170+
" ]"
171+
" },"
172+
" \"status\": \"Running\","
173+
" \"status_code\": 103,"
174+
" \"updated_at\": \"2020-05-19T11:17:20.979902453-04:00\""
175+
" },"
176+
"\"operation\": \"/1.0/operations/b043d632-5c48-44b3-983c-a25660d61164\","
177+
"\"status\": \"Operation created\","
178+
"\"status_code\": 100,"
179+
"\"type\": \"async\""
180+
"}\n"};
181+
182+
const QByteArray stop_vm_response{"HTTP/1.1 202 Accepted\r\n"
183+
"Content-Type: application/json\r\n\r\n"
184+
"{"
185+
"\"error\": \"\","
186+
"\"error_code\": 0,"
187+
"\"metadata\": {"
188+
" \"class\": \"task\","
189+
" \"created_at\": \"2020-05-19T11:17:20.979902453-04:00\","
190+
" \"description\": \"Stopping container\","
191+
" \"err\": \"\","
192+
" \"id\": \"b043d632-5c48-44b3-983c-a25660d61164\","
193+
" \"location\": \"none\","
194+
" \"may_cancel\": false,"
195+
" \"metadata\": null,"
196+
" \"resources\": {"
197+
" \"containers\": ["
198+
" \"/1.0/containers/pied-piper-valley\""
199+
" ]"
200+
" },"
201+
" \"status\": \"Running\","
202+
" \"status_code\": 103,"
203+
" \"updated_at\": \"2020-05-19T11:17:20.979902453-04:00\""
204+
" },"
205+
"\"operation\": \"/1.0/operations/b043d632-5c48-44b3-983c-a25660d61164\","
206+
"\"status\": \"Operation created\","
207+
"\"status_code\": 100,"
208+
"\"type\": \"async\""
209+
"}\n"};
210+
211+
const QByteArray vm_state_stopped_response{"HTTP/1.1 200 OK\r\n"
212+
"Content-Type: application/json\r\n\r\n"
213+
"{"
214+
"\"error\": \"\","
215+
"\"error_code\": 0,"
216+
"\"metadata\": {"
217+
" \"cpu\": {"
218+
" \"usage\": 0"
219+
" },"
220+
" \"disk\": null,"
221+
" \"memory\": {"
222+
" \"swap_usage\": 0,"
223+
" \"swap_usage_peak\": 0,"
224+
" \"usage\": 0,"
225+
" \"usage_peak\": 0"
226+
" },"
227+
" \"network\": null,"
228+
" \"pid\": 0,"
229+
" \"processes\": 0,"
230+
" \"status\": \"Stopped\","
231+
" \"status_code\": 102"
232+
" },"
233+
"\"operation\": \"\","
234+
"\"status\": \"Success\","
235+
"\"status_code\": 200,"
236+
"\"type\": \"sync\""
237+
"}\n"};
238+
239+
const QByteArray vm_state_fully_running_response{"HTTP/1.1 200 OK\r\n"
240+
"Content-Type: application/json\r\n\r\n"
241+
"{"
242+
"\"error\": \"\","
243+
"\"error_code\": 0,"
244+
"\"metadata\": {"
245+
" \"cpu\": {"
246+
" \"usage\": 0"
247+
" },"
248+
" \"disk\": {"
249+
" \"root\": {"
250+
" \"usage\": 100352"
251+
" }"
252+
" },"
253+
" \"memory\": {"
254+
" \"swap_usage\": 0,"
255+
" \"swap_usage_peak\": 0,"
256+
" \"usage\": 0,"
257+
" \"usage_peak\": 0"
258+
" },"
259+
" \"network\": {"
260+
" \"eth0\": {"
261+
" \"addresses\": ["
262+
" {"
263+
" \"address\": \"10.217.27.168\","
264+
" \"family\": \"inet\","
265+
" \"netmask\": \"24\","
266+
" \"scope\": \"global\""
267+
" }"
268+
" ],"
269+
" \"counters\": {"
270+
" \"bytes_received\": 0,"
271+
" \"bytes_sent\": 0,"
272+
" \"packets_received\": 0,"
273+
" \"packets_sent\": 0"
274+
" },"
275+
" \"host_name\": \"tape3019389\","
276+
" \"hwaddr\": \"00:16:3e:13:36:01\","
277+
" \"mtu\": 1500,"
278+
" \"state\": \"up\","
279+
" \"type\": \"broadcast\""
280+
" }"
281+
" },"
282+
" \"pid\": 1266500,"
283+
" \"processes\": -1,"
284+
" \"status\": \"Running\","
285+
" \"status_code\": 103"
286+
" },"
287+
"\"operation\": \"\","
288+
"\"status\": \"Success\","
289+
"\"status_code\": 200,"
290+
"\"type\": \"sync\""
291+
"}\n"};
292+
293+
QByteArray vm_stop_wait_task_response{"HTTP/1.1 200 OK\r\n"
294+
"Content-Type: application/json\r\n\r\n"
295+
"{"
296+
"\"error\": \"\","
297+
"\"error_code\": 0,"
298+
"\"metadata\": {"
299+
" \"class\": \"task\","
300+
" \"created_at\": \"2020-05-20T10:22:02.684673072-04:00\","
301+
" \"description\": \"Stopping container\","
302+
" \"err\": \"\","
303+
" \"id\": \"b043d632-5c48-44b3-983c-a25660d61164\","
304+
" \"location\": \"none\","
305+
" \"may_cancel\": false,"
306+
" \"metadata\": null,"
307+
" \"resources\": {"
308+
" \"containers\": ["
309+
" \"/1.0/containers/pied-piper-valley\""
310+
" ]"
311+
" },"
312+
" \"status\": \"Success\","
313+
" \"status_code\": 200,"
314+
" \"updated_at\": \"2020-05-20T10:22:02.684673072-04:00\""
315+
" },"
316+
"\"operation\": \"\","
317+
"\"status\": \"Success\","
318+
"\"status_code\": 200,"
319+
"\"type\": \"sync\""
320+
"}\n"};
321+
322+
} // namespace test
323+
} // namespace multipass
324+
325+
#endif // MULTIPASS_MOCK_LXD_SERVER_RESPONSES_H

0 commit comments

Comments
 (0)