Пример #1
0
	def __check_privileges(self):
		log.test("privileges")
		if os.getuid() != 0:
			log.result("You have to be root to run all following tests.")
			return False
		else:
			log.result()
			return True
Пример #2
0
	def __test_tuning_plugin(self, name, load):

		log.test("tuning plugin: %s" % name)
		log.indent()

		# initialization

		log.test("initialization")
		try:
			exec "from %s.%s import _plugin" % (self.tp_dir, name)
		except Exception as e:
			log.result_e()
			log.unindent()
			return False
		log.result()

		# init()

		log.test("call init()")
		try:
			_plugin.init(self.config)
		except Exception as e:
			log.result_e(e)
			log.unindent()
			return False
		log.result()

		# setTuning()

		log.test("call setTuning()")

		if load == None:
			log.info("no data from monitor plugin available")
		else:
			try:
				_plugin.setTuning(load)
			except Exception as e:
				log.result_e(e)
				log.unindent()
				return False
			log.result()

		# cleanup()

		log.test("call cleanup()")
		try:
			_plugin.cleanup()
		except Exception as e:
			log.result_e(e)
			log.unindent()
			return False
		log.result()

		log.unindent()
		return True
Пример #3
0
	def __test_monitor_plugin(self, name):

		log.test("monitor plugin: %s" % name)
		log.indent()

		# initialization

		log.test("initialization")
		try:
			exec "from %s.%s import _plugin" % (self.mp_dir, name)
		except Exception as e:
			log.result_e(e)
			log.unindent()
			return None

		log.result()

		# init()

		log.test("call init()")
		try:
			_plugin.init(self.config)
		except Exception as e:
			log.result_e(e)
			log.unindent()
			return None
		log.result()

		# getLoad()

		log.test("call getLoad()")
		try:
			load = _plugin.getLoad()
			if load == None:
				raise Exception("Plugin returned None as a result.")
		except Exception as e:
			log.result_e(e)
			log.unindent()
			return None
		log.result()

		# cleanup()

		log.test("call cleanup()")
		try:
			_plugin.cleanup()
		except Exception as e:
			log.result_e(e)
			log.unindent()
			return load

		log.result()

		log.unindent()
		return load
Пример #4
0
	def __check_sibling_plugins(self, monitorplugins, tuningplugins):

		ok = True

		log.test("monitor and tuning plugins availability")

		for mp in monitorplugins:
			if tuningplugins.count(mp) != 1:
				ok = False
				log.info("monitor plugin '%s' misses tuning plugin" % mp)

		for tp in tuningplugins:
			if monitorplugins.count(tp) != 1:
				ok = False
				log.info("tuning plugin '%s' misses monitor plugin" % tp)

		if ok:
			log.result()
		else:
			log.result("monitor and tunning plugins do not match")
Пример #5
0
	def __check_plugins(self):

		monitorplugins = self.__get_plugins_from_dir(self.mp_dir)
		tuningplugins = self.__get_plugins_from_dir(self.tp_dir)

		# check plugins availability

		self.__check_sibling_plugins(monitorplugins, tuningplugins)

		# monitor plugins test

		log.test("monitor plugins test")
		if len(monitorplugins) == 0:
			log.result("no plugins found")

		log.indent()

		monitor_results = {}
		for mp in monitorplugins:
			load = self.__test_monitor_plugin(mp)
			monitor_results[mp] = load

		log.unindent()

		# tuning plugins test

		log.test("tunning plugins test")

		if len(tuningplugins) == 0:
			log.result("no plugins found")

		log.indent()

		for tp in tuningplugins:
			try:
				load = monitor_results[tp]
			except:
				load = None
			self.__test_tuning_plugin(tp, load)

		log.unindent()
Пример #6
0
	def __check_profiles(self):
		log.test("profiles listing")

		profiles_tester = os.listdir(self.profiles_dir)
		profiles_tester = filter(lambda f: f[0] != ".", profiles_tester)

		try:
			capture.clean()
			capture.capture()
			self.tuned_adm.run(["list"])
			capture.stdout()
		except Exception as e:
			log.report_e(e)
			return False

		# printed profiles (first line "Modes:" is skipped)
		profiles_tuned = capture.getcaptured().splitlines()[1:]

		# compare profiles_tester and profiles_tuned

		error = False
		for p in profiles_tester:
			if not p in profiles_tuned:
				log.info("tune-adm does not report profile '%s'" % p)
				error = True

		for p in profiles_tuned:
			if not p in profiles_tester:
				log.info("tune-adm reports extra profile '%s'" % p)
				error = True

		if error:
			log.result("profiles detected by this test differ from these reported by tuned-adm")
		else:
			log.result()
		
		return True
Пример #7
0
	def __check_state(self, profile, tuned_running, ktune_running):
		is_ok = True

		if profile == None:
			self.tuned_adm.run(["off"])
			log.test("checking state: off")
		else:
			self.tuned_adm.run(["profile", profile])
			log.test("checking state: %s" % profile)

		log.indent()

		# services status

		log.test("service 'tuned'")
		if self.__service_running("tuned") == tuned_running:
			log.result()
		else:
			is_ok = False
			log.result("should %s" % ( "be running" if tuned_running else "not be running" ))

		log.test("service 'ktune'")
		if self.__service_running("ktune") == ktune_running:
			log.result()
		else:
			is_ok = False
			log.result("should %s" % ( "be running" if ktune_running else "not be running" ))

		# init scripts

		log.test("checking 'tuned' initscript")
		if self.__initscript_enabled("tuned") == tuned_running:
			log.result()
		else:
			is_ok = False
			log.result("%s be enabled" % ( "should" if tuned_running else "should not" ))

		log.test("checking 'ktune' initscript")
		if self.__initscript_enabled("ktune") == ktune_running:
			log.result()
		else:
			is_ok = False
			log.result("%s be enabled" % ( "should" if ktune_running else "should not" ))

		# config files

		want_tunedadm_sh = False
		want_tunedadm_conf = False

		if profile != None:
			want_tunedadm_sh = os.path.exists("%s/%s/ktune.sh" % (self.profiles_fake_dir, profile))
			want_tunedadm_conf = os.path.exists("%s/%s/sysctl.ktune" % (self.profiles_fake_dir, profile))

		log.test("checking '/etc/ktune.d/tunedadm.sh'")
		if want_tunedadm_sh == os.path.exists("/etc/ktune.d/tunedadm.sh"):
			log.result()
		else:
			is_ok = False
			log.result("file should %s" % ( "exist" if want_tunedadm_sh else "not exist" ))

		log.test("checking '/etc/ktune.d/tunedadm.conf'")
		if want_tunedadm_conf == os.path.exists("/etc/ktune.d/tunedadm.conf"):
			log.result()
		else:
			is_ok = False
			log.result("file should %s" % ( "exist" if want_tunedadm_conf else "not exist" ))

		log.unindent()
		return is_ok