Merge "Add metadata server fixture"

This commit is contained in:
Jenkins 2016-07-26 15:04:32 +00:00 committed by Gerrit Code Review
commit 533628f03e

@ -435,16 +435,16 @@ class OSAPIFixture(fixtures.Fixture):
# host, and dynamically allocate ports
conf_overrides = {
'osapi_compute_listen': '127.0.0.1',
'metadata_listen': '127.0.0.1',
'osapi_compute_listen_port': 0,
'metadata_listen_port': 0,
'verbose': True,
'debug': True
'debug': True,
}
self.useFixture(ConfPatcher(**conf_overrides))
self.osapi = service.WSGIService("osapi_compute")
self.osapi.start()
self.addCleanup(self.osapi.stop)
self.auth_url = 'http://%(host)s:%(port)s/%(api_version)s' % ({
'host': self.osapi.host, 'port': self.osapi.port,
'api_version': self.api_version})
@ -454,6 +454,43 @@ class OSAPIFixture(fixtures.Fixture):
'admin', 'admin', self.auth_url, self.project_id)
class OSMetadataServer(fixtures.Fixture):
"""Create an OS Metadata API server as a fixture.
This spawns an OS Metadata API server as a fixture in a new
greenthread in the current test.
TODO(sdague): ideally for testing we'd have something like the
test client which acts like requests, but connects any of the
interactions needed.
"""
def setUp(self):
super(OSMetadataServer, self).setUp()
# in order to run these in tests we need to bind only to local
# host, and dynamically allocate ports
conf_overrides = {
'metadata_listen': '127.0.0.1',
'metadata_listen_port': 0,
'verbose': True,
'debug': True
}
self.useFixture(ConfPatcher(**conf_overrides))
# NOTE(mikal): we don't have root to manipulate iptables, so just
# zero that bit out.
self.useFixture(fixtures.MonkeyPatch(
'nova.network.linux_net.IptablesManager._apply',
lambda _: None))
self.metadata = service.WSGIService("metadata")
self.metadata.start()
self.addCleanup(self.metadata.stop)
self.md_url = "http://%s:%s/" % (
conf_overrides['metadata_listen'],
self.metadata.port)
class PoisonFunctions(fixtures.Fixture):
"""Poison functions so they explode if we touch them.