Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
feudalBackend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
16
Issues
16
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
feudal
feudalBackend
Commits
762f7dd8
Commit
762f7dd8
authored
Jun 18, 2018
by
Lukas Burgey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename ..Task to ..State
parent
ca3d7553
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
137 additions
and
137 deletions
+137
-137
django_backend/backend/clientapi/serializers.py
django_backend/backend/clientapi/serializers.py
+2
-2
django_backend/backend/clientapi/urls.py
django_backend/backend/clientapi/urls.py
+1
-1
django_backend/backend/clientapi/views.py
django_backend/backend/clientapi/views.py
+21
-21
django_backend/backend/frontend/serializers.py
django_backend/backend/frontend/serializers.py
+10
-10
django_backend/backend/frontend/views.py
django_backend/backend/frontend/views.py
+3
-3
django_backend/backend/models.py
django_backend/backend/models.py
+95
-95
django_backend/backend/test_models.py
django_backend/backend/test_models.py
+5
-5
No files found.
django_backend/backend/clientapi/serializers.py
View file @
762f7dd8
...
...
@@ -40,7 +40,7 @@ class DeploymentsSerializer(serializers.Serializer):
)
class
Deployment
Task
Serializer
(
serializers
.
Serializer
):
class
Deployment
State
Serializer
(
serializers
.
Serializer
):
id
=
serializers
.
IntegerField
()
action
=
serializers
.
CharField
()
user
=
UserSerializer
()
...
...
@@ -49,7 +49,7 @@ class DeploymentTaskSerializer(serializers.Serializer):
class
SiteSerializer
(
serializers
.
Serializer
):
tasks
=
DeploymentTask
Serializer
(
many
=
True
)
states
=
DeploymentState
Serializer
(
many
=
True
)
class
RabbitMQInstanceSerializer
(
serializers
.
ModelSerializer
):
...
...
django_backend/backend/clientapi/urls.py
View file @
762f7dd8
...
...
@@ -4,6 +4,6 @@ from . import views
URLPATTERNS
=
[
url
(
r
'^deployments'
,
views
.
DeploymentsView
.
as_view
()),
url
(
r
'^config'
,
views
.
ConfigurationView
.
as_view
()),
url
(
r
'^ack/(?P<
task
_id>\d+)'
,
views
.
AckView
.
as_view
()),
url
(
r
'^ack/(?P<
state
_id>\d+)'
,
views
.
AckView
.
as_view
()),
url
(
r
'^response'
,
views
.
ResponseView
.
as_view
()),
]
django_backend/backend/clientapi/views.py
View file @
762f7dd8
...
...
@@ -3,7 +3,7 @@ import logging
from
rest_framework
import
generics
,
views
from
rest_framework.authentication
import
BasicAuthentication
from
rest_framework.response
import
Response
from
.serializers
import
Deployment
Task
Serializer
,
ServiceSerializer
,
RabbitMQInstanceSerializer
from
.serializers
import
Deployment
State
Serializer
,
ServiceSerializer
,
RabbitMQInstanceSerializer
from
..models
import
RabbitMQInstance
LOGGER
=
logging
.
getLogger
(
__name__
)
...
...
@@ -15,10 +15,10 @@ AUTHENTICATION_CLASSES = (BasicAuthentication, )
class
DeploymentsView
(
generics
.
ListAPIView
):
authentication_classes
=
AUTHENTICATION_CLASSES
serializer_class
=
Deployment
Task
Serializer
serializer_class
=
Deployment
State
Serializer
def
get_queryset
(
self
):
return
self
.
request
.
user
.
site
.
task
s
return
self
.
request
.
user
.
site
.
state
s
# the client has to fetch the configuration (like services etc.) here
...
...
@@ -42,15 +42,15 @@ class ConfigurationView(views.APIView):
class
AckView
(
views
.
APIView
):
authentication_classes
=
AUTHENTICATION_CLASSES
def
delete
(
self
,
request
,
task
_id
=
None
):
# find the corresponding
task
for this item
for
item
in
request
.
user
.
site
.
task
_items
.
all
():
if
item
.
task
.
id
==
int
(
task
_id
):
def
delete
(
self
,
request
,
state
_id
=
None
):
# find the corresponding
state
for this item
for
item
in
request
.
user
.
site
.
state
_items
.
all
():
if
item
.
state
.
id
==
int
(
state
_id
):
item
.
success
()
return
Response
({
'ok'
:
True
})
# this is no critical
LOGGER
.
info
(
'%s executed the obsolete
task#%s'
,
request
.
user
,
task
_id
)
LOGGER
.
info
(
'%s executed the obsolete
state#%s'
,
request
.
user
,
state
_id
)
return
Response
({
'ok'
:
True
})
...
...
@@ -60,33 +60,33 @@ class ResponseView(views.APIView):
def
post
(
self
,
request
):
output
=
request
.
data
[
'output'
]
status
=
output
[
'status'
]
task
_id
=
request
.
data
[
'id'
]
state
_id
=
request
.
data
[
'id'
]
LOGGER
.
debug
(
'%s responded to
task %s:
\n
%s'
,
request
.
user
,
task
_id
,
request
.
data
)
LOGGER
.
debug
(
'%s responded to
state %s:
\n
%s'
,
request
.
user
,
state
_id
,
request
.
data
)
# find the corresponding
task
for this item
task
_item
=
None
for
item
in
request
.
user
.
site
.
task
_items
.
all
():
if
item
.
task
.
id
==
int
(
task
_id
):
task
_item
=
item
# find the corresponding
state
for this item
state
_item
=
None
for
item
in
request
.
user
.
site
.
state
_items
.
all
():
if
item
.
state
.
id
==
int
(
state
_id
):
state
_item
=
item
if
task
_item
is
not
None
:
if
state
_item
is
not
None
:
if
status
==
'success'
:
task
_item
.
success
(
state
_item
.
success
(
credentials
=
request
.
data
.
output
.
get
(
'credentials'
,
None
),
)
return
Response
({})
elif
status
==
'fail'
:
task
_item
.
failed
()
state
_item
.
failed
()
return
Response
({})
elif
status
==
'reject'
:
task
_item
.
rejected
(
output
[
'questionnaire'
])
state
_item
.
rejected
(
output
[
'questionnaire'
])
return
Response
({})
LOGGER
.
info
(
'%s executed the obsolete
task#%s'
,
request
.
user
,
task
_id
)
LOGGER
.
info
(
'%s executed the obsolete
state#%s'
,
request
.
user
,
state
_id
)
return
Response
(
data
=
{
'error'
:
'obsolete_
task
'
},
data
=
{
'error'
:
'obsolete_
state
'
},
status
=
500
,
)
django_backend/backend/frontend/serializers.py
View file @
762f7dd8
...
...
@@ -20,14 +20,14 @@ class ServiceSerializer(serializers.ModelSerializer):
exclude
=
[]
class
Deployment
Task
ItemSerializer
(
serializers
.
ModelSerializer
):
class
Deployment
State
ItemSerializer
(
serializers
.
ModelSerializer
):
service
=
ServiceSerializer
()
key
=
backend_serializers
.
SSHPublicKeySerializerB
()
site
=
SiteSerializer
()
questionnaire
=
serializers
.
JSONField
()
class
Meta
:
model
=
models
.
Deployment
Task
Item
model
=
models
.
Deployment
State
Item
fields
=
[
'action'
,
'key'
,
...
...
@@ -39,11 +39,11 @@ class DeploymentTaskItemSerializer(serializers.ModelSerializer):
]
class
Deployment
Task
Serializer
(
serializers
.
ModelSerializer
):
class
Deployment
State
Serializer
(
serializers
.
ModelSerializer
):
key
=
backend_serializers
.
SSHPublicKeySerializerB
()
service
=
ServiceSerializer
()
class
Meta
:
model
=
models
.
Deployment
Task
model
=
models
.
Deployment
State
fields
=
[
'action'
,
'key'
,
...
...
@@ -56,8 +56,8 @@ class DeploymentSerializer(serializers.Serializer):
service
=
ServiceSerializer
()
ssh_keys
=
backend_serializers
.
SSHPublicKeySerializer
(
many
=
True
)
ssh_keys_to_withdraw
=
backend_serializers
.
SSHPublicKeySerializer
(
many
=
True
)
deploys
=
Deployment
Task
Serializer
(
many
=
True
)
withdrawals
=
Deployment
Task
Serializer
(
many
=
True
)
deploys
=
Deployment
State
Serializer
(
many
=
True
)
withdrawals
=
Deployment
State
Serializer
(
many
=
True
)
class
Meta
:
model
=
models
.
Deployment
...
...
@@ -76,8 +76,8 @@ class UserSerializer(serializers.ModelSerializer):
ssh_keys
=
backend_serializers
.
SSHPublicKeySerializer
(
many
=
True
)
deployments
=
DeploymentSerializer
(
many
=
True
)
auth_groups
=
backend_serializers
.
AuthGroupSerializer
(
many
=
True
)
deployment_
tasks
=
DeploymentTask
Serializer
(
many
=
True
)
deployment_
task_items
=
DeploymentTask
ItemSerializer
(
many
=
True
)
deployment_
states
=
DeploymentState
Serializer
(
many
=
True
)
deployment_
state_items
=
DeploymentState
ItemSerializer
(
many
=
True
)
class
Meta
:
model
=
models
.
User
...
...
@@ -89,8 +89,8 @@ class UserSerializer(serializers.ModelSerializer):
'groups'
,
'deployments'
,
'auth_groups'
,
'deployment_
task
s'
,
'deployment_
task
_items'
,
'deployment_
state
s'
,
'deployment_
state
_items'
,
]
...
...
django_backend/backend/frontend/views.py
View file @
762f7dd8
...
...
@@ -131,9 +131,9 @@ class DeploymentView(views.APIView):
class
QuestionnaireView
(
views
.
APIView
):
def
post
(
self
,
request
):
task
_item_id
=
request
.
query_params
.
get
(
'id'
,
''
)
if
task
_item_id
!=
''
:
item
=
models
.
Deployment
TaskItem
.
objects
.
filter
(
id
=
int
(
task
_item_id
))
state
_item_id
=
request
.
query_params
.
get
(
'id'
,
''
)
if
state
_item_id
!=
''
:
item
=
models
.
Deployment
StateItem
.
objects
.
filter
(
id
=
int
(
state
_item_id
))
if
item
.
exists
():
item
.
first
().
questionnaire_answered
(
answers
=
request
.
data
,
...
...
django_backend/backend/models.py
View file @
762f7dd8
...
...
@@ -330,7 +330,7 @@ class User(AbstractUser):
self
.
deactivate
()
# FIXME: deleting the user brings problems:
# the deletion cascades down to Deployment
Task and DeploymentTask
Item
# the deletion cascades down to Deployment
State and DeploymentState
Item
# but these need to be conserved so all clients withdrawals can be tracked
LOGGER
.
info
(
self
.
msg
(
'Deleting'
))
self
.
delete
()
...
...
@@ -399,15 +399,15 @@ class Site(models.Model):
def
__str__
(
self
):
return
self
.
name
#
task
s which are still to be executed on this site
#
state
s which are still to be executed on this site
@
property
def
task
s
(
self
):
task_items
=
self
.
task
_items
.
filter
(
state
=
'pending'
)
\
|
self
.
task
_items
.
filter
(
state
=
'failed'
)
\
|
self
.
task
_items
.
filter
(
state
=
'answered'
)
return
[
item
.
task
def
state
s
(
self
):
state_items
=
self
.
state
_items
.
filter
(
state
=
'pending'
)
\
|
self
.
state
_items
.
filter
(
state
=
'failed'
)
\
|
self
.
state
_items
.
filter
(
state
=
'answered'
)
return
[
item
.
state
for
item
in
task
_items
]
in
state
_items
]
class
Service
(
models
.
Model
):
...
...
@@ -458,7 +458,7 @@ class SSHPublicKey(models.Model):
# somewhere
# the receiver 'delete_withdrawn_ssh_key' does the actual deletion
def
delete_key
(
self
):
if
(
not
self
.
task
s
.
exists
()
and
not
self
.
deployments
.
exists
()):
if
(
not
self
.
state
s
.
exists
()
and
not
self
.
deployments
.
exists
()):
LOGGER
.
info
(
self
.
msg
(
'Direct deletion of key'
))
self
.
delete
()
return
...
...
@@ -473,7 +473,7 @@ class SSHPublicKey(models.Model):
# when a key is withdrawn by a client we try to finally delete it
def
try_final_deletion
(
self
):
if
(
self
.
deleted
and
not
self
.
task
s
.
exists
()):
if
(
self
.
deleted
and
not
self
.
state
s
.
exists
()):
LOGGER
.
info
(
self
.
msg
(
'All clients have withdrawn this key. Final deletion'
))
self
.
delete
()
...
...
@@ -490,8 +490,8 @@ class SSHPublicKey(models.Model):
# (exception: if is_active=False the ssh_keys contain the keys to be deployed
# if the deployment is reactivated)
#
# Deployment
Task
is what is sent to the clients via rabbitmq
# The Deployment
Task
Item track the acknowledgements from the clients
# Deployment
State
is what is sent to the clients via rabbitmq
# The Deployment
State
Item track the acknowledgements from the clients
class
Deployment
(
models
.
Model
):
user
=
models
.
ForeignKey
(
User
,
...
...
@@ -539,11 +539,11 @@ class Deployment(models.Model):
@
property
def
withdrawals
(
self
):
return
self
.
task
s
.
filter
(
action
=
'withdraw'
)
return
self
.
state
s
.
filter
(
action
=
'withdraw'
)
@
property
def
deploys
(
self
):
return
self
.
task
s
.
filter
(
action
=
'deploy'
)
return
self
.
state
s
.
filter
(
action
=
'deploy'
)
def
__str__
(
self
):
return
'{}:{}'
.
format
(
self
.
service
,
self
.
user
)
...
...
@@ -581,21 +581,21 @@ class Deployment(models.Model):
# only deploy the key
def
_deploy_key
(
self
,
key
):
task
=
DeploymentTask
.
construct_deployment_task
(
state
=
DeploymentState
.
construct_deployment_state
(
deployment
=
self
,
key
=
key
,
)
# publish the
task
task
.
publish
()
# publish the
state
state
.
publish
()
def
_withdraw_key
(
self
,
key
):
task
=
DeploymentTask
.
construct_withdrawal_task
(
state
=
DeploymentState
.
construct_withdrawal_state
(
deployment
=
self
,
key
=
key
,
)
# publish the
task
task
.
publish
()
# publish the
state
state
.
publish
()
# deploy key and track changes in the key lists
def
deploy_key
(
self
,
key
):
...
...
@@ -633,9 +633,9 @@ def invert_action(action):
return
'deploy'
# Deployment
Task
: knows:
# Deployment
State
: knows:
# user, service, key, action
class
Deployment
Task
(
models
.
Model
):
class
Deployment
State
(
models
.
Model
):
ACTION_CHOICES
=
(
(
'deploy'
,
'deploy'
),
(
'withdraw'
,
'withdraw'
),
...
...
@@ -646,38 +646,38 @@ class DeploymentTask(models.Model):
)
key
=
models
.
ForeignKey
(
SSHPublicKey
,
related_name
=
'
task
s'
,
related_name
=
'
state
s'
,
on_delete
=
models
.
CASCADE
,
)
deployment
=
models
.
ForeignKey
(
Deployment
,
related_name
=
'
task
s'
,
related_name
=
'
state
s'
,
on_delete
=
models
.
CASCADE
,
)
user
=
models
.
ForeignKey
(
User
,
related_name
=
'deployment_
task
s'
,
related_name
=
'deployment_
state
s'
,
on_delete
=
models
.
CASCADE
,
)
# the inverse action of this
task
is requirred
# so we invert the
task and manage its task
_items accordingly
def
invert_
task
(
self
):
# the inverse action of this
state
is requirred
# so we invert the
state and manage its state
_items accordingly
def
invert_
state
(
self
):
LOGGER
.
debug
(
self
.
msg
(
'inverting'
))
previous_action
=
self
.
action
self
.
action
=
invert_action
(
previous_action
)
self
.
save
()
pending_sites
=
[
task
.
site
for
task
in
self
.
task
_items
.
all
()]
pending_sites
=
[
state
.
site
for
state
in
self
.
state
_items
.
all
()]
self
.
chancel_items
()
# sites which already executed the
task
# sites which already executed the
state
# we have to send them an order to rollback the changes
for
site
in
self
.
deployment
.
service
.
site
.
all
():
if
site
not
in
pending_sites
:
deploy
=
Deployment
Task
Item
(
task
=
self
,
deploy
=
Deployment
State
Item
(
state
=
self
,
site
=
site
,
user
=
self
.
deployment
.
user
)
...
...
@@ -685,83 +685,83 @@ class DeploymentTask(models.Model):
LOGGER
.
debug
(
deploy
.
msg
(
'pending'
))
@
classmethod
def
construct_deployment_
task
(
cls
,
deployment
,
key
):
# does a
task
exist for this key?
query
=
deployment
.
task
s
.
filter
(
key
=
key
)
def
construct_deployment_
state
(
cls
,
deployment
,
key
):
# does a
state
exist for this key?
query
=
deployment
.
state
s
.
filter
(
key
=
key
)
if
query
.
exists
():
if
len
(
query
)
>
1
:
raise
Exception
(
'Unexpected query result'
)
task
=
query
.
first
()
if
task
.
action
==
'deploy'
:
raise
Exception
(
'Constructing deployment
task
when one already exists'
)
state
=
query
.
first
()
if
state
.
action
==
'deploy'
:
raise
Exception
(
'Constructing deployment
state
when one already exists'
)
task
.
invert_task
()
return
task
state
.
invert_state
()
return
state
else
:
#create new
task
task
=
cls
(
#create new
state
state
=
cls
(
action
=
'deploy'
,
deployment
=
deployment
,
key
=
key
,
user
=
deployment
.
user
,
)
task
.
save
()
LOGGER
.
debug
(
task
.
msg
(
'pending'
))
state
.
save
()
LOGGER
.
debug
(
state
.
msg
(
'pending'
))
# generate
task
items
# generate
state
items
for
site
in
deployment
.
service
.
site
.
all
():
deploy
=
Deployment
Task
Item
(
task
=
task
,
deploy
=
Deployment
State
Item
(
state
=
state
,
site
=
site
,
user
=
deployment
.
user
)
deploy
.
save
()
LOGGER
.
debug
(
deploy
.
msg
(
'pending'
))
return
task
return
state
@
classmethod
def
construct_withdrawal_
task
(
cls
,
deployment
,
key
):
# does a
task
exist for this key?
query
=
deployment
.
task
s
.
filter
(
key
=
key
)
def
construct_withdrawal_
state
(
cls
,
deployment
,
key
):
# does a
state
exist for this key?
query
=
deployment
.
state
s
.
filter
(
key
=
key
)
if
query
.
exists
():
if
len
(
query
)
>
1
:
raise
Exception
(
'Unexpected query result'
)
task
=
query
.
first
()
if
task
.
action
==
'withdraw'
:
raise
Exception
(
'Constructing deployment
task
when one already exists'
)
state
=
query
.
first
()
if
state
.
action
==
'withdraw'
:
raise
Exception
(
'Constructing deployment
state
when one already exists'
)
task
.
invert_task
()
return
task
state
.
invert_state
()
return
state
else
:
# create a new
task
task
=
cls
(
# create a new
state
state
=
cls
(
action
=
'withdraw'
,
deployment
=
deployment
,
key
=
key
,
user
=
deployment
.
user
,
)
task
.
save
()
LOGGER
.
debug
(
task
.
msg
(
'pending'
))
state
.
save
()
LOGGER
.
debug
(
state
.
msg
(
'pending'
))
# generate
task
items
# generate
state
items
for
site
in
deployment
.
service
.
site
.
all
():
deploy
=
Deployment
Task
Item
(
task
=
task
,
deploy
=
Deployment
State
Item
(
state
=
state
,
site
=
site
,
user
=
deployment
.
user
)
deploy
.
save
()
LOGGER
.
debug
(
deploy
.
msg
(
'pending'
))
return
task
return
state
def
chancel_items
(
self
):
for
item
in
self
.
task
_items
.
all
():
for
item
in
self
.
state
_items
.
all
():
item
.
chancel
()
def
chancel
(
self
):
...
...
@@ -781,12 +781,12 @@ class DeploymentTask(models.Model):
)
def
msg
(
self
,
msg
):
return
'[D
eploymentTask
:{}] {}'
.
format
(
self
,
msg
)
return
'[D
State
:{}] {}'
.
format
(
self
,
msg
)
def
publish
(
self
):
# mitigating circular dependencies here
from
.clientapi.serializers
import
Deployment
Task
Serializer
msg
=
json
.
dumps
(
Deployment
Task
Serializer
(
self
).
data
)
from
.clientapi.serializers
import
Deployment
State
Serializer
msg
=
json
.
dumps
(
Deployment
State
Serializer
(
self
).
data
)
RabbitMQInstance
.
load
().
publish_by_service
(
self
.
service
,
...
...
@@ -805,11 +805,11 @@ class DeploymentTask(models.Model):
)
def
try_finished
(
self
):
if
not
self
.
task
_items
.
exists
():
if
not
self
.
state
_items
.
exists
():
# finished sends its own message
self
.
_finished
()
# maintenance after all
task
items are done
# maintenance after all
state
items are done
def
_finished
(
self
):
LOGGER
.
info
(
self
.
msg
(
'done'
))
...
...
@@ -842,22 +842,22 @@ def questionnaire_default():
def
credential_default
():
return
{}
# Deployment
Task
Item: knows:
# Deployment
State
Item: knows:
# user, service, key, action, _and_ site
class
Deployment
Task
Item
(
models
.
Model
):
task
=
models
.
ForeignKey
(
Deployment
Task
,
related_name
=
'
task
_items'
,
class
Deployment
State
Item
(
models
.
Model
):
state
=
models
.
ForeignKey
(
Deployment
State
,
related_name
=
'
state
_items'
,
on_delete
=
models
.
CASCADE
,
)
site
=
models
.
ForeignKey
(
Site
,
related_name
=
'
task
_items'
,
related_name
=
'
state
_items'
,
on_delete
=
models
.
CASCADE
,
)
user
=
models
.
ForeignKey
(
User
,
related_name
=
'deployment_
task
_items'
,
related_name
=
'deployment_
state
_items'
,
on_delete
=
models
.
CASCADE
,
)
STATE_CHOICES
=
(
...
...
@@ -888,40 +888,40 @@ class DeploymentTaskItem(models.Model):
@
property
def
service
(
self
):
return
self
.
task
.
service
return
self
.
state
.
service
@
property
def
key
(
self
):
return
self
.
task
.
key
return
self
.
state
.
key
@
property
def
action
(
self
):
return
self
.
deployment
.
key
# the client acked the receipt and execution of the
task
for his site
# the client acked the receipt and execution of the
state
for his site
def
success
(
self
,
credentials
=
None
):
task
=
self
.
task
state
=
self
.
state
self
.
credentials
=
credentials
self
.
save
()
LOGGER
.
debug
(
self
.
msg
(
'success'
))
# TODO test: does not deleting the
task
item work?
# TODO test: does not deleting the
state
item work?
# self.delete()
task
.
send_state_update
()
state
.
send_state_update
()
# TODO test: does not deleting the
task
work?
#
task
.try_finished()
# TODO test: does not deleting the
state
work?
#
state
.try_finished()
# the user changed the deployment
# chancel (delete) this
task
item
# chancel (delete) this
state
item
def
chancel
(
self
):
LOGGER
.
debug
(
self
.
msg
(
'chanceled'
))
self
.
delete
()
# no update on chancel
# the next
task
will send an update
#
task
.send_state_update()
# the next
state
will send an update
#
state
.send_state_update()
# the client failed to execute the item
# the client can try again later
...
...
@@ -931,7 +931,7 @@ class DeploymentTaskItem(models.Model):
self
.
state
=
'failed'
self
.
save
()
self
.
task
.
send_state_update
()
self
.
state
.
send_state_update
()
# the client failed to execute the item
# the client needs additional information from the user to try again
...
...
@@ -942,7 +942,7 @@ class DeploymentTaskItem(models.Model):
self
.
questionnaire
=
questionnaire
self
.
save
()
self
.
task
.
send_state_update
()
self
.
state
.
send_state_update
()
def
questionnaire_answered
(
self
,
answers
=
None
):
LOGGER
.
debug
(
'%s %s'
,
self
.
msg
(
'answers'
),
answers
)
...
...
@@ -950,14 +950,14 @@ class DeploymentTaskItem(models.Model):
self
.
questionnaire
=
answers
self
.
save
()
# publish the
task
item
# publish the
state
item
self
.
publish
()
# only used when we got a questionnaire_answered
def
publish
(
self
):
# mitigating circular dependencies here
from
.clientapi.serializers
import
Deployment
Task
Serializer
data
=
Deployment
TaskSerializer
(
self
.
task
).
data
from
.clientapi.serializers
import
Deployment
State
Serializer
data
=
Deployment
StateSerializer
(
self
.
state
).
data
data
[
'questionnaire'
]
=
self
.
questionnaire
RabbitMQInstance
.
load
().
publish_by_site
(
...
...
@@ -968,13 +968,13 @@ class DeploymentTaskItem(models.Model):
def
__str__
(
self
):
return
"{}@{}#{}"
.
format
(
self
.
task
,
self
.
state
,
self
.
site
,
self
.
id
,
)
def
msg
(
self
,
msg
):
return
'[D
epl. Task
Item:{}] {}'
.
format
(
self
,
msg
)
return
'[D
S
Item:{}] {}'
.
format
(
self
,
msg
)
#
...
...
django_backend/backend/test_models.py