stricter zone_id checking

This commit is contained in:
Sandy Walsh
2011-07-07 10:20:35 -07:00
11 changed files with 94 additions and 130 deletions

View File

@@ -63,6 +63,19 @@ flags.DEFINE_flag(flags.HelpshortFlag())
flags.DEFINE_flag(flags.HelpXMLFlag())
def handle_flash_socket_policy(socket):
LOG.info(_("Received connection on flash socket policy port"))
fd = socket.makefile('rw')
expected_command = "<policy-file-request/>"
if expected_command in fd.read(len(expected_command) + 1):
LOG.info(_("Received valid flash socket policy request"))
fd.write('<?xml version="1.0"?><cross-domain-policy><allow-'
'access-from domain="*" to-ports="%d" /></cross-'
'domain-policy>' % (FLAGS.vncproxy_port))
fd.flush()
socket.close()
if __name__ == "__main__":
utils.default_flagfile()
FLAGS(sys.argv)
@@ -101,4 +114,6 @@ if __name__ == "__main__":
host=FLAGS.vncproxy_host,
port=FLAGS.vncproxy_port)
server.start()
server.start_tcp(handle_flash_socket_policy, 843, host=FLAGS.vncproxy_host)
server.wait()

View File

@@ -134,3 +134,13 @@ def get_id_from_href(href):
except:
LOG.debug(_("Error extracting id from href: %s") % href)
raise webob.exc.HTTPBadRequest(_('could not parse id from href'))
def remove_version_from_href(base_url):
"""Removes the api version from the href.
Given: 'http://www.nova.com/v1.1/123'
Returns: 'http://www.nova.com/123'
"""
return base_url.rsplit('/', 1).pop(0)

View File

@@ -71,6 +71,7 @@ class ViewBuilderV11(ViewBuilder):
def _build_links(self, flavor_obj):
"""Generate a container of links that refer to the provided flavor."""
href = self.generate_href(flavor_obj["id"])
bookmark = self.generate_bookmark(flavor_obj["id"])
links = [
{
@@ -79,13 +80,7 @@ class ViewBuilderV11(ViewBuilder):
},
{
"rel": "bookmark",
"type": "application/json",
"href": href,
},
{
"rel": "bookmark",
"type": "application/xml",
"href": href,
"href": bookmark,
},
]
@@ -94,3 +89,10 @@ class ViewBuilderV11(ViewBuilder):
def generate_href(self, flavor_id):
"""Create an url that refers to a specific flavor id."""
return "%s/flavors/%s" % (self.base_url, flavor_id)
def generate_bookmark(self, flavor_id):
"""Create an url that refers to a specific flavor id."""
return "%s/flavors/%s" % (
common.remove_version_from_href(self.base_url),
flavor_id,
)

View File

@@ -17,6 +17,8 @@
import os.path
from nova.api.openstack import common
class ViewBuilder(object):
"""Base class for generating responses to OpenStack API image requests."""
@@ -104,6 +106,7 @@ class ViewBuilderV11(ViewBuilder):
"""Return a standardized image structure for display by the API."""
image = ViewBuilder.build(self, image_obj, detail)
href = self.generate_href(image_obj["id"])
bookmark = self.generate_bookmark(image_obj["id"])
if detail:
image["metadata"] = image_obj.get("properties", {})
@@ -114,13 +117,12 @@ class ViewBuilderV11(ViewBuilder):
},
{
"rel": "bookmark",
"type": "application/json",
"href": href,
},
{
"rel": "bookmark",
"type": "application/xml",
"href": href,
"href": bookmark,
}]
return image
def generate_bookmark(self, image_id):
"""Create an url that refers to a specific flavor id."""
return os.path.join(common.remove_version_from_href(self._url),
"images", str(image_id))

View File

@@ -156,6 +156,7 @@ class ViewBuilderV11(ViewBuilder):
def _build_links(self, response, inst):
href = self.generate_href(inst["id"])
bookmark = self.generate_bookmark(inst["id"])
links = [
{
@@ -164,13 +165,7 @@ class ViewBuilderV11(ViewBuilder):
},
{
"rel": "bookmark",
"type": "application/json",
"href": href,
},
{
"rel": "bookmark",
"type": "application/xml",
"href": href,
"href": bookmark,
},
]
@@ -179,3 +174,8 @@ class ViewBuilderV11(ViewBuilder):
def generate_href(self, server_id):
"""Create an url that refers to a specific server id."""
return os.path.join(self.base_url, "servers", str(server_id))
def generate_bookmark(self, server_id):
"""Create an url that refers to a specific flavor id."""
return os.path.join(common.remove_version_from_href(self.base_url),
"servers", str(server_id))

View File

@@ -178,12 +178,14 @@ class ZoneAwareScheduler(driver.Scheduler):
to adjust the weights returned from the child zones. Alters
child_results in place.
"""
for zone, result in child_results:
for zone_id, result in child_results:
if not result:
continue
assert isinstance(zone_id, int)
for zone_rec in zones:
if zone_rec['id'] != zone:
if zone_rec['id'] != zone_id:
continue
for item in result:
@@ -196,7 +198,7 @@ class ZoneAwareScheduler(driver.Scheduler):
item['raw_weight'] = raw_weight
except KeyError:
LOG.exception(_("Bad child zone scaling values "
"for Zone: %(zone)s") % locals())
"for Zone: %(zone_id)s") % locals())
def schedule_run_instance(self, context, instance_id, request_spec,
*args, **kwargs):

View File

@@ -159,13 +159,7 @@ class FlavorsTest(test.TestCase):
},
{
"rel": "bookmark",
"type": "application/json",
"href": "http://localhost/v1.1/flavors/12",
},
{
"rel": "bookmark",
"type": "application/xml",
"href": "http://localhost/v1.1/flavors/12",
"href": "http://localhost/flavors/12",
},
],
}
@@ -188,13 +182,7 @@ class FlavorsTest(test.TestCase):
},
{
"rel": "bookmark",
"type": "application/json",
"href": "http://localhost/v1.1/flavors/1",
},
{
"rel": "bookmark",
"type": "application/xml",
"href": "http://localhost/v1.1/flavors/1",
"href": "http://localhost/flavors/1",
},
],
},
@@ -208,13 +196,7 @@ class FlavorsTest(test.TestCase):
},
{
"rel": "bookmark",
"type": "application/json",
"href": "http://localhost/v1.1/flavors/2",
},
{
"rel": "bookmark",
"type": "application/xml",
"href": "http://localhost/v1.1/flavors/2",
"href": "http://localhost/flavors/2",
},
],
},
@@ -240,13 +222,7 @@ class FlavorsTest(test.TestCase):
},
{
"rel": "bookmark",
"type": "application/json",
"href": "http://localhost/v1.1/flavors/1",
},
{
"rel": "bookmark",
"type": "application/xml",
"href": "http://localhost/v1.1/flavors/1",
"href": "http://localhost/flavors/1",
},
],
},
@@ -262,13 +238,7 @@ class FlavorsTest(test.TestCase):
},
{
"rel": "bookmark",
"type": "application/json",
"href": "http://localhost/v1.1/flavors/2",
},
{
"rel": "bookmark",
"type": "application/xml",
"href": "http://localhost/v1.1/flavors/2",
"href": "http://localhost/flavors/2",
},
],
},

View File

@@ -400,6 +400,7 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
actual_image = json.loads(response.body)
href = "http://localhost/v1.1/images/124"
bookmark = "http://localhost/images/124"
expected_image = {
"image": {
@@ -419,13 +420,7 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
},
{
"rel": "bookmark",
"type": "application/json",
"href": href,
},
{
"rel": "bookmark",
"type": "application/xml",
"href": href,
"href": bookmark,
}],
},
}
@@ -557,22 +552,17 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
continue
href = "http://localhost/v1.1/images/%s" % image["id"]
bookmark = "http://localhost/images/%s" % image["id"]
test_image = {
"id": image["id"],
"name": image["name"],
"links": [{
"rel": "self",
"href": "http://localhost/v1.1/images/%s" % image["id"],
},
{
"rel": "bookmark",
"type": "application/json",
"href": href,
},
{
"rel": "bookmark",
"type": "application/xml",
"href": href,
"href": bookmark,
}],
}
self.assertTrue(test_image in response_list)
@@ -652,13 +642,7 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
},
{
"rel": "bookmark",
"type": "application/json",
"href": "http://localhost/v1.1/images/123",
},
{
"rel": "bookmark",
"type": "application/xml",
"href": "http://localhost/v1.1/images/123",
"href": "http://localhost/images/123",
}],
},
{
@@ -678,13 +662,7 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
},
{
"rel": "bookmark",
"type": "application/json",
"href": "http://localhost/v1.1/images/124",
},
{
"rel": "bookmark",
"type": "application/xml",
"href": "http://localhost/v1.1/images/124",
"href": "http://localhost/images/124",
}],
},
{
@@ -705,13 +683,7 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
},
{
"rel": "bookmark",
"type": "application/json",
"href": "http://localhost/v1.1/images/125",
},
{
"rel": "bookmark",
"type": "application/xml",
"href": "http://localhost/v1.1/images/125",
"href": "http://localhost/images/125",
}],
},
{
@@ -731,13 +703,7 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
},
{
"rel": "bookmark",
"type": "application/json",
"href": "http://localhost/v1.1/images/126",
},
{
"rel": "bookmark",
"type": "application/xml",
"href": "http://localhost/v1.1/images/126",
"href": "http://localhost/images/126",
}],
},
{
@@ -757,13 +723,7 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
},
{
"rel": "bookmark",
"type": "application/json",
"href": "http://localhost/v1.1/images/127",
},
{
"rel": "bookmark",
"type": "application/xml",
"href": "http://localhost/v1.1/images/127",
"href": "http://localhost/images/127",
}],
},
{
@@ -779,13 +739,7 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
},
{
"rel": "bookmark",
"type": "application/json",
"href": "http://localhost/v1.1/images/129",
},
{
"rel": "bookmark",
"type": "application/xml",
"href": "http://localhost/v1.1/images/129",
"href": "http://localhost/images/129",
}],
},
]

View File

@@ -290,13 +290,7 @@ class ServersTest(test.TestCase):
},
{
"rel": "bookmark",
"type": "application/json",
"href": "http://localhost/v1.1/servers/1",
},
{
"rel": "bookmark",
"type": "application/xml",
"href": "http://localhost/v1.1/servers/1",
"href": "http://localhost/servers/1",
},
]
@@ -515,13 +509,7 @@ class ServersTest(test.TestCase):
},
{
"rel": "bookmark",
"type": "application/json",
"href": "http://localhost/v1.1/servers/%d" % (i,),
},
{
"rel": "bookmark",
"type": "application/xml",
"href": "http://localhost/v1.1/servers/%d" % (i,),
"href": "http://localhost/servers/%d" % (i,),
},
]

View File

@@ -67,6 +67,7 @@ class Server(object):
self.host = host or "0.0.0.0"
self.port = port or 0
self._server = None
self._tcp_server = None
self._socket = None
self._pool = eventlet.GreenPool(pool_size or self.default_pool_size)
self._logger = logging.getLogger("eventlet.wsgi.server")
@@ -106,6 +107,17 @@ class Server(object):
"""
LOG.info(_("Stopping WSGI server."))
self._server.kill()
if self._tcp_server is not None:
LOG.info(_("Stopping raw TCP server."))
self._tcp_server.kill()
def start_tcp(self, listener, port, host='0.0.0.0', key=None, backlog=128):
"""Run a raw TCP server with the given application."""
arg0 = sys.argv[0]
LOG.info(_('Starting TCP server %(arg0)s on %(host)s:%(port)s')
% locals())
socket = eventlet.listen((host, port), backlog=backlog)
self._tcp_server = self._pool.spawn_n(self._run_tcp, listener, socket)
def wait(self):
"""Block, until the server has stopped.
@@ -120,6 +132,15 @@ class Server(object):
except greenlet.GreenletExit:
LOG.info(_("WSGI server has stopped."))
def _run_tcp(self, listener, socket):
"""Start a raw TCP server in a new green thread."""
while True:
try:
new_sock, address = socket.accept()
self._pool.spawn_n(listener, new_sock)
except (SystemExit, KeyboardInterrupt):
pass
class Request(webob.Request):
pass

View File

@@ -114,7 +114,7 @@ if [ $just_pep8 -eq 1 ]; then
fi
if [ $recreate_db -eq 1 ]; then
rm tests.sqlite
rm -f tests.sqlite
fi
run_tests || exit