Update agent driver with new field driver_internal_info

Agent driver save agent_url/agent_last_heartbeat in driver_info before.
They are not input from admin, driver_internal_info should be the better
place.

Implements: blueprint driver-internal-info
Change-Id: Iaaa0081e3d4ab426832d5ddc5112606e2eda1e5f
This commit is contained in:
Lin Tan 2015-02-02 16:46:00 +08:00
parent e4d2622c86
commit 35a7dcdd4f
5 changed files with 29 additions and 14 deletions

View File

@ -335,20 +335,20 @@ class AgentVendorInterface(base.VendorInterface):
AGENT_PORT defaults to 9999.
"""
node = task.node
driver_info = node.driver_info
driver_internal_info = node.driver_internal_info
LOG.debug(
'Heartbeat from %(node)s, last heartbeat at %(heartbeat)s.',
{'node': node.uuid,
'heartbeat': driver_info.get('agent_last_heartbeat')})
driver_info['agent_last_heartbeat'] = int(_time())
'heartbeat': driver_internal_info.get('agent_last_heartbeat')})
driver_internal_info['agent_last_heartbeat'] = int(_time())
try:
driver_info['agent_url'] = kwargs['agent_url']
driver_internal_info['agent_url'] = kwargs['agent_url']
except KeyError:
raise exception.MissingParameterValue(_('For heartbeat operation, '
'"agent_url" must be '
'specified.'))
node.driver_info = driver_info
node.driver_internal_info = driver_internal_info
node.save()
# Async call backs don't set error state on their own

View File

@ -39,11 +39,17 @@ class AgentClient(object):
self.session = requests.Session()
def _get_command_url(self, node):
if 'agent_url' not in node.driver_info:
agent_url = node.driver_internal_info.get('agent_url')
if not agent_url:
# (lintan) Keep backwards compatible with booted nodes before this
# change. Remove this after K.
agent_url = node.driver_info.get('agent_url')
if not agent_url:
raise exception.IronicException(_('Agent driver requires '
'agent_url in driver_info'))
'agent_url in '
'driver_internal_info'))
return ('%(agent_url)s/%(api_version)s/commands' %
{'agent_url': node.driver_info['agent_url'],
{'agent_url': agent_url,
'api_version': CONF.agent.agent_api_version})
def _get_command_body(self, method, params):

View File

@ -126,12 +126,17 @@ def get_test_agent_instance_info():
def get_test_agent_driver_info():
return {
'agent_url': 'http://127.0.0.1/foo',
'deploy_kernel': 'glance://deploy_kernel_uuid',
'deploy_ramdisk': 'glance://deploy_ramdisk_uuid',
}
def get_test_agent_driver_internal_info():
return {
'agent_url': 'http://127.0.0.1/foo',
}
def get_test_iboot_info():
return {
"iboot_address": "1.2.3.4",

View File

@ -32,6 +32,7 @@ from ironic.tests.objects import utils as object_utils
INSTANCE_INFO = db_utils.get_test_agent_instance_info()
DRIVER_INFO = db_utils.get_test_agent_driver_info()
DRIVER_INTERNAL_INFO = db_utils.get_test_agent_driver_internal_info()
CONF = cfg.CONF
@ -66,7 +67,8 @@ class TestAgentDeploy(db_base.DbTestCase):
n = {
'driver': 'fake_agent',
'instance_info': INSTANCE_INFO,
'driver_info': DRIVER_INFO
'driver_info': DRIVER_INFO,
'driver_internal_info': DRIVER_INTERNAL_INFO,
}
self.node = object_utils.create_test_node(self.context, **n)
@ -139,7 +141,8 @@ class TestAgentVendor(db_base.DbTestCase):
n = {
'driver': 'fake_agent',
'instance_info': INSTANCE_INFO,
'driver_info': DRIVER_INFO
'driver_info': DRIVER_INFO,
'driver_internal_info': DRIVER_INTERNAL_INFO,
}
self.node = object_utils.create_test_node(self.context, **n)

View File

@ -34,7 +34,8 @@ class MockResponse(object):
class MockNode(object):
def __init__(self):
self.uuid = 'uuid'
self.driver_info = {
self.driver_info = {}
self.driver_internal_info = {
'agent_url': "http://127.0.0.1:9999"
}
self.instance_info = {}
@ -49,11 +50,11 @@ class TestAgentClient(base.TestCase):
def test__get_command_url(self):
command_url = self.client._get_command_url(self.node)
expected = self.node.driver_info['agent_url'] + '/v1/commands'
expected = self.node.driver_internal_info['agent_url'] + '/v1/commands'
self.assertEqual(expected, command_url)
def test__get_command_url_fail(self):
del self.node.driver_info['agent_url']
del self.node.driver_internal_info['agent_url']
self.assertRaises(exception.IronicException,
self.client._get_command_url,
self.node)