Consolidate content and configuration as node
This commit is contained in:
parent
27280d89d8
commit
947b783b6b
|
@ -123,8 +123,7 @@ class TeethAgent(object):
|
|||
self.command_lock = threading.Lock()
|
||||
self.log = log.getLogger(__name__)
|
||||
self.started_at = None
|
||||
self.configuration = None
|
||||
self.content = None
|
||||
self.node = None
|
||||
|
||||
def get_mode_name(self):
|
||||
if self.mode_implementation:
|
||||
|
@ -147,7 +146,7 @@ class TeethAgent(object):
|
|||
return self.hardware.list_hardware_info()
|
||||
|
||||
def get_node_uuid(self):
|
||||
return self.content['node']['uuid']
|
||||
return self.node['uuid']
|
||||
|
||||
def list_command_results(self):
|
||||
return self.command_results.values()
|
||||
|
@ -211,13 +210,9 @@ class TeethAgent(object):
|
|||
"""Run the Teeth Agent."""
|
||||
self.started_at = _time()
|
||||
# Get the UUID so we can heartbeat to Ironic
|
||||
mac_addresses = self.get_all_mac_addrs()
|
||||
self.configuration = self.api_client.lookup_node(
|
||||
mac_addresses,
|
||||
self.node = self.api_client.lookup_node(
|
||||
ipaddr=self.ipaddr,
|
||||
hardware_info=self.hardware.list_hardware_info(),
|
||||
mode=self.get_mode_name(),
|
||||
version=self.version,
|
||||
)
|
||||
self.heartbeater.start()
|
||||
wsgi = simple_server.make_server(
|
||||
|
|
|
@ -69,16 +69,13 @@ class APIClient(object):
|
|||
except Exception:
|
||||
raise errors.HeartbeatError('Invalid Heartbeat-Before header')
|
||||
|
||||
def lookup_node(self, mac_addrs, ipaddr, hardware_info, mode,
|
||||
version):
|
||||
def lookup_node(self, ipaddr, hardware_info):
|
||||
path = '/{api_version}/drivers/teeth/lookup'.format(
|
||||
api_version=self.api_version)
|
||||
api_version=self.api_version
|
||||
)
|
||||
data = {
|
||||
'mac_addresses': mac_addrs,
|
||||
'agent_url': self._get_agent_url(ipaddr),
|
||||
'hardware': hardware_info,
|
||||
'mode': mode,
|
||||
'version': version,
|
||||
}
|
||||
|
||||
try:
|
||||
|
@ -99,7 +96,7 @@ class APIClient(object):
|
|||
if 'node' not in content or 'uuid' not in content['node']:
|
||||
raise errors.LookupNodeError('Got invalid data from the API: '
|
||||
'{0}'.format(content))
|
||||
return content
|
||||
return content['node']
|
||||
|
||||
def _get_agent_url(self, ipaddr):
|
||||
return "http://{0}:9999".format(ipaddr)
|
||||
|
|
|
@ -103,11 +103,8 @@ class TestBaseTeethAgent(unittest.TestCase):
|
|||
self.api_client.session.request.return_value = response
|
||||
|
||||
self.api_client.lookup_node(
|
||||
mac_addrs=['aa:bb:cc:dd:ee:ff', '42:42:42:42:42:42'],
|
||||
ipaddr='42.42.42.42',
|
||||
hardware_info=self.hardware_info,
|
||||
version='15',
|
||||
mode='STANDBY',
|
||||
)
|
||||
|
||||
request_args = self.api_client.session.request.call_args[0]
|
||||
|
@ -116,8 +113,6 @@ class TestBaseTeethAgent(unittest.TestCase):
|
|||
|
||||
data = self.api_client.session.request.call_args[1]['data']
|
||||
content = json.loads(data)
|
||||
self.assertEqual(content['mode'], 'STANDBY')
|
||||
self.assertEqual(content['version'], '15')
|
||||
self.assertEqual(content['hardware'], [
|
||||
{
|
||||
'type': 'mac_address',
|
||||
|
@ -142,12 +137,8 @@ class TestBaseTeethAgent(unittest.TestCase):
|
|||
|
||||
self.assertRaises(errors.LookupNodeError,
|
||||
self.api_client.lookup_node,
|
||||
mac_addrs=['aa:bb:cc:dd:ee:ff',
|
||||
'42:42:42:42:42:42'],
|
||||
ipaddr='42.42.42.42',
|
||||
hardware_info=self.hardware_info,
|
||||
version='15',
|
||||
mode='STANDBY',
|
||||
)
|
||||
|
||||
def test_lookup_node_bad_response_data(self):
|
||||
|
@ -158,12 +149,8 @@ class TestBaseTeethAgent(unittest.TestCase):
|
|||
|
||||
self.assertRaises(errors.LookupNodeError,
|
||||
self.api_client.lookup_node,
|
||||
mac_addrs=['aa:bb:cc:dd:ee:ff',
|
||||
'42:42:42:42:42:42'],
|
||||
ipaddr='42.42.42.42',
|
||||
hardware_info=self.hardware_info,
|
||||
version='15',
|
||||
mode='STANDBY',
|
||||
hardware_info=self.hardware_info
|
||||
)
|
||||
|
||||
def test_lookup_node_bad_response_body(self):
|
||||
|
@ -176,10 +163,6 @@ class TestBaseTeethAgent(unittest.TestCase):
|
|||
|
||||
self.assertRaises(errors.LookupNodeError,
|
||||
self.api_client.lookup_node,
|
||||
mac_addrs=['aa:bb:cc:dd:ee:ff',
|
||||
'42:42:42:42:42:42'],
|
||||
ipaddr='42.42.42.42',
|
||||
hardware_info=self.hardware_info,
|
||||
version='15',
|
||||
mode='STANDBY',
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue