diff --git a/horizon/dashboards/nova/instances_and_volumes/volumes/forms.py b/horizon/dashboards/nova/instances_and_volumes/volumes/forms.py index 186f60f777c..067ec1e5033 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 exceptions from novaclient import exceptions as novaclient_exceptions +from .tables import ACTIVE_STATES LOG = logging.getLogger(__name__) @@ -59,8 +60,9 @@ def __init__(self, *args, **kwargs): 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 76f777504f1..617cbfdcef9 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 @@ def test_edit_attachments(self): 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)