def _create_objects(self, storage: Mysql, system_data: SystemData): storage._open_connection() for manager in system_data.get_managers_list(): node = system_data.get_node_by_id(manager.nodeId) storage._update_node(node) storage._update_manager(manager) storage._conn.commit()
def _create_objects(self, storage: Mysql, system_data: SystemData): storage._open_connection() for profile in system_data.get_profiles_list(): storage._update_profile(profile) for alert_level in system_data.get_alert_levels_list(): storage._update_alert_level(alert_level) storage._conn.commit()
def _create_objects(self, storage: Mysql, system_data: SystemData): storage._open_connection() for alert_level in system_data.get_alert_levels_list(): storage._update_alert_level(alert_level) for sensor in system_data.get_sensors_list(): node = system_data.get_node_by_id(sensor.nodeId) storage._update_node(node) storage._update_sensor(sensor) storage._conn.commit()
def _create_objects(self, storage: Mysql, system_data: SystemData): storage._open_connection() for profile in system_data.get_profiles_list(): storage._update_profile(profile) for alert_level in system_data.get_alert_levels_list(): storage._update_alert_level(alert_level) for alert in system_data.get_alerts_list(): node = system_data.get_node_by_id(alert.nodeId) storage._update_node(node) storage._update_alert(alert) storage._conn.commit()
def test_update_option(self): """ Tests updating of options 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 = 5 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 # Update database objects. storage._open_connection() for option in system_data.get_options_list(): storage._update_option(option) storage._conn.commit() storage._system_data = SystemData() storage.synchronize_database_to_system_data() compare_options_content(self, system_data.get_options_list(), storage._system_data.get_options_list())
def test_update_profile(self): """ Tests updating of profiles 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 profile in system_data.get_profiles_list(): temp_profile = ManagerObjProfile().deepcopy(profile) temp_profile.name = "new_profile" + str(ctr + 1) system_data.update_profile(temp_profile) ctr += 1 # Update database objects. storage._open_connection() for profile in system_data.get_profiles_list(): storage._update_profile(profile) storage._conn.commit() storage._system_data = SystemData() storage.synchronize_database_to_system_data() compare_profiles_content(self, system_data.get_profiles_list(), storage._system_data.get_profiles_list())
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())
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())
def test_update_alert(self): """ Tests updating of alerts 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 alert in system_data.get_alerts_list(): temp_alert = ManagerObjAlert().deepcopy(alert) temp_alert.description = "new_alert_" + str(ctr + 1) temp_alert.clientAlertId = 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 # Update database objects. storage._open_connection() for alert in system_data.get_alerts_list(): storage._update_alert(alert) storage._conn.commit() storage._system_data = SystemData() storage.synchronize_database_to_system_data() compare_alerts_content(self, system_data.get_alerts_list(), storage._system_data.get_alerts_list())
def _create_objects(self, storage: Mysql, system_data: SystemData): storage._open_connection() for profile in system_data.get_profiles_list(): storage._update_profile(profile) for alert_level in system_data.get_alert_levels_list(): storage._update_alert_level(alert_level) for node in system_data.get_nodes_list(): storage._update_node(node) if node.nodeType.lower() == "alert": for alert in system_data.get_alerts_list(): if alert.nodeId == node.nodeId: storage._update_alert(alert) elif node.nodeType.lower() == "manager": for manager in system_data.get_managers_list(): if manager.nodeId == node.nodeId: storage._update_manager(manager) elif node.nodeType.lower() in ["sensor", "server"]: for sensor in system_data.get_sensors_list(): if sensor.nodeId == node.nodeId: storage._update_sensor(sensor) storage._conn.commit()
def test_add_option(self): """ Tests adding of options 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_options_content(self, system_data.get_options_list(), storage._system_data.get_options_list())
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())
def test_update_sensor(self): """ Tests updating of sensors 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 sensor in system_data.get_sensors_list(): temp_sensor = ManagerObjSensor().deepcopy(sensor) temp_sensor.description = "new_sensor_" + str(ctr + 1) temp_sensor.clientSensorId = 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._open_connection() for sensor in system_data.get_sensors_list(): storage._update_sensor(sensor) storage._conn.commit() storage._system_data = SystemData() storage.synchronize_database_to_system_data() compare_sensors_content(self, system_data.get_sensors_list(), storage._system_data.get_sensors_list())
def test_update_alert_level(self): """ Tests updating of alert levels 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 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 + 1) % 2) == 0) if temp_alert_level.instrumentation_active: temp_alert_level.instrumentation_cmd = "new_alert_level_instrumentation_" + str( ctr + 1) temp_alert_level.instrumentation_timeout = 543 + ctr system_data.update_alert_level(temp_alert_level) ctr += 1 # Update database objects. storage._open_connection() for alert_level in system_data.get_alert_levels_list(): storage._update_alert_level(alert_level) storage._conn.commit() storage._system_data = SystemData() storage.synchronize_database_to_system_data() compare_alert_levels_content( self, system_data.get_alert_levels_list(), storage._system_data.get_alert_levels_list())
def _create_objects(self, storage: Mysql, system_data: SystemData): storage._open_connection() for option in system_data.get_options_list(): storage._update_option(option) storage._conn.commit()
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())