Merge "Added support for os_tenant_{name,id} after os_project_"

This commit is contained in:
Jenkins 2017-05-05 08:37:52 +00:00 committed by Gerrit Code Review
commit fed80a73ba
3 changed files with 48 additions and 0 deletions

View File

@ -95,6 +95,8 @@ When using Keystone to obtain the token and endpoint::
export OS_AUTH_VERSION=
When OS_USER_DOMAIN_NAME is not set, then 'Default' is assumed. Alternatively IDs can be used instead of names.
Although *deprecated*, but OS_TENANT_NAME and OS_TENANT_ID can be used for
OS_PROEJCT_NAME and OS_PROJECT_ID respectively.
When using Vagrant Environment with middleware disabled::

View File

@ -23,6 +23,7 @@ import argparse
import logging
import string
import sys
import warnings
from six.moves.urllib.parse import urljoin
@ -36,6 +37,17 @@ from monascaclient import ksclient
logger = logging.getLogger(__name__)
class DeprecatedStore(argparse._StoreAction):
def __init__(self, *args, **kwargs):
super(DeprecatedStore, self).__init__(*args, **kwargs)
def __call__(self, parser, namespace, values, option_string=None):
warnings.filterwarnings(action='default', category=DeprecationWarning, module='.*monascaclient.*')
warnings.warn("{} is deprecated".format(",".join(self.option_strings)),
DeprecationWarning)
setattr(namespace, self.dest, values)
class MonascaShell(object):
def get_base_parser(self):
@ -142,6 +154,30 @@ class MonascaShell(object):
parser.add_argument('--os_project_name',
help=argparse.SUPPRESS)
parser.add_argument('--os-tenant-name',
dest='os_project_name',
action=DeprecatedStore,
default=utils.env('OS_TENANT_NAME'),
help='(Deprecated, use --os-project_name) '
'Defaults to env[OS_TENANT_NAME].')
parser.add_argument('--os_tenant_name',
dest='os_project_name',
action=DeprecatedStore,
help=argparse.SUPPRESS)
parser.add_argument('--os-tenant-id',
dest='os_project_id',
action=DeprecatedStore,
default=utils.env('OS_TENANT_ID'),
help='(Deprecated, use --os-project_id) '
'Defaults to env[OS_TENANT_ID].')
parser.add_argument('--os_tenant_id',
dest='os_project_id',
action=DeprecatedStore,
help=argparse.SUPPRESS)
parser.add_argument('--os-project-domain-id',
default=utils.env('OS_PROJECT_DOMAIN_ID'),
help='Defaults to env[OS_PROJECT_DOMAIN_ID].')

View File

@ -15,6 +15,7 @@
import re
import sys
import warnings
import fixtures
from keystoneclient.v3 import client as ksclient
@ -149,6 +150,15 @@ class ShellTestCommon(ShellBase):
for r in required:
self.assertRegexpMatches(help_text, r)
def test_deprecated_warning(self):
argrequired = [('--help --os-tenant-name=this', '--os-tenant-name is deprecated'),
('--help --os-tenant-id=this', '--os-tenant-id is deprecated')]
for argstr, required in argrequired:
with warnings.catch_warnings(record=True) as w:
self.shell(argstr)
self.assertEqual(str(w[0].message), required)
self.assertEqual(w[0].category, DeprecationWarning)
class ShellTestMonascaCommands(ShellBase):