def test_connect(self): ''' Test if it activate nbd for an image file. ''' mock = MagicMock(return_value=True) with patch.dict(qemu_nbd.__salt__, {'cmd.run': mock}): with patch.object(os.path, 'isfile', MagicMock(return_value=False)): self.assertEqual(qemu_nbd.connect('/tmp/image.raw'), '') self.assertEqual(qemu_nbd.connect('/tmp/image.raw'), '') with patch.object(os.path, 'isfile', mock): with patch.object(glob, 'glob', MagicMock(return_value=['/dev/nbd0'])): with patch.dict(qemu_nbd.__salt__, { 'cmd.run': mock, 'cmd.retcode': MagicMock(side_effect=[1, 0]) }): self.assertEqual(qemu_nbd.connect('/tmp/image.raw'), '/dev/nbd0') with patch.dict(qemu_nbd.__salt__, { 'cmd.run': mock, 'cmd.retcode': MagicMock(return_value=False) }): self.assertEqual(qemu_nbd.connect('/tmp/image.raw'), '')
def test_connect(self): """ Test if it activate nbd for an image file. """ mock = MagicMock(return_value=True) with patch.dict(qemu_nbd.__salt__, {"cmd.run": mock}): with patch.object(os.path, "isfile", MagicMock(return_value=False)): self.assertEqual(qemu_nbd.connect("/tmp/image.raw"), "") self.assertEqual(qemu_nbd.connect("/tmp/image.raw"), "") with patch.object(os.path, "isfile", mock): with patch.object(glob, "glob", MagicMock(return_value=["/dev/nbd0"])): with patch.dict( qemu_nbd.__salt__, { "cmd.run": mock, "cmd.retcode": MagicMock(side_effect=[1, 0]) }, ): self.assertEqual(qemu_nbd.connect("/tmp/image.raw"), "/dev/nbd0") with patch.dict( qemu_nbd.__salt__, { "cmd.run": mock, "cmd.retcode": MagicMock(return_value=False) }, ): self.assertEqual(qemu_nbd.connect("/tmp/image.raw"), "")
def test_connect(self): ''' Test if it activate nbd for an image file. ''' mock = MagicMock(return_value=True) with patch.dict(qemu_nbd.__salt__, {'cmd.run': mock}): with patch.object(os.path, 'isfile', MagicMock(return_value=False)): self.assertEqual(qemu_nbd.connect('/tmp/image.raw'), '') self.assertEqual(qemu_nbd.connect('/tmp/image.raw'), '') with patch.object(os.path, 'isfile', mock): with patch.object(glob, 'glob', MagicMock(return_value=['/dev/nbd0'])): with patch.dict(qemu_nbd.__salt__, {'cmd.run': mock, 'cmd.retcode': MagicMock(side_effect=[1, 0])}): self.assertEqual(qemu_nbd.connect('/tmp/image.raw'), '/dev/nbd0') with patch.dict(qemu_nbd.__salt__, {'cmd.run': mock, 'cmd.retcode': MagicMock(return_value=False)}): self.assertEqual(qemu_nbd.connect('/tmp/image.raw'), '')