diff --git a/packstack/modules/ospluginutils.py b/packstack/modules/ospluginutils.py index 5109eb71a..164e95cf0 100644 --- a/packstack/modules/ospluginutils.py +++ b/packstack/modules/ospluginutils.py @@ -102,8 +102,12 @@ def isErrorException(line): return False -_re_errorline = re.compile('err: | Syntax error at|^Duplicate definition:|^Parameter name failed:') _re_color = re.compile('\x1b.*?\d\dm') +_re_errorline = re.compile('err: | Syntax error at|^Duplicate definition:|' + '^Parameter name failed:|' + '^No matching value for selector param') + + def validate_puppet_logfile(logfile): """ Check a puppet log file for errors and raise an error if we find any @@ -115,7 +119,7 @@ def validate_puppet_logfile(logfile): for line in data.split('\n'): line = line.strip() - if _re_errorline.search(line) == None: + if _re_errorline.search(line) is None: continue message = _re_color.sub('', line) # remove colors diff --git a/packstack/puppet/templates/postscript.pp b/packstack/puppet/templates/postscript.pp index 89dcb0bec..7ccf2efad 100644 --- a/packstack/puppet/templates/postscript.pp +++ b/packstack/puppet/templates/postscript.pp @@ -1,6 +1,6 @@ exec { 'persist-firewall': command => $operatingsystem ? { - 'debian' => '/sbin/iptables-save > /etc/iptables/rules.v4', - /(fedora|RedHat|CentOS)/ => '/sbin/iptables-save > /etc/sysconfig/iptables', + 'debian' => '/sbin/iptables-save > /etc/iptables/rules.v4', + /(Fedora|RedHat|CentOS)/ => '/sbin/iptables-save > /etc/sysconfig/iptables', }, -} \ No newline at end of file +} diff --git a/tests/test.py b/tests/test.py index a9295a8ed..c8ebeb7cd 100644 --- a/tests/test.py +++ b/tests/test.py @@ -14,12 +14,17 @@ # License for the specific language governing permissions and limitations # under the License. +import shutil +import tempfile + from unittest import TestCase class TestCase(TestCase): def setUp(self): - pass + # Creating a temp directory that can be used by tests + self.tempdir = tempfile.mkdtemp() def tearDown(self): - pass + # remove the temp directory + shutil.rmtree(self.tempdir) diff --git a/tests/test_ospluginutils.py b/tests/test_ospluginutils.py index 4d8e67806..9b455710a 100644 --- a/tests/test_ospluginutils.py +++ b/tests/test_ospluginutils.py @@ -14,9 +14,12 @@ # License for the specific language governing permissions and limitations # under the License. +import os from test import TestCase -from packstack.modules.ospluginutils import gethostlist +from packstack.modules.ospluginutils import gethostlist, \ + validate_puppet_logfile, \ + PackStackError class OSPluginUtilsTestCase(TestCase): @@ -26,3 +29,19 @@ class OSPluginUtilsTestCase(TestCase): hosts = gethostlist(conf) hosts.sort() self.assertEquals(['1.1.1.1', '2.2.2.2', '3.3.3.3'], hosts) + + def test_validate_puppet_logfile(self): + filename = os.path.join(self.tempdir, "puppet.log") + fp = open(filename, "w") + fp.write("Everything went ok") + fp.close() + + validate_puppet_logfile(filename) + + def test_validate_puppet_logfile_error(self): + filename = os.path.join(self.tempdir, "puppet.log") + fp = open(filename, "w") + fp.write("No matching value for selector param 'Fedora' ...") + fp.close() + + self.assertRaises(PackStackError, validate_puppet_logfile, filename) diff --git a/tox.ini b/tox.ini index 058e2a6bf..f8c66fcce 100644 --- a/tox.ini +++ b/tox.ini @@ -17,7 +17,8 @@ downloadcache = ~/cache/pip [testenv:pep8] deps=pep8==1.2 -commands = pep8 --exclude=*.pyc --repeat --show-source setup.py +commands = pep8 --exclude=*.pyc --repeat --show-source \ + packstack/modules tests setup.py [testenv:cover] setenv = NOSE_WITH_COVERAGE=1