Commit Graph

54 Commits

Author SHA1 Message Date
Pedro Martins 1db1764749 Add NAT rules to the floating IP workflow
The floating IP workflow is now able to manage NAT
rules (portforwarding) if the floating IP is not
associated with any NICs (ports).

This patch is the one of a series of patches
to implement floating ip port forwarding with
port ranges.

The specification is defined in:
https://github.com/openstack/neutron-specs/blob/master/specs/wallaby/port-forwarding-port-ranges.rst

Implements: blueprint https://blueprints.launchpad.net/neutron/+spec/floatingips-portforwarding-ranges
Change-Id: Id715da6591124de45f41cc367bf39a6bfe190c9a
2023-03-01 10:38:16 -03:00
Akihiro Motoki 516e57bc89 Add UT coverage for attach_interface by port
Previously attach_interface tests in project/instances/tests.py
did not cover the case of attach_interface by port.
This commit adds UT for such cases.

Details:
- The second call of the mocked network_list_for_tenant retured
  an empty list. It sounds tricky to change the return value for
  network_list_for_tenant() in two calls, but this trick was used
  to skip the processing of port_field_data.
  This should return a same value for the two calls to test
  port_field_data() function.
- To test the behavior of attach_interface by "port",
  an unbound port (whose device_owner/device_id of the port is empty)
  is required, so this commit adds it to neutron_data.py.
- test_interface_attach_get() covers a list of choices when "By Port"
  is selected in the form.
- test_interface_attach_post_by_port() is added.

Related to the addition of an unbound port to neutron_data.py,
the following other tests are adjusted.
They assumed that all non-network ports are owned by servers,
but it is no longer true as an unbound port is added to the test data.
Note that associating an unbound port with a floating IP is a valid
operation in neutron, so there is no problem to adjust UTs.

- openstack_dashboard/dashboards/project/floating_ips/tests.py
- openstack_dashboard/test/unit/api/test_neutron.py

Related-Bug: #1943639
Change-Id: Ib0ee342463e5668858078db43c04fe0a1be6e995
2022-10-26 15:34:17 -05:00
Akihiro Motoki d9266fd82c Address RemovedInDjango40Warning (3)
In Django 3.1, django.conf.urls.url() is deprecated
in favor of django.urls.re_path().

https://docs.djangoproject.com/en/4.0/releases/3.1/#id2

Change-Id: I484694f8718f61c022126a1935cf28fce075894b
2022-02-04 16:26:54 +09:00
Akihiro Motoki cd7c1b5110 Address RemovedInDjango40Warning (2)
django.utils.translation.ugettext(), ugettext_lazy(), ugettext_noop(),
ungettext(), and ungettext_lazy() are deprecated in favor of the
functions that they’re aliases for: django.utils.translation.gettext(),
gettext_lazy(), gettext_noop(), ngettext(), and ngettext_lazy().

https://docs.djangoproject.com/en/4.0/releases/3.0/#id3

Change-Id: I77878f84e9d10cf6a136dada81eabf4e18676250
2022-02-04 16:22:07 +09:00
Radomir Dopieralski 3d82d57353 Save instace_id inside Associate Floating IP workflow
Also, rename instance_id field to proper port_id.

Before this change, when instance_id was passed from the Instances
page in the URL, the information would be lost on form submission,
and if the form contained an error, the it would be redisplayed with
the port drop-down containing all ports from all instances. This also
made submitting this form slow, as the drop-down would be populated
with all ports on form validation.

It also creates a bug, where if there are more instances than Nova's
pagination allows, the ports from newer instances would no longer
appear in the drop-down, and the form would fail to validate, even
though the choice of port on initial form was correct.

Closes-bug: #1920010
Change-Id: I3ab26c19dc9ea1ed23fcff790d0db919039099eb
2021-03-18 12:39:23 +01:00
YuehuiLei 87f498bee5 Drop the usage of unicode prefix from unicode strings
All strings are considered as unicode strings in python 3,
so we no longer need "u" prefix (u'...').

Co-Authored-By: Akihiro Motoki <amotoki@gmail.com>
Change-Id: I796d2fcdca066475bbf29d25cbf2aa67b2b2178b
2021-02-12 13:05:27 -06:00
Zuul 05e232c03a Merge "Refactor quota related unit tests" 2020-11-18 10:13:54 +00:00
Akihiro Motoki b89c705164 Refactor quota related unit tests
openstack_dashboard/dashboards/project/floating_ips/tests.py:
The floating IP panel implementation calls
openstack_dashboard.usage.quotas.tenant_quota_usages, but
its unit test mocks functions called inside tenant_quota_usages.
tenant_quota_usages itself should be mocked.

openstack_dashboard/test/unit/usage/test_quotas.py:
Mocked methods were not verified test_tenant_quota_usages_non_legacy.
Verifications for called methods are added.
Mocking floating_ip_supported is dropped as it is not called and
there is no need to mock it.

Change-Id: Iad66c882738fd90eb6dd6de3df96459c10a29aa2
2020-10-26 17:20:52 +09:00
Akihiro Motoki e5d09edc20 Use python3-style super()
In python3, super() does not always require a class and self reference.
In other words, super() is enough for most cases.
This is much simpler and it is time to switch it to the newer style.

pylint provides a check for this.
Let's enable 'super-with-arguments' check.

NOTE: _prepare_mappings() method of FormRegion in
openstack_dashboard/test/integration_tests/regions/forms.py is refactored.
super() (without explicit class and self referece) does not work when
a subclass method calls a same method in a parent class multiple times.
It looks better to prepare a separate method to provide a common logic.

Change-Id: Id9512a14be9f20dbd5ebd63d446570c7b7c825ff
2020-10-15 14:37:20 +09:00
Akihiro Motoki 74df97f57c pylint: Fix unnecessary-comprehension warning
'unnecessary-comprehension' warning is emitted when
unnecessary use of a comprehension is found.

classes attribute in Action can be a tuple,
so we need list() to ensure it is a list before adding 'disabled'.
I think it is time to introduce a method in Action class or somewhere
but it should be handled separately.

Change-Id: I16a98d56b6d0bd0af234b00735c6ed576620df7e
2020-09-27 12:44:16 +09:00
Akihiro Motoki 692778f8cf pylint: Address no-else-return warning
This pylint check 'no-else-return' might be debatable.
but as far as I checked it works in most cases.

Change-Id: Ie8574d4a529454c6e050fa62a7a17ea097d00240
2020-09-27 12:44:16 +09:00
Ivan Kolodyazhny 14e779bbac Use unittest.mock instead of third party mock
Now that we no longer support py27, we can use the standard library
unittest.mock module instead of the third party mock lib.

Change-Id: I2de669d8e89b8daeb7ee5405ffab35af6307c40b
2020-03-26 19:45:37 +02:00
Ivan Kolodyazhny d870b40583 Remove six usage from openstack_dashboard package
We don't support Python 2 anymore so we don't need this
compatibility library.

six.reraise usages are left as is until it'll be moved to some
base lib like oslo.utils to not re-implenent this method in
Horizon.

This patch also removes Python2-specific base test case methods
assertItemsEqual and assertNotRegexpMatches in flavor of new
Python 3 analogues.

Change-Id: I26a59176be9e9f213128e4945a58b9459334b626
2020-01-15 12:47:48 +02:00
Marek 161b4ae5d4 Fixes a series of bugs related to Floating IPs.
- Fixes KeyErrors when accessing 'floatingip' values in usages, which
  broken Floating IP allocation.
- The quota display in the bottom right of the Allocation dialog are
  only displayed if 'enabled_quotas' is True
- Adds security group rule tallying for the usages overview page, which
  fixes a KeyError crash for installations where Horizon 'enable_quotas'
  is set to true, but the 'quota_details' extension is not installed on
  in Neutron
- Adds a policy check to show and hide The plus/add button in
  Instances->Associate Floating IP to match the Allocate IP To Project
  button in Floating IPs
- Fixed the page title not being set for the non-modal version of the
  modal allocation dialog/form
- Added an 'allowed' functionality for network usage overview charts to
  allow for them to be dynamically disabled
- Added tests and mocks for the above
- Added tests for non-legacy quota tallying for networks
- Added test for disabled network quotas in overview

Change-Id: I47f73ff94664d315a2400feb8ce8a25f4e6beced
closes-bug: #1838522
2019-12-17 13:30:25 +09:00
Akihiro Motoki ec970fd6e8 Handle partial dict setting
In Train cycle, we moved the definition of default values
to openstack_dashboard/defaults.py. The current code accesses
a dict member using []. It requires operators to define a dict
setting with a full member.

This commit allows to use dict-type settings with partial members.

A new function is introduced to retrieve a dict-type setting
considering default values defined in
{openstack_dashboard,horizon,openstack_auth}/defaults.py

Change-Id: I7ff0ad4bca698aef9c0eba370b0570200a14367a
Closes-Bug: #1843104
2019-09-26 14:31:17 +09:00
Corey Bryant 6f4742457f Switch from django string_concat to format_lazy
string_concat was removed in django 2.1 when it reached the end
of it's deprecation cycle. It was removed because the same behavior
can be achieved with format_lazy.

For more details see:
https://docs.djangoproject.com/en/2.2/releases/2.1/

Change-Id: I5e1c9bdfa1d0e049e0516198abbdb76be1667216
Closes-Bug: #1836671
Partial-Bug: #1789046
2019-07-19 16:50:16 -04:00
Akihiro Motoki fcdc67b819 Define default settings explicitly (openstack_dashboard 3/5)
This commit mainly covers settings
in openstack_dashboard/dashboards/project/.

Part of blueprint ini-based-configuration
Change-Id: I22413d2fe20576a507634dc4e2d0354c7db8800a
2019-07-03 14:54:16 +09:00
Akihiro Motoki 59beb951a3 pylint: Fix consider-using-(dict|set)-comprehension
Change-Id: I81c694c17106c179a53326a12e78cfa899872970
2019-01-13 00:59:05 +09:00
Marek 1456f7caa3 Disables Django 1.10 required attribute
Removes the default 'required' attribute rendered by Django into the
hidden Selects of the ThemableDynamicTypedChoiceField widgets. This
attribute causes issues in Chrome with a new, client side validation
present in Django 1.10.

Change-Id: I6d0a2951cc74ffa57d091a4589372bf9b93cd33f
Closes-Bug: #1792127
2018-09-12 13:16:29 +02:00
pengyuesheng 797859beb7 Floating ip filter has no effect
the API of tenant_floating_ip_list add '**search_opts',

Change-Id: Ie4f47f768909a2af7a916d2ad6ce43b3e157b432
Closes-Bug: #1763280
2018-08-23 09:58:16 +08:00
Jens Harbott 9e703aec2f Add DNS parameters to Floating IP panels
This adds support for the "DNS Domain" and "DNS Name" options to the
panels for listing and allocation Floating IPs.

These options are available as a Neutron extension, so we need to
make them conditional based on the availability of that extension.

Change-Id: Ife8e19aac44dccbdf11a6a6d4bb50cd3b7ed8d8e
2018-07-22 20:24:36 +09:00
Akihiro Motoki 06ca3c811b quota: Move targets argument to get_disabled_quotas
In addition, unnecessary API calls determined by 'targets'
are now removed.

blueprint make-quotas-great-again
Change-Id: I77b1335c25f2e2f3952e0d3c59f8c89a2bad3195
2018-04-19 20:37:46 +00:00
Akihiro Motoki d62d6e39e1 Convert project tests into mock: fip/sg/key_pairs/topology
Partially-Implements: blueprint mock-framework-in-unit-tests
Change-Id: I13b3f15736b9a26863d18f732fd26ea35ac00f00
2018-03-20 08:33:05 +09:00
Akihiro Motoki e477eafa45 django2: Replace django.core.urlresolves with django.urls
(In Django 2.0) The django.core.urlresolvers module is removed
in favor of its new location, django.urls.
It was depreacted in Django 1.10:
https://docs.djangoproject.com/en/2.0/releases/1.10/#id3

blueprint django2-support
Change-Id: I46ab5c325491274b8eaffbf848e5d80f83c2fd26
2018-02-17 01:36:48 +09:00
Zuul 98d0714939 Merge "quota: Use network quota field names consistently" 2017-12-26 21:40:34 +00:00
Zuul 135a279246 Merge "quota: Use neutron quota_details API to retrieve usage" 2017-12-26 21:20:18 +00:00
Trygve Vea d1225c606e Floating IP: Expose description field in form and tables
The networking API supports setting a description on floating IP addresses.
This patch adds a form input field to the allocation form, and a column to the
table that displays floating IP list.

Closes-Bug: #1738625
Change-Id: I3cec286d01f319402dd652f2f0fe7a59e7d1cfbb
2017-12-17 12:58:50 +00:00
Akihiro Motoki 1340904d47 quota: Use network quota field names consistently
Previously neutron quota names and nova-network quota names are
mixly used and this makes the readability terrible.
We no longer supports nova-network, so it looks simple to use
neutron quota names consistently.

Neutron quota names use singular form and it is different
from nova and cinder (which adopt plural form as quota names).
Although it might be confusing, the mixed usage is much worse.
Some wrapper layer may address singular vs plural form issue,
but it can be solved later. Let's use neutron quota names
directly now to simplify the code.

blueprint make-quotas-great-again
Change-Id: Ie31414ada34cbdbd046063b512d3cef0a6e68acf
2017-12-13 20:27:02 +09:00
Akihiro Motoki cd3f3e5127 quota: Use neutron quota_details API to retrieve usage
Previously neutron did not provide a way to retrieve resource usage
in a single API, so we need to call list APIs and count the number of
resources. Since Pike release, quota details API is provided and
it returns both quota and usage (used + reserved).

blueprint make-quotas-great-again
Change-Id: I63d0e81654c18f0f235631922d64d1109233fcfa
2017-12-13 20:27:02 +09:00
Akihiro Motoki d14fbc849e FIP associate: Show only ports from a target server
Previously when associating an FIP to a server, neutron ports which
do not belong to a target server were also shown in the target list.
It is clearer if only neutron ports connected to a target server
are shown. This commit changes the logic to lookup FIP targets to
achieve this.

Closes-Bug: #1630412
Change-Id: I9901b54e125b6bf09df86537c8308b2bfb1499f2
2017-11-18 00:03:00 +00:00
Akihiro Motoki 7961c6a84f Refactor FIP code to use FloatingIpTarget properly
FloatingIpTarget was introduced but it was used partially.
This commit clean up the remaining logic of FIP target ID calculation.

Related-Bug: #1725657
Change-Id: I4b93b9a7a3977b042bb9c3200923c5c2fa84476d
2017-11-18 00:03:00 +00:00
Zuul 1437fa6533 Merge "Fix displaying pool name for floating ip" 2017-10-16 16:57:38 +00:00
Max Yatsenko aec3a33a22 Fix displaying pool name for floating ip
It fixes an issue when pool name is not
displayed for floating ip in a case when any
floating ip is not associated with an instance.

Change-Id: Ic20ec3709fa7c5313f59a16aa32b975eb004f753
Closes-Bug: #1716431
2017-10-09 12:39:01 +03:00
Jenkins 6bc974850e Merge "flake8-import-order: Ensure to place project imports last" 2017-10-03 21:46:21 +00:00
Akihiro Motoki af3b7e4134 flake8-import-order: Ensure to place project imports last
To ensure project imports are placed after third party import,
we need to specify application-import-names.
Previously flake8-import-check checks only standard imports or not.

Change-Id: I9beb2105f686dc7d9aebfce8e21c5e182698e2fe
2017-09-20 01:19:38 +00:00
Eddie Ramirez d6f1d117b4 Add server-side filtering Floating IPs
References for field selection:
https://developer.openstack.org/api-ref/networking/v2/index.html?expanded=list-floating-ips-detail
https://github.com/openstack/python-neutronclient/blob/master/neutronclient/neutron/v2_0/floatingip.py

Co-authored-by: Eddie Ramirez <eddie.ramirez@intel.com>
Co-authored-by: David Lyle <dklyle0@gmail.com>

Implements blueprint: server-side-filtering

Change-Id: I614f0b1d9cf685aed3e3663d512a4ccd92455093
2017-09-14 23:30:57 +00:00
Mykhailo Dovgal ca0f293cb6 Fix tenant_quota_usages function calls caching
This patch changes type of 'targets' input parameter in
tenant_quota_usages function from list -> tuple. It provides
possibility for @memoized decorator to cache function calls.

Change-Id: I3c32c3b65ae91e8487fda6148f259fe1931d7c9f
Closes-Bug: #1700578
2017-06-26 17:36:07 +03:00
Jenkins 829a961d73 Merge "api.neutron: Explicit member of FloatingIpTarget class" 2017-06-14 12:10:03 +00:00
Akihiro Motoki cabdbcccb3 api.neutron: Explicit member of FloatingIpTarget class
This is a minor refactoring.
Members of FloatingIpTarget class is not clear.
From maintenance perspective, it would be nice if we have
explicit member definitions in the class definition.

TrivialFix

Change-Id: Iaaf5f8351e8ea35d19dc79c8dbfcc256f70d2e63
2017-06-14 09:05:18 +00:00
Akihiro Motoki 359467b401 Retrieve quota and usage only for resources really required
tenant_quota_usage() is used to retrieve quota and usage
to determine if a resource can be created.
However, tenant_quota_usage retrieves quota and usage for
all resources and it can be a performance problem.

This commit allows to load quota and usage only for resources
which are actually required.

Closes-Bug: #1675504
Change-Id: Iab7322a337a451a1a040cc2f4b55cc319b1ffc4c
2017-06-14 08:53:32 +00:00
Akihiro Motoki 9067ae8b0f Move SG and FIP API wrapper to api.neutron
We no longer need to have SG and FIP API wrapper in api.network
as we only supports a single network back-end.

Completes blueprint drop-nova-network

Change-Id: I4e59d897508b497a3cd2ae2fda93b30b786610dc
2017-06-04 17:51:25 +00:00
Jenkins 2516446b44 Merge "Fix quota of floating IP usage" 2017-05-21 21:43:54 +00:00
Akihiro Motoki acd3f2a240 Drop novalclient security group and floating IP dependency
novaclient 8.0.0 dropped python bindings for security group and
floating IP. This commit drops security group and floating IP logics
from the nova API wrapper.

The following changes are made accordingly.

* Update unit tests to consume neutron test data
* Drop API unit tests for nova security group and floating IP

Partially implement blueprint drop-nova-network
Change-Id: I946c508d7a82162fc8434213e006513867b79350
2017-04-28 08:38:28 +00:00
Akihiro Motoki f23c84189c Drop Nova SG and FIP related unit tests from dashboard code
Previously security group and floating IP tests covered
both nova and neutron APIs. This commit drops Nova security
group and floating IP unit tests. All these unit tests now
consumes neutron API wrapper and neutron test data.

Partially implement blueprint drop-nova-network

Change-Id: I1e3ad42cbeb90c00be29784869108d3d0db83162
2017-04-28 08:35:39 +00:00
Akihiro Motoki 8b6d3422e8 Drop Nova floating IP dependency from dashboard
This commit drops Nova floating IP dependency from
the dashboard implementation.

* Use neutron policy for floating IP operations.
* SimpleAssociateIP is supported only by Nova API,
  so the action was removed in this patch.

Floating IP support in the nova API wrapper will be dropped
in a separate patch.

Partially implement blueprint drop-nova-network

Change-Id: I1610fb9aa2212b3f34814fdb9894b715a5211d9c
2017-04-28 08:28:41 +00:00
MinSun af8a01b362 usage: Ensure to count resources of a given project
When retrieving resource usage, the current code calls subnet_list
twice for shared=False/True, but 'shared' attribute of subnet is
not defined in the Networking API and actually there is no need to
use it (even though it works as expected accidentally).

What we need here is to specify tenant_id as a query parameter
with a single API to limit the scope to a given project.

The same way can be used for network_list() and router_list() calls
and it is more efficient. By doing so, we now need only one
network_list() call.

Change-Id: I40d61ed9cbae4b083e4f3cec9caa269e92daf306
Closes-Bug: #1663170
2017-04-13 09:40:15 +00:00
Akihiro Motoki c4a59296fa Fix quota of floating IP usage
Closes-Bug: #1681756
Change-Id: I2629833e282631e8dc44e5574f017b0754e20f0a
2017-04-11 10:19:08 +00:00
Jenkins 24a4905f5e Merge "Update Horizon to use latest nova policy rules for validation" 2017-04-05 20:34:46 +00:00
Gábor Antal 34a3aa0ba8 Handle log message interpolation by the logger
According to OpenStack Guideline[1], logged string message should be
interpolated by the logger.

[1]: http://docs.openstack.org/developer/oslo.i18n/guidelines.html#adding-variables-to-log-messages
Change-Id: I51f50935f1eeffe4960562d6309dfdf05814e595
Closes-Bug: #1596829
2017-03-31 20:59:16 +09:00
Akihiro Motoki baa4ca8dce hacking: noqa cleanup in openstack_dashboard
attribute-level imports are not checked by hacking module now.
most noqa is used to disable warnings on attribute-level imports.
This commit drops noqa for this purpose.

After this, there are only 3 noqa under openstack_dashboard/ :)

Change-Id: I4a449802f5dbd6e44e4b8b5c378a555d47d9a99f
2017-03-17 19:38:47 +00:00