Skip to content

Commit

Permalink
Make run instances respect availability zone
Browse files Browse the repository at this point in the history
 * includes test
 * fixes bug 888918

Change-Id: I40985e9dcc153fae53675f3da5e2d5b5763cfca3
  • Loading branch information
vishvananda committed Nov 16, 2011
1 parent 57ad4de commit b6644ff
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion nova/api/ec2/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -1464,7 +1464,7 @@ def run_instances(self, context, **kwargs):
user_data=kwargs.get('user_data'),
security_group=kwargs.get('security_group'),
availability_zone=kwargs.get('placement', {}).get(
'AvailabilityZone'),
'availability_zone'),
block_device_mapping=kwargs.get('block_device_mapping', {}))
return self._format_run_instances(context, resv_id)

Expand Down
35 changes: 35 additions & 0 deletions nova/tests/api/ec2/test_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -1226,6 +1226,41 @@ def fake_show(self, context, id):
self.assertEqual(instance['instanceState']['name'], 'running')
self.assertEqual(instance['instanceType'], 'm1.small')

def test_run_instances_availability_zone(self):
kwargs = {'image_id': 'ami-00000001',
'instance_type': FLAGS.default_instance_type,
'max_count': 1,
'placement': {'availability_zone': 'fake'},
}
run_instances = self.cloud.run_instances

def fake_show(self, context, id):
return {'id': 'cedef40a-ed67-4d10-800e-17455edce175',
'properties': {
'kernel_id': 'cedef40a-ed67-4d10-800e-17455edce175',
'type': 'machine'},
'container_format': 'ami',
'status': 'active'}

self.stubs.Set(fake._FakeImageService, 'show', fake_show)
# NOTE(comstud): Make 'cast' behave like a 'call' which will
# ensure that operations complete
self.stubs.Set(rpc, 'cast', rpc.call)

def fake_format(*args, **kwargs):
pass

self.stubs.Set(self.cloud, '_format_run_instances', fake_format)

def fake_create(*args, **kwargs):
self.assertEqual(kwargs['availability_zone'], 'fake')
return ({'id': 'fake-instance'}, 'fake-res-id')

self.stubs.Set(self.cloud.compute_api, 'create', fake_create)

# NOTE(vish) the assert for this call is in the fake_create method.
run_instances(self.context, **kwargs)

def test_run_instances_image_state_none(self):
kwargs = {'image_id': 'ami-00000001',
'instance_type': FLAGS.default_instance_type,
Expand Down

0 comments on commit b6644ff

Please sign in to comment.