Skip to content

Commit

Permalink
requirements.txt and .travis.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
Michio Honda committed Nov 3, 2020
1 parent 33e6e55 commit 076d41c
Show file tree
Hide file tree
Showing 8 changed files with 289 additions and 108 deletions.
17 changes: 17 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
language: python
python:
- "3.8"
install:
- pip install -r requirements.txt
- mkdir -p test_tftpboot/pxelinux.cfg
- mkdir -p test_tftpboot/loaders/base
- touch test_tftpboot/loaders/base/n01
- touch test_tftpboot/loaders/base/n02
- touch test_tftpboot/loaders/base/n03
- mkdir test_tftpboot/loaders/`whoami`
- touch test_tftpboot/loaders/`whoami`/n01
- touch test_tftpboot/loaders/`whoami`/n02
- touch test_tftpboot/loaders/`whoami`/n03
- touch test_tmdb.json
script:
- pytest tests
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# tm - testbed manager
[![Build Status](https://travis-ci.org/micchie/tm.svg?branch=master)](https://travis-ci.org/micchie/tm)
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
python-ipmi
pandas
tinydb
pathlib
Empty file added tests/__init__.py
Empty file.
59 changes: 59 additions & 0 deletions tests/test_all.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
from tm import Tm
import shlex
from re import search
from datetime import datetime, timedelta

n01 = 'tm inventory add --mac 00:00:00:00:12:36 --ip=192.168.0.14 --ipmiaddr 192.168.0.114 --ipmipass root,root --cpu "E3-1220v2" --ram 16 --nic "x520-DA2" n01'
n02 = 'tm inventory add --mac 00:00:00:00:12:37 --ip=192.168.0.15 --ipmiaddr 192.168.0.115 --ipmipass root,root --cpu "E3-1220v2" --ram 8 --nic "x520-DA2" n02'
n03 = 'tm inventory add --mac 00:00:00:00:12:38 --ip=192.168.0.16 --ipmiaddr 192.168.0.116 --ipmipass root,root --cpu "E3-1220v2" --ram 4 --nic "N/A" n03'
addnodes = [n01, n02, n03]

dbf = './test_tmdb.json'
tfb = './test_tftpboot'

ret_rsv_date_past = 'date must be on or later than today'
ret_rsv_in_use = 'node in use'
ret_rsv_success = 'reserve successful'
ret_rsv_update_success = 'update successful'
ret_rsv_release_success = 'release successful'

def test_all():
out = Tm(shlex.split('tm inventory show'), dbfile=dbf, tftpboot=tfb).output
assert search('no db entry', out)

for a in addnodes:
out = Tm(shlex.split(a), dbfile=dbf, tftpboot=tfb).output
assert search('success', out)
out = Tm(shlex.split('tm inventory show --addr --devices'), dbfile=dbf, tftpboot=tfb).output
for n in ['n01', 'n02', 'n03']:
assert n in out['node'].values
for i in ['mac', 'ip', 'ipmiaddr', 'ipmipass', 'cpu', 'ram']:
assert len(out[i].values) == 3

now = datetime.now().date()
nowm1 = now + timedelta(days=-1)
nowm1_s = datetime.strftime(nowm1, '%d/%m/%y')
nowp1 = now + timedelta(days=1)
nowp1_s = datetime.strftime(nowp1, '%d/%m/%y')
nowp10 = now + timedelta(days=10)
nowp10_s = datetime.strftime(nowp10, '%d/%m/%y')

out = Tm(shlex.split('tm reservation reserve n01 {}'.format(nowm1_s)),
dbfile=dbf, tftpboot=tfb).output
assert search(ret_rsv_date_past, out)

out = Tm(shlex.split('tm reservation reserve n01 {}'.format(nowp1_s)),
dbfile=dbf, tftpboot=tfb).output
assert search(ret_rsv_success, out)

out = Tm(shlex.split('tm reservation reserve n01 {}'.format(nowm1_s)),
dbfile=dbf, tftpboot=tfb).output
assert search(ret_rsv_in_use, out)

out = Tm(shlex.split('tm reservation update n01 {}'.format(nowp10_s)),
dbfile=dbf, tftpboot=tfb).output
assert search(ret_rsv_update_success, out)

out = Tm(shlex.split('tm reservation release n01'),
dbfile=dbf, tftpboot=tfb).output
assert search(ret_rsv_release_success, out)
19 changes: 19 additions & 0 deletions tm-cleanup.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[Unit]
Description=Clean up tm reservations expired
ConditionACPower=true

[Service]
Type=oneshot
ExecStart=/usr/local/bin/tm reservation clean
User=root
ProtectSystem=strict
ReadWritePaths=/usr/local/tm
Nice=19
IOSchedulingClass=best-effort
IOSchedulingPriority=7
ProtectControlGroups=true
ProtectKernelModules=true
RestrictRealtime=true

[Install]
WantedBy=multi-user.target
10 changes: 10 additions & 0 deletions tm-cleanup.timer
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Unit]
Description=Daily tm cleanup of expired reservations

[Timer]
OnCalendar=daily
AccuracySec=1h
Persistent=true

[Install]
WantedBy=timers.target
Loading

0 comments on commit 076d41c

Please sign in to comment.