Commit 789d2d56 authored by Julien Muchembled's avatar Julien Muchembled

qa: minor code clean-up

parent 049c42b1
......@@ -30,13 +30,14 @@ import os
import sqlite3
import time
from slapos.test.promise import data
from ..promise import data
from slapos.monitor.collect import ResourceCollect
class TestMonitorCollect(unittest.TestCase):
base_path, = data.__path__
def setUp(self):
self.base_path = "/".join(data.__file__.split("/")[:-1])
self.status = "ok"
# populate db
......@@ -48,7 +49,6 @@ class TestMonitorCollect(unittest.TestCase):
# inititalise
self.collector = ResourceCollect('/tmp/')
def test_getPartitionUsedMemoryAverage(self):
self.assertEqual(1195.492578125,
......
......@@ -28,12 +28,15 @@ import os, shutil
import tempfile
import unittest
import json
from .. import data
from slapos.grid.promise import PromiseLauncher
from slapos.grid.promise.generic import (PROMISE_RESULT_FOLDER_NAME,
PROMISE_LOG_FOLDER_NAME)
class TestPromisePluginMixin(unittest.TestCase):
base_path, = data.__path__
def setUp(self):
self.partition_dir = tempfile.mkdtemp()
self.plugin_dir = os.path.join(self.partition_dir, 'plugin')
......
......@@ -28,7 +28,6 @@
from slapos.test.promise.plugin import TestPromisePluginMixin
import os
import time
from slapos.test.promise import data
from slapos.grid.promise import PromiseError
class TestCheckErrorOnHttpLog(TestPromisePluginMixin):
......@@ -61,7 +60,6 @@ class TestCheckErrorOnHttpLog(TestPromisePluginMixin):
log_folder = os.path.join(self.partition_dir, 'var/log')
os.makedirs(log_folder)
self.base_path = "/".join(data.__file__.split("/")[:-1])
self._update_logs()
self.promise_name = "check-error-on-apache-log.py"
......@@ -79,7 +77,6 @@ extra_config_dict = {
TestPromisePluginMixin.tearDown(self)
def test_no_error(self):
self.base_path = "/".join(data.__file__.split("/")[:-1])
content = self.base_content % {
'log_file': self.base_path + "/SOFTINST-0_infoonly_error_log",
'maximum_delay': 0
......@@ -110,7 +107,6 @@ extra_config_dict = {
self.assertEqual(result['result']['message'], "OK")
def test_error(self):
self.base_path = "/".join(data.__file__.split("/")[:-1])
content = self.base_content % {
'log_file': self.base_path + "/SOFTINST-0_apache_error_log",
'maximum_delay': 0
......@@ -142,7 +138,6 @@ extra_config_dict = {
self.assertEqual(result['result']['message'], "ERROR=1 (NOROUTE=1, UNREACHABLENET=0, TIMEOUT=0)")
def test_error_timeout(self):
self.base_path = "/".join(data.__file__.split("/")[:-1])
content = self.base_content % {
'log_file': self.base_path + "/SOFTINST-0_timeout_error_log",
'maximum_delay': 0
......@@ -174,7 +169,6 @@ extra_config_dict = {
self.assertEqual(result['result']['message'], "ERROR=2 (NOROUTE=0, UNREACHABLENET=0, TIMEOUT=2)")
def test_error_unreacheabler(self):
self.base_path = "/".join(data.__file__.split("/")[:-1])
content = self.base_content % {
'log_file': self.base_path + "/SOFTINST-0_unreachable_error_log",
'maximum_delay': 0
......
......@@ -27,7 +27,6 @@
from slapos.test.promise.plugin import TestPromisePluginMixin
import os
from slapos.test.promise import data
import time
from slapos.grid.promise import PromiseError
......@@ -37,7 +36,6 @@ class TestCheckErrorOnZopeLongrequestLog(TestPromisePluginMixin):
def setUp(self):
TestPromisePluginMixin.setUp(self)
self.promise_name = "check-error-on-zope_longrequest-log.py"
self.base_path = "/".join(data.__file__.split("/")[:-1])
self.log_file = self.base_path + "/longrequest_logger_zope.log"
self.test_log_file = self.base_path + "/SOFTINST-0_longrequest_logger_zope.log"
self._update_logs()
......
......@@ -29,7 +29,6 @@ from slapos.test.promise.plugin import TestPromisePluginMixin
from slapos.grid.promise import PromiseError
import os
import sqlite3
from slapos.test.promise import data
from slapos.grid.promise import PromiseError
class TestCheckFreeDiskSpace(TestPromisePluginMixin):
......@@ -40,7 +39,6 @@ class TestCheckFreeDiskSpace(TestPromisePluginMixin):
os.makedirs(log_folder)
self.db_file = '/tmp/collector.db'
self.base_path = "/".join(data.__file__.split("/")[:-1])
# populate db
self.conn = sqlite3.connect(self.db_file)
......
......@@ -33,12 +33,11 @@ import psutil
from slapos.promise.apache_mpm_watchdog import watchServerStatus, \
loadJSONFile, writeJSONFile, getServerStatus, search_pid_regex
from slapos.test.promise import data
from . import data
class TestApacheMPMWatchdog(unittest.TestCase):
def setUp(self):
self.base_path = "/".join(data.__file__.split("/")[:-1])
base_path, = data.__path__
def text_searchPidRegex(self):
......
......@@ -32,7 +32,7 @@ import tempfile
import datetime
import shutil
from slapos.test.promise import data
from . import data
from slapos.promise.check_apachedex_result import checkApachedexResult
apdex_not_found_message = "No result found in the apdex file or the file is corrupted"
......@@ -42,6 +42,8 @@ skip_message = "Instance has been just deployed. Skipping check.."
class TestCheckApacheDigestResult(unittest.TestCase):
base_path, = data.__path__
def _create_file(self, date, with_content):
content = ''
if with_content:
......@@ -59,8 +61,6 @@ class TestCheckApacheDigestResult(unittest.TestCase):
os.remove(self.base_dir+name)
def setUp(self):
self.base_path = "/".join(data.__file__.split("/")[:-1])
self.base_dir = "/tmp/ap/"
if not os.path.exists(self.base_dir):
os.makedirs(self.base_dir)
......
......@@ -29,15 +29,16 @@ import unittest
import os
import sqlite3
from slapos.test.promise import data
from . import data
from slapos.promise.check_computer_memory import getMemoryInfo, checkMemoryUsage
total_memory_fetch_failure_message = "couldn't fetch total memory, collectordb is empty?"
class TestComputerMemory(unittest.TestCase):
base_path, = data.__path__
def setUp(self):
self.base_path = "/".join(data.__file__.split("/")[:-1])
self.status = "ok"
self.db_file = '/tmp/collector.db'
......
......@@ -32,11 +32,13 @@ import tempfile
import datetime
import shutil
from slapos.test.promise import data
from . import data
from slapos.promise.check_slow_queries_digest_result import checkMariadbDigestResult
class TestCheckSlowQueriesDigestResult(unittest.TestCase):
base_path, = data.__path__
def _create_file(self, date, with_content):
content = ''
if with_content:
......@@ -54,8 +56,6 @@ class TestCheckSlowQueriesDigestResult(unittest.TestCase):
os.remove(self.base_dir+name)
def setUp(self):
self.base_path = "/".join(data.__file__.split("/")[:-1])
self.base_dir = "/tmp/ap/"
if not os.path.exists(self.base_dir):
os.makedirs(self.base_dir)
......
......@@ -30,15 +30,16 @@ import os
import sqlite3
from datetime import datetime
from slapos.test.promise import data
from . import data
from slapos.promise.check_user_memory import getMemoryInfo, checkMemoryUsage
no_result_message = "No result found in collector.db."
class TestUserMemory(unittest.TestCase):
base_path, = data.__path__
def setUp(self):
self.base_path = "/".join(data.__file__.split("/")[:-1])
self.status = "ok"
self.db_file = '/tmp/collector.db'
self.db_dir = os.path.dirname(self.db_file)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment