Commit f1054f5a authored by Lukas Burgey's avatar Lukas Burgey

Change deployment state target updating

parent 34fb6521
......@@ -44,9 +44,7 @@ class Site(models.Model):
dep_states = [
state
for state in self.states.all()
if (
state.is_pending or state.is_credential_pending
) and state.deployments.exists()
if state.is_pending and state.deployments.exists()
]
# make the deployments unique here
......
......@@ -428,13 +428,20 @@ class DeploymentState(models.Model):
return True
# pending because the state target is not reached
if self.state == QUESTIONNAIRE or self.state == REJECTED:
return False
if self.state_target != self.state:
return True
return False
# passing through is_credential_pending here
return self.is_credential_pending
@property
def is_credential_pending(self):
# little hack to not confuse the user
if self.state == QUESTIONNAIRE or self.state == REJECTED:
return False
for credential_state in self.credential_states.all():
if credential_state.is_pending:
return True
......@@ -496,6 +503,40 @@ class DeploymentState(models.Model):
# STATE TRANSITIONS
# DeploymentState.dep_target_changed
# called when one of our deployment changes its state_target
def dep_target_changed(self):
LOGGER.debug(self.msg('dep_target_changed'))
self._assure_credential_states_exist()
for cred_state in self.credential_states.all():
cred_state.set_target(self.state_target)
if self.state_target == DEPLOYED:
# handle the 7 states we can be in
if self.state == NOT_DEPLOYED or self.state == REMOVAL_PENDING:
self._set_state(DEPLOYMENT_PENDING)
elif self.state == DEPLOYED or self.state == DEPLOYMENT_PENDING:
LOGGER.debug(self.msg('has already reached the correct state'))
elif self.state == QUESTIONNAIRE:
LOGGER.debug(self.msg('is questionnaire! Need answers first'))
elif self.state == REJECTED:
LOGGER.debug(self.msg('is rejected! The site will never execute this deployement'))
elif self.state == FAILED:
LOGGER.debug(self.msg('is failed! We will retry it'))
elif self.state_target == NOT_DEPLOYED:
self._reset()
# handle the 7 states we can be in
if self.state == DEPLOYED or self.state == DEPLOYMENT_PENDING:
self._set_state(REMOVAL_PENDING)
elif self.state == NOT_DEPLOYED or self.state == REMOVAL_PENDING:
LOGGER.debug(self.msg('has already reached the correct state'))
elif self.state == FAILED or self.state == REJECTED or self.state == QUESTIONNAIRE:
self._set_state(NOT_DEPLOYED)
#
# DeploymentState.user_deploy
def user_deploy(self):
LOGGER.debug(self.msg('user_deploy'))
......@@ -514,6 +555,7 @@ class DeploymentState(models.Model):
self._set_state(DEPLOYMENT_PENDING)
# deprecated
# DeploymentState.user_remove
# returns True if no other deployment needs this state_item to be deployed
def user_remove(self):
......@@ -552,6 +594,7 @@ class DeploymentState(models.Model):
# True: signal the callee that a publish_to_client is permitted
return True
# deprecated
# user: questionnaire answered
def user_answers(self, answers=None):
if not self.deployments.exists():
......@@ -618,7 +661,7 @@ class DeploymentState(models.Model):
# publish after we updated the values of the response
self._set_state(state, publish=True)
if state == FAILED or state == REJECTED:
if self.state == FAILED or self.state == REJECTED or self.state == QUESTIONNAIRE:
return
# is the target reached now?
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment