def test_acquire_wan_vessels_some_vessels_fail(self):

    # Have every other vessel acquisition fail. We're going to acquire 50,
    # so we'll need 100 responses alternating between failure and success
    # (we're starting with failure, so 100, not 99).
    calls_results = [False, True] * 50
    mocklib.mock_backend_acquire_vessel(calls_results)
    
    # Create a user who will be doing the acquiring.
    user = maindb.create_user("testuser", "password", "*****@*****.**", "affiliation", "1 2", "2 2 2", "3 4")
    userport = user.usable_vessel_port
    
    # We need to give the user some donations so they have enough credits.
    # We're assuming it's 10 credits per donation.
    self.assertEqual(10, maindb.VESSEL_CREDITS_FOR_DONATIONS_MULTIPLIER)
    
    # Also make sure the user started with 10 credits.
    self.assertEqual(10, maindb.get_user_free_vessel_credits(user))
    
    # We need 100 nodes the user can acquire vessels on as we're having half of
    # the node acquisitions fail.
    testutil.create_nodes_on_different_subnets(100, [userport])
    
    # Now credit the user for donations on 4 of these.
    for node in maindb.get_active_nodes()[:4]:
      maindb.create_donation(node, user, '')
    
    # Ok, the user now has 50 vessels the can acquire and there are 100 nodes
    # with vessels available for them. Let's try to acquire all 50 at once and
    # make sure this works even though we'll have to get through 100 requests
    # to the backend to make it happen.
    vessel_list = interface.acquire_vessels(user, 50, 'wan')
    
    self.assertEqual(50, len(vessel_list))
  def test_acquire_wan_vessels_some_vessels_fail(self):

    # Have every other vessel acquisition fail. We're going to acquire 50,
    # so we'll need 100 responses alternating between failure and success
    # (we're starting with failure, so 100, not 99).
    calls_results = [False, True] * 50
    mocklib.mock_backend_acquire_vessel(calls_results)
    
    # Create a user who will be doing the acquiring.
    user = maindb.create_user("testuser", "password", "*****@*****.**", "affiliation", "1 2", "2 2 2", "3 4")
    userport = user.usable_vessel_port
    
    # We need to give the user some donations so they have enough credits.
    # We're assuming it's 10 credits per donation.
    self.assertEqual(10, maindb.VESSEL_CREDITS_FOR_DONATIONS_MULTIPLIER)
    
    # Also make sure the user started with 10 credits.
    self.assertEqual(10, maindb.get_user_free_vessel_credits(user))
    
    # We need 100 nodes the user can acquire vessels on as we're having half of
    # the node acquisitions fail.
    testutil.create_nodes_on_different_subnets(100, [userport])
    
    # Now credit the user for donations on 4 of these.
    for node in maindb.get_active_nodes()[:4]:
      maindb.create_donation(node, user, '')
    
    # Ok, the user now has 50 vessels the can acquire and there are 100 nodes
    # with vessels available for them. Let's try to acquire all 50 at once and
    # make sure this works even though we'll have to get through 100 requests
    # to the backend to make it happen.
    vessel_list = interface.acquire_vessels(user, 50, 'wan')
    
    self.assertEqual(50, len(vessel_list))
def assert_database_info_active():

  active_nodes_list = maindb.get_active_nodes()

  assert(len(active_nodes_list) == 1)
  assert(active_nodes_list[0].node_identifier == mockutil.nodeid_key_str)
  assert(active_nodes_list[0].last_known_ip == mockutil.node_ip)
  assert(active_nodes_list[0].last_known_port == mockutil.node_port)
  assert(active_nodes_list[0].extra_vessel_name == mockutil.extra_vessel_name)
  assert(active_nodes_list[0].owner_pubkey == mockutil.per_node_key_str)

  testuser = maindb.get_user(mockutil.testusername)
  donations_list = maindb.get_donations_by_user(testuser)

  assert(len(donations_list) == 1)
  assert(donations_list[0].node == active_nodes_list[0])
示例#4
0
def run_database_update_test():
    """
  <Purpose>
    Run the test and make sure that the database was modified
    properly, the right keys were set, and generally all information
    is what was expected.

  <Arguments>
    None

  <Exceptions>
    None

  <Side Effects>
    None

  <Return>
    None
  """

    transitionlist = []

    active_nodes_list = maindb.get_active_nodes()
    active_nodes_list[0].is_active = False
    active_nodes_list[0].save()

    transitionlist.append(
        (("startstatename", node_transition_lib.onepercentmanyeventspublickey),
         ("endstatename", node_transition_lib.onepercentmanyeventspublickey),
         transition_onepercentmanyevents_to_onepercentmanyevents.
         update_database, node_transition_lib.noop,
         transition_onepercentmanyevents_to_onepercentmanyevents.
         update_database_node))

    (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 == 0)
    # 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.
    assert (mockutil.set_vessel_user_keylist_call_count == 0)
示例#5
0
def assert_database_info_active():

    active_nodes_list = maindb.get_active_nodes()

    assert (len(active_nodes_list) == 1)
    assert (active_nodes_list[0].node_identifier == mockutil.nodeid_key_str)
    assert (active_nodes_list[0].last_known_ip == mockutil.node_ip)
    assert (active_nodes_list[0].last_known_port == mockutil.node_port)
    assert (
        active_nodes_list[0].extra_vessel_name == mockutil.extra_vessel_name)
    assert (active_nodes_list[0].owner_pubkey == mockutil.per_node_key_str)

    testuser = maindb.get_user(mockutil.testusername)
    donations_list = maindb.get_donations_by_user(testuser)

    assert (len(donations_list) == 1)
    assert (donations_list[0].node == active_nodes_list[0])
def run_database_update_test():
  """
  <Purpose>
    Run the test and make sure that the database was modified
    properly, the right keys were set, and generally all information
    is what was expected.

  <Arguments>
    None

  <Exceptions>
    None

  <Side Effects>
    None

  <Return>
    None
  """

  transitionlist = []

  active_nodes_list = maindb.get_active_nodes()
  active_nodes_list[0].is_active = False
  active_nodes_list[0].save()

  transitionlist.append(("twopercent", "twopercent", 
                         node_transition_lib.update_database,
                         node_transition_lib.noop, True,
                         node_transition_lib.update_database_node))

  (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 == 0)
  # 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.
  assert(mockutil.set_vessel_user_keylist_call_count == 0)  
def assert_database_info_non_active():

  active_nodes_list = maindb.get_active_nodes()
  assert(len(active_nodes_list) == 0)

  testuser = maindb.get_user(mockutil.testusername)

  active_donations = maindb.get_donations_by_user(testuser)
  assert(len(active_donations) == 0)

  all_donations = maindb.get_donations_by_user(testuser, include_inactive_and_broken=True)
  assert(len(all_donations) == 1)

  node = all_donations[0].node

  assert(node.node_identifier == mockutil.nodeid_key_str)
  assert(node.last_known_ip == mockutil.node_ip)
  assert(node.last_known_port == mockutil.node_port)
  assert(node.extra_vessel_name == mockutil.extra_vessel_name)
  assert(node.owner_pubkey == mockutil.per_node_key_str)
def assert_database_info():

  active_nodes_list = maindb.get_active_nodes()
  assert(len(active_nodes_list) == 0)
  
  testuser = maindb.get_user(mockutil.testusername)
    
  active_donations = maindb.get_donations_by_user(testuser)
  assert(len(active_donations) == 0)
  
  all_donations = maindb.get_donations_by_user(testuser, include_inactive_and_broken=True)
  assert(len(all_donations) == 1)
  
  node = all_donations[0].node
  
  assert(node.node_identifier == mockutil.nodeid_key_str)
  assert(node.last_known_ip == mockutil.node_ip)
  assert(node.last_known_port == mockutil.node_port)
  assert(node.extra_vessel_name == mockutil.extra_vessel_name)
  assert(node.owner_pubkey == mockutil.per_node_key_str)