Beispiel #1
0
def generate():
    handler = ListHandler()
    is_master_elected = False

    for i in range(random.randrange(5, 15)):
        # constructing entry parameters with some randomness
        ip = NETWORK + str(random.randrange(1, 255))

        # if there is no master
        if not is_master_elected:
            is_master = True if random.random() > 0.5 else False

            # if randomness selects this as master, set the flag.
            if is_master:
                is_master_elected = True

        # flag is set = there is already a master.
        else:
            is_master = False

        # just a placeholder
        name = "ip_" + str(ip)

        # set timestamp
        timestamp = int(time.time()) - random.randrange(0, 1000)

        # creating entry

        entry = Entry(is_master, name, "", timestamp) if random.random() < 0.7 else Entry()

        # adding entry

        handler.add_or_override_entry(ip, entry)
    return handler
Beispiel #2
0
#!/bin/python3

import time

from mergeDict.compareDict import TwoDicts
from util.listhandler import ListHandler

list1 = ListHandler()
list2 = ListHandler()

# create Entries

# by Nico:
# Creating entries for testing purpose shall be done by the generate method.
# Do not copy the ListHandler Class/File into your working directory.
# Import the version in util/listhandler
# you are creating duplicates and maintaining two different versions is not our goal
# please use the implementation in util and import it.


# The Entry is an object of the type Entry() which is implmented
# in the listhandler file.
# Please use the Entry Class over giving the handler an list.
# I will add functionality to take care of this and it will not
# accept any other type than Entry. I thought it would be clear
# due to the main method example.


list1.add_or_override_entry('10.20.0.200',entry=['FALSE','raspi_aaa','pyrouri',time.time()])
list1.add_or_override_entry('10.20.0.199',entry=['FALSE','raspi_bbb','pyrouri',time.time()-150])
list1.add_or_override_entry('10.20.0.19',entry=['FALSE','raspi_ccc','pyrouri',time.time()-250])