Merge "Save instace_id inside Associate Floating IP workflow" into stable/ussuri

This commit is contained in:
Zuul 2021-05-01 11:40:23 +00:00 committed by Gerrit Code Review
commit b37450e29a
3 changed files with 22 additions and 16 deletions

View File

@ -139,7 +139,7 @@ class FloatingIpViewTests(test.TestCase):
self._get_fip_targets() self._get_fip_targets()
self.mock_floating_ip_associate.return_value = None self.mock_floating_ip_associate.return_value = None
form_data = {'instance_id': port_target_id, form_data = {'port_id': port_target_id,
'ip_id': floating_ip.id} 'ip_id': floating_ip.id}
url = reverse('%s:associate' % NAMESPACE) url = reverse('%s:associate' % NAMESPACE)
res = self.client.post(url, form_data) res = self.client.post(url, form_data)
@ -168,7 +168,7 @@ class FloatingIpViewTests(test.TestCase):
self.mock_floating_ip_associate.return_value = None self.mock_floating_ip_associate.return_value = None
next = reverse("horizon:project:instances:index") next = reverse("horizon:project:instances:index")
form_data = {'instance_id': port_target_id, form_data = {'port_id': port_target_id,
'next': next, 'next': next,
'ip_id': floating_ip.id} 'ip_id': floating_ip.id}
url = reverse('%s:associate' % NAMESPACE) url = reverse('%s:associate' % NAMESPACE)
@ -197,7 +197,7 @@ class FloatingIpViewTests(test.TestCase):
self._get_fip_targets() self._get_fip_targets()
self.mock_floating_ip_associate.side_effect = self.exceptions.nova self.mock_floating_ip_associate.side_effect = self.exceptions.nova
form_data = {'instance_id': port_target_id, form_data = {'port_id': port_target_id,
'ip_id': floating_ip.id} 'ip_id': floating_ip.id}
url = reverse('%s:associate' % NAMESPACE) url = reverse('%s:associate' % NAMESPACE)
res = self.client.post(url, form_data) res = self.client.post(url, form_data)

View File

@ -36,7 +36,11 @@ class AssociateIPAction(workflows.Action):
coerce=filters.get_int_or_uuid, coerce=filters.get_int_or_uuid,
empty_value=None empty_value=None
) )
instance_id = forms.ThemableChoiceField( instance_id = forms.CharField(
widget=forms.widgets.HiddenInput(),
required=False,
)
port_id = forms.ThemableChoiceField(
label=_("Port to be associated") label=_("Port to be associated")
) )
@ -53,7 +57,8 @@ class AssociateIPAction(workflows.Action):
# an association target is not an instance but a port, so we need # an association target is not an instance but a port, so we need
# to get an association target based on a received instance_id # to get an association target based on a received instance_id
# and set the initial value of instance_id ChoiceField. # and set the initial value of instance_id ChoiceField.
q_instance_id = self.request.GET.get('instance_id') q_instance_id = self.data.get('instance_id',
self.request.GET.get('instance_id'))
q_port_id = self.request.GET.get('port_id') q_port_id = self.request.GET.get('port_id')
if policy.check((("network", "create_floatingip"),), if policy.check((("network", "create_floatingip"),),
@ -61,20 +66,21 @@ class AssociateIPAction(workflows.Action):
self.fields['ip_id'].widget.add_item_link = ALLOCATE_URL self.fields['ip_id'].widget.add_item_link = ALLOCATE_URL
if q_instance_id: if q_instance_id:
self.initial['instance_id'] = q_instance_id
targets = self._get_target_list(q_instance_id) targets = self._get_target_list(q_instance_id)
# Setting the initial value here is required to avoid a situation # Setting the initial value here is required to avoid a situation
# where instance_id passed in the URL is used as the initial value # where instance_id passed in the URL is used as the initial value
# unexpectedly. (This always happens if the form is invoked from # unexpectedly. (This always happens if the form is invoked from
# the instance table.) # the instance table.)
if targets: if targets:
self.initial['instance_id'] = targets[0].id self.initial['port_id'] = targets[0].id
else: else:
self.initial['instance_id'] = '' self.initial['port_id'] = ''
elif q_port_id: elif q_port_id:
targets = self._get_target_list() targets = self._get_target_list()
for target in targets: for target in targets:
if target.port_id == q_port_id: if target.port_id == q_port_id:
self.initial['instance_id'] = target.id self.initial['port_id'] = target.id
break break
def populate_ip_id_choices(self, request, context): def populate_ip_id_choices(self, request, context):
@ -112,9 +118,9 @@ class AssociateIPAction(workflows.Action):
redirect=redirect) redirect=redirect)
return targets return targets
# TODO(amotoki): [drop-nova-network] Rename instance_id to port_id def populate_port_id_choices(self, request, context):
def populate_instance_id_choices(self, request, context): q_instance_id = self.data.get('instance_id',
q_instance_id = self.request.GET.get('instance_id') self.initial.get('instance_id'))
# The reason of specifying an empty tuple when q_instance_id is None # The reason of specifying an empty tuple when q_instance_id is None
# is to make memoized_method _get_target_list work. Two calls of # is to make memoized_method _get_target_list work. Two calls of
# _get_target_list from here and __init__ must have a same arguments. # _get_target_list from here and __init__ must have a same arguments.
@ -132,7 +138,7 @@ class AssociateIPAction(workflows.Action):
class AssociateIP(workflows.Step): class AssociateIP(workflows.Step):
action_class = AssociateIPAction action_class = AssociateIPAction
contributes = ("ip_id", "instance_id", "ip_address") contributes = ("ip_id", "instance_id", "ip_address", "port_id")
def contribute(self, data, context): def contribute(self, data, context):
context = super(AssociateIP, self).contribute(data, context) context = super(AssociateIP, self).contribute(data, context)
@ -163,7 +169,7 @@ class IPAssociationWorkflow(workflows.Workflow):
try: try:
api.neutron.floating_ip_associate(request, api.neutron.floating_ip_associate(request,
data['ip_id'], data['ip_id'],
data['instance_id']) data['port_id'])
except neutron_exc.Conflict: except neutron_exc.Conflict:
msg = _('The requested instance port is already' msg = _('The requested instance port is already'
' associated with another floating IP.') ' associated with another floating IP.')

View File

@ -25,7 +25,7 @@ from openstack_dashboard.test.integration_tests.regions import tables
class FloatingIPTable(tables.TableRegion): class FloatingIPTable(tables.TableRegion):
name = 'floating_ips' name = 'floating_ips'
FLOATING_IP_ASSOCIATIONS = ( FLOATING_IP_ASSOCIATIONS = (
("ip_id", "instance_id")) ("ip_id", "port_id"))
@tables.bind_table_action('allocate') @tables.bind_table_action('allocate')
def allocate_ip(self, allocate_button): def allocate_ip(self, allocate_button):
@ -93,8 +93,8 @@ class FloatingipsPage(basepage.BaseNavigationPage):
instance_ip=None): instance_ip=None):
row = self._get_row_with_floatingip(floatingip) row = self._get_row_with_floatingip(floatingip)
floatingip_form = self.floatingips_table.associate_ip(row) floatingip_form = self.floatingips_table.associate_ip(row)
floatingip_form.instance_id.text = "{}: {}".format(instance_name, floatingip_form.port_id.text = "{}: {}".format(instance_name,
instance_ip) instance_ip)
floatingip_form.submit() floatingip_form.submit()
def disassociate_floatingip(self, floatingip): def disassociate_floatingip(self, floatingip):