Beispiel #1
0
    def _invalid_wrong_node_type(self, system_data: SystemData):
        # Test invalid node type.
        node = ManagerObjNode()
        node.nodeId = 1
        node.hostname = "hostname_1"
        node.nodeType = "sensor"
        node.instance = "instance_1"
        node.connected = 1
        node.version = 1.0
        node.rev = 0
        node.username = "******"
        node.persistent = 1
        system_data.update_node(node)

        manager = ManagerObjManager()
        manager.nodeId = 1
        manager.managerId = 1
        manager.description = "manager_1"
        is_exception = False
        try:
            system_data.update_manager(manager)
        except ValueError:
            is_exception = True
        if not is_exception:
            self.fail("Exception because of wrong node type expected.")
    def _invalid_alert_level_missing(self, system_data: SystemData):
        # Test non-existing alert level.
        node = ManagerObjNode()
        node.nodeId = 1
        node.hostname = "hostname_1"
        node.nodeType = "alert"
        node.instance = "instance_1"
        node.connected = 1
        node.version = 1.0
        node.rev = 0
        node.username = "******"
        node.persistent = 1
        system_data.update_node(node)

        alert = ManagerObjAlert()
        alert.nodeId = 1
        alert.alertId = 1
        alert.clientAlertId = 1
        alert.alertLevels = [99]
        alert.description = "alert_1"
        is_exception = False
        try:
            system_data.update_alert(alert)
        except ValueError:
            is_exception = True
        if not is_exception:
            self.fail("Exception because of wrong node type expected.")
Beispiel #3
0
    def _invalid_wrong_node_type(self, system_data: SystemData):
        # Test invalid node type.
        node = ManagerObjNode()
        node.nodeId = 1
        node.hostname = "hostname_1"
        node.nodeType = "alert"
        node.instance = "instance_1"
        node.connected = 1
        node.version = 1.0
        node.rev = 0
        node.username = "******"
        node.persistent = 1
        system_data.update_node(node)

        sensor = ManagerObjSensor()
        sensor.nodeId = 1
        sensor.sensorId = 1
        sensor.clientSensorId = 1
        sensor.alertDelay = 0
        sensor.alertLevels = []
        sensor.description = "sensor_1"
        sensor.lastStateUpdated = 0
        sensor.state = 0
        sensor.dataType = SensorDataType.NONE
        is_exception = False
        try:
            system_data.update_sensor(sensor)
        except ValueError:
            is_exception = True
        if not is_exception:
            self.fail("Exception because of wrong node type expected.")

        system_data = SystemData()
Beispiel #4
0
    def test_invalid_manager_adding(self):
        """
        Tests sanity checks for Manager object adding.
        """
        system_data = SystemData()
        self._invalid_wrong_node_type(system_data)

        system_data = SystemData()
        self._invalid_node_missing(system_data)
    def test_invalid_alert_adding(self):
        """
        Tests sanity checks for Alert object adding.
        """
        system_data = SystemData()
        self._invalid_wrong_node_type(system_data)

        system_data = SystemData()
        self._invalid_node_missing(system_data)

        system_data = SystemData()
        self._invalid_alert_level_missing(system_data)
Beispiel #6
0
 def _invalid_node_missing(self, system_data: SystemData):
     # Test non-existing node.
     manager = ManagerObjManager()
     manager.nodeId = 99
     manager.managerId = 1
     manager.description = "manager_1"
     is_exception = False
     try:
         system_data.update_manager(manager)
     except ValueError:
         is_exception = True
     if not is_exception:
         self.fail("Exception because of non-existing node expected.")
 def _invalid_node_missing(self, system_data: SystemData):
     # Test non-existing node.
     alert = ManagerObjAlert()
     alert.nodeId = 99
     alert.alertId = 1
     alert.clientAlertId = 1
     alert.alertLevels = []
     alert.description = "alert_1"
     is_exception = False
     try:
         system_data.update_alert(alert)
     except ValueError:
         is_exception = True
     if not is_exception:
         self.fail("Exception because of non-existing node expected.")
Beispiel #8
0
    def _create_options(self,
                        system_data: Optional[SystemData] = None
                        ) -> SystemData:

        if system_data is None:
            system_data = SystemData()
            self.alert_levels = []
            self.alerts = []
            self.managers = []
            self.nodes = []
            self.options = []
            self.sensors = []

        option = ManagerObjOption()
        option.type = "type_1"
        option.value = 1.0
        self.options.append(option)
        system_data.update_option(ManagerObjOption().deepcopy(option))

        option = ManagerObjOption()
        option.type = "type_2"
        option.value = 2.0
        self.options.append(option)
        system_data.update_option(ManagerObjOption().deepcopy(option))

        option = ManagerObjOption()
        option.type = "type_3"
        option.value = 3.0
        self.options.append(option)
        system_data.update_option(ManagerObjOption().deepcopy(option))

        return system_data
Beispiel #9
0
    def _create_profiles(self,
                         system_data: Optional[SystemData] = None
                         ) -> SystemData:

        if system_data is None:
            system_data = SystemData()
            self.alert_levels = []
            self.alerts = []
            self.managers = []
            self.nodes = []
            self.options = []
            self.profiles = []
            self.sensors = []

        profile = ManagerObjProfile()
        profile.profileId = 0
        profile.name = "profile_0"
        self.profiles.append(profile)
        system_data.update_profile(ManagerObjProfile().deepcopy(profile))

        profile = ManagerObjProfile()
        profile.profileId = 1
        profile.name = "profile_1"
        self.profiles.append(profile)
        system_data.update_profile(ManagerObjProfile().deepcopy(profile))

        profile = ManagerObjProfile()
        profile.profileId = 2
        profile.name = "profile_2"
        self.profiles.append(profile)
        system_data.update_profile(ManagerObjProfile().deepcopy(profile))

        return system_data
Beispiel #10
0
 def _invalid_node_missing(self, system_data: SystemData):
     # Test non-existing node.
     sensor = ManagerObjSensor()
     sensor.nodeId = 99
     sensor.sensorId = 1
     sensor.clientSensorId = 1
     sensor.alertDelay = 0
     sensor.alertLevels = []
     sensor.description = "sensor_1"
     sensor.lastStateUpdated = 0
     sensor.state = 0
     sensor.dataType = SensorDataType.NONE
     is_exception = False
     try:
         system_data.update_sensor(sensor)
     except ValueError:
         is_exception = True
     if not is_exception:
         self.fail("Exception because of non-existing node expected.")
    def _invalid_alert_level_missing(self, system_data: SystemData):
        # Test non-existing alert level.
        sensor_alert = ManagerObjSensorAlert()
        sensor_alert.sensorId = self.sensors[0].sensorId
        sensor_alert.state = 0
        sensor_alert.alertLevels = [99]
        sensor_alert.hasOptionalData = False
        sensor_alert.optionalData = None
        sensor_alert.changeState = True
        sensor_alert.hasLatestData = False
        sensor_alert.dataType = SensorDataType.NONE
        sensor_alert.timeReceived = 0

        is_exception = False
        try:
            system_data.add_sensor_alert(sensor_alert)
        except ValueError:
            is_exception = True
        if not is_exception:
            self.fail("Exception because of wrong node type expected.")
    def _invalid_wrong_data_type(self, system_data: SystemData):
        # Test data type mismatch.
        sensor_alert = ManagerObjSensorAlert()
        sensor_alert.sensorId = self.sensors[0].sensorId
        sensor_alert.state = 0
        sensor_alert.alertLevels = [self.sensors[0].alertLevels[0]]
        sensor_alert.hasOptionalData = False
        sensor_alert.optionalData = None
        sensor_alert.changeState = True
        sensor_alert.hasLatestData = False
        sensor_alert.dataType = SensorDataType.INT
        sensor_alert.sensorData = 0
        sensor_alert.timeReceived = 0

        is_exception = False
        try:
            system_data.add_sensor_alert(sensor_alert)
        except ValueError:
            is_exception = True
        if not is_exception:
            self.fail("Exception because of wrong node type expected.")
    def _invalid_sensor_missing_alert_level(self, system_data: SystemData):
        # Test sensor does not handle alert level.
        sensor_alert = ManagerObjSensorAlert()
        sensor_alert.sensorId = self.sensors[0].sensorId
        sensor_alert.state = 0
        sensor_alert.alertLevels = []
        for alert_level in self.alert_levels:
            if alert_level.level not in self.sensors[0].alertLevels:
                sensor_alert.alertLevels.append(alert_level.level)
        sensor_alert.hasOptionalData = False
        sensor_alert.optionalData = None
        sensor_alert.changeState = True
        sensor_alert.hasLatestData = False
        sensor_alert.dataType = SensorDataType.NONE
        sensor_alert.timeReceived = 0

        is_exception = False
        try:
            system_data.add_sensor_alert(sensor_alert)
        except ValueError:
            is_exception = True
        if not is_exception:
            self.fail("Exception because of wrong node type expected.")
Beispiel #14
0
    def _create_alert_levels(self,
                             system_data: Optional[SystemData] = None
                             ) -> SystemData:

        if system_data is None:
            system_data = SystemData()
            self.alert_levels = []
            self.alerts = []
            self.managers = []
            self.nodes = []
            self.options = []
            self.sensors = []

        alert_level = ManagerObjAlertLevel()
        alert_level.level = 1
        alert_level.name = "alert_level_1"
        alert_level.triggerAlways = 1
        alert_level.instrumentation_active = True
        alert_level.instrumentation_cmd = "instrumentation_cmd_1"
        alert_level.instrumentation_timeout = 1234
        self.alert_levels.append(alert_level)
        system_data.update_alert_level(
            ManagerObjAlertLevel().deepcopy(alert_level))

        alert_level = ManagerObjAlertLevel()
        alert_level.level = 2
        alert_level.name = "alert_level_2"
        alert_level.triggerAlways = 1
        alert_level.instrumentation_active = False
        self.alert_levels.append(alert_level)
        system_data.update_alert_level(
            ManagerObjAlertLevel().deepcopy(alert_level))

        alert_level = ManagerObjAlertLevel()
        alert_level.level = 3
        alert_level.name = "alert_level_3"
        alert_level.triggerAlways = 1
        alert_level.instrumentation_active = False
        self.alert_levels.append(alert_level)
        system_data.update_alert_level(
            ManagerObjAlertLevel().deepcopy(alert_level))

        return system_data
Beispiel #15
0
    def _create_managers(self,
                         system_data: Optional[SystemData] = None
                         ) -> SystemData:

        if system_data is None:
            system_data = SystemData()
            self.alert_levels = []
            self.alerts = []
            self.managers = []
            self.nodes = []
            self.options = []
            self.sensors = []

        node = ManagerObjNode()
        node.nodeId = 4
        node.hostname = "hostname_4"
        node.nodeType = "manager"
        node.instance = "instance_4"
        node.connected = 1
        node.version = 1.0
        node.rev = 0
        node.username = "******"
        node.persistent = 1
        self.nodes.append(node)
        system_data.update_node(ManagerObjNode().deepcopy(node))

        manager = ManagerObjManager()
        manager.nodeId = 4
        manager.managerId = 1
        manager.description = "manager_1"
        self.managers.append(manager)
        system_data.update_manager(ManagerObjManager().deepcopy(manager))

        node = ManagerObjNode()
        node.nodeId = 5
        node.hostname = "hostname_5"
        node.nodeType = "manager"
        node.instance = "instance_5"
        node.connected = 1
        node.version = 1.0
        node.rev = 0
        node.username = "******"
        node.persistent = 1
        self.nodes.append(node)
        system_data.update_node(ManagerObjNode().deepcopy(node))

        manager = ManagerObjManager()
        manager.nodeId = 5
        manager.managerId = 2
        manager.description = "manager_2"
        self.managers.append(manager)
        system_data.update_manager(ManagerObjManager().deepcopy(manager))

        node = ManagerObjNode()
        node.nodeId = 6
        node.hostname = "hostname_6"
        node.nodeType = "manager"
        node.instance = "instance_6"
        node.connected = 1
        node.version = 1.0
        node.rev = 0
        node.username = "******"
        node.persistent = 1
        self.nodes.append(node)
        system_data.update_node(ManagerObjNode().deepcopy(node))

        manager = ManagerObjManager()
        manager.nodeId = 6
        manager.managerId = 3
        manager.description = "manager_3"
        self.managers.append(manager)
        system_data.update_manager(ManagerObjManager().deepcopy(manager))

        return system_data