Skip to content

Commit

Permalink
Make AvailabilityZone parameter available to nova create
Browse files Browse the repository at this point in the history
Looks for the AvailabilityZone property in the instance's
resource section. For example:

"Resources" : {
  "Properties": {
    "AvailabilityZone" : "nova",
...

Fixes bug #1096006

Change-Id: I3333b5f909b27e53f6985713de58dd30efc1a80a
Signed-off-by: Jeff Peeler <jpeeler@redhat.com>
  • Loading branch information
jpeeler committed Feb 18, 2013
1 parent 6f330ae commit ea8bda2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
7 changes: 4 additions & 3 deletions heat/engine/resources/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ class Instance(resource.Resource):
'Required': True},
'KeyName': {'Type': 'String',
'Required': True},
'AvailabilityZone': {'Type': 'String',
'Default': 'nova'},
'AvailabilityZone': {'Type': 'String'},
'DisableApiTermination': {'Type': 'String',
'Implemented': False},
'KernelId': {'Type': 'String',
Expand Down Expand Up @@ -225,6 +224,7 @@ def handle_create(self):
userdata = self.properties['UserData'] or ''
flavor = self.properties['InstanceType']
key_name = self.properties['KeyName']
availability_zone = self.properties['AvailabilityZone']

keypairs = [k.name for k in self.nova().keypairs.list()]
if key_name not in keypairs:
Expand Down Expand Up @@ -279,7 +279,8 @@ def handle_create(self):
userdata=server_userdata,
meta=tags,
scheduler_hints=scheduler_hints,
nics=nics)
nics=nics,
availability_zone=availability_zone)
finally:
# Avoid a race condition where the thread could be cancelled
# before the ID is stored
Expand Down
4 changes: 3 additions & 1 deletion heat/tests/test_engine_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ def setup_mocks(mocks, stack):
fc.servers.create(image=744, flavor=3, key_name='test',
name='%s.WebServer' % stack.name, security_groups=None,
userdata=server_userdata, scheduler_hints=None,
meta=None, nics=None).AndReturn(fc.servers.list()[-1])
meta=None, nics=None,
availability_zone=None).AndReturn(
fc.servers.list()[-1])
return fc


Expand Down
11 changes: 6 additions & 5 deletions heat/tests/test_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ def test_instance_create(self):
name='%s.%s' % (stack_name, instance.name),
security_groups=None,
userdata=server_userdata, scheduler_hints=None,
meta=None, nics=None).AndReturn(self.fc.servers.list()[1])
meta=None, nics=None, availability_zone=None).AndReturn(
self.fc.servers.list()[1])
self.m.ReplayAll()

self.assertEqual(instance.create(), None)
Expand Down Expand Up @@ -112,7 +113,8 @@ def test_instance_create_delete(self):
name='%s.%s' % (stack_name, instance.name),
security_groups=None,
userdata=server_userdata, scheduler_hints=None,
meta=None, nics=None).AndReturn(self.fc.servers.list()[1])
meta=None, nics=None, availability_zone=None).AndReturn(
self.fc.servers.list()[1])
self.m.ReplayAll()

self.assertEqual(instance.create(), None)
Expand All @@ -131,8 +133,6 @@ def test_instance_create_delete(self):
self.assertEqual(instance.state, instance.DELETE_COMPLETE)
self.m.VerifyAll()

AZ = instance.FnGetAtt('AvailabilityZone')
self.assertEqual(AZ, 'nova')
private_ip = instance.FnGetAtt('PublicIp')
self.assertEqual(private_ip, '4.5.6.7')
private_ip = instance.FnGetAtt('PrivateIp')
Expand Down Expand Up @@ -173,7 +173,8 @@ def test_instance_update_metadata(self):
name='%s.%s' % (stack_name, instance.name),
security_groups=None,
userdata=server_userdata, scheduler_hints=None,
meta=None, nics=None).AndReturn(self.fc.servers.list()[1])
meta=None, nics=None, availability_zone=None).AndReturn(
self.fc.servers.list()[1])
self.m.ReplayAll()

self.assertEqual(instance.create(), None)
Expand Down
3 changes: 2 additions & 1 deletion heat/tests/test_loadbalancer.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ def test_loadbalancer(self):
flavor=2, image=745, key_name='test',
meta=None, nics=None, name=u'test_stack.LoadBalancer.LB_instance',
scheduler_hints=None, userdata=mox.IgnoreArg(),
security_groups=None).AndReturn(self.fc.servers.list()[1])
security_groups=None, availability_zone=None).AndReturn(
self.fc.servers.list()[1])
#stack.Stack.create_with_template(mox.IgnoreArg()).AndReturn(None)
Metadata.__set__(mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn(None)
Expand Down

0 comments on commit ea8bda2

Please sign in to comment.