Skip to content

Commit

Permalink
refactor: rename status column to state
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulFarault committed Nov 13, 2023
1 parent a4f473f commit 3da2ce8
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 43 deletions.
2 changes: 1 addition & 1 deletion tdp/cli/commands/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def deploy(
session.add_all(cluster_status_logs)
session.commit() # Update operation status to SUCCESS, FAILURE or HELD

if deployment_iterator.deployment.status != DeploymentStateEnum.SUCCESS:
if deployment_iterator.deployment.state != DeploymentStateEnum.SUCCESS:
raise click.ClickException("Deployment failed.")
else:
click.echo("Deployment finished with success.")
2 changes: 1 addition & 1 deletion tdp/cli/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ def get_planned_deployment(session: Session) -> Optional[DeploymentModel]:
Returns:
The planned deployment or None if there is no planned deployment.
"""
return session.query(DeploymentModel).filter_by(status="PLANNED").one_or_none()
return session.query(DeploymentModel).filter_by(state="PLANNED").one_or_none()


def get_operation_records(
Expand Down
10 changes: 5 additions & 5 deletions tdp/core/deployment/deployment_iterator.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def __next__(self) -> Optional[list[SCHStatusLogModel]]:
operation_rec: OperationModel = next(self._iter)

# Return early if deployment failed
if self.deployment.status == DeploymentStateEnum.FAILURE:
if self.deployment.state == DeploymentStateEnum.FAILURE:
operation_rec.state = OperationStateEnum.HELD
return
else:
Expand All @@ -130,7 +130,7 @@ def __next__(self) -> Optional[list[SCHStatusLogModel]]:

# Set deployment status to failure if the operation failed
if operation_rec.state != OperationStateEnum.SUCCESS:
self.deployment.status = DeploymentStateEnum.FAILURE
self.deployment.state = DeploymentStateEnum.FAILURE
# Return early as status is not updated
return

Expand Down Expand Up @@ -217,11 +217,11 @@ def __next__(self) -> Optional[list[SCHStatusLogModel]]:
# StopIteration is a "normal" exception raised when the iteration has stopped
except StopIteration as e:
self.deployment.end_time = datetime.utcnow()
if not self.deployment.status == DeploymentStateEnum.FAILURE:
self.deployment.status = DeploymentStateEnum.SUCCESS
if not self.deployment.state == DeploymentStateEnum.FAILURE:
self.deployment.state = DeploymentStateEnum.SUCCESS
raise e
# An unforeseen error has occured, stop the deployment and set as failure
except Exception as e:
self.deployment.end_time = datetime.utcnow()
self.deployment.status = DeploymentStateEnum.FAILURE
self.deployment.state = DeploymentStateEnum.FAILURE
raise e
2 changes: 1 addition & 1 deletion tdp/core/deployment/deployment_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def run(
Returns:
DeploymentIterator object, to iterate over operations logs.
"""
deployment.status = DeploymentStateEnum.RUNNING
deployment.state = DeploymentStateEnum.RUNNING
return DeploymentIterator(
deployment=deployment,
collections=self._collections,
Expand Down
24 changes: 12 additions & 12 deletions tdp/core/deployment/test_deployment_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def test_deployment_plan_is_success(
for _ in deployment_iterator:
pass

assert deployment_iterator.deployment.status == DeploymentStateEnum.SUCCESS
assert deployment_iterator.deployment.state == DeploymentStateEnum.SUCCESS
assert len(deployment_iterator.deployment.operations) == 8
for operation in deployment_iterator.deployment.operations:
assert operation.state == OperationStateEnum.SUCCESS
Expand All @@ -112,7 +112,7 @@ def test_deployment_plan_with_filter_is_success(
for i, _ in enumerate(deployment_iterator):
assert deployment.operations[i].state == OperationStateEnum.SUCCESS

assert deployment_iterator.deployment.status == DeploymentStateEnum.SUCCESS
assert deployment_iterator.deployment.state == DeploymentStateEnum.SUCCESS
assert len(deployment_iterator.deployment.operations) == 2


Expand All @@ -126,7 +126,7 @@ def test_noop_deployment_plan_is_success(
for i, _ in enumerate(deployment_iterator):
assert deployment.operations[i].state == OperationStateEnum.SUCCESS

assert deployment_iterator.deployment.status == DeploymentStateEnum.SUCCESS
assert deployment_iterator.deployment.state == DeploymentStateEnum.SUCCESS
assert len(deployment_iterator.deployment.operations) == 1


Expand All @@ -139,7 +139,7 @@ def test_failed_operation_stops(

for _ in deployment_iterator:
pass
assert deployment_iterator.deployment.status == DeploymentStateEnum.FAILURE
assert deployment_iterator.deployment.state == DeploymentStateEnum.FAILURE
assert len(deployment_iterator.deployment.operations) == 8


Expand All @@ -153,7 +153,7 @@ def test_service_log_is_emitted(
for _ in deployment_iterator:
pass

assert deployment_iterator.deployment.status == DeploymentStateEnum.SUCCESS
assert deployment_iterator.deployment.state == DeploymentStateEnum.SUCCESS


def test_service_log_is_not_emitted(
Expand All @@ -168,7 +168,7 @@ def test_service_log_is_not_emitted(
for _ in deployment_iterator:
pass

assert deployment_iterator.deployment.status == DeploymentStateEnum.SUCCESS
assert deployment_iterator.deployment.state == DeploymentStateEnum.SUCCESS


def test_service_log_only_noop_is_emitted(
Expand All @@ -183,7 +183,7 @@ def test_service_log_only_noop_is_emitted(
for _ in deployment_iterator:
pass

assert deployment_iterator.deployment.status == DeploymentStateEnum.SUCCESS
assert deployment_iterator.deployment.state == DeploymentStateEnum.SUCCESS


def test_service_log_not_emitted_when_config_start_wrong_order(
Expand All @@ -198,7 +198,7 @@ def test_service_log_not_emitted_when_config_start_wrong_order(
for _ in deployment_iterator:
pass

assert deployment_iterator.deployment.status == DeploymentStateEnum.SUCCESS
assert deployment_iterator.deployment.state == DeploymentStateEnum.SUCCESS


def test_service_log_emitted_once_with_start_and_restart(
Expand All @@ -213,7 +213,7 @@ def test_service_log_emitted_once_with_start_and_restart(
for _ in deployment_iterator:
pass

assert deployment_iterator.deployment.status == DeploymentStateEnum.SUCCESS
assert deployment_iterator.deployment.state == DeploymentStateEnum.SUCCESS


def test_service_log_emitted_once_with_multiple_config_and_start_on_same_component(
Expand All @@ -234,7 +234,7 @@ def test_service_log_emitted_once_with_multiple_config_and_start_on_same_compone
for _ in deployment_iterator:
pass

assert deployment_iterator.deployment.status == DeploymentStateEnum.SUCCESS
assert deployment_iterator.deployment.state == DeploymentStateEnum.SUCCESS


def test_deployment_dag_is_resumed(
Expand All @@ -248,7 +248,7 @@ def test_deployment_dag_is_resumed(
for _ in deployment_iterator:
pass

assert deployment_iterator.deployment.status == DeploymentStateEnum.FAILURE
assert deployment_iterator.deployment.state == DeploymentStateEnum.FAILURE

resume_log = DeploymentModel.from_failed_deployment(
mock_collections, deployment_iterator.deployment
Expand All @@ -261,7 +261,7 @@ def test_deployment_dag_is_resumed(
resume_deployment_iterator.deployment.deployment_type
== DeploymentTypeEnum.RESUME
)
assert resume_deployment_iterator.deployment.status == DeploymentStateEnum.SUCCESS
assert resume_deployment_iterator.deployment.state == DeploymentStateEnum.SUCCESS
failed_operation = next(
filter(
lambda x: x.state == DeploymentStateEnum.FAILURE,
Expand Down
20 changes: 10 additions & 10 deletions tdp/core/models/deployment_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ class DeploymentModel(BaseModel):
)
start_time: Mapped[Optional[datetime]] = mapped_column(doc="Deployment start time.")
end_time: Mapped[Optional[datetime]] = mapped_column(doc="Deployment end time.")
status: Mapped[Optional[DeploymentStateEnum]] = mapped_column(
doc="Deployment status."
state: Mapped[Optional[DeploymentStateEnum]] = mapped_column(
doc="Deployment state."
)
deployment_type: Mapped[Optional[DeploymentTypeEnum]] = mapped_column(
doc="Deployment type."
Expand All @@ -89,7 +89,7 @@ def __str__(self):
["id", self.id],
["start_time", self.start_time],
["end_time", self.end_time],
["state", self.status],
["state", self.state],
],
tablefmt="plain",
)
Expand Down Expand Up @@ -156,7 +156,7 @@ def from_dag(
}
),
},
status=DeploymentStateEnum.PLANNED,
state=DeploymentStateEnum.PLANNED,
)
deployment.operations = [
OperationModel(
Expand Down Expand Up @@ -209,7 +209,7 @@ def from_operations(
}
),
},
status=DeploymentStateEnum.PLANNED,
state=DeploymentStateEnum.PLANNED,
)
operation_order = 1
for operation in operations:
Expand Down Expand Up @@ -267,7 +267,7 @@ def from_operations_hosts_vars(
"""
deployment = DeploymentModel(
deployment_type=DeploymentTypeEnum.CUSTOM,
status=DeploymentStateEnum.PLANNED,
state=DeploymentStateEnum.PLANNED,
)

for operation_order, operation_host_vars in enumerate(
Expand Down Expand Up @@ -352,7 +352,7 @@ def from_stale_components(
}
),
},
status=DeploymentStateEnum.PLANNED,
state=DeploymentStateEnum.PLANNED,
)
operation_order = 1
for operation, host in operation_hosts_sorted:
Expand Down Expand Up @@ -395,10 +395,10 @@ def from_failed_deployment(
NothingToResumeError: If the deployment was successful.
UnsupportedDeploymentTypeError: If the deployment type is not supported.
"""
if failed_deployment.status != DeploymentStateEnum.FAILURE:
if failed_deployment.state != DeploymentStateEnum.FAILURE:
raise NothingToResumeError(
f"Nothing to resume, deployment #{failed_deployment.id} "
+ f"was {failed_deployment.status}."
+ f"was {failed_deployment.state}."
)

if len(failed_deployment.operations) == 0:
Expand Down Expand Up @@ -427,7 +427,7 @@ def from_failed_deployment(
options={
"from": failed_deployment.id,
},
status=DeploymentStateEnum.PLANNED,
state=DeploymentStateEnum.PLANNED,
)
deployment.operations = [
OperationModel(
Expand Down
22 changes: 11 additions & 11 deletions tdp/core/models/test_deployment_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def get_hosts_from_playbook(self, fd: TextIO) -> set[str]:


def fail_deployment(deployment: DeploymentModel, index_to_fail: int):
deployment.status = DeploymentStateEnum.FAILURE
deployment.state = DeploymentStateEnum.FAILURE
for operation in deployment.operations:
if operation.operation_order < index_to_fail:
operation.state = OperationStateEnum.SUCCESS
Expand All @@ -48,7 +48,7 @@ def fail_deployment(deployment: DeploymentModel, index_to_fail: int):


def set_success(deployment: DeploymentModel):
deployment.status = DeploymentStateEnum.SUCCESS
deployment.state = DeploymentStateEnum.SUCCESS
for operation in deployment.operations:
operation.state = OperationStateEnum.SUCCESS

Expand All @@ -61,7 +61,7 @@ def test_empty(self, mock_collections: Collections):
assert len(deployment.operations) == 0
assert deployment.deployment_type == DeploymentTypeEnum.OPERATIONS
assert deployment.options == {"operations": []} # TODO should be {}
assert deployment.status == DeploymentStateEnum.PLANNED
assert deployment.state == DeploymentStateEnum.PLANNED

def test_single_operation(self, mock_collections: Collections):
operations_names = ["serv_comp_config"]
Expand All @@ -72,7 +72,7 @@ def test_single_operation(self, mock_collections: Collections):
] == operations_names
assert deployment.deployment_type == DeploymentTypeEnum.OPERATIONS
assert deployment.options == {"operations": operations_names}
assert deployment.status == DeploymentStateEnum.PLANNED
assert deployment.state == DeploymentStateEnum.PLANNED

def test_single_restart_operation(self, mock_collections: Collections):
operations_names = ["serv_comp_restart"]
Expand All @@ -83,7 +83,7 @@ def test_single_restart_operation(self, mock_collections: Collections):
] == operations_names
assert deployment.deployment_type == DeploymentTypeEnum.OPERATIONS
assert deployment.options == {"operations": operations_names}
assert deployment.status == DeploymentStateEnum.PLANNED
assert deployment.state == DeploymentStateEnum.PLANNED

def test_single_noop_opeation(self, mock_collections: Collections):
operations_names = ["serv_config"]
Expand All @@ -94,7 +94,7 @@ def test_single_noop_opeation(self, mock_collections: Collections):
] == operations_names
assert deployment.deployment_type == DeploymentTypeEnum.OPERATIONS
assert deployment.options == {"operations": operations_names}
assert deployment.status == DeploymentStateEnum.PLANNED
assert deployment.state == DeploymentStateEnum.PLANNED

def test_single_restart_noop_operation(self, mock_collections: Collections):
operations_names = ["serv_restart"]
Expand All @@ -105,7 +105,7 @@ def test_single_restart_noop_operation(self, mock_collections: Collections):
] == operations_names
assert deployment.deployment_type == DeploymentTypeEnum.OPERATIONS
assert deployment.options == {"operations": operations_names}
assert deployment.status == DeploymentStateEnum.PLANNED
assert deployment.state == DeploymentStateEnum.PLANNED

def test_multiple_operations(self, mock_collections: Collections):
operations_names = ["serv_comp_config", "serv_comp_restart"]
Expand All @@ -116,7 +116,7 @@ def test_multiple_operations(self, mock_collections: Collections):
] == operations_names
assert deployment.deployment_type == DeploymentTypeEnum.OPERATIONS
assert deployment.options == {"operations": operations_names}
assert deployment.status == DeploymentStateEnum.PLANNED
assert deployment.state == DeploymentStateEnum.PLANNED

def test_single_host(self, mock_collections: Collections):
operations_names = ["serv_comp_config", "serv_comp_start"]
Expand All @@ -135,7 +135,7 @@ def test_single_host(self, mock_collections: Collections):
"operations": operations_names,
"hosts": [host],
}
assert deployment.status == DeploymentStateEnum.PLANNED
assert deployment.state == DeploymentStateEnum.PLANNED

def test_multiple_host(self, tmp_path_factory: pytest.TempPathFactory):
operations_names = ["serv_comp_config", "serv_comp_start"]
Expand Down Expand Up @@ -174,7 +174,7 @@ def test_multiple_host(self, tmp_path_factory: pytest.TempPathFactory):
"operations": operations_names,
"hosts": hosts,
}
assert deployment.status == DeploymentStateEnum.PLANNED
assert deployment.state == DeploymentStateEnum.PLANNED

def test_extra_vars(self, mock_collections: Collections):
operations_names = ["serv_comp_config", "serv_comp_start"]
Expand All @@ -195,7 +195,7 @@ def test_extra_vars(self, mock_collections: Collections):
"operations": operations_names,
"extra_vars": extra_vars,
}
assert deployment.status == DeploymentStateEnum.PLANNED
assert deployment.state == DeploymentStateEnum.PLANNED


class TestFromDag:
Expand Down
4 changes: 2 additions & 2 deletions tdp/core/models/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_create_deployment(db_session: Session):
},
start_time=datetime.utcnow(),
end_time=datetime.utcnow() + timedelta(0, 1),
status="SUCCESS",
state="SUCCESS",
deployment_type="Dag",
)
component_version_log = SCHStatusLogModel(
Expand Down Expand Up @@ -66,7 +66,7 @@ def test_create_deployment(db_session: Session):
"hosts": ["host1", "host2"],
"restart": False,
}
assert result.status == "Success"
assert result.state == "Success"
assert result.deployment_type == "Dag"

logger.info(result.operations)
Expand Down

0 comments on commit 3da2ce8

Please sign in to comment.