From a67402595b05909f18af9b827fd4e326bf95d3da Mon Sep 17 00:00:00 2001 From: Emma Steimann Date: Sat, 4 Feb 2012 19:42:58 -0600 Subject: [PATCH] Volumes page should not show inactive instances. * fixes bug 917779 Change-Id: Ic804b0c9d978c36974a0f3bef7c017abe5847c90 --- .../dashboards/nova/instances_and_volumes/volumes/forms.py | 6 ++++-- .../dashboards/nova/instances_and_volumes/volumes/tests.py | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/horizon/dashboards/nova/instances_and_volumes/volumes/forms.py b/horizon/dashboards/nova/instances_and_volumes/volumes/forms.py index 186f60f777..067ec1e503 100644 --- a/horizon/dashboards/nova/instances_and_volumes/volumes/forms.py +++ b/horizon/dashboards/nova/instances_and_volumes/volumes/forms.py @@ -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): diff --git a/horizon/dashboards/nova/instances_and_volumes/volumes/tests.py b/horizon/dashboards/nova/instances_and_volumes/volumes/tests.py index 76f777504f..617cbfdcef 100644 --- a/horizon/dashboards/nova/instances_and_volumes/volumes/tests.py +++ b/horizon/dashboards/nova/instances_and_volumes/volumes/tests.py @@ -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)