can sync file!

integration test works
This commit is contained in:
bj
2021-01-31 10:44:14 +02:00
parent 0af5811c96
commit afb1a2f7bd
9 changed files with 111 additions and 17 deletions
+10
View File
@@ -47,6 +47,12 @@ class Program:
self.my_device_id = self.syncthing.get_my_device_id()
print("Found My Device ID: {0}".format(self.my_device_id))
self.syncthing.patch_config()
self.syncthing.create_shared_folder("GXWxf-3zgnU", "SharedFolder", "/data", [{'id': self.my_device_id}])
if not self.syncthing.config_is_in_sync():
self.syncthing.restart()
self.etcd.register_device_update_handler(self.update_devices)
self.etcd.add_device_to_cluster(self.my_device_id, self.syncthing_public_host)
@@ -62,8 +68,12 @@ class Program:
def update_devices(self, event):
device_list = self.etcd.get_device_list()
self.syncthing.add_devices(device_list)
self.syncthing.create_shared_folder("GXWxf-3zgnU", "SharedFolder", "/data", device_list)
self.syncthing.print_config()
if not self.syncthing.config_is_in_sync():
self.syncthing.restart()
if __name__ == "__main__":
main()
+77
View File
@@ -48,10 +48,87 @@ class SyncthingClient:
print("Attempt to add device {0} to syncthing: {1}".format(device, response.content))
def create_shared_folder(self, folder_id, label, path, devices):
post_data = {
"id": folder_id,
"label": label,
"filesystemType": "basic",
"path": path,
"type": "sendreceive",
"devices": [],
"rescanIntervalS": 60,
"fsWatcherEnabled": False,
"fsWatcherDelayS": 10,
"ignorePerms": False,
"autoNormalize": False,
"minDiskFree": {
"value": 1,
"unit": "%"
},
"versioning": {
"type": "simple",
"params": {
"keep": "5"
}
},
"copiers": 0,
"pullerMaxPendingKiB": 0,
"hashers": 0,
"order": "random",
"ignoreDelete": False,
"scanProgressIntervalS": 0,
"pullerPauseS": 0,
"maxConflicts": 10,
"disableSparseFiles": False,
"disableTempIndexes": False,
"paused": False,
"weakHashThresholdPct": 25,
"markerName": ".stfolder",
"copyOwnershipFromParent": False,
"modTimeWindowS": 0
}
for device in devices:
folder_device = {
'deviceID': device['id'],
'introducedBy': ''
}
post_data['devices'].append(folder_device)
response = requests.post(self.make_url("/rest/config/folders"),
headers=self.headers, data=json.dumps(post_data))
print("Attempt to add shared folder to syncthing: {0}".format(response.content))
@retry
def print_config(self):
response = requests.get(self.make_url("/rest/config/devices"), headers=self.headers)
print("/rest/config/devices: {0}".format(response.content))
response = requests.get(self.make_url("/rest/config/folders"), headers=self.headers)
print("/rest/config/folders: {0}".format(response.content))
response = requests.get(self.make_url("/rest/config/options"), headers=self.headers)
print("/rest/config/options: {0}".format(response.content))
def config_is_in_sync(self):
response = requests.get(self.make_url("/rest/config/insync"), headers=self.headers)
return bool(json.loads(response.content)['configInSync'])
def restart(self):
response = requests.post(self.make_url("/rest/system/restart"), headers=self.headers, data='')
print("System reset: {0}".format(response.content))
@retry
def patch_config(self):
config_patch = {
"globalAnnounceEnabled": False,
"localAnnounceEnabled": False,
"relaysEnabled": False,
"announceLANAddresses": False,
}
response = requests.patch(self.make_url("/rest/config/options"),
headers=self.headers, data=json.dumps(config_patch))
print("Patched syncthing configuration: {0}".format(response.content))
def make_url(self, endpoint):
return "http://{0}:{1}{2}".format(self.host, self.port, endpoint)