def test_get_available_lan_vessels_by_subnet(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(29, 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_lan_vessels_by_subnet, user, 0)

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

        # We expect there to be 7 subnets with a single available vessel for the
        # user (the 7 on differnt subnets created above) and 1 subnet with 29
        # available vessels for the user (the 29 nodes on the same subnet created
        # above).

        # Request 1 vessel, make sure we get back a list of 8 subnets where one
        # subnet has more than one available vessel and the other 7 have only
        # one available vessel.
        subnet_vessel_list = maindb.get_available_lan_vessels_by_subnet(user, 1)
        self.assertEqual(8, len(subnet_vessel_list))

        vessel_list_sizes = []
        for vessel_list in subnet_vessel_list:
            vessel_list_sizes.append(len(vessel_list))
        vessel_list_sizes.sort()

        self.assertEqual([1, 1, 1, 1, 1, 1, 1], vessel_list_sizes[:7])
        self.assertTrue(vessel_list_sizes[7] > 1)

        # Request 5 vessels, make sure we get back a list that has one subnet and
        # in that subnet is a list of more than 5 potential vessels.
        subnet_vessel_list = maindb.get_available_lan_vessels_by_subnet(user, 5)
        self.assertEqual(1, len(subnet_vessel_list))
        self.assertTrue(len(subnet_vessel_list[0]) > 5)

        # Request 29 vessels, make sure we get back a list that has one subnet and
        # in that subnet is a list of 29 potential vessels.
        subnet_vessel_list = maindb.get_available_lan_vessels_by_subnet(user, 29)
        self.assertEqual(1, len(subnet_vessel_list))
        self.assertEqual(29, len(subnet_vessel_list[0]))

        # Request 30 vessels, make sure we get an exception.
        self.assertRaises(UnableToAcquireResourcesError, maindb.get_available_lan_vessels_by_subnet, user, 30)
Beispiel #2
0
def acquire_lan_vessels(lockserver_handle, geniuser, vesselcount):
    """
  <Purpose>
    Acquire 'lan' 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 that itself contains lists of vessels on the same subnet.
    subnet_vessel_list = maindb.get_available_lan_vessels_by_subnet(
        geniuser, vesselcount)

    # This case is a little more involved than with wan or rand vessels. If we
    # fail to get the number of desired vessels from one subnet, we need to try
    # another until we are out of subnets to try.
    for vessel_list in subnet_vessel_list:
        try:
            # If we don't hit an exception and return, then we found a subnet where
            # we could acquire all of the requested vessels. So, we're done.
            return _acquire_vessels_from_list(lockserver_handle, geniuser,
                                              vesselcount, vessel_list)
        except UnableToAcquireResourcesError:
            # Try the next subnet.
            continue

    # If we made it here, we tried all subnets in our list.
    raise UnableToAcquireResourcesError
def acquire_lan_vessels(lockserver_handle, geniuser, vesselcount):
  """
  <Purpose>
    Acquire 'lan' 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 that itself contains lists of vessels on the same subnet.
  subnet_vessel_list = maindb.get_available_lan_vessels_by_subnet(geniuser, vesselcount)
  
  # This case is a little more involved than with wan or rand vessels. If we
  # fail to get the number of desired vessels from one subnet, we need to try
  # another until we are out of subnets to try.
  for vessel_list in subnet_vessel_list:
    try:
      # If we don't hit an exception and return, then we found a subnet where
      # we could acquire all of the requested vessels. So, we're done.
      return _acquire_vessels_from_list(lockserver_handle, geniuser, vesselcount, vessel_list)
    except UnableToAcquireResourcesError:
      # Try the next subnet.
      continue

  # If we made it here, we tried all subnets in our list.
  raise UnableToAcquireResourcesError
Beispiel #4
0
    def test_get_available_lan_vessels_by_subnet(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(29, 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_lan_vessels_by_subnet, user, 0)

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

        # We expect there to be 7 subnets with a single available vessel for the
        # user (the 7 on differnt subnets created above) and 1 subnet with 29
        # available vessels for the user (the 29 nodes on the same subnet created
        # above).

        # Request 1 vessel, make sure we get back a list of 8 subnets where one
        # subnet has more than one available vessel and the other 7 have only
        # one available vessel.
        subnet_vessel_list = maindb.get_available_lan_vessels_by_subnet(
            user, 1)
        self.assertEqual(8, len(subnet_vessel_list))

        vessel_list_sizes = []
        for vessel_list in subnet_vessel_list:
            vessel_list_sizes.append(len(vessel_list))
        vessel_list_sizes.sort()

        self.assertEqual([1, 1, 1, 1, 1, 1, 1], vessel_list_sizes[:7])
        self.assertTrue(vessel_list_sizes[7] > 1)

        # Request 5 vessels, make sure we get back a list that has one subnet and
        # in that subnet is a list of more than 5 potential vessels.
        subnet_vessel_list = maindb.get_available_lan_vessels_by_subnet(
            user, 5)
        self.assertEqual(1, len(subnet_vessel_list))
        self.assertTrue(len(subnet_vessel_list[0]) > 5)

        # Request 29 vessels, make sure we get back a list that has one subnet and
        # in that subnet is a list of 29 potential vessels.
        subnet_vessel_list = maindb.get_available_lan_vessels_by_subnet(
            user, 29)
        self.assertEqual(1, len(subnet_vessel_list))
        self.assertEqual(29, len(subnet_vessel_list[0]))

        # Request 30 vessels, make sure we get an exception.
        self.assertRaises(UnableToAcquireResourcesError,
                          maindb.get_available_lan_vessels_by_subnet, user, 30)