def __call__(self, parser, namespace, values, option_string=None):
        try:
            backend_type = enum_util.from_string(BACKEND_TYPE, values)
        except KeyError:
            allowed = str([e.name for e in BACKEND_TYPE])
            parser.error(
                "'%s' is not a valid backend type. Allowed values are: '%s'" %
                (values, allowed))

        setattr(namespace, self.dest, backend_type)
    def get_cdb_data(component_name):

        cdb = CDBAccess.cdb()

        try:
            componentCDB = XmlObjectifier.XmlObject(
                cdb.get_DAO('alma/%s' % (component_name)))
        except CDBRecordDoesNotExistEx as e:
            raise BadCdbRecorderConfig(e)
        except ExpatError as e:
            raise BadCdbRecorderConfig(e)
        except Exception as e:
            raise BadCdbRecorderConfig(e)

        recorder_config = RecorderConfig()

        try:
            recorder_config.default_timer_trigger = float(
                componentCDB.firstChild.getAttribute(
                    "default_timer_trigger")
                )

        except Exception as e:
            raise BadCdbRecorderConfig(e, "default_timer_trigger")

        try:
            recorder_config.max_comps = int(
                componentCDB.firstChild.getAttribute(
                    "max_comps")
                )
        except Exception as e:
            raise BadCdbRecorderConfig(e, "max_comps")

        try:
            recorder_config.max_props = int(
                componentCDB.firstChild.getAttribute(
                    "max_props")
                )
        except Exception as e:
                raise BadCdbRecorderConfig(e, "max_props")

        try:
            recorder_config.backend_type = enum_util.from_string(
                BACKEND_TYPE,
                componentCDB.firstChild.getAttribute(
                    "backend")
                )
        except Exception as e:
            raise BadCdbRecorderConfig(e, "backend")

        try:
            recorder_config.backend_config = ast.literal_eval(
                componentCDB.firstChild.getAttribute(
                    "backend_config"))
        except Exception as e:
            raise BadCdbRecorderConfig(e, "backend_config")

        try:
            recorder_config.checking_period = int(
                componentCDB.firstChild.getAttribute(
                    "checking_period")
                )
        except Exception as e:
            raise BadCdbRecorderConfig(e, "checking_period")

        try:

            if componentCDB.firstChild.getAttribute("is_include") == 'true':
                recorder_config.is_include_mode = True
            elif componentCDB.firstChild.getAttribute("is_include") == 'false':
                recorder_config.is_include_mode = False
            else:
                raise BadCdbRecorderConfig()
        except Exception as e:
            raise BadCdbRecorderConfig(e, "is_include")

        try:
            if componentCDB.firstChild.getAttribute("autostart") == 'true':
                recorder_config.autostart = True
            else:
                recorder_config.autostart = False
        except Exception as e:
            pass

        try:
            componentCDB.firstChild.getAttribute(
                "component_list")
            recorder_config.set_components(set(
                ast.literal_eval(componentCDB.firstChild.getAttribute(
                    "component_list")
                )))
        except Exception as e:
            raise BadCdbRecorderConfig(e, "component_list")

        return recorder_config
Example #3
0
    def test_from_string(self):
        test_enum = Enum('test_enum', 'DUMMY LOG MYSQL MONGODB')
        self.assertEqual(test_enum.LOG,
                         enum_util.from_string(test_enum, 'LOG'))

        self.assertRaises(KeyError, enum_util.from_string, test_enum, 'NOPE')