Skip to content

Commit

Permalink
mockmodel.py: unsubscribing from 'exit' channel on cleanup
Browse files Browse the repository at this point in the history
The function virtviewertmpfile_cleanup executes the cleanup
of the temporary file that the virt viewer mockmodel uses. For
each instance of the Mockmodel class, a new file is created and
needs cleanup.

When running the unit tests in WoK, this function gives an error
saying that the file doesn't exist. Further investigation showed
that the same cleanup function was being called multiple times,
causing this error.

This happens because the cherrypy 'exit' channel is process
wide and its subscribers are kept in subsequent calls of
cherrypy.engine.exit(). This scenario is common when running
the current WoK tests, which creates multiple server instances
in the same process.

The sitation before this patch can be exemplified as follows:

- Server A is instanced. The function 'cleanA' is subscribed
in the Cherrypy 'exit' channel;

- Server A exits. 'cleanA' is executed but it is not unsubscribed
from the 'exit' channel;

- A new server B is instanced. A function 'cleanB' is subscribed
in the 'exit' channel;

- Server B exits. A message is sent to all subscribers of the 'exit'
channel. 'cleanA' is called again and throws an error because there is
nothing else to clean up from the previous server A.

Making the cleanup function unsubscribe itself from the 'exit' channel
solves the issue.

This fixes WoK bug kimchi-project/wok#183

Signed-off-by: Daniel Henrique Barboza <danielhb@linux.vnet.ibm.com>
  • Loading branch information
danielhb authored and alinefm committed Dec 26, 2016
1 parent d6c3976 commit 6288c73
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions mockmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ def _create_virt_viewer_tmp_file(self):

def virtviewertmpfile_cleanup(self):
os.unlink(self.virtviewerfile_tmp.name)
cherrypy.engine.unsubscribe('exit', self.virtviewertmpfile_cleanup)

def reset(self):
MockModel._mock_vms = defaultdict(list)
Expand Down

0 comments on commit 6288c73

Please sign in to comment.