Skip to content

Commit

Permalink
Merge pull request #129 from sarcasticadmin/sa/issue-128
Browse files Browse the repository at this point in the history
[READY] issue-128 - Adding golden files for template validation on openwrt
  • Loading branch information
kylerisse authored Feb 9, 2019
2 parents d8b953f + 5e8a34d commit 2b52230
Show file tree
Hide file tree
Showing 25 changed files with 415 additions and 10 deletions.
19 changes: 19 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: 2
jobs:
test:
docker:
# Lockdown version after gomplate issue is resolved
# https://github.com/hairyhenderson/gomplate/issues/484
- image: hairyhenderson/gomplate
steps:
- checkout:
path: tests/unit/openwrt
- run:
name: openwrt golden file test
command: sh test.sh

workflows:
version: 2
build_and_test:
jobs:
- test
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ openwrt/*.img
openwrt/aplist
*.swp

# Ignore openwrt test dir
tests/unit/openwrt/tmp*

# Ignore built configuration files directory
switch-configuration/config/output

Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
# scale-network
configurations, tooling and scripts for [SCALE's](https://www.socallinuxexpo.org/) on-site expo network
configurations, tooling and scripts for [SCaLE's](https://www.socallinuxexpo.org/) on-site expo network

## Table of Contents
* [CONTRIBUTING](./CONTRIBUTING.md)
* [MAPS](./MAPS.md)
* [SWITCH CONFIG](./switch-configuration/README.md)
* [ANSIBLE](./ansible/README.md)
* [OPENWRT](./openwrt/README.md)
* [TESTING](./tests/serverspec/README.md)
* [TESTING](./tests/README.md)

## Requirements
To use this git repo you will need the following pkgs:
- git >= 1.8.2
- git-lfs
- gomplete == 2.2.0
- gomplate >= 3.2.0

### Installation
#### Gomplate
Installation of `gomplate` is a little bit tricky since it doesnt come in a `.deb`:
```bash
sudo -i
cd /usr/local/bin/
curl -O https://github.com/hairyhenderson/gomplate/releases/download/v2.2.0/gomplate_linux-amd64 -L
curl -O https://github.com/hairyhenderson/gomplate/releases/download/<version>/gomplate_linux-amd64 -L
mv gomplate_linux-amd64 gomplate
```

## Contributing
SCALE happens once a year but the team has ongoing projects and prep year round.
SCaLE happens once a year but the team has ongoing projects and prep year round.
If you are interesting in volunteering please request to join our mailing list:
https://lists.linuxfests.org/cgi-bin/mailman/listinfo/tech
1 change: 1 addition & 0 deletions facts/secrets/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*
*/
!.gitignore
!*-example.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
root_hash: "$dfjakls$1md5crypthashofpassword"
# scale
root_hash: "$1$zh0PjBbB$f9aFGDX9vNYNdSRexhib8/"

rsyslog:
server: 'server2.scale.lan'
Expand All @@ -21,7 +22,7 @@ wired:
networks:
# interface names cant have special characters
- name: 'mgmt'
ifname: 'eth1.103 eth1.503'
ifname: 'eth1'
type: 'bridge'
proto: 'dhcp'
- name: 'mgmt6'
Expand Down
4 changes: 2 additions & 2 deletions openwrt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Make sure you have the prereq pkgs for the [LEDE Image Builder](https://openwrt.org/docs/guide-user/additional-software/imagebuilder)

If you are building images with templates you'll also need:
* gomplate 2.2.0: https://github.com/hairyhenderson/gomplate/releases/tag/v2.2.0
* [gomplate](../README.md#requirements)

# Build
## Stock Image
Expand All @@ -28,7 +28,7 @@ the image.

Copy over the default secrets:
```bash
cp ./facts/secrets/openwrt.yaml.example ./facts/secrets/openwrt.yaml
cp ./facts/secrets/openwrt-example.yaml ./facts/secrets/openwrt.yaml
```
> If needed update the defaults in `openwrt.yaml` to represent actual values
Expand Down
2 changes: 2 additions & 0 deletions openwrt/files/.gomplateignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.gomplateignore
*.sw*
2 changes: 1 addition & 1 deletion openwrt/files/etc/config/network
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ config switch
option blinkrate '2'
{{ end }}

{{ range $index, $element := (datasource "openwrt").wired.networks }}
{{ range (datasource "openwrt").wired.networks }}
config interface '{{.name}}'
{{ range $key, $value := . -}}
{{ if (ne $key "name") -}}
Expand Down
6 changes: 6 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Tests

## Table of Contents

* [SERVERSPEC](./serverspec/README.md)
* [OPENWRT UNITTEST](./unit/openwrt/README.md)
20 changes: 20 additions & 0 deletions tests/unit/openwrt/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Openwrt Goldens

## Usage

To test the template output from whats generated using gomplate. If does this by `diff`ing
a known good generated set of files found in `./golden` with generated files in `./tmp`.

Just run:

```
sh test.sh
```

If it returns a diff then the goldens dont match the current output. If this is intended
due to other code changes then you can run the same script with `-u` to update the goldens.

```
sh test.sh -u
```
> **NOTE:** This all needs to be done from the scripts current directory
59 changes: 59 additions & 0 deletions tests/unit/openwrt/golden/etc/apinger.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
## Following "macros" may be used in options below:
## %t - target name (address)
## %T - target description
## %a - alarm name
## %A - alarm type ("down"/"loss"/"delay")
## %r - reason of message ("ALARM"/"alarm canceled"/"alarm canceled (config reload)")
## %p - probes send
## %P - probes received
## %l - recent average packet loss
## %d - recent average delay
## %s - current timestamp
## %% - '%' character

## User and group the pinger should run as
# Needs to be root for interacting with wifi
user "root"
group "nogroup"

## Location of the pid-file (default: "/var/run/apinger.pid")
#pid_file "/var/run/apinger.pid"

status {
## File where the status information whould be written to
file "/tmp/apinger.status"
## Interval between file updates
## when 0 or not set, file is written only when SIGUSR1 is received
interval 10s
}

## Target defaults that are inheretted by each target
## and can be overwritten
target default {
## How often the probe should be sent
interval 2s

## How many replies should be used to compute average delay
## for controlling "delay" alarms
avg_delay_samples 10

## How many probes should be used to compute average loss
avg_loss_samples 50
## The delay (in samples) after which loss is computed
## without this delays larger than interval would be treated as loss
avg_loss_delay_samples 20
}

alarm down "wifi" {
time 10s
## Turn off network
command on "/usr/bin/logger -t apinger %t %a: %r && wifi down"
## Turn on network
command off "/usr/bin/logger -t apinger %t %a: %r && wifi up"
combine 10s
}

target "8.8.8.8" {
description "endpoint validation"
alarms override "wifi"
}
61 changes: 61 additions & 0 deletions tests/unit/openwrt/golden/etc/config/network
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
config interface 'loopback'
option ifname 'lo'
option proto 'static'
option ipaddr '127.0.0.1'
option netmask '255.0.0.0'

config globals 'globals'
option ula_prefix 'fdfa:7251:0374::/48'


config switch
option name 'switch0'
option reset '1'
option enable_vlan '1'
option enable_vlan4k '1'
option blinkrate '2'



config interface 'mgmt'
option ifname 'eth1'
option proto 'dhcp'
option type 'bridge'

config interface 'mgmt6'
option ifname '@mgmt'
option proto 'dhcpv6'
option reqprefix 'no'

config interface 'staffwifi'
option ifname 'eth1.108 eth1.508'
option proto 'none'
option type 'bridge'

config interface 'scaleslow'
option ifname 'eth1.100 eth1.500'
option proto 'none'
option type 'bridge'

config interface 'scalefast'
option ifname 'eth1.101 eth1.501'
option proto 'none'
option type 'bridge'



config switch_port
option device 'switch0'
option port '1'
option led '6'

config switch_port
option device 'switch0'
option port '2'
option led '9'

config switch_port
option device 'switch0'
option port '5'
option led '2'

57 changes: 57 additions & 0 deletions tests/unit/openwrt/golden/etc/config/wireless
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@

config wifi-device 'radio0'
option type 'mac80211'
option hwmode '11g'
option path 'pci0000:00/0000:00:11.0'
option htmode 'HT20'
option channel '11'
option txpower '8'
option country 'US'

config wifi-device 'radio1'
option type 'mac80211'
option hwmode '11a'
option path 'pci0000:00/0000:00:12.0'
option htmode 'HT20'
option channel '36'
option txpower '8'
option country 'US'



config wifi-iface 'scaleslow_radio0'
option device 'radio0'
option ssid 'scale-public-slow'
option mode 'ap'
option network 'scaleslow'
option encryption 'psk2'
option key 'tuxlinux'
option disabled '0'

config wifi-iface 'staffwifi_radio0'
option device 'radio0'
option ssid 'scale-staff-24'
option mode 'ap'
option network 'staffwifi'
option encryption 'psk2'
option key 'testpassword'
option disabled '0'

config wifi-iface 'scalefast_radio1'
option device 'radio1'
option ssid 'scale-public-fast'
option mode 'ap'
option network 'scalefast'
option encryption 'psk2'
option key 'tuxlinux'
option disabled '0'

config wifi-iface 'staffwifi_radio1'
option device 'radio1'
option ssid 'scale-staff-5'
option mode 'ap'
option network 'staffwifi'
option encryption 'psk2'
option key 'testpassword'
option disabled '0'

1 change: 1 addition & 0 deletions tests/unit/openwrt/golden/etc/crontabs/root
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0 * * * * /usr/sbin/logrotate -f /etc/logrotate.conf -s /tmp/logrotate.status
18 changes: 18 additions & 0 deletions tests/unit/openwrt/golden/etc/logrotate.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# rotate log files daily
daily

# keep 2 days worth of backlogs
rotate 2

# create new (empty) log files after rotating old ones
create

notifempty
nomail
missingok

# uncomment this if you want your log files compressed
compress

# packages can drop log rotation information into this directory
include /etc/logrotate.d
7 changes: 7 additions & 0 deletions tests/unit/openwrt/golden/etc/logrotate.d/rsyslog
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/var/log/messages {
missingok
notifempty
compress
size 500k
copytruncate
}
9 changes: 9 additions & 0 deletions tests/unit/openwrt/golden/etc/passwd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root:x:0:0:root:/root:/bin/ash
daemon:*:1:1:daemon:/var:/bin/false
ftp:*:55:55:ftp:/home/ftp:/bin/false
network:*:101:101:network:/var:/bin/false
nobody:*:65534:65534:nobody:/var:/bin/false
dnsmasq:x:453:453:dnsmasq:/var/run/dnsmasq:/bin/false
sshd:x:22:22:sshd:/var/run/sshd:/bin/false
zabbix:x:53:53:zabbix:/var/run/zabbix:/bin/false
lldp:x:121:129:lldp:/var/run/lldp:/bin/false
7 changes: 7 additions & 0 deletions tests/unit/openwrt/golden/etc/rc.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.

# TODO make this a true service
/root/bin/wifi-details.sh &

exit 0
1 change: 1 addition & 0 deletions tests/unit/openwrt/golden/etc/resolv.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nameserver 8.8.8.8
20 changes: 20 additions & 0 deletions tests/unit/openwrt/golden/etc/rsyslog.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module(load="imuxsock")
module(load="imklog")
module(load="imudp")
#input(type="imudp" port="514")
#module(load="imtcp")
#input(type="imtcp" port="514")

$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat

*.info;mail.none;authpriv.none;cron.none /var/log/messages

authpriv.* /var/log/secure

mail.* /var/log/maillog

cron.* /var/log/cron

local7.* /var/log/boot.log

*.* action(type="omfwd" target="server2.scale.lan" port="514" protocol="udp")
Loading

0 comments on commit 2b52230

Please sign in to comment.