def test_200_dashboard_free_disk_space(self): """Check if full disk space is within range """ df_fields = subprocess.check_output("df | grep /$ | tr -s ' '", shell=True).decode('ascii').split(' ') used = float(df_fields[2]) * 1024 available = float(df_fields[3]) * 1024 total_size = used + available in_threshold = int((total_size * .97) - used) out_threshold = int((total_size * .93) - used) full_filename = '/full.txt'; subprocess.call("/bin/fallocate -l " + str(in_threshold) + " " + full_filename, shell=True) df_fields = subprocess.check_output("df | grep /$ | tr -s ' '", shell=True).decode('ascii').split(' ') time.sleep(60) metrics_and_stats = uvmContext.metricManager().getMetricsAndStats() uvm_free_disk_percent = (float(metrics_and_stats["systemStats"]["freeDiskSpace"]) / float(metrics_and_stats["systemStats"]["totalDiskSpace"]) * 100) os.remove(full_filename) assert(uvm_free_disk_percent < 5) subprocess.call("/bin/fallocate -l " + str(out_threshold) + " " + full_filename, shell=True) df_fields = subprocess.check_output("df | grep /$ | tr -s ' '", shell=True).decode('ascii').split(' ') time.sleep(60) metrics_and_stats = uvmContext.metricManager().getMetricsAndStats() uvm_free_disk_percent = (float(metrics_and_stats["systemStats"]["freeDiskSpace"]) / float(metrics_and_stats["systemStats"]["totalDiskSpace"]) * 100) os.remove(full_filename) assert(uvm_free_disk_percent > 5)
def initial_setup(self): if (uvmContext.appManager().isInstantiated(self.module_name())): raise Exception('app %s already instantiated' % self.module_name()) app = uvmContext.appManager().instantiate(self.module_name(), default_policy_id) appmetrics = uvmContext.metricManager().getMetrics( app.getAppSettings()["id"]) self.app = app
def test_200_dashboard_free_disk_space(self): """Check if full disk space is within range """ df_fields = subprocess.check_output("df | grep /$ | tr -s ' '", shell=True).decode('utf-8').split(' ') used = float(df_fields[2]) * 1024 available = float(df_fields[3]) * 1024 total_size = used + available in_threshold = int((total_size * .97) - used) out_threshold = int((total_size * .93) - used) fallocate_path = "" full_filename = "/tmp/full.txt"; # check if fallocate exists and if in /bin or /usr/bin fallocate_output_obj = subprocess.run(["which", "fallocate"], capture_output=True) if fallocate_output_obj.returncode != 0 or fallocate_output_obj.stdout is None : raise unittest.SkipTest("fallocate not available") else: fallocate_path = fallocate_output_obj.stdout.decode("utf-8") fallocate_path = fallocate_path.replace("\n","") filename_output_obj = subprocess.run([fallocate_path,"-l",str(in_threshold),full_filename]) if filename_output_obj.returncode != 0: raise unittest.SkipTest(full_filename + " not available") df_fields = subprocess.check_output("df | grep /$ | tr -s ' '", shell=True).decode('utf-8').split(' ') time.sleep(60) metrics_and_stats = uvmContext.metricManager().getMetricsAndStats() uvm_free_disk_percent = (float(metrics_and_stats["systemStats"]["freeDiskSpace"]) / float(metrics_and_stats["systemStats"]["totalDiskSpace"]) * 100) subprocess.run(["rm", "-f", full_filename]) assert(uvm_free_disk_percent < 5) filename_output_obj= subprocess.run([fallocate_path, "-l", str(out_threshold), full_filename]) if filename_output_obj.returncode != 0: raise unittest.SkipTest(full_filename + " not available 2nd") df_fields = subprocess.check_output("df | grep /$ | tr -s ' '", shell=True).decode('utf-8').split(' ') time.sleep(60) metrics_and_stats = uvmContext.metricManager().getMetricsAndStats() uvm_free_disk_percent = (float(metrics_and_stats["systemStats"]["freeDiskSpace"]) / float(metrics_and_stats["systemStats"]["totalDiskSpace"]) * 100) subprocess.run(["rm", "-f", full_filename]) assert(uvm_free_disk_percent > 5)
def test_103_email_report_verify_apps(self): """ 1) Install all apps 2) Generate a report 3) Verify that the emailed report contains a section for each app """ global app, apps_list, apps_name_list if (not can_relay): raise unittest.SkipTest('Unable to relay through ' + global_functions.TEST_SERVER_HOST) if runtests.quick_tests_only: raise unittest.SkipTest('Skipping a time consuming test') # create settings to receive test_email_address configure_mail_relay() # add administrator adminsettings = uvmContext.adminManager().getSettings() orig_adminsettings = copy.deepcopy(adminsettings) adminsettings['users']['list'].append( create_admin_user(useremail=test_email_address)) uvmContext.adminManager().setSettings(adminsettings) # clear all report users settings = self._app.getSettings() settings["reportsUsers"]["list"] = settings["reportsUsers"]["list"][:1] self._app.setSettings(settings) # install all the apps that aren't already installed system_stats = uvmContext.metricManager().getStats() # print system_stats system_memory = system_stats['systemStats']['MemTotal'] if (int(system_memory) < 2200000000 ): # don't use high memory apps in devices with 2G or less. apps_list = apps_list_short apps_name_list = apps_name_list_short apps = [] for name in apps_list: if (uvmContext.appManager().isInstantiated(name)): print("App %s already installed" % name) else: apps.append(uvmContext.appManager().instantiate( name, default_policy_id)) # create some traffic result = remote_control.is_online(tries=1) # flush out events self._app.flushEvents() # send emails subprocess.call([ global_functions.get_prefix() + "/usr/share/untangle/bin/reports-generate-fixed-reports.py" ], stdout=subprocess.PIPE, stderr=subprocess.PIPE) # look for email email_found = fetch_email("/tmp/test_103_email_report_admin_file", test_email_address) # look for all the appropriate sections in the report email results = [] if email_found: for str in apps_name_list: results.append( remote_control.run_command( "grep -q -i '%s' /tmp/test_103_email_report_admin_file 2>&1" % str)) # restore uvmContext.adminManager().setSettings(orig_adminsettings) # remove apps that were installed above for a in apps: uvmContext.appManager().destroy(a.getAppSettings()["id"]) assert (email_found) for result in results: assert (result == 0)
def initial_setup(self): if (uvmContext.appManager().isInstantiated(self.module_name())): raise Exception('app %s already instantiated' % self.module_name()) app = uvmContext.appManager().instantiate(self.module_name(), default_policy_id) appmetrics = uvmContext.metricManager().getMetrics(app.getAppSettings()["id"]) self.app = app
def test_103_email_report_verify_apps(self): """ 1) Install all apps 2) Generate a report 3) Verify that the emailed report contains a section for each app """ global app,apps_list,apps_name_list if (not can_relay): raise unittest.SkipTest('Unable to relay through ' + global_functions.TEST_SERVER_HOST) if runtests.quick_tests_only: raise unittest.SkipTest('Skipping a time consuming test') # create settings to receive test_email_address configure_mail_relay() # add administrator adminsettings = uvmContext.adminManager().getSettings() orig_adminsettings = copy.deepcopy(adminsettings) adminsettings['users']['list'].append(create_admin_user(useremail=test_email_address)) uvmContext.adminManager().setSettings(adminsettings) # clear all report users settings = app.getSettings() settings["reportsUsers"]["list"] = settings["reportsUsers"]["list"][:1] app.setSettings(settings) # install all the apps that aren't already installed system_stats = uvmContext.metricManager().getStats() # print system_stats system_memory = system_stats['systemStats']['MemTotal'] if (int(system_memory) < 2200000000): # don't use high memory apps in devices with 2G or less. apps_list = apps_list_short apps_name_list = apps_name_list_short apps = [] for name in apps_list: if (uvmContext.appManager().isInstantiated(name)): print("App %s already installed" % name) else: apps.append( uvmContext.appManager().instantiate(name, default_policy_id) ) # create some traffic result = remote_control.is_online(tries=1) # flush out events app.flushEvents() # send emails subprocess.call([global_functions.get_prefix()+"/usr/share/untangle/bin/reports-generate-fixed-reports.py"],stdout=subprocess.PIPE,stderr=subprocess.PIPE) # look for email email_found = fetch_email( "/tmp/test_103_email_report_admin_file", test_email_address ) # look for all the appropriate sections in the report email results = [] if email_found: for str in apps_name_list: results.append(remote_control.run_command("grep -q -i '%s' /tmp/test_103_email_report_admin_file 2>&1"%str)) # restore uvmContext.adminManager().setSettings(orig_adminsettings) # remove apps that were installed above for a in apps: uvmContext.appManager().destroy( a.getAppSettings()["id"] ) assert(email_found) for result in results: assert(result == 0)