Update CLI to use autotemp for tempfiles

Signed-off-by: Scott Zawalski <scottz@google.com>


git-svn-id: http://test.kernel.org/svn/autotest/trunk@3396 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/cli/acl_unittest.py b/cli/acl_unittest.py
index 9f5c9ff..f895f00 100755
--- a/cli/acl_unittest.py
+++ b/cli/acl_unittest.py
@@ -15,10 +15,11 @@
         acl_list = acl.acl_list()
         afile = cli_mock.create_file('acl0\nacl3\nacl4\n')
         sys.argv = ['atest', 'acl0', 'acl1,acl2',
-                    '--alist', afile, 'acl5', 'acl6,acl7']
+                    '--alist', afile.name, 'acl5', 'acl6,acl7']
         acl_list.parse()
         self.assertEqualNoOrder(['acl%s' % x for x in range(8)],
                                 acl_list.acls)
+        afile.clean()
 
 
     def test_parse_list_user(self):
@@ -218,7 +219,7 @@
     def test_acl_delete_multiple_acl_ok(self):
         alist = cli_mock.create_file('acl2\nacl1')
         self.run_cmd(argv=['atest', 'acl', 'delete',
-                           'acl0', 'acl1', '--alist', alist],
+                           'acl0', 'acl1', '--alist', alist.name],
                      rpcs=[('delete_acl_group',
                            {'id': 'acl0'},
                            True,
@@ -232,12 +233,13 @@
                            True,
                            None)],
                      out_words_ok=['acl0', 'acl1', 'acl2', 'Deleted'])
+        alist.clean()
 
 
     def test_acl_delete_multiple_acl_bad(self):
         alist = cli_mock.create_file('acl2\nacl1')
         self.run_cmd(argv=['atest', 'acl', 'delete',
-                           'acl0', 'acl1', '--alist', alist],
+                           'acl0', 'acl1', '--alist', alist.name],
                      rpcs=[('delete_acl_group',
                            {'id': 'acl0'},
                            True,
@@ -255,6 +257,7 @@
                      err_words_ok=['acl1', 'delete_acl_group',
                                    'DoesNotExist', 'acl_group',
                                    'matching'])
+        alist.clean()
 
 
 class acl_add_unittest(cli_mock.cli_unittest):
diff --git a/cli/action_common_unittest.py b/cli/action_common_unittest.py
index 8f08f56..e80cdc1 100755
--- a/cli/action_common_unittest.py
+++ b/cli/action_common_unittest.py
@@ -4,7 +4,7 @@
 
 """Tests for action_common."""
 
-import unittest, os, sys, tempfile, StringIO, copy
+import unittest, os, sys, StringIO, copy
 
 import common
 from autotest_lib.cli import cli_mock, topic_common, action_common, rpc
diff --git a/cli/cli_mock.py b/cli/cli_mock.py
index 27b16ac..e6499e9 100755
--- a/cli/cli_mock.py
+++ b/cli/cli_mock.py
@@ -3,21 +3,22 @@
 
 """Test for cli."""
 
-import unittest, os, sys, tempfile, StringIO
+import unittest, os, sys, StringIO
 
 import common
 from autotest_lib.cli import atest, topic_common, rpc
 from autotest_lib.frontend.afe.json_rpc import proxy
 from autotest_lib.client.common_lib.test_utils import mock
+from autotest_lib.client.common_lib import autotemp
 
 CLI_USING_PDB = False
 CLI_UT_DEBUG = False
 
 def create_file(content):
-    (fp, filename) = tempfile.mkstemp(text=True)
-    os.write(fp, content)
-    os.close(fp)
-    return filename
+    file_temp = autotemp.tempfile(unique_id='cli_mock', text=True)
+    os.write(file_temp.fd, content)
+    os.close(file_temp.fd)
+    return file_temp
 
 
 class ExitException(Exception):
diff --git a/cli/host_unittest.py b/cli/host_unittest.py
index 5d74cab..e64477f 100755
--- a/cli/host_unittest.py
+++ b/cli/host_unittest.py
@@ -58,11 +58,12 @@
     def test_parse_with_hosts(self):
         hl = host.host_list()
         mfile = cli_mock.create_file('host0\nhost3\nhost4\n')
-        sys.argv = ['atest', 'host1', '--mlist', mfile, 'host3']
+        sys.argv = ['atest', 'host1', '--mlist', mfile.name, 'host3']
         (options, leftover) = hl.parse()
         self.assertEqualNoOrder(['host0', 'host1','host3', 'host4'],
                                 hl.hosts)
         self.assertEqual(leftover, [])
+        mfile.clean()
 
 
     def test_parse_with_labels(self):
@@ -84,13 +85,14 @@
     def test_parse_with_both(self):
         hl = host.host_list()
         mfile = cli_mock.create_file('host0\nhost3\nhost4\n')
-        sys.argv = ['atest', 'host1', '--mlist', mfile, 'host3',
+        sys.argv = ['atest', 'host1', '--mlist', mfile.name, 'host3',
                     '--label', 'label0']
         (options, leftover) = hl.parse()
         self.assertEqualNoOrder(['host0', 'host1','host3', 'host4'],
                                 hl.hosts)
         self.assertEqual('label0', hl.labels)
         self.assertEqual(leftover, [])
+        mfile.clean()
 
 
     def test_execute_list_all_no_labels(self):
@@ -174,7 +176,7 @@
     def test_execute_list_filter_two_hosts(self):
         mfile = cli_mock.create_file('host2')
         self.run_cmd(argv=['atest', 'host', 'list', 'host1',
-                           '--mlist', mfile, '--ignore_site_file'],
+                           '--mlist', mfile.name, '--ignore_site_file'],
                      # This is a bit fragile as the list order may change...
                      rpcs=[('get_hosts', {'hostname__in': ['host2', 'host1']},
                             True,
@@ -202,12 +204,13 @@
                                    'label2', 'label3', 'True',
                                    'host2', 'label4'],
                      out_words_no=['host0', 'label1', 'False'])
+        mfile.clean()
 
 
     def test_execute_list_filter_two_hosts_one_not_found(self):
         mfile = cli_mock.create_file('host2')
         self.run_cmd(argv=['atest', 'host', 'list', 'host1',
-                           '--mlist', mfile, '--ignore_site_file'],
+                           '--mlist', mfile.name, '--ignore_site_file'],
                      # This is a bit fragile as the list order may change...
                      rpcs=[('get_hosts', {'hostname__in': ['host2', 'host1']},
                             True,
@@ -225,6 +228,7 @@
                                    'label3', 'label4', 'True'],
                      out_words_no=['host1', 'False'],
                      err_words_ok=['host1'])
+        mfile.clean()
 
 
     def test_execute_list_filter_two_hosts_none_found(self):
@@ -1230,7 +1234,7 @@
     def test_execute_ready_hosts(self):
         mfile = cli_mock.create_file('host0\nhost1,host2\nhost3 host4')
         self.run_cmd(argv=['atest', 'host', 'mod', '--ready',
-                           'host5' ,'--mlist', mfile, 'host1', 'host6',
+                           'host5' ,'--mlist', mfile.name, 'host1', 'host6',
                            '--ignore_site_file'],
                      rpcs=[('modify_host', {'id': 'host6', 'status': 'Ready'},
                             True, None),
@@ -1248,6 +1252,7 @@
                             True, None)],
                      out_words_ok=['Ready', 'host0', 'host1', 'host2',
                                    'host3', 'host4', 'host5', 'host6'])
+        mfile.clean()
 
 
 
diff --git a/cli/job_unittest.py b/cli/job_unittest.py
index 31444c5..aa27043 100755
--- a/cli/job_unittest.py
+++ b/cli/job_unittest.py
@@ -587,19 +587,20 @@
 
 
     def test_execute_create_job_with_control(self):
-        filename = cli_mock.create_file(self.ctrl_file)
-        self.run_cmd(argv=['atest', 'job', 'create', '-f', filename,
+        file_temp = cli_mock.create_file(self.ctrl_file)
+        self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
                            'test_job0', '-m', 'host0', '--ignore_site_file'],
                      rpcs=[('create_job', self.data, True, 42)],
                      out_words_ok=['test_job0', 'Created'],
                      out_words_no=['Uploading', 'Done'])
+        file_temp.clean()
 
 
     def test_execute_create_job_with_control_and_kernel(self):
         data = self.data.copy()
         data['control_file'] = '# Made up control "file" for unittest.'
-        filename = cli_mock.create_file(self.trivial_ctrl_file)
-        self.run_cmd(argv=['atest', 'job', 'create', '-f', filename,
+        file_temp = cli_mock.create_file(self.trivial_ctrl_file)
+        self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
                            '-k', 'Kernel', 'test_job0', '-m', 'host0',
                            '--ignore_site_file'],
                      rpcs=[('generate_control_file',
@@ -614,42 +615,46 @@
                            ('create_job', data, True, 42)],
                      out_words_ok=['test_job0', 'Created',
                                    'Uploading', 'Done'])
+        file_temp.clean()
 
 
     def test_execute_create_job_with_control_and_email(self):
         data = self.data.copy()
         data['email_list'] = 'em'
-        filename = cli_mock.create_file(self.ctrl_file)
-        self.run_cmd(argv=['atest', 'job', 'create', '-f', filename,
+        file_temp = cli_mock.create_file(self.ctrl_file)
+        self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
                            'test_job0', '-m', 'host0', '-e', 'em',
                            '--ignore_site_file'],
                      rpcs=[('create_job', data, True, 42)],
                      out_words_ok=['test_job0', 'Created'],
                      out_words_no=['Uploading', 'Done'])
+        file_temp.clean()
 
 
     def test_execute_create_job_with_control_and_dependencies(self):
         data = self.data.copy()
         data['dependencies'] = ['dep1', 'dep2']
-        filename = cli_mock.create_file(self.ctrl_file)
-        self.run_cmd(argv=['atest', 'job', 'create', '-f', filename,
+        file_temp = cli_mock.create_file(self.ctrl_file)
+        self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
                            'test_job0', '-m', 'host0', '-d', 'dep1, dep2 ',
                            '--ignore_site_file'],
                      rpcs=[('create_job', data, True, 42)],
                      out_words_ok=['test_job0', 'Created'],
                      out_words_no=['Uploading', 'Done'])
+        file_temp.clean()
 
 
     def test_execute_create_job_with_synch_count(self):
         data = self.data.copy()
         data['synch_count'] = 2
-        filename = cli_mock.create_file(self.ctrl_file)
-        self.run_cmd(argv=['atest', 'job', 'create', '-f', filename,
+        file_temp = cli_mock.create_file(self.ctrl_file)
+        self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
                            'test_job0', '-m', 'host0', '-y', '2',
                            '--ignore_site_file'],
                      rpcs=[('create_job', data, True, 42)],
                      out_words_ok=['test_job0', 'Created'],
                      out_words_no=['Uploading', 'Done'])
+        file_temp.clean()
 
 
     def test_execute_create_job_with_test_and_dependencies(self):
@@ -724,14 +729,16 @@
 
     def test_execute_create_job_no_hosts(self):
         testjob = job.job_create()
-        filename = cli_mock.create_file(self.ctrl_file)
-        sys.argv = ['atest', '-f', filename, 'test_job0', '--ignore_site_file']
+        file_temp = cli_mock.create_file(self.ctrl_file)
+        sys.argv = ['atest', '-f', file_temp.name, 'test_job0',
+                    '--ignore_site_file']
         self.god.mock_io()
         (sys.exit.expect_call(mock.anything_comparator())
          .and_raises(cli_mock.ExitException))
         self.assertRaises(cli_mock.ExitException, testjob.parse)
         self.god.unmock_io()
         self.god.check_playback()
+        file_temp.clean()
 
 
     def test_execute_create_job_cfile_and_tests(self):
@@ -785,46 +792,51 @@
     def test_execute_create_job_with_mfile(self):
         data = self.data.copy()
         data['hosts'] = ['host3', 'host2', 'host1', 'host0']
-        cfile = cli_mock.create_file(self.ctrl_file)
-        filename = cli_mock.create_file('host0\nhost1\nhost2\nhost3')
-        self.run_cmd(argv=['atest', 'job', 'create', '--mlist', filename, '-f',
-                           cfile, 'test_job0', '--ignore_site_file'],
+        ctemp = cli_mock.create_file(self.ctrl_file)
+        file_temp = cli_mock.create_file('host0\nhost1\nhost2\nhost3')
+        self.run_cmd(argv=['atest', 'job', 'create', '--mlist', file_temp.name,
+                           '-f', ctemp.name, 'test_job0', '--ignore_site_file'],
                      rpcs=[('create_job', data, True, 42)],
                      out_words_ok=['test_job0', 'Created'])
+        ctemp.clean()
+        file_temp.clean()
 
 
     def test_execute_create_job_with_timeout(self):
         data = self.data.copy()
         data['timeout'] = '222'
-        filename = cli_mock.create_file(self.ctrl_file)
-        self.run_cmd(argv=['atest', 'job', 'create', '-f', filename,
+        file_temp = cli_mock.create_file(self.ctrl_file)
+        self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
                            'test_job0', '-m', 'host0', '-o', '222',
                            '--ignore_site_file'],
                      rpcs=[('create_job', data, True, 42)],
                      out_words_ok=['test_job0', 'Created'],)
+        file_temp.clean()
 
 
     def test_execute_create_job_with_max_runtime(self):
         data = self.data.copy()
         data['max_runtime_hrs'] = '222'
-        filename = cli_mock.create_file(self.ctrl_file)
-        self.run_cmd(argv=['atest', 'job', 'create', '-f', filename,
+        file_temp = cli_mock.create_file(self.ctrl_file)
+        self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
                            'test_job0', '-m', 'host0', '--max_runtime', '222',
                            '--ignore_site_file'],
                      rpcs=[('create_job', data, True, 42)],
                      out_words_ok=['test_job0', 'Created'],)
+        file_temp.clean()
 
 
 
     def test_execute_create_job_with_noverify(self):
         data = self.data.copy()
         data['run_verify'] = False
-        filename = cli_mock.create_file(self.ctrl_file)
-        self.run_cmd(argv=['atest', 'job', 'create', '-f', filename,
+        file_temp = cli_mock.create_file(self.ctrl_file)
+        self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
                            'test_job0', '-m', 'host0', '-n',
                            '--ignore_site_file'],
                      rpcs=[('create_job', data, True, 42)],
                      out_words_ok=['test_job0', 'Created'],)
+        file_temp.clean()
 
 
     def test_execute_create_job_oth(self):
@@ -885,8 +897,8 @@
     def test_execute_create_job_with_control_and_labels(self):
         data = self.data.copy()
         data['hosts'] = ['host0', 'host1', 'host2']
-        filename = cli_mock.create_file(self.ctrl_file)
-        self.run_cmd(argv=['atest', 'job', 'create', '-f', filename,
+        file_temp = cli_mock.create_file(self.ctrl_file)
+        self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
                            'test_job0', '-m', 'host0', '-b', 'label1,label2',
                            '--ignore_site_file'],
                      rpcs=[('get_hosts', {'multiple_labels': ['label1',
@@ -908,13 +920,14 @@
                             ('create_job', data, True, 42)],
                      out_words_ok=['test_job0', 'Created'],
                      out_words_no=['Uploading', 'Done'])
+        file_temp.clean()
 
 
     def test_execute_create_job_with_label_and_duplicate_hosts(self):
         data = self.data.copy()
         data['hosts'] = ['host1', 'host0']
-        filename = cli_mock.create_file(self.ctrl_file)
-        self.run_cmd(argv=['atest', 'job', 'create', '-f', filename,
+        file_temp = cli_mock.create_file(self.ctrl_file)
+        self.run_cmd(argv=['atest', 'job', 'create', '-f', file_temp.name,
                            'test_job0', '-m', 'host0,host1', '-b', 'label1',
                            '--ignore_site_file'],
                      rpcs=[('get_hosts', {'multiple_labels': ['label1']}, True,
@@ -928,6 +941,7 @@
                             ('create_job', data, True, 42)],
                      out_words_ok=['test_job0', 'Created'],
                      out_words_no=['Uploading', 'Done'])
+        file_temp.clean()
 
 
     def _test_parse_hosts(self, args, exp_hosts=[], exp_meta_hosts=[]):
diff --git a/cli/topic_common_unittest.py b/cli/topic_common_unittest.py
index 7d79e7f..1021f80 100755
--- a/cli/topic_common_unittest.py
+++ b/cli/topic_common_unittest.py
@@ -4,7 +4,7 @@
 
 """Test for atest."""
 
-import unittest, os, sys, tempfile, StringIO, urllib2
+import unittest, os, sys, StringIO, urllib2
 
 import common
 from autotest_lib.cli import cli_mock, topic_common, rpc
@@ -97,58 +97,67 @@
 
     def test_file_list_empty_file(self):
         class opt(object):
-            flist = cli_mock.create_file('')
+            flist_obj = cli_mock.create_file('')
+            flist = flist_obj.name
         self.__test_parsing_flist_bad(opt())
 
 
     def test_file_list_ok(self):
         class opt(object):
-            flist = cli_mock.create_file('a\nb\nc\n')
+            flist_obj = cli_mock.create_file('a\nb\nc\n')
+            flist = flist_obj.name
         self.__test_parsing_flist_good(opt(), ['a', 'b', 'c'])
 
 
     def test_file_list_one_line_space(self):
         class opt(object):
-            flist = cli_mock.create_file('a b c\nd e\nf\n')
+            flist_obj = cli_mock.create_file('a b c\nd e\nf\n')
+            flist = flist_obj.name
         self.__test_parsing_flist_good(opt(), ['a', 'b', 'c', 'd', 'e', 'f'])
 
 
     def test_file_list_one_line_comma(self):
         class opt(object):
-            flist = cli_mock.create_file('a,b,c\nd,e\nf\n')
+            flist_obj = cli_mock.create_file('a,b,c\nd,e\nf\n')
+            flist = flist_obj.name
         self.__test_parsing_flist_good(opt(), ['a', 'b', 'c', 'd', 'e', 'f'])
 
 
     def test_file_list_one_line_mix(self):
         class opt(object):
-            flist = cli_mock.create_file('a,b c\nd,e\nf\ng h,i')
+            flist_obj = cli_mock.create_file('a,b c\nd,e\nf\ng h,i')
+            flist = flist_obj.name
         self.__test_parsing_flist_good(opt(), ['a', 'b', 'c', 'd', 'e',
                                          'f', 'g', 'h', 'i'])
 
 
     def test_file_list_one_line_comma_space(self):
         class opt(object):
-            flist = cli_mock.create_file('a, b c\nd,e\nf\ng h,i')
+            flist_obj = cli_mock.create_file('a, b c\nd,e\nf\ng h,i')
+            flist = flist_obj.name
         self.__test_parsing_flist_good(opt(), ['a', 'b', 'c', 'd', 'e',
                                          'f', 'g', 'h', 'i'])
 
 
     def test_file_list_line_end_comma_space(self):
         class opt(object):
-            flist = cli_mock.create_file('a, b c\nd,e, \nf,\ng h,i ,')
+            flist_obj = cli_mock.create_file('a, b c\nd,e, \nf,\ng h,i ,')
+            flist = flist_obj.name
         self.__test_parsing_flist_good(opt(), ['a', 'b', 'c', 'd', 'e',
                                          'f', 'g', 'h', 'i'])
 
 
     def test_file_list_no_eof(self):
         class opt(object):
-            flist = cli_mock.create_file('a\nb\nc')
+            flist_obj = cli_mock.create_file('a\nb\nc')
+            flist = flist_obj.name
         self.__test_parsing_flist_good(opt(), ['a', 'b', 'c'])
 
 
     def test_file_list_blank_line(self):
         class opt(object):
-            flist = cli_mock.create_file('\na\nb\n\nc\n')
+            flist_obj = cli_mock.create_file('\na\nb\n\nc\n')
+            flist = flist_obj.name
         self.__test_parsing_flist_good(opt(), ['a', 'b', 'c'])
 
 
@@ -204,7 +213,8 @@
 
     def test_file_list_all_opt(self):
         class opt(object):
-            flist = cli_mock.create_file('f\ng\nh\n')
+            flist_obj = cli_mock.create_file('f\ng\nh\n')
+            flist = flist_obj.name
             inline = 'a b,c,d e'
         self.__test_parsing_all_good(opt(), ['i', 'j'],
                                      ['a', 'b', 'c', 'd', 'e',
@@ -213,14 +223,16 @@
 
     def test_file_list_all_opt_empty_file(self):
         class opt(object):
-            flist = cli_mock.create_file('')
+            flist_obj = cli_mock.create_file('')
+            flist = flist_obj.name
             inline = 'a b,c,d e'
         self.__test_parsing_all_bad(opt(), ['i', 'j'])
 
 
     def test_file_list_all_opt_in_common(self):
         class opt(object):
-            flist = cli_mock.create_file('f\nc\na\n')
+            flist_obj = cli_mock.create_file('f\nc\na\n')
+            flist = flist_obj.name
             inline = 'a b,c,d e'
         self.__test_parsing_all_good(opt(), ['i','j,d'],
                                      ['a', 'b', 'c', 'd', 'e', 'f', 'i', 'j'])
@@ -228,7 +240,8 @@
 
     def test_file_list_all_opt_in_common_space(self):
         class opt(object):
-            flist = cli_mock.create_file('a b c\nd,e\nf\ng')
+            flist_obj = cli_mock.create_file('a b c\nd,e\nf\ng')
+            flist = flist_obj.name
             inline = 'a b,c,d h'
         self.__test_parsing_all_good(opt(), ['i','j,d'],
                                      ['a', 'b', 'c', 'd', 'e',
@@ -237,7 +250,8 @@
 
     def test_file_list_all_opt_in_common_weird(self):
         class opt(object):
-            flist = cli_mock.create_file('a b c\nd,e\nf\ng, \n, ,,')
+            flist_obj = cli_mock.create_file('a b c\nd,e\nf\ng, \n, ,,')
+            flist = flist_obj.name
             inline = 'a b,c,d h, ,  ,,	'
         self.__test_parsing_all_good(opt(), ['i','j,d'],
                                      ['a', 'b', 'c', 'd', 'e',
@@ -385,7 +399,7 @@
     def test_parse_add_on(self):
         flist = cli_mock.create_file('host1\nhost2\nleft2')
         sys.argv = ['atest', '--web', 'fooweb', '--parse',
-                    '--kill-on-failure', 'left1', 'left2', '-M', flist]
+                    '--kill-on-failure', 'left1', 'left2', '-M', flist.name]
         self.atest.parser.add_option('-M', '--mlist', type='string')
         item_info = topic_common.item_parse_info(attribute_name='hosts',
                                                  filename_option='mlist',
@@ -394,7 +408,7 @@
         self.assertEqualNoOrder(self.atest.hosts,
                                 ['left1', 'left2', 'host1', 'host2'])
 
-        self.assertEqual({'mlist': flist,
+        self.assertEqual({'mlist': flist.name,
                           'web_server': 'fooweb',
                           'parse': True,
                           'parse_delim': '|',
@@ -402,12 +416,13 @@
                           'verbose': False,
                           'debug': False}, options)
         self.assertEqual(leftover, [])
+        flist.clean()
 
 
     def test_parse_no_add_on(self):
         flist = cli_mock.create_file('host1\nhost2\nleft2')
         sys.argv = ['atest', '--web', 'fooweb', '--parse', '-g',
-                    '--kill-on-failure', 'left1', 'left2', '-M', flist]
+                    '--kill-on-failure', 'left1', 'left2', '-M', flist.name]
         self.atest.parser.add_option('-M', '--mlist', type='string')
         item_info = topic_common.item_parse_info(attribute_name='hosts',
                                                  filename_option='mlist')
@@ -415,7 +430,7 @@
         self.assertEqualNoOrder(self.atest.hosts,
                                 ['left2', 'host1', 'host2'])
 
-        self.assertEqual({'mlist': flist,
+        self.assertEqual({'mlist': flist.name,
                           'web_server': 'fooweb',
                           'parse': True,
                           'parse_delim': '|',
@@ -423,14 +438,15 @@
                           'verbose': False,
                           'debug': True}, options)
         self.assertEqual(leftover, ['left1', 'left2'])
+        flist.clean()
 
 
     def test_parse_add_on_first(self):
         flist = cli_mock.create_file('host1\nhost2\nleft2')
         ulist = cli_mock.create_file('user1\nuser2\nuser3\n')
-        sys.argv = ['atest', '-g', '--parse', '--ulist', ulist,
+        sys.argv = ['atest', '-g', '--parse', '--ulist', ulist.name,
                     '-u', 'myuser,youruser',
-                    '--kill-on-failure', 'left1', 'left2', '-M', flist]
+                    '--kill-on-failure', 'left1', 'left2', '-M', flist.name]
         self.atest.parser.add_option('-M', '--mlist', type='string')
         self.atest.parser.add_option('-U', '--ulist', type='string')
         self.atest.parser.add_option('-u', '--user', type='string')
@@ -448,8 +464,8 @@
                                 ['user1', 'user2', 'user3',
                                  'myuser', 'youruser'])
 
-        self.assertEqual({'mlist': flist,
-                          'ulist': ulist,
+        self.assertEqual({'mlist': flist.name,
+                          'ulist': ulist.name,
                           'user': 'myuser,youruser',
                           'web_server': None,
                           'parse': True,
@@ -458,14 +474,16 @@
                           'verbose': False,
                           'debug': True}, options)
         self.assertEqual(leftover, [])
+        flist.clean()
+        ulist.clean()
 
 
     def test_parse_add_on_second(self):
         flist = cli_mock.create_file('host1\nhost2\nleft2')
         ulist = cli_mock.create_file('user1\nuser2\nuser3\n')
-        sys.argv = ['atest', '-g', '--parse', '-U', ulist,
+        sys.argv = ['atest', '-g', '--parse', '-U', ulist.name,
                     '-u', 'myuser,youruser',
-                    '--kill-on-failure', 'left1', 'left2', '-M', flist]
+                    '--kill-on-failure', 'left1', 'left2', '-M', flist.name]
         self.atest.parser.add_option('-M', '--mlist', type='string')
         self.atest.parser.add_option('-U', '--ulist', type='string')
         self.atest.parser.add_option('-u', '--user', type='string')
@@ -483,8 +501,8 @@
                                 ['user1', 'user2', 'user3',
                                  'myuser', 'youruser'])
 
-        self.assertEqual({'mlist': flist,
-                          'ulist': ulist,
+        self.assertEqual({'mlist': flist.name,
+                          'ulist': ulist.name,
                           'user': 'myuser,youruser',
                           'web_server': None,
                           'parse': True,
@@ -493,14 +511,16 @@
                           'verbose': False,
                           'debug': True}, options)
         self.assertEqual(leftover, [])
+        flist.clean()
+        ulist.clean()
 
 
     def test_parse_all_opts(self):
         flist = cli_mock.create_file('host1\nhost2\nleft2')
         ulist = cli_mock.create_file('user1\nuser2\nuser3\n')
-        sys.argv = ['atest', '-g', '--parse', '--ulist', ulist,
+        sys.argv = ['atest', '-g', '--parse', '--ulist', ulist.name,
                     '-u', 'myuser,youruser',
-                    '--kill-on-failure', '-M', flist, 'left1', 'left2']
+                    '--kill-on-failure', '-M', flist.name, 'left1', 'left2']
         self.atest.parser.add_option('-M', '--mlist', type='string')
         self.atest.parser.add_option('-U', '--ulist', type='string')
         self.atest.parser.add_option('-u', '--user', type='string')
@@ -517,8 +537,8 @@
                                 ['user1', 'user2', 'user3',
                                  'myuser', 'youruser'])
 
-        self.assertEqual({'mlist': flist,
-                          'ulist': ulist,
+        self.assertEqual({'mlist': flist.name,
+                          'ulist': ulist.name,
                           'user': 'myuser,youruser',
                           'web_server': None,
                           'parse': True,
@@ -527,13 +547,15 @@
                           'verbose': False,
                           'debug': True}, options)
         self.assertEqual(leftover, [])
+        flist.clean()
+        ulist.clean()
 
 
     def test_parse_no_add_on(self):
         flist = cli_mock.create_file('host1\nhost2\nleft2')
         ulist = cli_mock.create_file('user1\nuser2\nuser3\n')
-        sys.argv = ['atest', '-U', ulist,
-                    '--kill-on-failure', '-M', flist]
+        sys.argv = ['atest', '-U', ulist.name,
+                    '--kill-on-failure', '-M', flist.name]
         self.atest.parser.add_option('-M', '--mlist', type='string')
         self.atest.parser.add_option('-U', '--ulist', type='string')
         self.atest.parser.add_option('-u', '--user', type='string')
@@ -549,8 +571,8 @@
         self.assertEqualNoOrder(self.atest.users,
                                 ['user1', 'user2', 'user3'])
 
-        self.assertEqual({'mlist': flist,
-                          'ulist': ulist,
+        self.assertEqual({'mlist': flist.name,
+                          'ulist': ulist.name,
                           'user': None,
                           'web_server': None,
                           'parse': False,
@@ -559,6 +581,8 @@
                           'verbose': False,
                           'debug': False}, options)
         self.assertEqual(leftover, [])
+        flist.clean()
+        ulist.clean()
 
 
     def test_parse_no_flist_add_on(self):
diff --git a/cli/user_unittest.py b/cli/user_unittest.py
index d037a3d..a871b26 100755
--- a/cli/user_unittest.py
+++ b/cli/user_unittest.py
@@ -22,11 +22,12 @@
     def test_parse_with_users(self):
         ul = user.user_list()
         ufile = cli_mock.create_file('user0\nuser3\nuser4\n')
-        sys.argv = ['atest', 'user1', '--ulist', ufile, 'user3']
+        sys.argv = ['atest', 'user1', '--ulist', ufile.name, 'user3']
         (options, leftover) = ul.parse()
         self.assertEqualNoOrder(['user0', 'user1','user3', 'user4'],
                                 ul.users)
         self.assertEqual(leftover, [])
+        ufile.clean()
 
 
     def test_parse_with_acl(self):
@@ -48,7 +49,7 @@
     def test_parse_with_all(self):
         ul = user.user_list()
         ufile = cli_mock.create_file('user0\nuser3\nuser4\n')
-        sys.argv = ['atest', 'user1', '--ulist', ufile, 'user3',
+        sys.argv = ['atest', 'user1', '--ulist', ufile.name, 'user3',
                     '-l', '4', '-a', 'acl0']
         (options, leftover) = ul.parse()
         self.assertEqualNoOrder(['user0', 'user1','user3', 'user4'],
@@ -56,6 +57,7 @@
         self.assertEqual('acl0', ul.acl)
         self.assertEqual('4', ul.access_level)
         self.assertEqual(leftover, [])
+        ufile.clean()
 
 
     def test_execute_list_all(self):
@@ -126,7 +128,8 @@
 
     def test_execute_list_all_with_user_verbose(self):
         ufile = cli_mock.create_file('user0 user1\n')
-        self.run_cmd(argv=['atest', 'user', 'list', '--ulist', ufile, '-v'],
+        self.run_cmd(argv=['atest', 'user', 'list', '--ulist', ufile.name,
+                           '-v'],
                      rpcs=[('get_users', {'login__in': ['user0', 'user1']},
                             True,
                             [{u'access_level': 2,
@@ -136,6 +139,7 @@
                               u'login': u'user1',
                               u'id': 4}])],
                      out_words_ok=['user0', 'user1', '3', '4', '5'])
+        ufile.clean()
 
 
     def test_execute_list_all_with_acl_verbose(self):