Beispiel #1
0
def acquire_nat_vessels(lockserver_handle, geniuser, vesselcount):
  """
  <Purpose>
    Acquire 'nat' vessels for a geniuser.
  <Arguments>
    lockserver_handle
      The lockserver handle to be used for obtaining node locks.
    geniuser
      The GeniUser the vessels should be acquired for.
    vesselcount
      The number of vessels to acquire.
  <Exceptions>
    UnableToAcquireResourcesError
      If either the user does not not have enough vessel credits to acquire the
      number of vessels they requested or if there are not enough vessels
      available to fulfill the request.
  <Side Effects>
    The vessels are acquired for the user. The database has been updated to
    reflect the acquisition.
  <Returns>
    A list of the vessels that were acquired.
  """
  
  # Get a randomized list of nat vessels.
  vessel_list = maindb.get_available_nat_vessels(geniuser, vesselcount)
  
  return _acquire_vessels_from_list(lockserver_handle, geniuser, vesselcount, vessel_list)
    def test_get_available_nat_vessels(self):

        # 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 choose the numbers of each type of node in a way that helps ensure
        # that we don't accidentally pass the test if something is going wrong.

        # We will get one vessel on each created node for each port in portlist
        # and there will be only that one port on the vessel.
        portlist = [userport - 1, userport, userport + 1]

        create_nodes_on_same_subnet(3, portlist)
        create_nodes_on_different_subnets(7, portlist)
        create_nat_nodes(13, portlist)

        # Request 0 vessels, make sure it raises a AssertionError.
        self.assertRaises(AssertionError, maindb.get_available_nat_vessels,
                          user, 0)

        # Request a negative number of vessels, make sure it raises a AssertionError.
        self.assertRaises(AssertionError, maindb.get_available_nat_vessels,
                          user, -1)

        # We expect there to be 13 available nat vessels (one vessel on each node
        # nat node).

        # Request 1 vessel, make sure we get back more than 1 potential vessels.
        vessel_list = maindb.get_available_nat_vessels(user, 1)
        self.assertTrue(len(vessel_list) > 1)

        # Request 5 vessels, make sure we get back more than 5 potential vessels.
        vessel_list = maindb.get_available_nat_vessels(user, 5)
        self.assertTrue(len(vessel_list) > 5)

        # Request 13 vessels, make sure we get back all 13 vessels we expect.
        vessel_list = maindb.get_available_nat_vessels(user, 13)
        self.assertEqual(13, len(vessel_list))

        # Request 14 vessels, make sure we get an exception.
        self.assertRaises(UnableToAcquireResourcesError,
                          maindb.get_available_nat_vessels, user, 14)
 def test_get_available_nat_vessels(self):
   
   # 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 choose the numbers of each type of node in a way that helps ensure
   # that we don't accidentally pass the test if something is going wrong.
   
   # We will get one vessel on each created node for each port in portlist
   # and there will be only that one port on the vessel.
   portlist = [userport - 1, userport, userport + 1]
   
   create_nodes_on_same_subnet(3, portlist)
   create_nodes_on_different_subnets(7, portlist)
   create_nat_nodes(13, portlist)
     
   # Request 0 vessels, make sure it raises a AssertionError.
   self.assertRaises(AssertionError, maindb.get_available_nat_vessels, user, 0)
   
   # Request a negative number of vessels, make sure it raises a AssertionError.
   self.assertRaises(AssertionError, maindb.get_available_nat_vessels, user, -1)
   
   # We expect there to be 13 available nat vessels (one vessel on each node
   # nat node).
   
   # Request 1 vessel, make sure we get back more than 1 potential vessels.
   vessel_list = maindb.get_available_nat_vessels(user, 1)
   self.assertTrue(len(vessel_list) > 1)
     
   # Request 5 vessels, make sure we get back more than 5 potential vessels.
   vessel_list = maindb.get_available_nat_vessels(user, 5)
   self.assertTrue(len(vessel_list) > 5)
     
   # Request 13 vessels, make sure we get back all 13 vessels we expect.
   vessel_list = maindb.get_available_nat_vessels(user, 13)
   self.assertEqual(13, len(vessel_list))
   
   # Request 14 vessels, make sure we get an exception.
   self.assertRaises(UnableToAcquireResourcesError, maindb.get_available_nat_vessels, user, 14)