Prevent tests' unmocked access to utils.execute()

This change introduces a new base test class that mocks out
utils.execute and forces an exception if it gets called.
This has rooted out many tests that were doing this as a side effect of
calling other functions, doing things like modprobe and running iscsi
on the host's actual machine.

The tests are all now appropriately patched in places where this was
happening, and the new base class permanently prevents this from
accidentally happening again.

If you really want to call utils.execute() then you need to re-mock it
in your unit test.

Change-Id: Idf87d09a9c01a6bfe2767f8becabe65c02983518
This commit is contained in:
Julian Edwards
2017-04-03 15:32:44 +10:00
parent 4be702242e
commit f57cbccf8b
12 changed files with 113 additions and 47 deletions

View File

@@ -12,9 +12,8 @@
# License for the specific language governing permissions and limitations
# under the License.
from oslotest import base as test_base
from ironic_python_agent import encoding
from ironic_python_agent.tests.unit import base
class SerializableTesting(encoding.Serializable):
@@ -33,7 +32,7 @@ class SerializableComparableTesting(encoding.SerializableComparable):
self.jill = jill
class TestSerializable(test_base.BaseTestCase):
class TestSerializable(base.IronicAgentTest):
def test_baseclass_serialize(self):
obj = encoding.Serializable()
self.assertEqual({}, obj.serialize())
@@ -44,7 +43,7 @@ class TestSerializable(test_base.BaseTestCase):
self.assertEqual(expected, obj.serialize())
class TestSerializableComparable(test_base.BaseTestCase):
class TestSerializableComparable(base.IronicAgentTest):
def test_childclass_equal(self):
obj1 = SerializableComparableTesting('hello', 'world')