Skip to content

Commit

Permalink
[ECS] Force New Deployment (#8232)
Browse files Browse the repository at this point in the history
  • Loading branch information
armichaud authored Oct 16, 2024
1 parent 6d51cae commit 9dbd017
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions moto/ecs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1692,6 +1692,7 @@ def update_service(self, service_properties: Dict[str, Any]) -> Service:
task_definition_str = service_properties.pop("task_definition", None)
cluster = self._get_cluster(cluster_str)
service_name = service_properties.pop("service").split("/")[-1]
force_new_deployment = service_properties.pop("force_new_deployment", False)
cluster_service_pair = f"{cluster.name}:{service_name}"

if cluster_service_pair in self.services:
Expand All @@ -1705,6 +1706,12 @@ def update_service(self, service_properties: Dict[str, Any]) -> Service:
if task_definition_str:
self.describe_task_definition(task_definition_str)
current_service.task_definition = task_definition_str
if force_new_deployment and current_service.deployments:
deployment = current_service.deployments[0]
deployment["id"] = f"ecs-svc/{mock_random.randint(0, 32**12)}"
now = datetime.now(timezone.utc)
deployment["createdAt"] = now
deployment["updatedAt"] = now
return current_service
else:
raise ServiceNotFoundException
Expand Down
16 changes: 16 additions & 0 deletions tests/test_ecs/test_ecs_boto3.py
Original file line number Diff line number Diff line change
Expand Up @@ -1225,6 +1225,8 @@ def test_update_service():
desiredCount=2,
)
assert response["service"]["desiredCount"] == 2
id = response["service"]["deployments"][0]["id"]
created_at = response["service"]["deployments"][0]["createdAt"]

response = client.update_service(
cluster="test_ecs_cluster",
Expand All @@ -1248,6 +1250,20 @@ def test_update_service():
assert response["service"]["runningCount"] == 1
assert response["service"]["pendingCount"] == 0

response = client.update_service(
cluster="test_ecs_cluster",
service="test_ecs_service",
taskDefinition="test_ecs_task",
desiredCount=1,
forceNewDeployment=True,
)
assert response["service"]["deployments"][0]["id"] != id
assert response["service"]["deployments"][0]["createdAt"] != created_at
assert (
response["service"]["deployments"][0]["createdAt"]
== response["service"]["deployments"][0]["updatedAt"]
)


@mock_aws
def test_update_missing_service():
Expand Down

0 comments on commit 9dbd017

Please sign in to comment.