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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
|
"""
Fake responses for the Docker API
Adapted from https://github.com/docker/docker-py/blob/master/tests/unit/fake_api.py
"""
from typing import Any, Generator
FAKE_CONTAINER_ID = "3cc2351ab11b"
FAKE_LONG_ID = "e75ccd38cba33f61b09515e05f56fc243ef40186d600a9eeb6bc0bed8e2e1508"
FAKE_LOG_LINE_CONTENT = b"fake log"
FAKE_LOG_LINE_COUNT = 10
FAKE_IMAGE_ID = "sha256:e9aa60c60128"
FAKE_TAG = "sha256:e9aafierojv"
FAKE_CONTAINER_NAME = "jolly_black"
FAKE_LOGS_MESSAGE = 'Hello World\nThis is test logs'
def get_fake_containers() -> tuple[int, list[dict[str, str]]]:
"""Get list of fake containers"""
status_code = 200
response = [{
"Id": FAKE_CONTAINER_ID,
"Image": "busybox:latest",
"Created": "2 days ago",
"Command": "true",
"Status": "fake status"
}]
return status_code, response
def get_fake_inspect_container() -> tuple[int, dict[str, Any]]:
"""Get fake inspect data"""
status_code = 200
response = {
"Id": FAKE_CONTAINER_ID,
"Created": "2021-09-28T14:16:51.246200393Z",
"Path": "/docker-entrypoint.sh",
"Args": [
"apache2-foreground"
],
"State": {
"Status": "running",
"Running": True,
"Paused": False,
"Restarting": False,
"OOMKilled": False,
"Dead": False,
"Pid": 85110,
"ExitCode": 0,
"Error": "",
"StartedAt": "2021-09-28T14:16:51.540023895Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
"Image": FAKE_IMAGE_ID,
"Name": f"/{FAKE_CONTAINER_NAME}",
"RestartCount": 0,
"Driver": "overlay2",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "docker-default",
"ExecIDs": None,
"HostConfig": {
"Binds": None,
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "default",
"PortBindings": {
"80/tcp": [
{
"HostIp": "",
"HostPort": "8088"
}
]
},
"RestartPolicy": {
"Name": "no",
"MaximumRetryCount": 0
},
"AutoRemove": False,
"VolumeDriver": "",
"VolumesFrom": None,
"CapAdd": None,
"CapDrop": None,
"CgroupnsMode": "host",
"Dns": [],
"DnsOptions": [],
"DnsSearch": [],
"ExtraHosts": None,
"GroupAdd": None,
"IpcMode": "private",
"Cgroup": "",
"Links": None,
"OomScoreAdj": 0,
"PidMode": "",
"Privileged": False,
"PublishAllPorts": False,
"ReadonlyRootfs": False,
"SecurityOpt": None,
"UTSMode": "",
"UsernsMode": "",
"ShmSize": 67108864,
"Runtime": "runc",
"ConsoleSize": [
0,
0
],
"Isolation": "",
"CpuShares": 0,
"Memory": 0,
"NanoCpus": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": [],
"BlkioDeviceReadBps": None,
"BlkioDeviceWriteBps": None,
"BlkioDeviceReadIOps": None,
"BlkioDeviceWriteIOps": None,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": [],
"DeviceCgroupRules": None,
"DeviceRequests": None,
"KernelMemory": 0,
"KernelMemoryTCP": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": None,
"OomKillDisable": False,
"PidsLimit": None,
"Ulimits": None,
"CpuCount": 0,
"CpuPercent": 0,
"IOMaximumIOps": 0,
"IOMaximumBandwidth": 0,
"MaskedPaths": [
"/proc/asound",
"/proc/acpi",
"/proc/kcore",
"/proc/keys",
"/proc/latency_stats",
"/proc/timer_list",
"/proc/timer_stats",
"/proc/sched_debug",
"/proc/scsi",
"/sys/firmware"
],
"ReadonlyPaths": [
"/proc/bus",
"/proc/fs",
"/proc/irq",
"/proc/sys",
"/proc/sysrq-trigger"
]
},
"Mounts": [],
"Config": {
"Hostname": "03bfd76552c2",
"Domainname": "",
"User": "",
"AttachStdin": True,
"AttachStdout": True,
"AttachStderr": True,
"ExposedPorts": {
"80/tcp": {}
},
"Tty": True,
"OpenStdin": True,
"StdinOnce": True,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"PHP_INI_DIR=/usr/local/etc/php",
],
"Cmd": [
"apache2-foreground"
],
"Image": "phpmyadmin:latest",
"Volumes": None,
"WorkingDir": "/var/www/html",
"Entrypoint": [
"/docker-entrypoint.sh"
],
"OnBuild": None,
"StopSignal": "SIGWINCH"
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "c5cec0eaeadea649b43ea0fb6cec5b60cb3c7b1b06813a1f07e6b7f4e2cb180e",
"HairpinMode": False,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"80/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "8088"
},
{
"HostIp": "::",
"HostPort": "8088"
}
]
},
"SandboxKey": "/var/run/docker/netns/c5cec0eaeade",
"SecondaryIPAddresses": None,
"SecondaryIPv6Addresses": None,
"EndpointID": "0ec86c835121720138dad365e7ad4c5520882801494a971932194f1dd3baee8b",
"Gateway": "172.17.0.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"MacAddress": "02:42:ac:11:00:02",
"Networks": {
"bridge": {
"IPAMConfig": None,
"Links": None,
"Aliases": None,
"NetworkID": FAKE_LONG_ID,
"EndpointID": FAKE_LONG_ID,
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:02",
"DriverOpts": None
}
}
}
}
return status_code, response
def get_fake_inspect_image() -> tuple[int, dict[str, Any]]:
"Fake inspect image"
status_code = 200
response = {
'Id': FAKE_IMAGE_ID,
'Parent': "27cf784147099545",
'Created': "2013-03-23T22:24:18.818426-07:00",
'Container': FAKE_CONTAINER_ID,
'Config': {'Labels': {'bar': 'foo'}},
'ContainerConfig':
{
"Hostname": "",
"User": "",
"Memory": 0,
"MemorySwap": 0,
"AttachStdin": False,
"AttachStdout": False,
"AttachStderr": False,
"PortSpecs": "",
"Tty": True,
"OpenStdin": True,
"StdinOnce": False,
"Env": "",
"Cmd": ["/bin/bash"],
"Dns": "",
"Image": "base",
"Volumes": "",
"VolumesFrom": "",
"WorkingDir": ""
},
'Size': 6823592
}
return status_code, response
def get_fake_images() -> tuple[int, list[dict[str, Any]]]:
"Fake list images"
status_code = 200
response = [{
'Id': FAKE_IMAGE_ID,
'Created': '2 days ago',
'Repository': 'busybox',
'RepoTags': ['busybox:latest', 'busybox:1.0'],
}]
return status_code, response
def get_fake_prune_containers() -> tuple[int, dict[str, Any]]:
"""Get fake prune containers response"""
status_code = 200
response = {
"ContainersDeleted": [FAKE_LONG_ID],
"SpaceReclaimed": 123
}
return status_code, response
def get_fake_prune_images() -> tuple[int, dict[str, Any]]:
"""Get fake prune images response"""
status_code = 200
response = {
"ImagesDeleted": [FAKE_LONG_ID],
"SpaceReclaimed": 123
}
return status_code, response
def get_fake_prune_volumes() -> tuple[int, dict[str, Any]]:
"""Get fake prune volumes response"""
status_code = 200
response = {
"VolumesDeleted": [FAKE_LONG_ID],
"SpaceReclaimed": 123
}
return status_code, response
def get_fake_prune_networks() -> tuple[int, dict[str, Any]]:
"""Get fake prune networks response"""
status_code = 200
response = {
"NetworksDeleted": [FAKE_LONG_ID]
}
return status_code, response
def get_fake_prune_builds() -> tuple[int, dict[str, Any]]:
"""Get fake prune build caches response"""
status_code = 200
response = {
"CachesDeleted": [FAKE_LONG_ID],
"SpaceReclaimed": 123
}
return status_code, response
def _get_log_stream() -> Generator[bytes, None, None]:
for _ in range(FAKE_LOG_LINE_COUNT):
yield FAKE_LOG_LINE_CONTENT
def get_fake_logs() -> tuple[int, Generator[bytes, None, None]]:
"""Get fake container logs"""
status_code = 200
return status_code, _get_log_stream()
def get_fake_logs_response() -> tuple[int, bytes]:
"""Get fake logs response"""
status_code = 200
response = (bytes(FAKE_LOGS_MESSAGE, 'ascii'))
return status_code, response
|