Remove agent vendor passthru completely

This patch removes all the basic classes for lookup/heartbeat as vendor
passthru from Ironic code, as well as removes those API endpoints from
list of API public routes.

It also removes the agent vendor passthru from fake drivers.

Change-Id: Ia133a63ed4e8ed99551f6d2656d24e990300f3a2
Closes-Bug: #1640533
This commit is contained in:
Pavlo Shchelokovskyy 2016-11-15 13:13:10 +02:00 committed by Pavlo Shchelokovskyy
parent 87c2db4dc6
commit 5eb4ba26dd
9 changed files with 83 additions and 716 deletions

View File

@ -32,9 +32,6 @@ app = {
# IPA ramdisk methods
'/v1/lookup',
'/v1/heartbeat/[a-z0-9\-]+',
# Old IPA ramdisk methods - will be removed in the Ocata release
'/v1/drivers/[a-z0-9_]*/vendor_passthru/lookup',
'/v1/nodes/[a-z0-9\-]+/vendor_passthru/heartbeat',
],
}

View File

@ -107,7 +107,6 @@ class FakePXEDriver(base.BaseDriver):
self.power = fake.FakePower()
self.boot = pxe.PXEBoot()
self.deploy = iscsi_deploy.ISCSIDeploy()
self.vendor = iscsi_deploy.VendorPassthru()
class FakeSSHDriver(base.BaseDriver):
@ -163,7 +162,6 @@ class FakeAgentDriver(base.BaseDriver):
self.power = fake.FakePower()
self.boot = pxe.PXEBoot()
self.deploy = agent.AgentDeploy()
self.vendor = agent.AgentVendorInterface()
self.raid = agent.AgentRAID()

View File

@ -524,17 +524,6 @@ class AgentDeploy(AgentDeployMixin, base.DeployInterface):
task, manage_boot=CONF.agent.manage_agent_boot)
class AgentVendorInterface(agent_base_vendor.BaseAgentVendor,
AgentDeployMixin):
"""Implementation of agent vendor interface.
Contains old lookup and heartbeat endpoints currently pending deprecation.
WARNING: This class is deprecated and will be removed in the Ocata release.
Drivers should stop relying on it.
"""
class AgentRAID(base.RAIDInterface):
"""Implementation of RAIDInterface which uses agent ramdisk."""

View File

@ -20,27 +20,20 @@ import collections
from ironic_lib import metrics_utils
from oslo_log import log
from oslo_utils import excutils
from oslo_utils import strutils
from oslo_utils import timeutils
import retrying
from ironic.api.controllers.v1 import ramdisk
from ironic.common import boot_devices
from ironic.common import exception
from ironic.common.i18n import _, _LE, _LI, _LW
from ironic.common import policy
from ironic.common import states
from ironic.common import utils
from ironic.conductor import rpcapi
from ironic.conductor import task_manager
from ironic.conductor import utils as manager_utils
from ironic.conf import CONF
from ironic.drivers import base
from ironic.drivers.modules import agent_client
from ironic.drivers.modules import deploy_utils
from ironic.drivers import utils as driver_utils
from ironic import objects
LOG = log.getLogger(__name__)
@ -663,255 +656,3 @@ class AgentDeployMixin(object):
LOG.info(_LI('Local boot successfully configured for node %s'),
node.uuid)
# TODO(dtantsur): deprecate and remove it as soon as we stop using it ourselves
# in the Ocata release.
class BaseAgentVendor(AgentDeployMixin, base.VendorInterface):
def __init__(self):
self.supported_payload_versions = ['2']
super(BaseAgentVendor, self).__init__()
def get_properties(self):
"""Return the properties of the interface.
:returns: dictionary of <property name>:<property description> entries.
"""
return VENDOR_PROPERTIES
def validate(self, task, method, **kwargs):
"""Validate the driver-specific Node deployment info.
No validation necessary.
:param task: a TaskManager instance
:param method: method to be validated
"""
pass
def driver_validate(self, method, **kwargs):
"""Validate the driver deployment info.
:param method: method to be validated.
"""
version = kwargs.get('version')
if not version:
raise exception.MissingParameterValue(_('Missing parameter '
'version'))
if version not in self.supported_payload_versions:
raise exception.InvalidParameterValue(_('Unknown lookup '
'payload version: %s')
% version)
@METRICS.timer('BaseAgentVendor.heartbeat')
@base.passthru(['POST'],
description=_("Used by ramdisk agent to check in with the "
"ironic-conductor service. Required argument:"
" 'agent_url' - the API URL of the agent, in "
"the form http://<agent_host>:<agent_port>."))
@task_manager.require_exclusive_lock
def heartbeat(self, task, **kwargs):
"""Method for agent to periodically check in.
The agent should be sending its agent_url (so Ironic can talk back)
as a kwarg. kwargs should have the following format::
{
'agent_url': 'http://AGENT_HOST:AGENT_PORT'
}
AGENT_PORT defaults to 9999.
"""
try:
callback_url = kwargs['agent_url']
except KeyError:
raise exception.MissingParameterValue(_('For heartbeat operation, '
'"agent_url" must be '
'specified.'))
super(BaseAgentVendor, self).heartbeat(task, callback_url)
@METRICS.timer('BaseAgentVendor.lookup')
@base.driver_passthru(['POST'], async=False,
description=_("This should only be called by a "
"ramdisk agent, the first time the "
"agent checks in. It finds the Node "
"associated with the ramdisk and "
"returns the Node object."))
def lookup(self, context, **kwargs):
"""Find a matching node for the agent.
Method to be called the first time a ramdisk agent checks in. This
can be because this is a node just entering cleaning or a node that
rebooted for some reason. We will use the mac addresses listed in the
kwargs to find the matching node, then return the node object to the
agent. The agent can that use that UUID to use the node vendor
passthru method.
Currently, we don't handle the instance where the agent doesn't have
a matching node (i.e. a brand new, never been in Ironic node).
Additionally, we may pass on useful configurations to the agent, which
it would then be responsible for applying if relevant. Today these are
limited to heartbeat_timeout and metrics configuration.
kwargs should have the following format::
{
"version": "2"
"inventory": {
"interfaces": [
{
"name": "eth0",
"mac_address": "00:11:22:33:44:55",
"switch_port_descr": "port24",
"switch_chassis_descr": "tor1"
}, ...
], ...
},
"node_uuid": "ab229209-0139-4588-bbe5-64ccec81dd6e"
}
The interfaces list should include a list of the non-IPMI MAC addresses
in the form aa:bb:cc:dd:ee:ff.
node_uuid argument is optional. If it's provided (e.g. as a result of
inspection run before lookup), this method will just return a node and
options.
This method will also return the timeout for heartbeats. The driver
will expect the agent to heartbeat before that timeout, or it will be
considered down. This will be in a root level key called
'heartbeat_timeout'
:raises: NotFound if no matching node is found.
:raises: InvalidParameterValue with unknown payload version
"""
LOG.warning(
_LW('Agent lookup vendor passthru is deprecated and will be '
'removed in the Ocata release; please update your '
'ironic-python-agent image to the Newton version'))
LOG.debug('Agent lookup using data %s', kwargs)
uuid = kwargs.get('node_uuid')
if uuid:
node = objects.Node.get_by_uuid(context, uuid)
else:
inventory = kwargs.get('inventory')
interfaces = self._get_interfaces(inventory)
mac_addresses = self._get_mac_addresses(interfaces)
node = self._find_node_by_macs(context, mac_addresses)
LOG.info(_LI('Initial lookup for node %s succeeded, agent is running '
'and waiting for commands'), node.uuid)
ndict = node.as_dict()
cdict = context.to_dict()
show_driver_secrets = policy.check('show_password', cdict, cdict)
if not show_driver_secrets:
ndict['driver_info'] = strutils.mask_dict_password(
ndict['driver_info'], "******")
return {
# heartbeat_timeout is a config, so moving it into the
# config namespace. Instead of a separate deprecation,
# this will die when the vendor_passthru version of
# lookup goes away.
'heartbeat_timeout': CONF.api.ramdisk_heartbeat_timeout,
'node': ndict,
'config': ramdisk.config(),
}
def _get_interfaces(self, inventory):
interfaces = []
try:
interfaces = inventory['interfaces']
except (KeyError, TypeError):
raise exception.InvalidParameterValue(_(
'Malformed network interfaces lookup: %s') % inventory)
return interfaces
def _get_mac_addresses(self, interfaces):
"""Returns MACs for the network devices."""
mac_addresses = []
for interface in interfaces:
try:
mac_addresses.append(utils.validate_and_normalize_mac(
interface.get('mac_address')))
except exception.InvalidMAC:
LOG.warning(_LW('Malformed MAC: %s'), interface.get(
'mac_address'))
return mac_addresses
def _find_node_by_macs(self, context, mac_addresses):
"""Get nodes for a given list of MAC addresses.
Given a list of MAC addresses, find the ports that match the MACs
and return the node they are all connected to.
:raises: NodeNotFound if the ports point to multiple nodes or no
nodes.
"""
ports = self._find_ports_by_macs(context, mac_addresses)
if not ports:
raise exception.NodeNotFound(_(
'No ports matching the given MAC addresses %s exist in the '
'database.') % mac_addresses)
node_id = self._get_node_id(ports)
try:
node = objects.Node.get_by_id(context, node_id)
except exception.NodeNotFound:
with excutils.save_and_reraise_exception():
LOG.exception(_LE('Could not find matching node for the '
'provided MACs %s.'), mac_addresses)
return node
def _find_ports_by_macs(self, context, mac_addresses):
"""Get ports for a given list of MAC addresses.
Given a list of MAC addresses, find the ports that match the MACs
and return them as a list of Port objects, or an empty list if there
are no matches
"""
ports = []
for mac in mac_addresses:
# Will do a search by mac if the mac isn't malformed
try:
port_ob = objects.Port.get_by_address(context, mac)
ports.append(port_ob)
except exception.PortNotFound:
LOG.warning(_LW('MAC address %s not found in database'), mac)
return ports
def _get_node_id(self, ports):
"""Get a node ID for a list of ports.
Given a list of ports, either return the node_id they all share or
raise a NotFound if there are multiple node_ids, which indicates some
ports are connected to one node and the remaining port(s) are connected
to one or more other nodes.
:raises: NodeNotFound if the MACs match multiple nodes. This
could happen if you swapped a NIC from one server to another and
don't notify Ironic about it or there is a MAC collision (since
they're not guaranteed to be unique).
"""
# See if all the ports point to the same node
node_ids = set(port_ob.node_id for port_ob in ports)
if len(node_ids) > 1:
raise exception.NodeNotFound(_(
'Ports matching mac addresses match multiple nodes. MACs: '
'%(macs)s. Port ids: %(port_ids)s') %
{'macs': [port_ob.address for port_ob in ports], 'port_ids':
[port_ob.uuid for port_ob in ports]}
)
# Only have one node_id left, return it.
return node_ids.pop()

View File

@ -573,13 +573,3 @@ class ISCSIDeploy(AgentDeployMixin, base.DeployInterface):
"""
deploy_utils.tear_down_inband_cleaning(
task, manage_boot=True)
class VendorPassthru(AgentDeployMixin, agent_base_vendor.BaseAgentVendor):
"""Interface to mix IPMI and PXE vendor-specific interfaces.
Contains old lookup and heartbeat endpoints currently pending deprecation.
WARNING: This class is deprecated and will be removed in the Ocata release.
Drivers should stop relying on it.
"""

View File

@ -466,21 +466,6 @@ class TestAgentDeploy(db_base.DbTestCase):
self.driver.heartbeat(task, 'url')
self.assertFalse(task.shared)
class TestAgentVendor(db_base.DbTestCase):
def setUp(self):
super(TestAgentVendor, self).setUp()
mgr_utils.mock_the_extension_manager(driver="fake_agent")
self.passthru = agent.AgentVendorInterface()
n = {
'driver': 'fake_agent',
'instance_info': INSTANCE_INFO,
'driver_info': DRIVER_INFO,
'driver_internal_info': DRIVER_INTERNAL_INFO,
}
self.node = object_utils.create_test_node(self.context, **n)
def _test_continue_deploy(self, additional_driver_info=None,
additional_expected_image_info=None):
self.node.provision_state = states.DEPLOYWAIT
@ -502,11 +487,11 @@ class TestAgentVendor(db_base.DbTestCase):
expected_image_info.update(additional_expected_image_info or {})
client_mock = mock.MagicMock(spec_set=['prepare_image'])
self.passthru._client = client_mock
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
self.passthru.continue_deploy(task)
task.driver.deploy._client = client_mock
task.driver.deploy.continue_deploy(task)
client_mock.prepare_image.assert_called_with(task.node,
expected_image_info)
@ -590,11 +575,11 @@ class TestAgentVendor(db_base.DbTestCase):
}
client_mock = mock.MagicMock(spec_set=['prepare_image'])
self.passthru._client = client_mock
with task_manager.acquire(self.context, self.node.uuid,
shared=False) as task:
self.passthru.continue_deploy(task)
task.driver.deploy._client = client_mock
task.driver.deploy.continue_deploy(task)
client_mock.prepare_image.assert_called_with(task.node,
expected_image_info)
@ -602,7 +587,7 @@ class TestAgentVendor(db_base.DbTestCase):
self.assertEqual(states.ACTIVE,
task.node.target_provision_state)
@mock.patch.object(agent.AgentVendorInterface, '_get_uuid_from_result',
@mock.patch.object(agent.AgentDeployMixin, '_get_uuid_from_result',
autospec=True)
@mock.patch.object(manager_utils, 'node_power_action', autospec=True)
@mock.patch.object(fake.FakePower, 'get_power_state',
@ -611,7 +596,7 @@ class TestAgentVendor(db_base.DbTestCase):
spec=types.FunctionType)
@mock.patch.object(pxe.PXEBoot, 'prepare_instance',
autospec=True)
@mock.patch('ironic.drivers.modules.agent.AgentVendorInterface'
@mock.patch('ironic.drivers.modules.agent.AgentDeployMixin'
'.check_deploy_success', autospec=True)
@mock.patch.object(pxe.PXEBoot, 'clean_up_ramdisk', autospec=True)
def test_reboot_to_instance(self, clean_pxe_mock, check_deploy_mock,
@ -628,7 +613,7 @@ class TestAgentVendor(db_base.DbTestCase):
get_power_state_mock.return_value = states.POWER_OFF
task.node.driver_internal_info['is_whole_disk_image'] = True
self.passthru.reboot_to_instance(task)
task.driver.deploy.reboot_to_instance(task)
clean_pxe_mock.assert_called_once_with(task.driver.boot, task)
check_deploy_mock.assert_called_once_with(mock.ANY, task.node)
@ -644,7 +629,7 @@ class TestAgentVendor(db_base.DbTestCase):
self.assertFalse(uuid_mock.called)
@mock.patch.object(deploy_utils, 'get_boot_mode_for_deploy', autospec=True)
@mock.patch.object(agent.AgentVendorInterface, '_get_uuid_from_result',
@mock.patch.object(agent.AgentDeployMixin, '_get_uuid_from_result',
autospec=True)
@mock.patch.object(manager_utils, 'node_power_action', autospec=True)
@mock.patch.object(fake.FakePower, 'get_power_state',
@ -653,7 +638,7 @@ class TestAgentVendor(db_base.DbTestCase):
spec=types.FunctionType)
@mock.patch.object(pxe.PXEBoot, 'prepare_instance',
autospec=True)
@mock.patch('ironic.drivers.modules.agent.AgentVendorInterface'
@mock.patch('ironic.drivers.modules.agent.AgentDeployMixin'
'.check_deploy_success', autospec=True)
@mock.patch.object(pxe.PXEBoot, 'clean_up_ramdisk', autospec=True)
def test_reboot_to_instance_partition_image(self, clean_pxe_mock,
@ -673,7 +658,7 @@ class TestAgentVendor(db_base.DbTestCase):
get_power_state_mock.return_value = states.POWER_OFF
task.node.driver_internal_info['is_whole_disk_image'] = False
self.passthru.reboot_to_instance(task)
task.driver.deploy.reboot_to_instance(task)
self.assertFalse(clean_pxe_mock.called)
check_deploy_mock.assert_called_once_with(mock.ANY, task.node)
@ -687,10 +672,11 @@ class TestAgentVendor(db_base.DbTestCase):
driver_int_info = task.node.driver_internal_info
self.assertEqual('root_uuid',
driver_int_info['root_uuid_or_disk_id']),
uuid_mock.assert_called_once_with(self.passthru, task, 'root_uuid')
uuid_mock.assert_called_once_with(task.driver.deploy,
task, 'root_uuid')
boot_mode_mock.assert_called_once_with(task.node)
@mock.patch.object(agent.AgentVendorInterface, '_get_uuid_from_result',
@mock.patch.object(agent.AgentDeployMixin, '_get_uuid_from_result',
autospec=True)
@mock.patch.object(manager_utils, 'node_power_action', autospec=True)
@mock.patch.object(fake.FakePower, 'get_power_state',
@ -699,7 +685,7 @@ class TestAgentVendor(db_base.DbTestCase):
spec=types.FunctionType)
@mock.patch.object(pxe.PXEBoot, 'prepare_instance',
autospec=True)
@mock.patch('ironic.drivers.modules.agent.AgentVendorInterface'
@mock.patch('ironic.drivers.modules.agent.AgentDeployMixin'
'.check_deploy_success', autospec=True)
@mock.patch.object(pxe.PXEBoot, 'clean_up_ramdisk', autospec=True)
def test_reboot_to_instance_boot_none(self, clean_pxe_mock,
@ -718,7 +704,7 @@ class TestAgentVendor(db_base.DbTestCase):
task.node.driver_internal_info['is_whole_disk_image'] = True
task.driver.boot = None
self.passthru.reboot_to_instance(task)
task.driver.deploy.reboot_to_instance(task)
self.assertFalse(clean_pxe_mock.called)
self.assertFalse(prepare_mock.called)
@ -735,7 +721,7 @@ class TestAgentVendor(db_base.DbTestCase):
self.assertFalse(uuid_mock.called)
@mock.patch.object(driver_utils, 'collect_ramdisk_logs', autospec=True)
@mock.patch.object(agent.AgentVendorInterface, '_get_uuid_from_result',
@mock.patch.object(agent.AgentDeployMixin, '_get_uuid_from_result',
autospec=True)
@mock.patch.object(manager_utils, 'node_power_action', autospec=True)
@mock.patch.object(fake.FakePower, 'get_power_state',
@ -744,7 +730,7 @@ class TestAgentVendor(db_base.DbTestCase):
spec=types.FunctionType)
@mock.patch.object(pxe.PXEBoot, 'prepare_instance',
autospec=True)
@mock.patch('ironic.drivers.modules.agent.AgentVendorInterface'
@mock.patch('ironic.drivers.modules.agent.AgentDeployMixin'
'.check_deploy_success', autospec=True)
@mock.patch.object(pxe.PXEBoot, 'clean_up_ramdisk', autospec=True)
def test_reboot_to_instance_boot_error(
@ -761,7 +747,7 @@ class TestAgentVendor(db_base.DbTestCase):
get_power_state_mock.return_value = states.POWER_OFF
task.node.driver_internal_info['is_whole_disk_image'] = True
task.driver.boot = None
self.passthru.reboot_to_instance(task)
task.driver.deploy.reboot_to_instance(task)
self.assertFalse(clean_pxe_mock.called)
self.assertFalse(prepare_mock.called)
@ -771,10 +757,10 @@ class TestAgentVendor(db_base.DbTestCase):
self.assertEqual(states.ACTIVE, task.node.target_provision_state)
collect_ramdisk_logs_mock.assert_called_once_with(task.node)
@mock.patch.object(agent_base_vendor.BaseAgentVendor,
@mock.patch.object(agent_base_vendor.AgentDeployMixin,
'configure_local_boot', autospec=True)
@mock.patch.object(deploy_utils, 'try_set_boot_device', autospec=True)
@mock.patch.object(agent.AgentVendorInterface, '_get_uuid_from_result',
@mock.patch.object(agent.AgentDeployMixin, '_get_uuid_from_result',
autospec=True)
@mock.patch.object(manager_utils, 'node_power_action', autospec=True)
@mock.patch.object(fake.FakePower, 'get_power_state',
@ -783,7 +769,7 @@ class TestAgentVendor(db_base.DbTestCase):
spec=types.FunctionType)
@mock.patch.object(pxe.PXEBoot, 'prepare_instance',
autospec=True)
@mock.patch('ironic.drivers.modules.agent.AgentVendorInterface'
@mock.patch('ironic.drivers.modules.agent.AgentDeployMixin'
'.check_deploy_success', autospec=True)
@mock.patch.object(pxe.PXEBoot, 'clean_up_ramdisk', autospec=True)
def test_reboot_to_instance_localboot(self, clean_pxe_mock,
@ -806,7 +792,7 @@ class TestAgentVendor(db_base.DbTestCase):
task.node.driver_internal_info['is_whole_disk_image'] = False
boot_option = {'capabilities': '{"boot_option": "local"}'}
task.node.instance_info = boot_option
self.passthru.reboot_to_instance(task)
task.driver.deploy.reboot_to_instance(task)
self.assertFalse(clean_pxe_mock.called)
check_deploy_mock.assert_called_once_with(mock.ANY, task.node)
@ -823,7 +809,7 @@ class TestAgentVendor(db_base.DbTestCase):
def test_deploy_has_started(self, mock_get_cmd):
with task_manager.acquire(self.context, self.node.uuid) as task:
mock_get_cmd.return_value = []
self.assertFalse(self.passthru.deploy_has_started(task))
self.assertFalse(task.driver.deploy.deploy_has_started(task))
@mock.patch.object(agent_client.AgentClient, 'get_commands_status',
autospec=True)
@ -831,7 +817,7 @@ class TestAgentVendor(db_base.DbTestCase):
with task_manager.acquire(self.context, self.node.uuid) as task:
mock_get_cmd.return_value = [{'command_name': 'prepare_image',
'command_status': 'SUCCESS'}]
self.assertTrue(self.passthru.deploy_has_started(task))
self.assertTrue(task.driver.deploy.deploy_has_started(task))
@mock.patch.object(agent_client.AgentClient, 'get_commands_status',
autospec=True)
@ -839,7 +825,7 @@ class TestAgentVendor(db_base.DbTestCase):
with task_manager.acquire(self.context, self.node.uuid) as task:
mock_get_cmd.return_value = [{'command_name': 'prepare_image',
'command_status': 'RUNNING'}]
self.assertTrue(self.passthru.deploy_has_started(task))
self.assertTrue(task.driver.deploy.deploy_has_started(task))
@mock.patch.object(agent_client.AgentClient, 'get_commands_status',
autospec=True)
@ -849,7 +835,7 @@ class TestAgentVendor(db_base.DbTestCase):
'command_status': 'SUCCESS'},
{'command_name': 'prepare_image',
'command_status': 'RUNNING'}]
self.assertTrue(self.passthru.deploy_has_started(task))
self.assertTrue(task.driver.deploy.deploy_has_started(task))
@mock.patch.object(agent_client.AgentClient, 'get_commands_status',
autospec=True)
@ -857,7 +843,7 @@ class TestAgentVendor(db_base.DbTestCase):
with task_manager.acquire(self.context, self.node.uuid) as task:
mock_get_cmd.return_value = [{'command_name': 'cache_image',
'command_status': 'SUCCESS'}]
self.assertFalse(self.passthru.deploy_has_started(task))
self.assertFalse(task.driver.deploy.deploy_has_started(task))
@mock.patch.object(agent_client.AgentClient, 'get_commands_status',
autospec=True)
@ -865,14 +851,14 @@ class TestAgentVendor(db_base.DbTestCase):
with task_manager.acquire(self.context, self.node.uuid) as task:
mock_get_cmd.return_value = [{'command_name': 'prepare_image',
'command_status': 'SUCCESS'}]
self.assertTrue(self.passthru.deploy_is_done(task))
self.assertTrue(task.driver.deploy.deploy_is_done(task))
@mock.patch.object(agent_client.AgentClient, 'get_commands_status',
autospec=True)
def test_deploy_is_done_empty_response(self, mock_get_cmd):
with task_manager.acquire(self.context, self.node.uuid) as task:
mock_get_cmd.return_value = []
self.assertFalse(self.passthru.deploy_is_done(task))
self.assertFalse(task.driver.deploy.deploy_is_done(task))
@mock.patch.object(agent_client.AgentClient, 'get_commands_status',
autospec=True)
@ -880,7 +866,7 @@ class TestAgentVendor(db_base.DbTestCase):
with task_manager.acquire(self.context, self.node.uuid) as task:
mock_get_cmd.return_value = [{'command_name': 'some_other_command',
'command_status': 'SUCCESS'}]
self.assertFalse(self.passthru.deploy_is_done(task))
self.assertFalse(task.driver.deploy.deploy_is_done(task))
@mock.patch.object(agent_client.AgentClient, 'get_commands_status',
autospec=True)
@ -888,7 +874,7 @@ class TestAgentVendor(db_base.DbTestCase):
with task_manager.acquire(self.context, self.node.uuid) as task:
mock_get_cmd.return_value = [{'command_name': 'prepare_image',
'command_status': 'RUNNING'}]
self.assertFalse(self.passthru.deploy_is_done(task))
self.assertFalse(task.driver.deploy.deploy_is_done(task))
class AgentRAIDTestCase(db_base.DbTestCase):
@ -896,7 +882,6 @@ class AgentRAIDTestCase(db_base.DbTestCase):
def setUp(self):
super(AgentRAIDTestCase, self).setUp()
mgr_utils.mock_the_extension_manager(driver="fake_agent")
self.passthru = agent.AgentVendorInterface()
self.target_raid_config = {
"logical_disks": [
{'size_gb': 200, 'raid_level': 0, 'is_root_volume': True},

View File

@ -15,7 +15,6 @@
# License for the specific language governing permissions and limitations
# under the License.
import copy
import time
import types
@ -46,321 +45,6 @@ DRIVER_INFO = db_utils.get_test_agent_driver_info()
DRIVER_INTERNAL_INFO = db_utils.get_test_agent_driver_internal_info()
class TestBaseAgentVendor(db_base.DbTestCase):
def setUp(self):
super(TestBaseAgentVendor, self).setUp()
mgr_utils.mock_the_extension_manager(driver="fake_agent")
self.passthru = agent_base_vendor.BaseAgentVendor()
n = {
'driver': 'fake_agent',
'instance_info': INSTANCE_INFO,
'driver_info': DRIVER_INFO,
'driver_internal_info': DRIVER_INTERNAL_INFO,
}
self.node = object_utils.create_test_node(self.context, **n)
def test_validate(self):
with task_manager.acquire(self.context, self.node.uuid) as task:
method = 'heartbeat'
self.passthru.validate(task, method)
def test_driver_validate(self):
kwargs = {'version': '2'}
method = 'lookup'
self.passthru.driver_validate(method, **kwargs)
def test_driver_validate_invalid_paremeter(self):
method = 'lookup'
kwargs = {'version': '1'}
self.assertRaises(exception.InvalidParameterValue,
self.passthru.driver_validate,
method, **kwargs)
def test_driver_validate_missing_parameter(self):
method = 'lookup'
kwargs = {}
self.assertRaises(exception.MissingParameterValue,
self.passthru.driver_validate,
method, **kwargs)
def test_lookup_version_not_found(self):
kwargs = {
'version': '999',
}
with task_manager.acquire(self.context, self.node.uuid) as task:
self.assertRaises(exception.InvalidParameterValue,
self.passthru.lookup,
task.context,
**kwargs)
@mock.patch('ironic.common.policy.check', autospec=True)
@mock.patch('ironic.drivers.modules.agent_base_vendor.BaseAgentVendor'
'._find_node_by_macs', autospec=True)
def _test_lookup_v2(self, find_mock, check_mock, show_password=True):
kwargs = {
'version': '2',
'inventory': {
'interfaces': [
{
'mac_address': 'aa:bb:cc:dd:ee:ff',
'name': 'eth0'
},
{
'mac_address': 'ff:ee:dd:cc:bb:aa',
'name': 'eth1'
}
]
}
}
# NOTE(jroll) apparently as_dict() returns a dict full of references
expected = copy.deepcopy(self.node.as_dict())
if show_password:
check_mock.return_value = True
else:
check_mock.return_value = False
expected['driver_info']['ipmi_password'] = '******'
self.config(agent_backend='statsd', group='metrics')
expected_metrics = {
'metrics': {
'backend': 'statsd',
'prepend_host': CONF.metrics.agent_prepend_host,
'prepend_uuid': CONF.metrics.agent_prepend_uuid,
'prepend_host_reverse':
CONF.metrics.agent_prepend_host_reverse,
'global_prefix': CONF.metrics.agent_global_prefix
},
'metrics_statsd': {
'statsd_host': CONF.metrics_statsd.agent_statsd_host,
'statsd_port': CONF.metrics_statsd.agent_statsd_port
},
'heartbeat_timeout': CONF.api.ramdisk_heartbeat_timeout
}
find_mock.return_value = self.node
with task_manager.acquire(self.context, self.node.uuid) as task:
node = self.passthru.lookup(task.context, **kwargs)
self.assertEqual(expected, node['node'])
self.assertEqual(expected_metrics, node['config'])
def test_lookup_v2_show_password(self):
self._test_lookup_v2(show_password=True)
def test_lookup_v2_hide_password(self):
self._test_lookup_v2(show_password=False)
def test_lookup_v2_missing_inventory(self):
with task_manager.acquire(self.context, self.node.uuid) as task:
self.assertRaises(exception.InvalidParameterValue,
self.passthru.lookup,
task.context)
def test_lookup_v2_empty_inventory(self):
with task_manager.acquire(self.context, self.node.uuid) as task:
self.assertRaises(exception.InvalidParameterValue,
self.passthru.lookup,
task.context,
inventory={})
def test_lookup_v2_empty_interfaces(self):
with task_manager.acquire(self.context, self.node.uuid) as task:
self.assertRaises(exception.NodeNotFound,
self.passthru.lookup,
task.context,
version='2',
inventory={'interfaces': []})
@mock.patch.object(objects.Node, 'get_by_uuid')
def test_lookup_v2_with_node_uuid(self, mock_get_node):
expected = copy.deepcopy(self.node.as_dict())
expected['driver_info']['ipmi_password'] = '******'
kwargs = {
'version': '2',
'node_uuid': 'fake-uuid',
'inventory': {
'interfaces': [
{
'mac_address': 'aa:bb:cc:dd:ee:ff',
'name': 'eth0'
},
{
'mac_address': 'ff:ee:dd:cc:bb:aa',
'name': 'eth1'
}
]
}
}
mock_get_node.return_value = self.node
with task_manager.acquire(self.context, self.node.uuid) as task:
node = self.passthru.lookup(task.context, **kwargs)
self.assertEqual(expected, node['node'])
self.assertEqual([mock.call(self.context, self.node.uuid),
mock.call(self.context, 'fake-uuid')],
mock_get_node.call_args_list)
@mock.patch.object(objects.port.Port, 'get_by_address',
spec_set=types.FunctionType)
def test_find_ports_by_macs(self, mock_get_port):
fake_port = object_utils.get_test_port(self.context)
mock_get_port.return_value = fake_port
macs = ['aa:bb:cc:dd:ee:ff']
with task_manager.acquire(
self.context, self.node['uuid'], shared=True) as task:
ports = self.passthru._find_ports_by_macs(task, macs)
self.assertEqual(1, len(ports))
self.assertEqual(fake_port.uuid, ports[0].uuid)
self.assertEqual(fake_port.node_id, ports[0].node_id)
@mock.patch.object(objects.port.Port, 'get_by_address',
spec_set=types.FunctionType)
def test_find_ports_by_macs_bad_params(self, mock_get_port):
mock_get_port.side_effect = exception.PortNotFound(port="123")
macs = ['aa:bb:cc:dd:ee:ff']
with task_manager.acquire(
self.context, self.node['uuid'], shared=True) as task:
empty_ids = self.passthru._find_ports_by_macs(task, macs)
self.assertEqual([], empty_ids)
@mock.patch('ironic.objects.node.Node.get_by_id',
spec_set=types.FunctionType)
@mock.patch('ironic.drivers.modules.agent_base_vendor.BaseAgentVendor'
'._get_node_id', autospec=True)
@mock.patch('ironic.drivers.modules.agent_base_vendor.BaseAgentVendor'
'._find_ports_by_macs', autospec=True)
def test_find_node_by_macs(self, ports_mock, node_id_mock, node_mock):
ports_mock.return_value = object_utils.get_test_port(self.context)
node_id_mock.return_value = '1'
node_mock.return_value = self.node
macs = ['aa:bb:cc:dd:ee:ff']
with task_manager.acquire(
self.context, self.node['uuid'], shared=True) as task:
node = self.passthru._find_node_by_macs(task, macs)
self.assertEqual(self.node, node)
@mock.patch('ironic.drivers.modules.agent_base_vendor.BaseAgentVendor'
'._find_ports_by_macs', autospec=True)
def test_find_node_by_macs_no_ports(self, ports_mock):
ports_mock.return_value = []
macs = ['aa:bb:cc:dd:ee:ff']
with task_manager.acquire(
self.context, self.node['uuid'], shared=True) as task:
self.assertRaises(exception.NodeNotFound,
self.passthru._find_node_by_macs,
task,
macs)
@mock.patch('ironic.objects.node.Node.get_by_uuid',
spec_set=types.FunctionType)
@mock.patch('ironic.drivers.modules.agent_base_vendor.BaseAgentVendor'
'._get_node_id', autospec=True)
@mock.patch('ironic.drivers.modules.agent_base_vendor.BaseAgentVendor'
'._find_ports_by_macs', autospec=True)
def test_find_node_by_macs_nodenotfound(self, ports_mock, node_id_mock,
node_mock):
port = object_utils.get_test_port(self.context)
ports_mock.return_value = [port]
node_id_mock.return_value = self.node['uuid']
node_mock.side_effect = [self.node,
exception.NodeNotFound(node=self.node)]
macs = ['aa:bb:cc:dd:ee:ff']
with task_manager.acquire(
self.context, self.node['uuid'], shared=True) as task:
self.assertRaises(exception.NodeNotFound,
self.passthru._find_node_by_macs,
task,
macs)
def test_get_node_id(self):
fake_port1 = object_utils.get_test_port(self.context,
node_id=123,
address="aa:bb:cc:dd:ee:fe")
fake_port2 = object_utils.get_test_port(self.context,
node_id=123,
id=42,
address="aa:bb:cc:dd:ee:fb",
uuid='1be26c0b-03f2-4d2e-ae87-'
'c02d7f33c782')
node_id = self.passthru._get_node_id([fake_port1, fake_port2])
self.assertEqual(fake_port2.node_id, node_id)
def test_get_node_id_exception(self):
fake_port1 = object_utils.get_test_port(self.context,
node_id=123,
address="aa:bb:cc:dd:ee:fc")
fake_port2 = object_utils.get_test_port(self.context,
node_id=321,
id=42,
address="aa:bb:cc:dd:ee:fd",
uuid='1be26c0b-03f2-4d2e-ae87-'
'c02d7f33c782')
self.assertRaises(exception.NodeNotFound,
self.passthru._get_node_id,
[fake_port1, fake_port2])
def test_get_interfaces(self):
fake_inventory = {
'interfaces': [
{
'mac_address': 'aa:bb:cc:dd:ee:ff',
'name': 'eth0'
}
]
}
interfaces = self.passthru._get_interfaces(fake_inventory)
self.assertEqual(fake_inventory['interfaces'], interfaces)
def test_get_interfaces_bad(self):
self.assertRaises(exception.InvalidParameterValue,
self.passthru._get_interfaces,
inventory={})
def test_heartbeat(self):
kwargs = {
'agent_url': 'http://127.0.0.1:9999/bar'
}
with task_manager.acquire(
self.context, self.node['uuid'], shared=False) as task:
self.passthru.heartbeat(task, **kwargs)
def test_heartbeat_bad(self):
kwargs = {}
with task_manager.acquire(
self.context, self.node['uuid'], shared=False) as task:
self.assertRaises(exception.MissingParameterValue,
self.passthru.heartbeat, task, **kwargs)
def test_vendor_passthru_vendor_routes(self):
expected = ['heartbeat']
with task_manager.acquire(self.context, self.node.uuid,
shared=True) as task:
vendor_routes = task.driver.vendor.vendor_routes
self.assertIsInstance(vendor_routes, dict)
self.assertEqual(expected, list(vendor_routes))
def test_vendor_passthru_driver_routes(self):
expected = ['lookup']
with task_manager.acquire(self.context, self.node.uuid,
shared=True) as task:
driver_routes = task.driver.vendor.driver_routes
self.assertIsInstance(driver_routes, dict)
self.assertEqual(expected, list(driver_routes))
def test_get_properties(self):
expected = agent_base_vendor.VENDOR_PROPERTIES
self.assertEqual(expected, self.passthru.get_properties())
class AgentDeployMixinBaseTest(db_base.DbTestCase):
def setUp(self):

View File

@ -533,7 +533,6 @@ class ISCSIDeployTestCase(db_base.DbTestCase):
super(ISCSIDeployTestCase, self).setUp()
mgr_utils.mock_the_extension_manager(driver="fake_pxe")
self.driver = driver_factory.get_driver("fake_pxe")
self.driver.vendor = iscsi_deploy.VendorPassthru()
self.node = obj_utils.create_test_node(
self.context, driver='fake_pxe',
instance_info=INST_INFO_DICT,
@ -541,11 +540,6 @@ class ISCSIDeployTestCase(db_base.DbTestCase):
driver_internal_info=DRV_INTERNAL_INFO_DICT,
)
self.node.driver_internal_info['agent_url'] = 'http://1.2.3.4:1234'
self.task = mock.MagicMock(spec=task_manager.TaskManager)
self.task.shared = False
self.task.node = self.node
self.task.driver = self.driver
self.task.context = self.context
dhcp_factory.DHCPFactory._dhcp_provider = None
def test_get_properties(self):
@ -712,60 +706,30 @@ class ISCSIDeployTestCase(db_base.DbTestCase):
self.driver.deploy.heartbeat(task, 'url')
self.assertFalse(task.shared)
class TestVendorPassthru(db_base.DbTestCase):
def setUp(self):
super(TestVendorPassthru, self).setUp()
mgr_utils.mock_the_extension_manager()
self.driver = driver_factory.get_driver("fake")
self.driver.vendor = iscsi_deploy.VendorPassthru()
self.node = obj_utils.create_test_node(
self.context, driver='fake',
instance_info=INST_INFO_DICT,
driver_info=DRV_INFO_DICT,
driver_internal_info=DRV_INTERNAL_INFO_DICT,
)
self.node.driver_internal_info['agent_url'] = 'http://1.2.3.4:1234'
self.task = mock.MagicMock(spec=task_manager.TaskManager)
self.task.shared = False
self.task.node = self.node
self.task.driver = self.driver
self.task.context = self.context
def test_vendor_routes(self):
expected = ['heartbeat']
with task_manager.acquire(self.context, self.node.uuid,
shared=True) as task:
vendor_routes = task.driver.vendor.vendor_routes
self.assertIsInstance(vendor_routes, dict)
self.assertEqual(sorted(expected), sorted(list(vendor_routes)))
def test_driver_routes(self):
expected = ['lookup']
with task_manager.acquire(self.context, self.node.uuid,
shared=True) as task:
driver_routes = task.driver.vendor.driver_routes
self.assertIsInstance(driver_routes, dict)
self.assertEqual(sorted(expected), sorted(list(driver_routes)))
@mock.patch.object(agent_base_vendor.BaseAgentVendor,
@mock.patch.object(agent_base_vendor.AgentDeployMixin,
'reboot_and_finish_deploy', autospec=True)
@mock.patch.object(iscsi_deploy, 'do_agent_iscsi_deploy', autospec=True)
def test_continue_deploy_netboot(self, do_agent_iscsi_deploy_mock,
reboot_and_finish_deploy_mock):
self.node.provision_state = states.DEPLOYWAIT
self.node.target_provision_state = states.ACTIVE
self.node.save()
uuid_dict_returned = {'root uuid': 'some-root-uuid'}
do_agent_iscsi_deploy_mock.return_value = uuid_dict_returned
self.driver.vendor.continue_deploy(self.task)
do_agent_iscsi_deploy_mock.assert_called_once_with(
self.task, self.driver.vendor._client)
reboot_and_finish_deploy_mock.assert_called_once_with(
mock.ANY, self.task)
with task_manager.acquire(self.context, self.node.uuid) as task:
with mock.patch.object(
task.driver.boot, 'prepare_instance') as m_prep_instance:
task.driver.deploy.continue_deploy(task)
do_agent_iscsi_deploy_mock.assert_called_once_with(
task, task.driver.deploy._client)
reboot_and_finish_deploy_mock.assert_called_once_with(
mock.ANY, task)
m_prep_instance.assert_called_once_with(task)
@mock.patch.object(agent_base_vendor.BaseAgentVendor,
@mock.patch.object(agent_base_vendor.AgentDeployMixin,
'reboot_and_finish_deploy', autospec=True)
@mock.patch.object(agent_base_vendor.BaseAgentVendor,
@mock.patch.object(agent_base_vendor.AgentDeployMixin,
'configure_local_boot', autospec=True)
@mock.patch.object(iscsi_deploy, 'do_agent_iscsi_deploy', autospec=True)
def test_continue_deploy_localboot(self, do_agent_iscsi_deploy_mock,
@ -774,22 +738,25 @@ class TestVendorPassthru(db_base.DbTestCase):
self.node.instance_info = {
'capabilities': {'boot_option': 'local'}}
self.node.provision_state = states.DEPLOYWAIT
self.node.target_provision_state = states.ACTIVE
self.node.save()
uuid_dict_returned = {'root uuid': 'some-root-uuid'}
do_agent_iscsi_deploy_mock.return_value = uuid_dict_returned
self.driver.vendor.continue_deploy(self.task)
do_agent_iscsi_deploy_mock.assert_called_once_with(
self.task, self.driver.vendor._client)
configure_local_boot_mock.assert_called_once_with(
self.task.driver.vendor, self.task, root_uuid='some-root-uuid',
efi_system_part_uuid=None)
reboot_and_finish_deploy_mock.assert_called_once_with(
self.task.driver.vendor, self.task)
with task_manager.acquire(self.context, self.node.uuid) as task:
task.driver.deploy.continue_deploy(task)
do_agent_iscsi_deploy_mock.assert_called_once_with(
task, task.driver.deploy._client)
configure_local_boot_mock.assert_called_once_with(
task.driver.deploy, task, root_uuid='some-root-uuid',
efi_system_part_uuid=None)
reboot_and_finish_deploy_mock.assert_called_once_with(
task.driver.deploy, task)
@mock.patch.object(agent_base_vendor.BaseAgentVendor,
@mock.patch.object(agent_base_vendor.AgentDeployMixin,
'reboot_and_finish_deploy', autospec=True)
@mock.patch.object(agent_base_vendor.BaseAgentVendor,
@mock.patch.object(agent_base_vendor.AgentDeployMixin,
'configure_local_boot', autospec=True)
@mock.patch.object(iscsi_deploy, 'do_agent_iscsi_deploy', autospec=True)
def test_continue_deploy_localboot_uefi(self, do_agent_iscsi_deploy_mock,
@ -798,19 +765,22 @@ class TestVendorPassthru(db_base.DbTestCase):
self.node.instance_info = {
'capabilities': {'boot_option': 'local'}}
self.node.provision_state = states.DEPLOYWAIT
self.node.target_provision_state = states.ACTIVE
self.node.save()
uuid_dict_returned = {'root uuid': 'some-root-uuid',
'efi system partition uuid': 'efi-part-uuid'}
do_agent_iscsi_deploy_mock.return_value = uuid_dict_returned
self.driver.vendor.continue_deploy(self.task)
do_agent_iscsi_deploy_mock.assert_called_once_with(
self.task, self.driver.vendor._client)
configure_local_boot_mock.assert_called_once_with(
self.task.driver.vendor, self.task, root_uuid='some-root-uuid',
efi_system_part_uuid='efi-part-uuid')
reboot_and_finish_deploy_mock.assert_called_once_with(
self.task.driver.vendor, self.task)
with task_manager.acquire(self.context, self.node.uuid) as task:
task.driver.deploy.continue_deploy(task)
do_agent_iscsi_deploy_mock.assert_called_once_with(
task, task.driver.deploy._client)
configure_local_boot_mock.assert_called_once_with(
task.driver.deploy, task, root_uuid='some-root-uuid',
efi_system_part_uuid='efi-part-uuid')
reboot_and_finish_deploy_mock.assert_called_once_with(
task.driver.deploy, task)
# Cleanup of iscsi_deploy with pxe boot interface

View File

@ -0,0 +1,13 @@
---
upgrade:
- Ironic no longer supports agent lookup/heartbeats as vendor passthru.
All out-of-tree drivers must be updated to use AgentDeployMixin classes
directly without relying on BaseAgentVendor class and other classes
that were inheriting from it
(agent.AgentVendorInterface and iscsi_deploy.VendorPassthru).
This means that Ironic is incompatible with deploy ramdisks based on
Ironic Python Agent (IPA) < 1.5.0.
Operators should update their IPA-based deploy ramdisks in this case.
Operators using non-IPA based deploy ramdisks which use ironic
lookup/heartbeats functionality must update those to use top-level
ironic lookup/heartbeats REST API (available since ironic API v1.22).