Commit Graph

183 Commits

Author SHA1 Message Date
wangzihao feb22145a1 Remove six
Remove all usages of six

Change-Id: I3a5dedade263337aeef12eac1c4daf2f7e82e306
Story: 2008305
Task: 41190
2020-11-03 03:27:56 +00:00
Hervé Beraud 152a1a2e7c Stop to use the __future__ module.
The __future__ module [1] was used in this context to ensure compatibility
between python 2 and python 3.

We previously dropped the support of python 2.7 [2] and now we only support
python 3 so we don't need to continue to use this module and the imports
listed below.

Imports commonly used and their related PEPs:
- `division` is related to PEP 238 [3]
- `print_function` is related to PEP 3105 [4]
- `unicode_literals` is related to PEP 3112 [5]
- `with_statement` is related to PEP 343 [6]
- `absolute_import` is related to PEP 328 [7]

[1] https://docs.python.org/3/library/__future__.html
[2] https://governance.openstack.org/tc/goals/selected/ussuri/drop-py27.html
[3] https://www.python.org/dev/peps/pep-0238
[4] https://www.python.org/dev/peps/pep-3105
[5] https://www.python.org/dev/peps/pep-3112
[6] https://www.python.org/dev/peps/pep-0343
[7] https://www.python.org/dev/peps/pep-0328

Change-Id: I932c7c332a26bd33ecb59bc299cabf63f63c84b2
2020-06-02 20:49:51 +02:00
Zuul 1571a1a3e4 Merge "Fix mock import statements" 2020-04-21 12:44:24 +00:00
Zuul b07e4b55cc Merge "Don't hard code notification types into Monasca client" 2020-04-18 12:51:02 +00:00
Zuul 557fd9cf06 Merge "Allow users to set periodic notifications on all notification types" 2020-04-18 12:50:59 +00:00
Witek Bedyk 78569fec5b Fix mock import statements
As we dropped Python 2 support we don't have to use the third party
mock library with Python 2 compatibility and can move to Python 3
standard library. The change updates the import statements to reflect
that.

Change-Id: I39d9410ae43a2d9e6f6d6eaf74d06a82f2c33524
2020-04-16 18:44:52 +02:00
Andreas Jaeger a09afa37b0 Update hacking for Python3
The repo is Python 3 now, so update hacking to version 3.0 which
supports Python 3.

Fix problems found by updated hacking version.

Remove hacking and friends from lower-constraints, they are not needed
there.

Change-Id: I14aee6250d80b7485c5c582a20abf4efafcc28c2
2020-03-31 22:07:59 +02:00
Doug Szumski 5c78113e65 Don't hard code notification types into Monasca client
Available notification types depend on what is enabled in Monasca
Notification. As such, we should avoid hard coding them into the
client and rely on the Monasca API to validate whether a type is
supported, and to list the supported types.

Change-Id: Icc18bffa04806235583459721f8cb8e36a247f05
Story: 2005551
Task: 37848
2019-12-19 10:39:43 +00:00
Doug Szumski b228dfa61e Allow users to set periodic notifications on all notification types
In some cases, users may want to send periodic notifications for
notification types other than webhooks.

Change-Id: I0256e9a8c3dacaf8bc6066b00daefaa993460a2d
Story: 2006837
Task: 37420
2019-12-19 10:05:21 +00:00
Michał Piotrowski 52707a31a1 Fix metric list formatting with Python 3
Story: 2005269
Task: 30113
Change-Id: Ia12e9b15262eb87594c4724e2c84e003b360b643
2019-03-25 15:35:10 +01:00
Zuul a1d50c6055 Merge "Update json module to jsonutils" 2019-03-06 13:55:38 +00:00
ZhijunWei 7939777a15 Update hacking version
1. Use latest release 1.1.0 and compatible changes w.r.t pep8
2. cleanup of .keys() from dict_object.keys() *in* operator

Story: 2004930
Task: 29772
Change-Id: I5c41100494efee5f0d29d094ccb4d85a6f64bcec
2019-03-01 16:07:52 +00:00
cao.yuan dde64fb950 Update json module to jsonutils
oslo project provide jsonutils, and monascaclient  use it in many place[1],
this PS to update the remained json moudule to oslo jsonutils for
consistency.

[1]: https://github.com/openstack/python-monascaclient/search?utf8=%E2%9C%93&q=jsonutils&type=

Change-Id: I895bc58dafa250b1279ffe70f779c5cc1e865db1
2019-02-25 00:45:47 +08:00
Doug Szumski 59e2a9bd2f Fix alarm-definition-list in Python 3
Python 3 uses unicode strings by default. This bug was caused by
attempting to join a byte string to a unicode string when running
with the Python 3 interpreter.

A unit test was added to reproduce the problem.

Whilst this fix allows alarm definitions to be listed, it doesn't
fix the formatting problem in Python 3. A better fix may be
to return unicode strings in Python 3 as part of a wider code
audit.

Story: 2004972
Task: 29427
Change-Id: Ib008ed2aacd93f499b15094cf5a7e1bb0bb50a1f
2019-02-11 15:24:57 +00:00
Dobroslaw Zybort 0b14b4d492 Return status from running command
This way when someone use code like `sys.exit(main())` it will have
proper exit code on error (so different than `0`).

Story: 2001246
Task: 5776

Change-Id: I1c04fbf73d1fc44da7738c8f22296992d2e7a4f8
2019-01-04 12:53:36 +01:00
ricolin a8b6bb06b4 Remove unused TimingSession class
TimingSession is removed and replaced by keystone session (see [1]).
This patch remove it from monasca client.

[1] https://review.openstack.org/#/c/579139/

Change-Id: I4bfcef96bcb9c8fd14e2c57f318630aa508710ca
Story: #2002978
Task: #22987
2018-07-16 15:39:57 +08:00
Doug Hellmann bf36aa85bb replace unicode with six.text_type
The unicode() built-in does not exist under Python 3 so use
six.text_type, which is set correctly to str or unicode, instead.

Change-Id: I22265e35c04be2fa663b63aac208f7894588d629
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
2018-06-13 15:39:32 -04:00
Amir Mofakhar 1aadb99495 Update pep8 checks
* set the maximum line length to 100
* cleaned up the codes for pep8

Change-Id: Ib4398e601fbf36619a07822b6a616ab13adaa55d
Signed-off-by: Amir Mofakhar <amofakhar@op5.com>
2018-04-10 14:39:23 +02:00
Dao Cong Tien 67111536d4 TrivialFix: remove redundant import alias
Change-Id: I40c06ea652ea85469e85690e959e9fbaa0e4d835
2017-12-21 20:05:55 +07:00
Witold Bedyk fecf0e3d66 Fix auth version detection
If OS_CLOUD is not set the defalt value is parsed which is empty string. This
is wrong, as it deactivates all other environment variables for cloud
configuration.

Change-Id: I48452bb5300fcc46047f8e94501bba1c42629ea1
Story: 2001158
Task: 4890
2017-09-27 09:28:09 +02:00
Tomasz Trębski 8e4adb110e Allow to reuse the session
Add possibility to reuse the session,
passed as kwarg, passed from a component
that initializes the client.

Change-Id: I35bb752680f499dac163305cd81daa2c7b7a817b
2017-08-03 06:37:16 +00:00
Tomasz Trębski 7e19131bfd Bringing back backward compatybility
Removing *args in 94c5223f02,
turned out to break projects that are using monascaclient.

Following code adds it back with the note about the deprecation.

Change-Id: If2664b5054d668f5e088699ae1493c54692a2e8c
2017-07-24 07:59:13 +02:00
Tomasz Trębski 94c5223f02 Integrate client with osc-lib
osc-lib library is foundation on which a CLI client
for openstack can be built. It is meant to facilitate several
aspects, that were previously hard-coded in client:

* keystone communication handling
* supporting multiple authentication methods (not only password)
* common authentication parameters (i.e. environmental OS_*)
* communicating over http with service endpoint
* interactive CLI mode

Thanks to those items, it was possible not only to drop
nearly 3k lines of code and replace them with osc-lib but also
increase reliabity of the client in terms of new openstack releases.
Also it allowed to greatly simpify existing set of unit-tests.
They are now testing only actual logic instead of mocking
entire process of calling shell (i.e. MonascaShell.run(args)) or
mocking HTTP communication. Both items are handled by osc-lib thus
not they are not subject of monascaclient unit tests layers.

Note:
This change is partial integration with osc-lib and its main
purpose is to move the responsibility of:

* keystone communication
* rest-ful communication with service endpoint

to underlying library thus allowing client to implement only
necessary functionality and not supporting boilerplate code,
mentioned above.

Story: 2000995
Task: 4172

Change-Id: I1712a24739438e2d8331a495f18f357749a633c5
2017-07-15 01:37:08 +02:00
Jenkins fed80a73ba Merge "Added support for os_tenant_{name,id} after os_project_" 2017-05-05 08:37:52 +00:00
Sumit Jamgade 3a320ee5d1 Added support for os_auth_version when os_auth_url is unversiond
Change-Id: I89e9b040e41caabcf366def480bb5c5cd0eb965d
Story: 2000965
2017-04-16 16:34:43 +00:00
Sumit Jamgade 9269be018f Added support for os_tenant_{name,id} after os_project_
and deprecation warning for using them.

Change-Id: I69080d4a2e1a2ccae24ee7f181aec30d7754a031
Story: 2000960
Task: 4097
2017-04-12 09:35:28 +02:00
rajat29 7f5c3e035e Replacing six.iteritems() with .items()
We can use dict.items instead, as it will return iterators
in PY3* as well. And dict.items/keys will more readable.

Change-Id: I76683ba60193b725a668716366f020391f61ac4c
2017-04-04 16:42:31 +05:30
Jenkins 3fa5659855 Merge "Fix: CLI metric-create using project-id fails" 2017-02-28 16:46:50 +00:00
Jenkins cc793ac8a0 Merge "Fix notification-patch CLI fails if type not given" 2017-02-22 15:55:52 +00:00
Tomasz Trębski f9696d6816 Migrate fully to ostestr
Following commit migrates python-monascaclient
fully to os-testr and oslo.test

Additionally:
- removed mock requirement (unused)
- removed sphinx requirement (unused)

Change-Id: If534134ced5081ccdf40ab7963e087e29672608d
2017-02-20 11:07:46 +01:00
Craig Bryant 537389cad3 Fix notification-patch CLI fails if type not given
The type field was always being sent to the API even if a value wasn't
given. Change code to only send type field if --type was actually used
as an argument

Added tests for this case

Change-Id: Idb495eceb189db341753fd82be57d414e17cd64b
Closes-Bug: #1664326
2017-02-13 22:23:38 -07:00
Craig Bryant 3736d114be Fix: CLI metric-create using project-id fails
The tenant-id query parameter was being passed as a list instead
of as a string

Added test

Change-Id: Ib8300530a3a17d9cb96962c1ffdf5362ed0553ca
Closes-Bug:#1664415
2017-02-13 18:27:08 -07:00
Jenkins 27cebc673c Merge "Use correct ENV variables for scoping" 2017-01-20 16:47:46 +00:00
Jenkins 7b15f2211d Merge "Don't send X-Auth- headers in requests" 2017-01-16 11:54:34 +00:00
Jamie Lennox 6105dddba8 Don't send X-Auth- headers in requests
From looking through monasca server code there is nowhere that is
actuall reading the X-Auth-User, X-Auth-Key, X-Auth-Url or X-Auth-Region
headers. The shell also enforces that a user provide keystone
authentication. This means we are sending the server a user's password
for no reason. They were initially added in the very first monascaclient
commit so assume they were unneeded and remove it.

Change-Id: Ic6e6dd1a14474537ab9180bb4af1a3fae09fc8a6
2017-01-12 09:04:54 -07:00
Jenkins 37f3899577 Merge "Add __ne__ built-in function" 2017-01-10 21:31:13 +00:00
Jamie Lennox d50f05a60b Use requests-mock instead of custom fakes
Mocking out the entire http layer means there is no testing being
performed that a request is actually being sent out as expected.
requests-mock mocks requests and responses at the point where it would
be sent out over the wire so we can better see actual made requests.

Change-Id: I66657ecc6a53b23cecfe92c911aee6fd27c68f40
2017-01-09 11:11:13 -07:00
Jenkins de70f047dd Merge "Add list_next for pagination" 2016-12-09 06:26:12 +00:00
Jenkins db4ced5b1f Merge "Add state-updated-timestamp filter to alarm count CLI" 2016-12-06 05:33:25 +00:00
gengchc2 83ced3537c Correct reraising of exception
When an exception was caught and rethrown, it should
call 'raise' without any arguments because it shows
the place where an exception occured initially instead
of place where the exception re-raised

Change-Id: Ida52fc0078eebea9441c3caa0efc8f7f4c9b53f2
2016-12-02 10:14:24 +08:00
gecong1973 57be21cd16 Add __ne__ built-in function
In Python 3 __ne__ by default delegates to __eq__ and inverts the
result, but in Python 2 they urge you to define __ne__ when you
define __eq__ for it to work properly [1].There are no implied
relationships among the comparison operators. The truth of x==y does
not imply that x!=y is false. Accordingly, when defining __eq__(),
one should also define __ne__() so that the operators will behave as
expected.
[1]https://docs.python.org/2/reference/datamodel.html#object.__ne__

Change-Id: I52d4b7396136dd3be7b8767dccb0613e8faba536
2016-11-29 09:25:45 +08:00
Ryan Bak 78a8486d1c Add list_next for pagination
Preserves the 'next' link from list queries to allow pagination
and adds a new command to pick the last query where the limit
stopped it

Change-Id: I564c3824b0dd8458e3d6237ec546b4e6e1052334
2016-11-19 22:21:24 -07:00
Cao Xuan Hoang c3bb2b818a Fix LOG.warn to LOG.warning
logging.warn is deprecated in Python 3.
https://docs.python.org/3/library/logging.html#logging.warning

Change-Id: I424f8d946929702e5d71401e1d0f8ed9af6e2015
2016-11-15 13:24:41 +07:00
Steve Martinelli 43f63e00de move old apiclient code out of openstack/common
As part of the first community-wide goal [1], teams were asked
to remove the openstack/common package of their projects
if one existed. This was a byproduct of the old oslo-incubator
form of syncing common functionality.

The package, apiclient, was moved to a top level location
and cliutils was moved to the common module. There are no oslo
specific libraries, the recommended solution is to move it
in tree and maintain it there.

[1] http://governance.openstack.org/goals/ocata/remove-incubated-oslo-code.html

Change-Id: If28f22e5ff6002bef8d9dfc27a694d1100535dc9
2016-11-14 07:41:45 -05:00
Steve Martinelli 8cc2dbde68 remove unused openstack/common/gettextutils.py
the module is completely unused.

Change-Id: I69d7d0dc0284f551d96de31524b7568eaa2e3f9d
2016-11-14 12:41:03 +00:00
Steve Martinelli 746c4c3677 use six.moves.urllib.parse instead of py3kcompat
as part of the openstack wide ocata goal, all references to the
now obsolete oslo-incubator modules (in openstack/common) should
be removed. this is the first step in doing that, a future patch
will move the apiclient to be a top level module.

Change-Id: I0bcd01b3f6ff6c7e562bd9419c6a8e86989b1e27
2016-11-14 07:40:22 -05:00
Joachim Barheine bad6819485 Use correct ENV variables for scoping
Closes-Bug: #1555228
Change-Id: Ib4b5f9fd6f2bb23044df64b5499711f3706c30de
2016-11-14 09:46:15 +00:00
Jenkins 89be3ee5e8 Merge "Fix dimension validation and help message for alarm count" 2016-11-03 01:51:42 +00:00
Ryan Brandt 44cfaa75ec Add state-updated-timestamp filter to alarm count CLI
Change-Id: Ia5808ebea26c6af95e690c029ba511d7f9d8da85
2016-10-27 14:16:07 -06:00
Kaiyan Sheng 635b75e5c3 Dimension value list doesn't recognize dimension name input
When using CLI to query dimension value list,
monasca dimension-value-list --metric-name cpu.user_perc hostname
'Namespace' object has no attribute 'dimension_name'

The attribute name was 'dimension-name' instead of 'dimension_name'

Change-Id: I826fa95beafa106bbc7189928d258302fb288c44
2016-10-09 22:30:43 -06:00