def test_db_manage_zk_route_target_missing(self):
     # create  vn
     vn_name = 'vn_' + self.id()
     vn_obj = self.create_virtual_network(vn_name, '10.0.0.0/24')
     ri_obj = self._vnc_lib.routing_instance_read(
         vn_obj.get_routing_instances()[0]['to'])
     rt_obj = self.wait_for_route_target(ri_obj)
     rt_id_str = "%(#)010d" % {
         '#': int(rt_obj.get_fq_name_str().split(':')[-1])
     }
     db_checker = db_manage.DatabaseChecker(
         *db_manage._parse_args('check --cluster_id %s' % self._cluster_id))
     db_healer = db_manage.DatabaseHealer(
         *db_manage._parse_args('--execute heal --cluster_id %s' %
                                self._cluster_id))
     path = '%s%s/%s' % (self._cluster_id, db_checker.BASE_RTGT_ID_ZK_PATH,
                         rt_id_str)
     print "make sure node exists in zk"
     self.assertIsNotNone(db_checker._zk_client.get(path))
     print "Remove node from zk"
     with db_checker._zk_client.patch_path(path):
         print "check for node to be missing in zk"
         errors = db_checker.check_route_targets_id()
         error_types = [type(x) for x in errors]
         self.assertIn(db_manage.ZkRTgtIdMissingError, error_types)
         print "heal missing node in zk"
         db_healer.heal_route_targets_id()
         print "check for node to be re-created in zk by heal"
         errors = db_checker.check_route_targets_id()
         self.assertEqual([], errors)
Exemple #2
0
    def test_db_manage_zk_route_target_missing(self):
        vn_obj = self.create_virtual_network('vn_' + self.id(), '10.0.0.0/24')
        ri_fq_name = vn_obj.fq_name + [vn_obj.fq_name[-1]]
        rt_obj = self.wait_for_route_target(vn_obj)
        rt_id_str = "%(#)010d" % {
            '#': int(rt_obj.get_fq_name_str().split(':')[-1])
        }
        db_checker = db_manage.DatabaseChecker(
            *db_manage._parse_args('check --cluster_id %s' % self._cluster_id))
        db_cleaner = db_manage.DatabaseCleaner(
            *db_manage._parse_args('--execute clean --cluster_id %s' %
                                   self._cluster_id))
        path = '%s%s%s' % (self._cluster_id, db_checker.BASE_RTGT_ID_ZK_PATH,
                           rt_id_str)
        self.assertEqual(
            db_checker._zk_client.get(path)[0], ':'.join(ri_fq_name))
        with db_checker._zk_client.patch_path(path):
            errors = db_checker.check_route_targets_id()
            error_types = [type(x) for x in errors]
            self.assertIn(db_manage.SchemaRTgtIdExtraError, error_types)
            self.assertIn(db_manage.ConfigRTgtIdExtraError, error_types)

            db_cleaner.clean_stale_route_target_id()
            errors = db_checker.check_route_targets_id()
            self.assertEqual([], errors)
            self.assertIsNone(db_checker._zk_client.exists(path))
            self.assertRaises(NoIdError,
                              self._vnc_lib.route_target_read,
                              id=rt_obj.uuid)

            test_common.reinit_schema_transformer()
            new_rt_obj = self.wait_for_route_target(vn_obj)
            new_rt_id_str = "%(#)010d" % {
                '#': int(new_rt_obj.get_fq_name_str().split(':')[-1])
            }
            new_path = '%s%s%s' % (
                self._cluster_id,
                db_checker.BASE_RTGT_ID_ZK_PATH,
                new_rt_id_str,
            )
            self.assertEqual(
                db_checker._zk_client.get(new_path)[0], ':'.join(ri_fq_name))
    def test_db_manage_zk_route_target_missing(self):
        vn_obj = self.create_virtual_network('vn_' + self.id(), '10.0.0.0/24')
        ri_fq_name = vn_obj.fq_name + [vn_obj.fq_name[-1]]
        rt_obj = self.wait_for_route_target(vn_obj)
        rt_id_str = "%(#)010d" % {
            '#': int(rt_obj.get_fq_name_str().split(':')[-1])}
        db_checker = db_manage.DatabaseChecker(
            *db_manage._parse_args('check --cluster_id %s' % self._cluster_id))
        db_cleaner = db_manage.DatabaseCleaner(
            *db_manage._parse_args('--execute clean --cluster_id %s' %
                                   self._cluster_id))
        path = '%s%s/%s' % (
            self._cluster_id, db_checker.BASE_RTGT_ID_ZK_PATH, rt_id_str)
        self.assertEqual(db_checker._zk_client.get(path)[0],
                         ':'.join(ri_fq_name))
        with db_checker._zk_client.patch_path(path):
            errors = db_checker.check_route_targets_id()
            error_types = [type(x) for x in errors]
            self.assertIn(db_manage.SchemaRTgtIdExtraError, error_types)
            self.assertIn(db_manage.ConfigRTgtIdExtraError, error_types)

            db_cleaner.clean_stale_route_target_id()
            errors = db_checker.check_route_targets_id()
            self.assertEqual([], errors)
            self.assertIsNone(db_checker._zk_client.exists(path))
            self.assertRaises(NoIdError, self._vnc_lib.route_target_read,
                              id=rt_obj.uuid)

            test_common.reinit_schema_transformer()
            new_rt_obj = self.wait_for_route_target(vn_obj)
            new_rt_id_str = "%(#)010d" % {
                '#': int(new_rt_obj.get_fq_name_str().split(':')[-1])}
            new_path = '%s%s/%s' % (
                self._cluster_id,
                db_checker.BASE_RTGT_ID_ZK_PATH,
                new_rt_id_str,
            )
            self.assertEqual(db_checker._zk_client.get(new_path)[0],
                             ':'.join(ri_fq_name))
    def test_route_target_id_collision(self):
        db_checker = db_manage.DatabaseChecker(
            *db_manage._parse_args('check --cluster_id %s' % self._cluster_id))
        zkc = db_checker._zk_client

        DEPRECATED_BASE_RTGT = "/".join(
            [x for x in db_checker.BASE_RTGT_ID_ZK_PATH.split("/")
             if x not in ["type0", "type1_2"]])

        vn_exst_obj = self.create_virtual_network('existing_vn_%s' % self.id())
        rt_exst_obj = self.wait_for_route_target(vn_exst_obj)
        rt_exst_id_str = "%(#)010d" % {
            '#': int(rt_exst_obj.get_fq_name_str().split(':')[-1])}

        # TestRouteTarget/id/bgp/route-target/type0/{rt_exst_id_str}
        node_exst_path = '%s%s%s' % (
            self._cluster_id, db_checker.BASE_RTGT_ID_ZK_PATH, rt_exst_id_str)

        # TestRouteTarget/id/bgp/route-target/{rt_exst_id_str}
        node_collision_path = '%s%s%s' % (
            self._cluster_id,
            DEPRECATED_BASE_RTGT,
            rt_exst_id_str)

        # TestRouteTarget/id/bgp/route-target
        rt_path = '%s%s' % (self._cluster_id, DEPRECATED_BASE_RTGT)

        # invariant
        _, zk_node_stat = zkc.get(node_exst_path)

        # create node in ZK
        zkc.create_node(node_collision_path,
                        "6a77156f-e062-4d6b-b228-05a173b612e3")

        # is colliding node present
        rts = zkc.get_children(rt_path)
        self.assertIn(rt_exst_id_str, rts)

        # reinit ST
        test_common.reinit_schema_transformer()
        self.wait_for_route_target(vn_exst_obj)

        # check if initially existing node hasn't been modified
        _, new_zk_node_stat = db_checker._zk_client.get(node_exst_path)
        self.assertEqual(zk_node_stat, new_zk_node_stat)

        # is colliding node gone
        rts = zkc.get_children(rt_path)
        self.assertNotIn(rt_exst_id_str, rts)
Exemple #5
0
    def test_asn_change_when_zk_rt_missing(self):
        vn_obj = self.create_virtual_network('vn_for_asn' + self.id(),
                                             '10.0.0.0/24')
        ri_fq_name = vn_obj.fq_name + [vn_obj.fq_name[-1]]
        rt_obj = self.wait_for_route_target(vn_obj)
        rt_id_str = "%(#)010d" % {
            '#': int(rt_obj.get_fq_name_str().split(':')[-1])
        }
        db_checker = db_manage.DatabaseChecker(
            *db_manage._parse_args('check --cluster_id %s' % self._cluster_id))
        path = '%s%s%s' % (self._cluster_id, db_checker.BASE_RTGT_ID_ZK_PATH,
                           rt_id_str)
        self.assertEqual(
            db_checker._zk_client.get(path)[0], ':'.join(ri_fq_name))
        with db_checker._zk_client.patch_path(path):
            errors = db_checker.check_route_targets_id()
            error_types = [type(x) for x in errors]
            self.assertIn(db_manage.SchemaRTgtIdExtraError, error_types)
            self.assertIn(db_manage.ConfigRTgtIdExtraError, error_types)

            free_rt_orig = SchemaTransformerDB.free_route_target

            # Flag to be used to check free_route_target function failure
            has_test_failed = [False]

            def mock_free_rt(*args, **kwargs):
                try:
                    return free_rt_orig(*args, **kwargs)
                except Exception:
                    has_test_failed[0] = True

            SchemaTransformerDB.free_route_target = mock_free_rt
            gsc = self._vnc_lib.global_system_config_read(
                GlobalSystemConfig().fq_name)

            gsc.enable_4byte_as = True
            gsc.autonomous_system = 81000
            self._vnc_lib.global_system_config_update(gsc)

            # Wait for Schema_tranformer to process ASN change
            gevent.sleep(10)
            SchemaTransformerDB.free_route_target = free_rt_orig
            if has_test_failed[0]:
                self.fail("free_route_target failed in schema transformer")