tests working again for weight_scale/weight_offset

This commit is contained in:
Sandy Walsh
2011-06-21 04:54:01 -07:00
parent 46855896a8
commit 2069b17f8b
5 changed files with 49 additions and 10 deletions

@ -90,6 +90,12 @@ You'll find complete documentation on the shell by running
root-password Change the root password for a server. root-password Change the root password for a server.
show Show details about the given server. show Show details about the given server.
unrescue Unrescue a server. unrescue Unrescue a server.
zone Show or edit a Child Zone
zone-add Add a Child Zone.
zone-boot Boot a server, considering Zones.
zone-delete Remove a Child Zone.
zone-info Show the capabilities for this Zone.
zone-list List all the immediate Child Zones.
Optional arguments: Optional arguments:
--username USERNAME Defaults to env[NOVA_USERNAME]. --username USERNAME Defaults to env[NOVA_USERNAME].

@ -680,6 +680,10 @@ class OpenStackShell(object):
@arg('--zone_username', dest='zone_username', default=None, @arg('--zone_username', dest='zone_username', default=None,
help='New zone username.') help='New zone username.')
@arg('--password', dest='password', default=None, help='New password.') @arg('--password', dest='password', default=None, help='New password.')
@arg('--weight_offset', dest='weight_offset', default=None,
help='Child Zone weight offset.')
@arg('--weight_scale', dest='weight_scale', default=None,
help='Child Zone weight scale.')
def do_zone(self, args): def do_zone(self, args):
"""Show or edit a child zone. No zone arg for this zone.""" """Show or edit a child zone. No zone arg for this zone."""
zone = self.cs.zones.get(args.zone) zone = self.cs.zones.get(args.zone)
@ -692,6 +696,10 @@ class OpenStackShell(object):
zone_delta['username'] = args.zone_username zone_delta['username'] = args.zone_username
if args.password: if args.password:
zone_delta['password'] = args.password zone_delta['password'] = args.password
if args.weight_offset:
zone_delta['weight_offset'] = args.weight_offset
if args.weight_scale:
zone_delta['weight_scale'] = args.weight_scale
if zone_delta: if zone_delta:
zone.update(**zone_delta) zone.update(**zone_delta)
else: else:
@ -706,10 +714,15 @@ class OpenStackShell(object):
@arg('zone_username', metavar='<zone_username>', @arg('zone_username', metavar='<zone_username>',
help='Authentication username.') help='Authentication username.')
@arg('password', metavar='<password>', help='Authentication password.') @arg('password', metavar='<password>', help='Authentication password.')
@arg('weight_offset', metavar='<weight_offset>',
help='Child Zone weight offset.')
@arg('weight_scale', metavar='<weight_scale>',
help='Child Zone weight scale.')
def do_zone_add(self, args): def do_zone_add(self, args):
"""Add a new child zone.""" """Add a new child zone."""
zone = self.cs.zones.create(args.api_url, args.zone_username, zone = self.cs.zones.create(args.api_url, args.zone_username,
args.password) args.password, args.weight_offset,
args.weight_scale)
print_dict(zone._info) print_dict(zone._info)
@arg('zone', metavar='<zone name>', help='Name or ID of the zone') @arg('zone', metavar='<zone name>', help='Name or ID of the zone')

@ -49,15 +49,19 @@ class Zone(base.Resource):
""" """
self.manager.delete(self) self.manager.delete(self)
def update(self, api_url=None, username=None, password=None): def update(self, api_url=None, username=None, password=None,
weight_offset=None, weight_scale=None):
""" """
Update the name for this child zone. Update the name for this child zone.
:param api_url: Update the child zone's API URL. :param api_url: Update the child zone's API URL.
:param username: Update the child zone's username. :param username: Update the child zone's username.
:param password: Update the child zone's password. :param password: Update the child zone's password.
:param weight_offset: Update the child zone's weight offset.
:param weight_scale: Update the child zone's weight scale.
""" """
self.manager.update(self, api_url, username, password) self.manager.update(self, api_url, username, password,
weight_offset, weight_scale)
class ZoneManager(base.BootingManagerWithFind): class ZoneManager(base.BootingManagerWithFind):
@ -90,18 +94,23 @@ class ZoneManager(base.BootingManagerWithFind):
detail = "/detail" detail = "/detail"
return self._list("/zones%s" % detail, "zones") return self._list("/zones%s" % detail, "zones")
def create(self, api_url, username, password): def create(self, api_url, username, password,
weight_offset=0.0, weight_scale=1.0):
""" """
Create a new child zone. Create a new child zone.
:param api_url: The child zone's API URL. :param api_url: The child zone's API URL.
:param username: The child zone's username. :param username: The child zone's username.
:param password: The child zone's password. :param password: The child zone's password.
:param weight_offset: The child zone's weight offset.
:param weight_scale: The child zone's weight scale.
""" """
body = {"zone": { body = {"zone": {
"api_url": api_url, "api_url": api_url,
"username": username, "username": username,
"password": password, "password": password,
"weight_offset": weight_offset,
"weight_scale": weight_scale
}} }}
return self._create("/zones", body, "zone") return self._create("/zones", body, "zone")
@ -128,6 +137,8 @@ class ZoneManager(base.BootingManagerWithFind):
by Nova for routing between Zones. Users cannot populate by Nova for routing between Zones. Users cannot populate
this field. this field.
:param reservation_id: a UUID for the set of servers being requested. :param reservation_id: a UUID for the set of servers being requested.
:param min_count: minimum number of servers to create.
:param max_count: maximum number of servers to create.
""" """
if not min_count: if not min_count:
min_count = 1 min_count = 1
@ -156,7 +167,8 @@ class ZoneManager(base.BootingManagerWithFind):
""" """
self._delete("/zones/%s" % base.getid(zone)) self._delete("/zones/%s" % base.getid(zone))
def update(self, zone, api_url=None, username=None, password=None): def update(self, zone, api_url=None, username=None, password=None,
weight_offset=None, weight_scale=None):
""" """
Update the name or the api_url for a zone. Update the name or the api_url for a zone.
@ -164,6 +176,8 @@ class ZoneManager(base.BootingManagerWithFind):
:param api_url: Update the API URL. :param api_url: Update the API URL.
:param username: Update the username. :param username: Update the username.
:param password: Update the password. :param password: Update the password.
:param weight_offset: Update the child zone's weight offset.
:param weight_scale: Update the child zone's weight scale.
""" """
body = {"zone": {}} body = {"zone": {}}
@ -173,7 +187,10 @@ class ZoneManager(base.BootingManagerWithFind):
body["zone"]["username"] = username body["zone"]["username"] = username
if password: if password:
body["zone"]["password"] = password body["zone"]["password"] = password
if weight_offset:
body["zone"]["weight_offset"] = weight_offset
if weight_scale:
body["zone"]["weight_scale"] = weight_scale
if not len(body["zone"]): if not len(body["zone"]):
return return
self._update("/zones/%s" % base.getid(zone), body) self._update("/zones/%s" % base.getid(zone), body)

@ -424,14 +424,16 @@ class FakeClient(OpenStackClient):
assert_equal(body.keys(), ['zone']) assert_equal(body.keys(), ['zone'])
assert_has_keys(body['zone'], assert_has_keys(body['zone'],
required=['api_url', 'username', 'password'], required=['api_url', 'username', 'password'],
optional=[]) optional=['weight_offset', 'weight_scale'])
return (202, self.get_zones_1()[1]) return (202, self.get_zones_1()[1])
def put_zones_1(self, body, **kw): def put_zones_1(self, body, **kw):
assert_equal(body.keys(), ['zone']) assert_equal(body.keys(), ['zone'])
assert_has_keys(body['zone'], optional=['api_url', 'username', assert_has_keys(body['zone'], optional=['api_url', 'username',
'password']) 'password',
'weight_offset',
'weight_scale'])
return (204, None) return (204, None)
def delete_zones_1(self, **kw): def delete_zones_1(self, **kw):

@ -319,11 +319,12 @@ def test_zone():
) )
def test_zone_add(): def test_zone_add():
shell('zone-add http://zzz frank xxx') shell('zone-add http://zzz frank xxx 0.0 1.0')
assert_called( assert_called(
'POST', '/zones', 'POST', '/zones',
{'zone': {'api_url': 'http://zzz', 'username': 'frank', {'zone': {'api_url': 'http://zzz', 'username': 'frank',
'password': 'xxx'}} 'password': 'xxx',
'weight_offset': '0.0', 'weight_scale': '1.0'}}
) )
def test_zone_delete(): def test_zone_delete():