Updated the DB cleaner to clean the host_resource_usage table as well
This commit is contained in:
parent
bd85baf977
commit
beacd650ca
11
neat/db.py
11
neat/db.py
@ -296,6 +296,17 @@ class Database(object):
|
||||
self.vm_resource_usage.delete().where(
|
||||
self.vm_resource_usage.c.timestamp < datetime_threshold))
|
||||
|
||||
@contract(datetime_threshold=datetime.datetime)
|
||||
def cleanup_host_resource_usage(self, datetime_threshold):
|
||||
""" Delete host resource usage data older than the threshold.
|
||||
|
||||
:param datetime_threshold: A datetime threshold.
|
||||
:type datetime_threshold: datetime.datetime
|
||||
"""
|
||||
self.connection.execute(
|
||||
self.host_resource_usage.delete().where(
|
||||
self.host_resource_usage.c.timestamp < datetime_threshold))
|
||||
|
||||
@contract
|
||||
def insert_host_states(self, hosts):
|
||||
""" Insert host states for a set of hosts.
|
||||
|
@ -89,6 +89,7 @@ def execute(config, state):
|
||||
"""
|
||||
datetime_threshold = today() - state['time_delta']
|
||||
state['db'].cleanup_vm_resource_usage(datetime_threshold)
|
||||
state['db'].cleanup_host_resource_usage(datetime_threshold)
|
||||
if log.isEnabledFor(logging.INFO):
|
||||
log.info('Cleaned up data older than %s',
|
||||
datetime_threshold.strftime('%Y-%m-%d %H:%M:%S'))
|
||||
|
@ -230,6 +230,22 @@ class Db(TestCase):
|
||||
db.cleanup_vm_resource_usage(time.replace(second=5))
|
||||
assert db.select_cpu_mhz_for_vm(uuid, 100) == range(5, 10)
|
||||
|
||||
@qc(1)
|
||||
def cleanup_host_resource_usage(
|
||||
hostname=str_(of='abc123', min_length=5, max_length=10)
|
||||
):
|
||||
db = db_utils.init_db('sqlite:///:memory:')
|
||||
host_id = db.update_host(hostname, 1, 1, 1)
|
||||
time = datetime.datetime.today()
|
||||
for i in range(10):
|
||||
db.host_resource_usage.insert().execute(
|
||||
host_id=1,
|
||||
cpu_mhz=i,
|
||||
timestamp=time.replace(second=i))
|
||||
assert db.select_cpu_mhz_for_host(hostname, 100) == range(10)
|
||||
db.cleanup_host_resource_usage(time.replace(second=5))
|
||||
assert db.select_cpu_mhz_for_host(hostname, 100) == range(5, 10)
|
||||
|
||||
def test_insert_host_states(self):
|
||||
db = db_utils.init_db('sqlite:///:memory:')
|
||||
hosts = {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user