ironic-python-agent代码调试

本文介绍了ironic-python-agent如何在调试模式下工作,包括如何通过修改pxelinux配置启用standalone模式,以及如何在裸机上执行调试操作,如打断点进行代码检查。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ironic-python-agent支持调试模式,在该模式下,ironic-python-agent 启动后不会执行任何向ironic conductor或ironic inspector发送请求的操作(不会主动发送心跳,因此ironic conductor无法向agent下发动作),只会启动WSGIserver 用于接受外界发来的请求,从而进行调试。
调试的方法是在内核命令行参数中添加"ipa-standalone=True",以x86_64位的bios启动方式的裸机为例,需要修改pxelinux.cfg/default文件,现给出一个完整的配置文件:

# cat pxelinux.cfg/default
default introspect

label introspect
kernel ironic-agent.kernel
append initrd=ironic-initramfs-zyf-20201112-enable ipa-inspection-callback-url=http://40.40.50.5:5050/v1/continue ipa-standalone=True ipa-inspection-collectors=default,logs systemd.journald.forward_to_console=yes coreos.autologin ipa-collect-lldp=True ipa-collect-network-interface=active

ipappend 2

pxe启动裸机(裸机的vlan需要调整为provision网络的vlan):

ironic node-set-boot-device ee565101-130d-4411-b67c-85e72de5c239 pxe
ironic node-set-power-state ee565101-130d-4411-b67c-85e72de5c239 on

裸机启动成功后登陆裸机,先设置ironic-python-agent服务为不设置重启服务,把“Restart”和“RestartSec”去掉:

执行命令:

sed -i '/Restart/d' /usr/lib/systemd/system/ironic-python-agent.service
sed -i '/RestartSec/d' /usr/lib/systemd/system/ironic-python-agent.service
systemctl daemon-reload
systemctl stop ironic-python-agent.service

后面即可进行调试,比如,打断点:

# /opt/ironic-python-agent/lib/python3.6/site-packages/ironic_python_agent/extensions/base.py
    def execute_command(self, command_name, **kwargs):
        """Execute an agent command."""
        with self.command_lock:
            LOG.debug('Executing command: %(name)s with args: %(args)s',
                      {'name': command_name, 'args': kwargs})
            extension_part, command_part = self.split_command(command_name)

            if len(self.command_results) > 0:
                last_command = list(self.command_results.values())[-1]
                if not last_command.is_done():
                    LOG.error('Tried to execute %(command)s, agent is still '
                              'executing %(last)s', {'command': command_name,
                                                     'last': last_command})
                    raise errors.CommandExecutionError('agent is busy')

            import pdb;pdb.set_trace()
            try:
                ext = self.get_extension(extension_part)
                result = ext.execute(command_part, **kwargs)
            ......
            return result

在ironic节点上编写调试脚本并运行:

from ironic import objects
from ironic.common.context import get_admin_context
from ironic.common import profiler
from ironic.conf import CONF
from ironic.common import config
from ironic.common import context


def_files=['/etc/ironic/ironic.conf']
CONF(project='ironic', default_config_files=def_files)
objects.register_all()
profiler.setup('ironic_conductor', CONF.host)


def agent_execute_clean_step(context, node, step):
    from ironic.drivers.modules import agent_client
    client = agent_client.AgentClient()
    ports = objects.Port.list_by_node_id(
        context, node.id)
    agent_get_ret = client.get_clean_steps(node, ports).get(
        'command_result', {})
    node.driver_internal_info['hardware_manager_version'] = agent_get_ret[
        'hardware_manager_version']
    return client.execute_clean_step(step, node, ports)


def main():
    cx = get_admin_context()
    node = objects.Node.get_by_uuid(cx, "ee565101-130d-4411-b67c-85e72de5c239")
    node.driver_internal_info['agent_url']="http://40.40.50.61:9999"
    step = {'interface': 'deploy',
            'priority': 99,
            'step': 'erase_devices_metadata',
            'abortable': True}
    result = agent_execute_clean_step(cx, node, step)
    import pdb;pdb.set_trace()
    print("ok")

main()

ironic-pythont-agent的pdb结果:

[root@localhost ~]# /usr/local/bin/ironic-python-agent
/opt/ironic-python-agent/lib64/python3.6/site-packages/pecan/__init__.py:122: RuntimeWarning: `static_root` is only used when `debug` is True, ignoring
  RuntimeWarning
2021-01-18 08:36:52.934 2148 INFO root [-] Picked root device /dev/sdf for node None based on root device hints None
2021-01-18 08:36:52.961 2148 INFO root [-] Picked root device /dev/sdf for node None based on root device hints None
2021-01-18 08:36:52.988 2148 INFO root [-] Picked root device /dev/sdf for node None based on root device hints None
2021-01-18 08:36:53.001 2148 INFO root [-] Hardware manager found: ironic_python_agent.hardware_managers.cna:IntelCnaHardwareManager
2021-01-18 08:36:53.001 2148 INFO root [-] Hardware manager found: ironic_python_agent.hardware_managers.mlnx:MellanoxDeviceHardwareManager
2021-01-18 08:36:53.027 2148 INFO root [-] Picked root device /dev/sdf for node None based on root device hints None
2021-01-18 08:36:53.028 2148 INFO root [-] Hardware manager found: ironic_python_agent.hardware:GenericHardwareManager
> /opt/ironic-python-agent/lib64/python3.6/site-packages/ironic_python_agent/extensions/base.py(252)execute_command()
-> ext = self.get_extension(extension_part)
(Pdb) l
247                                                          'last': last_command})
248                         raise errors.CommandExecutionError('agent is busy')
249
250                 try:
251                     import pdb;pdb.set_trace()
252  ->                 ext = self.get_extension(extension_part)
253                     result = ext.execute(command_part, **kwargs)
254                 except KeyError:
255                     # Extension Not found
256                     LOG.exception('Extension %s not found', extension_part)
257                     raise errors.RequestedObjectNotFoundError('Extension',
(Pdb)

``
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值