blob: a5eb2da27db5ebff45ece62b0f666282e9a7c898 [file] [log] [blame]
import sh
import unittest
from unittest.mock import MagicMock
from steps import metadata_setup
import inspect
class TestMetadataSetup(unittest.TestCase):
def setUp(self):
self.step = metadata_setup.MetadataSetup()
self.step.append_sources_mirror_urls = MagicMock()
self.step.omit_crashdump = MagicMock()
self.step.replace_downstream_url = MagicMock()
self.step.run_script()
def init_step(self):
self.step.firmware_machine = "machine0"
self.step.metadata_obmc_repo = "repo0"
self.step.metadata_repo = "repo1"
self.step.build_script_dir = "path/to/volume"
self.step.main_repo_name = "repo3"
def test_append_sources_mirror_urls(self):
"""Tests that run_script calls append_sources_mirror_urls"""
self.step.append_sources_mirror_urls.assert_called_with()
def test_omit_crashdump(self):
"""Tests that run_script calls omit_crashdump"""
self.step.omit_crashdump.assert_called_with()
def test_replace_downstream_url(self):
"""Tests that run_script calls replace_downstream_url"""
self.step.replace_downstream_url.assert_called_with()
def test_sh_sh(self):
"""Tests sh.sh executes the the right commands in the right order"""
self.step = metadata_setup.MetadataSetup()
self.init_step()
sh.sh = MagicMock()
self.step.run_script()
actual_calls = sh.sh.call_args_list
call0 = inspect.cleandoc(
f"""
cat << EOT >> build/{self.step.firmware_machine}/conf/local.conf
INHERIT += "own-mirrors"
CONNECTIVITY_CHECK_URIS = ""
BB_NO_NETWORK = "0"
# Allow fetching external mirrors
BB_ALLOWED_NETWORKS = ""
BB_GENERATE_MIRROR_TARBALLS = "1"
SOURCE_MIRROR_URL = "file://{self.step.build_script_dir}/{self.step.main_repo_name}/build/sources"
BB_NUMBER_THREADS = "16"
EOT
""")
call1 = inspect.cleandoc(
f"""
# Omit crashdump and at-scale-debug.
# They are tested in the gBMC version of presubmit.
cat << EOT >> {self.step.metadata_obmc_repo}/{self.step.metadata_repo}/recipes-phosphor/images/obmc-phosphor-image.bbappend
OBMC_IMAGE_EXTRA_INSTALL:remove:{self.step.firmware_machine} = " at-scale-debug"
OBMC_IMAGE_EXTRA_INSTALL:remove:{self.step.firmware_machine} = " crashdump"
EOT
""")
call2 = "find meta* -type f -exec sed -i \
's/\.git\.corp\.google/\.googlesource/;\s/protocol=sso/protocol=https/' {} \;"
expected_calls = [(("-c", call0),), (("-c", call1),), (("-c", call2),)]
self.assertEqual(actual_calls, expected_calls)