From 84f4e1e10c4f18ff61425018a09940581747ec78 Mon Sep 17 00:00:00 2001 From: Andrey Kurilin Date: Wed, 22 Jun 2016 16:35:21 +0300 Subject: [PATCH] Raise an exception in v2.client for direct_use The direct use of novaclient.v2.client.Client was deprecated long time ago (2.29.0 release of novaclient, which relates to Liberty release of OpenStack). It is time to move from warning message to an exception. It will allow us to change novaclient.v2.client.Client interface and keep compatible stuff to novaclient.client.Client. Change-Id: I6e6c6eebcf7992d553a2f85f57b8c2ede0cc8311 Related-Bug: #1493576 --- novaclient/v2/client.py | 19 ++++++++++--------- ...rect-use-of-v2client-c8e1ee2afefec5a1.yaml | 5 +++++ 2 files changed, 15 insertions(+), 9 deletions(-) create mode 100644 releasenotes/notes/restrict-direct-use-of-v2client-c8e1ee2afefec5a1.yaml diff --git a/novaclient/v2/client.py b/novaclient/v2/client.py index c202b754e..f5dee15dc 100644 --- a/novaclient/v2/client.py +++ b/novaclient/v2/client.py @@ -17,7 +17,8 @@ import logging from novaclient import api_versions from novaclient import client -from novaclient.i18n import _LW +from novaclient import exceptions +from novaclient.i18n import _LE from novaclient.v2 import agents from novaclient.v2 import aggregates from novaclient.v2 import availability_zones @@ -101,18 +102,18 @@ class Client(object): :param str session: Session :param str auth: Auth :param api_version: Compute API version - :param direct_use: Direct use + :param direct_use: Inner variable of novaclient. Do not use it outside + novaclient. It's restricted. :param logger: Logger :type api_version: novaclient.api_versions.APIVersion """ if direct_use: - import warnings - - warnings.warn( - _LW("'novaclient.v2.client.Client' is not designed to be " - "initialized directly. It is inner class of novaclient. " - "Please, use 'novaclient.client.Client' instead. " - "Related lp bug-report: 1493576")) + raise exceptions.Forbidden( + 403, _LE("'novaclient.v2.client.Client' is not designed to be " + "initialized directly. It is inner class of " + "novaclient. You should use " + "'novaclient.client.Client' instead. Related lp " + "bug-report: 1493576")) # FIXME(comstud): Rename the api_key argument above when we # know it's not being used as keyword argument diff --git a/releasenotes/notes/restrict-direct-use-of-v2client-c8e1ee2afefec5a1.yaml b/releasenotes/notes/restrict-direct-use-of-v2client-c8e1ee2afefec5a1.yaml new file mode 100644 index 000000000..0e90cc810 --- /dev/null +++ b/releasenotes/notes/restrict-direct-use-of-v2client-c8e1ee2afefec5a1.yaml @@ -0,0 +1,5 @@ +--- +upgrade: + - novaclient.v2.client.Client raises an exception in case of direct usage + instead of warning message. novaclient.client.Client is a primary + interface to initialize the python client for Nova.