Example #1
0
def setup_test():
    """
  <Purpose>
    Prepare everything in order to run the tests.

  <Arguments>
    None

  <Exceptions>
    None

  <Side Efects>
    None

  <Return>
    None
  """

    testlib.setup_test_db()

    # Make sure all the variables are its default values
    mockutil.mockutil_cleanup_variables()

    # Create a user who has the donation key.
    user_object = maindb.create_user(mockutil.testusername, "password",
                                     "*****@*****.**", "affiliation",
                                     "10 11", "2 2 2", mockutil.donor_key_str)

    # Create a database entry for the node
    node_object = maindb.create_node(mockutil.nodeid_key_str, mockutil.node_ip,
                                     mockutil.node_port, "10.0test", False,
                                     mockutil.per_node_key_str,
                                     mockutil.extra_vessel_name)

    # Create a donation for user
    maindb.create_donation(node_object, user_object, "Making a donation")

    # Setup all the mock functions
    mockutil.mock_nodemanager_get_node_info(mockutil.nodeid_key, "10.0test",
                                            vessels_dict)
    mockutil.mock_lockserver_calls()
    mockutil.mock_backend_generate_key([mockutil.per_node_key_str])
    mockutil.mock_nodemanager_get_vesselresources()
    mockutil.mock_transitionlib_do_advertise_lookup([mockutil.node_address])
    mockutil.mock_backend_set_vessel_owner_key()
    mockutil.mock_backend_split_vessel()
    mockutil.mock_backend_set_vessel_user_keylist([
        mockutil._mock_pubkey_to_string(
            node_transition_lib.
            transition_state_keys['movingto_onepercentmanyevents'])
    ])
def run_database_stituation_three_test():
  """
  <Purpose>
    The purpose of this test is to test the case where a record
    for the node has been registered in the database and a 
    record for the donation has been registered, but the
    owner key on the node has not been changed.

  <Arguments>
    None

  <Exceptions>
    None

  <Side Effects>
    None

  <Return>
    None
  """

  # Create a database entry for the node
  node_object = maindb.create_node(mockutil.nodeid_key_str, mockutil.node_ip, mockutil.node_port, "10.0test",
                                  False, mockutil.per_node_key_str, mockutil.extra_vessel_name)

  user_object = maindb.get_user(mockutil.testusername)

  # Create a donation for user
  maindb.create_donation(node_object, user_object, "Making a donation")

  transitionlist = []

  transitionlist.append((("donation_state", node_transition_lib.acceptdonationpublickey),
                        ("canonical_state", node_transition_lib.canonicalpublickey),
                         node_transition_lib.noop,
                         node_transition_lib.noop))

  print "Running test where database has record of node, has record of donation and node has donor key"

  (success_count, failure_count) = node_transition_lib.do_one_processnode_run(transitionlist, "startstatename", 1)[0]

  assert(success_count == 1)
  assert(failure_count == 0)

  assert_database_info()

  assert(mockutil.set_vessel_owner_key_call_count == 1)
  assert(mockutil.set_vessel_user_keylist_call_count == 1)
Example #3
0
def setup_test():
    """
  <Purpose>
    Prepare everything in order to run the tests.

  <Arguments>
    None

  <Exceptions>
    None

  <Side Efects>
    None

  <Return>
    None
  """

    testlib.setup_test_db()

    # Create a user who has the donation key.
    user_object = maindb.create_user(mockutil.testusername, "password",
                                     "*****@*****.**", "affiliation",
                                     "10 11", "2 2 2", mockutil.donor_key_str)

    # Create a database entry for the node
    node_object = maindb.create_node(mockutil.nodeid_key_str, mockutil.node_ip,
                                     mockutil.node_port, "10.0test", True,
                                     mockutil.per_node_key_str,
                                     mockutil.extra_vessel_name)

    # Create a donation for user
    maindb.create_donation(node_object, user_object, "Making a donation")
    # Setup all the mock functions
    mockutil.mock_nodemanager_get_node_info(mockutil.nodeid_key, "10.0test",
                                            vessels_dict)
    mockutil.mock_lockserver_calls()
    mockutil.mock_backend_generate_key([mockutil.per_node_key_str])
    mockutil.mock_nodemanager_get_vesselresources()
    mockutil.mock_transitionlib_do_advertise_lookup([mockutil.node_address])
    mockutil.mock_backend_set_vessel_owner_key()
    mockutil.mock_backend_split_vessel()
    # set_vessel_user_keylist_call_count won't be called because the
    # node_transition_lib will see that it's a state change to the same state.
    mockutil.mock_backend_set_vessel_user_keylist(None)
def setup_test():
  """
  <Purpose>
    Prepare everything in order to run the tests.

  <Arguments>
    None

  <Exceptions>
    None

  <Side Efects>
    None

  <Return>
    None
  """

  testlib.setup_test_db()

  # Make sure all the variables are its default values  
  mockutil.mockutil_cleanup_variables()

  # Create a user who has the donation key.
  user_object = maindb.create_user(mockutil.testusername, "password", "*****@*****.**", "affiliation", 
                    "10 11", "2 2 2", mockutil.donor_key_str)

  # Create a database entry for the node
  node_object = maindb.create_node(mockutil.nodeid_key_str, mockutil.node_ip, mockutil.node_port, "10.0test",
                                  False, mockutil.per_node_key_str, mockutil.extra_vessel_name)

  # Create a donation for user
  maindb.create_donation(node_object, user_object, "Making a donation")

  # Setup all the mock functions
  mockutil.mock_nodemanager_get_node_info(mockutil.nodeid_key, "10.0test", vessels_dict)
  mockutil.mock_lockserver_calls()
  mockutil.mock_backend_generate_key([mockutil.per_node_key_str])
  mockutil.mock_nodemanager_get_vesselresources()
  mockutil.mock_transitionlib_do_advertise_lookup([mockutil.node_address])
  mockutil.mock_backend_set_vessel_owner_key()
  mockutil.mock_backend_split_vessel()
  mockutil.mock_backend_set_vessel_user_keylist([mockutil._mock_pubkey_to_string(
                                                node_transition_lib.transition_state_keys['movingto_twopercent'])])
def create_new_node_object(node_string, node_info, donated_vesselname):
  """
  <Purpose>
    Create a new node entry in the database with a newly generated
    per node key
  
  <Arguments>
    node_string - the address of the node 

    node_info - information about the node

    vesselname - the name of the extra vessel

  <Exceptions>
    None

  <Side Effects>
    None

  <Return>
    Returns a database node object
  """ 

  nodeID = _do_rsa_publickey_to_string(node_info['nodekey'])
  (ip_or_nat_string, port_num) = split_node_string(node_string)

  # Generate a new set of keys for the node. The pubkey gets passed
  # down to us while the private key is stored in a database elsewhere.
  log("Generating new keys for node owner_key....")   
  new_node_owner_pubkey = backend.generate_key(ip_or_nat_string+". "+nodeID)
  log("Generated publickey for node "+node_string+" : "+str(new_node_owner_pubkey))
  
  try:
    # Attempt to add new node to db.
    database_nodeobject = maindb.create_node(nodeID, ip_or_nat_string, port_num, 
                                                 node_info['version'], False, 
                                                 new_node_owner_pubkey, 
                                                 donated_vesselname) 
     
    log("Added node to the database with nodeID: " + nodeID)  
  except:
    raise DatabaseError("Failed to create node and add to database. " + traceback.format_exc())    
 
  return database_nodeobject
def create_new_node_object(node_string, node_info, donated_vesselname):
  """
  <Purpose>
    Create a new node entry in the database with a newly generated
    per node key
  
  <Arguments>
    node_string - the address of the node 

    node_info - information about the node

    vesselname - the name of the extra vessel

  <Exceptions>
    None

  <Side Effects>
    None

  <Return>
    Returns a database node object
  """ 

  nodeID = _do_rsa_publickey_to_string(node_info['nodekey'])
  (ip_or_nat_string, port_num) = split_node_string(node_string)

  # Generate a new set of keys for the node. The pubkey gets passed
  # down to us while the private key is stored in a database elsewhere.
  log("Generating new keys for node owner_key....")   
  new_node_owner_pubkey = backend.generate_key(ip_or_nat_string+". "+nodeID)
  log("Generated publickey for node "+node_string+" : "+str(new_node_owner_pubkey))
  
  try:
    # Attempt to add new node to db.
    database_nodeobject = maindb.create_node(nodeID, ip_or_nat_string, port_num, 
                                                 node_info['version'], False, 
                                                 new_node_owner_pubkey, 
                                                 donated_vesselname) 
     
    log("Added node to the database with nodeID: " + nodeID)  
  except:
    raise DatabaseError("Failed to create node and add to database. " + traceback.format_exc())    
 
  return database_nodeobject
def setup_test():
  """
  <Purpose>
    Prepare everything in order to run the tests.

  <Arguments>
    None

  <Exceptions>
    None

  <Side Efects>
    None

  <Return>
    None
  """

  testlib.setup_test_db()

  # Create a user who has the donation key.
  user_object = maindb.create_user(mockutil.testusername, "password", "*****@*****.**", "affiliation", 
                    "10 11", "2 2 2", mockutil.donor_key_str)

  # Create a database entry for the node
  node_object = maindb.create_node(mockutil.nodeid_key_str, mockutil.node_ip, mockutil.node_port, "10.0test",
                                  True, mockutil.per_node_key_str, mockutil.extra_vessel_name)

  # Create a donation for user
  maindb.create_donation(node_object, user_object, "Making a donation")
  # Setup all the mock functions
  mockutil.mock_nodemanager_get_node_info(mockutil.nodeid_key, "10.0test", vessels_dict)
  mockutil.mock_lockserver_calls()
  mockutil.mock_backend_generate_key([mockutil.per_node_key_str])
  mockutil.mock_nodemanager_get_vesselresources()
  mockutil.mock_transitionlib_do_advertise_lookup([mockutil.node_address])
  mockutil.mock_backend_set_vessel_owner_key()
  mockutil.mock_backend_split_vessel()
  # set_vessel_user_keylist_call_count won't be called because the
  # node_transition_lib will see that it's a state change to the same state.
  mockutil.mock_backend_set_vessel_user_keylist(None)
Example #8
0
def create_node_and_vessels_with_one_port_each(ip, portlist, is_active=True):
  
  global next_nodeid_number
  next_nodeid_number += 1
  
  nodeid = "node" + str(next_nodeid_number)
  port = 1234
  version = "10.0test"
  owner_pubkey = "1 2"
  extra_vessel_name = "v1"
  
  node = maindb.create_node(nodeid, ip, port, version, is_active, owner_pubkey, extra_vessel_name)

  single_vessel_number = 2

  for vesselport in portlist:
    single_vessel_name = "v" + str(single_vessel_number)
    single_vessel_number += 1
    vessel = maindb.create_vessel(node, single_vessel_name)
    maindb.set_vessel_ports(vessel, [vesselport])
  
  return node
Example #9
0
def create_node_and_vessels_with_one_port_each(ip, portlist, is_active=True):

    global next_nodeid_number
    next_nodeid_number += 1

    nodeid = "node" + str(next_nodeid_number)
    port = 1234
    version = "10.0test"
    owner_pubkey = "1 2"
    extra_vessel_name = "v1"

    node = maindb.create_node(nodeid, ip, port, version, is_active,
                              owner_pubkey, extra_vessel_name)

    single_vessel_number = 2

    for vesselport in portlist:
        single_vessel_name = "v" + str(single_vessel_number)
        single_vessel_number += 1
        vessel = maindb.create_vessel(node, single_vessel_name)
        maindb.set_vessel_ports(vessel, [vesselport])

    return node
def setup_general():
  """
  <Purpose>
    Prepare all the general stuff in order to run the tests.

  <Arguments>
    None

  <Exceptions>
    None

  <Side Efects>
    None

  <Return>
    None
  """

  testlib.setup_test_db()

  # Make sure all the variables are its default values
  mockutil.mockutil_cleanup_variables()

  # Create a user who has the donation key.
  user_object = maindb.create_user(mockutil.testusername, "password", "*****@*****.**", "affiliation",
                    "10 11", "2 2 2", mockutil.donor_key_str)

  # Create a database entry for the node
  node_object = maindb.create_node(mockutil.nodeid_key_str, mockutil.node_ip, mockutil.node_port, "10.0test",
                                  True, mockutil.per_node_key_str, mockutil.extra_vessel_name)


  # Create a donation for user
  maindb.create_donation(node_object, user_object, "Making a donation")

  testuser = maindb.get_user(mockutil.testusername)

  # Retrieve the info about the donation we just made.
  all_donations = maindb.get_donations_by_user(testuser, include_inactive_and_broken=True)
  node = all_donations[0].node

  global vessels_dict
  vessels_dict = vessels_dict_basic.copy()
  # Create 9 different vessels, assuming that the original vessel got split into 9.
  for i in range(9):
    vessels_dict["vessel"+str(i)]={}
    vessels_dict["vessel"+str(i)]["userkeys"] = []
    vessels_dict["vessel"+str(i)]["ownerkey"] = rsa.rsa_string_to_publickey(node.owner_pubkey)
    vessels_dict["vessel"+str(i)]["ownerinfo"] = ""
    vessels_dict["vessel"+str(i)]["status"] = ""
    vessels_dict["vessel"+str(i)]["advertise"] = True

    maindb.create_vessel(node, "vessel"+str(i))


  # Setup all the mock functions
  mockutil.mock_nodemanager_get_node_info(mockutil.nodeid_key, "10.0test", vessels_dict)
  mockutil.mock_lockserver_calls()
  mockutil.mock_backend_generate_key([mockutil.per_node_key_str])
  mockutil.mock_nodemanager_get_vesselresources()
  mockutil.mock_transitionlib_do_advertise_lookup([mockutil.node_address])
  mockutil.mock_backend_set_vessel_owner_key()
Example #11
0
def setup_general():
    """
  <Purpose>
    Prepare all the general stuff in order to run the tests.

  <Arguments>
    None

  <Exceptions>
    None

  <Side Efects>
    None

  <Return>
    None
  """

    testlib.setup_test_db()

    # Make sure all the variables are its default values
    mockutil.mockutil_cleanup_variables()

    # Create a user who has the donation key.
    user_object = maindb.create_user(mockutil.testusername, "password",
                                     "*****@*****.**", "affiliation",
                                     "10 11", "2 2 2", mockutil.donor_key_str)

    # Create a database entry for the node
    node_object = maindb.create_node(mockutil.nodeid_key_str, mockutil.node_ip,
                                     mockutil.node_port, "10.0test", True,
                                     mockutil.per_node_key_str,
                                     mockutil.extra_vessel_name)

    # Create a donation for user
    maindb.create_donation(node_object, user_object, "Making a donation")

    testuser = maindb.get_user(mockutil.testusername)

    # Retrieve the info about the donation we just made.
    all_donations = maindb.get_donations_by_user(
        testuser, include_inactive_and_broken=True)
    node = all_donations[0].node

    global vessels_dict
    vessels_dict = vessels_dict_basic.copy()
    # Create 9 different vessels, assuming that the original vessel got split into 9.
    for i in range(9):
        vessels_dict["vessel" + str(i)] = {}
        vessels_dict["vessel" + str(i)]["userkeys"] = []
        vessels_dict["vessel" +
                     str(i)]["ownerkey"] = rsa.rsa_string_to_publickey(
                         node.owner_pubkey)
        vessels_dict["vessel" + str(i)]["ownerinfo"] = ""
        vessels_dict["vessel" + str(i)]["status"] = ""
        vessels_dict["vessel" + str(i)]["advertise"] = True

        maindb.create_vessel(node, "vessel" + str(i))

    # Setup all the mock functions
    mockutil.mock_nodemanager_get_node_info(mockutil.nodeid_key, "10.0test",
                                            vessels_dict)
    mockutil.mock_lockserver_calls()
    mockutil.mock_backend_generate_key([mockutil.per_node_key_str])
    mockutil.mock_nodemanager_get_vesselresources()
    mockutil.mock_transitionlib_do_advertise_lookup([mockutil.node_address])
    mockutil.mock_backend_set_vessel_owner_key()
def run_multiple_donation_test():
  """
  <Purpose>
    The purpose of this test is to see how the transtion script would
    react if we provide a dictionary where a vessel is in the acceptdonation
    state but the node has already in the canonical state. This is possible
    if the node had two vessel in the acceptdonation state to start with.
    This is essentially if the node has two donations. Currently we don't handle
    multiple donations from the second node, so when we run the test, the success
    count should be 0 and the failure count should be 1. Also the name of the extra
    vessel should not change.

  <Arguments>
    None

  <Exceptions>
    None

  <Side Effects>
    None

  <Return>
    None
  """
 
  # Have the extra vessel in canonical form
  vessels_dict[mockutil.extra_vessel_name]["userkeys"] = [node_transition_lib.canonicalpublickey]

  # Have a second vessel in acceptdonation state. Essentially a second donation.
  vessels_dict["second_donation"] = {"userkeys" : [node_transition_lib.acceptdonationpublickey],
                                   "ownerkey" : mockutil.donor_key,
                                   "ownerinfo" : "",
                                   "status" : "",
                                   "advertise" : True}

  # Create a database entry for the node
  node_object = maindb.create_node(mockutil.nodeid_key_str, mockutil.node_ip, mockutil.node_port, "10.0test",
                                  False, mockutil.per_node_key_str, mockutil.extra_vessel_name)
  user_object = maindb.get_user(mockutil.testusername)
  # Create a donation for user
  maindb.create_donation(node_object, user_object, "Making a donation")
  
  # Register the new vesseldict so get_info returns this new modified vesseldict
  mockutil.mock_nodemanager_get_node_info(mockutil.nodeid_key, "10.0test", vessels_dict)




  transitionlist = []

  transitionlist.append((("donation_state", node_transition_lib.acceptdonationpublickey),
                        ("canonical_state", node_transition_lib.canonicalpublickey),
                         node_transition_lib.noop,
                         node_transition_lib.noop))

  print "Running test where database has record of node, no record of donation and node has donor key"

  (success_count, failure_count) = node_transition_lib.do_one_processnode_run(transitionlist, "startstatename", 1)[0]

  assert(success_count == 0)
  assert(failure_count == 1)

  assert_database_info()

  assert(mockutil.set_vessel_owner_key_call_count == 0)
  assert(mockutil.set_vessel_user_keylist_call_count == 0)