def start_run_at_date():
    app_variables.restart_run_once_test_server = 0
    while not app_variables.restart_run_once_test_server:
        while not current_config.schedule_run_once_enabled:
            sleep(30)

        try:
            utc_now = datetime.utcnow()
            scheduled_runtime = datetime.strptime(
                current_config.schedule_run_once_at_time, "%Y-%m-%dT%H:%M")
            sleep_time = (scheduled_runtime - utc_now).total_seconds()

            if sleep_time > 0:
                total_sleep_time = 0
                skip_test_runs = 0
                primary_logger.info("Single Run Tests set to run in: " +
                                    str(sleep_time) + " Seconds")
                while total_sleep_time < sleep_time:
                    sleep(5)
                    total_sleep_time += 5
                    if app_variables.restart_run_once_test_server:
                        skip_test_runs = 1
                        sleep_time = total_sleep_time
                if not skip_test_runs:
                    run_commands.start_mtr()
                    run_commands.start_iperf()
            else:
                primary_logger.warning(
                    "Single Run Tests Date & Time has already passed, disabling Run Once Schedule"
                )
                current_config.schedule_run_once_enabled = 0
                current_config.write_config_to_file()
        except Exception as error:
            primary_logger.error("Single scheduled test run: " + str(error))
            current_config.schedule_run_once_enabled = 0
Beispiel #2
0
    def load_installed_hardware_from_file(self):
        """ Loads Installed Hardware configuration from local disk. """
        log_msg = "Loading Installed Hardware Configuration from: " + file_locations.installed_hardware_file_location
        primary_logger.debug(log_msg)
        if os.path.isfile(file_locations.installed_hardware_file_location):
            try:
                config_file_lines = get_file_content(
                    file_locations.installed_hardware_file_location).split(
                        "\n")
                config_list = []
                for line in config_file_lines:
                    config_list.append(line.split("=")[0].strip())

                self.installed_interactive_hw["WaveShare27"] = int(
                    config_list[1])
            except Exception as error:
                primary_logger.error(
                    "Unable to load Installed Hardware configuration File: " +
                    str(error))
                self.write_installed_hardware_to_file()
        else:
            primary_logger.warning(
                "No Installed Hardware Configuration file found, saving default"
            )
            self.write_installed_hardware_to_file()
 def _thread_and_monitor(self):
     try:
         monitored_thread = Thread(target=self._worker_thread_and_monitor)
         monitored_thread.daemon = True
         monitored_thread.start()
     except Exception as error:
         primary_logger.warning("Error starting program thread " +
                                self.thread_name + ": " + str(error))
Beispiel #4
0
def ip_address_validation_check(ip_address):
    try:
        if _check_ip_address(ip_address):
            return True
        return False
    except Exception as error:
        primary_logger.warning("IP validation check error: " + str(error))
        return False
def send_command(url):
    """ Sends command URL using requests. """
    try:
        requests.get(url=url, timeout=5, headers={'Connection': 'close'})
        primary_logger.debug(str(url) + " sent OK")
        return True
    except Exception as error:
        primary_logger.warning("Error sending '" + str(url) + "': " +
                               str(error))
        return False
Beispiel #6
0
def get_ip_from_socket():
    """ Returns IPv4 Address as a String. """
    try:
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        s.connect(("8.8.8.8", 80))
        ip_address = (s.getsockname()[0])
        s.close()
    except Exception as error:
        primary_logger.warning("Error getting IP address: " + str(error))
        ip_address = "0.0.0.0"
    return ip_address
Beispiel #7
0
 def load_wpa_supplicant_wifi(self):
     try:
         app_variables.wpa_supplicant_file_content = get_file_content(
             file_locations.wpa_supplicant_file)
         self.wifi_country_code = network_wifi.get_wifi_country_code()
         self.wifi_ssid = network_wifi.get_wifi_ssid()
         self.wifi_security_type = network_wifi.get_wifi_security_type()
         self.wifi_pass_key = network_wifi.get_wifi_psk()
     except Exception as error:
         primary_logger.warning(
             "Unable to get Wireless information from wpa_supplicant.conf: "
             + str(error))
Beispiel #8
0
    def load_config_from_file(self):
        """ Loads Primary configuration from local disk and set's accordingly. """
        primary_logger.debug("Loading Primary Configuration from: " +
                             file_locations.config_file_location)
        if os.path.isfile(file_locations.config_file_location):
            try:
                config_file_lines = get_file_content(
                    file_locations.config_file_location).split("\n")
                config_list = []
                for line in config_file_lines:
                    config_list.append(line.split("=")[0].strip())

                self.is_iperf_server = int(config_list[1])
                self.remote_tester_ip = config_list[2]
                self.iperf_port = config_list[3]
                self.mtr_run_count = config_list[4]
                if len(config_list) > 4:
                    if config_list[5].strip() == "0":
                        self.schedule_run_every_minutes = 0
                    else:
                        self.schedule_run_every_minutes = int(config_list[5])
                    if len(config_list) > 5:
                        if config_list[6].strip() == "0":
                            self.schedule_run_on_boot = 0
                        else:
                            self.schedule_run_on_boot = int(config_list[6])
                            if self.schedule_run_every_minutes < 5:
                                self.schedule_run_every_minutes = 5
                        if len(config_list) > 6:
                            if config_list[7].strip() == "0":
                                self.schedule_run_every_minutes_enabled = 0
                            else:
                                self.schedule_run_every_minutes_enabled = int(
                                    config_list[7])
                            if len(config_list) > 7:
                                if config_list[8].strip() == "0":
                                    self.schedule_run_once_enabled = 0
                                else:
                                    self.schedule_run_once_enabled = int(
                                        config_list[8])
                                self.schedule_run_once_at_time = config_list[9]

            except Exception as error:
                primary_logger.error(
                    "Unable to load Configuration File, saving default: " +
                    str(error))
                self.write_config_to_file()
        else:
            primary_logger.warning(
                "No Configuration file found, saving default")
            self.write_config_to_file()
    def __init__(self):
        if current_config.using_dummy_access:
            log_msg = "No Interactive Hardware Detected.  Interactive Server Disabled.  Using Web Access Only."
            primary_logger.warning(log_msg)
            while True:
                sleep(600)

        while True:
            while current_config.mtr_running or current_config.iperf_running:
                sleep(2)
            count = 0
            for key_state in hardware_access.get_key_states():
                if not key_state:
                    run_commands.run_command(count)
                    break
                count += 1
            sleep(1)
Beispiel #10
0
    def load_dhcpcd_conf_from_file(self):
        try:
            app_variables.dhcpcd_config_file_content = get_file_content(
                file_locations.dhcpcd_config_file)
            self.local_ethernet_dhcp = network_ip.check_for_dhcp()
            self.local_ethernet_ip = network_ip.get_dhcpcd_ip()
            self.local_ethernet_subnet = network_ip.get_subnet()
            self.local_ethernet_gateway = network_ip.get_gateway()
            self.local_ethernet_dns1 = network_ip.get_dns(dns_server=0)
            self.local_ethernet_dns2 = network_ip.get_dns(dns_server=1)

            self.local_wireless_dhcp = network_ip.check_for_dhcp(wireless=True)
            self.local_wireless_ip = network_ip.get_dhcpcd_ip(wireless=True)
            self.local_wireless_subnet = network_ip.get_subnet(wireless=True)
            self.local_wireless_gateway = network_ip.get_gateway(wireless=True)
            self.local_wireless_dns1 = network_ip.get_dns(dns_server=0,
                                                          wireless=True)
            self.local_wireless_dns2 = network_ip.get_dns(dns_server=1,
                                                          wireless=True)
        except Exception as error:
            primary_logger.warning(
                "Unable to get IP information from dhcpcd.conf: " + str(error))
def start_run_every_minutes():
    if current_config.schedule_run_on_boot:
        run_commands.start_mtr()
        run_commands.start_iperf()

    if current_config.schedule_run_every_minutes < 5:
        primary_logger.warning("Scheduled times cannot be less then 5 minutes")
        current_config.schedule_run_every_minutes = 5

    if current_config.schedule_run_every_minutes_enabled:
        log_msg = "Tests scheduled to run every " + str(
            current_config.schedule_run_every_minutes) + " minutes"
        primary_logger.info(log_msg)

    while True:
        try:
            if current_config.schedule_run_every_minutes_enabled:
                sleep(current_config.schedule_run_every_minutes * 60)
                run_commands.start_mtr()
                run_commands.start_iperf()
            else:
                sleep(300)
        except Exception as error:
            primary_logger.error("Error Running Scheduled Test: " + str(error))