Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request qca#2 from ericschultz/local_work
Browse files Browse the repository at this point in the history
Update to latest running code
  • Loading branch information
wwahammy committed May 25, 2016
2 parents ee59516 + b8990ee commit 0c3b295
Show file tree
Hide file tree
Showing 17 changed files with 608 additions and 22 deletions.
12 changes: 6 additions & 6 deletions bft
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def main():
import devices
from termcolor import colored
from library import print_bold
from devices import board_decider, debian, logstash, elasticlogger
from devices import board_decider, debian_decider, logstash, elasticlogger

# Connect to any board in list
connected_to_board = False
Expand Down Expand Up @@ -69,29 +69,29 @@ def main():
config.wlan2g = None

if config.board.get('wan_device'):
config.wan = debian.DebianBox(config.board.get('wan_device'),
config.wan = debian_decider.debian(config.board.get('wan_device'),
color='cyan', reboot=config.reboot_vms,
location=config.board.get('location'),
username=config.board.get('wan_username', "root"),
password=config.board.get('wan_password', "bigfoot1"),
port=config.board.get('wan_port', "22"))
if config.board.get('lan_device'):
config.lan = debian.DebianBox(config.board.get('lan_device'), color='blue', reboot=config.reboot_vms,
config.lan = debian_decider.debian(config.board.get('lan_device'), color='blue', reboot=config.reboot_vms,
username=config.board.get('lan_username', "root"),
password=config.board.get('lan_password', "bigfoot1"),
port=config.board.get('lan_port', "22"))
if config.board.get('wlan_device'):
config.wlan = debian.DebianBox(config.board.get('wlan_device'), color='green', reboot=config.reboot_vms,
config.wlan = debian_decider.debian(config.board.get('wlan_device'), color='green', reboot=config.reboot_vms,
username=config.board.get('wlan_username', "root"),
password=config.board.get('wlan_password', "bigfoot1"),
port=config.board.get('wlan_port', "22"))
if config.board.get('5g_device'):
config.wlan5g = debian.DebianBox(config.board.get('5g_device'), color='grey', reboot=config.reboot_vms,
config.wlan5g = debian_decider.debian(config.board.get('5g_device'), color='grey', reboot=config.reboot_vms,
username=config.board.get('5g_username', "root"),
password=config.board.get('5g_password', "bigfoot1"),
port=config.board.get('5g_port', "22"))
if config.board.get('2g_device'):
config.wlan2g = debian.DebianBox(config.board.get('2g_device'), color='magenta', reboot=config.reboot_vms,
config.wlan2g = debian_decider.debian(config.board.get('2g_device'), color='magenta', reboot=config.reboot_vms,
username=config.board.get('2g_username', "root"),
password=config.board.get('2g_password', "bigfoot1"),
port=config.board.get('2g_port', "22"))
Expand Down
15 changes: 15 additions & 0 deletions bin/ip_neigh_flush
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
set -x

SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
DIR="$( cd -P "$DIR/../devices" && pwd )"

python $DIR/local_debian_runner.py ip_neigh_flush 1>&2 | tee /tmp/ip_neigh_flush.log

exit 0
15 changes: 15 additions & 0 deletions bin/restart_tftp_server
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
set -x

SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
DIR="$( cd -P "$DIR/../devices" && pwd )"

python $DIR/local_debian_runner.py restart_tftp_server 1>&2 | tee /tmp/restart_tftp_server.log

exit 0
14 changes: 14 additions & 0 deletions bin/setup_lan
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
set -x

SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
DIR="$( cd -P "$DIR/../devices" && pwd )"

python $DIR/local_debian_runner.py init_lan 2>&1 | tee /tmp/setup_lan.log
exit 0
14 changes: 14 additions & 0 deletions bin/setup_wan
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
set -x

SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
DIR="$( cd -P "$DIR/../devices" && pwd )"

python $DIR/local_debian_runner.py init_wan 2>&1 | tee /tmp/setup_wan.log
exit 0
15 changes: 15 additions & 0 deletions bin/start_lan_client
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
set -x

SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
DIR="$( cd -P "$DIR/../devices" && pwd )"

python $DIR/local_debian_runner.py start_lan_client 1>&2 | tee /tmp/start_lan_client

exit 0
21 changes: 14 additions & 7 deletions boardfarm_config_example.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
{
"board01": {
"board_type": "apXYZ",
"conn_cmd": "telnet consoleserver.mysite.com 6001",
"lan_device": "machine01",
"board_type": "db120",
"conn_cmd": "cu -l /dev/ttyUSB0 -s 115200",
"lan_device": "rpi3",
"location": "austin",
"powerip": "pdu.mysite.com",
"powerport": "8",
"wan_device": "machine02",
"notes": "Old board"
"powerip": "10.0.2.230",
"powerport": "1",
"power_username": "outlet1",
"power_password": "test",
"wan_device": "rpi2",
"notes": "Old board",
"connection_type": "local_serial",
"lan_username": "tester",
"lan_password": "test",
"wan_password": "test",
"wan_username": "tester"
},
"board02": {
"board_type": "apXYZ",
Expand Down
1 change: 1 addition & 0 deletions conf/boardfarm_cron
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*/10 * * * * root systemctl start dhclient.eth0
10 changes: 10 additions & 0 deletions conf/dhclient.eth0.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Unit]
Description=dhclient on eth0
Wants=network.target
Before=network.target

[Service]
ExecStart=/sbin/dhclient -d -v eth0

[Install]
WantedBy=multi-user.target
10 changes: 10 additions & 0 deletions conf/lan_setup.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Unit]
Description=Startup Script for non-root Boardfarm LAN setup
After=network.target

[Service]
ExecStart=/usr/bin/setup_lan
Type=forking

[Install]
WantedBy=multi-user.target
2 changes: 2 additions & 0 deletions conf/testing_sudoers
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Cmnd_Alias TESTING_CMDS = /sbin/reboot, /usr/bin/start_lan_client, /usr/bin/ip_neigh_flush, /usr/bin/turn_on_pppoe, /usr/bin/restart_tftp_server, /usr/bin/stop_lan_client
__username__ ALL=(ALL) NOPASSWD: TESTING_CMDS
10 changes: 10 additions & 0 deletions conf/wan_setup.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Unit]
Description=Startup Script for non-root Boardfarm WAN setup
After=network.target

[Service]
ExecStart=/usr/bin/setup_wan
Type=forking

[Install]
WantedBy=multi-user.target
23 changes: 23 additions & 0 deletions devices/debian_decider.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import debian
import non_root_debian
import sys

def debian(name, color,
username,
password,
port,
output=sys.stdout,
reboot=False,
location=None):
'''
This function controls which class to use for your debian boxes: DebianBox
when your username is root and NotRootDebianBox for other usernames.
'''
if (username is 'root'):
return debian.DebianBox(name=name, color=color, username=username,
password=password, port=port, output=output,
reboot=reboot, location=location)
else:
return non_root_debian.NonRootDebianBox(name=name, color=color, username=username,
password=password, port=port, output=output,
reboot=reboot, location=location)
74 changes: 74 additions & 0 deletions devices/local_debian_runner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import base
import pexpect
import debian
import sys
import argparse
from termcolor import colored, cprint

class LocalDebianRunner(debian.DebianBox):
prompt = ['root\\@.*:.*#', '/ # ', ".*:~ #", ".*:~.*\\$", ".*\\@.*:.*\\$" ]

def __init__(self,
color,
output=sys.stdout,
reboot=False,
location=None
):

pexpect.spawn.__init__(self,
command="bash")

self.color = color
self.output = output
self.location = location
cprint("%s device console = %s" % ("local device", colored(color, color)), None, attrs=['bold'])
self.expect(self.prompt)

if reboot:
self.reset()

self.logfile_read = output

def setup_as_wan_gateway(self):
debian.DebianBox.setup_as_wan_gateway(self)
def setup_as_lan_device(self):
debian.DebianBox.setup_as_lan_device(self)
def start_lan_client(self):
debian.DebianBox.start_lan_client(self)

def restart_tftp_server(self):
debian.DebianBox.restart_tftp_server(self)

def turn_on_pppoe(self):
debian.DebianBox.turn_on_pppoe(self)
def ip_neigh_flush(self):
debian.DebianBox.ip_neigh_flush(self)

def stop_lan_client(self):
debian.DebianBox.stop_lan_client(self)


if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("action", choices=['init_wan', 'init_lan', 'start_lan_client',
'restart_tftp_server', 'turn_on_pppoe', 'ip_neigh_flush', 'stop_lan_client'])

args = parser.parse_args()
dev = LocalDebianRunner('cyan')

if args.action == "init_wan":
dev.setup_as_wan_gateway()
elif args.action == 'init_lan':
dev.setup_as_lan_device()
elif args.action == 'start_lan_client':
dev.start_lan_client()
elif args.action == 'restart_tftp_server':
dev.restart_tftp_server()
elif args.action == 'ip_neigh_flush':
dev.ip_neigh_flush()
elif args.action == 'turn_on_pppoe':
dev.turn_on_pppoe()
elif args.action == 'stop_lan_client':
dev.stop_lan_client()
else:
parser.print_help()
Loading

0 comments on commit 0c3b295

Please sign in to comment.