-
-
Notifications
You must be signed in to change notification settings - Fork 194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feature] Implemented device deactivation and reactivation #625 #840
Conversation
2c16d95
to
5f9523f
Compare
@@ -368,7 +368,6 @@ def update_config(self): | |||
except Exception as e: | |||
logger.exception(e) | |||
else: | |||
self.device.config.set_status_applied() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nemesifier why do we need this? It is creating an issue for marking the device as deactivated. Instead of changing the status from deactivating to deactivated, this code is changing the status to applied. Can we rely on the report status request from the agent for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, proceed, there may be some test to change because of this removal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4382340
to
b427efd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good!
I did a quick code review, find my comments below.
Please let's take advantage to introduce the improvement discussed yesterday:
diff --git a/openwisp_controller/config/admin.py b/openwisp_controller/config/admin.py
index 764ae7f..cd573fb 100644
--- a/openwisp_controller/config/admin.py
+++ b/openwisp_controller/config/admin.py
@@ -641,6 +641,10 @@ class DeviceAdmin(MultitenantAdminMixin, BaseConfigAdmin, UUIDAdmin):
ip.short_description = _('IP address')
def config_status(self, obj):
+ if obj.is_deactivated:
+ return _('deactivated')
+ if not obj.config:
+ return _('unknown')
return obj.config.status
config_status.short_description = _('config status')
Another note:
Can we hide the save and save continue button on deactivated devices?
What else is missing?
- Do not allow to delete devices which are not deactivated first via admin action
- Admin inlines
- It would be great to show the readonly config value as indented JSON (now it shows
OrderedDict(...)
).
API changes:
- Disable API endpoints to make changes to deactivated devices
- I think we need to allow to enable and disable a device via API too, right?
We could split the API changes in a separate issue but we need to discuss this first
Anything else?
acef298
to
bbeb197
Compare
bbeb197
to
f26be19
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update the checklist in this PR.
I see the following item: "add an admin action which sets the config status to applied;" did we discuss adding such an action? To flag the config as applied? Or what did we mean here?
Please also rebase on the latest master, updating docs and code formatting.
Can you please also double check if there's any other documentation section we need to add or if it's worth mentioning this in some other page?
I believe there's a typo in the point. Instead of "setting config status to applied", the admin action should be to activate the device. And this has been already implemented. |
docs/developer/utils.rst
Outdated
|
||
- ``instance``: instance of the device being deactivated | ||
|
||
This signal is emitted when a device is deactivated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this emitted right when the device is flagged for deactivation or when the deactivation is complete?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is sent when the device is flagged for deactivation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, please clarify this in the text when you can.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After merging with the latest master and removing the reference to the openwisp-utils branch which was already merged, the feature is not working as expected anymore :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a few questions below.
|
||
if action == 'post_clear': | ||
if instance.is_deactivating_or_deactivated(): | ||
# If the config is being deactivating or deactivated, then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# If the config is being deactivating or deactivated, then | |
# If the device is deactivated or in the process of deactivatiing, then |
not self.is_deactivated() | ||
or (self._has_config() and not self.config.is_deactivated()) | ||
): | ||
raise PermissionDenied('The device should be deactivated before deleting') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
raise PermissionDenied('The device should be deactivated before deleting') | |
raise PermissionDenied('The device must be deactivated prior to deletion') |
if self._has_config(): | ||
self.config.set_status_deactivating() | ||
self._is_deactivated = True | ||
self.management_ip = '' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's clear the management IP only once the deactivation is completed. This way we can speed up the deactivation because if the management IP is set, openwisp may be able to SSH into the device and remove the configuration faster.
d83d03a
to
4e891cc
Compare
4e891cc
to
10ef8df
Compare
d2f0642
to
e358125
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's reapply all default templates when a device is activated again: shared default and required templates, org default and required templates, group templates if the device has any group, also tagged.
I think the best solution would be to basically register it again, without triggering the notification and register signal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should take advantage of this chance and add a docs page similar to what we have in the monitoring module: https://openwisp.io/docs/dev/monitoring/user/device-health-status.html, which lists the possible config status options and explains them briefly.
12a58f5
to
ca8eab9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update the rest-api.rst docs file:
- Add new endpoints
- Update delete device endpoint to mention the device needs to be deactivated first or it will return 403
f40f43b
to
8c12801
Compare
Closes #625
Blockers
TODOS