Skip to content
Snippets Groups Projects
Commit d6c80b5d authored by Rafael De Lima Prado's avatar Rafael De Lima Prado
Browse files

Improved proinfo_test to fail some machines

parent e548962d
Branches
No related tags found
No related merge requests found
...@@ -8,7 +8,9 @@ import unittest ...@@ -8,7 +8,9 @@ import unittest
# TODO: Unit tests # TODO: Unit tests
MACHINE_PEAK = 10000 MACHINE_PEAK = 10000
DAYS = 3 DAYS = 4
NUM_REMOVE_MACHINE = 5
FIRST_MAC_REMOVE = 2
MACHINE_DOUBLE_COMM_RATIO = 0.12 MACHINE_DOUBLE_COMM_RATIO = 0.12
MACHINE_MULTI_COMM_RATIO = 0.02 MACHINE_MULTI_COMM_RATIO = 0.02
MACHINE_DECREASE_RATIO = 1.1 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)) ...@@ -35,7 +37,7 @@ WHERE i.macaddr = %s AND s.id = i.sch_id AND s.inep = %s''', (mac, INEP))
def insert_data(cur): def insert_data(cur):
for day in range(DAYS): for day in range(DAYS):
machines = machine_increase(day) machines = machine_increase(day + 1)
refresh_machines(machines, day, cur) refresh_machines(machines, day, cur)
return max_machine(machines, DAYS - 1) return max_machine(machines, DAYS - 1)
...@@ -52,18 +54,31 @@ def gen_macaddress(integer): ...@@ -52,18 +54,31 @@ def gen_macaddress(integer):
p4 = (integer & 2147483647) >> 24 p4 = (integer & 2147483647) >> 24
return "00:00:" + toHex(p4) + ":" + toHex(p3) + ":" + toHex(p2) + ":" + toHex(p1) return "00:00:" + toHex(p4) + ":" + toHex(p3) + ":" + toHex(p2) + ":" + toHex(p1)
def refresh_machines(machines, day, cur): def insert_machine(machine, day, cur, contact):
contact = INITIAL_DATE + timedelta(days = day) macaddr = gen_macaddress(machine)
for i in updated_machines(machines, day):
macaddr = gen_macaddress(i)
# print "Mac {0}".format(macaddr) # print "Mac {0}".format(macaddr)
if i < MULTI_HD_TOTAL: if machine < MULTI_HD_TOTAL:
cur.execute(TEMPLATE, (contact, macaddr, HD_MODEL, HD_SIZE, HD_USED, HD_EXTRA)) cur.execute(TEMPLATE, (contact, macaddr, HD_MODEL, HD_SIZE, HD_USED, HD_EXTRA))
else: else:
cur.execute(TEMPLATE, (contact, macaddr, None, None, None, 0)) 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):
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): def max_machine(machines, day):
return intround(machines / (MACHINE_DECREASE_RATIO * (day + 1))) return intround(machines)
def intround(f): def intround(f):
return int(round(f)) return int(round(f))
...@@ -90,7 +105,7 @@ def get_connection(dbname, user): ...@@ -90,7 +105,7 @@ def get_connection(dbname, user):
if __name__ == '__main__': if __name__ == '__main__':
if len(sys.argv) != 3: 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]) connection = get_connection(sys.argv[1], sys.argv[2])
cur = connection.cursor() cur = connection.cursor()
count = insert_data(cur) count = insert_data(cur)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment