Exemplo n.º 1
0
    def test_cluster_id_automatically_assigned(self):
        sc = SubCluster('sc-%s' % self.id())
        self.api.sub_cluster_create(sc)

        sc = self.api.sub_cluster_read(id=sc.uuid)
        self.assertIsNotNone(sc.get_sub_cluster_id())
        zk_db = self._api_server._db_conn._zk_db
        self.assertEqual(
            zk_db._get_sub_cluster_from_id(sc.get_sub_cluster_id()),
            sc.get_fq_name_str(),
        )
Exemplo n.º 2
0
    def test_change_global_asn_from_2_to_4_bytes(self):
        sc = SubCluster('sc-%s' % self.id())
        self.api.sub_cluster_create(sc)
        sc = self.api.sub_cluster_read(id=sc.uuid)
        allocated_id = sc.get_sub_cluster_id()
        self.assertIsNotNone(allocated_id)
        self.assertLess(allocated_id, 1 << 16)

        self._gsc.set_autonomous_system(ASN_4_BYTES)
        self._gsc.enable_4byte_as = True
        self.api.global_system_config_update(self._gsc)

        sc = self.api.sub_cluster_read(id=sc.uuid)
        self.assertEqual(sc.get_sub_cluster_id(), allocated_id)

        self._gsc.set_autonomous_system(ASN_2_BYTES)
        self._gsc.enable_4byte_as = False
        self.api.global_system_config_update(self._gsc)
Exemplo n.º 3
0
    def test_cannot_use_allocated_sub_cluster_id(self):
        # automatically allocated
        sc1 = SubCluster('sc1-%s' % self.id())
        self.api.sub_cluster_create(sc1)
        sc1 = self.api.sub_cluster_read(id=sc1.uuid)

        sc2 = SubCluster(
            'sc2-%s' % self.id(), sub_cluster_id=sc1.get_sub_cluster_id())
        self.assertRaises(BadRequest, self.api.sub_cluster_create, sc2)

        # or manually allocated
        sc3 = SubCluster(
            'sc3-%s' % self.id(), sub_cluster_id=self._id_range.pop())
        self.api.sub_cluster_create(sc3)

        sc4 = SubCluster(
            'sc4-%s' % self.id(),
            sub_cluster_id=sc3.get_sub_cluster_id())
        self.assertRaises(BadRequest, self.api.sub_cluster_create, sc4)
Exemplo n.º 4
0
    def test_sub_cluster_id_deallocated_on_delete(self):
        sc = SubCluster('sc-%s' % self.id())
        self.api.sub_cluster_create(sc)

        sc = self.api.sub_cluster_read(id=sc.uuid)
        self.api.sub_cluster_delete(id=sc.uuid)
        zk_db = self._api_server._db_conn._zk_db
        self.assertNotEqual(
            zk_db._get_sub_cluster_from_id(sc.get_sub_cluster_id()),
            sc.get_fq_name_str(),
        )
Exemplo n.º 5
0
    def test_manually_allocate_sub_cluster_id(self):
        sub_cluster_id = self._id_range.pop()
        sc = SubCluster('sc-%s' % self.id(), sub_cluster_id=sub_cluster_id)
        self.api.sub_cluster_create(sc)

        sc = self.api.sub_cluster_read(id=sc.uuid)
        self.assertEqual(sc.get_sub_cluster_id(), sub_cluster_id)
        zk_db = self._api_server._db_conn._zk_db
        self.assertEqual(
            zk_db._get_sub_cluster_from_id(sub_cluster_id),
            sc.get_fq_name_str(),
        )
Exemplo n.º 6
0
    def test_update_allocated_id(self):
        sc = SubCluster('sc-%s' % self.id())
        self.api.sub_cluster_create(sc)
        sc = self.api.sub_cluster_read(id=sc.uuid)
        allocated_id = sc.get_sub_cluster_id()
        self.assertIsNotNone(allocated_id)

        sub_cluster_id = self._id_range.pop()
        self.assertNotEqual(allocated_id, sub_cluster_id)
        sc.set_sub_cluster_id(sub_cluster_id)
        self.api.sub_cluster_update(sc)
        zk_db = self._api_server._db_conn._zk_db
        self.assertEqual(
            zk_db._get_sub_cluster_from_id(sub_cluster_id),
            sc.get_fq_name_str(),
        )
        self.assertIsNone(zk_db._get_sub_cluster_from_id(allocated_id))
Exemplo n.º 7
0
    def test_first_allocated_id_is_one(self):
        sc = SubCluster('sc-%s' % self.id())
        self.api.sub_cluster_create(sc)
        sc = self.api.sub_cluster_read(id=sc.uuid)

        self.assertEqual(sc.get_sub_cluster_id(), 1)