Commit Graph

48 Commits

Author SHA1 Message Date
Pedro Kostelec ae7896cea5 Consisent abbreviation of size units
Most units (KB, MB, GB, TB, PB) are shown in an abbreviated format.
The exception were bytes, which where shown as "Bytes". This commit
resolves this inconsistency by showing "B" for byte units.

Change-Id: Ied94c777a70bf8955f5a328ffcb63d98a7a2befd
Closes-Bug: 1411595
Signed-off-by: Iago Estrela <hiagoestrelas@gmail.com>
2021-05-04 11:50:17 -03:00
Akihiro Motoki 1dd12d8deb test: Ensure to stop mock when create_mocks decorator exits
During reviewing https://review.opendev.org/c/openstack/horizon/+/772603,
we noticed that a method decorated by create_mocks is called multiple time
in a single test. Previously create_mocks decorator does not stop mocking,
so this means that multiple active mock can exist for one method.
In general, it is not a good idea to mock a method multiple times at the
same time.

To cope with this situation, this commit ensures for create_mocks decorator
to stop active mocks when exiting the decorator.

This works for most cases, but it does not work only when mocking and
assertions are handled by separate methods and test logic is placed between
them. To cope with this, "stop_mock" optional argument is introduced.

FYI: Details on why "stop_mock" is needed.
I explored various ways but could not find a good way so far.
create_mocks needs to be a decorator as it needs to refer an object
reference (self). On the other hand, if we would like to merge the logic of
mocking and assertions (for example, _stub_api_calls() and _check_api_calls()
in openstack_dashboard/dashboards/project/overview/tests.py), a context
manager would be good as we would like to call it inside a class.
However, we cannot mix a decorator and a context manger as a decorator is
executed when a context manager is iniitialized and stopping mock in
the create_mocks decorator is done during the initialization of the
context manager and methods are not mocked when test code is run.

Change-Id: I9e37dc1eaa08adf36d11975fed6f5a0a90cdde52
2021-02-26 18:44:11 +09:00
Akihiro Motoki c45cc6b1c5 Drop the usage of nova extensions in python code
Part of the removal of OPENSTACK_NOVA_EXTENSIONS_BLACKLIST (1/3)

All references of nova extensions in the python code are cleaned up.
Note that the API layer is not touched yet as it is used by the
JavaScript side.

Change-Id: I66cd0a9629253a6462aace9902ef8200b94b2a21
2020-10-27 20:00:45 +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
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 f897837444 usage: Categorize Limit Summary by service
blueprint make-quotas-great-again
Change-Id: Ia030defa851d8ce3e9a5e225dbf9c360b2b0c09a
2018-04-20 05:34:33 +09:00
Akihiro Motoki 7fabda7ef1 usage: Use tenant_quota_usages() for Limit Summary
Previously we have almost duplicated logic for the limit summary
and quota usages. This commit shares the logic.

blueprint make-quotas-great-again
Change-Id: Ie5d7e51c9424701fdbcbfbcb1032c0b833a69371
2018-04-20 05:29:53 +09:00
Akihiro Motoki dd560d95fd Convert project tests into mock: api_access/backups/overview/snapshots
Partially-Implements: blueprint mock-framework-in-unit-tests
Change-Id: I5a61d26d21f14ec44e8e82f6539196d53b6783fd
2018-03-07 23:27:00 +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
Akihiro Motoki df0a18e7a3 quota: retrieve quota (limit) and usage at once
Previously tenant_quota_usages() uses list API operations
to count usages. It is not efficient. This commit changes
the limit APIs from nova and cinder to retrieve usages.

blueprint make-quotas-great-again
Change-Id: I2c9a479758a1dfe134e5fabf16ab02831338718d
2017-12-13 20:27:02 +09:00
Ivan Kolodyazhny 8f4e02c96d Show NotAuthorized error message on a separate page
Change-Id: I02d9d610a0e5feff7da14f86d003ec21010ab26a
Closes-Bug: #1709077
2017-08-29 16:37:04 +03: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
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 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
Bin Zhou 9afd7d0875 Modify use of assertTrue(A in B)
Developers should use assertIn(A, B) instead of assertTrue(A in B ).

TrivialFix

Change-Id: I93f3c540e4cc9015162283ea71813613a13e3555
2016-09-03 11:26:52 +08:00
Jenkins 12d7d0bc72 Merge "Make sure we always get all limits" 2016-06-24 02:42:40 +00:00
Itxaka 35eb25a955 Make sure we always get all limits
When checking with nova for the absolute limits
we were not taking into account the reserved
quotas (i.e. instance in rebuilding will take
cpu and ram) so this could lead to wrongly
thinking that the user could launch more instances
that its quota allowed. It also made the overview
page display wrong quotas as it didnt took into
account those reserved resources.

Change-Id: If51470d185ddc122acbdf4cf0d0fd952f3f791a0
Closes-bug: 1561310
2016-06-08 10:40:46 +00:00
Timur Sufiev 5da5fd3196 Reduce the default date range on Overview panel to 1 day
First, the default default date range used on Overview panel is made
configurable (setting OVERVIEW_DAYS_RANGE). Second, its default value
is set to 1 day. Changing the default behavior is aimed to improve
load time of the default page in the presence of large amounts of
data. If OVERVIEW_DAYS_RANGE setting is explicitly set to None, the
behavior remains the same - the default date range is from the
beginning of the current month until today.

Co-Authored-By: Dmitry Sutyagin <dsutyagin@mirantis.com>
Change-Id: I55a0397f69e33ba9c8fb1f27d57838efcd8648af
Closes-Bug: #1508571
2016-05-31 17:57:53 +03:00
IWAMOTO Toshihiro 2e59431227 Look for volumev2 endpoints instead of volume
Volumes tabs should be enabled when volumev2 endpoint is registered.
Currently, Horizon considers no volume service is running if there
is no V1 endpoint, which doesn't make sense as Horizon no longer
supports the cinder V1 protocol.

Co-Authored-By: itxaka <itxaka@redhat.com>
Change-Id: I35d821eedb75f73f9330ed11f921694104eed0c6
Closes-Bug: 1415712
2016-02-23 11:47:25 +01:00
LiuNanke f96797a006 Replace assertTrue(isinstance()) with assertIsInstance()
Some of tests use different method of assertTrue(isinstance(A, B)) or
assertEqual(type(A), B). The correct way is to use assertIsInstance(A,
B) provided by testtools.

Change-Id: Ib44771be349f359376e35d7673192bc62805b1c2
Closes-Bug: #1268480
2015-12-31 00:05:14 +08:00
Vlad Okhrimenko 878c703fd0 Logout user if he has no valid tokens
Before this patch, if user's rights were changed
or revoked - there would be "Unauthorized" errors
on every page since user had no rights to view them
because he had no valid tokens in that case.

Now user will be logged out if he has no valid tokens.
Set `escalate` to True (for unauthorized-error)
to always log user out.

Also, now horizon.exceptions.NotAuthorized is a part of
UNAUTHORIZED tuple in the exceptions.py, because this type
of exception is re-raised after handling services unauthorized errors.
Looks like it was missing. Now the horizon.exceptions.NotAuthorized
is handled like all NotAuthorized exceptions.

And horizon_middleware.py in process_exception now generates
logout_reason for cases if user is not authorized.

Closes-Bug: #1252341
Closes-Bug: #1407105
Co-Authored-By: Paul Karikh <pkarikh@mirantis.com>
Change-Id: I417cad936ea80c0569c2f442fc87cbd58745757e
2015-08-29 04:02:54 +00:00
Victor Stinner 674a45ffe0 Replace mox with mox3
mox doesn't work on Python 3, whereas mox3 works on Python 2 and Python
3. Cinder, Nova and many other projects already replaced mox with mox3.
mox3 is now maintained by OpenStack.

Partial-Implements: blueprint porting-python3
Change-Id: I10e6a9754ebd58a2640d73ec8966527c3aa1fe9a
2015-07-13 15:02:10 +02:00
Bradley Jones 286245b423 Refactor quota limit summary template
Refactor the quota limit summary template to allow easier customisation.
Also change it so that it removes the 'of' when there is no quota limits in
place so that it just reads Used 'x' (No Limit).

Added tests for checking usage['charts'] is in the context and that (No Limit)
is present when there is an infinite quota on the page.

Change-Id: Iba62ca89e53f0d6b9c583e4cc450e853c18ba107
Closes-bug: 1439717
2015-05-26 11:39:52 +01:00
Bradley Jones f9048484bd Refactor project overview tests
Use decorators for creating stubs and remove duplicated code

Change-Id: I16764ae417f5cf544dd6d6521707591d52fb5172
Closes-bug: 1441591
2015-04-08 14:58:30 +01:00
Akihiro Motoki f99981fc9c Fix E127 errors in openstack_dashboard/dashboards/project/
E127 continuation line over-indented for visual indent

Partial-Bug: #1375931
Change-Id: Ia62781d24f13407ca600743b167392dddf6c271d
2014-10-11 13:33:28 +09:00
Akihiro Motoki 9ea081ef6c Display Network panels based on neutron ext-list
Neutron features like LBaaS, FWaaS or VPNaaS are provided as
extensions in Neutron. This commit changes these features are enabled
only when they are included in the extension list from Neutron.

It also change the default settings of enable_lb/firewall/vpn to True.
The default of these settings were set to False to avoid confusion to
users because LB/FW/VPNaaS are optional features in Neutron. By this
commit corresponding features in Horizon are enabled dynamically, so
it is reasonable to change the default to True.

This commit introduces Horizon version of override_settings
"update_settings" decorator which allows override an item in dict.
Django original override_settings replaces a dict completely,
however OpenStack dashboard setting has many dictionary configuration
and there are test case where we want to override only one item
in a dictionary and keep other items in the dictionary.
This version of override_settings allows this.

DocImpact

Implements blueprint neutron-feature-control-with-ext-list

Change-Id: I19424d448c800524de0ee8ac769974272dbb84a0
2014-09-02 03:48:32 +09:00
Akihiro Motoki 936fc59aa8 Disable Floating IP features if Neutron router is disabled
If the config option 'enable_router' is set to False,
Floating IP features are disabled when Neutron is enabled.
It does not affect when Neutron is disabled.

It also adds unit tests for api.network.servers_update_addresses
which is affected by this change.

Completes blueprint hide-router-panel-by-config
Closes-Bug: #1292022
Change-Id: Ib63c6a0e7bb5661d4a60d10a1722fdad978b50bb
2014-08-30 05:12:27 +09:00
Jiri Tomasek 92146772b6 Update Twitter Bootstrap to version 3
Updated to bootstrap 3.2.0
back to v3.1.1
fix base-line-height variable
Revamped grid system
Replaced help-inline with help-block
Change .control-group to .form-group
Add column widths to horizontal form labels and .controls, remove .controls class
Datepicker form fix
Add btn-default to btn elements with no other color
Topbar switcher fix
Rename button sizes
Replace alert-error with alert-danger
Removed alert-block
Alerts fixing
Updated LinkAction and Action table actions to define icon, replaced btn-default icon with glyphicon
Replaced icons with glyphicons, removed btn-icon styling from horizon.scss
change Button Icons text in customizing docs
Fixed table header
Fix page_header h2 margin
Nav accordion fix
Tables fix
Modal fixes
added form-control class to input and selects
Forms fixes
Workflow modal fix
Fix quota bar
updated customizing docs
removed unused styling from horizon.scss
make datepicker form inline
fix table filter styling
added btn-danger to terminate instances button
fixed loading spinner
form fields and validations
Created bootstrap_form_field filter and template to render bootstrap forms properly
Style up the datepicker
Fixed failing test cases

Implements: blueprint bootstrap-update

Change-Id: Ic826849be1af7fc6bf06f97dd7a60fc54b862148
2014-07-28 16:13:21 +02:00
Akihiro Motoki ea0000f6a0 Handle error from neutron extension check in Overview page
Previously some Neutron API calls in get_neutron_limits are outside
try/except and if an error occurs a traceback will be displayed.

Change-Id: I191aecbf3135ddac3b20dbc7e0f22b63aa3837f9
Closes-Bug: #1252878
2014-06-07 18:26:52 +09:00
He Yongli e790ac070e Remove extraneous vim configuration comments
Remove vim setting:
comment - # vim: tabstop=4 shiftwidth=4 softtabstop=4

at the top of source code files, except for files in
openstack/common.

Change-Id: I9a5c6b17c6ef7ecec601f4503dfc7b31fc72e90a
Close-bug: #1229324
2014-05-06 15:30:10 +08:00
Thiago Paiva Brito 497f69aef3 Correct default usage filtering on overview page
On the overview page, the usage data showed by default was not filtered by
the dates shown on the date selectors. This can lead the user to wrong
conclusions about resource usage.

This patch corrects the default filtering dates to match the dates showed
by default on overview (first day in the month to current date).

Change-Id: I37a240d784ca0826821c125f06922d2c1d1e8659
Closes-Bug: #1294668
2014-04-14 11:44:22 -03:00
Tatiana Mazur 193f624e1b Remove leftovers of "# noqa"
This patch set removes leftovers of "# noqa" from imports
added to import_exceptions.

It also adds "django.test.utils.override_settings" to
import_exceptions, so a few more "# noqa" tags become
unnecessary.

Closes-Bug: #1273647

Change-Id: I39f856ac3ea371a2fcab272bbf358d0243164b6d
2014-01-28 15:51:04 +04:00
Radomir Dopieralski 028332da4a Remove #noqa from most common imports and add them to import_exceptions
We have a lot of import with #noqa that is there to ignore h302,
because it's traditional to import and use a name directly, instead
of a whole module. This hides other errors and gives people the
impression that it's actually fine to import non-modules, you just
have to slap #noqa on those lines.

I went through the code and identified about a dozen names that are
most commonly imported this way. I remove the #noqa tag from them,
and added them to the list in import_exceptions.

I also removed a few unused imports that were revealed in the process.

Change-Id: I27afb8e2b1d4759ec974ded9464d8f010312ee78
2014-01-07 12:26:35 +01:00
Leandro I. Costantino 9bca5d3680 Add volume limits to project overview.
Commit d4b0ab4aa3 fixing
bug #1178694 removed volume quotas from project overview.
Cinder is not reporting Snapshot limits today, so that info
can't be added without including quotas again, defeating the
purpose of the original fix.
This fix will only add Volume Qty & Total Storage GB used (including
snapshot size, if any ).
Information is hidden if volume list is empty.

Partial-Bug: #1244875
Change-Id: Ia72e40329ecf08b57fb26cd847f02cececc53579
2013-11-29 06:19:40 -05:00
Romain Hardouin d43e49ae46 Handle the case no SimpleTenantUsage Nova extension
When the SimpleTenantUsage Nova extension is not enabled,
panels that include usages produce an error and
the usage table is useless.

Three panels use the SimpleTenantUsage extension:
- openstack_dashboard.dashboards.admin.overview
- openstack_dashboard.dashboards.admin.projects
- openstack_dashboard.dashboards.project.overview

This fix avoids errors and does not show the usage
table in such a case.

A context variable 'simple_tenant_usage_enabled' is now
available in templates rendered by usage.UsageView subclasses.

Unit tests now mock nova 'extension_supported' API.

Change-Id: Ib306846bf6c947572ba0e7c773125d03b3dbf68b
Closes-Bug: #1211470
2013-10-08 22:22:35 +02:00
Akihiro MOTOKI c44552fe66 Retrieve security group quotas from Neutron if enabled
Secuirty group quota information in Project overview charts,
Admin defaults panel, and Admin create/update project is
retrieved from Neutron secuirty group is enabled.

Neutron security group is enbled when Neutron is used Neutron
security group extension is supported by a backend plugin.

Also removes the logic to remove quotas of floating IP and fixed IP
when neutron is enabled in dashboards/admin/defaults/tabs.py.
quotas.get_default_quota_data() already handles it properly
and this logic is no longer required.

Closes-Bug: #1212600

Change-Id: I59f069931fad519ca4ec135b92df0040ec8fc230
2013-09-29 17:50:00 +09:00
Julie Pichon fde88906b3 Show Neutron floating IPs quotas on Overview
Display the correct limits and usage when Neutron is in use and the
quotas extension is enabled. If Neutron is enabled but the quotas
extensions is not supported, assume the floating IPs quota is
unlimited (a floating IP quota is expected to exist in other places,
e.g. Security and Access panel)

Because quotas may not be configured or enabled even if the extension
is available, add an 'enable_quotas' setting.

Partial-Bug: #1109140

Change-Id: Id6345f4700f0ff45be8ce8acb69cca0d4e05e14a
2013-08-26 16:39:27 +01:00
Tatiana Mazur 953d1b9793 Enable H302 check
This patch replaces some method imports with module imports and
makes H302 test enabled.

Fixes bug 1188531

Change-Id: Ibfbddeaa19cbbb244da58ffd5c918c41f03a0c65
2013-08-22 17:39:09 +04:00
Victoria Martinez de la Cruz 142a6e97fe Query a period of time for usage summary
Allows the user to pick a range of time
to query services usage data.

Fallback mode: the user will have to input
dates by hand if JavaScript is disabled.

Change-Id: I4cf4d4fd56fd450743b9d624dc066d6ed74df881
Fixes: bug #1102448
2013-07-25 09:50:42 -03:00
Tihomir Trifonov 0c0153a037 Improvements in csv export for usage data
Added a csv writer using the 'csv' library to format
properly exported data - escaping, encoding etc.
Added a HttpResponse-based class to handle csv generation
Added translation for the CSV columns and template.

Fix bug #1158383

Renamed few occurencies of 'tenant' to 'project'.

Also added a new 'project' in nova_data.py, which required
some refactoring of few tests, that didn't consider the current project
for project-based calls.

Note: I've added a StreamingHttpResponse example,
which is introduced in Django 1.5+ and being advised in the ticket.
However, my opinion is that at the moment we don't need this - it is
too complicated for the current usage.

Change-Id: I18bd70a23b7b8389c7c0f96dbf8794fea5e1e75b
2013-06-21 14:00:37 +03:00
Matthias Runge cea720e793 Sort imports alphabetically
This patch also re-organizes imports to import one per line.

Change-Id: Ia958e3a30a48d4308d08d51df243c1272425c316
Fixes: bug 1188529
Fixes: bug 1188537
2013-06-14 12:05:55 +02:00
Eric Peterson d4b0ab4aa3 switching to use limits instead of quotas
Fixes bug 1178694

Change-Id: I6fad061faf84079492338016fd2bada9a2e434f3
2013-06-05 15:40:37 -06:00
Kieran Spear ef26414b8d Revert "Improvements in csv export for usage data"
This reverts commit a4e583cffb

Fixes bug 1183441, bug 1183230, bug 1183310.
2013-05-23 16:50:57 +00:00
Tihomir Trifonov a4e583cffb Improvements in csv export for usage data
Added a csv writer using the 'csv' library to format
properly exported data - escaping, encoding etc.
Added a HttpResponse-based class to handle csv generation
Added translation for the CSV columns and template.
Improved consistency for exported data - now passing project name
instead of project id for csv export. Also added both project name/id
in the header of a project usage export.

Fix bug #1158383

Renamed few occurencies of 'tenant' to project.

Also added a new 'project' in nova_data.py, which required
some refactoring of few tests, that didn't consider the current project
for project-based calls.

Note: I've added a StreamingHttpResponse example,
which is introduced in Django 1.5+ and  being advised in the ticket.
However, my opinion is that at the moment we don't need this - it is
too complicated for the current usage.

Change-Id: Ic00626b273921fa5c6c89704b3a9e08b252aaeb0
2013-05-22 11:09:49 +03:00
Gabriel Hurley e1d12a4e49 Improve UX around "unauthorized" API exceptions.
Instead of blindly logging out the user when any API returns
a 401 or 403 response (which in most cases is due to a service
being down or misconfigured) we catch the error and inform the
user that they are not authorized for that data.

This is separate from being unauthorized for a dashboard or
panel in Horizon, since those are within our control and involve
security concerns around exposing admin functionalities to end
users. Those checks function as they have previously.

Fixes bug 1060426.

Change-Id: Ied800f10926ac5fb3b9ac1c1c26bbb4fa94a2557
2013-03-18 11:57:37 -07:00
Akihiro MOTOKI 12faaa5c30 Ensure to use api.<category>.<method>
In the current code both api.<method> and api.<category>.<method> are used.
Using api.<method> directly makes it difficult to identify which module
defined a method and forces developers to use unique method names among
projects. This commit removes api.<method> style method calls.

Change-Id: Iaefa1061f99b7865e02541df87c112a6b2868ec0
2013-01-22 20:37:12 +09:00
Gabriel Hurley cdcd8e3df6 Enable quota data from multiple sources.
Now that there are multiple projects with quota data (cinder, quantum)
we need to accommodate that data being aggregated in a centralized
fashion. This commit takes care of that for nova + cinder, and paves
the way for quantum later.

Fixes bug 1070022.

Change-Id: Ifc68c2dc681b2a7b4e7787e0b1a7dca1a970fc36
2012-10-24 12:53:42 -07:00
Gabriel Hurley cb8e7c1f8f Splits OpenStack Dashboard bits from framework app code.
Moves everything OpenStack-specific (dashboards, apis, etc.)
into the openstack_dashboard project, achieving a much
cleaner separation between the project-specific code and
the generic Horizon framework code.

Change-Id: I7235b41d449b26c980668fc3eb4360b24508717b
2012-10-11 11:47:50 -07:00