Bug 1581224 - convert mach uuid to be compatible with both python2/3 r=Callek

Changes:
- remove `uuid` from the python3 blacklist in `mach`
- enable `test_telemetry.py` for python3
- adjust test outcome expectation for Windows + python3, suspect `mozpack.path` is not filtering Windows path correctly in python3 environment
- switch file read mode between `r` and `rb` depending on version of python

Differential Revision: https://phabricator.services.mozilla.com/D45903

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Edwin Takahashi 2019-10-21 16:33:00 +00:00
Родитель ef95ddd8f6
Коммит 8eb4f8e716
4 изменённых файлов: 30 добавлений и 11 удалений

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

@ -87,7 +87,6 @@ py2commands="
test-info
tps-build
try
uuid
valgrind-test
vendor
visualmetrics

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

@ -10,5 +10,4 @@ skip-if = python == 3
skip-if = python == 3
[test_logger.py]
[test_mach.py]
[test_telemetry.py]
skip-if = python == 3
[test_telemetry.py]

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

@ -5,13 +5,14 @@ from __future__ import absolute_import, print_function
import json
import os
import platform
import subprocess
import sys
import buildconfig
import mozunit
import pytest
from six import text_type
from six import text_type, PY3
from mozboot.bootstrap import update_or_create_build_telemetry_config
@ -30,10 +31,13 @@ def run_mach(tmpdir):
"""
# Use tmpdir as the mozbuild state path, and enable telemetry in
# a machrc there.
update_or_create_build_telemetry_config(text_type(tmpdir.join('machrc')))
if PY3:
update_or_create_build_telemetry_config(str(tmpdir.join('machrc')))
else:
update_or_create_build_telemetry_config(text_type(tmpdir.join('machrc')))
env = dict(os.environ)
env[b'MOZBUILD_STATE_PATH'] = str(tmpdir)
env[b'MACH_TELEMETRY_NO_SUBMIT'] = b'1'
env['MOZBUILD_STATE_PATH'] = str(tmpdir)
env['MACH_TELEMETRY_NO_SUBMIT'] = '1'
# Let whatever mach command we invoke from tests believe it's the main command.
del env['MACH_MAIN_PID']
mach = os.path.join(buildconfig.topsrcdir, 'mach')
@ -47,7 +51,11 @@ def run_mach(tmpdir):
# Load any telemetry data that was written
path = tmpdir.join('telemetry', 'outgoing')
try:
return [json.load(f.open('rb')) for f in path.listdir()]
if PY3:
read_mode = 'r'
else:
read_mode = 'rb'
return [json.load(f.open(read_mode)) for f in path.listdir()]
except EnvironmentError:
print(TELEMETRY_LOAD_ERROR % out, file=sys.stderr)
for p in path.parts(reverse=True):
@ -63,11 +71,18 @@ def test_simple(run_mach, tmpdir):
d = data[0]
assert d['command'] == 'python'
assert d['argv'] == ['-c', 'pass']
client_id_data = json.load(tmpdir.join('telemetry_client_id.json').open('rb'))
if PY3:
read_mode = 'r'
else:
read_mode = 'rb'
client_id_data = json.load(tmpdir.join(
'telemetry_client_id.json').open(read_mode))
assert 'client_id' in client_id_data
assert client_id_data['client_id'] == d['client_id']
@pytest.mark.xfail(platform.system() == "Windows" and PY3,
reason='Windows and Python3 mozpath filtering issues')
def test_path_filtering(run_mach, tmpdir):
srcdir_path = os.path.join(buildconfig.topsrcdir, 'a')
srcdir_path_2 = os.path.join(buildconfig.topsrcdir, 'a/b/c')
@ -93,6 +108,8 @@ def test_path_filtering(run_mach, tmpdir):
assert d['argv'] == expected
@pytest.mark.xfail(platform.system() == "Windows" and PY3,
reason='Windows and Python3 mozpath filtering issues')
def test_path_filtering_in_objdir(run_mach, tmpdir):
srcdir_path = os.path.join(buildconfig.topsrcdir, 'a')
srcdir_path_2 = os.path.join(buildconfig.topsrcdir, 'a/b/c')

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

@ -17,7 +17,7 @@ import pprint
import sys
from datetime import datetime
from six import string_types
from six import string_types, PY3
from voluptuous import (
Any,
Optional,
@ -96,7 +96,11 @@ def get_client_id(state_dir):
import uuid
# uuid4 is random, other uuid types may include identifiers from the local system.
client_id = str(uuid.uuid4())
with open(path, 'wb') as f:
if PY3:
file_mode = 'w'
else:
file_mode = 'wb'
with open(path, file_mode) as f:
json.dump({'client_id': client_id}, f)
return client_id