mirror of
https://github.com/xcat2/confluent.git
synced 2026-04-06 08:56:27 +00:00
Replace 'backdoor' with 'debugger'
This commit is contained in:
@@ -1,35 +1,79 @@
|
||||
import asyncio
|
||||
import code
|
||||
import os
|
||||
import socket
|
||||
import sys
|
||||
import confluent.util as util
|
||||
|
||||
#this will ultimately fill the role of the 'backdoor' of eventlet
|
||||
|
||||
# since we have to asyncio up the input and output, we use InteractiveInterpreter and handle the
|
||||
# input ourselves, since code is not asyncio friendly in and of itself
|
||||
#code.InteractiveConsole().interact()
|
||||
async def interact(sock):
|
||||
cloop = asyncio.get_event_loop()
|
||||
prompt = '>>> '
|
||||
|
||||
|
||||
|
||||
async def interact(cloop, cnn):
|
||||
prompt = b'>>> '
|
||||
somecode = ''
|
||||
itr = code.InteractiveInterpreter()
|
||||
confile = cnn.makefile('rw')
|
||||
while True:
|
||||
await cloop.sock_sendall(prompt)
|
||||
prompt = '... '
|
||||
await cloop.sock_sendall(cnn, prompt)
|
||||
prompt = b'... '
|
||||
newinput = b''
|
||||
while b'\n' not in newinput:
|
||||
newinput += await cloop.sock_recv()
|
||||
somecode += newinput
|
||||
if newinput.startswith(' '):
|
||||
prompt = '... '
|
||||
rcv = await cloop.sock_recv(cnn, 4)
|
||||
newinput += rcv
|
||||
somecode += newinput.decode()
|
||||
if newinput.startswith(b' '):
|
||||
prompt = b'... '
|
||||
continue
|
||||
try:
|
||||
compcode = code.compile_command(somecode)
|
||||
except SyntaxError as e:
|
||||
await cloop.sock_sendall(repr(e).encode('utf8'))
|
||||
await cloop.sock_sendall(cnn, repr(e).encode('utf8'))
|
||||
await cloop.sock_sendall(cnn, b'\n')
|
||||
compcode = None
|
||||
somecode = ''
|
||||
prompt = '>>> '
|
||||
prompt = b'>>> '
|
||||
if compcode:
|
||||
itr.runcode(compcode)
|
||||
saved = sys.stdin, sys.stderr, sys.stdout
|
||||
try:
|
||||
cnn.settimeout(10)
|
||||
confile = cnn.makefile('rw')
|
||||
sys.stderr = sys.stdout = confile
|
||||
itr.runcode(compcode)
|
||||
confile.flush()
|
||||
finally:
|
||||
sys.stdin, sys.stderr, sys.stdout = saved
|
||||
cnn.settimeout(0)
|
||||
print("done")
|
||||
somecode = ''
|
||||
prompt = '>>> '
|
||||
prompt = b'>>> '
|
||||
|
||||
|
||||
async def srv_debug(sock):
|
||||
cloop = asyncio.get_event_loop()
|
||||
while True:
|
||||
cnn, addr = await cloop.sock_accept(sock)
|
||||
cnn.settimeout(0)
|
||||
util.spawn(interact(cloop, cnn))
|
||||
|
||||
|
||||
def start_dbgif():
|
||||
unixsocket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
unixsocket.settimeout(0)
|
||||
try:
|
||||
os.remove("/var/run/confluent/dbg.sock")
|
||||
except OSError: # if file does not exist, no big deal
|
||||
pass
|
||||
if not os.path.isdir("/var/run/confluent"):
|
||||
os.makedirs('/var/run/confluent', 0o755)
|
||||
oumask = os.umask(0o077)
|
||||
unixsocket.bind("/var/run/confluent/dbg.sock")
|
||||
unixsocket.listen(12)
|
||||
os.chmod("/var/run/confluent/dbg.sock",
|
||||
0o600)
|
||||
os.umask(oumask)
|
||||
util.spawn(srv_debug(unixsocket))
|
||||
|
||||
@@ -85,18 +85,13 @@ import confluent.noderange as noderange
|
||||
import confluent.util as util
|
||||
import inspect
|
||||
import json
|
||||
import eventlet
|
||||
import traceback
|
||||
import shlex
|
||||
import struct
|
||||
#import eventlet.green.socket as socket
|
||||
import socket
|
||||
import socket as nsocket
|
||||
#webclient = eventlet.import_patched('pyghmi.util.webclient')
|
||||
|
||||
|
||||
import eventlet
|
||||
|
||||
autosensors = set()
|
||||
scanner = None
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ import atexit
|
||||
import confluent.auth as auth
|
||||
import confluent.config.conf as conf
|
||||
import confluent.config.configmanager as configmanager
|
||||
import confluent.debugger as debugger
|
||||
try:
|
||||
import anydbm as dbm
|
||||
except ModuleNotFoundError:
|
||||
@@ -50,13 +51,6 @@ except ImportError:
|
||||
#only for now
|
||||
pass
|
||||
import confluent.discovery.core as disco
|
||||
import eventlet
|
||||
dbgif = False
|
||||
try:
|
||||
import eventlet.backdoor as backdoor
|
||||
dbgif = True
|
||||
except Exception:
|
||||
pass
|
||||
havefcntl = True
|
||||
try:
|
||||
import fcntl
|
||||
@@ -336,19 +330,7 @@ async def run(args):
|
||||
configmanager.set_global('confluent_uuid', confluentuuid)
|
||||
if not configmanager._masterkey:
|
||||
configmanager.init_masterkey()
|
||||
if dbgif:
|
||||
oumask = os.umask(0o077)
|
||||
try:
|
||||
os.remove('/var/run/confluent/dbg.sock')
|
||||
except OSError:
|
||||
pass # We are not expecting the file to exist
|
||||
try:
|
||||
dbgsock = eventlet.listen("/var/run/confluent/dbg.sock",
|
||||
family=socket.AF_UNIX)
|
||||
eventlet.spawn_n(backdoor.backdoor_server, dbgsock)
|
||||
except AttributeError:
|
||||
pass # Windows...
|
||||
os.umask(oumask)
|
||||
debugger.start_dbgif()
|
||||
auth.check_for_yaml()
|
||||
collective.startup()
|
||||
await consoleserver.initialize()
|
||||
@@ -369,7 +351,7 @@ async def run(args):
|
||||
break
|
||||
except Exception:
|
||||
await asyncio.sleep(0.5)
|
||||
eventlet.spawn_n(disco.start_detection)
|
||||
disco.start_detection()
|
||||
await asyncio.sleep(1)
|
||||
await consoleserver.start_console_sessions()
|
||||
while 1:
|
||||
|
||||
@@ -47,7 +47,7 @@ pci_cache = {}
|
||||
|
||||
def get_dns_txt(qstring):
|
||||
return None
|
||||
# return eventlet.support.greendns.resolver.query(
|
||||
# return support.greendns.resolver.query(
|
||||
# qstring, 'TXT')[0].strings[0].replace('i=', '')
|
||||
|
||||
def get_pci_text_from_ids(subdevice, subvendor, device, vendor):
|
||||
@@ -77,7 +77,7 @@ def get_pci_text_from_ids(subdevice, subvendor, device, vendor):
|
||||
|
||||
|
||||
# There is something not right with the RLocks used in pyghmi when
|
||||
# eventlet comes into play. It seems like sometimes on acquire,
|
||||
# greenthreads comes into play. It seems like sometimes on acquire,
|
||||
# it calls _get_ident and it isn't the id(greenlet) and so
|
||||
# a thread deadlocks itself due to identity crisis?
|
||||
# However, since we are not really threaded, the operations being protected
|
||||
@@ -93,14 +93,6 @@ class NullLock(object):
|
||||
acquire = donothing
|
||||
release = donothing
|
||||
|
||||
#console.session.select = eventlet.green.select
|
||||
#console.session.threading = eventlet.green.threading
|
||||
#console.session.WAITING_SESSIONS = NullLock()
|
||||
#console.session.KEEPALIVE_SESSIONS = NullLock()
|
||||
#console.session.socket.getaddrinfo = eventlet.support.greendns.getaddrinfo
|
||||
|
||||
|
||||
#_ipmiworkers = greenpool.GreenPool(512)
|
||||
|
||||
_ipmithread = None
|
||||
_ipmiwaiters = []
|
||||
|
||||
@@ -38,7 +38,7 @@ pci_cache = {}
|
||||
|
||||
def get_dns_txt(qstring):
|
||||
return None
|
||||
# return eventlet.support.greendns.resolver.query(
|
||||
# return support.greendns.resolver.query(
|
||||
# qstring, 'TXT')[0].strings[0].replace('i=', '')
|
||||
|
||||
def get_pci_text_from_ids(subdevice, subvendor, device, vendor):
|
||||
@@ -67,24 +67,6 @@ def get_pci_text_from_ids(subdevice, subvendor, device, vendor):
|
||||
return vendorstr, devstr
|
||||
|
||||
|
||||
# There is something not right with the RLocks used in pyghmi when
|
||||
# eventlet comes into play. It seems like sometimes on acquire,
|
||||
# it calls _get_ident and it isn't the id(greenlet) and so
|
||||
# a thread deadlocks itself due to identity crisis?
|
||||
# However, since we are not really threaded, the operations being protected
|
||||
# are not actually dangerously multiplexed... so we can replace with
|
||||
# a null context manager for now
|
||||
class NullLock(object):
|
||||
|
||||
def donothing(self, *args, **kwargs):
|
||||
return 1
|
||||
|
||||
__enter__ = donothing
|
||||
__exit__ = donothing
|
||||
acquire = donothing
|
||||
release = donothing
|
||||
|
||||
|
||||
sensor_categories = {
|
||||
'temperature': frozenset(['Temperature']),
|
||||
'energy': frozenset(['Energy']),
|
||||
@@ -150,9 +132,6 @@ class IpmiCommandWrapper(ipmicommand.Command):
|
||||
cfm, node, 'pubkeys.tls_hardwaremanager').verify_cert
|
||||
kwargs['verifycallback'] = kv
|
||||
self = await super().create(**kwargs)
|
||||
#kwargs['pool'] = eventlet.greenpool.GreenPool(4)
|
||||
#Some BMCs at the time of this writing crumble under the weight
|
||||
#of 4 concurrent requests. For now give up on this optimization.
|
||||
self.cfm = cfm
|
||||
self.node = node
|
||||
self._inhealth = False
|
||||
|
||||
Reference in New Issue
Block a user