tests working

This commit is contained in:
Sandy Walsh 2011-11-09 07:10:46 -08:00
parent c386221bd8
commit cdde0d22cd
12 changed files with 50 additions and 46 deletions

View File

@ -40,7 +40,7 @@ with the ``--username``, ``--apikey`` and ``--projectid`` params, but it's easi
set them as environment variables::
export NOVA_USERNAME=openstack
export NOVA_API_KEY=yadayada
export NOVA_PASSWORD=yadayada
export NOVA_PROJECT_ID=myproject
You will also need to define the authentication url with ``--url`` and the
@ -64,6 +64,7 @@ You'll find complete documentation on the shell by running
usage: nova [--username USERNAME] [--apikey APIKEY] [--projectid PROJECTID]
[--url URL] [--version VERSION] [--region_name NAME]
[--endpoint_name NAME]
<subcommand> ...
Command-line interface to the OpenStack Nova API.
@ -141,7 +142,7 @@ You'll find complete documentation on the shell by running
Optional arguments:
--username USERNAME Defaults to env[NOVA_USERNAME].
--apikey APIKEY Defaults to env[NOVA_API_KEY].
--apikey PASSWORD Defaults to env[NOVA_PASSWORD].
--apikey PROJECTID Defaults to env[NOVA_PROJECT_ID].
--url AUTH_URL Defaults to env[NOVA_URL] or
https://auth.api.rackspacecloud.com/v1.0
@ -164,7 +165,7 @@ __ http://packages.python.org/python-novaclient/
By way of a quick-start::
>>> import novaclient
>>> nt = novaclient.OpenStack(USERNAME, API_KEY,PROJECT_ID [, AUTH_URL])
>>> nt = novaclient.OpenStack(USERNAME, PASSWORD, PROJECT_ID [, AUTH_URL])
>>> nt.flavors.list()
[...]
>>> nt.servers.list()

View File

@ -12,7 +12,7 @@ Usage
First create an instance of :class:`OpenStack` with your credentials::
>>> from novaclient import OpenStack
>>> nova = OpenStack(USERNAME, API_KEY, AUTH_URL)
>>> nova = OpenStack(USERNAME, PASSWORD, AUTH_URL)
Then call methods on the :class:`OpenStack` object:

View File

@ -11,7 +11,7 @@ First, you'll need an OpenStack Nova account and an API key. You get this
by using the `nova-manage` command in OpenStack Nova.
You'll need to provide :program:`nova` with your OpenStack username and
API key. You can do this with the :option:`--username`, :option:`--apikey`
API key. You can do this with the :option:`--username`, :option:`--password`
and :option:`--projectid` options, but it's easier to just set them as
environment variables by setting two environment variables:
@ -19,9 +19,9 @@ environment variables by setting two environment variables:
Your OpenStack Nova username.
.. envvar:: NOVA_API_KEY
.. envvar:: NOVA_PASSWORD
Your API key.
Your password.
.. envvar:: NOVA_PROJECT_ID
@ -38,7 +38,7 @@ environment variables by setting two environment variables:
For example, in Bash you'd use::
export NOVA_USERNAME=yourname
export NOVA_API_KEY=yadayadayada
export NOVA_PASSWORD=yadayadayada
export NOVA_PROJECT_ID=myproject
export NOVA_URL=http://...
export NOVA_VERSION=1.0

View File

@ -37,11 +37,11 @@ class HTTPClient(httplib2.Http):
USER_AGENT = 'python-novaclient'
def __init__(self, user, apikey, projectid, auth_url, insecure=False,
def __init__(self, user, password, projectid, auth_url, insecure=False,
timeout=None, token=None, region_name=None):
super(HTTPClient, self).__init__(timeout=timeout)
self.user = user
self.apikey = apikey
self.password = password
self.projectid = projectid
self.auth_url = auth_url
self.version = 'v1.0'
@ -239,7 +239,7 @@ class HTTPClient(httplib2.Http):
raise NoTokenLookupException()
headers = {'X-Auth-User': self.user,
'X-Auth-Key': self.apikey}
'X-Auth-Key': self.password}
if self.projectid:
headers['X-Auth-Project-Id'] = self.projectid
@ -260,7 +260,7 @@ class HTTPClient(httplib2.Http):
"""Authenticate against a v2.0 auth service."""
body = {"auth": {
"passwordCredentials": {"username": self.user,
"password": self.apikey}}}
"password": self.password}}}
if self.projectid:
body['auth']['tenantName'] = self.projectid

View File

@ -674,7 +674,8 @@ def do_delete(cs, args):
@utils.arg('--api_url', dest='api_url', default=None, help='New URL.')
@utils.arg('--zone_username', dest='zone_username', default=None,
help='New zone username.')
@utils.arg('--password', dest='password', default=None, help='New password.')
@utils.arg('--zone_password', dest='zone_password', default=None,
help='New password.')
@utils.arg('--weight_offset', dest='weight_offset', default=None,
help='Child Zone weight offset.')
@utils.arg('--weight_scale', dest='weight_scale', default=None,
@ -689,8 +690,8 @@ def do_zone(cs, args):
zone_delta['api_url'] = args.api_url
if args.zone_username:
zone_delta['username'] = args.zone_username
if args.password:
zone_delta['password'] = args.password
if args.zone_password:
zone_delta['password'] = args.zone_password
if args.weight_offset:
zone_delta['weight_offset'] = args.weight_offset
if args.weight_scale:
@ -713,7 +714,7 @@ def do_zone_info(cs, args):
@utils.arg('--zone_username', metavar='<zone_username>',
help='Optional Authentication username. (Default=None)',
default=None)
@utils.arg('--password', metavar='<password>',
@utils.arg('--zone_password', metavar='<zone_password>',
help='Authentication password. (Default=None)',
default=None)
@utils.arg('--weight_offset', metavar='<weight_offset>',
@ -725,7 +726,7 @@ def do_zone_info(cs, args):
def do_zone_add(cs, args):
"""Add a new child zone."""
zone = cs.zones.create(args.zone_name, args.api_url,
args.zone_username, args.password,
args.zone_username, args.zone_password,
args.weight_offset, args.weight_scale)
utils.print_dict(zone._info)

View File

@ -455,15 +455,16 @@ def do_reboot(cs, args):
@utils.arg('server', metavar='<server>', help='Name or ID of server.')
@utils.arg('image', metavar='<image>', help="Name or ID of new image.")
@utils.arg('--password', dest='password', metavar='<password>', default=False,
@utils.arg('--rebuild_password', dest='rebuild_password',
metavar='<rebuild_password>', default=False,
help="Set the provided password on the rebuild instance.")
def do_rebuild(cs, args):
"""Shutdown, re-image, and re-boot a server."""
server = _find_server(cs, args.server)
image = _find_image(cs, args.image)
if args.password != False:
_password = args.password
if args.rebuild_password != False:
_password = args.rebuild_password
else:
_password = None
@ -675,7 +676,8 @@ def _find_flavor(cs, flavor):
@utils.arg('--api_url', dest='api_url', default=None, help='New URL.')
@utils.arg('--zone_username', dest='zone_username', default=None,
help='New zone username.')
@utils.arg('--password', dest='password', default=None, help='New password.')
@utils.arg('--zone_password', dest='zone_password', default=None,
help='New password.')
@utils.arg('--weight_offset', dest='weight_offset', default=None,
help='Child Zone weight offset.')
@utils.arg('--weight_scale', dest='weight_scale', default=None,
@ -690,8 +692,8 @@ def do_zone(cs, args):
zone_delta['api_url'] = args.api_url
if args.zone_username:
zone_delta['username'] = args.zone_username
if args.password:
zone_delta['password'] = args.password
if args.zone_password:
zone_delta['password'] = args.zone_password
if args.weight_offset:
zone_delta['weight_offset'] = args.weight_offset
if args.weight_scale:
@ -714,7 +716,7 @@ def do_zone_info(cs, args):
@utils.arg('--zone_username', metavar='<zone_username>',
help='Optional Authentication username. (Default=None)',
default=None)
@utils.arg('--password', metavar='<password>',
@utils.arg('--zone_password', metavar='<zone_password>',
help='Authentication password. (Default=None)',
default=None)
@utils.arg('--weight_offset', metavar='<weight_offset>',
@ -726,7 +728,7 @@ def do_zone_info(cs, args):
def do_zone_add(cs, args):
"""Add a new child zone."""
zone = cs.zones.create(args.zone_name, args.api_url,
args.zone_username, args.password,
args.zone_username, args.zone_password,
args.weight_offset, args.weight_scale)
utils.print_dict(zone._info)

View File

@ -14,7 +14,7 @@ class ShellTest(utils.TestCase):
global _old_env
fake_env = {
'NOVA_USERNAME': 'username',
'NOVA_API_KEY': 'password',
'NOVA_PASSWORD': 'password',
'NOVA_PROJECT_ID': 'project_id',
'NOVA_URL': 'http://no.where',
}

View File

@ -18,7 +18,7 @@ class FakeClient(fakes.FakeClient, client.Client):
class FakeHTTPClient(base_client.HTTPClient):
def __init__(self, **kwargs):
self.username = 'username'
self.apikey = 'apikey'
self.password = 'password'
self.auth_url = 'auth_url'
self.callstack = []

View File

@ -14,7 +14,7 @@ class ShellTest(utils.TestCase):
self.old_environment = os.environ.copy()
os.environ = {
'NOVA_USERNAME': 'username',
'NOVA_API_KEY': 'password',
'NOVA_PASSWORD': 'password',
'NOVA_PROJECT_ID': 'project_id',
'NOVA_VERSION': '1.0',
}
@ -304,7 +304,7 @@ class ShellTest(utils.TestCase):
self.assert_called('GET', '/zones/1')
self.run_command('zone 1 --api_url=http://zzz '
'--zone_username=frank --password=xxx')
'--zone_username=frank --zone_password=xxx')
self.assert_called(
'PUT', '/zones/1',
{'zone': {'username': 'frank', 'password': 'xxx',
@ -313,7 +313,7 @@ class ShellTest(utils.TestCase):
def test_zone_add(self):
self.run_command('zone-add child_zone http://zzz '
'--zone_username=frank --password=xxx '
'--zone_username=frank --zone_password=xxx '
'--weight_offset=0.0 --weight_scale=1.0')
self.assert_called(
'POST', '/zones',

View File

@ -8,7 +8,7 @@ from tests import fakes
class FakeClient(fakes.FakeClient, client.Client):
def __init__(self, *args, **kwargs):
client.Client.__init__(self, 'username', 'apikey',
client.Client.__init__(self, 'username', 'password',
'project_id', 'auth_url')
self.client = FakeHTTPClient(**kwargs)
@ -17,7 +17,7 @@ class FakeHTTPClient(base_client.HTTPClient):
def __init__(self, **kwargs):
self.username = 'username'
self.apikey = 'apikey'
self.password = 'password'
self.auth_url = 'auth_url'
self.callstack = []

View File

@ -19,7 +19,7 @@ def to_http_response(resp_dict):
class AuthenticateAgainstKeystoneTests(utils.TestCase):
def test_authenticate_success(self):
cs = client.Client("username", "apikey", "project_id", "auth_url/v2.0")
cs = client.Client("username", "password", "project_id", "auth_url/v2.0")
resp = {"access":
{"token": {"expires": "12345", "id": "FAKE_ID"},
"serviceCatalog": [
@ -44,7 +44,7 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
'Content-Type': 'application/json', }
body = {'auth': {
'passwordCredentials': {'username': cs.client.user,
'password': cs.client.apikey},
'password': cs.client.password},
'tenantName': cs.client.projectid, }}
token_url = urlparse.urljoin(cs.client.auth_url, "tokens")
@ -60,7 +60,7 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
test_auth_call()
def test_authenticate_failure(self):
cs = client.Client("username", "apikey", "project_id", "auth_url/v2.0")
cs = client.Client("username", "password", "project_id", "auth_url/v2.0")
resp = {"unauthorized": {"message": "Unauthorized", "code": "401"}}
auth_response = httplib2.Response({
"status": 401,
@ -77,7 +77,7 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
test_auth_call()
def test_auth_redirect(self):
cs = client.Client("username", "apikey", "project_id", "auth_url/v1.0")
cs = client.Client("username", "password", "project_id", "auth_url/v1.0")
dict_correct_response = {"access": {"token": {"expires": "12345", "id": "FAKE_ID"},
"serviceCatalog": [{
"type": "compute",
@ -116,7 +116,7 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
'Content-Type': 'application/json',}
body = {'auth': {
'passwordCredentials': {'username': cs.client.user,
'password': cs.client.apikey},
'password': cs.client.password},
'tenantName': cs.client.projectid,}}
token_url = urlparse.urljoin(cs.client.auth_url, "tokens")
@ -135,7 +135,7 @@ class AuthenticateAgainstKeystoneTests(utils.TestCase):
class AuthenticationTests(utils.TestCase):
def test_authenticate_success(self):
cs = client.Client("username", "apikey", "project_id", "auth_url")
cs = client.Client("username", "password", "project_id", "auth_url")
management_url = 'https://servers.api.rackspacecloud.com/v1.1/443470'
auth_response = httplib2.Response({
'status': 204,
@ -149,7 +149,7 @@ class AuthenticationTests(utils.TestCase):
cs.client.authenticate()
headers = {
'X-Auth-User': 'username',
'X-Auth-Key': 'apikey',
'X-Auth-Key': 'password',
'X-Auth-Project-Id': 'project_id',
'User-Agent': cs.client.USER_AGENT
}
@ -163,7 +163,7 @@ class AuthenticationTests(utils.TestCase):
test_auth_call()
def test_authenticate_failure(self):
cs = client.Client("username", "apikey", "project_id", "auth_url")
cs = client.Client("username", "password", "project_id", "auth_url")
auth_response = httplib2.Response({'status': 401})
mock_request = mock.Mock(return_value=(auth_response, None))
@ -174,7 +174,7 @@ class AuthenticationTests(utils.TestCase):
test_auth_call()
def test_auth_automatic(self):
cs = client.Client("username", "apikey", "project_id", "auth_url")
cs = client.Client("username", "password", "project_id", "auth_url")
http_client = cs.client
http_client.management_url = ''
mock_request = mock.Mock(return_value=(None, None))
@ -189,7 +189,7 @@ class AuthenticationTests(utils.TestCase):
test_auth_call()
def test_auth_manual(self):
cs = client.Client("username", "apikey", "project_id", "auth_url")
cs = client.Client("username", "password", "project_id", "auth_url")
@mock.patch.object(cs.client, 'authenticate')
def test_auth_call(m):

View File

@ -17,7 +17,7 @@ class ShellTest(utils.TestCase):
self.old_environment = os.environ.copy()
os.environ = {
'NOVA_USERNAME': 'username',
'NOVA_API_KEY': 'password',
'NOVA_PASSWORD': 'password',
'NOVA_PROJECT_ID': 'project_id',
'NOVA_VERSION': '1.1',
'NOVA_URL': 'http://no.where',
@ -228,7 +228,7 @@ class ShellTest(utils.TestCase):
# {'rebuild': {'imageRef': 1}})
self.assert_called('GET', '/images/2')
self.run_command('rebuild sample-server 1 --password asdf')
self.run_command('rebuild sample-server 1 --rebuild_password asdf')
# XXX need a way to test multiple calls
#self.assert_called('POST', '/servers/1234/action',
# {'rebuild': {'imageRef': 1, 'adminPass': 'asdf'}})