diff --git a/database/test/proinfo_inventory.py b/database/test/proinfo_inventory.py index c85a2af9335a0f525fe9e0f02e75eba1306f0055..40bf370871fba761f82ccea7ad317e7aa82f8b13 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)