#!/usr/bin/python3

##**************************************************************
##
## Copyright (C) 1990-2018, Condor Team, Computer Sciences Department,
## University of Wisconsin-Madison, WI.
##
## Licensed under the Apache License, Version 2.0 (the "License"); you
## may not use this file except in compliance with the License.  You may
## obtain a copy of the License at
##
##    http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
##
##**************************************************************

import os
import time

# request a  personal condor with the given config appended
#testreq: personal
append_config = """
#<<CONDOR_TESTREQ_CONFIG;
use feature : PartitionableSlot
NEGOTIATOR_INTERVAL = 5
MaxJobRetirementTime = 120
MachineMaxVacateTime = 5
NUM_CPUS = 3
CONDOR_TESTREQ_CONFIG
#endtestreq
"""

testName = 'python_example'
testSucceeded = 1

print '--- appending config fragment ---'
print append_config
print '---'

pid = os.popen('condor_config_val -write:up -')
config_diff = pid.read()
pid.close()

print '--- config diff ----'
print '    ' + '    \n'.join(config_diff.split('\n'))
print '---'

# kill some time
time.sleep(5)

# query startd ads
pid = os.popen('condor_status -compact')
status_lines = pid.read()
pid.close()

# and then print the output
print '--- condor_status -compact output ----'
print status_lines
print '---'


exit (0 if testSucceeded else 1)
