简体   繁体   English

从Python绑定中重置net-snmp库的所有全局内部状态

[英]Resetting all global internal state of the net-snmp library from the Python bindings

I'm trying to create automated integration tests for this hardware+software test subject which runs a SNMP agent as it's command interface. 我正在尝试为此硬件和软件测试主题创建自动集成测试,该主题运行SNMP代理作为其命令界面。 Our test setup looks like this: We're using Fitnesse as a test runner and PyFit to be able to write the tests in Python. 我们的测试设置如下所示:我们使用Fitnesse作为测试运行程序,使用PyFit能够用Python编写测试。 We then use netsnmp with Python bindings to send SNMP commands. 然后,我们将netsnmp与Python绑定一起使用来发送SNMP命令。 This works pretty well. 效果很好。

However, when I try to run a suite the SNMP agent (the test subject) is restarted (and usually at a different simulated time) which makes the internals of netsnmp get all sorts of interesting errors. 但是,当我尝试运行套件时,会重新启动SNMP代理(测试对象)(通常在不同的模拟时间),这使netsnmp的内部结构得到各种有趣的错误。

Turns out there is a lot of global state stored inside the netsnmp library like community and context names and problematically EngineTime and EngineBootCnt, which is used to prevent replay attacks in SNMP v3. 事实证明,netsnmp库中存储了很多全局状态,例如社区和上下文名称,并且有问题的是EngineTime和EngineBootCnt,它用于防止SNMP v3中的重放攻击。 This causes the agent to reject my snmp commands. 这将导致代理拒绝我的snmp命令。

My problems is how do I reinitialise the netsnmp library (from the Python bindings) in a way that the internal global state are reset? 我的问题是如何以重置内部全局状态的方式重新初始化netsnmp库(从Python绑定)? The netsnmp.Session object in the Python bindings do take the parameter EngineTime and EngineBoots and setting them to 0 should reset them, but actually it doesn't seem to do that. Python绑定中的netsnmp.Session对象确实采用了参数EngineTime和EngineBoots并将它们设置为0应该重置它们,但实际上似乎不这样做。 I also do not know if there is other global state in there which needs to be reset. 我也不知道是否还有其他全局状态需要重置。

I'm at a point where I think I need to rewrite the tests to use the pure python snmp library pysnmp, but I was hoping to avoid it. 我认为我需要重写测试以使用纯python snmp库pysnmp,但我希望避免使用它。

The engineTime and engineBoots values are probably what is messing you up because SNMPv3 requires they not go backwards. engineTime和engineBoots值可能使您感到困惑,因为SNMPv3要求它们不能向后移动。 If you have an agent that is restarting from scratch and not incrementing it's boots count (which is illegal, but under tests I could see why you'd be doing that) then you'd need to reset the internal notion of boots and time. 如果您有一个从头重新启动且未增加其启动计数的代理(这是非法的,但是在测试中我可以看到您为什么这样做),那么您需要重置启动和时间的内部概念。

However, setting them to 0 and 0 won't help because it'll assume those are defaults. 但是,将它们设置为0和0将无济于事,因为它将假定它们是默认值。 You should, instead, change one of them to '1' which should trigger the override clause to actually use the values. 相反,您应将其中之一更改为“ 1”,这将触发override子句以实际使用这些值。 Set the time to 1 and try it and I think it'll work (and if it doesn't, set them both to 1 instead and try that). 将时间设置为1并尝试一下,我认为它会起作用(如果不行,请将它们都设置为1并尝试一下)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM