mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 14:01:15 +02:00
Restore images & projects tarballs
This commit is contained in:
1 parent
270017d945
commit
fc14deee1b
5 files changed
+118
-22
No files matched your search
@@ -51,6 +51,74 @@ def test_upload(server, tmpdir):
|
||||
assert "test2" in response.body.decode("utf-8")
|
||||
|
||||
|
||||
def test_upload_images_backup(server, tmpdir):
|
||||
Config.instance().set("Server", "images_path", str(tmpdir / 'images'))
|
||||
os.makedirs(str(tmpdir / 'images' / 'IOU'))
|
||||
# An old IOU image that we need to replace
|
||||
with open(str(tmpdir / 'images' / 'IOU' / 'b.img'), 'w+') as f:
|
||||
f.write('bad')
|
||||
|
||||
os.makedirs(str(tmpdir / 'old' / 'QEMU'))
|
||||
with open(str(tmpdir / 'old' / 'QEMU' / 'a.img'), 'w+') as f:
|
||||
f.write('hello')
|
||||
os.makedirs(str(tmpdir / 'old' / 'IOU'))
|
||||
with open(str(tmpdir / 'old' / 'IOU' / 'b.img'), 'w+') as f:
|
||||
f.write('world')
|
||||
|
||||
os.chdir(str(tmpdir / 'old'))
|
||||
with tarfile.open(str(tmpdir / 'test.tar'), 'w') as tar:
|
||||
tar.add('.', recursive=True)
|
||||
|
||||
body = aiohttp.FormData()
|
||||
body.add_field('type', 'IMAGES')
|
||||
body.add_field('file', open(str(tmpdir / 'test.tar'), 'rb'), content_type='application/x-gtar', filename='test.tar')
|
||||
response = server.post('/upload', api_version=None, body=body, raw=True)
|
||||
assert response.status == 200
|
||||
|
||||
with open(str(tmpdir / 'images' / 'QEMU' / 'a.img')) as f:
|
||||
assert f.read() == 'hello'
|
||||
with open(str(tmpdir / 'images' / 'IOU' / 'b.img')) as f:
|
||||
assert f.read() == 'world'
|
||||
|
||||
assert 'a.img' in response.body.decode('utf-8')
|
||||
assert 'b.img' in response.body.decode('utf-8')
|
||||
assert not os.path.exists(str(tmpdir / 'images' / 'archive.tar'))
|
||||
|
||||
|
||||
def test_upload_projects_backup(server, tmpdir):
|
||||
Config.instance().set("Server", "projects_path", str(tmpdir / 'projects'))
|
||||
os.makedirs(str(tmpdir / 'projects' / 'b'))
|
||||
# An old b image that we need to replace
|
||||
with open(str(tmpdir / 'projects' / 'b' / 'b.img'), 'w+') as f:
|
||||
f.write('bad')
|
||||
|
||||
os.makedirs(str(tmpdir / 'old' / 'a'))
|
||||
with open(str(tmpdir / 'old' / 'a' / 'a.img'), 'w+') as f:
|
||||
f.write('hello')
|
||||
os.makedirs(str(tmpdir / 'old' / 'b'))
|
||||
with open(str(tmpdir / 'old' / 'b' / 'b.img'), 'w+') as f:
|
||||
f.write('world')
|
||||
|
||||
os.chdir(str(tmpdir / 'old'))
|
||||
with tarfile.open(str(tmpdir / 'test.tar'), 'w') as tar:
|
||||
tar.add('.', recursive=True)
|
||||
|
||||
body = aiohttp.FormData()
|
||||
body.add_field('type', 'PROJECTS')
|
||||
body.add_field('file', open(str(tmpdir / 'test.tar'), 'rb'), content_type='application/x-gtar', filename='test.tar')
|
||||
response = server.post('/upload', api_version=None, body=body, raw=True)
|
||||
assert response.status == 200
|
||||
|
||||
with open(str(tmpdir / 'projects' / 'a' / 'a.img')) as f:
|
||||
assert f.read() == 'hello'
|
||||
with open(str(tmpdir / 'projects' / 'b' / 'b.img')) as f:
|
||||
assert f.read() == 'world'
|
||||
|
||||
assert 'a.img' not in response.body.decode('utf-8')
|
||||
assert 'b.img' not in response.body.decode('utf-8')
|
||||
assert not os.path.exists(str(tmpdir / 'projects' / 'archive.tar'))
|
||||
|
||||
|
||||
def test_backup_images(server, tmpdir, loop):
|
||||
Config.instance().set('Server', 'images_path', str(tmpdir))
|
||||
|
||||
@@ -60,7 +128,7 @@ def test_backup_images(server, tmpdir, loop):
|
||||
with open(str(tmpdir / 'QEMU' / 'b.img'), 'w+') as f:
|
||||
f.write('world')
|
||||
|
||||
response = server.get('/upload/backup/images.tar', api_version=None, raw=True)
|
||||
response = server.get('/backup/images.tar', api_version=None, raw=True)
|
||||
assert response.status == 200
|
||||
assert response.headers['CONTENT-TYPE'] == 'application/x-gtar'
|
||||
|
||||
@@ -92,7 +160,7 @@ def test_backup_projects(server, tmpdir, loop):
|
||||
with open(str(tmpdir / 'b' / 'b.gns3'), 'w+') as f:
|
||||
f.write('world')
|
||||
|
||||
response = server.get('/upload/backup/projects.tar', api_version=None, raw=True)
|
||||
response = server.get('/backup/projects.tar', api_version=None, raw=True)
|
||||
assert response.status == 200
|
||||
assert response.headers['CONTENT-TYPE'] == 'application/x-gtar'
|
||||
|
||||
|
||||
Reference in new issue
Block a user