Permalink
Browse files

Fix the configuration not being passed to ha processes

  • Loading branch information...
1 parent 284dd7e commit 0c686ed2a2669e55820045202a7cc4f5f917a2a9 @oldpatricka oldpatricka committed Sep 13, 2012
Showing with 44 additions and 12 deletions.
  1. +8 −10 ion/agents/cei/high_availability_agent.py
  2. +36 −2 ion/agents/cei/test/test_haagent.py
@@ -1,11 +1,6 @@
-import datetime
-import logging
-
from pyon.agent.simple_agent import SimpleResourceAgent
-from pyon.public import IonObject, log
-from pyon.util.containers import get_safe
-from pyon.net.endpoint import Publisher
from pyon.event.event import EventPublisher
+from pyon.public import log
from interface.objects import AgentCommand, ProcessDefinition, ProcessSchedule, ProcessStateEnum
from interface.services.cei.iprocess_dispatcher_service import ProcessDispatcherServiceClient
@@ -64,7 +59,7 @@ def on_init(self):
process_spec = self.CFG.get_safe("highavailability.process_spec")
# TODO: Allow other core class?
self.core = HighAvailabilityCore(cfg, ProcessDispatcherSimpleAPIClient,
- pds, process_spec, self.policy)
+ pds, process_spec, self.policy, parameters=policy_parameters)
self.policy_thread = looping_call(self.policy_interval, self.core.apply_policy)
@@ -125,8 +120,11 @@ class ProcessDispatcherSimpleAPIClient(object):
ProcessStateEnum.ERROR: '850-FAILED'
}
- def __init__(self, name, **kwargs):
- self.real_client = ProcessDispatcherServiceClient(to_name=name, **kwargs)
+ def __init__(self, name, real_client=None, **kwargs):
+ if real_client is not None:
+ self.real_client = real_client
+ else:
+ self.real_client = ProcessDispatcherServiceClient(to_name=name, **kwargs)
self.event_pub = EventPublisher()
def create_definition(self, definition_id, definition_type, executable,
@@ -153,7 +151,7 @@ def schedule_process(self, upid, definition_id, configuration=None,
process_schedule = ProcessSchedule()
sched_pid = self.real_client.schedule_process(definition_id,
- process_schedule, configuration={}, process_id=pid)
+ process_schedule, configuration=configuration, process_id=upid)
proc = self.real_client.read_process(sched_pid)
dict_proc = {'upid': proc.process_id,
@@ -4,17 +4,20 @@
from nose.plugins.attrib import attr
from nose.plugins.skip import SkipTest
+from mock import Mock
from pyon.agent.simple_agent import SimpleResourceAgentClient
from pyon.event.event import EventSubscriber
from pyon.public import log
from pyon.service.service import BaseService
+from pyon.util.containers import DotDict
+from pyon.util.unit_test import PyonTestCase
from pyon.util.int_test import IonIntegrationTestCase
from pyon.util.context import LocalContextMixin
from interface.services.icontainer_agent import ContainerAgentClient
-from ion.agents.cei.high_availability_agent import HighAvailabilityAgentClient
+from ion.agents.cei.high_availability_agent import HighAvailabilityAgentClient, ProcessDispatcherSimpleAPIClient
from interface.services.cei.iprocess_dispatcher_service import ProcessDispatcherServiceClient
-from interface.objects import ProcessDefinition, ProcessSchedule, ProcessTarget, ProcessStateEnum
+from interface.objects import ProcessStateEnum
class FakeProcess(LocalContextMixin):
@@ -32,6 +35,7 @@ def needs_epu(test):
def wrapped(*args, **kwargs):
try:
import epu
+ assert epu
return test(*args, **kwargs)
except ImportError:
raise SkipTest("Need epu to run this test.")
@@ -177,3 +181,33 @@ def test_features(self):
self.await_state_event("test", ProcessStateEnum.TERMINATE)
self.assertEqual(len(self.get_running_procs()), 0)
+
+@attr('UNIT', group='cei')
+class ProcessDispatcherSimpleAPIClientTest(PyonTestCase):
+
+ def setUp(self):
+ self.mock_real_client = DotDict()
+ self.mock_real_client.read_process_definition = Mock()
+ self.mock_real_client.create_process = Mock()
+ self.mock_real_client.schedule_process = Mock()
+ self.mock_real_client.read_process = Mock()
+ self.mock_eventpub = DotDict()
+ self.mock_eventpub.publish_event = Mock()
+
+ self.client = ProcessDispatcherSimpleAPIClient('fake', real_client=self.mock_real_client)
+ self.client.event_pub = self.mock_eventpub
+
+ def test_schedule(self):
+
+ upid = 'my_pid'
+ definition_id = 'my_def'
+ configuration = {'some': 'value'}
+
+ self.client.schedule_process(upid, definition_id, configuration=configuration)
+
+ self.assertEqual(self.mock_real_client.schedule_process.call_count, 1)
+ args, kwargs = self.mock_real_client.schedule_process.call_args
+
+ self.assertEqual(args[0], definition_id)
+ self.assertEqual(kwargs['configuration'], configuration)
+ self.assertEqual(kwargs['process_id'], upid)

0 comments on commit 0c686ed

Please sign in to comment.