Skip to content

Commit

Permalink
Merge pull request #2089 from FroggyFlox/Issue2087_Restore_Service_St…
Browse files Browse the repository at this point in the history
…atus

[Config Backup/Restore] Restore Service status. Fixes #2087
  • Loading branch information
phillxnet authored Nov 30, 2019
2 parents ec3903d + 25f3e85 commit d64a4a3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
29 changes: 26 additions & 3 deletions src/rockstor/storageadmin/views/config_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import rest_framework_custom as rfc
from cli.rest_util import api_call
from smart_manager.models.service import Service, ServiceStatus
from storageadmin.models import ConfigBackup
from storageadmin.serializers import ConfigBackupSerializer
from storageadmin.util import handle_exception
Expand Down Expand Up @@ -138,15 +139,37 @@ def restore_services(ml):
if m["model"] == "smart_manager.service":
name = m["fields"]["name"]
config = m["fields"]["config"]
pkid = m["pk"]
if config is not None:
config = json.loads(config)
services[name] = {"config": config}
logger.debug("services = ({}).".format(services))
services[name] = {
"conf": {"config": config},
"id": pkid
}
for s in services:
generic_post("%s/sm/services/%s/config" % (BASE_URL, s), services[s])
generic_post("{}/sm/services/{}/config".format(BASE_URL, s), services[s]["conf"])
# Turn the service ON if it is ON in backup AND currently OFF
so = Service.objects.get(name=s)
if validate_service_status(ml, services[s]["id"]) and not \
ServiceStatus.objects.get(service_id=so.id).status:
generic_post("{}/sm/services/{}/start".format(BASE_URL, s), {})
logger.debug("Finished restoring services.")


def validate_service_status(ml, pkid):
"""
Parses a model list (ml) and returns True if the service identified by
its id (pkid) was ON in the config backup.
:param ml: dict of models list
:param pkid: int
:return: True
"""
for m in ml:
if m["model"] == 'smart_manager.servicestatus' and \
m["fields"]["service"] is pkid:
return m["fields"]["status"]


def restore_scheduled_tasks(ml):
"""
Parses the config backup to re-create a valid POST request to be sent to the
Expand Down
1 change: 1 addition & 0 deletions src/rockstor/system/config_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def backup_config():
],
"smart_manager": [
"service",
"servicestatus",
"taskdefinition"
],
}
Expand Down

0 comments on commit d64a4a3

Please sign in to comment.