85 Commits

Author SHA1 Message Date
Stephen Finucane
e736394d1b tests: Add functional test for adding, removing SGs
The fix is in openstacksdk. Let's test it here though.

Change-Id: I661e6d66c8196e8c9ca8b9cda3d08e756e3d5877
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
Depends-on: https://review.opendev.org/c/openstack/openstacksdk/+/936947
Related-bug: #2089821
2024-12-09 13:56:58 +00:00
Stephen Finucane
f98006ca9d pre-commit: Migrate pyupgrade to ruff
Change-Id: Ic50d2a5e0bc9dcdfe29f382607135cab510cd396
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2024-09-12 18:08:23 +01:00
Stephen Finucane
628ac48901 compute: Always use SDK client to display server
This affects the 'server create', 'server show', 'server rebuild' and
'server set' commands. We also fix a few mistakes around the fields
shown.

Change-Id: I9946e12146efff39f9ba1591c90a4a9bccd46919
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2024-07-08 12:00:49 +01:00
Stephen Finucane
c5b772db76 trivial: Prepare for pyupgrade pre-commit hook
This change is entirely automated save for the update of some mocks from
'io.open' to '__builtins__.open').

We are keeping this change separate from addition of the actual hook so
that we can ignore the commit later.

Change-Id: I0a9d8736632084473b57b57b693322447d7be519
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2024-04-23 12:24:23 +01:00
Stephen Finucane
0a63f8603e compute: Fix bug with start/stop server
A mistake was introduced during the conversion from novaclient to SDK in
change I5ebfa6b2468d5f20b99ea0eab1aea9377be09b8c. Fix the issue and add
functional tests to prevent it being reintroduced.

Change-Id: I6b314eab31bcf452e88b8b6a239ac2e296497cb9
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
Story: 2010750
Task: 48004
2023-05-17 15:59:33 +01:00
Stephen Finucane
28ffa2bf9f Blacken openstackclient.compute
Black used with the '-l 79 -S' flags.

A future change will ignore this commit in git-blame history by adding a
'git-blame-ignore-revs' file.

Change-Id: I9af45c062d179ab3dc2a5e969e1c467932753a2b
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2023-05-10 10:51:30 +01:00
Stephen Finucane
2454636386 compute: Generate SSH keypairs ourselves
Starting with the 2.92 microversion, nova will no longer generate SSH
keys. Avoid breaking users by generating keypairs ourselves using the
cryptography library, which was already an indirect dependency through
openstacksdk.

Change-Id: I3ad2732f70854ab72da0947f00847351dda23944
Implements: blueprint keypair-generation-removal
2023-05-02 12:18:52 +01:00
Huda Irshad
737540cca0 Migrate 'server event *' commands to SDK
This one is tricky since the ServerAction resources includes a nested
ServerActionEvent resource which requires a custom formatter in order
for things to render as expected.

Change-Id: I3d24851303222af9efcee8d7e1565278b1018efd
Co-authored-by: Stephen Finucane <stephenfin@redhat.com>
2023-04-20 12:09:59 +01:00
Zuul
fa90ad1392 Merge "Switch list server volume to sdk" 2023-02-21 13:28:35 +00:00
Zuul
e00400eff5 Merge "Use the SDK in server migration list" 2022-12-15 18:05:11 +00:00
Zuul
a103b6ca34 Merge "Use the SDK for server show" 2022-12-15 17:45:29 +00:00
Zuul
3f7663a00e Merge "Fix parameter handling in server add fixed ip cmd" 2022-12-15 17:45:27 +00:00
Ritvik Vinodkumar
d47e432005 Switch list server volume to sdk
Switch the server volume list command from novaclient to SDK.
Modified functional test for server add/remove volume.

Change-Id: I5b4ab7d0275aec2e02451c5371319ac350af6a5f
2022-12-15 17:39:16 +00:00
Ariel-Berkowicz
318df521ed Create a functional test case for hypervisor list and show
This functional test case for hypervisor list and show makes sure it
works with the openstackclient sdk.

Change-Id: Ibaeaf68d6056fcf904b546f30287c65173b5a368
2022-12-14 16:50:42 +00:00
Dr. Jens Harbott
f23322c5ef Fix parameter handling in server add fixed ip cmd
The fixed_ip_address parameter needs to be passed in a hash with key
"ip_address" in order to be processed by the server, the previous arg
was simply being ignored.

Added a functional test for better coverage.

Closes-Bug: 1998927

Change-Id: I6956d2642d8e80fc10c3739f0a571aa7ba276b1a
2022-12-12 12:27:48 -05:00
Daniel Wilson
70dbb01ea3 Use the SDK for server show
Use the SDK for the server show command. This change modifies a helper
function that is used by server show as well as other commands that
print information about an individual server. The helper still uses
novaclient APIs when additional OpenStack requests are needed since some
of its callers are still using the nova client.

Depends-On: https://review.opendev.org/c/openstack/openstacksdk/+/864340
Change-Id: Ic253184ee5f911ec2052419d328260dc4664b273
2022-12-11 18:04:29 -05:00
Zuul
f9d2d69ed2 Merge "tests: Convert compute tests to use 'parse_output'" 2022-12-02 14:21:47 +00:00
Daniel Wilson
86c5470134 Use the SDK in server migration list
Update server migration list to use the OpenStack SDK instead of
directly using the nova interface.

Change-Id: I40dc95ee47e7c33ebf596f8ad437228b4bb0ab33
2022-11-30 12:18:31 +00:00
Daniel Wilson
c97f73ce2a Use the compute SDK in server list
Update server list to use the compute component of the OpenStack SDK
instead of directly using the nova interface. This change depends on SDK
version 0.102.0 for automatic client-side query filters.

Change-Id: Ib9985812bfd98320b75f3a82bb594a0daa6e4d93
2022-11-29 20:24:45 -05:00
Stephen Finucane
874519e980 tests: Convert compute tests to use 'parse_output'
Change-Id: Ib5b2f46639f14877a9ec295b26cae01a05395d4d
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2022-11-29 16:21:29 +00:00
Violet Kurtz
a9f8133274 Migrate server_groups to the new API
Moved the server_groups to the new API.

Change-Id: Ied7bd6f56e277f0c5efcd5ba028765f9be65050f
2022-08-02 20:39:19 +00:00
Zuul
4b14c400ff Merge "tests: Improve logging for executed commands" 2022-05-13 11:57:56 +00:00
melanie witt
72a2477ec0 Fix 'server event list|show' for deleted servers
As of compute microversion >= 2.21, support for list and show of server
events for deleted servers was added. This however wasn't working using
the openstackclient because the compute GET /servers/{server_id} will
not return a deleted server, so osc_lib.utils.find_resource() fails to
find the server and the command bails early.

This adds a check for a uuid-like <server> arg and uses it directly if
the <server> cannot be found via find_resource().

A note is also added to the command help to indicate that list and show
for deleted servers will only work if a server ID is passed (name will
not work).

Story: 2009841
Task: 44443

Change-Id: Icd33b3b9a3a1855d7893dd111bbb2aca059f45fd
2022-02-09 23:26:25 +00:00
Stephen Finucane
b3cb85f112 tests: Improve logging for executed commands
We're seeing failures in a recently added tests,
'ServerTests.test_server_add_remove_volume' from
'openstackclient/tests/functional/compute/v2/test_server.py'. These
failures are likely the result of slow CI nodes, but we don't have
enough information in the CI logs to debug them. Starting logging the
various commands executed in tests so that we can see these logs if and
when tests fail.

Change-Id: I4584dc5e6343fe8c8544431a527d8c3c7e7b3c5b
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2021-12-09 17:23:32 +00:00
Diwei Zhu
f82afc7f37 Switch openstack server remove port/network to using sdk
Change-Id: I1540c1f52e9a107dba20eeea9dc323c5510fe2b1
2021-11-29 14:31:07 +00:00
Diwei Zhu
28cd5763de Add functional test for server add/remove volume.
Change-Id: I86a76f32790cafcff1d94364fb72f8890a8cb025
2021-11-26 14:11:02 +00:00
Diwei Zhu
2183a61147 Switch openstack server add port/network to using sdk.
The old novaclient.v2.server.Server.interface_attach() method is
replaced with proxy.create_server_interface().
In swargs, 'net_id' and 'port_id' are mutual-exclusive, if one of
them is given with value, the other one cannot be None, as the
API would responde with 400 (None is not string).
In unit test, temporary method 'setup_sdk_servers_mock' is added,
because other tests are still using the old 'setup_servers_mock'.
Functional tests are added. Releasenote is generated.

Change-Id: I9899f0509febc5143560a1859ae6344d0a6d1427
2021-11-14 15:23:36 +00:00
Stephen Finucane
7c1d6f769c compute: Add functional tests for --block-device
This mostly reuses the existing tests for '--block-device-mapping',
which can hopefully be removed at some point in the future.

This highlights two issues with the implementation of this option.
Firstly, the 'boot_index' parameter is not required so don't mandate it.
Secondly, and more significantly, we were defaulting the destination
type for the 'image' source type to 'local'. Nova only allows you to
attach a single image to local mapping [1], which means this default
would only make sense if you were expecting users to use the
'--block-device' option exclusively and omit the '--image' option. This
is the *less common* case so this is a bad default. Default instead to a
destination type of 'volume' like everything else, and require users
specifying '--block-device' alone to pass 'destination_type=local'
explicitly.

[1] https://github.com/openstack/nova/blob/c8a6f8d2e/nova/block_device.py#L193-L206

Change-Id: I1718be965f57c3bbdb8a14f3cfac967dd4c55b4d
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2021-03-05 12:44:52 +00:00
Stephen Finucane
e2a9a9607c compute: Fix 'server group * -f yaml' output
Make use of 'FormattableColumn'-derived formatters, which provide better
output than what we were using before, particularly for the YAML output
format.

Change-Id: Id6d25a0a348596d5a0430ff7afbf87b049a76bc8
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2021-01-06 12:02:25 +00:00
Stephen Finucane
03776d82e5 compute: Fix 'server * -f yaml' output
Make use of 'FormattableColumn'-derived formatters, which provide better
output than what we were using before, particularly for the YAML output
format. For example, compare before for the 'server show' command:

  $ openstack --os-compute-api-version 2.79 server show test-server -f yaml
  ...
  addresses: private=fdff:77e3:9bb4:0:f816:3eff:fe6d:a944, 10.0.0.44
  flavor: disk='1', ephemeral='0', extra_specs.hw_rng:allowed='True', original_name='m1.tiny',
    ram='512', swap='0', vcpus='1'
  ...

To after:

  $ openstack --os-compute-api-version 2.79 server show test-server -f yaml
  ...
  addresses:
    private:
    - fdff:77e3:9bb4:0:f816:3eff:fe6d:a944
    - 10.0.0.44
  flavor:
    disk: 1
    ephemeral: 0
    extra_specs:
      hw_rng:allowed: 'True'
    original_name: m1.tiny
    ram: 512
    swap: 0
    vcpus: 1
  ...

Similarly, compare before for 'server list':

  $ openstack --os-compute-api-version 2.79 server list -f yaml
  - ...
    Networks: private=fdff:77e3:9bb4:0:f816:3eff:fe6d:a944, 10.0.0.44
    Power State: Running
    Properties: ''
    ...

To after:

  $ openstack --os-compute-api-version 2.79 server list -f yaml
  - ...
    Networks:
      private:
      - fdff:77e3:9bb4:0:f816:3eff:fe6d:a944
      - 10.0.0.44
    Power State: 1
    Properties: {}
    ...

We also fix the human-readable output for the 'tags' field.

Before:

  $ openstack --os-compute-api-version 2.79 server list
  ...
  | tags   | ['bar', 'foo']  |

After:

  $ openstack --os-compute-api-version 2.79 server list
  ...
  | tags   | bar, foo  |

Change-Id: I7a8349106e211c57c4577b75326b39b88bd9ac1e
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2021-01-06 12:02:24 +00:00
Stephen Finucane
ebaf0eae2c tests: Remove 'agent' functional tests
The 'os-agents' API was recently removed from nova [1]. Remove the
functional tests, since they will always fail going forward but will
continue to run on older stable branches.

Also Squeeze https://review.opendev.org/#/c/762559/ inside, since those
2 are simultaneously blocking gate

[1] https://review.opendev.org/#/c/749309/

Change-Id: I0bf7d4c0ba2a9d4637db0d209d8d52163d772f12
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
2020-11-16 15:54:27 +01:00
Artem Goncharov
ad3369ed1f Fix formatting of the flavor properties
Do not stringify flavor properties to allow proper output formatting to
json/yaml/etc

Change-Id: I9f4c42acb85b726af87123134dd19de98fe95074
2020-11-02 15:09:09 +01:00
Zuul
e7b2528c4a Merge "Show words indicating booted from volume for server image" 2020-09-30 20:34:53 +00:00
jay
bae89b3014 Output correct json for security groups in 'openstack server show'
Fixes incorrect json output for 'openstack server show -f json'.
The security group json output groups all the json as one
for e.g. "security_groups": "name='group1'\nname='group2'"
The correct output should be
"security_groups" : [{"name" : "group1"}, {"name" : "group2"}]
properties and volumes_attached fields also has similar issue.

Story: 2007755

Change-Id: I1b1cac716329e0530400aff782c08000b21d8e1d
2020-09-14 15:22:27 +02:00
melanie witt
4a3c5207c1 Show words indicating booted from volume for server image
For a server booted from a volume, nova API does not store an image_id
and instead returns an empty string. Currently, openstackclient
similarly shows an empty string for Image Name and Image ID for servers
booted from volumes.

To aid CLI users in understanding the meaning of no image_id, we can
display the string "N/A (booted from volume)" in the image field if the
server was booted from a volume.

Change-Id: I9c62cf6fe23b2e934dcbf5ebbf706b2705d2e424
2020-08-27 20:24:48 +00:00
KeithMnemonic
f5384ae16a Fix openstack server list --deleted --marker option
This patch removes using the "name" option for a marker when
--deleted is also used. The find_resource() function
that is being called does not correctly handle using the marker
as the "name" in the search when also using deleted=True.
One simple way to fix this is force the marker to only be an ID
when --deleted is used. This is how the nova client works.

Using the --deleted option is available to users with the admin
role by default. If you're an admin listing --deleted servers
with a marker by name, find_resource() is going to fail to find
it since it doesn't apply the --deleted filter to find_resource().

The find_resource() function is trying to find the marker server
by name if it's not found by id, and to find it by name it's
listing servers with the given marker as the name, but not
applying the --deleted filter so it doesn't get back any results.

In the story it was suggested modifying find_resource to include
the deleted query param when it's specified on the command line but
that didn't work because it still results in something like this:

http://192.168.1.123/compute/v2.1/servers?deleted=True&name=4cecd49f-bc25-4a7e-826e-4aea6f9267d9

It seems like there are bugs in find_resource().

Restricting the marker to be the server ID when listing deleted servers
is probably OK since if you're using --deleted you're an admin and you could
be listing across all projects and if you're filtering by a server across all
projects anyway (not that you have to, I'm just saying if you are), or even
showing a server in another project, you have to do it by id rather than name
because find_resource() won't find the server in another project by name, only ID.

story: 2006761
Task: 37258

Change-Id: Ib878982b1d469212ca3483dcfaf407a8e1d2b417
2020-01-02 20:05:56 +00:00
Eric Fried
3b409e4d0e Refactor AggregateTests
While investigating the referenced story/bug I noticed that
wait_for_status in
openstackclient.tests.functional.compute.v2.test_aggregate.AggregateTests
was doing a lot more than it should ever need to (it probably got copied
in from somewhere). The two places calling it only need to a) check the
output of `openstack aggregate show`, and b) try once -- since they just
got done creating the aggregate synchronously, there should never be a
need to delay/retry. So this commit removes the helper method and just
inlines the check.

At the same time, the addCleanup(aggregate delete) directives are moved
above their respective creates. This is a defensive best practice which
makes sure cleanup happens even if something fails very soon after the
actual back-end create (as was in fact the case with the referenced
bug/story).

It is unknown whether this will impact the referenced bug.

Change-Id: I0d7432f13642fbccd5ca79da9c76adfcbabb5fa9
Story: 2006811
Related-Bug: #1851391
2019-11-05 21:32:15 +00:00
Eric Fried
f1d742f32a Fix functional tests for py3
Fix various things so the functional tests will work under python3:

- A hashlib.md5() can only be update()d with an encoded string in py3.
- There's no dict.iteritems(), change to dict.items() (which is already
  an iterator).
- Open temp files with 'w+' mode rather than the default 'w+b' (as an
  alternative to encoding all the write and expected-read payloads as
  bytes).
- (This is a weird one) Explicitly raise SkipTest from unittest (rather
  than unittest2, which is where cls.skipException landed). Not sure why
  this is busted, but this moves the ball.

Change-Id: Ic9b2b47848a600e87a3674289ae7ae8c3e091fee
2019-10-31 00:17:35 +00:00
Dean Troyer
de8ab5e8fd More aggregate functional race chasing
AggregateTests.wait_for_status() was a classmethod, those often
are sources of conflict in parallel testing...

Change-Id: I6211fd9c36926ca97de51a11923933d4d9d2dfda
Signed-off-by: Dean Troyer <dtroyer@gmail.com>
2019-09-10 14:09:29 -05:00
Dean Troyer
03a2accb2f Format aggregate command fields and de-race functional tests
Rename metadata to property in all aggregate commands

Beef up functional tests to reduce street racing

Change-Id: I4598da73b85a954f3e6a3981db21891b45d9548c
Signed-off-by: Dean Troyer <dtroyer@gmail.com>
2019-08-26 17:50:06 -05:00
Matt Riedemann
b9d6310556 Add openstack server create --boot-from-volume option
This adds a --boot-from-volume option to the server create
command which is used with the --image or --image-property
option and will create a volume-backed server from the
specified image with the specified size. Similar to the
--volume option, the created root volume will not be deleted
when the server is deleted. The --boot-from-volume option
is not allowed with the --volume option since they both create
a block device mapping with boot_index=0.

Change-Id: I88c590361cb232c1df7b5bb010dcea307080d34c
Story: 2006302
Task: 36017
2019-08-09 16:44:46 +00:00
Matt Riedemann
6a199bd141 Support type=image with --block-device-mapping option
The --block-device-mapping option on the server create
command currently only supports booting from volume and
volume snapshot. A common boot-from-volume scenario is
providing an image and letting nova orchestrate the
creation of the image-backed volume and attaching it to
the server.

This adds support for type=image in the --block-device-mapping
option. The volume size is required in this case. Note that
the CLI currently says if type=snapshot that size is also required
but that's technically not true. When booting from a volume
snapshot, the compute API will use the size of the volume snapshot
to create the volume if an explicit size is not provided. For the
purposes of this patch, we need the size anyway for the image
being the block device mapping source type.

Change-Id: I57b3c261d8309f7b9f62a3e91612bce592a887a3
Story: 2006302
Task: 36016
2019-08-09 16:36:17 +00:00
Zuul
82823f89f0 Merge "Rename review.openstack.org to review.opendev.org" 2019-06-14 02:25:02 +00:00
zhangbailin
ef1fd38815 Add changes-before attribute to server list
Closes-Bug: #1827844
Part of bp support-to-query-nova-resources-filter-by-changes-before

Change-Id: I4f28168188973730247bcbcb70ba0e70eb81e3be
2019-05-31 05:39:29 +00:00
Dean Troyer
99c3be93c8 Serialize more aggregate functional tests
These tests are showing signs of problems running in parallel
so serialse the create/delete/list/set/unset tests.  They all
used two aggregates each anyway...

Change-Id: Iba4b52c179e6914eaeefea1da0f7eaefcdcf1f87
Signed-off-by: Dean Troyer <dtroyer@gmail.com>
2019-05-17 19:15:28 -05:00
Dean Troyer
bb659cf438 Aggregate functional test tweak
This seems to still be racy, lengthen the timeout to wait for
agregate creation.

Change-Id: I3601c5baee03745ae21714b9dff0e278ad016877
Signed-off-by: Dean Troyer <dtroyer@gmail.com>
2019-05-16 07:43:55 -05:00
melissaml
aabc67f3a2 Rename review.openstack.org to review.opendev.org
There are many references to review.openstack.org, and while the
redirect should work, we can also go ahead and fix them.

Change-Id: I82e3797dd4c05e4944f40c950b4fafe9a5334cbf
2019-05-12 04:41:27 +08:00
Glenn Van de Water
7741347041 Fix service discovery in functional tests
If a required service is not enabled then we skip the test.
The discovery is done by tests/functional/base.py:is_service_enabled
but this method is broken, credentials are not passed to the
'openstack service show' command so every call will fail and every test
that relies on it will be skipped. This commit fixed that method and
the issues that popped up when re-enabling tests.

Network segment range:
 - issue where we assumed network-segment-range extension is always
   present
 - issue where we compare integers and string representations of numbers

Subnet:
 - issue where we try to deepcopy an uncopyable object in UnsetSubnet

Change-Id: Id3cc907c1ed2a25b49cf6f4a7233e0401a02383a
Story: 2005169
Task: 29908
2019-03-13 16:16:24 +01:00
liuyamin
5bec3b7e3b Replace assertEqual(True/False, expr) with assertTrue/assertFalse
In some cases, If the result of expr is a boolen value, we shoud
use assertTrue/assertFalse to instead. Because it is clear and simple.

Change-Id: I53b345fc3915a7b0e737e9dd4d58fe09c746d61c
2018-11-14 14:50:05 +08:00
Zuul
0fa3c84b4f Merge "Default --nic to 'auto' if creating a server with >= 2.37" 2018-10-26 03:20:17 +00:00