Mock socket in test_bad_hostname_errors

This test wasn't mocking socket, therefore was calling a real command out
to the test runners local network, which lead to unpredictable results.
This patch mocks and adds a sideeffect to the socket command to ensure
that it is behaving as expected for the test.

Change-Id: Ie9ab0a12c0d26ae4fa571941e181ebbf800b8ceb
This commit is contained in:
Sam Betts 2015-08-19 11:52:25 +01:00
parent 661e8186b3
commit 535d1d18a9
1 changed files with 4 additions and 1 deletions

View File

@ -11,6 +11,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import socket
import unittest
from ironicclient import client
@ -155,7 +156,9 @@ class TestGetIpmiAddress(base.BaseTest):
mock_socket.assert_called_once_with('www.example.com')
self.assertEqual(ip, '192.168.1.1')
def test_bad_hostname_errors(self, mock_node):
@mock.patch('socket.gethostbyname')
def test_bad_hostname_errors(self, mock_socket, mock_node):
mock_socket.side_effect = socket.gaierror('Boom')
node = mock_node.return_value
node.driver_info.get.return_value = 'meow'
self.assertRaises(utils.Error, utils.get_ipmi_address, node)