Junos OS

 View Only
last person joined: 3 days ago 

Ask questions and share experiences about Junos OS.
  • 1.  Getting Python Junos SDK example working

    Posted 07-01-2014 02:51

    I'm following Junos SDK Documentation (Release 13.2R1.7) trying to get a python script working. Specifically, I'm reading "Building a Junos SDK Package Containing Python Scripts". I followed step by step all the process and installed final bundle in my Junos Router MX 480 in version 13.2R2.4 (I know, it is not exactly the same version, but it should be similar, I think).

     

    I achieved generating the bundle and installing it in the router with any warning or error, but when I want to execute script using shell I got:

     

    /opt/sdk/<my_company>/test-python.py: Command not found.

     

    How can I execute my script? How can I debug the reason that produces this error? Is there a way to troubleshoot this kind of errors?

     

    Thank you.


    #Python
    #junos-sdk
    #JUNOS


  • 2.  RE: Getting Python Junos SDK example working
    Best Answer

    Posted 07-01-2014 03:42

    I found the error. In the documentation, the example Python script is:

     

    #! /opt/bin/python
    print "Python test: Hello world!"

    But in my Juniper MX 480 router, python binary is located in /usr/bin/python. Then script should be:

     

    #! /usr/bin/python
    print "Python test: Hello world!"

    I reinstalled the bundle with this change and it worked in the router.

     

    Junos SDK documentation is plenty of this kind of small errors. It makes the development process a nightmare and sometimes one feel like an idiot because there is no progress during learning process. I desire you, Juniper, improve documentation to make easier developers life.

     

    PD: Other mistakes in this page:

     

    1) In "Preparing the Sandbox" section, the instructions to create Makefile are:

    # Note we are positioned at /home/user/sandboxes/test-python/src
    $ mkdir -p package-scripts/test-python
    $ echo ".include ../Makefile.inc" > package-scripts/test-python/Makefile

    but hits period (".") should be removed and the result should be:

     

    # Note we are positioned at /home/user/sandboxes/test-python/src
    $ mkdir -p package-scripts/test-python
    $ echo "include ../Makefile.inc" > package-scripts/test-python/Makefile

    If the period is present, an error is produced during mk process:

    bmake: "/usr/home/user/sandboxes/test-python/src/package-scripts/test-python/Makefile" line 1: .include filename must be delimited by '"' or '<'

     2) In the "Creating the Package Manifest" section, there is an example of manifext file like this:

    # package_id must be a unique value from 0-31
    # role must be Provider_Application
    
    /set package_id=32 role=Provider_Application
    
    # Each script must have a unique program_id value from 0-63
    %TOPDIR%/py-scripts/test-python.py store=opt/sdk/juniper/test-python.py mode=555 program_id=1

    There are one susicious error here. It says package_id must be a unique value from 0-31, but it uses 32 as value. I don't know the consequences of this value, but I used a valid value in the range and it worked.

     

    3) In the previous file, it is important to notice that store flag (store=opt/sdk/juniper/test-python.py) must point to local company used to generate certificate, something like this: store=opt/sdk/<my_company>/test-python.py. If it is not the case, an error will be produced during mk process:

     

    ERROR: makeiso: test-python.py should be stored under 'opt/sdk/<my_company>' sub-directory

    I consider there are too many errors in documentation and the user of it will be stucked during the learning process if he could not guess how to solve them.

     

    Hope it could help other users.