diff options
author | Radomir Dopieralski <openstack@sheep.art.pl> | 2015-08-10 10:48:27 +0200 |
---|---|---|
committer | Radomir Dopieralski <openstack@sheep.art.pl> | 2015-10-01 08:03:51 +0000 |
commit | 5b9bdca15b31fbc75dc674da8d3f965ebe94cf1c (patch) | |
tree | 79a17620bb424bba3a48271410df8f1db497c20a | |
parent | 2d84fac6afbb0734a52503b89606ffb1386afd28 (diff) | |
download | horizon-5b9bdca15b31fbc75dc674da8d3f965ebe94cf1c.tar.gz |
Use security group id not name in the create instance dialog
It's possible to create multiple security groups with the same name,
and then launching an instance will error with "Error: Multiple
security_group matches found for name 'foo', use an ID to be more specific."
The solution is to use the group id instead of group name in the form.
This only works with Neutron, because Nova-Network not only requires the
groups to be passed by name, but also passes them by name internally in
several places.
Change-Id: I83587e15a8c18d64a29fd1083e786a73162b19f9
Partial-bug: #1203413
(cherry picked from commit 5562694b7c81821820a846dd76471f66d8a47c12)
-rw-r--r-- | openstack_dashboard/dashboards/project/instances/tests.py | 38 | ||||
-rw-r--r-- | openstack_dashboard/dashboards/project/instances/workflows/create_instance.py | 6 |
2 files changed, 24 insertions, 20 deletions
diff --git a/openstack_dashboard/dashboards/project/instances/tests.py b/openstack_dashboard/dashboards/project/instances/tests.py index 36ea1f69f..478a7c09c 100644 --- a/openstack_dashboard/dashboards/project/instances/tests.py +++ b/openstack_dashboard/dashboards/project/instances/tests.py @@ -1717,7 +1717,7 @@ class InstanceTests(helpers.TestCase): flavor.id, keypair.name, customization_script, - [sec_group.name], + [str(sec_group.id)], block_device_mapping=None, block_device_mapping_v2=None, nics=nics, @@ -1742,7 +1742,7 @@ class InstanceTests(helpers.TestCase): 'script_data': customization_script, 'project_id': self.tenants.first().id, 'user_id': self.user.id, - 'groups': sec_group.name, + 'groups': str(sec_group.id), 'availability_zone': avail_zone.zoneName, 'volume_type': '', 'network': self.networks.first().id, @@ -1871,7 +1871,7 @@ class InstanceTests(helpers.TestCase): 'script_data': customization_script, 'project_id': self.tenants.first().id, 'user_id': self.user.id, - 'groups': sec_group.name, + 'groups': str(sec_group.id), 'availability_zone': avail_zone.zoneName, 'volume_type': '', 'network': self.networks.first().id, @@ -2013,7 +2013,7 @@ class InstanceTests(helpers.TestCase): flavor.id, keypair.name, customization_script, - [sec_group.name], + [str(sec_group.id)], block_device_mapping=block_device_mapping, block_device_mapping_v2=None, nics=nics, @@ -2036,7 +2036,7 @@ class InstanceTests(helpers.TestCase): 'script_data': customization_script, 'project_id': self.tenants.first().id, 'user_id': self.user.id, - 'groups': sec_group.name, + 'groups': str(sec_group.id), 'availability_zone': avail_zone.zoneName, 'volume_size': '1', 'volume_id': volume_choice, @@ -2152,7 +2152,7 @@ class InstanceTests(helpers.TestCase): flavor.id, keypair.name, customization_script, - [sec_group.name], + [str(sec_group.id)], block_device_mapping=block_device_mapping, block_device_mapping_v2=None, nics=nics, @@ -2173,7 +2173,7 @@ class InstanceTests(helpers.TestCase): 'script_data': customization_script, 'project_id': self.tenants.first().id, 'user_id': self.user.id, - 'groups': sec_group.name, + 'groups': str(sec_group.id), 'availability_zone': avail_zone.zoneName, 'network': self.networks.first().id, 'volume_type': 'volume_id', @@ -2280,7 +2280,7 @@ class InstanceTests(helpers.TestCase): 'script_data': customization_script, 'project_id': self.tenants.first().id, 'user_id': self.user.id, - 'groups': sec_group.name, + 'groups': str(sec_group.id), 'availability_zone': avail_zone.zoneName, 'volume_type': '', 'count': 1} @@ -2546,7 +2546,7 @@ class InstanceTests(helpers.TestCase): flavor.id, keypair.name, customization_script, - [sec_group.name], + [str(sec_group.id)], block_device_mapping=None, block_device_mapping_v2=None, nics=nics, @@ -2577,7 +2577,7 @@ class InstanceTests(helpers.TestCase): 'script_data': customization_script, 'project_id': self.tenants.first().id, 'user_id': self.user.id, - 'groups': sec_group.name, + 'groups': str(sec_group.id), 'volume_type': '', 'network': self.networks.first().id, 'count': 1, @@ -2689,7 +2689,7 @@ class InstanceTests(helpers.TestCase): 'script_data': customization_script, 'project_id': self.tenants.first().id, 'user_id': self.user.id, - 'groups': sec_group.name, + 'groups': str(sec_group.id), 'volume_type': 'volume_id', 'volume_id': volume_choice, 'device_name': device_name, @@ -2796,7 +2796,7 @@ class InstanceTests(helpers.TestCase): 'script_data': customization_script, 'project_id': self.tenants.first().id, 'user_id': self.user.id, - 'groups': sec_group.name, + 'groups': str(sec_group.id), 'volume_type': 'volume_id', 'volume_id': volume_choice, 'device_name': device_name, @@ -2920,7 +2920,7 @@ class InstanceTests(helpers.TestCase): 'script_data': customization_script, 'project_id': self.tenants.first().id, 'user_id': self.user.id, - 'groups': sec_group.name, + 'groups': str(sec_group.id), 'volume_type': 'volume_id', 'volume_id': volume_choice, 'device_name': device_name, @@ -3049,7 +3049,7 @@ class InstanceTests(helpers.TestCase): 'customization_script': customization_script, 'project_id': self.tenants.first().id, 'user_id': self.user.id, - 'groups': sec_group.name, + 'groups': str(sec_group.id), 'volume_type': 'volume_id', 'volume_id': volume_choice, 'volume_size': max( @@ -3175,7 +3175,7 @@ class InstanceTests(helpers.TestCase): 'script_data': customization_script, 'project_id': self.tenants.first().id, 'user_id': self.user.id, - 'groups': sec_group.name, + 'groups': str(sec_group.id), 'volume_size': volume_size, 'device_name': device_name, 'count': 1 @@ -3348,7 +3348,7 @@ class InstanceTests(helpers.TestCase): flavor.id, keypair.name, customization_script, - [sec_group.name], + [str(sec_group.id)], block_device_mapping=None, block_device_mapping_v2=device_mapping_v2, nics=nics, @@ -3371,7 +3371,7 @@ class InstanceTests(helpers.TestCase): 'script_data': customization_script, 'project_id': self.tenants.first().id, 'user_id': self.user.id, - 'groups': sec_group.name, + 'groups': str(sec_group.id), 'volume_size': image.size, 'device_name': device_name, 'network': self.networks.first().id, @@ -4420,7 +4420,7 @@ class ConsoleManagerTests(helpers.TestCase): flavor.id, keypair.name, customization_script, - [sec_group.name], + [str(sec_group.id)], block_device_mapping=None, block_device_mapping_v2=None, nics=nics, @@ -4450,7 +4450,7 @@ class ConsoleManagerTests(helpers.TestCase): 'script_data': customization_script, 'project_id': self.tenants.first().id, 'user_id': self.user.id, - 'groups': sec_group.name, + 'groups': [str(sec_group.id)], 'volume_type': '', 'network': self.networks.first().id, 'count': 1, diff --git a/openstack_dashboard/dashboards/project/instances/workflows/create_instance.py b/openstack_dashboard/dashboards/project/instances/workflows/create_instance.py index 9f6130c2c..3c5e882e3 100644 --- a/openstack_dashboard/dashboards/project/instances/workflows/create_instance.py +++ b/openstack_dashboard/dashboards/project/instances/workflows/create_instance.py @@ -568,7 +568,11 @@ class SetAccessControlsAction(workflows.Action): def populate_groups_choices(self, request, context): try: groups = api.network.security_group_list(request) - security_group_list = [(sg.name, sg.name) for sg in groups] + if base.is_service_enabled(request, 'network'): + security_group_list = [(sg.id, sg.name) for sg in groups] + else: + # Nova-Network requires the groups to be listed by name + security_group_list = [(sg.name, sg.name) for sg in groups] except Exception: exceptions.handle(request, _('Unable to retrieve list of security groups')) |