Merge "Change message in certain cases"
This commit is contained in:
@@ -20,7 +20,7 @@ import shutil
|
||||
import sys
|
||||
from unittest import TestCase
|
||||
|
||||
from packstack.modules import ospluginutils
|
||||
from packstack.modules import ospluginutils, puppet
|
||||
from packstack.installer import run_setup, basedefs
|
||||
|
||||
from ..test_base import PackstackTestCaseMixin
|
||||
@@ -55,9 +55,9 @@ class CommandLineTestCase(PackstackTestCaseMixin, TestCase):
|
||||
|
||||
# There is no puppet logfile to validate, so replace
|
||||
# ospluginutils.validate_puppet_logfile with a mock function
|
||||
orig_validate_logfile = ospluginutils.validate_puppet_logfile
|
||||
ospluginutils.validate_puppet_logfile = lambda a: None
|
||||
ospluginutils.scan_puppet_logfile = lambda a: []
|
||||
orig_validate_logfile = puppet.validate_logfile
|
||||
puppet.validate_logfile = lambda a: None
|
||||
puppet.scan_logfile = lambda a: []
|
||||
|
||||
# If there is a error in a plugin sys.exit() gets called, this masks
|
||||
# the actual error that should be reported, so we replace it to
|
||||
|
||||
@@ -105,3 +105,11 @@ class ParameterTestCase(PackstackTestCaseMixin, TestCase):
|
||||
mask_list=["'text'"],
|
||||
replace_list=[("'", "'\\''")])
|
||||
self.assertEqual(masked, 'test %s' % STR_MASK)
|
||||
|
||||
def test_shortcuts(self):
|
||||
"""Test packstack.installer.utils.shortcuts functions"""
|
||||
conf = {"A_HOST": "1.1.1.1", "B_HOSTS": "2.2.2.2,1.1.1.1",
|
||||
"C_HOSTS": "3.3.3.3/vdc"}
|
||||
hostlist = list(hosts(conf))
|
||||
hostlist.sort()
|
||||
self.assertEquals(['1.1.1.1', '2.2.2.2', '3.3.3.3'], hostlist)
|
||||
|
||||
0
tests/modules/__init__.py
Normal file
0
tests/modules/__init__.py
Normal file
31
tests/modules/test_ospluginutils.py
Normal file
31
tests/modules/test_ospluginutils.py
Normal file
@@ -0,0 +1,31 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2013, Red Hat, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import os
|
||||
from unittest import TestCase
|
||||
|
||||
from ..test_base import PackstackTestCaseMixin
|
||||
from packstack.modules.ospluginutils import gethostlist
|
||||
|
||||
|
||||
class OSPluginUtilsTestCase(PackstackTestCaseMixin, TestCase):
|
||||
def test_gethostlist(self):
|
||||
conf = {"A_HOST": "1.1.1.1", "B_HOSTS": "2.2.2.2,1.1.1.1",
|
||||
"C_HOSTS": "3.3.3.3/vdc"}
|
||||
hosts = gethostlist(conf)
|
||||
hosts.sort()
|
||||
self.assertEquals(['1.1.1.1', '2.2.2.2', '3.3.3.3'], hosts)
|
||||
62
tests/modules/test_puppet.py
Normal file
62
tests/modules/test_puppet.py
Normal file
@@ -0,0 +1,62 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2013, Red Hat, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import os
|
||||
|
||||
from unittest import TestCase
|
||||
from ..test_base import PackstackTestCaseMixin
|
||||
|
||||
from packstack.installer.exceptions import PuppetError
|
||||
from packstack.modules.puppet import validate_logfile, scan_logfile
|
||||
|
||||
|
||||
class PuppetTestCase(PackstackTestCaseMixin, TestCase):
|
||||
|
||||
def test_validate_logfile(self):
|
||||
"""Test packstack.modules.validate_logfile"""
|
||||
filename = os.path.join(self.tempdir, "puppet.log")
|
||||
# test valid run
|
||||
with open(filename, "w") as fp:
|
||||
fp.write("Everything went ok")
|
||||
validate_logfile(filename)
|
||||
# test invalid run
|
||||
with open(filename, "w") as fp:
|
||||
fp.write("No matching value for selector param 'Fedora' ...")
|
||||
self.assertRaises(PuppetError, validate_logfile, filename)
|
||||
# test run with error exception
|
||||
with open(filename, "w") as fp:
|
||||
err = ("err: Could not prefetch database_grant provider 'mysql': "
|
||||
"Execution of '/usr/bin/mysql --defaults-file=/root/.my.cnf"
|
||||
" mysql -Be describe user' returned 1: Could not open "
|
||||
"required defaults file: /root/.my.cnf")
|
||||
fp.write(err)
|
||||
validate_logfile(filename)
|
||||
# test surrogate
|
||||
with open(filename, "w") as fp:
|
||||
err = ("err: /Stage[main]/Vswitch::Ovs/Package[openvswitch]/ensure"
|
||||
": change from absent to present failed: Execution of "
|
||||
"'/usr/bin/yum -d 0 -e 0 -y install openvswitch' returned "
|
||||
"1: Error: Nothing to do")
|
||||
fp.write(err)
|
||||
self.assertRaises(PuppetError, validate_logfile, filename)
|
||||
try:
|
||||
validate_logfile(filename)
|
||||
except PuppetError as ex:
|
||||
ex_msg = str(ex)
|
||||
sr_msg = ("Package openvswitch has not been found in enabled Yum "
|
||||
"repos")
|
||||
assert sr_msg in ex_msg
|
||||
@@ -1,60 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||
|
||||
# Copyright 2013, Red Hat, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import os
|
||||
from unittest import TestCase
|
||||
|
||||
from test_base import PackstackTestCaseMixin
|
||||
from packstack.modules.ospluginutils import gethostlist, \
|
||||
validate_puppet_logfile, \
|
||||
PackStackError
|
||||
|
||||
|
||||
class OSPluginUtilsTestCase(PackstackTestCaseMixin, TestCase):
|
||||
def test_gethostlist(self):
|
||||
conf = {"A_HOST": "1.1.1.1", "B_HOSTS": "2.2.2.2,1.1.1.1",
|
||||
"C_HOSTS": "3.3.3.3/vdc"}
|
||||
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)
|
||||
|
||||
def test_validate_puppet_logfile_okerror(self):
|
||||
filename = os.path.join(self.tempdir, "puppet.log")
|
||||
fp = open(filename, "w")
|
||||
fp.write("err: Could not prefetch database_grant provider 'mysql': "
|
||||
"Execution of '/usr/bin/mysql --defaults-file=/root/.my.cnf "
|
||||
"mysql -Be describe user' returned 1: Could not open required"
|
||||
" defaults file: /root/.my.cnf")
|
||||
fp.close()
|
||||
|
||||
validate_puppet_logfile(filename)
|
||||
Reference in New Issue
Block a user