mirror of
https://github.com/xcat2/confluent.git
synced 2026-09-21 16:39:32 +00:00
Run the module self tests through asyncio
These __main__ blocks called coroutines as if they were functions, so they did nothing at all. Single calls go through asyncio.run; sshutil, proxmox and vcenter needed an _selftest coroutine. Two were invisible to pyrefly because repr() and list() count as using the result: vcenter's get_vm_serial needs an await, and proxmox's get_vm_inventory is an async generator. lldp called _extract_neighbor_data twice, once correctly, so the bare call is dropped. xcc3.remote_nodecfg is not a self test: every other handler defines it as a coroutine and selfservice.py awaits it.
This commit is contained in:
@@ -113,5 +113,5 @@ if __name__ == '__main__':
|
||||
info = {'addresses': [[sys.argv[1]]]}
|
||||
print(repr(info))
|
||||
testr = NodeHandler(info, c)
|
||||
testr.config(sys.argv[2])
|
||||
asyncio.run(testr.config(sys.argv[2]))
|
||||
|
||||
|
||||
@@ -357,4 +357,4 @@ if __name__ == '__main__':
|
||||
info = {'addresses': [[sys.argv[1]]] }
|
||||
print(repr(info))
|
||||
testr = NodeHandler(info, c)
|
||||
testr.config(sys.argv[2])
|
||||
asyncio.run(testr.config(sys.argv[2]))
|
||||
|
||||
@@ -246,4 +246,4 @@ if __name__ == '__main__':
|
||||
info = {'addresses': [[sys.argv[1]]] }
|
||||
print(repr(info))
|
||||
testr = NodeHandler(info, c)
|
||||
testr.config(sys.argv[2])
|
||||
asyncio.run(testr.config(sys.argv[2]))
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import asyncio
|
||||
import codecs
|
||||
import confluent.discovery.handlers.redfishbmc as redfishbmc
|
||||
import confluent.util as util
|
||||
@@ -90,7 +91,7 @@ class NodeHandler(redfishbmc.NodeHandler):
|
||||
|
||||
|
||||
|
||||
def remote_nodecfg(nodename, cfm):
|
||||
async def remote_nodecfg(nodename, cfm):
|
||||
cfg = cfm.get_node_attributes(
|
||||
nodename, 'hardwaremanagement.manager')
|
||||
ipaddr = cfg.get(nodename, {}).get('hardwaremanagement.manager', {}).get(
|
||||
@@ -102,7 +103,7 @@ def remote_nodecfg(nodename, cfm):
|
||||
'address')
|
||||
info = {'addresses': [ipaddr]}
|
||||
nh = NodeHandler(info, cfm)
|
||||
nh.config(nodename)
|
||||
await nh.config(nodename)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
@@ -112,5 +113,5 @@ if __name__ == '__main__':
|
||||
info = {'addresses': [[sys.argv[1]]]}
|
||||
print(repr(info))
|
||||
testr = NodeHandler(info, c)
|
||||
testr.config(sys.argv[2])
|
||||
asyncio.run(testr.config(sys.argv[2]))
|
||||
|
||||
|
||||
@@ -480,4 +480,4 @@ from pprint import pprint
|
||||
if __name__ == '__main__':
|
||||
def printit(rsp):
|
||||
print(repr(rsp))
|
||||
snoop(pprint)
|
||||
asyncio.run(snoop(pprint))
|
||||
|
||||
@@ -1004,4 +1004,4 @@ async def consider_discover(info, packet, sock, cfg, reqview, nodeguess, addr=No
|
||||
if __name__ == '__main__':
|
||||
def testsnoop(info):
|
||||
print(repr(info))
|
||||
snoop(testsnoop)
|
||||
asyncio.run(snoop(testsnoop))
|
||||
|
||||
@@ -698,4 +698,4 @@ async def scan(srvtypes=_slp_services, addresses=None, localonly=False):
|
||||
if __name__ == '__main__':
|
||||
def testsnoop(a):
|
||||
print(repr(a))
|
||||
snoop(testsnoop)
|
||||
asyncio.run(snoop(testsnoop))
|
||||
|
||||
@@ -411,7 +411,6 @@ if __name__ == '__main__':
|
||||
# a quick one-shot test, args are switch and snmpv1 string for now
|
||||
# (should do three argument form for snmpv3 test
|
||||
import sys
|
||||
_extract_neighbor_data((sys.argv[1], sys.argv[2], None, True))
|
||||
asyncio.run(_extract_neighbor_data((sys.argv[1], sys.argv[2], None, True)))
|
||||
print(repr(_neighdata))
|
||||
|
||||
|
||||
@@ -481,7 +481,7 @@ async def create(nodes, element, configmanager, inputdata):
|
||||
return
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
async def _selftest():
|
||||
import sys
|
||||
import os
|
||||
myuser = os.environ['PMXUSER']
|
||||
@@ -489,12 +489,16 @@ if __name__ == '__main__':
|
||||
vc = PmxApiClient(sys.argv[1], myuser, mypass, None)
|
||||
vm = sys.argv[2]
|
||||
if sys.argv[3] == 'setboot':
|
||||
vc.set_vm_bootdev(vm, sys.argv[4])
|
||||
vc.get_vm_bootdev(vm)
|
||||
await vc.set_vm_bootdev(vm, sys.argv[4])
|
||||
await vc.get_vm_bootdev(vm)
|
||||
elif sys.argv[3] == 'power':
|
||||
vc.set_vm_power(vm, sys.argv[4])
|
||||
await vc.set_vm_power(vm, sys.argv[4])
|
||||
elif sys.argv[3] == 'getinfo':
|
||||
print(repr(list(vc.get_vm_inventory(vm))))
|
||||
print("Bootdev: " + vc.get_vm_bootdev(vm))
|
||||
print("Power: " + vc.get_vm_power(vm))
|
||||
print(repr([datum async for datum in vc.get_vm_inventory(vm)]))
|
||||
print("Bootdev: " + await vc.get_vm_bootdev(vm))
|
||||
print("Power: " + await vc.get_vm_power(vm))
|
||||
#print("Serial: " + repr(vc.get_vm_serial(vm)))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
asyncio.run(_selftest())
|
||||
|
||||
@@ -411,7 +411,7 @@ async def create(nodes, element, configmanager, inputdata):
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
async def _selftest():
|
||||
import sys
|
||||
import os
|
||||
myuser = os.environ['VMWUSER']
|
||||
@@ -419,12 +419,16 @@ if __name__ == '__main__':
|
||||
vc = VmwApiClient(sys.argv[1], myuser, mypass, None)
|
||||
vm = sys.argv[2]
|
||||
if sys.argv[3] == 'setboot':
|
||||
vc.set_vm_bootdev(vm, sys.argv[4])
|
||||
vc.get_vm_bootdev(vm)
|
||||
await vc.set_vm_bootdev(vm, sys.argv[4])
|
||||
await vc.get_vm_bootdev(vm)
|
||||
elif sys.argv[3] == 'power':
|
||||
vc.set_vm_power(vm, sys.argv[4])
|
||||
await vc.set_vm_power(vm, sys.argv[4])
|
||||
elif sys.argv[3] == 'getinfo':
|
||||
vc.get_vm(vm)
|
||||
print("Bootdev: " + vc.get_vm_bootdev(vm))
|
||||
print("Power: " + vc.get_vm_power(vm))
|
||||
print("Serial: " + repr(vc.get_vm_serial(vm)))
|
||||
await vc.get_vm(vm)
|
||||
print("Bootdev: " + await vc.get_vm_bootdev(vm))
|
||||
print("Power: " + await vc.get_vm_power(vm))
|
||||
print("Serial: " + repr(await vc.get_vm_serial(vm)))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
asyncio.run(_selftest())
|
||||
|
||||
@@ -271,8 +271,13 @@ def ca_exists():
|
||||
return os.path.exists('/etc/confluent/ssh/ca')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
initialize_root_key(True)
|
||||
async def _selftest():
|
||||
await initialize_root_key(True)
|
||||
if not ca_exists():
|
||||
initialize_ca()
|
||||
print(repr(sign_host_key(open('/etc/ssh/ssh_host_ed25519_key.pub').read(), collective.get_myname())))
|
||||
await initialize_ca()
|
||||
print(repr(await sign_host_key(
|
||||
open('/etc/ssh/ssh_host_ed25519_key.pub').read(), collective.get_myname())))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
asyncio.run(_selftest())
|
||||
|
||||
Reference in New Issue
Block a user