Esempio n. 1
0
    def test_add_multi_segment_binding(self):
        with self.network() as network:
            TEST_NETWORK_ID = network['network']['id']

            self.assertRaises(c_exc.NetworkBindingNotFound,
                              n1kv_db_v2.get_network_binding,
                              self.session,
                              TEST_NETWORK_ID)

            p = _create_test_network_profile_if_not_there(
                self.session,
                TEST_NETWORK_PROFILE_MULTI_SEGMENT)
            n1kv_db_v2.add_network_binding(
                self.session, TEST_NETWORK_ID,
                c_const.NETWORK_TYPE_MULTI_SEGMENT,
                None, 0, '0.0.0.0', p.id,
                [(TEST_NETWORK_ID2, TEST_NETWORK_ID3)])
            binding = n1kv_db_v2.get_network_binding(
                self.session, TEST_NETWORK_ID)
            self.assertIsNotNone(binding)
            self.assertEqual(binding.network_id, TEST_NETWORK_ID)
            self.assertEqual(binding.network_type,
                             c_const.NETWORK_TYPE_MULTI_SEGMENT)
            self.assertIsNone(binding.physical_network)
            self.assertEqual(binding.segmentation_id, 0)
            ms_binding = (n1kv_db_v2.get_multi_segment_network_binding(
                          self.session, TEST_NETWORK_ID,
                          (TEST_NETWORK_ID2, TEST_NETWORK_ID3)))
            self.assertIsNotNone(ms_binding)
            self.assertEqual(ms_binding.multi_segment_id, TEST_NETWORK_ID)
            self.assertEqual(ms_binding.segment1_id, TEST_NETWORK_ID2)
            self.assertEqual(ms_binding.segment2_id, TEST_NETWORK_ID3)
            ms_members = (n1kv_db_v2.get_multi_segment_members(
                          self.session, TEST_NETWORK_ID))
            self.assertEqual(ms_members,
                             [(TEST_NETWORK_ID2, TEST_NETWORK_ID3)])
            self.assertTrue(n1kv_db_v2.is_multi_segment_member(
                            self.session, TEST_NETWORK_ID2))
            self.assertTrue(n1kv_db_v2.is_multi_segment_member(
                            self.session, TEST_NETWORK_ID3))
            n1kv_db_v2.del_multi_segment_binding(
                self.session, TEST_NETWORK_ID,
                [(TEST_NETWORK_ID2, TEST_NETWORK_ID3)])
            ms_members = (n1kv_db_v2.get_multi_segment_members(
                          self.session, TEST_NETWORK_ID))
            self.assertEqual(ms_members, [])
    def test_add_multi_segment_binding(self):
        with self.network() as network:
            TEST_NETWORK_ID = network['network']['id']

            self.assertRaises(c_exc.NetworkBindingNotFound,
                              n1kv_db_v2.get_network_binding,
                              self.session,
                              TEST_NETWORK_ID)

            p = _create_test_network_profile_if_not_there(
                self.session,
                TEST_NETWORK_PROFILE_MULTI_SEGMENT)
            n1kv_db_v2.add_network_binding(
                self.session, TEST_NETWORK_ID,
                c_const.NETWORK_TYPE_MULTI_SEGMENT,
                None, 0, '0.0.0.0', p.id,
                [(TEST_NETWORK_ID2, TEST_NETWORK_ID3)])
            binding = n1kv_db_v2.get_network_binding(
                self.session, TEST_NETWORK_ID)
            self.assertIsNotNone(binding)
            self.assertEqual(binding.network_id, TEST_NETWORK_ID)
            self.assertEqual(binding.network_type,
                             c_const.NETWORK_TYPE_MULTI_SEGMENT)
            self.assertIsNone(binding.physical_network)
            self.assertEqual(binding.segmentation_id, 0)
            ms_binding = (n1kv_db_v2.get_multi_segment_network_binding(
                          self.session, TEST_NETWORK_ID,
                          (TEST_NETWORK_ID2, TEST_NETWORK_ID3)))
            self.assertIsNotNone(ms_binding)
            self.assertEqual(ms_binding.multi_segment_id, TEST_NETWORK_ID)
            self.assertEqual(ms_binding.segment1_id, TEST_NETWORK_ID2)
            self.assertEqual(ms_binding.segment2_id, TEST_NETWORK_ID3)
            ms_members = (n1kv_db_v2.get_multi_segment_members(
                          self.session, TEST_NETWORK_ID))
            self.assertEqual(ms_members,
                             [(TEST_NETWORK_ID2, TEST_NETWORK_ID3)])
            self.assertTrue(n1kv_db_v2.is_multi_segment_member(
                            self.session, TEST_NETWORK_ID2))
            self.assertTrue(n1kv_db_v2.is_multi_segment_member(
                            self.session, TEST_NETWORK_ID3))
            n1kv_db_v2.del_multi_segment_binding(
                self.session, TEST_NETWORK_ID,
                [(TEST_NETWORK_ID2, TEST_NETWORK_ID3)])
            ms_members = (n1kv_db_v2.get_multi_segment_members(
                          self.session, TEST_NETWORK_ID))
            self.assertEqual(ms_members, [])