本文整理汇总了Python中pyon.agent.agent.ResourceAgentClient.get_agent_process_id方法的典型用法代码示例。如果您正苦于以下问题:Python ResourceAgentClient.get_agent_process_id方法的具体用法?Python ResourceAgentClient.get_agent_process_id怎么用?Python ResourceAgentClient.get_agent_process_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyon.agent.agent.ResourceAgentClient
的用法示例。
在下文中一共展示了ResourceAgentClient.get_agent_process_id方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_agent_registration
# 需要导入模块: from pyon.agent.agent import ResourceAgentClient [as 别名]
# 或者: from pyon.agent.agent.ResourceAgentClient import get_agent_process_id [as 别名]
def test_agent_registration(self):
self._start_container()
idev = IonObject("TestInstrument", name="any_resource")
idev_id, _ = self.container.resource_registry.create(idev)
config = dict(agent=dict(resource_id=idev_id))
pid1 = self.container.spawn_process('agent1', 'pyon.agent.test.test_agent', 'SampleAgent', config)
rac = ResourceAgentClient(idev_id)
rac_pid = rac.get_agent_process_id()
rac_de = rac.get_agent_directory_entry()
self.assertEquals(rac_pid, pid1)
# Now fake a second agent directory entry that wasn't cleaned up
self.container.directory.register("/Agents", "fake_pid",
**dict(name="agent1",
container=self.container.id,
resource_id=idev_id,
agent_id="fake"))
entries = self.container.directory.find_by_value('/Agents', 'resource_id', idev_id)
self.assertEquals(len(entries), 2)
rac = ResourceAgentClient(idev_id)
rac_pid1 = rac.get_agent_process_id()
self.assertEquals(rac_pid1, "fake_pid")
# Check cleanup side effect of agent client
entries = self.container.directory.find_by_value('/Agents', 'resource_id', idev_id)
self.assertEquals(len(entries), 1)
# Now restore the original process id
self.container.directory.register("/Agents", pid1,
**dict(name="agent1",
container=self.container.id,
resource_id=idev_id,
agent_id=rac_de.attributes["agent_id"]))
rac = ResourceAgentClient(idev_id)
rac_pid1 = rac.get_agent_process_id()
self.assertEquals(rac_pid1, pid1)
# Check cleanup side effect of agent client
entries = self.container.directory.find_by_value('/Agents', 'resource_id', idev_id)
self.assertEquals(len(entries), 1)
self.container.terminate_process(pid1)