can sync file!
integration test works
This commit is contained in:
		
							parent
							
								
									0af5811c96
								
							
						
					
					
						commit
						afb1a2f7bd
					
				
							
								
								
									
										4
									
								
								.env
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								.env
									
									
									
									
									
								
							|  | @ -1,4 +1,4 @@ | |||
| SYNCTHING_VERSION=latest | ||||
| PUID=1001 | ||||
| PGID=1001 | ||||
| PUID=0 | ||||
| PGID=0 | ||||
| TZ=Europe/London | ||||
|  |  | |||
|  | @ -17,9 +17,9 @@ services: | |||
|     build: . | ||||
|     links: | ||||
|       - sync1:sync | ||||
|       - etcd | ||||
|     volumes: | ||||
|       - sync1config:/config | ||||
|       - etcd | ||||
|     environment: | ||||
|       - SYNCTHING_PUBLIC_HOST=sync1 | ||||
|     networks: | ||||
|  |  | |||
							
								
								
									
										3
									
								
								integration-test.bat
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								integration-test.bat
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,3 @@ | |||
| docker-compose -f docker-compose.test.yml -p ci down -v | ||||
| docker-compose -f docker-compose.test.yml -p ci up --build --force-recreate -d | ||||
| docker wait ci_test_1 | ||||
							
								
								
									
										5
									
								
								integration-test.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								integration-test.sh
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,5 @@ | |||
| #!/usr/bin/env bash | ||||
| 
 | ||||
| docker-compose -f docker-compose.test.yml -p ci down -v | ||||
| docker-compose -f docker-compose.test.yml -p ci up --build --force-recreate -d | ||||
| docker wait ci_test_1 | ||||
|  | @ -4,6 +4,8 @@ RUN apt-get update && apt-get install -yq curl && apt-get clean | |||
| 
 | ||||
| WORKDIR /app | ||||
| 
 | ||||
| ADD test.sh /app/test.sh | ||||
| ADD test_file_sync.sh /app/test_file_sync.sh | ||||
| 
 | ||||
| CMD ["bash", "test.sh"] | ||||
| VOLUME [ "/data1", "/data2" ] | ||||
| 
 | ||||
| CMD ["bash", "test_file_sync.sh"] | ||||
|  |  | |||
|  | @ -1,12 +0,0 @@ | |||
| sleep 5 | ||||
| echo "test string" > /sync1/testfile | ||||
| echo /sync1/testfile | ||||
| echo /sync2/testfile | ||||
| 
 | ||||
| #if curl web | grep -q '<b>Visits:</b> '; then | ||||
| #  echo "Tests passed!" | ||||
| #  exit 0 | ||||
| #else | ||||
| #  echo "Tests failed!" | ||||
| #  exit 1 | ||||
| #fi | ||||
							
								
								
									
										9
									
								
								integrationtest/test_file_sync.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								integrationtest/test_file_sync.sh
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,9 @@ | |||
| TEST_TEXT="test string" | ||||
| 
 | ||||
| echo "${TEST_TEXT}" > /data1/testfile | ||||
| 
 | ||||
| # shellcheck disable=SC2034 | ||||
| for i in $(seq 1 30); do | ||||
|   [ "${TEST_TEXT}" == "$(cat /data2/testfile)" ] && s=0 && break || s=$? && sleep 2 | ||||
| done | ||||
| (exit $s) | ||||
|  | @ -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() | ||||
|  |  | |||
|  | @ -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) | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user