Move salt-monitor scripts and packaging to salt-monitor project

This commit is contained in:
Erik Nolte 2011-08-10 11:20:33 -06:00
parent b8122f4113
commit 86213377df
9 changed files with 29 additions and 384 deletions

View file

@ -1,9 +1,11 @@
# Convenience targets for building and installing Arch packages
# prior to committing changes to git.
PKGNAME=salt
local:
-rm -rf ../../build
-rm salt-*.pkg.tar.xz
-rm $(PKGNAME)-*.pkg.tar.xz
-rm -rf pkg
if [ "$$(id -u)" -eq 0 ]; \
then \
@ -15,11 +17,9 @@ local:
-rm -rf ../../build
install: local
-/etc/rc.d/salt-monitor stop
-/etc/rc.d/salt-minion stop
-/etc/rc.d/salt-master stop
-yes | pacman -R salt-local
-yes | pacman -R salt-git
-yes | pacman -R salt
yes | pacman -U salt-local-*
-for script in /etc/rc.d/salt*; \
do \
"$$script" stop; \
done
-yes | pacman -R $(PKGNAME)
yes | pacman -U $(PKGNAME)-*.pkg.tar.xz

12
pkg/arch/PKGBUILD Normal file → Executable file
View file

@ -13,18 +13,15 @@ depends=('python2'
'python2-yaml'
'pycrypto')
backup=('etc/salt/master'
'etc/salt/minion'
'etc/salt/monitor')
'etc/salt/minion')
makedepends=()
optdepends=()
options=()
source=("https://github.com/downloads/thatch45/salt/$pkgname-$pkgver.tar.gz"
"salt-master"
"salt-minion"
"salt-monitor")
"salt-minion")
md5sums=('26456860e89f53deaf75193da50b449a'
'4baf45d1610d771b742de2cbd8951b9f'
'11bc2e9042a5764e029fefbe49dddcc7')
'4baf45d1610d771b742de2cbd8951b9f')
package() {
cd $srcdir/$pkgname-$pkgver
@ -32,6 +29,7 @@ package() {
python2 setup.py install --root=$pkgdir/ --optimize=1
mkdir -p $pkgdir/etc/rc.d/
cp $srcdir/salt-m* $pkgdir/etc/rc.d/
cp $srcdir/pkg/arch/salt-master $pkgdir/etc/rc.d/
cp $srcdir/pkg/arch/salt-minion $pkgdir/etc/rc.d/
chmod +x $pkgdir/etc/rc.d/*
}

16
pkg/arch/PKGBUILD-git Normal file → Executable file
View file

@ -1,6 +1,6 @@
# Maintainer: Thomas S Hatch <thatch45 at gmail dot com>
pkgname=salt-git
pkgver=20110727
pkgname=salt
pkgver=$(date +%Y%m%d)
pkgrel=1
pkgdesc="A remote execution and communication system built on zeromq"
arch=('any')
@ -15,15 +15,12 @@ depends=('python2'
makedepends=('git')
provides=()
backup=('etc/salt/master'
'etc/salt/minion'
'etc/salt/monitor')
'etc/salt/minion')
options=()
source=("salt-master"
"salt-minion"
"salt-monitor")
"salt-minion")
md5sums=('1594591acb0a266854186a694da21103'
'21ab2eac231e9f61bf002ba5f16f8a3d'
'c435daa3b553a6425b48a8abed11b863')
'21ab2eac231e9f61bf002ba5f16f8a3d')
_gitroot="git://github.com/thatch45/salt.git"
_gitname="salt"
@ -53,6 +50,7 @@ package() {
python2 setup.py install --root=$pkgdir/ --optimize=1
mkdir -p $pkgdir/etc/rc.d/
cp $srcdir/salt-m* $pkgdir/etc/rc.d/
cp $srcdir/pkg/arch/salt-master $pkgdir/etc/rc.d/
cp $srcdir/pkg/arch/salt-minion $pkgdir/etc/rc.d/
chmod +x $pkgdir/etc/rc.d/*
}

View file

@ -1,7 +1,7 @@
# Maintainer: Thomas S Hatch <thatch45 at gmail dot com>
# Build the salt package from local files.
# Use this to test Arch installation before committing changes.
pkgname=salt-local
pkgname=salt
pkgver=$(date +%Y%m%d)
pkgrel=1
pkgdesc="A remote execution and communication system built on zeromq"
@ -28,6 +28,7 @@ package() {
python2 setup.py install --root=$pkgdir/ --optimize=1
mkdir -p $pkgdir/etc/rc.d/
cp $srcdir/pkg/arch/salt-m* $pkgdir/etc/rc.d/
cp $srcdir/pkg/arch/salt-master $pkgdir/etc/rc.d/
cp $srcdir/pkg/arch/salt-minion $pkgdir/etc/rc.d/
chmod +x $pkgdir/etc/rc.d/*
}

View file

@ -1,63 +0,0 @@
#!/bin/bash
daemon_name='salt-monitor'
. /etc/rc.conf
. /etc/rc.d/functions
[ -f /etc/conf.d/$daemon_name ] && . /etc/conf.d/$daemon_name
get_pid() {
ps aux | grep -v grep | grep '/usr/bin/python2 /usr/bin/salt-monitor' | awk '{print $2}'
}
case "$1" in
start)
stat_busy "Starting Salt Monitor"
PID=$(get_pid)
if [ -z "$PID" ]; then
[ -f /var/run/$daemon_name.pid ] && rm -f /var/run/$daemon_name.pid
# RUN
/usr/bin/$daemon_name -d
#
if [ $? -gt 0 ]; then
stat_fail
exit 1
else
echo $(get_pid) > /var/run/$daemon_name.pid
add_daemon $daemon_name
stat_done
fi
else
stat_fail
exit 1
fi
;;
stop)
stat_busy "Stopping Salt Monitor"
PID=$(get_pid)
# KILL
[ ! -z "$PID" ] && kill $PID &> /dev/null
#
if [ $? -gt 0 ]; then
stat_fail
exit 1
else
rm -f /var/run/$daemon_name.pid &> /dev/null
rm_daemon $daemon_name
stat_done
fi
;;
restart)
$0 stop
sleep 1
$0 start
;;
*)
echo "usage: $0 {start|stop|restart|status}"
esac
exit 0

View file

@ -1,21 +0,0 @@
#!/usr/bin/python2
'''
This script is used to kick off a salt monitor
'''
import salt
import os
def main():
'''
The main function
'''
pid = os.getpid()
try:
monitor = salt.Monitor()
monitor.start()
except KeyboardInterrupt:
os.kill(pid, 15)
if __name__ == '__main__':
main()

View file

@ -4,7 +4,6 @@ The setup script for salt
'''
import os
import sys
import unittest
from distutils import log
from distutils.cmd import Command
from distutils.core import setup
@ -25,51 +24,6 @@ if os.environ.has_key('SYSCONFDIR'):
else:
etc_path = os.path.join(os.path.dirname(PREFIX), 'etc')
class UnitTest(Command):
description = "run unit tests"
user_options = []
def initialize_options(self):
self.test_dirs = None
def finalize_options(self):
if self.test_dirs is None:
self.test_dirs = ["test"]
def run(self):
errors = 0
failures = 0
for path in self.test_dirs:
for root, dirs, files in os.walk(path):
for filename in files:
if filename.startswith("test_") and \
filename.endswith(".py"):
results = self._run_test(os.path.join(root, filename))
errors += results[0]
failures += results[1]
self.announce(
"unit test: {} errors and {} failures".format(errors, failures),
level=log.INFO)
def _run_test(self, path):
self.announce("run tests in " + path, log.INFO)
dirname, basename = os.path.split(path)
sys.path.insert(0, dirname)
try:
modname = os.path.splitext(basename)[0]
mod = __import__(modname)
if hasattr(mod, "test_suite"):
suite = mod.test_suite()
runner = unittest.TextTestRunner(verbosity=2)
results = runner.run(suite)
return len(results.errors), len(results.failures)
else:
return (0, 0)
finally:
if sys.path[0] == dirname:
del sys.path[0]
setup(
name=NAME,
version=VER,
@ -78,7 +32,6 @@ setup(
Extension('salt.modules.cytest', ['salt/modules/cytest.pyx']),
],
cmdclass={
'test':UnitTest,
'build_ext': build_ext,
},
description=DESC,
@ -96,23 +49,22 @@ setup(
'Intended Audience :: System Administrators',
'License :: OSI Approved :: Apache Software License',
'Operating System :: POSIX :: Linux',
'Topic :: System :: Monitoring',
'Topic :: System :: Clustering',
'Topic :: System :: Distributed Computing',
],
packages=['salt',
'salt.modules',
'salt.cli',
'salt.returners',
'salt.renderers',
'salt.runners',
'salt.ext',
'salt.grains',
'salt.modules',
'salt.renderers',
'salt.returners',
'salt.runners',
'salt.states',
'salt.utils',
],
scripts=['scripts/salt-master',
'scripts/salt-minion',
'scripts/salt-monitor',
'scripts/salt-syndic',
'scripts/salt-key',
'scripts/salt-cp',
@ -122,7 +74,6 @@ setup(
data_files=[(os.path.join(etc_path, 'salt'),
['conf/master',
'conf/minion',
'conf/monitor',
]),
('share/man/man1',
['doc/man/salt-master.1',
@ -131,7 +82,6 @@ setup(
'doc/man/salt-cp.1',
'doc/man/salt-run.1',
'doc/man/salt-minion.1',
'doc/man/salt-monitor.1',
]),
('share/man/man7',
['doc/man/salt.7',

View file

@ -1,91 +0,0 @@
#!/usr/bin/env python
import doctest
import locale
import unittest
import salt.cron
class TestTime(unittest.TestCase):
def setUp(self):
self.cron = salt.cron.CronParser()
def _test_interval(self, intime, expected):
actual = salt.cron.parse_interval(intime)
self.assertEqual(actual, expected)
def _test_parse_cron(self, intime, expected):
actual = self.cron.parse(intime)
self.assertEqual(actual, expected)
def _test_parse_group(self, unit, values, expected):
for value in values:
self._test_parse_cron({unit : value}, {unit : [expected]})
def test_doc(self):
doctest.testmod(salt.cron)
def test_interval(self):
self._test_interval({'second' : 1}, 1)
self._test_interval({'seconds' : 1}, 1)
self._test_interval({'minute' : 1}, 60)
self._test_interval({'minutes' : 1}, 60)
self._test_interval({'hour' : 1}, 60 * 60)
self._test_interval({'hours' : 1}, 60 * 60)
self._test_interval({'day' : 1}, 24 * 60 * 60)
self._test_interval({'days' : 1}, 24 * 60 * 60)
self._test_interval({'second' : 10}, 10) # 10 seconds
self._test_interval({'second' : 0.123}, 0.123)
self._test_interval({'minute' : 0.5}, 30) # 30 seconds
self._test_interval({'minute' : 5}, 300) # 5 minutes
self._test_interval({'hour' : 0.25}, 15 * 60) # 15 minutes
self._test_interval({'day' : 2,
'hour' : 3,
'minute' : 4,
'second' : 5}, 2 * 24 * 60 * 60 +
3 * 60 * 60 +
4 * 60 +
5)
def test_cron_parse_month(self):
self._test_parse_group('month', ('January', 'jan', '1'), 1)
self._test_parse_group('month', ('February', 'feb', '2'), 2)
self._test_parse_group('month', ('March', 'mar', '3'), 3)
self._test_parse_group('month', ('April', 'apr', '4'), 4)
self._test_parse_group('month', ('May', 'may', '5'), 5)
self._test_parse_group('month', ('June', 'jun', '6'), 6)
self._test_parse_group('month', ('July', 'jul', '7'), 7)
self._test_parse_group('month', ('August', 'aug', '8'), 8)
self._test_parse_group('month', ('September', 'sep', '9'), 9)
self._test_parse_group('month', ('October', 'oct', '10'), 10)
self._test_parse_group('month', ('November', 'nov', '11'), 11)
self._test_parse_group('month', ('December', 'dec', '12'), 12)
self._test_parse_cron({'month' : '*'},
{'month' : [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]})
self._test_parse_cron({'month' : '3-6,11-12'},
{'month' : [3, 4, 5, 6, 11, 12]})
self._test_parse_cron({'month' : 'mar - june, nov-DeceMbEr'},
{'month' : [3, 4, 5, 6, 11, 12]})
self._test_parse_cron({'month' : ', ,mar- june /2 nov -DeceMbEr/1,,, '},
{'month' : [3, 5, 11, 12]})
def test_cron_parse_weekday(self):
self._test_parse_group('weekday', ('Sunday', 'sun', '1'), 1)
self._test_parse_group('weekday', ('Monday', 'mon', '2'), 2)
self._test_parse_group('weekday', ('Tuesday', 'tue', '3'), 3)
self._test_parse_group('weekday', ('Wednesday', 'wed', '4'), 4)
self._test_parse_group('weekday', ('Thursday', 'thu', '5'), 5)
self._test_parse_group('weekday', ('Friday', 'fri', '6'), 6)
self._test_parse_group('weekday', ('Saturday', 'sat', '7'), 7)
self._test_parse_cron({'weekday' : '*'}, {'weekday' : [1, 2, 3, 4, 5, 6, 7]})
self._test_parse_cron({"weekday" : "monday-friday"}, {"weekday" : [2, 3, 4, 5, 6]})
self._test_parse_cron({"weekday" : "wed-sat"}, {"weekday" : [4, 5, 6, 7]})
self._test_parse_cron({"weekday" : "wed-sat/2"}, {"weekday" : [4, 6]})
def test_suite():
locale.setlocale(locale.LC_ALL, 'C')
return unittest.TestLoader().loadTestsFromName(__name__)

View file

@ -1,127 +0,0 @@
#!/usr/bin/env python
"""
Unit tests for salt/modules/monitor.py.
"""
import doctest
import unittest
import salt.log
def dummy(*args, **kwargs):
pass
class MockMonitor(object):
def __init__(self):
self.opts = {}
self.functions = {'test.echo' : dummy}
class TestMonitor(unittest.TestCase):
def setUp(self):
# Late import so logging works correctly
import salt.monitor
self.loader = salt.monitor.Loader(MockMonitor())
def _test_expand(self, intext, expected):
self.assertEqual(self.loader._expand_references(intext), expected)
def _test_call(self, intext, expected):
self.assertEqual(self.loader._expand_call(intext), expected)
def _test_conditional(self, incond, inactions, expected):
actual = self.loader._expand_conditional(incond, inactions)
self.assertEqual(actual, expected)
def test_doc(self):
doctest.testmod(salt.monitor)
def test_plain_text_passthrough(self):
self._test_expand('salt.cmd', 'salt.cmd') # passthrough
self._test_expand('sys.argv[0]', 'sys.argv[0]') # unquoted
self._test_expand('123', '123') # text
self._test_expand('abc', 'abc')
self._test_expand('abc 123', 'abc 123')
self._test_expand('3.14159265', '3.14159265')
def test_quoting(self):
self._test_expand("'123'", "'123'")
self._test_expand("'abc'", "'abc'")
self._test_expand("'abc 123'", "'abc 123'")
self._test_expand('"abc 123"', "'abc 123'")
self._test_expand("bob's stuff", "bob's stuff")
self._test_expand('say "what?"', 'say "what?"')
self._test_expand("'", "'")
self._test_expand("''", "''")
def test_escape_sequences(self):
self._test_expand('\\', '\\') # escape at end of string
self._test_expand('\\abc', '\\abc') # escape non-special char
self._test_expand('\\\\', '\\') # escape escape char
self._test_expand('\\$', '$') # escape reference
self._test_expand('\\$value', '$value') # escape reference
self._test_expand('\\${value}', '${value}') # escape reference
def test_reserved_chars(self):
self._test_expand('{}', '{}') # not formatting
self._test_expand('abc{}123', 'abc{}123') # not formatting
self._test_expand("'{$x}'", "'{{{}}}'.format(x)") # needs escape
self._test_expand("'}$x{'", "'}}{}{{'.format(x)") # needs escape
self._test_expand("'$x {}'", "'{} {{}}'.format(x)") # needs escape
def test_simple_references(self):
self._test_expand('$value', 'value') # unquoted variable
self._test_expand('${value}', 'value') # unquoted variable
self._test_expand("'$value'", 'str(value)') # just quoted variable
self._test_expand("'${value}'", 'str(value)') # just quoted variable
self._test_expand("'v=$v'", "'v={}'.format(v)") # quoted var plus text
def test_multiple_references(self):
self._test_expand('$key=$value', 'key=value') # e.g. kwargs param
self._test_expand('${key}=${value}', 'key=value') # e.g. kwargs param
self._test_expand("'$key=$value'", "'{}={}'.format(key, value)")
self._test_expand("'${key}=${value}'", "'{}={}'.format(key, value)")
self._test_expand("${value['available']}/${value['total']}",
"value['available']/value['total']")
self._test_expand("'${value['available']}/${value['total']}'",
"'{}/{}'.format(value['available'], value['total'])")
def test_expression_references(self):
self._test_expand("${value['available']<1024*1024}",
"value['available']<1024*1024")
self._test_expand("${value['available']}<1024*1024",
"value['available']<1024*1024")
def test_conditional_expansion(self):
self._test_expand("if value['available'] * 100 / value['total'] < 90:",
"if value['available'] * 100 / value['total'] < 90:")
self._test_expand("if ${value['available']} * 100 / ${value['total']} < 90:",
"if value['available'] * 100 / value['total'] < 90:")
self._test_expand("if ${value['available'] * 100} / ${value['total']} < 90:",
"if value['available'] * 100 / value['total'] < 90:")
self._test_expand("if ${value['available'] * 100 / value['total']} < 90:",
"if value['available'] * 100 / value['total'] < 90:")
def test_expand_call(self):
self._test_call("test.echo",
"_run('test.echo', [])")
self._test_call("test.echo 'hello, world'",
"_run('test.echo', ['hello, world'])")
self._test_call("test.echo '${value[\"available\"]/(1024*1024)} MB ${value[\"available\"]*100/value[\"total\"]}%'",
"_run('test.echo', ['{} MB {}%'.format(value[\"available\"]/(1024*1024), "\
"value[\"available\"]*100/value[\"total\"])])")
def test_expand_conditional(self):
self._test_conditional("${value['available']} > 100", [],
[ "if value['available'] > 100:",
" pass" ])
self._test_conditional("${value['available']} > 100 and ${value['total']} < 1000",
[ "test.echo \"${value['available']} too low\"" ],
[ "if value['available'] > 100 and value['total'] < 1000:",
" _run('test.echo', ['{} too low'.format(value['available'])])" ])
def test_suite():
salt.log.setup_console_logger("none")
return unittest.TestLoader().loadTestsFromName(__name__)