Junos
Junos

Getting Python Junos SDK example working

‎07-01-2014 02:50 AM

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.

1 REPLY 1
Junos
Solution
Accepted by topic author logoff
‎08-26-2015 01:27 AM

Re: Getting Python Junos SDK example working

[ Edited ]
‎07-01-2014 03:42 AM

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.