Commit 7fe949f4 authored by Theodor-Adrian Stana's avatar Theodor-Adrian Stana

sw: Changed rename phase in PTS software build

The rename phase (which was previously sed-based) has now been changed to change
the ELMA IP/hostname in the men-on, men-off and get-fan-speeds scripts.
Previously, I had omitted these three scripts and the IP and hostname were
hard-coded.

This has now been changed by environment variables, which "incidentally" have
the same way of definition in shell script as template strings under Python.
Therefore, this nice similarity between Python and shell script was used to
create a Python script that does the renaming where needed.

The renaming is done as follows:
- ptsdefine.py, via three template strings that are replaced by the `rename'
  script
- men-on/men-off/get-fan-speeds, via three template strings that double as
  environment variables; this doubling can be used in the future, should it be
  needed

When you run `make', the `rename' script is called with the necessary params
by the Makefile (assuming you give the Makefile variables -- otherwise the
`rename' script fails, telling you why) and it handles the renaming in all the
places above.
parent 73be1c35
BOARD = T485
ELMAIP =
ELMAPWD =
ELMASLOT =
......@@ -11,9 +12,7 @@ all:
mkdir -p ubuntu/t485/pyts/
cp python/* ubuntu/t485/pyts/
sed -i "s/ELMAIP = \"\"/ELMAIP = \"$(ELMAIP)\"/" ubuntu/t485/pyts/ptsdefine.py
sed -i "s/ELMAPWD = \"\"/ELMAPWD = \"$(ELMAPWD)\"/" ubuntu/t485/pyts/ptsdefine.py
sed -i "s/ELMASLOT =/ELMASLOT = $(ELMASLOT)/" ubuntu/t485/pyts/ptsdefine.py
./rename $(BOARD) $(ELMAIP) $(ELMAPWD) $(ELMASLOT)
cp ubuntu/t485/pyts/pts.py ubuntu/t485/pts
cp ubuntu/t485/pyts/jpts.py ubuntu/t485/jpts
......
......@@ -39,10 +39,12 @@
# TODO: -
#===============================================================================
import os
# ELMA crate definitions
ELMAIP = ""
ELMAPWD = ""
ELMASLOT =
ELMAIP = "$ELMAIP"
ELMAPWD = "$ELMAPWD"
ELMASLOT = $ELMASLOT
# Board ID register
BIDR = 0x000
......
#!/usr/bin/python
import sys
from subprocess import *
from string import Template
sys.argv[1] = sys.argv[1].lower()
try:
with open("ubuntu/%s/pyts/ptsdefine.py" % (sys.argv[1]), "r+") as f:
buf = f.read()
buf = Template(buf)
buf = buf.substitute(ELMAIP=sys.argv[2], ELMAPWD=sys.argv[3], ELMASLOT=sys.argv[4])
f.seek(0)
f.write(buf)
with open("ubuntu/%s/shell/get-fan-speeds" % (sys.argv[1]), "r+") as f:
buf = f.read()
buf = Template(buf)
buf = buf.substitute(ELMAIP=sys.argv[2], ELMAPWD=sys.argv[3])
f.seek(0)
f.write(buf)
with open("ubuntu/%s/shell/men-on" % (sys.argv[1]), "r+") as f:
buf = f.read()
buf = Template(buf)
buf = buf.substitute(ELMAIP=sys.argv[2], ELMAPWD=sys.argv[3])
f.seek(0)
f.write(buf)
with open("ubuntu/%s/shell/men-off" % (sys.argv[1]), "r+") as f:
buf = f.read()
buf = Template(buf)
buf = buf.substitute(ELMAIP=sys.argv[2], ELMAPWD=sys.argv[3])
f.seek(0)
f.write(buf)
except IndexError:
print("ERROR: Are you sure you give all the makefile variables as input?")
raise
#!/bin/bash
echo Get ELMA fan speeds and store them in log/fan-speeds
rm -f ../log/fan-speeds
snmpwalk -v2c -c Gr@nBr@st0 cfvm-864-celma1 1.3.6.1.4.1.37968.1.1.5.2.1.3 > ../log/fan-speeds
snmpwalk -v2c -c $ELMAPWD $ELMAIP 1.3.6.1.4.1.37968.1.1.5.2.1.3 > ../log/fan-speeds
#!/bin/bash
echo Power OFF ELMA crate
snmpset -v2c -c Gr@nBr@st0 cfvm-864-celma1 1.3.6.1.4.1.37968.1.1.7.2.1.3.1 i 1
snmpset -v2c -c $ELMAPWD $ELMAIP 1.3.6.1.4.1.37968.1.1.7.2.1.3.1 i 1
#!/bin/bash
echo Power ON ELMA crate
snmpset -v2c -c Gr@nBr@st0 cfvm-864-celma1 1.3.6.1.4.1.37968.1.1.7.2.1.3.1 i 0
snmpset -v2c -c $ELMAPWD $ELMAIP 1.3.6.1.4.1.37968.1.1.7.2.1.3.1 i 0
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment