示例#1
0
    def _get_action_instance(self):
        actions_cls = action_loader.register_plugin(Action, self._file_path)
        action_cls = actions_cls[0] if actions_cls and len(
            actions_cls) > 0 else None

        if not action_cls:
            raise Exception(
                'File "%s" has no action or the file doesn\'t exist.' %
                (self._file_path))

        config_parser = ContentPackConfigParser(pack_name=self._pack)
        config = config_parser.get_action_config(
            action_file_path=self._file_path)

        if config:
            LOG.info('Using config "%s" for action "%s"' %
                     (config.file_path, self._file_path))

            action_instance = action_cls(config=config.config)
        else:
            LOG.info('No config found for action "%s"' % (self._file_path))
            action_instance = action_cls(config={})

        # Setup action_instance proeprties
        action_instance.logger = self._set_up_logger(action_cls.__name__)
        action_instance.datastore = DatastoreService(
            logger=action_instance.logger,
            pack_name=self._pack,
            class_name=action_cls.__name__,
            api_username="******")

        return action_instance
示例#2
0
    def _get_action_instance(self):
        actions_cls = action_loader.register_plugin(Action, self._file_path)
        action_cls = actions_cls[0] if actions_cls and len(actions_cls) > 0 else None

        if not action_cls:
            raise Exception('File "%s" has no action or the file doesn\'t exist.' %
                            (self._file_path))

        config_parser = ContentPackConfigParser(pack_name=self._pack)
        config = config_parser.get_action_config(action_file_path=self._file_path)

        if config:
            LOG.info('Using config "%s" for action "%s"' % (config.file_path,
                                                            self._file_path))

            action_instance = action_cls(config=config.config)
        else:
            LOG.info('No config found for action "%s"' % (self._file_path))
            action_instance = action_cls(config={})

        # Setup action_instance proeprties
        action_instance.logger = self._set_up_logger(action_cls.__name__)
        action_instance.datastore = DatastoreService(logger=action_instance.logger,
                                                     pack_name=self._pack,
                                                     class_name=action_cls.__name__,
                                                     api_username="******")

        return action_instance
示例#3
0
    def _get_action_instance(self):
        actions_cls = action_loader.register_plugin(Action, self._file_path)
        action_cls = actions_cls[0] if actions_cls and len(
            actions_cls) > 0 else None

        if not action_cls:
            raise Exception(
                'File "%s" has no action or the file doesn\'t exist.' %
                (self._file_path))

        config_parser = ContentPackConfigParser(pack_name=self._pack)
        config = config_parser.get_action_config(
            action_file_path=self._file_path)

        if config:
            LOG.info('Using config "%s" for action "%s"' %
                     (config.file_path, self._file_path))
            config = config.config
        else:
            LOG.info('No config found for action "%s"' % (self._file_path))
            config = None

        action_service = ActionService(action_wrapper=self)
        action_instance = get_action_class_instance(
            action_cls=action_cls,
            config=config,
            action_service=action_service)
        return action_instance
示例#4
0
    def test_get_action_and_sensor_config_no_config(self):
        pack_name = 'dummy_pack_1'
        parser = ContentPackConfigParser(pack_name=pack_name)

        config = parser.get_action_config(action_file_path='my_action.py')
        self.assertEqual(config, None)

        config = parser.get_sensor_config(sensor_file_path='my_sensor.py')
        self.assertEqual(config, None)
示例#5
0
    def test_get_action_and_sensor_config_existing_config(self):
        pack_name = 'dummy_pack_2'
        parser = ContentPackConfigParser(pack_name=pack_name)

        config = parser.get_action_config(action_file_path='my_action.py')
        self.assertEqual(config.config['section1']['key1'], 'value1')
        self.assertEqual(config.config['section2']['key10'], 'value10')

        config = parser.get_sensor_config(sensor_file_path='my_sensor.py')
        self.assertEqual(config.config['section1']['key1'], 'value1')
        self.assertEqual(config.config['section2']['key10'], 'value10')
示例#6
0
    def _load_action(self):
        actions_kls = action_loader.register_plugin(Action, self.entry_point)
        action_kls = actions_kls[0] if actions_kls and len(actions_kls) > 0 else None

        if not action_kls:
            raise Exception('%s has no action.' % self.entry_point)

        config_parser = ContentPackConfigParser(pack_name=self.pack)
        config = config_parser.get_action_config(action_file_path=self.entry_point)

        if config:
            LOG.info('Using config "%s" for action "%s"' % (config.file_path,
                                                            self.entry_point))

            return action_kls(config=config.config)
        else:
            LOG.info('No config found for action "%s"' % (self.entry_point))
            return action_kls(config={})
    def _get_action_instance(self):
        actions_cls = action_loader.register_plugin(Action, self._file_path)
        action_cls = actions_cls[0] if actions_cls and len(actions_cls) > 0 else None

        if not action_cls:
            raise Exception('File "%s" has no action or the file doesn\'t exist.' %
                            (self._file_path))

        config_parser = ContentPackConfigParser(pack_name=self._pack)
        config = config_parser.get_action_config(action_file_path=self._file_path)

        if config:
            LOG.info('Using config "%s" for action "%s"' % (config.file_path,
                                                            self._file_path))

            return action_cls(config=config.config)
        else:
            LOG.info('No config found for action "%s"' % (self._file_path))
            return action_cls(config={})
示例#8
0
 def test_get_action_config_inexistent_pack(self):
     parser = ContentPackConfigParser(pack_name='inexistent')
     config = parser.get_action_config(action_file_path='test.py')
     self.assertEqual(config, None)