From ad2deeb378b998fb238b7f7016200f6e4f6d40b3 Mon Sep 17 00:00:00 2001 From: Liam Kelleher Date: Thu, 5 Jan 2012 15:37:18 +0000 Subject: [PATCH] Add attaching state for Volumes bug 897726 Add "attaching" status for volumes and clear state on error This closes a gap where multiple calls of attach for the same volume can happen before the volume is actually attached. Change-Id: I59d22ceda83729c1a455af9994c9ffec1912e23b --- Authors | 1 + nova/tests/policy.json | 2 ++ nova/tests/test_compute.py | 6 +++++- nova/utils.py | 6 ++++++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Authors b/Authors index ad6351b07..888f3008f 100644 --- a/Authors +++ b/Authors @@ -106,6 +106,7 @@ Kevin L. Mitchell Kiall Mac Innes Kirill Shileev Koji Iida +Liam Kelleher Likitha Shetty Loganathan Parthipan Lorin Hochstein diff --git a/nova/tests/policy.json b/nova/tests/policy.json index c231bff60..d2e647f9f 100644 --- a/nova/tests/policy.json +++ b/nova/tests/policy.json @@ -127,6 +127,8 @@ "volume:attach": [], "volume:detach": [], + "volume:reserve_volume": [], + "volume:unreserve_volume": [], "volume:check_attach": [], "volume:check_detach": [], "volume:initialize_connection": [], diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py index 30027eb67..f8f87cba7 100644 --- a/nova/tests/test_compute.py +++ b/nova/tests/test_compute.py @@ -3049,12 +3049,16 @@ class ComputeAPITestCase(BaseTestCase): def fake_check_attach(*args, **kwargs): pass + def fake_reserve_volume(*args, **kwargs): + pass + def fake_volume_get(self, context, volume_id): return {'id': volume_id} self.stubs.Set(nova.volume.api.API, 'get', fake_volume_get) self.stubs.Set(nova.volume.api.API, 'check_attach', fake_check_attach) - + self.stubs.Set(nova.volume.api.API, 'reserve_volume', + fake_reserve_volume) instance = self._create_fake_instance() self.compute_api.attach_volume(self.context, instance, 1, '/dev/vdb') diff --git a/nova/utils.py b/nova/utils.py index 85f39dbe0..172b68afa 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -24,6 +24,7 @@ import datetime import functools import hashlib import inspect +import itertools import json import lockfile import os @@ -712,6 +713,11 @@ def to_primitive(value, convert_instances=False, level=0): if test(value): return unicode(value) + # value of itertools.count doesn't get caught by inspects + # above and results in infinite loop when list(value) is called. + if type(value) == itertools.count: + return unicode(value) + # FIXME(vish): Workaround for LP bug 852095. Without this workaround, # tests that raise an exception in a mocked method that # has a @wrap_exception with a notifier will fail. If