def test_revert_snapshot_and_lab_is_not_whitelisted( self, mock_revert, mock_change_lab_status): lab = dict(lab_name='reserved_lab', reservation="1234567890") with HTTMock(self.mock_api): with self.assertRaises(exceptions.TaskError): snapshot_tasks.revert_to_snapshot("reserved_lab", lab, "not_whitelisted_state") mock_change_lab_status.assert_called_with("reserved_lab", "state_operation_failed") mock_revert.assert_not_called()
def test_revert_snapshot(self, mock_revert_storage_snapshot, mock_change_lab_status): my_lab = "reserved_lab" lab = dict(lab_name='reserved_lab', reservation="1234567890") mock_change_lab_status.return_value = "etag" with HTTMock(self.mock_api): snapshot_tasks.revert_to_snapshot(my_lab, lab, "available_state", lab_whitelisted=True) mock_revert_storage_snapshot.assert_called_with(my_lab, "12334", False) mock_change_lab_status.assert_called_with(my_lab, "ready")
def test_revert_snapshot_and_lab_is_not_reserved( self, mock_revert_storage_snapshot, mock_change_lab_status): my_lab = "free_lab" lab = dict(lab_name='lab') mock_change_lab_status.return_value = "etag" with HTTMock(self.mock_api): with self.assertRaises(exceptions.InvalidTaskError): snapshot_tasks.revert_to_snapshot(my_lab, lab, "available_state", lab_whitelisted=True) mock_revert_storage_snapshot.assert_not_called() mock_change_lab_status.assert_called_with(my_lab, "state_operation_failed")
def test_revert_snapshot_fails(self, mock_revert_storage_snapshot, mock_change_lab_status): my_lab = "reserved_lab" lab = dict(lab_name='reserved_lab', reservation="1234567890") mock_change_lab_status.return_value = "etag" mock_revert_storage_snapshot.side_effect = [RuntimeError] with HTTMock(self.mock_api): with self.assertRaises(RuntimeError): snapshot_tasks.revert_to_snapshot(my_lab, lab, "available_state", lab_whitelisted=True) mock_revert_storage_snapshot.assert_called_with(my_lab, "12334", False) mock_change_lab_status.assert_called_with(my_lab, 'state_operation_failed') mock_revert_storage_snapshot.assert_called_with(my_lab, "12334", False)