Commit 19a85b5d authored by Paul Rich's avatar Paul Rich
Browse files

adding in tests for validator and handling for no forkers registered case

parent 5dca1eba
...@@ -7,10 +7,9 @@ import time ...@@ -7,10 +7,9 @@ import time
import sys import sys
import xmlrpclib import xmlrpclib
import json import json
import ConfigParser
import Cobalt.Util import Cobalt.Util
import Cobalt.Components.system.AlpsBridge as ALPSBridge import Cobalt.Components.system.AlpsBridge as ALPSBridge
from Cobalt.Components.base import Component, exposed, automatic, query, locking from Cobalt.Components.base import Component, exposed, automatic, query, locking
from Cobalt.Components.system.base_system import BaseSystem from Cobalt.Components.system.base_system import BaseSystem
from Cobalt.Components.system.CrayNode import CrayNode from Cobalt.Components.system.CrayNode import CrayNode
...@@ -28,7 +27,6 @@ _logger = logging.getLogger(__name__) ...@@ -28,7 +27,6 @@ _logger = logging.getLogger(__name__)
init_cobalt_config() init_cobalt_config()
SYSTEM_SIZE = int(get_config_option('system', 'size'))
UPDATE_THREAD_TIMEOUT = int(get_config_option('alpssystem', UPDATE_THREAD_TIMEOUT = int(get_config_option('alpssystem',
'update_thread_timeout', 10)) 'update_thread_timeout', 10))
TEMP_RESERVATION_TIME = int(get_config_option('alpssystem', TEMP_RESERVATION_TIME = int(get_config_option('alpssystem',
...@@ -90,6 +88,11 @@ class CraySystem(BaseSystem): ...@@ -90,6 +88,11 @@ class CraySystem(BaseSystem):
component. component.
''' '''
try:
self.system_size = int(get_config_option('system', 'size'))
except (ConfigParser.NoSectionError, ConfigParser.NoOptionError):
_logger.critical('ALPS SYSTEM: ABORT STARTUP: System size must be specified in the [system] section of the cobalt configuration file.')
sys.exit(1)
if DRAIN_MODE not in DRAIN_MODES: if DRAIN_MODE not in DRAIN_MODES:
#abort startup, we have a completely invalid config. #abort startup, we have a completely invalid config.
_logger.critical('ALPS SYSTEM: ABORT STARTUP: %s is not a valid drain mode. Must be one of %s.', _logger.critical('ALPS SYSTEM: ABORT STARTUP: %s is not a valid drain mode. Must be one of %s.',
...@@ -1247,10 +1250,10 @@ class CraySystem(BaseSystem): ...@@ -1247,10 +1250,10 @@ class CraySystem(BaseSystem):
spec['nodecount'] = int(spec['nodecount']) spec['nodecount'] = int(spec['nodecount'])
# proccount = spec.get('proccount', None) # proccount = spec.get('proccount', None)
# if proccount is None: # if proccount is None:
# nodes * # nodes *
if spec['proccount'] > SYSTEM_SIZE: if spec['nodecount'] > self.system_size:
raise JobValidationError('Job requested %s nodes. Maximum permitted size is %s' % raise JobValidationError('Job requested %s nodes. Maximum permitted size is %s' %
(spec['proccount'], SYSTEM_SIZE)) (spec['nodecount'], self.system_size))
spec['proccount'] = spec['nodecount'] #set multiplier for default depth spec['proccount'] = spec['nodecount'] #set multiplier for default depth
mode = spec.get('mode', 'script') mode = spec.get('mode', 'script')
spec['mode'] = mode spec['mode'] = mode
......
...@@ -260,7 +260,10 @@ class ProcessGroupManager(object): #degenerate with ProcessMonitor. ...@@ -260,7 +260,10 @@ class ProcessGroupManager(object): #degenerate with ProcessMonitor.
if len(ordered_forkers) < 0: if len(ordered_forkers) < 0:
raise RuntimeError("No forkers registered!") raise RuntimeError("No forkers registered!")
else: else:
forker = ordered_forkers[0] #this is now a tuple if len(ordered_forkers) > 0:
forker = ordered_forkers[0] #this is now a tuple
else:
return None
try: try:
return self.forker_locations[forker] return self.forker_locations[forker]
except KeyError: except KeyError:
......
# Test Cray-specific utilities/calls. # Test Cray-specific utilities/calls.
SYSTEM_CONFIG_ENTRY = """
[system]
size: 10
elogin_hosts: foo:bar
"""
import Cobalt
import TestCobalt
config_file = Cobalt.CONFIG_FILES[0]
config_fp = open(config_file, "w")
config_fp.write(SYSTEM_CONFIG_ENTRY)
config_fp.close()
from nose.tools import raises from nose.tools import raises
from testsuite.TestCobalt.Utilities.assert_functions import assert_match, assert_not_match from testsuite.TestCobalt.Utilities.assert_functions import assert_match, assert_not_match
from Cobalt.Components.system.CrayNode import CrayNode from Cobalt.Components.system.CrayNode import CrayNode
...@@ -10,7 +22,6 @@ import Cobalt.Components.system.AlpsBridge as AlpsBridge ...@@ -10,7 +22,6 @@ import Cobalt.Components.system.AlpsBridge as AlpsBridge
from mock import MagicMock, Mock, patch from mock import MagicMock, Mock, patch
def is_match(a, b): def is_match(a, b):
return a is b return a is b
...@@ -954,3 +965,22 @@ class TestCraySystem(object): ...@@ -954,3 +965,22 @@ class TestCraySystem(object):
self.assert_draining(i, 550, 2) self.assert_draining(i, 550, 2)
for i in [1, 4, 5]: for i in [1, 4, 5]:
self.assert_not_draining(i) self.assert_not_draining(i)
def test_validate_job_normal(self):
'''CraySystem.validate_job: valid job submission'''
expected = {'mode':'script', 'nodecount': 1, 'proccount': 1}
spec = {'mode':'script', 'nodecount': 1}
ret_spec = self.system.validate_job(spec)
assert expected == ret_spec, "Invalid spec returned"
@raises(Cobalt.Exceptions.JobValidationError)
def test_validate_job_reject_too_large(self):
'''CraySystem.validate_job: reject too big job'''
spec = {'mode':'script', 'nodecount': 9999}
ret_spec = self.system.validate_job(spec)
@raises(Cobalt.Exceptions.JobValidationError)
def test_validate_job_reject_no_host(self):
'''CraySystem.validate_job: reject missing ssh host'''
spec = {'mode':'interactive', 'nodecount': 1, 'qsub_host':'foo'}
ret_spec = self.system.validate_job(spec)
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