From d6c80b5dc90ec9d71759d17cb1dce1e1b2518323 Mon Sep 17 00:00:00 2001 From: Rafael de Lima Prado <rlp09@inf.ufpr.br> Date: Wed, 6 Mar 2013 10:56:36 -0300 Subject: [PATCH] Improved proinfo_test to fail some machines Signed-off-by: Rafael de Lima Prado <rlp09@inf.ufpr.br> --- database/test/proinfo_inventory.py | 35 +++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/database/test/proinfo_inventory.py b/database/test/proinfo_inventory.py index c85a2af..40bf370 100755 --- a/database/test/proinfo_inventory.py +++ b/database/test/proinfo_inventory.py @@ -8,7 +8,9 @@ import unittest # TODO: Unit tests MACHINE_PEAK = 10000 -DAYS = 3 +DAYS = 4 +NUM_REMOVE_MACHINE = 5 +FIRST_MAC_REMOVE = 2 MACHINE_DOUBLE_COMM_RATIO = 0.12 MACHINE_MULTI_COMM_RATIO = 0.02 MACHINE_DECREASE_RATIO = 1.1 @@ -35,7 +37,7 @@ WHERE i.macaddr = %s AND s.id = i.sch_id AND s.inep = %s''', (mac, INEP)) def insert_data(cur): for day in range(DAYS): - machines = machine_increase(day) + machines = machine_increase(day + 1) refresh_machines(machines, day, cur) return max_machine(machines, DAYS - 1) @@ -52,18 +54,31 @@ def gen_macaddress(integer): p4 = (integer & 2147483647) >> 24 return "00:00:" + toHex(p4) + ":" + toHex(p3) + ":" + toHex(p2) + ":" + toHex(p1) +def insert_machine(machine, day, cur, contact): + macaddr = gen_macaddress(machine) +# print "Mac {0}".format(macaddr) + if machine < MULTI_HD_TOTAL: + cur.execute(TEMPLATE, (contact, macaddr, HD_MODEL, HD_SIZE, HD_USED, HD_EXTRA)) + else: + cur.execute(TEMPLATE, (contact, macaddr, None, None, None, 0)) + + +def fail_machines(machine, day): + if machine >= FIRST_MAC_REMOVE + day and machine < FIRST_MAC_REMOVE + NUM_REMOVE_MACHINE + day: + return 0 + else: + return 1 + def refresh_machines(machines, day, cur): contact = INITIAL_DATE + timedelta(days = day) for i in updated_machines(machines, day): - macaddr = gen_macaddress(i) -# print "Mac {0}".format(macaddr) - if i < MULTI_HD_TOTAL: - cur.execute(TEMPLATE, (contact, macaddr, HD_MODEL, HD_SIZE, HD_USED, HD_EXTRA)) - else: - cur.execute(TEMPLATE, (contact, macaddr, None, None, None, 0)) + if day % 2 == 0: + insert_machine(i, day, cur, contact) + elif fail_machines(i, day): + insert_machine(i, day, cur, contact) def max_machine(machines, day): - return intround(machines / (MACHINE_DECREASE_RATIO * (day + 1))) + return intround(machines) def intround(f): return int(round(f)) @@ -90,7 +105,7 @@ def get_connection(dbname, user): if __name__ == '__main__': if len(sys.argv) != 3: - sys.exit("Usage: {0} <database> <user>".format(sys.argv[0])) + sys.exit ("How to use: test_migration <database> <user>") connection = get_connection(sys.argv[1], sys.argv[2]) cur = connection.cursor() count = insert_data(cur) -- GitLab