Volumes page should not show inactive instances.

* fixes bug 917779

Change-Id: Ic804b0c9d978c36974a0f3bef7c017abe5847c90
This commit is contained in:
Emma Steimann 2012-02-04 19:42:58 -06:00 committed by jakedahn
parent 4b4bbd4a5e
commit a67402595b
2 changed files with 8 additions and 2 deletions

View File

@ -18,6 +18,7 @@ from horizon import forms
from horizon import exceptions
from novaclient import exceptions as novaclient_exceptions
from .tables import ACTIVE_STATES
LOG = logging.getLogger(__name__)
@ -59,8 +60,9 @@ class AttachForm(forms.SelfHandlingForm):
instance_list = kwargs.get('initial', {}).get('instances', [])
instances = [('', "Select an instance")]
for instance in instance_list:
instances.append((instance.id, '%s (%s)' % (instance.name,
instance.id)))
if instance.status in ACTIVE_STATES:
instances.append((instance.id, '%s (%s)' % (instance.name,
instance.id)))
self.fields['instance'].choices = instances
def handle(self, request, data):

View File

@ -40,4 +40,8 @@ class VolumeViewTests(test.TestCase):
url = reverse('horizon:nova:instances_and_volumes:volumes:attach',
args=[volume.id])
res = self.client.get(url)
# Asserting length of 2 accounts for the one instance option,
# and the one 'Choose Instance' option.
self.assertEqual(len(res.context['form'].fields['instance']._choices),
2)
self.assertEqual(res.status_code, 200)