Code Monkey home page Code Monkey logo

Comments (3)

butjar avatar butjar commented on June 28, 2024

I was looking at the code and it is not as simple as implementing it within the openrd dry_run method. My idea was piping OpenR and wait for the output Starting OpenR daemon.

openrd --foo="bar" [...] --dryrun | grep -m1 "Starting OpenR daemon."

I realized that piping is not possible with the current implementation of pexec in the router.

Maybe an expect script would be a viable solution. However, this would introduce a new dependency. Any thoughts how to implement a proper dry_run for OpenR?

from ipmininet.

oliviertilmans avatar oliviertilmans commented on June 28, 2024

What you likely want is to launch openrd using popen instead of pexec.

One way to do that would be to rework how we use dry_run such that:

  • The logic using dry_run is abstracted, i.e., extractedfrom __router.py to a new method in Daemon such as do_config_check()
def do_config_check(self):
    out, err, code = self._node.pexec(shlex.split(self.dry_run))
    if code:
        lg.error(d.NAME, 'configuration check failed [ rcode:', str(code), ']\nstdout:',
                  str(out), '\nstderr:', str(err))
    return code
  • OpenrDaemon would then override that new method à-la:
import fcntl
import os
import time
# [...]

@property
def dry_run(self):
    raise TypeError('OpenrDaemon requires to use its custom do_config_check')

def do_config_check(self):
    p = self._node.popen('...')
    # read p.stdout or p.stderr here and match on your target string
    # naive example below
    fcntl.fcntl(p.stdout.fileno(), fcntl.F_SETFL,
                fcntl.fcntl(proc.stdout.fileno(), fcntl.F_GETFL) | os.O_NONBLOCK)
    output = ''
    start -= time.clock()
    while True:
        output += p.stdout.read(64)
        if 'some_string' in output:
            break
        if start + time.clock() > 5:
            p.terminate()
            raise RuntimeError('OpenrDaemon took more than 5s to check the config')
        time.sleep(.1)
    p.terminate()
    return perform_more_sanity_checks()

The downside of this is that there would not be any integration with the current process management system that tries to ensure that all processes are cleaned up before the network is destroyed.
Maybe the daemons should hold a reference to the router __processes instance instead of the node? (I cannot remember if this is already the case)

from ipmininet.

butjar avatar butjar commented on June 28, 2024

Ok, this is exactly the direction I was thinking of. Maybe a decorator comes in handy. I need to study the cleanup code more. Thx for the guidance.

from ipmininet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.