Commit Graph

44 Commits

Author SHA1 Message Date
melanie witt 21edd11ba9 Add unit tests for client logger
Change I53caceb08667eb12e27016731868e8015dd10e34 fixed a bug where we
weren't using our novaclient logger default when a logger was not
passed to the Client constructor.

This adds unit tests to assert the fixed behavior and protect against
regression.

Related-Bug: #1921388

Change-Id: I9f622c01a6b1abe328a60de6d3e438e68872dd80
2021-04-10 03:10:04 +00:00
Takashi Natsume 7ef2c28bf3 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: I4d45ae17f6f84f945f5dd049a929216ce6b6b58e
Signed-off-by: Takashi Natsume <takanattie@gmail.com>
2020-04-26 10:12:09 +00:00
Takashi NATSUME 81ec72ecf8 Remove deprecated methods and properties
Remove deprecated methods, properties and unused classes.

Change-Id: I16e0b6e55a9c9da04c4582f9be672018d37bf368
2019-07-04 04:06:42 +00:00
Takashi NATSUME 8eb7d1c5cc Remove deprecated novaclient.v2.contrib modules
All modules of novaclient.v2.contrib have been removed.
The 'only_contrib' parameter for the
'novaclient.client.discover_extensions' method is no longer valid.

Change-Id: I6da83057dda1f27afe98a2412bc0815f100f34a4
2019-02-07 15:00:36 +09:00
Takashi NATSUME 46ad782fb0 Use uuidutils of oslo.utils
Replace standard uuid library with uuidutils of oslo.utils.

TrivialFix
Change-Id: Ibb6ec8b56a404685d9727f1b771dbff178fdecdf
2018-08-08 15:12:28 +09:00
Sean Dague d25502cbe2 Have python-novaclient support global_request_id
As part of the Boston Summit, support the global_request_id effort by
making python-novaclient support passing global_request_id during
construction.

part of bp:oslo-middleware-request-id

oslo spec I65de8261746b25d45e105394f4eeb95b9cb3bd42

Change-Id: Ife29b1856c0c278eab1708c3971fef14b9d77e2e
2017-05-26 08:32:05 -04:00
jichenjc 4c18c8bd97 Remove version 1.1 support
v2 and v2.1 is supported now and it ask user to use v2.x API
should be what we wanted , this already deprecated for a
couple of release, so we can remove it now

Change-Id: I8de6fdbf21ccc4969297044a49590ffcd9cd27d8
2017-03-26 17:58:58 +08:00
Matt Riedemann ac7c96690f Remove deprecated tenant network APIs
These were deprecated in Newton:

aaebeb05a0

Since this is the last of the deprecated contrib extensions,
we can also deprecate the 'only_contrib' parameter from the
novaclient.client.discover_extensions method.

Change-Id: Ie2e3fdc4e044f6eb304724d16a7d0f1f7ba705fd
2017-03-20 16:36:58 -04:00
Abhishek Kekane 98976d5ab8 x-openstack-request-id logged twice in logs
In the recent release of keystoneauth1 2.18.0 provision is made to log
x-openstack-request-id for session client. Once this new library is synced
in openstack projects, the x-openstack-request-id will be logged twice
on the console if session client is used.

For example,
$ nova --debug list

DEBUG (session:640) GET call to compute for
http://10.232.48.204:8774/v2.1/servers/detail used request id
req-b6aeff56-0408-44ed-80ba-cd7b950a8f21

DEBUG (client:85) GET call to compute for
http://10.232.48.204:8774/v2.1/servers/detail used request id
req-b6aeff56-0408-44ed-80ba-cd7b950a8f21

Above log will be logged twice on the console.

Removed logging of x-openstack-request-id in case of SessionClient as it
is already logged in keystoneauth1.

Depends-On: I492b331ff3da8d0b91178bf0d5fe1d3702f15bd7
Closes-Bug: #1657351

Change-Id: I9ba6a9e498fbcb027f45499d27ece966c52580ba
2017-01-19 18:12:39 +05:30
Andrey Kurilin 2e5576dafc Remove all code related to HTTPClient
In previous patch we switched to use SessionClient in all cases. It means that all
HTTPClient code is redundant now.

Change-Id: I5a0da970fd82c79db3d88f1b49279133bbdba639
2016-12-16 12:56:18 +00:00
Andrey Kurilin 8409e006c5 Create keystone session instance if not present
Since all authentication plugins should be stored in Keystone, there is no
need to share responsibility for authentication stuff with Keystone team.
Let's use convinient and the right way to use keystone - keystone sessions.
We have own adapter for it - novaclient.client.Session which can be used in
100% cases of novaclient usage. Let's create session object if it is not
transmitted via arguments and get rid of novaclient.client.HTTPClient
implementation.

NOTE: novaclient.client.HTTPClient and all related code will be removed
      separately.

Co-Authored-By: Clenimar Filemon <clenimar@lsd.ufcg.edu.br>
Change-Id: Ibb99fdafbf02b3e92f1a5d04d168151b3400b901
2016-12-16 12:56:10 +00:00
Andrey Kurilin e4dc84e0f6 Make SessionClient interface similar to HTTPClient
HttpClient will be deprecated soon and SessionClient will be used by default.
To not break integration novaclient with other project at the step of moving
from HTTPClient, SessionClient should have similar interface.

Change-Id: I855ccc5160dc7628f4550e93bf133adf8263aace
2016-12-16 12:55:57 +00:00
Andrey Kurilin f98b8470de Rename api_key to password
"password" term is more clear. Resolves FIXME from the code:

    FIXME(comstud): Rename the api_key argument above when we
                    know it's not being used as keyword argument

Change-Id: I39f810a181b119591cf017eded71356a437a8c0a
2016-12-15 19:49:03 +02:00
Andrey Kurilin 73196fd3c1 Remove redundant args of _construct_http_client
Arguments 'extenstions' and 'no_cache' were not transmitted to
'_construct_http_client' method. They are redundant

Change-Id: Ibe0f874e510eef7cc28fcee87b0083c7febd5161
2016-12-15 19:49:03 +02:00
Andrey Kurilin bf09ad844e Introduce helper for checking args deprecation
This patch introduces `_check_arguments` methods for processing deprecation
workflow of novaclient.client.Client entry-point.

Also, this patch adds a proper warning messages for 'auth_plugin',
'auth_system' arguments, which were removed previously

Change-Id: I7ee210c08f4126b267572c5428511451aeb17260
2016-12-15 19:49:03 +02:00
Jamie Lennox 749fee3346 Replace requests mocking with requests-mock
The novaclient tests are broken with the master (unreleased) branch of
requests. This is because most of the mocking that novaclient does with
requests in insufficient.

Requests-mock is for exactly this purpose and is already widely used in
novaclient so replace using mock with requests-mock where appropriate.

Closes-Bug: #1630157
Change-Id: Ie91daeb5f0c241eb83b77c04ac1b12e431d6671c
2016-10-05 06:53:05 +11:00
Thiago Paiva f7dc91dc11 Fixes TypeError on Client instantiation
When instantiating novaclient with kwargs or named attributes, the 'password'
field is duplicated due to an overwrite on the __init__ method of Client v2.
This patch pops out the password field when it's passed and no api_key is
provided.

Co-Authored-By: Pavel Kholkin <pkholkin@mirantis.com>

Closes-bug: #1511417

Change-Id: Id8310eccef5f0f9a2983e25dd35541d1eb0efe86
2016-08-26 11:41:12 +03:00
EdLeafe 85ef6f46fa Change all test URLs to use example.com
The tests in novaclient/tests/unit/test_client.py use several domain
names other than example.com, which should always be used to avoid
conflict with actual domains. These include foo.com, blah.com, and
nooooooooo.com, all of which are legitimate owned domain names. These
have been replaced with example.com usages.

Closes-bug 1555682

Change-Id: I6573e118364300cd09653b87df28ba1a95870d3c
2016-07-20 21:12:12 +00:00
Takashi NATSUME d16c3692e6 Log request_id for each api call
Add the function to log 'x-openstack-request-id' or
'x-compute-request-id' in each API call.
If the caller (e.g. heat) uses oslo.log,
the caller's request id in oslo.context and
the callee's request id can be output in the same
log message (same line).

Change-Id: I29312ce278ecfae41a688a0ddf76c24cfa0eaf6b
Implements: blueprint log-request-id
2016-06-08 00:10:55 +00:00
Andrey Kurilin c18ccb1bfa Add a way to discover only contrib extensions
Several OS projects(cinder, neutron, osc...) use
`novaclient.discover_extensions` for initialization novaclient.client.Client
with novaclient.v2.contrib extensions. In this case, it would be nice to
provide a way to not discover extension via python path an entry-point.

Change-Id: I030f4c55c2795c7f7973f5f12e54b9819c4a5578
Closes-Bug: #1509500
2016-02-19 11:42:24 +00:00
Chaozhe.Chen 14f63647e9 Test: Clean v2 client userwarning
Problem:
When we run nova client unit test, there are lots of UserWarnings
printed on the screen. These warnings mean to remind users not to
use v2.client directly.

Solution:
1. In top level tests such as some tests in test_auth_plugins.py
test_client.py and fixture_data/client.py, we use updated usage
novaclient.client instead of using novaclient.v2.client directly.
2. In v2 unit tests, we clean those warnings with setting direct_use
False.

Change-Id: I70682e54874860f1d67d29325811c9da616bb705
Closes-Bug: #1532711
2016-01-12 12:05:50 +08:00
Monty Taylor 1f11840dd8 Migrate to keystoneauth from keystoneclient
As a stepping stone to the os-client-config patch, first switch to
using keystoneauth, its Session and its argparse registration and
plugin loading to sort out any issues with that level of plumbing.
The next patch will layer on the ability to use os-client-config
for argument processing and client construction.

Change-Id: Id681e5eb56b47d06000620f7c92c9b0c5f8d4408
2015-12-12 20:39:57 -08:00
Matt Riedemann 63c7a576e1 Revert "Do not expose exceptions from requests library"
This reverts commit 2961e82bfa

This broke cinder unit tests that have a timeout test for novaclient
where they mock the requests library raising a Timeout exception. That
test expects to get a requests Timeout passed through but with the
change being reverted it was getting a RequestTimeout exception from
novaclient, which breaks the test and fails the gate runs.

We could change the cinder unit test to handle both the requests.Timeout
and the new novaclient RequestTimeout, but that's just papering over
the cinder failure, we wouldn't know what other clients are failing
in the same way because they have code working around the requests
exceptions getting passed through, so we should treat this like an API
change.

I'd be in favor of making the same change again iff the novaclient
exceptions extended the requests exception types so it would be transparent
to consumers, since novaclient.exceptions.RequestTimeout would be a
requests.Timeout via inheritance. But given the gate breakage and it being
summit week I'm inclined to revert first and think about a better long term
fix later when people are back to discuss.

Change-Id: I368728588e5997eef860a168539eb66c58f2e72a
Closes-Bug: #1510790
2015-10-28 07:27:40 -07:00
Jason Dunsmore 2961e82bfa Do not expose exceptions from requests library
Novaclient expects the requests library to always be able to get a
response back and doesn't handle other cases where it might raise
an exception even before the request is completed (e.g.
ConnectionError).

These exceptions should be captured and properly converted to some
native novaclient exception.

Change-Id: Iec7247b715c38c29910b30e76413cead4e951a37
Co-Authored-By: Kuo-tung Kao <jelly.k@inwinstack.com>
Closes-Bug: #1406586
2015-10-22 14:34:23 -05:00
Jenkins 72190ba9a2 Merge "Fix versions.list for v2.1 Nova API" 2015-08-24 23:19:10 +00:00
Feodor Tersin b6130e2e18 Fix a fault of request logging with no credentials
If a user doesn't specify for novaclient's Client neither credentials
nor auth token, but specifies http_log_debug=True, and requests Nova
version list, novaclient fails with AttributeError exception.

The reason is that obfuscation of auth token doesn't expect None value
of the token. This patch bypass obfuscation of None token.

Closes-Bug: #1488169
Change-Id: I3712d633719bc77310ce863da33b2eec59a7ce91
2015-08-24 19:46:17 +03:00
Feodor Tersin bf91805f35 Fix versions.list for v2.1 Nova API
novaclient transforms its management_url to get an url for a request for
server versions list. Currently this transformation does not consider
that version part of an url can be complex and contain major and minor
parts. As a result versions.list does request on a wrong url and fails
with NotFound error.

This patch adds support of version formats like 'vN.N', 'vN.NN', etc.

Partial-Bug: #1483030
Change-Id: Ie105bec37ee41c6a77ffc5f1cf680bbf88846159
2015-08-21 22:04:15 +03:00
Ian Cordasco c69c38c58f Use keystoneclient's TCPKeepAliveAdapter
When novaclient isn't using a session from keystoneclient, it needs to
set reasonable TCP Keep-Alive values otherwise the operating system
defaults may cause the client to hang for hours before a connection will
time out. Using keystoneclient's adpater (which sets good defaults) will
allow us to not have to maintain this adapter here and to benefit from
their defaults.

Closes-bug: 1477275
Related-bug: 1323862
Depends-On: Ibd53ae2d4d2455db0ebc9951e5c764befc57850f
Change-Id: I1924bd96eb1a4bac5d57a5cc5d5461acb3f7f5ac
2015-07-28 20:20:29 -05:00
Andrey Kurilin ea0b3bd608 Implements 'microversions' api type - Part 1
Compute API version will be transmitted to API side via
X-OpenStack-Nova-API-Version header, if minor part of version is presented.

New module "novaclient.api_versions" was added as storage for all api versions
related functions, classes, variables and etc.

`novaclient.api_versions.APIVersion` class is similar to
`nova.api.openstack.api_version_request.APIVersionRequest`. The main
difference relates to compare methods(method `cmp` is missed from Py3) and
processing "latest" version.

Related to bp api-microversion-support

Change-Id: I0e6574ddaec11fdd053a49adb6b9de9056d0fbac
2015-07-16 16:06:28 +03:00
Matt Thompson 84aec86319 Pass full path to pkgutil.iter_modules()
On my production system, when using client version 3, an exception is
raised with an incomplete message as the installed novaclient is
failing to find the bundled client versions.  This commit creates a new
_get_available_client_versions() method and moves the client version
searching from get_client_class() into it.

We also update __get_available_client_versions() to pass
pkgutil.iter_modules the full path to novaclient rather than
'novaclient', which is what actually resolves the issue here.

Lastly, we add a single test to ensure that
__get_available_client_versions() does not return an empty list.

Change-Id: I07ce414863e833c72e50ad8cf1824054cfb41457
Closes-Bug: #1463809
2015-06-11 09:42:02 +01:00
Jenkins 2a7c2f14c2 Merge "Don't lookup service url when bypass_url is given" 2015-04-27 17:12:51 +00:00
Andrey Kurilin 61ef35fe79 Deprecate v1.1 and remove v3
Module novaclient.v1_1 is already deprecated, so it's time to stop using it
inside novaclient.

Since support of v3 nova is undocumented feature, which uses v2
implementation, we can remove code related to it.

Also, this patch removes redundant check for compute api version != 1.0.

Change-Id: I06b349f704d5ae2c592d8d286da268870f2a69e9
2015-04-22 15:03:07 +03:00
melanie witt 4f9e65c438 Don't lookup service url when bypass_url is given
Change https://review.openstack.org/#/c/164321 broke the bypass_url
option. It made the assumption that self.service_catalog won't be set
in novaclient/client.py when bypass_url is specified, which isn't
necessarily true. This change adds a check for self.bypass_url and
looks up service url only if bypass_url hasn't been specified.

Closes-Bug: #1445086

Change-Id: I72d2b3e3199aeae7fb2f2c68be259774e07a4501
2015-04-21 23:54:14 +00:00
ZhiQiang Fan 1c39f8fabf Don't record time when self.timing is False
The expected behavior is when timing is True, then we record each
request's time, then we should call reset_timings() to release memory.

However, the shell, client.{HTTPClient,SessionClient} will record each
request's time no matter what timing is set, then after long running
time in service like ceilometer-agent-compute, the memory keeps increasing.

We'd better not record request's time when timing is set to False.
Users are not responiable to call reset_timings() when they don't want
timing functionality.

Change-Id: I3e7d2fadf9a21be018781d528a1b6562228da6dd
Closes-Bug: #1433491
2015-03-21 19:27:36 +08:00
melanie witt e0f5072907 Ensure the use of volume endpoint in volumes apis
Currently, several of the volumes apis depend on callers to pass
service_type='volume' as a parameter when creating a client object,
to route correctly. The problem is, it makes it impossible for
callers to work with both the compute and volume endpoints at the
same time. They can either work with compute and have volumes.* calls
return 404, or they can work with volume and have servers.* images.*
flavors.* calls return 404.

The CLI sets service_type='volume' for client objects for the
following commands via a decorator:

volume-list
volume-show
volume-create
volume-delete
volume-snapshot-list
volume-snapshot-show
volume-snapshot-create
volume-snapshot-delete
volume-type-list
volume-type-create
volume-type-delete

With this change, the service_type 'volume' is set in the api,
so the decorators on the shell commands are no longer needed.

Closes-Bug: #1431154

Change-Id: I11b48ac14fa4c64d8aae528552ec5b363be384c5
2015-03-17 01:19:11 +00:00
melanie witt 8c0baaea57 Add a test for the TCPKeepAliveAdapter
Related-Bug: #1430935

Change-Id: Idfea26c8eb6448a4c6adc0f3a916515bd4655c1a
2015-03-11 21:03:25 +00:00
Pavel Kholkin 560eeafb6d Cleanup in asserts in python-novaclient
The following replacements were done:

1) assertEqual(True, *) -> assertTrue(*)
2) assertEqual(False, *) -> assertFalse(*)
3) assertTrue(a in b) -> assertIn(a, b)
4) assertTrue(* is not None) -> assertIsNotNone(*)

TrivialFix

Change-Id: I8d8a2d7b5d3505e07728544b683b301d1a8850cf
2015-03-03 15:36:49 +03:00
Sergey Nikitin 53f0c5428f Enable check for E124 rule
Fix E124 failures and enable check for E124

E124 closing bracket does not match visual indentation

Change-Id: Iec6af44362dcf613cfaccbccbe53de82aba51a6a
2015-02-27 16:30:03 +03:00
Andrew Laski ac6636a54d Revert "Overhaul bash-completion to support non-UUID based IDs"
This reverts commit 4c8cefb98a.

The cache completion was causing a bug where 'nova volume-attach' would
then try to query Nova for volume information using a URL that was not
valid.  This caused it to appear that the attach had failed.

Additionally the idea of making extra API queries for a bash completion
cache should be thought through more.

Conflicts:

	novaclient/client.py
	novaclient/shell.py
	novaclient/v2/client.py
	novaclient/v3/client.py

Closes-Bug: #1423695
Change-Id: I6676a11f9b5318a1cda2d03a5d4550bda549d5c2
2015-02-20 01:35:57 +00:00
Jenkins 578390ee7e Merge "Change the unsuitable item caching for completion" 2015-02-07 00:52:15 +00:00
melanie witt edb42ed4dc Compare dicts for POST data in test_client_reauth
I observed a transient unit test failure [1] where occasionally the
ordering of the keys in the string result from json.dumps() didn't
match the ordering in the call_args_list, causing the test to fail.

This change adds a dict comparison of the POST data payload instead
of comparing the json.dumps(data) strings.

[1] http://logs.openstack.org/03/153203/3/check/
gate-python-novaclient-python34/f8a12bc/

Change-Id: I6b8bd4169b92870f657bf4e7f7fca02722749017
2015-02-06 22:06:45 +00:00
Ikuo Kumagai 9a6a7664c2 Change the unsuitable item caching for completion
This fix changes the item that cached for completion from
"human_id" to "name".
A string for completion shoud not be changed in any way,
because changed keyword can not use as command line parameter.
But the "human_id" means "human readable id" that is
changed from "name" by method "to_slug". "to_slug" is meant to
create a valid path name from a string.

The tools/nova.bash_completion take the completion string from
the file ".novaclient/*/*-cache". The file is created when client
call "list" command. For example , "nova list","nova image-list",
and the others.
Currently, items that are written to the cache file is the "id"
and "human_id".

Closes-Bug: #1193049

Change-Id: I241ec8b7c8729274ee43db6e360141fd381b265e
2015-02-06 05:14:05 +00:00
Andrey Kurilin 0a60aae852 Rename v1_1 to v2
Module novaclient.v1_1 is used as implementation of V1.1, V2 and V3.
Since future development(microversioning) will be done across V2,
implementation should be done in appropriate module(to prevent misleading).

Despite the fact that implementation for all versions are equal, discover
method for contrib path worked only for v1.1. This patch fixes this bug and
modifies shell tests to check all versions.

Change-Id: Ib6798f4dfe177586302141f522dc593560ce6a5b
2015-02-04 17:40:46 +02:00
Joe Gordon 3561772f8b Move unit tests into unit test directory
In order to pave the way for functional testing, move existing unit
tests into a directory labeled unit. A subsequent patch will add a
directory for functional tests.

Change-Id: I0adb8b9f14451acb382c725d31f5387b4b6d82bb
2015-01-27 13:06:06 -08:00