Added atexit.register(flush) for DB and Connections

This commit is contained in:
Przemyslaw Kaminski 2015-06-03 12:03:44 +02:00
parent 2abd8a6b40
commit 15aeb9c7a0
3 changed files with 9 additions and 3 deletions

View File

@ -168,9 +168,6 @@ def deploy():
signals.connect(keystone_config1, glance_api_endpoint, {'admin_token': 'admin_token'}) signals.connect(keystone_config1, glance_api_endpoint, {'admin_token': 'admin_token'})
signals.connect(keystone_service1, glance_api_endpoint, {'ip': 'keystone_host', 'admin_port': 'keystone_port'}) signals.connect(keystone_service1, glance_api_endpoint, {'ip': 'keystone_host', 'admin_port': 'keystone_port'})
if hasattr(db, 'flush'):
db.flush()
signals.Connections.flush() signals.Connections.flush()

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import atexit
from collections import defaultdict from collections import defaultdict
import itertools import itertools
import networkx as nx import networkx as nx
@ -67,9 +68,13 @@ class Connections(object):
@staticmethod @staticmethod
def flush(): def flush():
print 'FLUSHING Connections'
utils.save_to_config_file(CLIENTS_CONFIG_KEY, CLIENTS) utils.save_to_config_file(CLIENTS_CONFIG_KEY, CLIENTS)
atexit.register(Connections.flush)
def guess_mapping(emitter, receiver): def guess_mapping(emitter, receiver):
"""Guess connection mapping between emitter and receiver. """Guess connection mapping between emitter and receiver.

View File

@ -1,5 +1,6 @@
from solar.third_party.dir_dbm import DirDBM from solar.third_party.dir_dbm import DirDBM
import atexit
import os import os
import types import types
import yaml import yaml
@ -19,6 +20,8 @@ class CachedFileSystemDB(DirDBM):
super(CachedFileSystemDB, self).__init__(self.STORAGE_PATH) super(CachedFileSystemDB, self).__init__(self.STORAGE_PATH)
self.entities = {} self.entities = {}
atexit.register(self.flush)
def __setitem__(self, k, v): def __setitem__(self, k, v):
""" """
C{dirdbm[k] = v} C{dirdbm[k] = v}
@ -102,5 +105,6 @@ class CachedFileSystemDB(DirDBM):
return key return key
def flush(self): def flush(self):
print 'FLUSHING DB'
for path, data in self._CACHE.items(): for path, data in self._CACHE.items():
super(CachedFileSystemDB, self)._writeFile(path, yaml.dump(data)) super(CachedFileSystemDB, self)._writeFile(path, yaml.dump(data))