def test_is_open_false(self): """ VDI is not open """ self.mock_blktap2.Tapdisk.find_by_path.return_value = None vdi_uuid = uuid.uuid4() mock_session = mock.MagicMock() is_open = on_slave.is_open(mock_session, { 'vdiUuid': vdi_uuid, 'srRef': 'opaqueref:sr_mine' }) self.assertEqual('False', is_open)
def test_is_open_nfssr_success(self): """ VDI is open """ vdi_uuid = uuid.uuid4() mock_session = mock.MagicMock() sr_uuid = uuid.uuid4() mock_session.xenapi.SR.get_record.return_value = { 'type': 'nfssr', 'uuid': sr_uuid } is_open = on_slave.is_open(mock_session, { 'vdiUuid': vdi_uuid, 'srRef': 'opaqueref:sr_mine' }) self.mock_sr.driver.assert_called_once_with('nfssr') self.assertEqual('True', is_open)
def test_is_open_lvm_success(self): """ LVM srs are uplifted to lvhd """ vdi_uuid = uuid.uuid4() mock_session = mock.MagicMock() sr_uuid = uuid.uuid4() mock_session.xenapi.SR.get_record.return_value = { 'type': 'lvmoiscsisr', 'uuid': sr_uuid } is_open = on_slave.is_open(mock_session, { 'vdiUuid': vdi_uuid, 'srRef': 'opaqueref:sr_mine' }) self.mock_sr.driver.assert_called_once_with('lvhd') self.assertEqual('True', is_open)
def test_is_open_xapi_exception(self, mock_util): """ Exceptions from is_open are logged """ mock_log_exception = mock.MagicMock() mock_util.logException.side_effect = mock_log_exception mock_blktap2 = mock.MagicMock() self.mocks['blktap2'] = mock_blktap2 mock_blktap2.Tapdisk.find_by_path.return_value = None vdi_uuid = uuid.uuid4() mock_session = mock.MagicMock() mock_session.xenapi.SR.get_record.side_effect = Exception('Failed') with self.assertRaises(Exception): is_open = on_slave.is_open(mock_session, { 'vdiUuid': vdi_uuid, 'srRef': 'opaqueref:sr_mine' }) self.assertTrue(mock_log_exception.called) mock_log_exception.assert_called_once_with('is_open')