コード例 #1
0
    def setUp(self):

        self._my_acs_client = create_autospec(PySimpleClient)
        self._logger = logging.Logger("test_logger")
        self._logger.setLevel(logging.CRITICAL)
        #self._my_acs_client.getLogger = MagicMock(return_value=self._logger)
        config = RecorderConfig()
        config.backend_type = BACKEND_TYPE.DUMMY
        self._front_end = FrontEnd(config, self._my_acs_client)
        self._my_component_id = "TEST_PROPERTIES_COMPONENT"
コード例 #2
0
    def get_config(self):
        """
        Factory to create the configuration of the recorder

        The configuration will be created from the parsed configuration data.
        @return: Configuration of the recorder.
        @rtype: ctamonitoring.property_recorder.config.RecorderConfig
        """
        recorder_config = RecorderConfig()

        if 'default_timer_trigger' in self._args:
            recorder_config.default_timer_trigger = (
                self._args['default_timer_trigger'])
        if 'max_comps' in self._args:
            recorder_config.max_comps = self._args['max_comps']
        if 'max_props' in self._args:
            recorder_config.max_props = self._args['max_props']
        if 'checking_period' in self._args:
            recorder_config.checking_period = self._args['checking_period']
        if 'backend_type' in self._args:
            recorder_config.backend_type = self._args['backend_type']
        if 'backend_config' in self._args:
            recorder_config.backend_config = self._args['backend_config']
        if 'is_include_mode' in self._args:
            recorder_config.is_include_mode = self._args['is_include_mode']
        if 'component_list' in self._args:
            recorder_config.set_components(self._args['component_list'])
        recorder_config.autostart = False  # in standalone mode recording start automatically anyway

        return recorder_config
コード例 #3
0
    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
コード例 #4
0
 def setUp(self):
     self._my_acs_client = PySimpleClient()
     self._my_acs_client.getLogger().setLevel(logging.CRITICAL)
     self._front_end = FrontEnd(RecorderConfig(), self._my_acs_client)
     self.__my_component_id = "TEST_PROPERTIES_COMPONENT"
コード例 #5
0
ファイル: test_config.py プロジェクト: sliusar/ctamonitoring
 def setUp(self):
     self.recoder_config = RecorderConfig()
コード例 #6
0
ファイル: test_config.py プロジェクト: sliusar/ctamonitoring
class RecorderConfigTest(unittest.TestCase):
    a_long = 150
    a_float = 0.8
    a_neg_long = -1
    a_string = 'a'
    a_string_set = set(['a', 'b'])
    a_hybrid_set = set(['a', 1])
    a_backend_type = BACKEND_TYPE.MONGODB

    def setUp(self):
        self.recoder_config = RecorderConfig()

    def test_default_timer_trigger(self):
        # check the default value
        self.assertEqual(self.recoder_config.default_timer_trigger,
                         Defaults.default_timer_trigger)

        self.recoder_config.default_timer_trigger = self.a_float
        self.assertEqual(self.recoder_config.default_timer_trigger,
                         self.a_float)

        self.assertRaises(ValueError, setattr, self.recoder_config,
                          'default_timer_trigger', self.a_neg_long)
        self.assertRaises(ValueError, setattr, self.recoder_config,
                          'default_timer_trigger', self.a_string)

    def test_max_comps(self):
        self.assertEqual(self.recoder_config.max_comps, Defaults.max_comps)

        self.recoder_config.max_comps = self.a_long
        self.assertEqual(self.recoder_config.max_comps, self.a_long)

        self.assertRaises(ValueError, setattr, self.recoder_config,
                          'max_comps', self.a_neg_long)
        self.assertRaises(ValueError, setattr, self.recoder_config,
                          'max_comps', self.a_float)
        self.assertRaises(ValueError, setattr, self.recoder_config,
                          'max_comps', self.a_string)

    def test_max_props(self):
        # check the default value
        self.assertEqual(self.recoder_config.max_props, Defaults.max_props)

        self.recoder_config.max_props = self.a_long
        self.assertEqual(self.recoder_config.max_props, self.a_long)

        self.assertRaises(ValueError, setattr, self.recoder_config,
                          'max_props', self.a_neg_long)
        self.assertRaises(ValueError, setattr, self.recoder_config,
                          'max_props', self.a_float)
        self.assertRaises(ValueError, setattr, self.recoder_config,
                          'max_props', self.a_string)

    def test_checking_period(self):
        # check the default value
        self.assertEqual(self.recoder_config.checking_period,
                         Defaults.checking_period)

        self.recoder_config.checking_period = self.a_long
        self.assertEqual(self.recoder_config.checking_period, self.a_long)

        self.assertRaises(ValueError, setattr, self.recoder_config,
                          'checking_period', self.a_neg_long)
        self.assertRaises(ValueError, setattr, self.recoder_config,
                          'checking_period', self.a_float)
        self.assertRaises(ValueError, setattr, self.recoder_config,
                          'checking_period', self.a_string)

    def test_backend_type(self):
        # check the default value
        self.assertEqual(self.recoder_config.backend_type,
                         Defaults.backend_type)

        self.recoder_config.backend_type = self.a_backend_type
        self.assertEqual(self.recoder_config.backend_type, self.a_backend_type)

        self.assertRaises(ValueError, setattr, self.recoder_config,
                          'backend_type', self.a_string)
        self.assertRaises(ValueError, setattr, self.recoder_config,
                          'backend_type', self.a_long)

    def test_is_include_mode(self):
        self.recoder_config.is_include_mode = True
        self.assertTrue(self.recoder_config.is_include_mode)

        self.recoder_config.is_include_mode = False
        self.assertFalse(self.recoder_config.is_include_mode)
        # should raise an exception for other data types
        self.assertRaises(TypeError, setattr, self.recoder_config,
                          'is_include_mode', self.a_long)
        self.assertRaises(TypeError, setattr, self.recoder_config,
                          'is_include_mode', self.a_float)
        self.assertRaises(TypeError, setattr, self.recoder_config,
                          'is_include_mode', self.a_string)

    def test_components(self):

        self.assertRaises(NotImplementedError, setattr, self.recoder_config,
                          'components', self.a_string_set)

        self.recoder_config.set_components(self.a_string_set)
        self.assertEqual(self.recoder_config.components, self.a_string_set)

        self.assertRaises(TypeError, self.recoder_config.set_components,
                          self.a_float)

        self.assertRaises(TypeError, self.recoder_config.set_components,
                          self.a_hybrid_set)
コード例 #7
0
 def setUp(self):
     recorder_config = RecorderConfig()
     self.recorder = MockedStandaloneRecorder(
         recorder_config, logging.CRITICAL)