summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
authorJesse Andrews <anotherjesse@gmail.com>2011-08-18 15:33:15 -0700
committerJesse Andrews <anotherjesse@gmail.com>2011-08-18 15:33:15 -0700
commit983e37ac5451cf26baf3460b33c90da498dff8ea (patch)
tree553d4d212a4a8a4dc508d33ab910ef00c7690c5a /nova
parent805c1cec609b39ee5a0ba1517bf2f1d41e0c4fa9 (diff)
parent2cb2e71454373f6baa857c8d73122c485e18c4c3 (diff)
downloadnova-983e37ac5451cf26baf3460b33c90da498dff8ea.tar.gz
nova-983e37ac5451cf26baf3460b33c90da498dff8ea.tar.xz
nova-983e37ac5451cf26baf3460b33c90da498dff8ea.zip
merge trunk
Diffstat (limited to 'nova')
-rw-r--r--nova/api/openstack/create_instance_helper.py2
-rw-r--r--nova/compute/api.py12
-rw-r--r--nova/db/sqlalchemy/api.py3
-rw-r--r--nova/tests/test_cloud.py11
-rw-r--r--nova/tests/test_db_api.py17
-rw-r--r--nova/tests/test_metadata.py40
6 files changed, 81 insertions, 4 deletions
diff --git a/nova/api/openstack/create_instance_helper.py b/nova/api/openstack/create_instance_helper.py
index 031b06921..e64a076c8 100644
--- a/nova/api/openstack/create_instance_helper.py
+++ b/nova/api/openstack/create_instance_helper.py
@@ -117,6 +117,7 @@ class CreateInstanceHelper(object):
raise exc.HTTPBadRequest(explanation=msg)
zone_blob = server_dict.get('blob')
+ user_data = server_dict.get('user_data')
availability_zone = server_dict.get('availability_zone')
name = server_dict['name']
self._validate_server_name(name)
@@ -158,6 +159,7 @@ class CreateInstanceHelper(object):
reservation_id=reservation_id,
min_count=min_count,
max_count=max_count,
+ user_data=user_data,
availability_zone=availability_zone))
except quota.QuotaError as error:
self._handle_quota_error(error)
diff --git a/nova/compute/api.py b/nova/compute/api.py
index e909e9959..b3932c644 100644
--- a/nova/compute/api.py
+++ b/nova/compute/api.py
@@ -1068,15 +1068,21 @@ class API(base.Base):
"""Unpause the given instance."""
self._cast_compute_message('unpause_instance', context, instance_id)
+ def _call_compute_message_for_host(self, action, context, host, params):
+ """Call method deliberately designed to make host/service only calls"""
+ queue = self.db.queue_get_for(context, FLAGS.compute_topic, host)
+ kwargs = {'method': action, 'args': params}
+ return rpc.call(context, queue, kwargs)
+
def set_host_enabled(self, context, host, enabled):
"""Sets the specified host's ability to accept new instances."""
- return self._call_compute_message("set_host_enabled", context,
+ return self._call_compute_message_for_host("set_host_enabled", context,
host=host, params={"enabled": enabled})
def host_power_action(self, context, host, action):
"""Reboots, shuts down or powers up the host."""
- return self._call_compute_message("host_power_action", context,
- host=host, params={"action": action})
+ return self._call_compute_message_for_host("host_power_action",
+ context, host=host, params={"action": action})
@scheduler_api.reroute_compute("diagnostics")
def get_diagnostics(self, context, instance_id):
diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py
index 95ec3f715..fe80056ab 100644
--- a/nova/db/sqlalchemy/api.py
+++ b/nova/db/sqlalchemy/api.py
@@ -1222,7 +1222,8 @@ def instance_get_all_by_filters(context, filters):
options(joinedload('security_groups')).\
options(joinedload_all('fixed_ips.network')).\
options(joinedload('metadata')).\
- options(joinedload('instance_type'))
+ options(joinedload('instance_type')).\
+ filter_by(deleted=can_read_deleted(context))
# Make a copy of the filters dictionary to use going forward, as we'll
# be modifying it and we shouldn't affect the caller's use of it.
diff --git a/nova/tests/test_cloud.py b/nova/tests/test_cloud.py
index b2afc53c9..0793784f8 100644
--- a/nova/tests/test_cloud.py
+++ b/nova/tests/test_cloud.py
@@ -487,6 +487,17 @@ class CloudTestCase(test.TestCase):
db.service_destroy(self.context, comp1['id'])
db.service_destroy(self.context, comp2['id'])
+ def test_describe_instances_deleted(self):
+ args1 = {'reservation_id': 'a', 'image_ref': 1, 'host': 'host1'}
+ inst1 = db.instance_create(self.context, args1)
+ args2 = {'reservation_id': 'b', 'image_ref': 1, 'host': 'host1'}
+ inst2 = db.instance_create(self.context, args2)
+ db.instance_destroy(self.context, inst1.id)
+ result = self.cloud.describe_instances(self.context)
+ result = result['reservationSet'][0]['instancesSet']
+ self.assertEqual(result[0]['instanceId'],
+ ec2utils.id_to_ec2_id(inst2.id))
+
def _block_device_mapping_create(self, instance_id, mappings):
volumes = []
for bdm in mappings:
diff --git a/nova/tests/test_db_api.py b/nova/tests/test_db_api.py
index 0c07cbb7c..038c07f40 100644
--- a/nova/tests/test_db_api.py
+++ b/nova/tests/test_db_api.py
@@ -76,3 +76,20 @@ class DbApiTestCase(test.TestCase):
self.assertEqual(instance['id'], result['id'])
self.assertEqual(result['fixed_ips'][0]['floating_ips'][0].address,
'1.2.1.2')
+
+ def test_instance_get_all_by_filters(self):
+ args = {'reservation_id': 'a', 'image_ref': 1, 'host': 'host1'}
+ inst1 = db.instance_create(self.context, args)
+ inst2 = db.instance_create(self.context, args)
+ result = db.instance_get_all_by_filters(self.context, {})
+ self.assertTrue(2, len(result))
+
+ def test_instance_get_all_by_filters_deleted(self):
+ args1 = {'reservation_id': 'a', 'image_ref': 1, 'host': 'host1'}
+ inst1 = db.instance_create(self.context, args1)
+ args2 = {'reservation_id': 'b', 'image_ref': 1, 'host': 'host1'}
+ inst2 = db.instance_create(self.context, args2)
+ db.instance_destroy(self.context, inst1.id)
+ result = db.instance_get_all_by_filters(self.context.elevated(), {})
+ self.assertEqual(1, len(result))
+ self.assertEqual(result[0].id, inst2.id)
diff --git a/nova/tests/test_metadata.py b/nova/tests/test_metadata.py
index bfc7a6d44..b06e5c136 100644
--- a/nova/tests/test_metadata.py
+++ b/nova/tests/test_metadata.py
@@ -23,12 +23,21 @@ import httplib
import webob
+from nova import exception
from nova import test
from nova import wsgi
from nova.api.ec2 import metadatarequesthandler
from nova.db.sqlalchemy import api
+USER_DATA_STRING = ("This is an encoded string")
+ENCODE_USER_DATA_STRING = base64.b64encode(USER_DATA_STRING)
+
+
+def return_non_existing_server_by_address(context, address):
+ raise exception.NotFound()
+
+
class MetadataTestCase(test.TestCase):
"""Test that metadata is returning proper values."""
@@ -79,3 +88,34 @@ class MetadataTestCase(test.TestCase):
self.stubs.Set(api, 'security_group_get_by_instance', sg_get)
self.assertEqual(self.request('/meta-data/security-groups'),
'default\nother')
+
+ def test_user_data_non_existing_fixed_address(self):
+ self.stubs.Set(api, 'instance_get_all_by_filters',
+ return_non_existing_server_by_address)
+ request = webob.Request.blank('/user-data')
+ request.remote_addr = "127.1.1.1"
+ response = request.get_response(self.app)
+ self.assertEqual(response.status_int, 404)
+
+ def test_user_data_none_fixed_address(self):
+ self.stubs.Set(api, 'instance_get_all_by_filters',
+ return_non_existing_server_by_address)
+ request = webob.Request.blank('/user-data')
+ request.remote_addr = None
+ response = request.get_response(self.app)
+ self.assertEqual(response.status_int, 500)
+
+ def test_user_data_invalid_url(self):
+ request = webob.Request.blank('/user-data-invalid')
+ request.remote_addr = "127.0.0.1"
+ response = request.get_response(self.app)
+ self.assertEqual(response.status_int, 404)
+
+ def test_user_data_with_use_forwarded_header(self):
+ self.instance['user_data'] = ENCODE_USER_DATA_STRING
+ self.flags(use_forwarded_for=True)
+ request = webob.Request.blank('/user-data')
+ request.remote_addr = "127.0.0.1"
+ response = request.get_response(self.app)
+ self.assertEqual(response.status_int, 200)
+ self.assertEqual(response.body, USER_DATA_STRING)