Commit ba4b3b4c authored by Tristan Cavelier's avatar Tristan Cavelier

check_computer_memory: refactor getFreeMemory to fit code behavior

parent bd09f20e
...@@ -14,7 +14,7 @@ import datetime ...@@ -14,7 +14,7 @@ import datetime
from slapos.collect.db import Database from slapos.collect.db import Database
def getFreeMemory(database, time, date): def getMemoryInfo(database, time, date):
mem = {} mem = {}
database = Database(database) database = Database(database)
...@@ -55,7 +55,7 @@ def main(): ...@@ -55,7 +55,7 @@ def main():
db_path = args.collectordb db_path = args.collectordb
if db_path.endswith("collector.db"):db_path=db_path[:-len("collector.db")] if db_path.endswith("collector.db"):db_path=db_path[:-len("collector.db")]
memory, error = getFreeMemory(db_path, currenttime, currentdate) memory, error = getMemoryInfo(db_path, currenttime, currentdate)
if error: if error:
print error print error
return 0 return 0
......
...@@ -30,7 +30,7 @@ import os ...@@ -30,7 +30,7 @@ import os
import sqlite3 import sqlite3
from slapos.test.promise import data from slapos.test.promise import data
from slapos.promise.check_computer_memory import getFreeMemory from slapos.promise.check_computer_memory import getMemoryInfo
total_memory_fetch_failure_message = "couldn't fetch total memory, collectordb is empty?" total_memory_fetch_failure_message = "couldn't fetch total memory, collectordb is empty?"
...@@ -50,12 +50,12 @@ class TestComputerMemory(unittest.TestCase): ...@@ -50,12 +50,12 @@ class TestComputerMemory(unittest.TestCase):
def test_check_memory(self): def test_check_memory(self):
self.assertEquals(({'total': 33705312256.0, 'used': 33139023872.0, 'free': 566288384.0}, ""), self.assertEquals(({'total': 33705312256.0, 'used': 33139023872.0, 'free': 566288384.0}, ""),
getFreeMemory('/tmp', '00:02', '2017-09-15')) getMemoryInfo('/tmp', '00:02', '2017-09-15'))
def test_check_memory_with_unavailable_dates(self): def test_check_memory_with_unavailable_dates(self):
self.assertEquals( self.assertEquals(
(None, total_memory_fetch_failure_message), (None, total_memory_fetch_failure_message),
getFreeMemory('/tmp', '18:00', '2017-09-14'), getMemoryInfo('/tmp', '18:00', '2017-09-14'),
) )
def tearDown(self): def tearDown(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment