def test_reusing_first_available_mapping_id(self): """Ensure that we reuse the first available ID. Make sure that the next lowest ID is obtained from the mapping table when there are "holes" from deletions. Database query sorts the entries, so will return them in order. Using tunnel ID, as the logic is the same for each ID type. """ self.query_mock.return_value = [(0, ), (1, ), (2, ), (5, ), (6, )] next_id = csr_db.get_next_available_tunnel_id(self.session) self.assertEqual(3, next_id)
def test_reusing_first_available_mapping_id(self): """Ensure that we reuse the first available ID. Make sure that the next lowest ID is obtained from the mapping table when there are "holes" from deletions. Database query sorts the entries, so will return them in order. Using tunnel ID, as the logic is the same for each ID type. """ self.query_mock.return_value = [(0, ), (1, ), (2, ), (5, ), (6, )] next_id = csr_db.get_next_available_tunnel_id(self.session) self.assertEqual(3, next_id)
def test_identifying_first_mapping_id(self): """Make sure first available ID is obtained for each ID type.""" # Simulate mapping table is empty - get first one self.query_mock.return_value = [] next_id = csr_db.get_next_available_tunnel_id(self.session) self.assertEqual(0, next_id) next_id = csr_db.get_next_available_ike_policy_id(self.session) self.assertEqual(1, next_id) next_id = csr_db.get_next_available_ipsec_policy_id(self.session) self.assertEqual(1, next_id)
def test_identifying_first_mapping_id(self): """Make sure first available ID is obtained for each ID type.""" # Simulate mapping table is empty - get first one self.query_mock.return_value = [] next_id = csr_db.get_next_available_tunnel_id(self.session) self.assertEqual(0, next_id) next_id = csr_db.get_next_available_ike_policy_id(self.session) self.assertEqual(1, next_id) next_id = csr_db.get_next_available_ipsec_policy_id(self.session) self.assertEqual(1, next_id)
def test_last_mapping_id_available(self): """Make sure can get the last ID for each of the table types.""" # Simulate query indicates table is full self.query_mock.return_value = [(x,) for x in xrange(csr_db.MAX_CSR_TUNNELS - 1)] next_id = csr_db.get_next_available_tunnel_id(self.session) self.assertEqual(csr_db.MAX_CSR_TUNNELS - 1, next_id) self.query_mock.return_value = [(x,) for x in xrange(1, csr_db.MAX_CSR_IKE_POLICIES)] next_id = csr_db.get_next_available_ike_policy_id(self.session) self.assertEqual(csr_db.MAX_CSR_IKE_POLICIES, next_id) self.query_mock.return_value = [(x,) for x in xrange(1, csr_db.MAX_CSR_IPSEC_POLICIES)] next_id = csr_db.get_next_available_ipsec_policy_id(self.session) self.assertEqual(csr_db.MAX_CSR_IPSEC_POLICIES, next_id)
def test_last_mapping_id_available(self): """Make sure can get the last ID for each of the table types.""" # Simulate query indicates table is full self.query_mock.return_value = [ (x, ) for x in xrange(csr_db.MAX_CSR_TUNNELS - 1)] next_id = csr_db.get_next_available_tunnel_id(self.session) self.assertEqual(csr_db.MAX_CSR_TUNNELS - 1, next_id) self.query_mock.return_value = [ (x, ) for x in xrange(1, csr_db.MAX_CSR_IKE_POLICIES)] next_id = csr_db.get_next_available_ike_policy_id(self.session) self.assertEqual(csr_db.MAX_CSR_IKE_POLICIES, next_id) self.query_mock.return_value = [ (x, ) for x in xrange(1, csr_db.MAX_CSR_IPSEC_POLICIES)] next_id = csr_db.get_next_available_ipsec_policy_id(self.session) self.assertEqual(csr_db.MAX_CSR_IPSEC_POLICIES, next_id)