Exemplo n.º 1
0
    def test_delete_node(self):
        """
        Tests deleting of nodes in the database.
        """
        config_logging(logging.ERROR)

        storage = self._init_database()

        system_data = self._create_system_data()
        self._create_objects(storage, system_data)

        # Delete object and check correct deletion.
        for node in system_data.get_nodes_list():
            storage._open_connection()
            storage._delete_node(node.nodeId)
            storage._conn.commit()

            system_data.delete_node_by_id(node.nodeId)

            storage.synchronize_database_to_system_data()
            compare_nodes_content(self, system_data.get_nodes_list(),
                                  storage._system_data.get_nodes_list())

            # Delete function of database also deletes all Alert, Manager, and Sensor objects.
            compare_alerts_content(self, system_data.get_alerts_list(),
                                   storage._system_data.get_alerts_list())
            compare_managers_content(self, system_data.get_managers_list(),
                                     storage._system_data.get_managers_list())
            compare_sensors_content(self, system_data.get_sensors_list(),
                                    storage._system_data.get_sensors_list())
Exemplo n.º 2
0
    def test_add_data(self):
        """
        Tests adding of system information to the database.
        """
        config_logging(logging.ERROR)

        storage = self._init_database()

        # Create database objects.
        system_data = self._create_system_data()
        storage.update_server_information(0, system_data.get_options_list(),
                                          system_data.get_nodes_list(),
                                          system_data.get_sensors_list(),
                                          system_data.get_alerts_list(),
                                          system_data.get_managers_list(),
                                          system_data.get_alert_levels_list(),
                                          [])

        storage._system_data = SystemData()
        storage.synchronize_database_to_system_data()

        compare_nodes_content(self, system_data.get_nodes_list(),
                              storage._system_data.get_nodes_list())
        compare_alerts_content(self, system_data.get_alerts_list(),
                               storage._system_data.get_alerts_list())
        compare_managers_content(self, system_data.get_managers_list(),
                                 storage._system_data.get_managers_list())
        compare_sensors_content(self, system_data.get_sensors_list(),
                                storage._system_data.get_sensors_list())
Exemplo n.º 3
0
    def test_update_manager(self):
        """
        Tests updating of managers in the database.
        """
        config_logging(logging.ERROR)

        storage = self._init_database()

        system_data = self._create_system_data()
        self._create_objects(storage, system_data)

        # Update local objects.
        ctr = 0
        for manager in system_data.get_managers_list():
            temp_manager = ManagerObjManager().deepcopy(manager)
            temp_manager.description = "new_manager_" + str(ctr + 1)
            system_data.update_manager(temp_manager)
            ctr += 1

        # Update database objects.
        storage._open_connection()
        for manager in system_data.get_managers_list():
            storage._update_manager(manager)
        storage._conn.commit()

        storage._system_data = SystemData()
        storage.synchronize_database_to_system_data()

        compare_managers_content(self, system_data.get_managers_list(),
                                 storage._system_data.get_managers_list())
Exemplo n.º 4
0
    def test_update_manager(self):
        """
        Test Manager object updating.
        """
        system_data = self._create_system_data()

        # Create changes that should be copied to the stored object.
        new_managers = []
        for i in range(len(self.managers)):
            temp_manager = ManagerObjManager().deepcopy(self.managers[i])
            temp_manager.description = "new_manager_" + str(i + 1)
            new_managers.append(temp_manager)

        for i in range(len(new_managers)):

            # Update store with new object data.
            temp_manager = new_managers[i]
            system_data.update_manager(temp_manager)

            gt_storage = []
            for j in range(i+1):
                gt_storage.append(new_managers[j])
            for j in range(i+1, len(new_managers)):
                gt_storage.append(self.managers[j])

            stored_managers = system_data.get_managers_list()
            compare_managers_content(self, gt_storage, stored_managers)
Exemplo n.º 5
0
    def test_add_manager(self):
        """
        Tests adding of managers to the database.
        """
        config_logging(logging.ERROR)

        storage = self._init_database()

        system_data = self._create_system_data()
        self._create_objects(storage, system_data)

        storage._system_data = SystemData()
        storage.synchronize_database_to_system_data()

        compare_managers_content(self, system_data.get_managers_list(),
                                 storage._system_data.get_managers_list())
Exemplo n.º 6
0
    def test_update_node(self):
        """
        Tests updating of nodes in the database.
        """
        config_logging(logging.ERROR)

        storage = self._init_database()

        system_data = self._create_system_data()
        self._create_objects(storage, system_data)

        # Update local objects.
        ctr = 0
        for node in system_data.get_nodes_list():
            temp_node = ManagerObjNode().deepcopy(node)
            temp_node.hostname = "new_hostname_" + str(ctr + 1)
            temp_node.nodeType = ["alert", "manager", "sensor",
                                  "server"][ctr % 4]
            temp_node.instance = "new_instance_" + str(ctr + 1)
            temp_node.connected = (ctr % 2)
            temp_node.version = float(5 + ctr)
            temp_node.rev = ctr
            temp_node.username = "******" + str(ctr + 1)
            temp_node.persistent = (ctr % 2)
            system_data.update_node(temp_node)
            ctr += 1

        # Update database objects.
        storage._open_connection()
        for node in system_data.get_nodes_list():
            storage._update_node(node)
        storage._conn.commit()

        storage._system_data = SystemData()
        storage.synchronize_database_to_system_data()

        compare_nodes_content(self, system_data.get_nodes_list(),
                              storage._system_data.get_nodes_list())

        # Update function of database also deletes all Alert, Manager, and Sensor objects if node type changes.
        compare_alerts_content(self, system_data.get_alerts_list(),
                               storage._system_data.get_alerts_list())
        compare_managers_content(self, system_data.get_managers_list(),
                                 storage._system_data.get_managers_list())
        compare_sensors_content(self, system_data.get_sensors_list(),
                                storage._system_data.get_sensors_list())
Exemplo n.º 7
0
    def test_delete_profile(self):
        """
        Tests deleting of profiles in system information data in the database.
        """
        config_logging(logging.ERROR)

        storage = self._init_database()

        # Create database objects.
        system_data = self._create_system_data()
        storage.update_server_information(0, system_data.get_options_list(),
                                          system_data.get_profiles_list(),
                                          system_data.get_nodes_list(),
                                          system_data.get_sensors_list(),
                                          system_data.get_alerts_list(),
                                          system_data.get_managers_list(),
                                          system_data.get_alert_levels_list(),
                                          [])

        # Delete profile objects and check correct deletion.
        for profile in system_data.get_profiles_list():
            system_data.delete_profile_by_id(profile.profileId)

            storage.update_server_information(
                0, system_data.get_options_list(),
                system_data.get_profiles_list(), system_data.get_nodes_list(),
                system_data.get_sensors_list(), system_data.get_alerts_list(),
                system_data.get_managers_list(),
                system_data.get_alert_levels_list(), [])

            storage.synchronize_database_to_system_data()
            compare_profiles_content(self, system_data.get_profiles_list(),
                                     storage._system_data.get_profiles_list())
            compare_nodes_content(self, system_data.get_nodes_list(),
                                  storage._system_data.get_nodes_list())
            compare_alerts_content(self, system_data.get_alerts_list(),
                                   storage._system_data.get_alerts_list())
            compare_managers_content(self, system_data.get_managers_list(),
                                     storage._system_data.get_managers_list())
            compare_sensors_content(self, system_data.get_sensors_list(),
                                    storage._system_data.get_sensors_list())
            compare_alert_levels_content(
                self, system_data.get_alert_levels_list(),
                storage._system_data.get_alert_levels_list())
Exemplo n.º 8
0
    def test_delete_manager(self):
        """
        Tests deleting of managers in the database.
        """
        config_logging(logging.ERROR)

        storage = self._init_database()

        system_data = self._create_system_data()
        self._create_objects(storage, system_data)

        # Delete object and check correct deletion.
        for manager in system_data.get_managers_list():
            storage._open_connection()
            storage._delete_manager(manager.managerId)
            storage._conn.commit()

            system_data.delete_manager_by_id(manager.managerId)

            storage.synchronize_database_to_system_data()
            compare_managers_content(self, system_data.get_managers_list(),
                                     storage._system_data.get_managers_list())
Exemplo n.º 9
0
    def test_update(self):
        """
        Tests updating of system information in the database.
        """
        config_logging(logging.ERROR)

        storage = self._init_database()

        # Create database objects.
        system_data = self._create_system_data()
        storage.update_server_information(0, system_data.get_options_list(),
                                          system_data.get_nodes_list(),
                                          system_data.get_sensors_list(),
                                          system_data.get_alerts_list(),
                                          system_data.get_managers_list(),
                                          system_data.get_alert_levels_list(),
                                          [])

        # Update local objects.
        ctr = 0
        for option in system_data.get_options_list():
            temp_option = ManagerObjOption().deepcopy(option)
            temp_option.value = float(ctr)
            system_data.update_option(temp_option)
            ctr += 1

        for alert_level in system_data.get_alert_levels_list():
            temp_alert_level = ManagerObjAlertLevel().deepcopy(alert_level)
            temp_alert_level.name = "new_alert_level_" + str(ctr + 1)
            temp_alert_level.triggerAlways = (ctr % 2)
            temp_alert_level.instrumentation_active = (ctr % 2) == 0

            if temp_alert_level.instrumentation_active:
                temp_alert_level.instrumentation_cmd = "alert_level_instrumentation_" + str(
                    ctr + 1)
                temp_alert_level.instrumentation_timeout = 123 + ctr

            system_data.update_alert_level(temp_alert_level)
            ctr += 1

        for node in system_data.get_nodes_list():
            temp_node = ManagerObjNode().deepcopy(node)
            temp_node.hostname = "new_hostname_" + str(ctr + 1)
            temp_node.nodeType = ["alert", "manager", "sensor",
                                  "server"][ctr % 4]
            temp_node.instance = "new_instance_" + str(ctr + 1)
            temp_node.connected = (ctr % 2)
            temp_node.version = float(5 + ctr)
            temp_node.rev = ctr
            temp_node.username = "******" + str(ctr + 1)
            temp_node.persistent = (ctr % 2)
            system_data.update_node(temp_node)
            ctr += 1

        for alert in system_data.get_alerts_list():
            temp_alert = ManagerObjAlert().deepcopy(alert)
            temp_alert.description = "new_alert_" + str(ctr + 1)
            temp_alert.remoteAlertId = ctr
            # We started the alert levels in our test data with level 1.
            temp_alert.alertLevels = [
                (ctr % len(system_data.get_alert_levels_list())) + 1
            ]
            system_data.update_alert(temp_alert)
            ctr += 1

        for manager in system_data.get_managers_list():
            temp_manager = ManagerObjManager().deepcopy(manager)
            temp_manager.description = "new_manager_" + str(ctr + 1)
            system_data.update_manager(temp_manager)
            ctr += 1

        for sensor in system_data.get_sensors_list():
            temp_sensor = ManagerObjSensor().deepcopy(sensor)
            temp_sensor.description = "new_sensor_" + str(ctr + 1)
            temp_sensor.remoteSensorId = ctr
            temp_sensor.alertDelay = ctr + 10
            temp_sensor.lastStateUpdated = ctr + 10
            temp_sensor.state = ctr % 2
            temp_sensor.dataType = SensorDataType.INT
            temp_sensor.data = ctr
            # We started the alert levels in our test data with level 1.
            temp_sensor.alertLevels = [
                (ctr % len(system_data.get_alert_levels_list())) + 1
            ]
            system_data.update_sensor(temp_sensor)
            ctr += 1

        # Update database objects.
        storage.update_server_information(0, system_data.get_options_list(),
                                          system_data.get_nodes_list(),
                                          system_data.get_sensors_list(),
                                          system_data.get_alerts_list(),
                                          system_data.get_managers_list(),
                                          system_data.get_alert_levels_list(),
                                          [])

        storage._system_data = SystemData()
        storage.synchronize_database_to_system_data()

        compare_nodes_content(self, system_data.get_nodes_list(),
                              storage._system_data.get_nodes_list())
        compare_alerts_content(self, system_data.get_alerts_list(),
                               storage._system_data.get_alerts_list())
        compare_managers_content(self, system_data.get_managers_list(),
                                 storage._system_data.get_managers_list())
        compare_sensors_content(self, system_data.get_sensors_list(),
                                storage._system_data.get_sensors_list())
        compare_alert_levels_content(
            self, system_data.get_alert_levels_list(),
            storage._system_data.get_alert_levels_list())
Exemplo n.º 10
0
    def test_content_update(self):
        """
        Tests status update of content.
        """
        global_data = GlobalData()
        global_data.system_data = self._create_system_data()
        event_handler = BaseManagerEventHandler(global_data)

        # Update local objects.
        ctr = 1
        for option in self.options:
            option.value += ctr
            ctr += 1

        for profile in self.profiles:
            profile.name += "_new_" + str(ctr)
            ctr += 1

        for alert_level in self.alert_levels:
            alert_level.name += "_new_" + str(ctr)
            ctr += 1

        for node in self.nodes:
            node.hostname += "_new_" + str(ctr)
            ctr += 1

        for alert in self.alerts:
            alert.description += "_new_" + str(ctr)
            ctr += 1

        for sensor in self.sensors:
            sensor.description += "_new_" + str(ctr)
            ctr += 1

        for manager in self.managers:
            manager.description += "_new_" + str(ctr)
            ctr += 1

        # Check stored and local objects differ.
        for stored_option in global_data.system_data.get_options_list():
            found = False
            for local_option in self.options:
                if local_option.type == stored_option.type:
                    found = True
                    if local_option == stored_option:
                        self.fail(
                            "Local and stored object have not the same object."
                        )

                    if local_option.value == stored_option.value:
                        self.fail(
                            "Local and stored object have the same content.")

                    break

            if not found:
                self.fail("Stored Option object not found in local objects.")

        # Check stored and local objects differ.
        for stored_profile in global_data.system_data.get_profiles_list():
            found = False
            for local_profile in self.profiles:
                if local_profile.profileId == stored_profile.profileId:
                    found = True
                    if local_profile == stored_profile:
                        self.fail(
                            "Local and stored object have not the same object."
                        )

                    if local_profile.name == stored_profile.name:
                        self.fail(
                            "Local and stored object have the same content.")

                    break

            if not found:
                self.fail("Stored Option object not found in local objects.")

        for stored_alert_level in global_data.system_data.get_alert_levels_list(
        ):
            found = False
            for local_alert_level in self.alert_levels:
                if local_alert_level.level == stored_alert_level.level:
                    found = True
                    if local_alert_level == stored_alert_level:
                        self.fail(
                            "Local and stored object are the same object.")

                    if local_alert_level.name == stored_alert_level.name:
                        self.fail(
                            "Local and stored object have the same content.")

                    break

            if not found:
                self.fail(
                    "Stored Alert Level object not found in local objects.")

        for stored_node in global_data.system_data.get_nodes_list():
            found = False
            for local_node in self.nodes:
                if local_node.nodeId == stored_node.nodeId:
                    found = True
                    if local_node == stored_node:
                        self.fail(
                            "Local and stored object are the same object.")

                    if local_node.hostname == stored_node.hostname:
                        self.fail(
                            "Local and stored object have the same content.")

                    break

            if not found:
                self.fail("Stored Node object not found in local objects.")

        for stored_alert in global_data.system_data.get_alerts_list():
            found = False
            for local_alert in self.alerts:
                if local_alert.alertId == stored_alert.alertId:
                    found = True
                    if local_alert == stored_alert:
                        self.fail(
                            "Local and stored object are the same object.")

                    if local_alert.description == stored_alert.description:
                        self.fail(
                            "Local and stored object have the same content.")

                    break

            if not found:
                self.fail("Stored Alert object not found in local objects.")

        for stored_manager in global_data.system_data.get_managers_list():
            found = False
            for local_manager in self.managers:
                if local_manager.managerId == stored_manager.managerId:
                    found = True
                    if local_manager == stored_manager:
                        self.fail(
                            "Local and stored object are the same object.")

                    if local_manager.description == stored_manager.description:
                        self.fail(
                            "Local and stored object have the same content.")

                    break

            if not found:
                self.fail("Stored Manager object not found in local objects.")

        for stored_sensor in global_data.system_data.get_sensors_list():
            found = False
            for local_sensor in self.sensors:
                if local_sensor.sensorId == stored_sensor.sensorId:
                    found = True
                    if local_sensor == stored_sensor:
                        self.fail(
                            "Local and stored object are the same object.")

                    if local_sensor.description == stored_sensor.description:
                        self.fail(
                            "Local and stored object have the same content.")

                    break

            if not found:
                self.fail("Stored Sensor object not found in local objects.")

        if not event_handler.status_update(
                1337, self.options, self.profiles, self.nodes, self.sensors,
                self.managers, self.alerts, self.alert_levels):
            self.fail("Status update failed.")

        if event_handler.msg_time != 1337:
            self.fail("Server time update failed.")

        # Check changes are stored.
        compare_options_content(self, self.options,
                                global_data.system_data.get_options_list())
        compare_profiles_content(self, self.profiles,
                                 global_data.system_data.get_profiles_list())
        compare_alert_levels_content(
            self, self.alert_levels,
            global_data.system_data.get_alert_levels_list())
        compare_nodes_content(self, self.nodes,
                              global_data.system_data.get_nodes_list())
        compare_alerts_content(self, self.alerts,
                               global_data.system_data.get_alerts_list())
        compare_managers_content(self, self.managers,
                                 global_data.system_data.get_managers_list())
        compare_sensors_content(self, self.sensors,
                                global_data.system_data.get_sensors_list())