Skip to content

Commit

Permalink
Merge "Add retry to server launch in respawn test."
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Jul 6, 2012
2 parents 33ed25f + 7dc34f4 commit c70974a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
20 changes: 15 additions & 5 deletions glance/tests/functional/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ def start_server(self,
:param server: the server to launch
:param expect_launch: true iff the server is expected to
successfully start
:param expect_exit: true iff the launched server is expected
:param expect_exit: true iff the launched process is expected
to exit in a timely fashion
:param expected_exitcode: expected exitcode from the launcher
"""
Expand All @@ -537,24 +537,34 @@ def start_server(self,
launch_msg = self.wait_for_servers([server], expect_launch)
self.assertTrue(launch_msg is None, launch_msg)

def start_with_retry(self, server, port_name, max_retries, **kwargs):
def start_with_retry(self, server, port_name, max_retries,
expect_launch=True, expect_exit=True,
expect_confirmation=True, **kwargs):
"""
Starts a server, with retries if the server launches but
fails to start listening on the expected port.
:param server: the server to launch
:param port_name: the name of the port attribute
:param max_retries: the maximum number of attempts
:param expect_launch: true iff the server is expected to
successfully start
:param expect_exit: true iff the launched process is expected
to exit in a timely fashion
:param expect_confirmation: true iff launch confirmation msg
expected on stdout
"""
launch_msg = None
for i in range(0, max_retries):
exitcode, out, err = server.start(**kwargs)
exitcode, out, err = server.start(expect_exit=expect_exit,
**kwargs)
name = server.server_name
self.assertEqual(0, exitcode,
"Failed to spin up the %s server. "
"Got: %s" % (name, err))
self.assertTrue(("Starting glance-%s with" % name) in out)
launch_msg = self.wait_for_servers([server])
if expect_confirmation:
self.assertTrue(("Starting glance-%s with" % name) in out)
launch_msg = self.wait_for_servers([server], expect_launch)
if launch_msg:
server.stop()
server.bind_port = get_unused_port()
Expand Down
22 changes: 14 additions & 8 deletions glance/tests/functional/test_respawn.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,13 @@ def test_respawn(self):
self.api_server.server_control_options += ' --respawn'

# start API server, allowing glance-control to continue running
self.start_server(self.api_server,
expect_launch=True,
expect_exit=False,
**self.__dict__.copy())
self.start_with_retry(self.api_server,
'api_port',
3,
expect_launch=True,
expect_exit=False,
expect_confirmation=False,
**self.__dict__.copy())

# ensure the service pid has been cached
pid_cached = lambda: os.path.exists(self.api_server.pid_file)
Expand Down Expand Up @@ -131,10 +134,13 @@ def test_bouncing(self):
self.api_server.default_store = 'shouldnotexist'

# start API server, allowing glance-control to continue running
self.start_server(self.api_server,
expect_launch=False,
expect_exit=False,
**self.__dict__.copy())
self.start_with_retry(self.api_server,
'api_port',
1,
expect_launch=False,
expect_exit=False,
expect_confirmation=False,
**self.__dict__.copy())

# ensure the service pid has been cached
pid_cached = lambda: os.path.exists(self.api_server.pid_file)
Expand Down

0 comments on commit c70974a

Please sign in to comment.