Commit Graph

302 Commits

Author SHA1 Message Date
Zuul 061380cba7 Merge "fix: ignore errors when flavors are deleted" 2024-03-04 07:20:21 +00:00
Rodrigo Barbieri 95089025fd Extend configurable skippability of neutron calls to project instance detail
The OPENSTACK_INSTANCE_RETRIEVE_IP_ADDRESSES config aids
in envs struggling to load the instance list due to having
too many ports or bad neutron plugin performance. However,
the config does not apply its effect to the instance detail
page, which cannot be loaded due to the neutron calls
taking too long.

This patch extends the config option to the instance
detail page, allowing the same benefit (and side-effects)
of the instance list page.

Related-bug: #2045168
Change-Id: I3e71a208a1c7212e168d63a259f2adddf27dbabf
2024-01-29 15:11:33 +00:00
okozachenko aa21f4baa3 fix: ignore errors when flavors are deleted
The code used to list flavors when in the admin
or project side was not consistent and raised
alerts if viewing in the admin side but not in the
project side.

This patch moves their behaviour to be consistent
and refactors the code to use the same code-base.

Closes-Bug: #2042362
Change-Id: I37cc02102285b1e83ec1343b710a57fb5ac4ba15
2023-11-02 01:27:40 +11:00
Thomas Goirand 8770753fcc Specify transform=repr in assertQuerysetEqual()
Previously "repr" was automatically applied to "qs" argument of
assertQuerysetEqual() and most horizon unittest behaviors assume it.
It was deprecated in Django 3.2 and removed in Django 4.1. We need to
specify transform=repr explicitly to use the existing behavior.

[1] https://docs.djangoproject.com/en/3.2/topics/testing/tools/#django.test.TransactionTestCase.assertQuerysetEqual

Closes-Bug: #2038474
Change-Id: Ie7c7e9a1efc492889639e25509c8e614268c1d26
2023-10-23 14:24:49 +09: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
Tatiana Ovchinnikova d0e9e976f2 Fix flavor specification at instance overview page
The details page uses flavor id to resolve instance flavor, relying
on legacy Nova API v2.46. This patch adds the current Nova API
option, resolving instance flavor by flavor name, so flavor
specification at instance overview page is displayed properly.

Change-Id: I1fe45063c9d1cdd8682998329d81f843d30f80b3
2022-09-29 18:49:01 +00:00
Akihiro Motoki f2832f3b09 instance UT: Recover mock_server_get.return_value
https://review.opendev.org/c/openstack/horizon/+/830630 dropped
mock_server_get.return_value by mistake. This commit recovers it.

Change-Id: Icedb1d206aca1c8eeac51e76b3c92c26b40f0806
2022-03-09 09:50:58 +09:00
Akihiro Motoki a7956cd004 Avoid extra flavor_get in resize server form
commit d269b1640f fixes the bug on
the resize server form, but it introduced an extra flavor_get call
even when we retrieve the list of flavors. This commit recovers
the previous behavior that we first looks up the list of flavors.

Related-Bug: #1940834
Change-Id: I891aa6b8652f330326535732d0886362dfabb989
2022-03-04 22:50:42 +01:00
Zuul 6a64bdd625 Merge "Get ports directly instead of via loop" 2022-02-25 19:08:44 +00:00
Zuul b2b12bbf9c Merge "Follow-up: Drop Django launch instance (part 2)" 2022-02-25 17:07:48 +00:00
Nicolas Bock 9f5d659d16 Get ports directly instead of via loop
In order to get a list of available ports, the current implementation
of the form code in `project/instances/attach_interface` loops through
the available networks in the project and requests a list of ports for
each via the Neutron API. This implementation is O(N) in time with a
large prefactor (the time for a Neutron API call) where N is the
number of networks.

Instead of calling the Neutron API for each network this change uses
one call to the Neutron API to get the list of ports on all networks
and filters this list via a list comprehension. While this
implementation is still O(N) the prefactor is significantly smaller.

Closes-Bug: #1943639
Change-Id: I8fd32c3aad22d8ef7f57201f5144f6b2e357ef10
Signed-off-by: Nicolas Bock <nicolas.bock@canonical.com>
2022-02-24 16:23:38 +09:00
Akihiro Motoki 3c4accf94f Follow-up: Drop Django launch instance (part 2)
This is another follow-up of dropping the django version of the
launch instance form. ResizeInstance workflow was cleaned up
as a follow-up in [1] and "config_drive" field no longer exists.
This commit drops an unnecesary check for "config_drive" field in UT.

[1] https://review.opendev.org/c/openstack/horizon/+/826262/

Change-Id: Ic3c458f70b146299f41a3ac02b78ddc156e02d93
2022-02-16 19:35:33 +09:00
Vadym Markov d269b1640f Fix for "Resize instance" button
Currently, "Resize instance" widget is not working because it relies on
legacy Nova API v2.46, obsoleted in Pike release. Proposed patch make
Horizon use current Nova API (>=2.47).

Closes-Bug: #1940834
Co-Authored-By: Akihiro Motoki <amotoki@gmail.com>
Change-Id: Id2f38acfc27cdf93cc4341422873e512aaff716a
2022-02-16 16:07:55 +09:00
manchandavishal 6ac31e0ba8 Drop Django based implementation of launch instance
horizon already deprecated launch instance Django based implementation
in the wallaby cycle [1]. This patch remove code for launch instance
Django based implementation as angular based implementation is the
default one from long and all features gaps between angular and Django
implementation is closed.

It also moves SetAdvanced step code to ``resize_instance.py`` as
``workflows/create_instance.py`` file is deleted and remove server_group
option from Advanced Options of resizing instance action because
"server_group" is not required while resizing an instance as per
nova-api reference [2].

Closes-Bug: #1869222

[1] https://review.opendev.org/c/openstack/horizon/+/779125
[2] https://docs.openstack.org/api-ref/compute/?expanded=resize-server-resize-action-detail#resize-server-resize-action

Change-Id: I5e01cd81f309491f1a58ea93911030366a86e3c7
2022-01-24 16:21:18 +05:30
Akihiro Motoki a0dd4d738c Support Django 3.0 and 3.1 support (3)
The result of the encoded (i.e., escaped) text in HTML changed
between Django pre-3.0 and 3.0+. For example, decimal and hex encoding
are semantically same but they are different in literal texts.
While I don't know what triggers this change, I think it makes sense
to compare these texts after decoding as HTML.
Considering this, html=True is passed to self.assertContains().

When passing html=True, a text in an HTML element is not compared
partially and a full text as a value of the HTML element is compared,
so we need to pass the full text of an HTML element value now.

I believe the above change is caused by the change that django.test.html.Parser
is initialized with convert_charrefs=False previously. On the other hand,
it is not specified now in Django 3.0+ [1]. This leads to the situation that
escapes on unicode characters are handled differently.

[1] 48235ba807

Change-Id: I0f26436eb384a95f8446d8fd447c9577d50a5c21
2021-09-14 19:35:05 +00: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
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
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
Zuul f90c3cd501 Merge "Use python3-style super()" 2020-10-27 04:42:53 +00: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 b79ebc85b0 Drop remaining glance v1 related code
We dropped glance v1 support in ussuri.
glance v1 related tests still exist in the project instance test.

Change-Id: I3079c579a1f3d42e5b02fc224f7677ea86583a7e
2020-09-12 10:58:20 +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
Ivan Kolodyazhny e976461d85 Remove six usage from horizon 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: I0b567382edf4d68674a7b8d0b02333fb57293958
2020-01-15 12:36:11 +02:00
Akihiro Motoki a2a3e8b6c3 Drop Django 1.11 support
Django 1.11 support was dropped. Django 1.11 ends its extended support
in April 2020 which is before Ussuri release. Considering this,
horizon dropped Django 1.11 support.

Unnecessary Django version checks in the code are also dropped.

Change-Id: I2c58934f2b026745fbc97a58212b91d149db3657
2019-12-29 06:20:37 +09:00
Adam Harwell 70629916fe Use quoting for CSV Writing
An attacker could create an instance with a malicious name beginning
with an equals sign (=) or at sign (‘@’).
These are both recognized in Excel as metacharacters for a formula. The
attacker can create an instance name that includes a payload that will
execute code such as:
=cmd|' /C calc'!A0
This payload opens the calculator program when the resulting CSV is
opened on a Windows machine with Microsoft Excel. An attacker could
easily substitute this payload with another that runs any arbitrary
shell commands.

Quote the CSV output so this is no longer a possibility.

Closes-Bug: #1842749
Change-Id: I937fa2a14bb483d87f057b3e8be219ecdc9363eb
2019-10-11 19:52:08 +00:00
Stephen Finucane f654c893ec django22: django.test.client.encode_multipart no longer accepts None
As seen here [1]. With this change, all test are passing with Django
2.2.

[1] https://github.com/django/django/commit/6fe9c45b725

Change-Id: Idef0bd9dff4b27d22cfb756fc248c5c6bd24e097
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2019-09-11 07:25:03 +09:00
Zuul a87ca08160 Merge "Allow to select multiattach volume that has been attached" 2019-08-08 07:52:16 +00:00
shutingm 86e1960f99 Allow to select multiattach volume that has been attached
When one multiattach enable volume is attached to one instance,
it can be only attached to another instance by cli. This patch
allows users to do so from horizon

Part of blueprint multi-attach-volume

Change-Id: Ic65d84d00a9113b7ee71f06b9c41cd09dcaa1325
Co-Authored-By: Vishal Manchanda <manchandavishal143@gmail.com>
2019-07-30 10:33:26 +00:00
Akihiro Motoki 42f4ef334d Do not always assume image_id in volume_image_metadata
volume_image_metadata can contain only fields other than image_id.
We should not assume volume_image_metadata always contain image_id
when volume_image_metadata exists.

Change-Id: I0db8a05e488eb6bf276760d5116d05633c882701
Closes-Bug: #1834747
2019-07-29 18:18:56 +00:00
Akihiro Motoki 82a20c670a Fix boot-from-volume test in project.instances.tests
The test for the instance table with boot-from-volume had
several issues previously.

a) api.cinder.volume_list is mocked but return_value was not
   specified and called arguments were not checked.
b) The mocked api.nova.server_list returned Server instance
   from novaclient, but it should return Server instance from
   the horizon API wrapper (api.nova.Server). As a result,
   for example, "image_name" property in api.nova.Server
   was skipped.
c) Test data for cinder volumes had wrong attachment information.
   attachment ID must match a volume ID, but it did not.

This commit fixes the above issues and adds a test logic to
check volume_image_metadata handling in instances/views.py.

This is a preparation to implement a unit test in
https://review.opendev.org/#/c/668595/.

NOTE:
The issues (a) and (b) above need to be fixed globally
in the openstack_dashboard testing, but it will be covered
by follow-up commit(s). This commit focues to prepare for
https://review.opendev.org/#/c/668595/.

Change-Id: I7ebb68220f75fef36b43b89e32e5aff18fc0fe25
2019-07-26 21:58:34 +09:00
Akihiro Motoki 363802d9e9 Avoid using nova volume test data for cinder API mocking
self.volumes from nova test data is used as return values
of cinder API wrapper mock. Nova test data is based on
novaclient.v2.volumes.Volume class. This is not correct.
They should be based on cinderclient Volume class.

This commit changes to use cinder test data for
return values of openstack_dashboard.api.cinder mock.
'bootable' attribute is required, so it is added to cinder_data.

This confusion comes from the naming of self.volumes.
This commit renames self.volumes to self.nova_volumes
to avoid further confusions.

Note that api.nova.instance_volumes_list() calls get_server_volumes
from novaclient and it is correct to use self.nova_volumes.

Change-Id: I9c431dbb03f90bab84a4a6a3e3ea8fd5a5498b5b
2019-07-18 04:11:19 +09: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
Zuul d254dac067 Merge "Adds community image loading for instance index view" 2019-06-19 11:18:00 +00:00
Marek 6f807b6b05 Adds community image loading for instance index view
This patch adds community image loading to the Instances index view
so that image names may be displayed in this view even for community
images.

Note, that a second image list API call had to be added to achieve
this, because the glance Rest API does not currently support adding
multiple visiblity values to it's GET filters and community images
have to be retrieved explicitly.

Change-Id: I55249de8762e0744b69ff655fcd7a4aeb56ba9d6
Closes-Bug: #1818823
2019-05-29 05:54:47 +00:00
Akihiro Motoki 9c19b07a26 Define default settings explicitly (openstack_dashboard 1/5)
Currently horizon defines default values of settings in the logic
using getattr(settings, <setting name>, <default value>) and
it is not easy to handle the default values of available settings.

This commit starts the effort to define default settings explicitly.
This is a preparation for ini-based-configurations.

It covers settings in openstack_dashboard/api.

Part of blueprint ini-based-configuration
Change-Id: Id4c3287f0a572fd14ea93b54bcab8fabda39e583
2019-04-24 02:32:47 +09:00
Dmitriy Rabotjagov 3c82a38f71 Display first volume image_metadata as an instance image
When instance is created from cinder volume, it's image is not displayed
Nowdays using cinder as instance source becomes more widespread,
so there is sense in displaying instance image,
when instance is created from cinder volumes.
We're trying to get volume_image_metadata from the first volume of
the instance, when instance doesn't have image attribute itself.
First volume is suggested based on its device name (eg. '/dev/vda').

This info is displayed only in instances list, not in detail overview.

Change-Id: I00aa9ef07d1680bb2390a30271bb39cd7bea6329
2019-03-06 20:46:05 +02:00
Zuul 7649526278 Merge "instances.tests: Set return_value for tenant_absolute_limits" 2019-02-15 14:39:00 +00:00
Akihiro Motoki 1ca0c6f6ec instances.tests: Set return_value for tenant_absolute_limits
Previously tenant_absolute_limits was mocked but return_value
was not set properly. As a result, MagicMock() is compared to
an integer and this causes TypeError in python 3.

Change-Id: I4c912c77f28df816811b9bb1667629548f3998c4
Closes-Bug: #1815287
2019-02-09 21:43:32 +09:00
Akihiro Motoki 949802264e pylint: fix cyclic-import
openstack_dashboard/api nova.py and cinder.py are imported
by each other. To avoid cyclic imports, some imports are placed
inside functions now, but it would be nice if we can move them
to a separate module and nova.py/cinder.py can import it.

This commit tries to achieve this by moving some stuffs in nova.py
into a separate module named _nova.py.
The module name starts with an underscore to clarify
it is intended to use only in openstack_dashboard.api.

Change-Id: If91cf4f30d2ddab471757129c2a74b26b6d38b1e
2019-02-09 21:08:48 +09:00
wangliangyu 3ac9037677 Table checkbox display problem when updating row
Multi-process:
  If there only one table action, DeleteAction.
  Assume the first time retrieving an empty table in one
  process, the checkbox is hidden.
  In the other process, creating a item, like a instance.
  Now, the checkbox is shown in second process.
  Then updating the item state in first process, the checkbox
  will be hidden. In second process, the checkbox will be shown.

  For above case, we need set the checkbox visibility every time
  when updating single row by ajax.

Change-Id: Ib230ad775070ee089c8f82e7df3ec30c1cda7aa0
Closes-Bug: #1799151
2019-02-09 16:52:44 +09:00
Zuul 400d3559a3 Merge "the name needs to be word wrap" 2019-01-10 21:44:11 +00:00
Zuul ccaf2eb435 Merge "Changed the message level for deleting some resources to info" 2019-01-07 10:12:08 +00:00
pengyuesheng 3d899d9078 the name needs to be word wrap
if the name is too long,
it will affect the display.

Change-Id: Ib1e35d32b0b3f82a0f949d94a2f4c8bcfd4eff41
Closes-Bug: #1801862
2019-01-07 14:29:44 +08:00
Zuul 3a7ff423ff Merge "Better support for community images" 2019-01-03 13:19:41 +00:00
Simon Collins 2a3b04ce6c Changed the message level for deleting some resources to info
Added functionality to the handle function in the BatchAction class
in action.py and allowed the easy changing between the alert types
and made deleting images, instances, and volumes give an info alert
rather than a success message and altered the testing parameters

Change-Id: I93251d6d12cf89a331b5c051bf4fe10a6e470f51
Closes-Bug: #1291681
2019-01-03 18:45:08 +13:00
Ferenc Cserepkei 4676694179 Add "prev" link to instance page list pagination
Currently there is no link to previous page at paginated instances
table. This patch resolves that issue by re-using the pagination
code for flavors.

It also supports Ying Zuo's scenario:
After I set only 1 item per page and deleted the instance on the first page,
the expected behavior is showing the next instance in the table after one is
deleted.

xxxIndexView uses PagedTableMixin's _get_marker() from now instead of GET()-
ing the markers

Closes-Bug: #1274427
Co-Authored-By: Dmitry Ratushnyy <dratushn@cisco.com>
Co-Authored-By: Akihiro Motoki <amotoki@gmail.com>
Change-Id: Id8eaae6bf1b5d6f42291291655e14b8715c08bc8
Signed-off-by: Ferenc Cserepkei <ferenc.cserepkei@ericsson.com>
2018-12-28 20:46:11 +09:00
Andy Botting d641e6d105 Better support for community images
This commit updates several places where image information is processed
and extends support for the 'community' image visibility value.

Some support did exist already, which was mostly just the main Images
tab of the dashboard, but this commit also includes support for:
  - image name in the instances list/details
  - 'Community' visibility label in the Images tab
  - Listing of community images in launch instance wizard

Closes-Bug: #1779250

Change-Id: Iedea0b7d20313837a72a2759511251a7bb324869
2018-12-27 09:04:53 +09:00
pengyuesheng ffa8b5404e Support of rescue instance in Horizon
Change-Id: Ie195befde8fe10ce419583ead06fdb759dd3813c
Implements: blueprint instance-rescue-horizon-support
2018-11-20 10:25:37 +00:00
wangliangyu 5f4057f8b5 Show snapshots list correctly when launching instance
In launch instance modal, when a user selects 'Instance Snapshots',
not all snapshots are listed. The snapshots which are created from
an instance with new volume or an instance created from volume
or volume snapshot don't have 'image_type' but 'block_device_mapping'.
So, judging only by image_type is not enough.

Change-Id: I7e175b6a7260ca3d82560427a8f742f8cfa35565
Closes-Bug: #1627619
2018-11-06 22:06:52 +00:00