mirror of
https://pagure.io/fm-orchestrator.git
synced 2026-04-05 03:38:12 +08:00
fix unicode/str/bytes inconsistencies
This commit is contained in:
@@ -202,7 +202,7 @@ class KojiContentGenerator(object):
|
||||
|
||||
(stdout, stderr) = p.communicate()
|
||||
status = p.wait()
|
||||
output = stdout
|
||||
output = stdout.decode("utf-8")
|
||||
|
||||
if status != 0:
|
||||
log.debug("%s: stderr output: %s", cmd, stderr)
|
||||
@@ -710,7 +710,7 @@ class KojiContentGenerator(object):
|
||||
# Fill in the list of built RPMs.
|
||||
mmd = self._fill_in_rpms_list(mmd, arch)
|
||||
|
||||
return unicode(mmd.dumps())
|
||||
return text_type(mmd.dumps())
|
||||
|
||||
def _download_source_modulemd(self, mmd, output_path):
|
||||
"""
|
||||
|
||||
@@ -115,7 +115,7 @@ def generate_koji_tag(name, stream, version, context, max_length=256):
|
||||
if len(nsvc_tag) + len('-build') > max_length:
|
||||
# Fallback to the old format of 'module-<hash>' if the generated koji tag
|
||||
# name is longer than max_length
|
||||
nsvc_hash = hashlib.sha1('.'.join(nsvc_list)).hexdigest()[:16]
|
||||
nsvc_hash = hashlib.sha1('.'.join(nsvc_list).encode('utf-8')).hexdigest()[:16]
|
||||
return 'module-' + nsvc_hash
|
||||
return nsvc_tag
|
||||
|
||||
|
||||
@@ -371,7 +371,7 @@ def record_component_builds(mmd, module, initial_batch=1,
|
||||
|
||||
def submit_module_build_from_yaml(username, handle, stream=None, skiptests=False,
|
||||
optional_params=None):
|
||||
yaml_file = handle.read()
|
||||
yaml_file = handle.read().decode("utf-8")
|
||||
mmd = load_mmd(yaml_file)
|
||||
dt = datetime.utcfromtimestamp(int(time.time()))
|
||||
def_name = str(os.path.splitext(os.path.basename(handle.filename))[0])
|
||||
|
||||
@@ -145,13 +145,14 @@ def _populate_data(session, data_size=10, contexts=False):
|
||||
build_one.state = BUILD_STATES['ready']
|
||||
if contexts:
|
||||
build_one.stream = str(index)
|
||||
unique_hash = hashlib.sha1("%s:%s:%d:%d" % (
|
||||
build_one.name, build_one.stream, build_one.version, context)).hexdigest()
|
||||
unique_hash = hashlib.sha1(("%s:%s:%d:%d" % (
|
||||
build_one.name, build_one.stream, build_one.version,
|
||||
context)).encode("utf-8")).hexdigest()
|
||||
build_one.build_context = unique_hash
|
||||
build_one.runtime_context = unique_hash
|
||||
build_one.ref_build_context = unique_hash
|
||||
combined_hashes = '{0}:{1}'.format(unique_hash, unique_hash)
|
||||
build_one.context = hashlib.sha1(combined_hashes).hexdigest()[:8]
|
||||
build_one.context = hashlib.sha1(combined_hashes.encode("utf-8")).hexdigest()[:8]
|
||||
with open(os.path.join(base_dir, "staged_data", "nginx_mmd.yaml")) as mmd:
|
||||
build_one.modulemd = mmd.read()
|
||||
build_one.koji_tag = 'module-nginx-1.2'
|
||||
|
||||
@@ -107,8 +107,8 @@ class TestBuild:
|
||||
pkg_res.return_value = Mock()
|
||||
pkg_res.return_value.version = "current-tested-version"
|
||||
rpm_mock = Mock()
|
||||
rpm_out = "rpm-name;1.0;r1;x86_64;(none);sigmd5:1;sigpgp:p;siggpg:g\n" \
|
||||
"rpm-name-2;2.0;r2;i686;1;sigmd5:2;sigpgp:p2;siggpg:g2"
|
||||
rpm_out = b"rpm-name;1.0;r1;x86_64;(none);sigmd5:1;sigpgp:p;siggpg:g\n" \
|
||||
b"rpm-name-2;2.0;r2;i686;1;sigmd5:2;sigpgp:p2;siggpg:g2"
|
||||
attrs = {'communicate.return_value': (rpm_out, 'error'),
|
||||
'wait.return_value': 0}
|
||||
rpm_mock.configure_mock(**attrs)
|
||||
@@ -163,8 +163,8 @@ class TestBuild:
|
||||
pkg_res.return_value = Mock()
|
||||
pkg_res.return_value.version = "current-tested-version"
|
||||
rpm_mock = Mock()
|
||||
rpm_out = "rpm-name;1.0;r1;x86_64;(none);sigmd5:1;sigpgp:p;siggpg:g\n" \
|
||||
"rpm-name-2;2.0;r2;i686;1;sigmd5:2;sigpgp:p2;siggpg:g2"
|
||||
rpm_out = b"rpm-name;1.0;r1;x86_64;(none);sigmd5:1;sigpgp:p;siggpg:g\n" \
|
||||
b"rpm-name-2;2.0;r2;i686;1;sigmd5:2;sigpgp:p2;siggpg:g2"
|
||||
attrs = {'communicate.return_value': (rpm_out, 'error'),
|
||||
'wait.return_value': 0}
|
||||
rpm_mock.configure_mock(**attrs)
|
||||
@@ -270,7 +270,7 @@ class TestBuild:
|
||||
@patch("module_build_service.builder.KojiContentGenerator.open", create=True)
|
||||
def test_get_arch_mmd_output(self, patched_open):
|
||||
patched_open.return_value = mock_open(
|
||||
read_data=self.cg.mmd).return_value
|
||||
read_data=self.cg.mmd.encode("utf-8")).return_value
|
||||
ret = self.cg._get_arch_mmd_output("./fake-dir", "x86_64")
|
||||
assert ret == {
|
||||
'arch': 'x86_64',
|
||||
@@ -290,7 +290,7 @@ class TestBuild:
|
||||
rpm_artifacts = mmd.get_rpm_artifacts()
|
||||
rpm_artifacts.add("dhcp-libs-12:4.3.5-5.module_2118aef6.x86_64")
|
||||
mmd.set_rpm_artifacts(rpm_artifacts)
|
||||
mmd_data = mmd.dumps()
|
||||
mmd_data = mmd.dumps().encode("utf-8")
|
||||
|
||||
patched_open.return_value = mock_open(
|
||||
read_data=mmd_data).return_value
|
||||
|
||||
@@ -277,7 +277,7 @@ class TestUtilsComponentReuse:
|
||||
with open(modulemd_file_path, "w") as fd:
|
||||
fd.write(modulemd_yaml)
|
||||
|
||||
with open(modulemd_file_path, "r") as fd:
|
||||
with open(modulemd_file_path, "rb") as fd:
|
||||
handle = FileStorage(fd)
|
||||
module_build_service.utils.submit_module_build_from_yaml(username, handle,
|
||||
stream=stream, skiptests=True)
|
||||
|
||||
Reference in New Issue
Block a user