コード例 #1
0
ファイル: nodestatus.py プロジェクト: Ashmita89/attic
def _release_vessel(readonly, vessel):
  if vessel not in actionstaken["vessel_released"]:
    actionstaken["vessel_released"].append(vessel)
  
  if readonly:
    log.info(str(vessel) + " Not recording vessel as released because called in readonly mode.")
  else:
    log.info(str(vessel) + " Recording vessel as released.")
    maindb.record_released_vessel(vessel)
コード例 #2
0
def _release_vessel(readonly, vessel):
    if vessel not in actionstaken["vessel_released"]:
        actionstaken["vessel_released"].append(vessel)

    if readonly:
        log.info(
            str(vessel) +
            " Not recording vessel as released because called in readonly mode."
        )
    else:
        log.info(str(vessel) + " Recording vessel as released.")
        maindb.record_released_vessel(vessel)
コード例 #3
0
def stop_all_vessels_on_node(node_id):

    try:
        node = maindb.get_node(node_id)
    except DoesNotExistError:
        print "No such node"
        sys.exit(1)

    if not node.is_active:
        print "This node is marked as inactive, thus the backend will not try to clean up vessels."
        sys.exit(0)

    if node.is_broken:
        print "This node is marked as broken, thus the backend will not try to clean up vessels."
        sys.exit(0)

    vessels_on_node = maindb.get_vessels_on_node(node)
    if not vessels_on_node:
        print "No vessels on node."
        sys.exit(0)

    lockserver_handle = lockserver.create_lockserver_handle()
    try:
        print "Indicating to the backend to release/reset all %s vessels." % len(
            vessels_on_node)
        lockserver.lock_node(lockserver_handle, node_id)
        try:
            for vessel in vessels_on_node:
                maindb.record_released_vessel(vessel)
        finally:
            lockserver.unlock_node(lockserver_handle, node_id)

        print "Releases indicated. Monitoring db to see if the backend cleaned them up."
        while True:
            for vessel in vessels_on_node[:]:
                updated_vessel = maindb.get_vessel(node_id, vessel.name)
                if updated_vessel.is_dirty:
                    print "Vessel %s has not been cleaned up yet." % updated_vessel
                else:
                    print "Vessel %s has been cleaned up." % updated_vessel
                    vessels_on_node.remove(vessel)
            if not vessels_on_node:
                print "All vessels have been cleaned up."
                break
            else:
                print "%s vessels remain to be cleaned up." % len(
                    vessels_on_node)
            print "Sleeping 10 seconds."
            time.sleep(10)

    finally:
        lockserver.destroy_lockserver_handle(lockserver_handle)
コード例 #4
0
def stop_all_vessels_on_node(node_id):

  try:
    node = maindb.get_node(node_id)
  except DoesNotExistError:
    print "No such node"
    sys.exit(1)

  if not node.is_active:
    print "This node is marked as inactive, thus the backend will not try to clean up vessels."
    sys.exit(0)

  if node.is_broken:
    print "This node is marked as broken, thus the backend will not try to clean up vessels."
    sys.exit(0)

  vessels_on_node = maindb.get_vessels_on_node(node)
  if not vessels_on_node:
    print "No vessels on node."
    sys.exit(0)

  lockserver_handle = lockserver.create_lockserver_handle()
  try:
    print "Indicating to the backend to release/reset all %s vessels." % len(vessels_on_node)
    lockserver.lock_node(lockserver_handle, node_id)
    try:
      for vessel in vessels_on_node:
        maindb.record_released_vessel(vessel)
    finally:
      lockserver.unlock_node(lockserver_handle, node_id)

    print "Releases indicated. Monitoring db to see if the backend cleaned them up."
    while True:
      for vessel in vessels_on_node[:]:
        updated_vessel = maindb.get_vessel(node_id, vessel.name)
        if updated_vessel.is_dirty:
          print "Vessel %s has not been cleaned up yet." % updated_vessel
        else:
          print "Vessel %s has been cleaned up." % updated_vessel
          vessels_on_node.remove(vessel)
      if not vessels_on_node:
        print "All vessels have been cleaned up."
        break
      else:
        print "%s vessels remain to be cleaned up." % len(vessels_on_node)
      print "Sleeping 10 seconds."
      time.sleep(10)

  finally:
    lockserver.destroy_lockserver_handle(lockserver_handle)
コード例 #5
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())
コード例 #6
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())
コード例 #7
0
def _do_release_vessel(vessel, geniuser):
  """
  Obtains a lock on the node the vessel is on and then makes a call to the
  backend to release the vessel.
  """
  
  if vessel.acquired_by_user != geniuser:
    # The vessel was either already released, someone is trying to do things
    # they shouldn't, or we have a bug.
    log.info("Not releasing vessel " + str(vessel) + 
             " because it is not acquired by user " + str(geniuser))
    return
  
  # We don't check for node.is_active == True because we might as well have
  # the backend try to clean up the vessel even if the database says it's
  # inactive (maybe the node is back online?).
  
  # This will not raise an exception, even if the node the vessel is on is down.
  backend.release_vessel(vessel)
  
  # Update the database to reflect the release of the vessel.
  maindb.record_released_vessel(vessel)