Bug 1415858 - Adding logs for Talos cloning step r=jmaher

MozReview-Commit-ID: GVXcCty2nNi

--HG--
extra : rebase_source : 0569448d579e98955951b6a83d3f788bbb55785d
This commit is contained in:
Tarek Ziadé 2017-11-15 10:37:39 +01:00
Родитель 43771ba19d
Коммит 988457f958
3 изменённых файлов: 39 добавлений и 7 удалений

Просмотреть файл

@ -184,16 +184,17 @@ class Profile(object):
break
@classmethod
def clone(cls, path_from, path_to=None, **kwargs):
def clone(cls, path_from, path_to=None, ignore=None, **kwargs):
"""Instantiate a temporary profile via cloning
- path: path of the basis to clone
- ignore: callable passed to shutil.copytree
- kwargs: arguments to the profile constructor
"""
if not path_to:
tempdir = tempfile.mkdtemp() # need an unused temp dir name
mozfile.remove(tempdir) # copytree requires that dest does not exist
path_to = tempdir
copytree(path_from, path_to)
copytree(path_from, path_to, ignore=ignore)
c = cls(path_to, **kwargs)
c.create_new = True # deletes a cloned profile when restore is True

Просмотреть файл

@ -34,14 +34,28 @@ class CloneCleanupTest(unittest.TestCase):
self.assertTrue(os.path.exists(user_js))
def test_restore_true(self):
counter = [0]
def _feedback(dir, content):
# Called by shutil.copytree on each visited directory.
# Used here to display info.
#
# Returns the items that should be ignored by
# shutil.copytree when copying the tree, so always returns
# an empty list.
counter[0] += 1
return []
# make a clone of this profile with restore=True
clone = Profile.clone(self.profile.profile, restore=True)
clone = Profile.clone(self.profile.profile, restore=True,
ignore=_feedback)
self.addCleanup(mozfile.remove, clone.profile)
clone.cleanup()
# clone should be deleted
self.assertFalse(os.path.exists(clone.profile))
self.assertTrue(counter[0] > 0)
def test_restore_false(self):
# make a clone of this profile with restore=False

Просмотреть файл

@ -98,14 +98,30 @@ class FFSetup(object):
path = heavy.download_profile(self.test_config['profile'])
self.test_config['profile_path'] = path
profile = Profile.clone(
os.path.normpath(self.test_config['profile_path']),
self.profile_dir,
restore=False)
profile_path = os.path.normpath(self.test_config['profile_path'])
LOG.info("Cloning profile located at %s" % profile_path)
def _feedback(directory, content):
# Called by shutil.copytree on each visited directory.
# Used here to display info.
#
# Returns the items that should be ignored by
# shutil.copytree when copying the tree, so always returns
# an empty list.
sub = directory.split(profile_path)[-1].lstrip("/")
if sub:
LOG.info("=> %s" % sub)
return []
profile = Profile.clone(profile_path,
self.profile_dir,
ignore=_feedback,
restore=False)
profile.set_preferences(preferences)
# installing addons
LOG.info("Installing Add-ons")
profile.addon_manager.install_addons(extensions)
# installing webextensions
@ -114,6 +130,7 @@ class FFSetup(object):
webextensions = [webextensions]
if webextensions is not None:
LOG.info("Installing Webextensions")
for webext in webextensions:
filename = utils.interpolate(webext)
if mozinfo.os == 'win':