#!/usr/share/ucs-test/runner python
## desc: ucs-school-singlemaster-check
## roles: [domaincontroller_master]
## tags: [apptest,ucsschool]
## exposure: safe
## packages:
##    - ucs-school-master | ucs-school-singlemaster

import subprocess
import sys
import univention.testing.ucr as ucr_test


def main():
	dpkgQuery = subprocess.Popen(["dpkg-query", "-W", "-f", '${Status}\n', "ucs-school-singlemaster"], stdout=subprocess.PIPE).communicate()[0]
	ucr = ucr_test.UCSTestConfigRegistry()
	ucr.load()
	if ucr.is_true('ucsschool/singlemaster'):
		if (dpkgQuery == "install ok installed\n"):
			print 'ucs-school-singlemaster is installed'
			print "ucsschool/singlemaster =", ucr.get('ucsschool/singlemaster'), ' (Correct Value)'
			returnValue = 0
		else:
			print 'ucs-school-singlemaster is not installed '
			print "ucsschool/singlemaster =", ucr.get('ucsschool/singlemaster'), ' (Wrong Value)'
			returnValue = 1
	else:
		if (dpkgQuery == "install ok installed\n"):
			print 'ucs-school-singlemaster is installed '
			print "ucsschool/singlemaster = false", ' (Wrong Value)'
			returnValue = 1
		else:
			print 'ucs-school-singlemaster is not installed '
			print "ucsschool/singlemaster = false", ' (Correct Value)'
			returnValue = 0
	return returnValue


if __name__ == '__main__':
	sys.exit(main())
