Exemple #1
0
    def test_get_queryset_vessel_acquired_by_user_changes(self):
        """
    This is ultimately testing
    maindb._get_queryset_of_all_available_vessels_for_a_port_include_nat_nodes()
    """

        # 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

        # Create two nodes that have three vessels but only one vessel on the user's port.
        portlist = [userport - 1, userport, userport + 1]
        ip = "127.0.0.1"
        create_node_and_vessels_with_one_port_each(ip, portlist)
        ip = "127.0.0.2"
        create_node_and_vessels_with_one_port_each(ip, portlist)

        # We expect two available vessels.
        queryset = _get_queryset_include_nat(userport)
        self.assertEqual(2, queryset.count())

        # Mark one of the vessels as acquired.
        vessel = queryset[0]
        maindb.record_acquired_vessel(user, vessel)

        # We expect one available vessel, and it shouldn't be the acquired one.
        queryset = _get_queryset_include_nat(userport)
        self.assertEqual(1, queryset.count())
        self.assertNotEqual(vessel, queryset[0])

        # Release the vessel. It should still be dirty.
        maindb.record_released_vessel(vessel)

        # We expect one available vessel, and it shouldn't be the acquired one.
        queryset = _get_queryset_include_nat(userport)
        self.assertEqual(1, queryset.count())
        self.assertNotEqual(vessel, queryset[0])

        # Mark the vessel as clean (as if the backend cleaned it up).
        maindb.mark_vessel_as_clean(vessel)

        # We expect two available vessels.
        queryset = _get_queryset_include_nat(userport)
        self.assertEqual(2, queryset.count())
    def test_get_queryset_vessel_acquired_by_user_changes(self):
        """
    This is ultimately testing
    maindb._get_queryset_of_all_available_vessels_for_a_port_include_nat_nodes()
    """

        # 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

        # Create two nodes that have three vessels but only one vessel on the user's port.
        portlist = [userport - 1, userport, userport + 1]
        ip = "127.0.0.1"
        create_node_and_vessels_with_one_port_each(ip, portlist)
        ip = "127.0.0.2"
        create_node_and_vessels_with_one_port_each(ip, portlist)

        # We expect two available vessels.
        queryset = _get_queryset_include_nat(userport)
        self.assertEqual(2, queryset.count())

        # Mark one of the vessels as acquired.
        vessel = queryset[0]
        maindb.record_acquired_vessel(user, vessel)

        # We expect one available vessel, and it shouldn't be the acquired one.
        queryset = _get_queryset_include_nat(userport)
        self.assertEqual(1, queryset.count())
        self.assertNotEqual(vessel, queryset[0])

        # Release the vessel. It should still be dirty.
        maindb.record_released_vessel(vessel)

        # We expect one available vessel, and it shouldn't be the acquired one.
        queryset = _get_queryset_include_nat(userport)
        self.assertEqual(1, queryset.count())
        self.assertNotEqual(vessel, queryset[0])

        # Mark the vessel as clean (as if the backend cleaned it up).
        maindb.mark_vessel_as_clean(vessel)

        # We expect two available vessels.
        queryset = _get_queryset_include_nat(userport)
        self.assertEqual(2, queryset.count())
  
  node = maindb.get_node(node_id)
  if node.is_active is False:
    message = "Vessel's node is no longer active once the node lock was obtained."
    raise UnableToAcquireResourcesError("UnableToAcquireResourcesError: " + message)
  
  # This will raise a UnableToAcquireResourcesException if it fails (e.g if
  # the node is down). We want to allow the exception to be passed up to
  # the caller.
  try:
    backend.acquire_vessel(geniuser, vessel)
  except UnableToAcquireResourcesError, e:
    raise UnableToAcquireResourcesError("UnableToAcquireResourcesError: " + str(e))
  
  # Update the database to reflect the successful vessel acquisition.
  maindb.record_acquired_vessel(geniuser, vessel)
    
  # The _acquire_vessels_from_list() function will make use of this return value.
  return vessel





@log_function_call
def flag_vessels_for_user_keys_sync(lockserver_handle, vessel_list):
  """
  This function will mark (flag) the vessels in vessel_list as needing
  their user keys synced. The backend will then notice the vessels flagged
  in this way and will sync the user keys.
  
    if node.is_active is False:
        message = "Vessel's node is no longer active once the node lock was obtained."
        raise UnableToAcquireResourcesError("UnableToAcquireResourcesError: " +
                                            message)

    # This will raise a UnableToAcquireResourcesException if it fails (e.g if
    # the node is down). We want to allow the exception to be passed up to
    # the caller.
    try:
        backend.acquire_vessel(geniuser, vessel)
    except UnableToAcquireResourcesError, e:
        raise UnableToAcquireResourcesError("UnableToAcquireResourcesError: " +
                                            str(e))

    # Update the database to reflect the successful vessel acquisition.
    maindb.record_acquired_vessel(geniuser, vessel)

    # The _acquire_vessels_from_list() function will make use of this return value.
    return vessel


@log_function_call
def flag_vessels_for_user_keys_sync(lockserver_handle, vessel_list):
    """
  This function will mark (flag) the vessels in vessel_list as needing
  their user keys synced. The backend will then notice the vessels flagged
  in this way and will sync the user keys.
  
  We don't try to do the actual updating of user keys on vessels as that seems
  like a bad user experience, especially down the road when we may allow the
  users some form of giving others access to their vessels. Imagine a user wants