#!/usr/share/ucs-test/runner python
## desc: check samba-tool drs showrepl
## exposure: safe
## tags:
##  - apptest
## packages:
## - univention-samba4

from __future__ import print_function
from subprocess import PIPE, Popen
import univention.testing.utils as utils
import re

proc = Popen(['samba-tool', 'drs', 'showrepl'], stdout=PIPE, stderr=PIPE)

stdout, stderr = proc.communicate()

print('** STDERR')
print(stderr.strip())
print('** STDOUT')
print(stdout.strip())
print('**')

if stderr.strip():
	errors = []
	for line in stderr.splitlines():
		if not line.endswith('WARNING: The "blocking locks" option is deprecated'):
			errors.append(line)
	if errors:
		utils.fail('samba-tool drsi showrepl returned on stderr: %s' % '\n'.join(errors))

if re.search('ERR_', stdout):
	utils.fail('samba-tool drsi showrepl returned a string with ERR_')
