| 
									
										
										
										
											2019-11-01 19:24:21 +02:00
										 |  |  | import boto3 | 
					
						
							| 
									
										
										
										
											2019-11-02 21:34:35 +02:00
										 |  |  | from botocore.exceptions import ClientError | 
					
						
							| 
									
										
										
										
											2019-11-01 19:24:21 +02:00
										 |  |  | from moto import mock_datasync | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  | import pytest | 
					
						
							| 
									
										
										
										
											2021-10-18 19:44:29 +00:00
										 |  |  | import sure  # noqa # pylint: disable=unused-import | 
					
						
							| 
									
										
										
										
											2019-11-01 19:24:21 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-02 21:34:35 +02:00
										 |  |  | def create_locations(client, create_smb=False, create_s3=False): | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     """
 | 
					
						
							| 
									
										
										
										
											2019-11-02 21:34:35 +02:00
										 |  |  |     Convenience function for creating locations. | 
					
						
							|  |  |  |     Locations must exist before tasks can be created. | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     smb_arn = None | 
					
						
							|  |  |  |     s3_arn = None | 
					
						
							|  |  |  |     if create_smb: | 
					
						
							|  |  |  |         response = client.create_location_smb( | 
					
						
							|  |  |  |             ServerHostname="host", | 
					
						
							|  |  |  |             Subdirectory="somewhere", | 
					
						
							|  |  |  |             User="", | 
					
						
							|  |  |  |             Password="", | 
					
						
							|  |  |  |             AgentArns=["stuff"], | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         smb_arn = response["LocationArn"] | 
					
						
							|  |  |  |     if create_s3: | 
					
						
							|  |  |  |         response = client.create_location_s3( | 
					
						
							|  |  |  |             S3BucketArn="arn:aws:s3:::my_bucket", | 
					
						
							|  |  |  |             Subdirectory="dir", | 
					
						
							|  |  |  |             S3Config={"BucketAccessRoleArn": "role"}, | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |         s3_arn = response["LocationArn"] | 
					
						
							|  |  |  |     return {"smb_arn": smb_arn, "s3_arn": s3_arn} | 
					
						
							| 
									
										
										
										
											2019-11-01 21:16:59 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-01 19:24:21 +02:00
										 |  |  | @mock_datasync | 
					
						
							|  |  |  | def test_create_location_smb(): | 
					
						
							|  |  |  |     client = boto3.client("datasync", region_name="us-east-1") | 
					
						
							| 
									
										
										
										
											2019-11-02 21:34:35 +02:00
										 |  |  |     response = client.create_location_smb( | 
					
						
							|  |  |  |         ServerHostname="host", | 
					
						
							|  |  |  |         Subdirectory="somewhere", | 
					
						
							|  |  |  |         User="", | 
					
						
							|  |  |  |         Password="", | 
					
						
							|  |  |  |         AgentArns=["stuff"], | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     assert "LocationArn" in response | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_datasync | 
					
						
							|  |  |  | def test_describe_location_smb(): | 
					
						
							|  |  |  |     client = boto3.client("datasync", region_name="us-east-1") | 
					
						
							|  |  |  |     agent_arns = ["stuff"] | 
					
						
							|  |  |  |     user = "user" | 
					
						
							|  |  |  |     response = client.create_location_smb( | 
					
						
							|  |  |  |         ServerHostname="host", | 
					
						
							|  |  |  |         Subdirectory="somewhere", | 
					
						
							|  |  |  |         User=user, | 
					
						
							|  |  |  |         Password="", | 
					
						
							|  |  |  |         AgentArns=agent_arns, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     response = client.describe_location_smb(LocationArn=response["LocationArn"]) | 
					
						
							|  |  |  |     assert "LocationArn" in response | 
					
						
							|  |  |  |     assert "LocationUri" in response | 
					
						
							|  |  |  |     assert response["User"] == user | 
					
						
							|  |  |  |     assert response["AgentArns"] == agent_arns | 
					
						
							| 
									
										
										
										
											2019-11-01 19:24:21 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_datasync | 
					
						
							|  |  |  | def test_create_location_s3(): | 
					
						
							|  |  |  |     client = boto3.client("datasync", region_name="us-east-1") | 
					
						
							| 
									
										
										
										
											2019-11-02 21:34:35 +02:00
										 |  |  |     response = client.create_location_s3( | 
					
						
							|  |  |  |         S3BucketArn="arn:aws:s3:::my_bucket", | 
					
						
							|  |  |  |         Subdirectory="dir", | 
					
						
							|  |  |  |         S3Config={"BucketAccessRoleArn": "role"}, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     assert "LocationArn" in response | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_datasync | 
					
						
							|  |  |  | def test_describe_location_s3(): | 
					
						
							|  |  |  |     client = boto3.client("datasync", region_name="us-east-1") | 
					
						
							|  |  |  |     s3_config = {"BucketAccessRoleArn": "role"} | 
					
						
							|  |  |  |     response = client.create_location_s3( | 
					
						
							|  |  |  |         S3BucketArn="arn:aws:s3:::my_bucket", Subdirectory="dir", S3Config=s3_config | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     response = client.describe_location_s3(LocationArn=response["LocationArn"]) | 
					
						
							|  |  |  |     assert "LocationArn" in response | 
					
						
							|  |  |  |     assert "LocationUri" in response | 
					
						
							|  |  |  |     assert response["S3Config"] == s3_config | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_datasync | 
					
						
							|  |  |  | def test_describe_location_wrong(): | 
					
						
							|  |  |  |     client = boto3.client("datasync", region_name="us-east-1") | 
					
						
							|  |  |  |     agent_arns = ["stuff"] | 
					
						
							|  |  |  |     user = "user" | 
					
						
							|  |  |  |     response = client.create_location_smb( | 
					
						
							|  |  |  |         ServerHostname="host", | 
					
						
							|  |  |  |         Subdirectory="somewhere", | 
					
						
							|  |  |  |         User=user, | 
					
						
							|  |  |  |         Password="", | 
					
						
							|  |  |  |         AgentArns=agent_arns, | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(ClientError) as e: | 
					
						
							| 
									
										
										
										
											2021-10-18 19:44:29 +00:00
										 |  |  |         client.describe_location_s3(LocationArn=response["LocationArn"]) | 
					
						
							|  |  |  |     err = e.value.response["Error"] | 
					
						
							|  |  |  |     err["Code"].should.equal("InvalidRequestException") | 
					
						
							|  |  |  |     err["Message"].should.equal("Invalid Location type: SMB") | 
					
						
							| 
									
										
										
										
											2019-11-02 21:34:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-01 19:24:21 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | @mock_datasync | 
					
						
							|  |  |  | def test_list_locations(): | 
					
						
							|  |  |  |     client = boto3.client("datasync", region_name="us-east-1") | 
					
						
							|  |  |  |     response = client.list_locations() | 
					
						
							| 
									
										
										
										
											2019-11-02 21:34:35 +02:00
										 |  |  |     assert len(response["Locations"]) == 0 | 
					
						
							| 
									
										
										
										
											2019-11-01 21:16:59 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-02 21:34:35 +02:00
										 |  |  |     create_locations(client, create_smb=True) | 
					
						
							| 
									
										
										
										
											2019-11-01 21:16:59 +02:00
										 |  |  |     response = client.list_locations() | 
					
						
							| 
									
										
										
										
											2019-11-02 21:34:35 +02:00
										 |  |  |     assert len(response["Locations"]) == 1 | 
					
						
							|  |  |  |     assert response["Locations"][0]["LocationUri"] == "smb://host/somewhere" | 
					
						
							| 
									
										
										
										
											2019-11-01 21:16:59 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-02 21:34:35 +02:00
										 |  |  |     create_locations(client, create_s3=True) | 
					
						
							|  |  |  |     response = client.list_locations() | 
					
						
							|  |  |  |     assert len(response["Locations"]) == 2 | 
					
						
							|  |  |  |     assert response["Locations"][1]["LocationUri"] == "s3://my_bucket/dir" | 
					
						
							| 
									
										
										
										
											2019-11-01 21:16:59 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-02 21:34:35 +02:00
										 |  |  |     create_locations(client, create_s3=True) | 
					
						
							| 
									
										
										
										
											2019-11-01 21:16:59 +02:00
										 |  |  |     response = client.list_locations() | 
					
						
							| 
									
										
										
										
											2019-11-02 21:34:35 +02:00
										 |  |  |     assert len(response["Locations"]) == 3 | 
					
						
							|  |  |  |     assert response["Locations"][2]["LocationUri"] == "s3://my_bucket/dir" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-01 21:16:59 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-05 12:30:05 +02:00
										 |  |  | @mock_datasync | 
					
						
							|  |  |  | def test_delete_location(): | 
					
						
							|  |  |  |     client = boto3.client("datasync", region_name="us-east-1") | 
					
						
							|  |  |  |     locations = create_locations(client, create_smb=True) | 
					
						
							|  |  |  |     response = client.list_locations() | 
					
						
							|  |  |  |     assert len(response["Locations"]) == 1 | 
					
						
							|  |  |  |     location_arn = locations["smb_arn"] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-18 19:44:29 +00:00
										 |  |  |     client.delete_location(LocationArn=location_arn) | 
					
						
							| 
									
										
										
										
											2019-11-05 12:30:05 +02:00
										 |  |  |     response = client.list_locations() | 
					
						
							|  |  |  |     assert len(response["Locations"]) == 0 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     with pytest.raises(ClientError): | 
					
						
							| 
									
										
										
										
											2021-10-18 19:44:29 +00:00
										 |  |  |         client.delete_location(LocationArn=location_arn) | 
					
						
							| 
									
										
										
										
											2019-11-05 12:30:05 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-01 21:16:59 +02:00
										 |  |  | @mock_datasync | 
					
						
							|  |  |  | def test_create_task(): | 
					
						
							|  |  |  |     client = boto3.client("datasync", region_name="us-east-1") | 
					
						
							| 
									
										
										
										
											2019-11-02 21:34:35 +02:00
										 |  |  |     locations = create_locations(client, create_smb=True, create_s3=True) | 
					
						
							| 
									
										
										
										
											2019-11-01 21:16:59 +02:00
										 |  |  |     response = client.create_task( | 
					
						
							| 
									
										
										
										
											2019-11-02 21:34:35 +02:00
										 |  |  |         SourceLocationArn=locations["smb_arn"], | 
					
						
							|  |  |  |         DestinationLocationArn=locations["s3_arn"], | 
					
						
							| 
									
										
										
										
											2019-11-01 21:16:59 +02:00
										 |  |  |     ) | 
					
						
							| 
									
										
										
										
											2019-11-02 21:34:35 +02:00
										 |  |  |     assert "TaskArn" in response | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_datasync | 
					
						
							|  |  |  | def test_create_task_fail(): | 
					
						
							| 
									
										
										
										
											2021-07-26 16:21:17 +02:00
										 |  |  |     """Test that Locations must exist before a Task can be created""" | 
					
						
							| 
									
										
										
										
											2019-11-02 21:34:35 +02:00
										 |  |  |     client = boto3.client("datasync", region_name="us-east-1") | 
					
						
							|  |  |  |     locations = create_locations(client, create_smb=True, create_s3=True) | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(ClientError) as e: | 
					
						
							| 
									
										
										
										
											2021-10-18 19:44:29 +00:00
										 |  |  |         client.create_task( | 
					
						
							| 
									
										
										
										
											2019-11-02 21:34:35 +02:00
										 |  |  |             SourceLocationArn="1", DestinationLocationArn=locations["s3_arn"] | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2021-10-18 19:44:29 +00:00
										 |  |  |     err = e.value.response["Error"] | 
					
						
							|  |  |  |     err["Code"].should.equal("InvalidRequestException") | 
					
						
							|  |  |  |     err["Message"].should.equal("Location 1 not found.") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(ClientError) as e: | 
					
						
							| 
									
										
										
										
											2021-10-18 19:44:29 +00:00
										 |  |  |         client.create_task( | 
					
						
							| 
									
										
										
										
											2019-11-02 21:34:35 +02:00
										 |  |  |             SourceLocationArn=locations["smb_arn"], DestinationLocationArn="2" | 
					
						
							|  |  |  |         ) | 
					
						
							| 
									
										
										
										
											2021-10-18 19:44:29 +00:00
										 |  |  |     err = e.value.response["Error"] | 
					
						
							|  |  |  |     err["Code"].should.equal("InvalidRequestException") | 
					
						
							|  |  |  |     err["Message"].should.equal("Location 2 not found.") | 
					
						
							| 
									
										
										
										
											2019-11-02 21:34:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-01 21:16:59 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | @mock_datasync | 
					
						
							|  |  |  | def test_list_tasks(): | 
					
						
							|  |  |  |     client = boto3.client("datasync", region_name="us-east-1") | 
					
						
							| 
									
										
										
										
											2019-11-02 21:34:35 +02:00
										 |  |  |     locations = create_locations(client, create_s3=True, create_smb=True) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-18 19:44:29 +00:00
										 |  |  |     client.create_task( | 
					
						
							| 
									
										
										
										
											2019-11-02 21:34:35 +02:00
										 |  |  |         SourceLocationArn=locations["smb_arn"], | 
					
						
							|  |  |  |         DestinationLocationArn=locations["s3_arn"], | 
					
						
							| 
									
										
										
										
											2019-11-01 21:16:59 +02:00
										 |  |  |     ) | 
					
						
							| 
									
										
										
										
											2021-10-18 19:44:29 +00:00
										 |  |  |     client.create_task( | 
					
						
							| 
									
										
										
										
											2019-11-02 21:34:35 +02:00
										 |  |  |         SourceLocationArn=locations["s3_arn"], | 
					
						
							|  |  |  |         DestinationLocationArn=locations["smb_arn"], | 
					
						
							|  |  |  |         Name="task_name", | 
					
						
							| 
									
										
										
										
											2019-11-01 21:16:59 +02:00
										 |  |  |     ) | 
					
						
							|  |  |  |     response = client.list_tasks() | 
					
						
							| 
									
										
										
										
											2019-11-02 21:34:35 +02:00
										 |  |  |     tasks = response["Tasks"] | 
					
						
							| 
									
										
										
										
											2019-11-01 21:16:59 +02:00
										 |  |  |     assert len(tasks) == 2 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     task = tasks[0] | 
					
						
							| 
									
										
										
										
											2019-11-02 21:34:35 +02:00
										 |  |  |     assert task["Status"] == "AVAILABLE" | 
					
						
							|  |  |  |     assert "Name" not in task | 
					
						
							| 
									
										
										
										
											2019-11-01 21:16:59 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     task = tasks[1] | 
					
						
							| 
									
										
										
										
											2019-11-02 21:34:35 +02:00
										 |  |  |     assert task["Status"] == "AVAILABLE" | 
					
						
							|  |  |  |     assert task["Name"] == "task_name" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-01 21:16:59 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | @mock_datasync | 
					
						
							|  |  |  | def test_describe_task(): | 
					
						
							|  |  |  |     client = boto3.client("datasync", region_name="us-east-1") | 
					
						
							| 
									
										
										
										
											2019-11-02 21:34:35 +02:00
										 |  |  |     locations = create_locations(client, create_s3=True, create_smb=True) | 
					
						
							| 
									
										
										
										
											2019-11-01 21:16:59 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-02 21:34:35 +02:00
										 |  |  |     response = client.create_task( | 
					
						
							|  |  |  |         SourceLocationArn=locations["smb_arn"], | 
					
						
							|  |  |  |         DestinationLocationArn=locations["s3_arn"], | 
					
						
							|  |  |  |         Name="task_name", | 
					
						
							| 
									
										
										
										
											2019-11-01 21:16:59 +02:00
										 |  |  |     ) | 
					
						
							| 
									
										
										
										
											2019-11-02 21:34:35 +02:00
										 |  |  |     task_arn = response["TaskArn"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.describe_task(TaskArn=task_arn) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     assert "TaskArn" in response | 
					
						
							|  |  |  |     assert "Status" in response | 
					
						
							|  |  |  |     assert "SourceLocationArn" in response | 
					
						
							|  |  |  |     assert "DestinationLocationArn" in response | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_datasync | 
					
						
							|  |  |  | def test_describe_task_not_exist(): | 
					
						
							|  |  |  |     client = boto3.client("datasync", region_name="us-east-1") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(ClientError) as e: | 
					
						
							| 
									
										
										
										
											2019-11-02 21:34:35 +02:00
										 |  |  |         client.describe_task(TaskArn="abc") | 
					
						
							| 
									
										
										
										
											2021-10-18 19:44:29 +00:00
										 |  |  |     err = e.value.response["Error"] | 
					
						
							|  |  |  |     err["Code"].should.equal("InvalidRequestException") | 
					
						
							|  |  |  |     err["Message"].should.equal("The request is not valid.") | 
					
						
							| 
									
										
										
										
											2019-11-02 21:34:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-01 21:16:59 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-05 12:30:05 +02:00
										 |  |  | @mock_datasync | 
					
						
							|  |  |  | def test_update_task(): | 
					
						
							|  |  |  |     client = boto3.client("datasync", region_name="us-east-1") | 
					
						
							|  |  |  |     locations = create_locations(client, create_s3=True, create_smb=True) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     initial_name = "Initial_Name" | 
					
						
							|  |  |  |     updated_name = "Updated_Name" | 
					
						
							|  |  |  |     initial_options = { | 
					
						
							|  |  |  |         "VerifyMode": "NONE", | 
					
						
							|  |  |  |         "Atime": "BEST_EFFORT", | 
					
						
							|  |  |  |         "Mtime": "PRESERVE", | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     updated_options = { | 
					
						
							|  |  |  |         "VerifyMode": "POINT_IN_TIME_CONSISTENT", | 
					
						
							|  |  |  |         "Atime": "BEST_EFFORT", | 
					
						
							|  |  |  |         "Mtime": "PRESERVE", | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     response = client.create_task( | 
					
						
							|  |  |  |         SourceLocationArn=locations["smb_arn"], | 
					
						
							|  |  |  |         DestinationLocationArn=locations["s3_arn"], | 
					
						
							|  |  |  |         Name=initial_name, | 
					
						
							|  |  |  |         Options=initial_options, | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     task_arn = response["TaskArn"] | 
					
						
							|  |  |  |     response = client.describe_task(TaskArn=task_arn) | 
					
						
							|  |  |  |     assert response["TaskArn"] == task_arn | 
					
						
							|  |  |  |     assert response["Name"] == initial_name | 
					
						
							|  |  |  |     assert response["Options"] == initial_options | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-18 19:44:29 +00:00
										 |  |  |     client.update_task(TaskArn=task_arn, Name=updated_name, Options=updated_options) | 
					
						
							| 
									
										
										
										
											2019-11-05 12:30:05 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     response = client.describe_task(TaskArn=task_arn) | 
					
						
							|  |  |  |     assert response["TaskArn"] == task_arn | 
					
						
							|  |  |  |     assert response["Name"] == updated_name | 
					
						
							|  |  |  |     assert response["Options"] == updated_options | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     with pytest.raises(ClientError): | 
					
						
							| 
									
										
										
										
											2019-11-05 12:30:05 +02:00
										 |  |  |         client.update_task(TaskArn="doesnt_exist") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_datasync | 
					
						
							|  |  |  | def test_delete_task(): | 
					
						
							|  |  |  |     client = boto3.client("datasync", region_name="us-east-1") | 
					
						
							|  |  |  |     locations = create_locations(client, create_s3=True, create_smb=True) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-18 19:44:29 +00:00
										 |  |  |     client.create_task( | 
					
						
							| 
									
										
										
										
											2019-11-05 12:30:05 +02:00
										 |  |  |         SourceLocationArn=locations["smb_arn"], | 
					
						
							|  |  |  |         DestinationLocationArn=locations["s3_arn"], | 
					
						
							|  |  |  |         Name="task_name", | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.list_tasks() | 
					
						
							|  |  |  |     assert len(response["Tasks"]) == 1 | 
					
						
							|  |  |  |     task_arn = response["Tasks"][0]["TaskArn"] | 
					
						
							|  |  |  |     assert task_arn is not None | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-18 19:44:29 +00:00
										 |  |  |     client.delete_task(TaskArn=task_arn) | 
					
						
							| 
									
										
										
										
											2019-11-05 12:30:05 +02:00
										 |  |  |     response = client.list_tasks() | 
					
						
							|  |  |  |     assert len(response["Tasks"]) == 0 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 08:04:09 +02:00
										 |  |  |     with pytest.raises(ClientError): | 
					
						
							| 
									
										
										
										
											2021-10-18 19:44:29 +00:00
										 |  |  |         client.delete_task(TaskArn=task_arn) | 
					
						
							| 
									
										
										
										
											2019-11-05 12:30:05 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-01 21:16:59 +02:00
										 |  |  | @mock_datasync | 
					
						
							|  |  |  | def test_start_task_execution(): | 
					
						
							|  |  |  |     client = boto3.client("datasync", region_name="us-east-1") | 
					
						
							| 
									
										
										
										
											2019-11-02 21:34:35 +02:00
										 |  |  |     locations = create_locations(client, create_s3=True, create_smb=True) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-01 21:16:59 +02:00
										 |  |  |     response = client.create_task( | 
					
						
							| 
									
										
										
										
											2019-11-02 21:34:35 +02:00
										 |  |  |         SourceLocationArn=locations["smb_arn"], | 
					
						
							|  |  |  |         DestinationLocationArn=locations["s3_arn"], | 
					
						
							|  |  |  |         Name="task_name", | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     task_arn = response["TaskArn"] | 
					
						
							|  |  |  |     response = client.describe_task(TaskArn=task_arn) | 
					
						
							|  |  |  |     assert "CurrentTaskExecutionArn" not in response | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.start_task_execution(TaskArn=task_arn) | 
					
						
							|  |  |  |     assert "TaskExecutionArn" in response | 
					
						
							|  |  |  |     task_execution_arn = response["TaskExecutionArn"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.describe_task(TaskArn=task_arn) | 
					
						
							|  |  |  |     assert response["CurrentTaskExecutionArn"] == task_execution_arn | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_datasync | 
					
						
							|  |  |  | def test_start_task_execution_twice(): | 
					
						
							|  |  |  |     client = boto3.client("datasync", region_name="us-east-1") | 
					
						
							|  |  |  |     locations = create_locations(client, create_s3=True, create_smb=True) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.create_task( | 
					
						
							|  |  |  |         SourceLocationArn=locations["smb_arn"], | 
					
						
							|  |  |  |         DestinationLocationArn=locations["s3_arn"], | 
					
						
							|  |  |  |         Name="task_name", | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     task_arn = response["TaskArn"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.start_task_execution(TaskArn=task_arn) | 
					
						
							| 
									
										
										
										
											2022-04-18 20:44:56 +00:00
										 |  |  |     response.should.have.key("TaskExecutionArn") | 
					
						
							| 
									
										
										
										
											2019-11-02 21:34:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-18 20:44:56 +00:00
										 |  |  |     with pytest.raises(ClientError) as exc: | 
					
						
							| 
									
										
										
										
											2021-10-18 19:44:29 +00:00
										 |  |  |         client.start_task_execution(TaskArn=task_arn) | 
					
						
							| 
									
										
										
										
											2022-04-18 20:44:56 +00:00
										 |  |  |     err = exc.value.response["Error"] | 
					
						
							|  |  |  |     err["Code"].should.equal("InvalidRequestException") | 
					
						
							| 
									
										
										
										
											2019-11-02 21:34:35 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_datasync | 
					
						
							|  |  |  | def test_describe_task_execution(): | 
					
						
							|  |  |  |     client = boto3.client("datasync", region_name="us-east-1") | 
					
						
							|  |  |  |     locations = create_locations(client, create_s3=True, create_smb=True) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.create_task( | 
					
						
							|  |  |  |         SourceLocationArn=locations["smb_arn"], | 
					
						
							|  |  |  |         DestinationLocationArn=locations["s3_arn"], | 
					
						
							|  |  |  |         Name="task_name", | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |     task_arn = response["TaskArn"] | 
					
						
							| 
									
										
										
										
											2019-11-05 12:30:05 +02:00
										 |  |  |     response = client.describe_task(TaskArn=task_arn) | 
					
						
							|  |  |  |     assert response["Status"] == "AVAILABLE" | 
					
						
							| 
									
										
										
										
											2019-11-02 21:34:35 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     response = client.start_task_execution(TaskArn=task_arn) | 
					
						
							|  |  |  |     task_execution_arn = response["TaskExecutionArn"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Each time task_execution is described the Status will increment | 
					
						
							|  |  |  |     # This is a simple way to simulate a task being executed | 
					
						
							|  |  |  |     response = client.describe_task_execution(TaskExecutionArn=task_execution_arn) | 
					
						
							|  |  |  |     assert response["TaskExecutionArn"] == task_execution_arn | 
					
						
							|  |  |  |     assert response["Status"] == "INITIALIZING" | 
					
						
							| 
									
										
										
										
											2019-11-05 12:30:05 +02:00
										 |  |  |     response = client.describe_task(TaskArn=task_arn) | 
					
						
							|  |  |  |     assert response["Status"] == "RUNNING" | 
					
						
							| 
									
										
										
										
											2019-11-02 21:34:35 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     response = client.describe_task_execution(TaskExecutionArn=task_execution_arn) | 
					
						
							|  |  |  |     assert response["TaskExecutionArn"] == task_execution_arn | 
					
						
							|  |  |  |     assert response["Status"] == "PREPARING" | 
					
						
							| 
									
										
										
										
											2019-11-05 12:30:05 +02:00
										 |  |  |     response = client.describe_task(TaskArn=task_arn) | 
					
						
							|  |  |  |     assert response["Status"] == "RUNNING" | 
					
						
							| 
									
										
										
										
											2019-11-02 21:34:35 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     response = client.describe_task_execution(TaskExecutionArn=task_execution_arn) | 
					
						
							|  |  |  |     assert response["TaskExecutionArn"] == task_execution_arn | 
					
						
							|  |  |  |     assert response["Status"] == "TRANSFERRING" | 
					
						
							| 
									
										
										
										
											2019-11-05 12:30:05 +02:00
										 |  |  |     response = client.describe_task(TaskArn=task_arn) | 
					
						
							|  |  |  |     assert response["Status"] == "RUNNING" | 
					
						
							| 
									
										
										
										
											2019-11-02 21:34:35 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     response = client.describe_task_execution(TaskExecutionArn=task_execution_arn) | 
					
						
							|  |  |  |     assert response["TaskExecutionArn"] == task_execution_arn | 
					
						
							|  |  |  |     assert response["Status"] == "VERIFYING" | 
					
						
							| 
									
										
										
										
											2019-11-05 12:30:05 +02:00
										 |  |  |     response = client.describe_task(TaskArn=task_arn) | 
					
						
							|  |  |  |     assert response["Status"] == "RUNNING" | 
					
						
							| 
									
										
										
										
											2019-11-02 21:34:35 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     response = client.describe_task_execution(TaskExecutionArn=task_execution_arn) | 
					
						
							|  |  |  |     assert response["TaskExecutionArn"] == task_execution_arn | 
					
						
							|  |  |  |     assert response["Status"] == "SUCCESS" | 
					
						
							| 
									
										
										
										
											2019-11-05 12:30:05 +02:00
										 |  |  |     response = client.describe_task(TaskArn=task_arn) | 
					
						
							|  |  |  |     assert response["Status"] == "AVAILABLE" | 
					
						
							| 
									
										
										
										
											2019-11-02 21:34:35 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     response = client.describe_task_execution(TaskExecutionArn=task_execution_arn) | 
					
						
							|  |  |  |     assert response["TaskExecutionArn"] == task_execution_arn | 
					
						
							|  |  |  |     assert response["Status"] == "SUCCESS" | 
					
						
							| 
									
										
										
										
											2019-11-05 12:30:05 +02:00
										 |  |  |     response = client.describe_task(TaskArn=task_arn) | 
					
						
							|  |  |  |     assert response["Status"] == "AVAILABLE" | 
					
						
							| 
									
										
										
										
											2019-11-02 21:34:35 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_datasync | 
					
						
							|  |  |  | def test_describe_task_execution_not_exist(): | 
					
						
							|  |  |  |     client = boto3.client("datasync", region_name="us-east-1") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 07:54:49 +02:00
										 |  |  |     with pytest.raises(ClientError) as e: | 
					
						
							| 
									
										
										
										
											2019-11-02 21:34:35 +02:00
										 |  |  |         client.describe_task_execution(TaskExecutionArn="abc") | 
					
						
							| 
									
										
										
										
											2021-10-18 19:44:29 +00:00
										 |  |  |     err = e.value.response["Error"] | 
					
						
							|  |  |  |     err["Code"].should.equal("InvalidRequestException") | 
					
						
							|  |  |  |     err["Message"].should.equal("The request is not valid.") | 
					
						
							| 
									
										
										
										
											2019-11-02 21:34:35 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @mock_datasync | 
					
						
							|  |  |  | def test_cancel_task_execution(): | 
					
						
							|  |  |  |     client = boto3.client("datasync", region_name="us-east-1") | 
					
						
							|  |  |  |     locations = create_locations(client, create_s3=True, create_smb=True) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.create_task( | 
					
						
							|  |  |  |         SourceLocationArn=locations["smb_arn"], | 
					
						
							|  |  |  |         DestinationLocationArn=locations["s3_arn"], | 
					
						
							|  |  |  |         Name="task_name", | 
					
						
							| 
									
										
										
										
											2019-11-01 21:16:59 +02:00
										 |  |  |     ) | 
					
						
							| 
									
										
										
										
											2019-11-02 21:34:35 +02:00
										 |  |  |     task_arn = response["TaskArn"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.start_task_execution(TaskArn=task_arn) | 
					
						
							|  |  |  |     task_execution_arn = response["TaskExecutionArn"] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     response = client.describe_task(TaskArn=task_arn) | 
					
						
							|  |  |  |     assert response["CurrentTaskExecutionArn"] == task_execution_arn | 
					
						
							| 
									
										
										
										
											2019-11-05 12:30:05 +02:00
										 |  |  |     assert response["Status"] == "RUNNING" | 
					
						
							| 
									
										
										
										
											2019-11-02 21:34:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-18 19:44:29 +00:00
										 |  |  |     client.cancel_task_execution(TaskExecutionArn=task_execution_arn) | 
					
						
							| 
									
										
										
										
											2019-11-02 21:34:35 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     response = client.describe_task(TaskArn=task_arn) | 
					
						
							|  |  |  |     assert "CurrentTaskExecutionArn" not in response | 
					
						
							| 
									
										
										
										
											2019-11-05 12:30:05 +02:00
										 |  |  |     assert response["Status"] == "AVAILABLE" | 
					
						
							| 
									
										
										
										
											2019-11-02 21:34:35 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     response = client.describe_task_execution(TaskExecutionArn=task_execution_arn) | 
					
						
							|  |  |  |     assert response["Status"] == "ERROR" |