def _get_queryset_include_nat(port): """ Give a nicer though less accurate name to the function as we're using it a lot here in the tests. """ return maindb._get_queryset_of_all_available_vessels_for_a_port_include_nat_nodes( port)
def test_acquire_specific_vessels(self): # 8 vessels will ultimately be acquired. calls_results = [True] * 8 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 vesselcount = maindb.get_user_free_vessel_credits(user) # We use userport + 1 to make sure the user isn't being restricted to only # vessels that have their user port in their port list. testutil.create_nodes_on_different_subnets(vesselcount + 10, [userport + 1]) vessels = list(maindb._get_queryset_of_all_available_vessels_for_a_port_include_nat_nodes(userport + 1)) # Request the first 4 vessels in the list. first_vessel_list = interface.acquire_specific_vessels(user, vessels[:4]) # Now request the first 6 vessels in the list. We should only get 2. second_vessel_list = interface.acquire_specific_vessels(user, vessels[:6]) self.assertEqual(4, len(first_vessel_list)) self.assertEqual(2, len(second_vessel_list)) # Now ask for more vessels than the user has available, regardless of the # fact that some of the requested vessels aren't available. requestcount = vesselcount - 6 + 1 func = interface.acquire_specific_vessels args = (user, vessels[:requestcount]) self.assertRaises(InsufficientUserResourcesError, func, *args)
def get_available_vessel_counts_by_port(): # Set the log level high enough so that we don't produce a bunch of logging # output due to the logging decorators. initial_log_level = log.loglevel log.set_log_level(log.LOG_LEVEL_INFO) available_vessels_dict = {} for port in maindb.ALLOWED_USER_PORTS: available_vessels_dict[port] = {} available_vessels_dict[port]["all"] = maindb._get_queryset_of_all_available_vessels_for_a_port_include_nat_nodes(port).count() available_vessels_dict[port]["no_nat"] = maindb._get_queryset_of_all_available_vessels_for_a_port_exclude_nat_nodes(port).count() available_vessels_dict[port]["only_nat"] = maindb._get_queryset_of_all_available_vessels_for_a_port_only_nat_nodes(port).count() # Restore the original log level. log.set_log_level(initial_log_level) return available_vessels_dict
def _get_queryset_include_nat(port): """ Give a nicer though less accurate name to the function as we're using it a lot here in the tests. """ return maindb._get_queryset_of_all_available_vessels_for_a_port_include_nat_nodes(port)