Exemplo n.º 1
0
 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()
Exemplo n.º 2
0
    def _init_database(self) -> Mysql:
        """
        Initializes database for testing.
        :return: storage object
        """
        global_data = GlobalData()
        global_data.sensorAlertLifeSpan = 0

        storage = None
        try:
            config_root = xml.etree.ElementTree.parse(global_data.configFile).getroot()
            backend_username = str(config_root.find("manager").find("storage").attrib["username"])
            backend_password = str(config_root.find("manager").find("storage").attrib["password"])
            backend_server = str(config_root.find("manager").find("storage").attrib["server"])
            backend_port = int(config_root.find("manager").find("storage").attrib["port"])
            backend_database = str(config_root.find("manager").find("storage").attrib["database"])

            storage = Mysql(backend_server,
                            backend_port,
                            backend_database,
                            backend_username,
                            backend_password,
                            global_data)

            storage._open_connection()
            storage._delete_storage()
            storage._conn.commit()
            storage._close_connection()
            storage.create_storage()

        except Exception:
            logging.exception("Unable to initialize database.")
            self.skipTest("Unable to initialize database.")

        return storage
Exemplo n.º 3
0
    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 _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()
Exemplo n.º 5
0
    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()
Exemplo n.º 6
0
    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()
Exemplo n.º 7
0
 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()