2019-04-16 00:19:20 +00:00
|
|
|
"""Generate test fixtures"""
|
2019-04-16 16:22:28 +00:00
|
|
|
from datetime import datetime
|
|
|
|
import hashlib
|
|
|
|
|
|
|
|
|
|
|
|
def generate_sha256():
|
|
|
|
"""Generate a unique sha256"""
|
|
|
|
h = hashlib.sha256()
|
|
|
|
h.update(str(datetime.now().timestamp()).encode())
|
|
|
|
return h.hexdigest()
|
2019-04-16 00:19:20 +00:00
|
|
|
|
|
|
|
|
2019-04-16 00:57:06 +00:00
|
|
|
def containers(project="default", containers=[]):
|
2019-04-16 00:19:20 +00:00
|
|
|
"""
|
|
|
|
Args:
|
|
|
|
project (str): Name of the compose project
|
|
|
|
containers (dict):
|
|
|
|
{
|
|
|
|
'containers: [
|
2019-04-16 16:22:28 +00:00
|
|
|
'id': 'something'
|
2019-04-16 00:57:06 +00:00
|
|
|
'service': 'service_name',
|
|
|
|
'mounts: [{
|
|
|
|
'Source': '/home/user/stuff',
|
|
|
|
'Destination': '/srv/stuff',
|
|
|
|
'Type': 'bind' / 'volume'
|
|
|
|
}],
|
2019-04-16 00:19:20 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
def wrapper(*args, **kwargs):
|
2019-04-16 00:57:06 +00:00
|
|
|
return [
|
|
|
|
{
|
2019-04-16 00:19:20 +00:00
|
|
|
'HostConfig': {'NetworkMode': 'restic-volume-backup_default'},
|
2019-04-16 16:22:28 +00:00
|
|
|
'Id': container.get('id', generate_sha256()),
|
2019-04-16 00:19:20 +00:00
|
|
|
'Image': 'restic-volume-backup_backup',
|
|
|
|
'ImageID': 'sha256:4d9a81206af7d65563b85d06be160dc90dc20ade94edcf544261f0e1db4472b3',
|
|
|
|
'Labels': {
|
2019-04-16 00:57:06 +00:00
|
|
|
'com.docker.compose.oneoff': 'False',
|
2019-04-16 00:19:20 +00:00
|
|
|
'com.docker.compose.project': project,
|
2019-04-16 00:57:06 +00:00
|
|
|
'com.docker.compose.service': container['service'],
|
|
|
|
**container.get('labels', {}),
|
2019-04-16 00:19:20 +00:00
|
|
|
},
|
2019-04-16 00:57:06 +00:00
|
|
|
'Mounts': container.get('mounts', []),
|
2019-04-16 00:19:20 +00:00
|
|
|
'Names': ['/restic-volume-backup_backup_run_58d1699be0d8'],
|
|
|
|
'NetworkSettings': {
|
|
|
|
'Networks': {
|
|
|
|
'restic-volume-backup_default': {
|
|
|
|
'Aliases': None,
|
|
|
|
'DriverOpts': None,
|
|
|
|
'EndpointID': '96ac233ec96ae2318a15419c4d211bbc0d130fc33baaaba6dcd8c13328ba4b8f',
|
|
|
|
'Gateway': '172.22.0.1',
|
|
|
|
'GlobalIPv6Address': '',
|
|
|
|
'GlobalIPv6PrefixLen': 0,
|
|
|
|
'IPAMConfig': None,
|
|
|
|
'IPAddress': '172.22.0.2',
|
|
|
|
'IPPrefixLen': 16,
|
|
|
|
'IPv6Gateway': '',
|
|
|
|
'Links': None,
|
|
|
|
'MacAddress': '02:42:ac:16:00:02',
|
|
|
|
'NetworkID': '98886e14fddc2b3d31d15fbbfc3ea1b339626374ba2ff6c2dad406b1617ee09c',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'State': 'running',
|
2019-04-16 00:57:06 +00:00
|
|
|
}
|
|
|
|
for container in containers]
|
2019-04-16 00:19:20 +00:00
|
|
|
|
|
|
|
return wrapper
|