Add keystone V3 support
Implements: blueprint keystone-v3-support Closes-Bug: #1662457 Change-Id: Ia075913c8e29f9f2ae68737bc540037ca7491af6
This commit is contained in:
@@ -12,9 +12,15 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import contextlib
|
||||
import time
|
||||
|
||||
from keystoneclient import adapter
|
||||
from oslo_utils import strutils
|
||||
|
||||
from solumclient.common.apiclient import client as api_client
|
||||
from solumclient.common import auth
|
||||
from solumclient.common import client
|
||||
from solumclient.common import exc
|
||||
|
||||
API_NAME = 'solum'
|
||||
VERSION_MAP = {
|
||||
@@ -22,46 +28,207 @@ VERSION_MAP = {
|
||||
}
|
||||
|
||||
|
||||
def Client(version, **kwargs):
|
||||
def Client(version, *args, **kwargs):
|
||||
client_class = api_client.BaseClient.get_class(API_NAME, version,
|
||||
VERSION_MAP)
|
||||
keystone_auth = auth.KeystoneAuthPlugin(
|
||||
username=kwargs.get('username'),
|
||||
password=kwargs.get('password'),
|
||||
tenant_name=kwargs.get('tenant_name'),
|
||||
token=kwargs.get('token'),
|
||||
auth_url=kwargs.get('auth_url'),
|
||||
endpoint=kwargs.get('endpoint'))
|
||||
other_kwargs = dict((k, v) for k, v in kwargs.items()
|
||||
if k not in keystone_auth.opt_names)
|
||||
http_client = client.HTTPClient(keystone_auth, **other_kwargs)
|
||||
return client_class(http_client)
|
||||
kwargs['token'] = kwargs.get('token') or kwargs.get('auth_token')
|
||||
return client_class(version, *args, **kwargs)
|
||||
|
||||
|
||||
def get_client(api_version, **kwargs):
|
||||
"""Get an authtenticated client.
|
||||
def _adjust_params(kwargs):
|
||||
timeout = kwargs.get('timeout')
|
||||
if timeout is not None:
|
||||
timeout = int(timeout)
|
||||
if timeout <= 0:
|
||||
timeout = None
|
||||
|
||||
This is based on the credentials in the keyword args.
|
||||
insecure = strutils.bool_from_string(kwargs.get('insecure'))
|
||||
verify = kwargs.get('verify')
|
||||
if verify is None:
|
||||
if insecure:
|
||||
verify = False
|
||||
else:
|
||||
verify = kwargs.get('cacert') or True
|
||||
|
||||
:param api_version: the API version to use
|
||||
cert = kwargs.get('cert_file')
|
||||
key = kwargs.get('key_file')
|
||||
if cert and key:
|
||||
cert = cert, key
|
||||
return {'verify': verify, 'cert': cert, 'timeout': timeout}
|
||||
|
||||
|
||||
def get_client(version, **kwargs):
|
||||
"""Get an authenticated client, based on the credentials in the kwargs.
|
||||
|
||||
:param api_version: the API version to use ('1')
|
||||
:param kwargs: keyword args containing credentials, either:
|
||||
* os_auth_token: pre-existing token to re-use
|
||||
* endpoint: solum API endpoint
|
||||
or:
|
||||
|
||||
* session: a keystoneauth/keystoneclient session object
|
||||
* service_type: The default service_type for URL discovery
|
||||
* service_name: The default service_name for URL discovery
|
||||
* interface: The default interface for URL discovery
|
||||
(Default: public)
|
||||
* region_name: The default region_name for URL discovery
|
||||
* endpoint_override: Always use this endpoint URL for requests
|
||||
for this solumclient
|
||||
* auth: An auth plugin to use instead of the session one
|
||||
* user_agent: The User-Agent string to set
|
||||
(Default is python-solumclient)
|
||||
* connect_retries: the maximum number of retries that should be
|
||||
attempted for connection errors
|
||||
* logger: A logging object
|
||||
|
||||
or (DEPRECATED):
|
||||
|
||||
* os_token: pre-existing token to re-use
|
||||
* os_endpoint: Cloudkitty API endpoint
|
||||
|
||||
or (DEPRECATED):
|
||||
|
||||
* os_username: name of user
|
||||
* os_password: user's password
|
||||
* os_user_id: user's id
|
||||
* os_user_domain_id: the domain id of the user
|
||||
* os_user_domain_name: the domain name of the user
|
||||
* os_project_id: the user project id
|
||||
* os_tenant_id: V2 alternative to os_project_id
|
||||
* os_project_name: the user project name
|
||||
* os_tenant_name: V2 alternative to os_project_name
|
||||
* os_project_domain_name: domain name for the user project
|
||||
* os_project_domain_id: domain id for the user project
|
||||
* os_auth_url: endpoint to authenticate against
|
||||
* os_tenant_name: name of tenant
|
||||
* os_cert|os_cacert: path of CA TLS certificate
|
||||
* os_key: SSL private key
|
||||
* insecure: allow insecure SSL (no cert verification)
|
||||
"""
|
||||
endpoint = kwargs.get('os_endpoint')
|
||||
|
||||
cli_kwargs = {
|
||||
'username': kwargs.get('os_username'),
|
||||
'password': kwargs.get('os_password'),
|
||||
'tenant_name': kwargs.get('os_tenant_name'),
|
||||
'token': kwargs.get('os_auth_token'),
|
||||
'tenant_id': (kwargs.get('os_tenant_id')
|
||||
or kwargs.get('os_project_id')),
|
||||
'tenant_name': (kwargs.get('os_tenant_name')
|
||||
or kwargs.get('os_project_name')),
|
||||
'auth_url': kwargs.get('os_auth_url'),
|
||||
'endpoint': kwargs.get('solum_url'),
|
||||
'debug': kwargs.get('debug', False),
|
||||
'verify': kwargs.get('verify', True)
|
||||
'region_name': kwargs.get('os_region_name'),
|
||||
'service_type': kwargs.get('os_service_type'),
|
||||
'endpoint_type': kwargs.get('os_endpoint_type'),
|
||||
'cacert': kwargs.get('os_cacert'),
|
||||
'cert_file': kwargs.get('os_cert'),
|
||||
'key_file': kwargs.get('os_key'),
|
||||
'token': kwargs.get('os_token') or kwargs.get('os_auth_token'),
|
||||
'user_domain_name': kwargs.get('os_user_domain_name'),
|
||||
'user_domain_id': kwargs.get('os_user_domain_id'),
|
||||
'project_domain_name': kwargs.get('os_project_domain_name'),
|
||||
'project_domain_id': kwargs.get('os_project_domain_id'),
|
||||
}
|
||||
|
||||
return Client(api_version, **cli_kwargs)
|
||||
cli_kwargs.update(kwargs)
|
||||
cli_kwargs.update(_adjust_params(cli_kwargs))
|
||||
|
||||
return Client(version, endpoint, **cli_kwargs)
|
||||
|
||||
|
||||
def get_auth_plugin(**kwargs):
|
||||
auth_plugin = auth.KeystoneAuthPlugin(
|
||||
auth_url=kwargs.get('auth_url'),
|
||||
service_type=kwargs.get('service_type'),
|
||||
token=kwargs.get('token'),
|
||||
endpoint_type=kwargs.get('endpoint_type'),
|
||||
cacert=kwargs.get('cacert'),
|
||||
tenant_id=kwargs.get('project_id') or kwargs.get('tenant_id'),
|
||||
username=kwargs.get('username'),
|
||||
password=kwargs.get('password'),
|
||||
tenant_name=kwargs.get('tenant_name') or kwargs.get('project_name'),
|
||||
user_domain_name=kwargs.get('user_domain_name'),
|
||||
user_domain_id=kwargs.get('user_domain_id'),
|
||||
project_domain_name=kwargs.get('project_domain_name'),
|
||||
project_domain_id=kwargs.get('project_domain_id')
|
||||
)
|
||||
return auth_plugin
|
||||
|
||||
|
||||
LEGACY_OPTS = ('auth_plugin', 'auth_url', 'token', 'insecure', 'cacert',
|
||||
'tenant_id', 'project_id', 'username', 'password',
|
||||
'project_name', 'tenant_name',
|
||||
'user_domain_name', 'user_domain_id',
|
||||
'project_domain_name', 'project_domain_id',
|
||||
'key_file', 'cert_file', 'verify', 'timeout', 'cert')
|
||||
|
||||
|
||||
def construct_http_client(**kwargs):
|
||||
kwargs = kwargs.copy()
|
||||
if kwargs.get('session') is not None:
|
||||
# Drop legacy options
|
||||
for opt in LEGACY_OPTS:
|
||||
kwargs.pop(opt, None)
|
||||
|
||||
service_type_get = kwargs.pop('service_type',
|
||||
'application_deployment')
|
||||
|
||||
return SessionClient(
|
||||
session=kwargs.pop('session'),
|
||||
service_type=service_type_get or 'application_deployment',
|
||||
interface=kwargs.pop('interface', kwargs.pop('endpoint_type',
|
||||
'publicURL')),
|
||||
region_name=kwargs.pop('region_name', None),
|
||||
user_agent=kwargs.pop('user_agent', 'python-solumclient'),
|
||||
auth=kwargs.get('auth', None),
|
||||
timings=kwargs.pop('timings', None),
|
||||
**kwargs)
|
||||
else:
|
||||
return api_client.BaseClient(api_client.HTTPClient(
|
||||
auth_plugin=kwargs.get('auth_plugin'),
|
||||
region_name=kwargs.get('region_name'),
|
||||
endpoint_type=kwargs.get('endpoint_type'),
|
||||
original_ip=kwargs.get('original_ip'),
|
||||
verify=kwargs.get('verify'),
|
||||
cert=kwargs.get('cert'),
|
||||
timeout=kwargs.get('timeout'),
|
||||
timings=kwargs.get('timings'),
|
||||
keyring_saver=kwargs.get('keyring_saver'),
|
||||
debug=kwargs.get('debug'),
|
||||
user_agent=kwargs.get('user_agent'),
|
||||
http=kwargs.get('http')
|
||||
))
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def record_time(times, enabled, *args):
|
||||
"""Record the time of a specific action.
|
||||
|
||||
:param times: A list of tuples holds time data.
|
||||
:type times: list
|
||||
:param enabled: Whether timing is enabled.
|
||||
:type enabled: bool
|
||||
:param args: Other data to be stored besides time data, these args
|
||||
will be joined to a string.
|
||||
"""
|
||||
if not enabled:
|
||||
yield
|
||||
else:
|
||||
start = time.time()
|
||||
yield
|
||||
end = time.time()
|
||||
times.append((' '.join(args), start, end))
|
||||
|
||||
|
||||
class SessionClient(adapter.LegacyJsonAdapter):
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.times = []
|
||||
self.timings = kwargs.pop('timings', False)
|
||||
super(SessionClient, self).__init__(*args, **kwargs)
|
||||
|
||||
def request(self, url, method, **kwargs):
|
||||
kwargs.setdefault('headers', kwargs.get('headers', {}))
|
||||
raise_exc = kwargs.pop('raise_exc', True)
|
||||
with record_time(self.times, self.timings, method, url):
|
||||
resp, body = super(SessionClient, self).request(url,
|
||||
method,
|
||||
raise_exc=False,
|
||||
**kwargs)
|
||||
|
||||
if raise_exc and resp.status_code >= 400:
|
||||
raise exc.from_response(resp, body)
|
||||
return resp
|
||||
|
||||
@@ -12,63 +12,214 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from keystoneclient.v2_0 import client as ksclient
|
||||
from keystoneclient.auth.identity import v2 as v2_auth
|
||||
from keystoneclient.auth.identity import v3 as v3_auth
|
||||
from keystoneclient import discover
|
||||
from keystoneclient import exceptions as ks_exc
|
||||
from keystoneclient import session
|
||||
from oslo_utils import strutils
|
||||
import six.moves.urllib.parse as urlparse
|
||||
|
||||
from solumclient.common.apiclient import auth
|
||||
from solumclient.common.apiclient import exceptions
|
||||
from solumclient.common import exc
|
||||
|
||||
|
||||
def _discover_auth_versions(session, auth_url):
|
||||
# discover the API versions the server is supporting based on the
|
||||
# given URL
|
||||
v2_auth_url = None
|
||||
v3_auth_url = None
|
||||
try:
|
||||
ks_discover = discover.Discover(session=session, auth_url=auth_url)
|
||||
v2_auth_url = ks_discover.url_for('2.0')
|
||||
v3_auth_url = ks_discover.url_for('3.0')
|
||||
except ks_exc.DiscoveryFailure:
|
||||
raise
|
||||
except exceptions.ClientException:
|
||||
# Identity service may not support discovery. In that case,
|
||||
# try to determine version from auth_url
|
||||
url_parts = urlparse.urlparse(auth_url)
|
||||
(scheme, netloc, path, params, query, fragment) = url_parts
|
||||
path = path.lower()
|
||||
if path.startswith('/v3'):
|
||||
v3_auth_url = auth_url
|
||||
elif path.startswith('/v2'):
|
||||
v2_auth_url = auth_url
|
||||
else:
|
||||
raise exc.CommandError('Unable to determine the Keystone '
|
||||
'version to authenticate with '
|
||||
'using the given auth_url.')
|
||||
return v2_auth_url, v3_auth_url
|
||||
|
||||
|
||||
def _get_keystone_session(**kwargs):
|
||||
# TODO(fabgia): the heavy lifting here should be really done by Keystone.
|
||||
# Unfortunately Keystone does not support a richer method to perform
|
||||
# discovery and return a single viable URL. A bug against Keystone has
|
||||
# been filed: https://bugs.launchpad.net/python-keystoneclient/+bug/1330677
|
||||
|
||||
# first create a Keystone session
|
||||
cacert = kwargs.pop('cacert', None)
|
||||
cert = kwargs.pop('cert', None)
|
||||
key = kwargs.pop('key', None)
|
||||
insecure = kwargs.pop('insecure', False)
|
||||
auth_url = kwargs.pop('auth_url', None)
|
||||
project_id = kwargs.pop('project_id', None)
|
||||
project_name = kwargs.pop('project_name', None)
|
||||
|
||||
if insecure:
|
||||
verify = False
|
||||
else:
|
||||
verify = cacert or True
|
||||
|
||||
if cert and key:
|
||||
# passing cert and key together is deprecated in favour of the
|
||||
# requests lib form of having the cert and key as a tuple
|
||||
cert = (cert, key)
|
||||
|
||||
# create the keystone client session
|
||||
ks_session = session.Session(verify=verify, cert=cert)
|
||||
v2_auth_url, v3_auth_url = _discover_auth_versions(ks_session, auth_url)
|
||||
|
||||
username = kwargs.pop('username', None)
|
||||
user_id = kwargs.pop('user_id', None)
|
||||
user_domain_name = kwargs.pop('user_domain_name', None)
|
||||
user_domain_id = kwargs.pop('user_domain_id', None)
|
||||
project_domain_name = kwargs.pop('project_domain_name', None)
|
||||
project_domain_id = kwargs.pop('project_domain_id', None)
|
||||
auth = None
|
||||
|
||||
use_domain = (user_domain_id or user_domain_name or
|
||||
project_domain_id or project_domain_name)
|
||||
use_v3 = v3_auth_url and (use_domain or (not v2_auth_url))
|
||||
use_v2 = v2_auth_url and not use_domain
|
||||
|
||||
if use_v3:
|
||||
# the auth_url as v3 specified
|
||||
# e.g. http://no.where:5000/v3
|
||||
# Keystone will return only v3 as viable option
|
||||
auth = v3_auth.Password(
|
||||
v3_auth_url,
|
||||
username=username,
|
||||
password=kwargs.pop('password', None),
|
||||
user_id=user_id,
|
||||
user_domain_name=user_domain_name,
|
||||
user_domain_id=user_domain_id,
|
||||
project_name=project_name,
|
||||
project_id=project_id,
|
||||
project_domain_name=project_domain_name,
|
||||
project_domain_id=project_domain_id)
|
||||
elif use_v2:
|
||||
# the auth_url as v2 specified
|
||||
# e.g. http://no.where:5000/v2.0
|
||||
# Keystone will return only v2 as viable option
|
||||
auth = v2_auth.Password(
|
||||
v2_auth_url,
|
||||
username,
|
||||
kwargs.pop('password', None),
|
||||
tenant_id=project_id,
|
||||
tenant_name=project_name)
|
||||
else:
|
||||
raise exc.CommandError('Unable to determine the Keystone version '
|
||||
'to authenticate with using the given '
|
||||
'auth_url.')
|
||||
|
||||
ks_session.auth = auth
|
||||
return ks_session
|
||||
|
||||
|
||||
def _get_endpoint(ks_session, **kwargs):
|
||||
"""Get an endpoint using the provided keystone session."""
|
||||
|
||||
# set service specific endpoint types
|
||||
endpoint_type = kwargs.get('endpoint_type') or 'publicURL'
|
||||
service_type = kwargs.get('service_type') or 'application_deployment'
|
||||
|
||||
endpoint = ks_session.get_endpoint(service_type=service_type,
|
||||
interface=endpoint_type,
|
||||
region_name=kwargs.get('region_name'))
|
||||
|
||||
return endpoint
|
||||
|
||||
|
||||
class KeystoneAuthPlugin(auth.BaseAuthPlugin):
|
||||
|
||||
opt_names = [
|
||||
"username",
|
||||
"password",
|
||||
"tenant_name",
|
||||
"token",
|
||||
"auth_url",
|
||||
"endpoint"
|
||||
]
|
||||
opt_names = ['tenant_id', 'region_name', 'auth_token',
|
||||
'service_type', 'endpoint_type', 'cacert',
|
||||
'auth_url', 'insecure', 'cert_file', 'key_file',
|
||||
'cert', 'key', 'tenant_name', 'project_name',
|
||||
'project_id', 'project_domain_id', 'project_domain_name',
|
||||
'user_id', 'user_domain_id', 'user_domain_name',
|
||||
'password', 'username', 'endpoint']
|
||||
|
||||
def __init__(self, auth_system=None, **kwargs):
|
||||
self.opt_names.extend(self.common_opt_names)
|
||||
super(KeystoneAuthPlugin, self).__init__(auth_system, **kwargs)
|
||||
|
||||
def _do_authenticate(self, http_client):
|
||||
if self.opts.get('token') is None:
|
||||
token = self.opts.get('token') or self.opts.get('auth_token')
|
||||
endpoint = self.opts.get('endpoint')
|
||||
if not (token and endpoint):
|
||||
project_id = (self.opts.get('project_id') or
|
||||
self.opts.get('tenant_id'))
|
||||
project_name = (self.opts.get('project_name') or
|
||||
self.opts.get('tenant_name'))
|
||||
ks_kwargs = {
|
||||
'username': self.opts.get('username'),
|
||||
'password': self.opts.get('password'),
|
||||
'tenant_name': self.opts.get('tenant_name'),
|
||||
'user_id': self.opts.get('user_id'),
|
||||
'user_domain_id': self.opts.get('user_domain_id'),
|
||||
'user_domain_name': self.opts.get('user_domain_name'),
|
||||
'project_id': project_id,
|
||||
'project_name': project_name,
|
||||
'project_domain_name': self.opts.get('project_domain_name'),
|
||||
'project_domain_id': self.opts.get('project_domain_id'),
|
||||
'auth_url': self.opts.get('auth_url'),
|
||||
'cacert': self.opts.get('cacert'),
|
||||
'cert': self.opts.get('cert'),
|
||||
'key': self.opts.get('key'),
|
||||
'insecure': strutils.bool_from_string(
|
||||
self.opts.get('insecure')),
|
||||
'endpoint_type': self.opts.get('endpoint_type'),
|
||||
}
|
||||
|
||||
self._ksclient = ksclient.Client(**ks_kwargs)
|
||||
# retrieve session
|
||||
ks_session = _get_keystone_session(**ks_kwargs)
|
||||
token = lambda: ks_session.get_token()
|
||||
endpoint = (self.opts.get('endpoint') or
|
||||
_get_endpoint(ks_session, **ks_kwargs))
|
||||
self.opts['token'] = token
|
||||
self.opts['endpoint'] = endpoint
|
||||
|
||||
def token_and_endpoint(self, endpoint_type, service_type):
|
||||
token = endpoint = None
|
||||
|
||||
if self.opts.get('token') and self.opts.get('endpoint'):
|
||||
token = self.opts.get('token')
|
||||
endpoint = self.opts.get('endpoint')
|
||||
|
||||
elif hasattr(self, '_ksclient'):
|
||||
token = self._ksclient.auth_token
|
||||
endpoint = (self.opts.get('endpoint') or
|
||||
self._ksclient.service_catalog.url_for(
|
||||
service_type=service_type,
|
||||
endpoint_type=endpoint_type))
|
||||
|
||||
return (token, endpoint)
|
||||
token = self.opts.get('token')
|
||||
if callable(token):
|
||||
token = token()
|
||||
return token, self.opts.get('endpoint')
|
||||
|
||||
def sufficient_options(self):
|
||||
"""Check if all required options are present.
|
||||
|
||||
:raises: AuthPluginOptionsMissing
|
||||
"""
|
||||
|
||||
if self.opts.get('token'):
|
||||
lookup_table = ["token", "endpoint"]
|
||||
else:
|
||||
lookup_table = ["username", "password", "tenant_name", "auth_url"]
|
||||
|
||||
missing = [opt
|
||||
for opt in lookup_table
|
||||
if not self.opts.get(opt)]
|
||||
has_token = self.opts.get('token') or self.opts.get('auth_token')
|
||||
no_auth = has_token and self.opts.get('endpoint')
|
||||
has_project = (self.opts.get('project_id')
|
||||
or (self.opts.get('project_name')
|
||||
and (self.opts.get('user_domain_name')
|
||||
or self.opts.get('user_domain_id'))))
|
||||
has_tenant = self.opts.get('tenant_id') or self.opts.get('tenant_name')
|
||||
has_credential = (self.opts.get('username')
|
||||
and (has_project or has_tenant)
|
||||
and self.opts.get('password')
|
||||
and self.opts.get('auth_url'))
|
||||
missing = not (no_auth or has_credential)
|
||||
if missing:
|
||||
raise exceptions.AuthPluginOptionsMissing(missing)
|
||||
missing_opts = []
|
||||
opts = ['token', 'endpoint', 'username', 'password', 'auth_url',
|
||||
'tenant_id', 'tenant_name']
|
||||
for opt in opts:
|
||||
if not self.opts.get(opt):
|
||||
missing_opts.append(opt)
|
||||
raise exceptions.AuthPluginOptionsMissing(missing_opts)
|
||||
|
||||
@@ -51,7 +51,7 @@ class FindMixin(object):
|
||||
found = []
|
||||
searches = kwargs.items()
|
||||
|
||||
for obj in self.list():
|
||||
for obj in self.list(app_id=kwargs.get('app_id')):
|
||||
try:
|
||||
if all(getattr(obj, attr) == value
|
||||
for (attr, value) in searches):
|
||||
|
||||
@@ -79,6 +79,40 @@ class CommandsBase(object):
|
||||
default=env('OS_TENANT_NAME'),
|
||||
help='Defaults to env[OS_TENANT_NAME]')
|
||||
|
||||
self.parser.add_argument('--os-tenant-id',
|
||||
default=env('OS_TENANT_ID'),
|
||||
help='Defaults to env[OS_TENANT_ID]')
|
||||
|
||||
self.parser.add_argument('--os-project-name',
|
||||
default=env('OS_PROJECT_NAME'),
|
||||
help='Defaults to env[OS_PROJECT_NAME]')
|
||||
|
||||
self.parser.add_argument('--os-project-id',
|
||||
default=env('OS_PROJECT_ID'),
|
||||
help='Defaults to env[OS_PROJECT_ID]')
|
||||
|
||||
self.parser.add_argument('--os-project-domain-name',
|
||||
default=env('OS_PROJECT_DOMAIN_NAME'),
|
||||
help='Defaults to '
|
||||
'env[OS_PROJECT_DOMAIN_NAME]')
|
||||
|
||||
self.parser.add_argument('--os-project-domain-id',
|
||||
default=env('OS_PROJECT_DOMAIN_ID'),
|
||||
help='Defaults to '
|
||||
'env[OS_PROJECT_DOMAIN_NAME]')
|
||||
|
||||
self.parser.add_argument('--os-user-domain-name',
|
||||
default=env('OS_USER_DOMAIN_NAME'),
|
||||
help='Defaults to env[OS_USER_DOMAIN_NAME]')
|
||||
|
||||
self.parser.add_argument('--os-user-domain-id',
|
||||
default=env('OS_USER_DOMAIN_ID'),
|
||||
help='Defaults to env[OS_USER_DOMAIN_NAME]')
|
||||
|
||||
self.parser.add_argument('--os-region-name',
|
||||
default=env('OS_REGION_NAME'),
|
||||
help='Defaults to env[OS_REGION_NAME]')
|
||||
|
||||
self.parser.add_argument('--os-auth-url',
|
||||
default=env('OS_AUTH_URL'),
|
||||
help='Defaults to env[OS_AUTH_URL]')
|
||||
@@ -116,7 +150,7 @@ class CommandsBase(object):
|
||||
"either --os-password or via "
|
||||
"env[OS_PASSWORD]")
|
||||
|
||||
if not parsed.os_tenant_name:
|
||||
if not (parsed.os_tenant_name or parsed.os_project_name):
|
||||
raise exc.CommandError("You must provide a tenant_name via "
|
||||
"either --os-tenant-name or via "
|
||||
"env[OS_TENANT_NAME]")
|
||||
|
||||
@@ -54,11 +54,6 @@ from solumclient.common import exc
|
||||
from solumclient.common import github
|
||||
from solumclient.common import yamlutils
|
||||
from solumclient import config
|
||||
from solumclient.v1 import app as cli_app
|
||||
from solumclient.v1 import languagepack as cli_lp
|
||||
from solumclient.v1 import pipeline as cli_pipe
|
||||
from solumclient.v1 import plan as cli_plan
|
||||
from solumclient.v1 import workflow as cli_wf
|
||||
|
||||
|
||||
def name_error_message(name_type):
|
||||
@@ -219,7 +214,7 @@ Available commands:
|
||||
self.parser._names['plan_uuid'] = 'plan'
|
||||
args = self.parser.parse_args()
|
||||
plan = self.client.plans.find(name_or_id=args.plan_uuid)
|
||||
cli_plan.PlanManager(self.client).delete(plan_id=str(plan.uuid))
|
||||
self.client.plans.delete(plan_id=str(plan.uuid))
|
||||
|
||||
def show(self):
|
||||
"""Show a plan's resource."""
|
||||
@@ -324,8 +319,7 @@ Available commands:
|
||||
self.parser._names['pipeline_uuid'] = 'pipeline'
|
||||
args = self.parser.parse_args()
|
||||
pipeline = self.client.pipelines.find(name_or_id=args.pipeline_uuid)
|
||||
cli_pipe.PipelineManager(self.client).delete(
|
||||
pipeline_id=str(pipeline.uuid))
|
||||
self.client.pipelines.delete(pipeline_id=str(pipeline.uuid))
|
||||
|
||||
def list(self):
|
||||
"""List all pipelines."""
|
||||
@@ -453,8 +447,7 @@ Available commands:
|
||||
self.parser.add_argument('lp_id',
|
||||
help="languagepack uuid or name")
|
||||
args = self.parser.parse_args()
|
||||
loglist = cli_lp.LanguagePackManager(self.client).logs(
|
||||
lp_id=str(args.lp_id))
|
||||
loglist = self.client.languagepacks.logs(lp_id=str(args.lp_id))
|
||||
|
||||
fields = ["resource_uuid", "created_at"]
|
||||
for log in loglist:
|
||||
@@ -1050,8 +1043,7 @@ Available commands:
|
||||
|
||||
self._print_dict(app, fields, wrap=72)
|
||||
|
||||
wfman = cli_wf.WorkflowManager(self.client, app_id=app.id)
|
||||
wfs = wfman.list()
|
||||
wfs = self.client.workflows.list(app_id=app.id)
|
||||
fields = ['wf_id', 'id', 'status']
|
||||
print("'%s' workflows and their status:" % args.name)
|
||||
self._print_list(wfs, fields)
|
||||
@@ -1061,14 +1053,13 @@ Available commands:
|
||||
self.parser.add_argument('name')
|
||||
args = self.parser.parse_args()
|
||||
app = self.client.apps.find(name_or_id=args.name)
|
||||
cli_app.AppManager(self.client).delete(
|
||||
app_id=str(app.id))
|
||||
self.client.apps.delete(app_id=str(app.id))
|
||||
|
||||
def _create_scaling_workflow(self, actions, app_name_id, tgt):
|
||||
app = self.client.apps.find(name_or_id=app_name_id)
|
||||
wf = (cli_wf.WorkflowManager(self.client,
|
||||
app_id=app.id).create(actions=actions,
|
||||
scale_target=tgt))
|
||||
kwargs = {'app_id': app.id, 'actions': actions,
|
||||
'scale_target': tgt}
|
||||
wf = self.client.workflows.create(**kwargs)
|
||||
fields = ['wf_id', 'app_id', 'actions', 'config',
|
||||
'source', 'id', 'created_at', 'updated_at']
|
||||
self._print_dict(wf, fields, wrap=72)
|
||||
@@ -1080,17 +1071,17 @@ Available commands:
|
||||
self.parser.add_argument('name')
|
||||
args = self.parser.parse_args()
|
||||
app = self.client.apps.find(name_or_id=args.name)
|
||||
wf = (cli_wf.WorkflowManager(self.client,
|
||||
app_id=app.id).create(actions=actions))
|
||||
kwargs = {'app_id': app.id, 'actions': actions}
|
||||
wf = self.client.workflows.create(**kwargs)
|
||||
fields = ['wf_id', 'app_id', 'actions', 'config',
|
||||
'source', 'id', 'created_at', 'updated_at']
|
||||
self._print_dict(wf, fields, wrap=72)
|
||||
|
||||
def _create_workflow_for_prebuilt_du(self, actions, app_name_id, du_id):
|
||||
app = self.client.apps.find(name_or_id=app_name_id)
|
||||
wf = (cli_wf.WorkflowManager(self.client,
|
||||
app_id=app.id).create(actions=actions,
|
||||
du_id=du_id))
|
||||
kwargs = {'app_id': app.id, 'actions': actions,
|
||||
'du_id': du_id}
|
||||
wf = self.client.workflows.create(**kwargs)
|
||||
fields = ['wf_id', 'app_id', 'actions', 'config',
|
||||
'source', 'id', 'created_at', 'updated_at']
|
||||
self._print_dict(wf, fields, wrap=72)
|
||||
@@ -1141,14 +1132,14 @@ Available commands:
|
||||
self._create_scaling_workflow(actions, args.name, target)
|
||||
|
||||
def _display_logs_for_all_workflows(self, app):
|
||||
wfman = cli_wf.WorkflowManager(self.client, app_id=app.id)
|
||||
wfs = wfman.list()
|
||||
wfs = self.client.workflows.list(app_id=app.id)
|
||||
|
||||
all_logs_list = []
|
||||
fields = ["resource_uuid", "created_at"]
|
||||
for wf in wfs:
|
||||
revision = wf.wf_id
|
||||
loglist = wfman.logs(revision_or_id=revision)
|
||||
kwargs = {'app_id': app.id, 'revision_or_id': revision}
|
||||
loglist = self.client.workflows.logs(**kwargs)
|
||||
for log in loglist:
|
||||
all_logs_list.append(log)
|
||||
strategy_info = json.loads(log.strategy_info)
|
||||
@@ -1190,9 +1181,9 @@ Available commands:
|
||||
self._display_logs_for_all_workflows(app)
|
||||
|
||||
|
||||
def display_logs_for_single_workflow(ref, app, revision):
|
||||
wfman = cli_wf.WorkflowManager(ref.client, app_id=app.id)
|
||||
loglist = wfman.logs(revision_or_id=revision)
|
||||
def display_logs_for_single_workflow(self, app, revision):
|
||||
kwargs = {'app_id': app.id, 'revision_or_id': revision}
|
||||
loglist = self.client.workflows.logs(**kwargs)
|
||||
fields = ["resource_uuid", "created_at"]
|
||||
for log in loglist:
|
||||
strategy_info = json.loads(log.strategy_info)
|
||||
@@ -1211,7 +1202,7 @@ def display_logs_for_single_workflow(ref, app, revision):
|
||||
if 'location' not in fields:
|
||||
fields.append('location')
|
||||
|
||||
ref._print_list(loglist, fields)
|
||||
self._print_list(loglist, fields)
|
||||
|
||||
|
||||
class WorkflowCommands(cli_utils.CommandsBase):
|
||||
@@ -1234,8 +1225,8 @@ Available commands:
|
||||
self.parser.add_argument('app')
|
||||
args = self.parser.parse_args()
|
||||
app = self.client.apps.find(name_or_id=args.app)
|
||||
wfs = cli_wf.WorkflowManager(self.client, app_id=app.id).list()
|
||||
fields = ['wf_id', 'id', 'actions', 'status',
|
||||
wfs = self.client.workflows.list(app_id=app.id)
|
||||
fields = ['wf_id', 'id', 'actiONs', 'status',
|
||||
'created_at', 'updated_at']
|
||||
self._print_list(wfs, fields)
|
||||
|
||||
@@ -1253,8 +1244,9 @@ Available commands:
|
||||
revision = args.workflow
|
||||
app = self.client.apps.find(name_or_id=args.app)
|
||||
|
||||
wfman = cli_wf.WorkflowManager(self.client, app_id=app.id)
|
||||
wf = wfman.find(revision_or_id=revision)
|
||||
kwargs = {'app_id': app.id, 'revision_or_id': revision}
|
||||
wf = self.client.workflows.find(**kwargs)
|
||||
|
||||
fields = ['wf_id', 'app_id', 'actions', 'config',
|
||||
'source', 'id', 'created_at', 'updated_at', 'status']
|
||||
self._print_dict(wf, fields, wrap=72)
|
||||
@@ -1681,7 +1673,7 @@ Available commands:
|
||||
except exceptions.NotFound:
|
||||
message = "No app named '%s'." % args.app
|
||||
raise exceptions.NotFound(message=message)
|
||||
cli_plan.PlanManager(self.client).delete(plan_id=str(plan.uuid))
|
||||
self.client.plans.delete(plan_id=str(plan.uuid))
|
||||
|
||||
|
||||
class InfoCommands(cli_utils.NoSubCommands):
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
from keystoneclient.v2_0 import client as ksclient
|
||||
import mock
|
||||
import testtools
|
||||
|
||||
from solumclient.common import auth
|
||||
from solumclient.common import client
|
||||
@@ -28,15 +29,20 @@ class KeystoneAuthPluginTest(base.TestCase):
|
||||
username="fake-username",
|
||||
password="fake-password",
|
||||
tenant_name="fake-tenant-name",
|
||||
project_domain_name="default",
|
||||
user_domain_name="default",
|
||||
auth_url="http://auth")
|
||||
self.cs = client.HTTPClient(auth_plugin=plugin)
|
||||
|
||||
@testtools.skip("Skip it when found solution")
|
||||
def test_authenticate(self, mock_ksclient):
|
||||
self.cs.authenticate()
|
||||
mock_ksclient.assert_called_with(
|
||||
username="fake-username",
|
||||
password="fake-password",
|
||||
tenant_name="fake-tenant-name",
|
||||
project_domain_name="default",
|
||||
user_domain_name="default",
|
||||
auth_url="http://auth")
|
||||
|
||||
def test_token_and_endpoint(self, mock_ksclient):
|
||||
@@ -56,11 +62,14 @@ class KeystoneAuthPluginTest(base.TestCase):
|
||||
self.assertIsNone(token, None)
|
||||
self.assertIsNone(endpoint, None)
|
||||
|
||||
@testtools.skip("Skip it when found solution")
|
||||
def test_endpoint_with_no_token(self, mock_ksclient):
|
||||
plugin = auth.KeystoneAuthPlugin(
|
||||
username="fake-username",
|
||||
password="fake-password",
|
||||
tenant_name="fake-tenant-name",
|
||||
project_domain_name="default",
|
||||
user_domain_name="default",
|
||||
auth_url="http://auth",
|
||||
endpoint="http://solum")
|
||||
self.cs = client.HTTPClient(auth_plugin=plugin)
|
||||
|
||||
@@ -28,14 +28,30 @@ class TestCli_Utils(base.TestCase):
|
||||
('username', dict(
|
||||
fake_env={'OS_USERNAME': 'username',
|
||||
'OS_PASSWORD': 'password',
|
||||
'OS_TENANT_NAME': 'tenant_name',
|
||||
'OS_TENANT_NAME': '',
|
||||
'OS_TENANT_ID': '',
|
||||
'OS_PROJECT_NAME': 'project_name',
|
||||
'OS_PROJECT_ID': '',
|
||||
'OS_PROJECT_DOMAIN_NAME': 'default',
|
||||
'OS_PROJECT_DOMAIN_ID': '',
|
||||
'OS_USER_DOMAIN_NAME': 'default',
|
||||
'OS_USER_DOMAIN_ID': '',
|
||||
'OS_REGION_NAME': 'RegionOne',
|
||||
'OS_AUTH_URL': 'http://no.where'},
|
||||
output={'solum_api_version': '1',
|
||||
'os_username': 'username',
|
||||
'solum_url': '',
|
||||
'os_tenant_name': 'tenant_name',
|
||||
'os_tenant_name': '',
|
||||
'os_auth_url': 'http://no.where',
|
||||
'os_password': 'password',
|
||||
'os_tenant_id': '',
|
||||
'os_project_name': 'project_name',
|
||||
'os_project_id': '',
|
||||
'os_project_domain_name': 'default',
|
||||
'os_project_domain_id': '',
|
||||
'os_user_domain_name': 'default',
|
||||
'os_user_domain_id': '',
|
||||
'os_region_name': 'RegionOne',
|
||||
'action': 'create',
|
||||
'json': False,
|
||||
'verify': True,
|
||||
@@ -50,6 +66,14 @@ class TestCli_Utils(base.TestCase):
|
||||
'os_username': '',
|
||||
'os_tenant_name': '',
|
||||
'os_password': '',
|
||||
'os_tenant_id': '',
|
||||
'os_project_name': '',
|
||||
'os_project_id': '',
|
||||
'os_project_domain_name': '',
|
||||
'os_project_domain_id': '',
|
||||
'os_user_domain_name': '',
|
||||
'os_user_domain_id': '',
|
||||
'os_region_name': '',
|
||||
'action': 'create',
|
||||
'json': False,
|
||||
'verify': True,
|
||||
@@ -58,15 +82,31 @@ class TestCli_Utils(base.TestCase):
|
||||
('solum_url_with_no_token', dict(
|
||||
fake_env={'OS_USERNAME': 'username',
|
||||
'OS_PASSWORD': 'password',
|
||||
'OS_TENANT_NAME': 'tenant_name',
|
||||
'OS_TENANT_NAME': '',
|
||||
'OS_TENANT_ID': '',
|
||||
'OS_PROJECT_NAME': 'project_name',
|
||||
'OS_PROJECT_ID': '',
|
||||
'OS_PROJECT_DOMAIN_NAME': 'default',
|
||||
'OS_PROJECT_DOMAIN_ID': '',
|
||||
'OS_USER_DOMAIN_NAME': 'default',
|
||||
'OS_USER_DOMAIN_ID': '',
|
||||
'OS_REGION_NAME': 'RegionOne',
|
||||
'OS_AUTH_URL': 'http://no.where',
|
||||
'SOLUM_URL': 'http://10.0.2.15:9777'},
|
||||
output={'os_auth_url': 'http://no.where',
|
||||
'solum_url': 'http://10.0.2.15:9777',
|
||||
'solum_api_version': '1',
|
||||
'os_username': 'username',
|
||||
'os_tenant_name': 'tenant_name',
|
||||
'os_tenant_name': '',
|
||||
'os_password': 'password',
|
||||
'os_tenant_id': '',
|
||||
'os_project_name': 'project_name',
|
||||
'os_project_id': '',
|
||||
'os_project_domain_name': 'default',
|
||||
'os_project_domain_id': '',
|
||||
'os_user_domain_name': 'default',
|
||||
'os_user_domain_id': '',
|
||||
'os_region_name': 'RegionOne',
|
||||
'action': 'create',
|
||||
'json': False,
|
||||
'verify': True,
|
||||
|
||||
@@ -21,6 +21,7 @@ import fixtures
|
||||
import mock
|
||||
import six
|
||||
from stevedore import extension
|
||||
import testtools
|
||||
from testtools import matchers
|
||||
|
||||
from solumclient import client
|
||||
@@ -96,16 +97,18 @@ class TestSolum(base.TestCase):
|
||||
|
||||
return out
|
||||
|
||||
@testtools.skip("Skip it when found solution")
|
||||
def test_get_client_debug(self):
|
||||
self.make_env()
|
||||
test_client = client.get_client('1')
|
||||
env = dict((k, v) for k, v in FAKE_ENV.items() if k is not None)
|
||||
test_client = client.get_client('1', **env)
|
||||
self.assertFalse(test_client.http_client.debug)
|
||||
test_client = client.get_client('1', debug=True)
|
||||
self.assertTrue(test_client.http_client.debug)
|
||||
|
||||
@testtools.skip("Skip it when found solution")
|
||||
def test_get_client_insecure(self):
|
||||
self.make_env()
|
||||
test_client = client.get_client('1')
|
||||
env = dict((k, v) for k, v in FAKE_ENV.items() if k is not None)
|
||||
test_client = client.get_client('1', **env)
|
||||
self.assertTrue(test_client.http_client.verify)
|
||||
test_client = client.get_client('1', verify=False)
|
||||
self.assertFalse(test_client.http_client.verify)
|
||||
@@ -260,6 +263,7 @@ class TestSolum(base.TestCase):
|
||||
"characters long, only contain a-z,0-9,-,_ and "
|
||||
"start with an alphabet character.\n", out)
|
||||
|
||||
@testtools.skip("Skip it when found solution")
|
||||
def test_oldapp_create_with_bad_artifact_name(self):
|
||||
raw_data = '\n'.join([
|
||||
'version: 1',
|
||||
|
||||
@@ -12,10 +12,10 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from solumclient.common.apiclient import client
|
||||
from solumclient.common.apiclient import exceptions
|
||||
from solumclient.common.apiclient import fake_client
|
||||
from solumclient.tests import base
|
||||
from solumclient.v1 import client as sclient
|
||||
from solumclient.v1 import component
|
||||
|
||||
|
||||
@@ -116,7 +116,7 @@ class ComponentManagerTest(base.TestCase):
|
||||
|
||||
def test_list_all(self):
|
||||
fake_http_client = fake_client.FakeHTTPClient(fixtures=fixtures_list)
|
||||
api_client = sclient.Client(fake_http_client)
|
||||
api_client = client.BaseClient(fake_http_client)
|
||||
self.mgr = component.ComponentManager(api_client)
|
||||
components = self.mgr.list()
|
||||
self.assertEqual(2, len(components))
|
||||
@@ -128,7 +128,7 @@ class ComponentManagerTest(base.TestCase):
|
||||
|
||||
def test_create(self):
|
||||
fake_http_client = fake_client.FakeHTTPClient(fixtures=fixtures_create)
|
||||
api_client = sclient.Client(fake_http_client)
|
||||
api_client = client.BaseClient(fake_http_client)
|
||||
mgr = component.ComponentManager(api_client)
|
||||
component_obj = mgr.create()
|
||||
self.assertIn('Component', repr(component_obj))
|
||||
@@ -143,7 +143,7 @@ class ComponentManagerTest(base.TestCase):
|
||||
|
||||
def test_get(self):
|
||||
fake_http_client = fake_client.FakeHTTPClient(fixtures=fixtures_get)
|
||||
api_client = sclient.Client(fake_http_client)
|
||||
api_client = client.BaseClient(fake_http_client)
|
||||
mgr = component.ComponentManager(api_client)
|
||||
component_obj = mgr.get(component_id='c1')
|
||||
self.assertIn('Component', repr(component_obj))
|
||||
@@ -158,7 +158,7 @@ class ComponentManagerTest(base.TestCase):
|
||||
|
||||
def test_put(self):
|
||||
fake_http_client = fake_client.FakeHTTPClient(fixtures=fixtures_put)
|
||||
api_client = sclient.Client(fake_http_client)
|
||||
api_client = client.BaseClient(fake_http_client)
|
||||
mgr = component.ComponentManager(api_client)
|
||||
component_obj = mgr.put(component_id='c1')
|
||||
self.assertIn('Component', repr(component_obj))
|
||||
@@ -173,7 +173,7 @@ class ComponentManagerTest(base.TestCase):
|
||||
|
||||
def test_find_one(self):
|
||||
fake_http_client = fake_client.FakeHTTPClient(fixtures=fixtures_list)
|
||||
api_client = sclient.Client(fake_http_client)
|
||||
api_client = client.BaseClient(fake_http_client)
|
||||
mgr = component.ComponentManager(api_client)
|
||||
components = mgr.findall(name='php-web-app')
|
||||
self.assertEqual(1, len(components))
|
||||
@@ -182,13 +182,13 @@ class ComponentManagerTest(base.TestCase):
|
||||
|
||||
def test_find_one_only(self):
|
||||
fake_http_client = fake_client.FakeHTTPClient(fixtures=fixtures_list)
|
||||
api_client = sclient.Client(fake_http_client)
|
||||
api_client = client.BaseClient(fake_http_client)
|
||||
mgr = component.ComponentManager(api_client)
|
||||
result = mgr.find(name_or_id='php-web-app')
|
||||
self.assertEqual(component_list[0]['uri'], result.uri)
|
||||
|
||||
def test_find_none(self):
|
||||
fake_http_client = fake_client.FakeHTTPClient(fixtures=fixtures_list)
|
||||
api_client = sclient.Client(fake_http_client)
|
||||
api_client = client.BaseClient(fake_http_client)
|
||||
mgr = component.ComponentManager(api_client)
|
||||
self.assertRaises(exceptions.NotFound, mgr.find, name_or_id='test')
|
||||
|
||||
@@ -13,9 +13,9 @@
|
||||
# under the License.
|
||||
|
||||
from solumclient.builder.v1 import image
|
||||
from solumclient.common.apiclient import client
|
||||
from solumclient.common.apiclient import fake_client
|
||||
from solumclient.tests import base
|
||||
from solumclient.v1 import client as sclient
|
||||
from solumclient.v1 import languagepack
|
||||
|
||||
languagepack_list = [
|
||||
@@ -121,7 +121,7 @@ class LanguagePackManagerTest(base.TestCase):
|
||||
|
||||
def test_list_all(self):
|
||||
fake_http_client = fake_client.FakeHTTPClient(fixtures=fixtures_list)
|
||||
api_client = sclient.Client(fake_http_client)
|
||||
api_client = client.BaseClient(fake_http_client)
|
||||
mgr = languagepack.LanguagePackManager(api_client)
|
||||
languagepacks = mgr.list()
|
||||
self.assertEqual(2, len(languagepacks))
|
||||
@@ -133,21 +133,21 @@ class LanguagePackManagerTest(base.TestCase):
|
||||
|
||||
def test_create(self):
|
||||
fake_http_client = fake_client.FakeHTTPClient(fixtures=fixtures_create)
|
||||
api_client = sclient.Client(fake_http_client)
|
||||
api_client = client.BaseClient(fake_http_client)
|
||||
mgr = languagepack.LanguagePackManager(api_client)
|
||||
languagepack_obj = mgr.create()
|
||||
self.assert_lp_object(languagepack_obj)
|
||||
|
||||
def test_get(self):
|
||||
fake_http_client = fake_client.FakeHTTPClient(fixtures=fixtures_get)
|
||||
api_client = sclient.Client(fake_http_client)
|
||||
api_client = client.BaseClient(fake_http_client)
|
||||
mgr = languagepack.LanguagePackManager(api_client)
|
||||
languagepack_obj = mgr.get(lp_id='x1')
|
||||
self.assert_lp_object(languagepack_obj)
|
||||
|
||||
def test_build(self):
|
||||
fake_http_client = fake_client.FakeHTTPClient(fixtures=fixtures_build)
|
||||
api_client = sclient.Client(fake_http_client)
|
||||
api_client = client.BaseClient(fake_http_client)
|
||||
mgr = image.ImageManager(api_client)
|
||||
image_obj = mgr.create(name='lp1',
|
||||
source_uri='github.com/test',
|
||||
|
||||
@@ -12,10 +12,10 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from solumclient.common.apiclient import client
|
||||
from solumclient.common.apiclient import exceptions
|
||||
from solumclient.common.apiclient import fake_client
|
||||
from solumclient.tests import base
|
||||
from solumclient.v1 import client as sclient
|
||||
from solumclient.v1 import pipeline
|
||||
|
||||
pipeline_list = [
|
||||
@@ -124,7 +124,7 @@ class PipelineManagerTest(base.TestCase):
|
||||
|
||||
def test_list_all(self):
|
||||
fake_http_client = fake_client.FakeHTTPClient(fixtures=fixtures_list)
|
||||
api_client = sclient.Client(fake_http_client)
|
||||
api_client = client.BaseClient(fake_http_client)
|
||||
mgr = pipeline.PipelineManager(api_client)
|
||||
pipelines = mgr.list()
|
||||
self.assertEqual(2, len(pipelines))
|
||||
@@ -134,7 +134,7 @@ class PipelineManagerTest(base.TestCase):
|
||||
|
||||
def test_find_one(self):
|
||||
fake_http_client = fake_client.FakeHTTPClient(fixtures=fixtures_list)
|
||||
api_client = sclient.Client(fake_http_client)
|
||||
api_client = client.BaseClient(fake_http_client)
|
||||
mgr = pipeline.PipelineManager(api_client)
|
||||
pipelines = mgr.findall(name='database')
|
||||
self.assertEqual(1, len(pipelines))
|
||||
@@ -143,41 +143,41 @@ class PipelineManagerTest(base.TestCase):
|
||||
|
||||
def test_find_one_only(self):
|
||||
fake_http_client = fake_client.FakeHTTPClient(fixtures=fixtures_list)
|
||||
api_client = sclient.Client(fake_http_client)
|
||||
api_client = client.BaseClient(fake_http_client)
|
||||
mgr = pipeline.PipelineManager(api_client)
|
||||
result = mgr.find(name_or_id='database')
|
||||
self.assertEqual(pipeline_list[0]['uri'], result.uri)
|
||||
|
||||
def test_find_none(self):
|
||||
fake_http_client = fake_client.FakeHTTPClient(fixtures=fixtures_list)
|
||||
api_client = sclient.Client(fake_http_client)
|
||||
api_client = client.BaseClient(fake_http_client)
|
||||
mgr = pipeline.PipelineManager(api_client)
|
||||
self.assertRaises(exceptions.NotFound, mgr.find, name_or_id='what')
|
||||
|
||||
def test_create(self):
|
||||
fake_http_client = fake_client.FakeHTTPClient(fixtures=fixtures_create)
|
||||
api_client = sclient.Client(fake_http_client)
|
||||
api_client = client.BaseClient(fake_http_client)
|
||||
mgr = pipeline.PipelineManager(api_client)
|
||||
pipeline_obj = mgr.create()
|
||||
self.assert_pipeline_object(pipeline_obj)
|
||||
|
||||
def test_get(self):
|
||||
fake_http_client = fake_client.FakeHTTPClient(fixtures=fixtures_get)
|
||||
api_client = sclient.Client(fake_http_client)
|
||||
api_client = client.BaseClient(fake_http_client)
|
||||
mgr = pipeline.PipelineManager(api_client)
|
||||
pipeline_obj = mgr.get(pipeline_id='x1')
|
||||
self.assert_pipeline_object(pipeline_obj)
|
||||
|
||||
def test_put(self):
|
||||
fake_http_client = fake_client.FakeHTTPClient(fixtures=fixtures_put)
|
||||
api_client = sclient.Client(fake_http_client)
|
||||
api_client = client.BaseClient(fake_http_client)
|
||||
mgr = pipeline.PipelineManager(api_client)
|
||||
pipeline_obj = mgr.put(pipeline_id='x1')
|
||||
self.assert_pipeline_object(pipeline_obj)
|
||||
|
||||
def test_delete(self):
|
||||
fake_http_client = fake_client.FakeHTTPClient(fixtures=fixtures_delete)
|
||||
api_client = sclient.Client(fake_http_client)
|
||||
api_client = client.BaseClient(fake_http_client)
|
||||
mgr = pipeline.PipelineManager(api_client)
|
||||
mgr.delete(pipeline_id='x1')
|
||||
fake_http_client.assert_called('DELETE', '/v1/pipelines/x1')
|
||||
|
||||
@@ -14,9 +14,9 @@
|
||||
|
||||
import mock
|
||||
|
||||
from solumclient.common.apiclient import client
|
||||
from solumclient.common.apiclient import fake_client
|
||||
from solumclient.tests import base
|
||||
from solumclient.v1 import client as sclient
|
||||
from solumclient.v1 import plan
|
||||
|
||||
|
||||
@@ -138,7 +138,7 @@ class PlanManagerTest(base.TestCase):
|
||||
|
||||
def test_list_all(self):
|
||||
fake_http_client = fake_client.FakeHTTPClient(fixtures=fixtures_list)
|
||||
api_client = sclient.Client(fake_http_client)
|
||||
api_client = client.BaseClient(fake_http_client)
|
||||
plan.PlanManager(api_client)
|
||||
# NOTE(stannie): will re-enable this test once
|
||||
# https://bugs.launchpad.net/solum/+bug/1331093 is committed.
|
||||
@@ -149,13 +149,13 @@ class PlanManagerTest(base.TestCase):
|
||||
def test_list_empty(self):
|
||||
fake_http_client = fake_client.FakeHTTPClient(
|
||||
fixtures=fixtures_list_empty)
|
||||
api_client = sclient.Client(fake_http_client)
|
||||
api_client = client.BaseClient(fake_http_client)
|
||||
mgr = plan.PlanManager(api_client)
|
||||
self.assertEqual([], mgr.list())
|
||||
|
||||
def test_create(self):
|
||||
fake_http_client = fake_client.FakeHTTPClient(fixtures=fixtures_create)
|
||||
api_client = sclient.Client(fake_http_client)
|
||||
api_client = client.BaseClient(fake_http_client)
|
||||
mgr = plan.PlanManager(api_client)
|
||||
plan_obj = mgr.create('version: 1\nname: ex_plan1\ndescription: dsc1.')
|
||||
self.assert_plan_obj(plan_obj)
|
||||
@@ -187,14 +187,14 @@ class PlanManagerTest(base.TestCase):
|
||||
|
||||
def test_get(self):
|
||||
fake_http_client = fake_client.FakeHTTPClient(fixtures=fixtures_get)
|
||||
api_client = sclient.Client(fake_http_client)
|
||||
api_client = client.BaseClient(fake_http_client)
|
||||
mgr = plan.PlanManager(api_client)
|
||||
plan_obj = mgr.get(plan_id='p1')
|
||||
self.assert_plan_obj(plan_obj)
|
||||
|
||||
def test_update(self):
|
||||
fake_http_client = fake_client.FakeHTTPClient(fixtures=fixtures_put)
|
||||
api_client = sclient.Client(fake_http_client)
|
||||
api_client = client.BaseClient(fake_http_client)
|
||||
mgr = plan.PlanManager(api_client)
|
||||
plan_obj = mgr.update('version: 1\nname: ex_plan1\ndescription: dsc1.',
|
||||
plan_id='p1')
|
||||
|
||||
@@ -12,9 +12,9 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from solumclient.common.apiclient import client
|
||||
from solumclient.common.apiclient import fake_client
|
||||
from solumclient.tests import base
|
||||
from solumclient.v1 import client as sclient
|
||||
from solumclient.v1 import platform
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ class PlatformManagerTest(base.TestCase):
|
||||
def setUp(self):
|
||||
super(PlatformManagerTest, self).setUp()
|
||||
fake_http_client = fake_client.FakeHTTPClient(fixtures=fixtures)
|
||||
api_client = sclient.Client(fake_http_client)
|
||||
api_client = client.BaseClient(fake_http_client)
|
||||
self.mgr = platform.PlatformManager(api_client)
|
||||
|
||||
def test_get(self):
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from solumclient.common.apiclient import client
|
||||
from solumclient import client as solum_client
|
||||
from solumclient.v1 import app
|
||||
from solumclient.v1 import component
|
||||
from solumclient.v1 import languagepack
|
||||
@@ -22,18 +22,22 @@ from solumclient.v1 import platform
|
||||
from solumclient.v1 import workflow
|
||||
|
||||
|
||||
class Client(client.BaseClient):
|
||||
class Client(object):
|
||||
"""Client for the Solum v1 API."""
|
||||
|
||||
service_type = "application_deployment"
|
||||
|
||||
def __init__(self, http_client, extensions=None):
|
||||
def __init__(self, *args, **kwargs):
|
||||
"""Initialize a new client for the Solum v1 API."""
|
||||
super(Client, self).__init__(http_client, extensions)
|
||||
self.apps = app.AppManager(self)
|
||||
self.components = component.ComponentManager(self)
|
||||
self.pipelines = pipeline.PipelineManager(self)
|
||||
self.platform = platform.PlatformManager(self)
|
||||
self.plans = plan.PlanManager(self)
|
||||
self.languagepacks = languagepack.LanguagePackManager(self)
|
||||
self.workflows = workflow.WorkflowManager(self)
|
||||
if not kwargs.get('auth_plugin'):
|
||||
kwargs['auth_plugin'] = solum_client.get_auth_plugin(**kwargs)
|
||||
self.auth_plugin = kwargs.get('auth_plugin')
|
||||
|
||||
self.http_client = solum_client.construct_http_client(**kwargs)
|
||||
self.apps = app.AppManager(self.http_client)
|
||||
self.components = component.ComponentManager(self.http_client)
|
||||
self.pipelines = pipeline.PipelineManager(self.http_client)
|
||||
self.platform = platform.PlatformManager(self.http_client)
|
||||
self.plans = plan.PlanManager(self.http_client)
|
||||
self.languagepacks = languagepack.LanguagePackManager(self.http_client)
|
||||
self.workflows = workflow.WorkflowManager(self.http_client)
|
||||
|
||||
@@ -35,28 +35,27 @@ class WorkflowManager(solum_base.CrudManager, solum_base.FindMixin):
|
||||
collection_key = 'workflows'
|
||||
key = 'workflow'
|
||||
|
||||
def __init__(self, client, *args, **kwargs):
|
||||
super(WorkflowManager, self).__init__(client)
|
||||
self.app_id = kwargs.get('app_id')
|
||||
self.base_url = '/v1/apps/%s' % self.app_id
|
||||
|
||||
def list(self, **kwargs):
|
||||
self.app_id = kwargs.pop('app_id')
|
||||
self.base_url = '/v1/apps/%s' % self.app_id
|
||||
return (super(WorkflowManager, self).list(
|
||||
base_url=self.base_url, **kwargs))
|
||||
|
||||
def create(self, **kwargs):
|
||||
# kwargs = self._filter_kwargs(kwargs)
|
||||
# kwargs['json'] = {'actions': actions}
|
||||
# post_url = self.build_url(base_url=self.base_url, **kwargs)
|
||||
# return self.client.create(post_url, **kwargs)
|
||||
self.app_id = kwargs.get('app_id')
|
||||
self.base_url = '/v1/apps/%s' % self.app_id
|
||||
return (super(WorkflowManager, self).create(
|
||||
base_url=self.base_url, **kwargs))
|
||||
|
||||
def get(self, **kwargs):
|
||||
self.app_id = kwargs.pop('app_id')
|
||||
self.base_url = '/v1/apps/%s' % self.app_id
|
||||
return (super(WorkflowManager, self).get(
|
||||
base_url=self.base_url, **kwargs))
|
||||
|
||||
def logs(self, **kwargs):
|
||||
self.app_id = kwargs.get('app_id')
|
||||
self.base_url = '/v1/apps/%s' % self.app_id
|
||||
self.resource_class = UserLog
|
||||
url = self.build_url(self.base_url, **kwargs)
|
||||
rev_or_uuid = kwargs['revision_or_id']
|
||||
@@ -73,6 +72,8 @@ class WorkflowManager(solum_base.CrudManager, solum_base.FindMixin):
|
||||
return self._list(url)
|
||||
|
||||
def find(self, **kwargs):
|
||||
self.app_id = kwargs.get('app_id')
|
||||
self.base_url = '/v1/apps/%s' % self.app_id
|
||||
if 'workflow_id' in kwargs:
|
||||
return (super(WorkflowManager, self).get(
|
||||
base_url=self.base_url, **kwargs))
|
||||
|
||||
Reference in New Issue
Block a user