def setup(self) -> None: """Fetch, unpack, and setup rospack.""" # Make sure we can run multiple times without error os.makedirs(self._rospack_install_path, exist_ok=True) # rospack isn't necessarily a dependency of the project, so we'll unpack # it off to the side and use it from there. logger.info("Preparing to fetch rospack...") ubuntu_repo = repo.Ubuntu( self._rospack_path, sources=self._ubuntu_sources, keyrings=self._ubuntu_keyrings, project_options=self._project, ) logger.info("Fetching rospack...") ubuntu_repo.get( [ "ros-{}-rospack".format(self._ros_distro), "ros-{}-catkin".format(self._ros_distro), ] ) logger.info("Installing rospack...") ubuntu_repo.unpack(self._rospack_install_path)
def _ubuntu(self): if not self.__ubuntu: self.__ubuntu = repo.Ubuntu(self._cache_dir, sources=self._sources, project_options=self._project_options) return self.__ubuntu
def setup(self) -> None: """Download/install wstool, and initialize workspace.""" os.makedirs(self._wstool_install_path, exist_ok=True) # wstool isn't a dependency of the project, so we'll unpack it # somewhere else, and use it from there. logger.info("Preparing to fetch wstool...") ubuntu = repo.Ubuntu( self._wstool_path, sources=self._ubuntu_sources, keyrings=self._ubuntu_keyrings, project_options=self._project, ) logger.info("Fetching wstool...") ubuntu.get(["python-wstool"]) logger.info("Installing wstool...") ubuntu.unpack(self._wstool_install_path) logger.info("Initializing workspace (if necessary)...") try: self._run([ "init", self._ros_package_path, "-j{}".format(self._project.parallel_build_count), ]) except subprocess.CalledProcessError as e: output = e.output.decode(sys.getfilesystemencoding()).strip() if "already is a workspace" not in output: stderr = e.stderr.decode(sys.getfilesystemencoding()).strip() raise WorkspaceInitializationError(stderr)
def ubuntu(self): if not self._ubuntu: self._ubuntu = repo.Ubuntu(self.ubuntudir, sources=self.code.PLUGIN_STAGE_SOURCES, project_options=self._project_options) return self._ubuntu
def test_get_package(self, mock_apt_pkg, mock_fetch_binary): fake_package_path = os.path.join(self.path, "fake-package.deb") open(fake_package_path, "w").close() mock_fetch_binary.return_value = fake_package_path self.mock_cache().is_virtual_package.return_value = False fake_trusted_parts_path = os.path.join(self.path, "fake-trusted-parts") os.mkdir(fake_trusted_parts_path) open(os.path.join(fake_trusted_parts_path, "trusted-part.gpg"), "w").close() def _fake_find_file(key: str): if key == "Dir::Etc::TrustedParts": return fake_trusted_parts_path else: return DEFAULT mock_apt_pkg.config.find_file.side_effect = _fake_find_file project_options = snapcraft.ProjectOptions() ubuntu = repo.Ubuntu(self.tempdir, project_options=project_options) ubuntu.get(["fake-package"]) mock_apt_pkg.assert_has_calls( [ call.config.set("Apt::Install-Recommends", "False"), call.config.set("Acquire::AllowInsecureRepositories", "False"), call.config.find_file("Dir::Etc::Trusted"), call.config.set("Dir::Etc::Trusted", ANY), call.config.find_file("Dir::Etc::TrustedParts"), call.config.set("Dir::Etc::TrustedParts", ANY), call.config.clear("APT::Update::Post-Invoke-Success"), ] ) self.mock_cache.assert_has_calls( [ call(memonly=True, rootdir=ANY), call().update(fetch_progress=ANY, sources_list=ANY), call().open(), ] ) # __getitem__ is tricky self.assertThat( self.mock_cache.return_value.__getitem__.call_args_list, Contains(call("fake-package")), ) # Verify that the package was actually fetched and copied into the # requested location. self.assertThat( os.path.join(self.tempdir, "download", "fake-package.deb"), FileExists() ) # Verify that TrustedParts were properly setup trusted_parts_dir = os.path.join( ubuntu._cache.base_dir, os.path.join(self.path, "fake-trusted-parts").lstrip("/"), ) self.assertThat(os.listdir(trusted_parts_dir), Equals(["trusted-part.gpg"]))
def test_get_package(self, mock_apt_pkg): project_options = snapcraft.ProjectOptions(use_geoip=False) ubuntu = repo.Ubuntu(self.tempdir, project_options=project_options) ubuntu.get(['fake-package']) mock_apt_pkg.assert_has_calls([ call.config.set('Apt::Install-Recommends', 'False'), call.config.find_file('Dir::Etc::Trusted'), call.config.set('Dir::Etc::Trusted', ANY), call.config.find_file('Dir::Etc::TrustedParts'), call.config.set('Dir::Etc::TrustedParts', ANY), call.config.clear('APT::Update::Post-Invoke-Success'), ]) self.mock_cache.assert_has_calls([ call(memonly=True, rootdir=ANY), call().update(fetch_progress=ANY, sources_list=ANY), call().open(), ]) # __getitem__ is tricky self.assertThat( self.mock_cache.return_value.__getitem__.call_args_list, Contains(call('fake-package'))) self.mock_package.assert_has_calls( [call.candidate.fetch_binary(ANY, progress=ANY)]) # Verify that the package was actually fetched and copied into the # requested location. self.assertThat( os.path.join(self.tempdir, 'download', 'fake-package.deb'), FileExists())
def test_get_package_fetch_error(self, mock_apt_pkg, mock_fetch_binary): mock_fetch_binary.side_effect = apt.package.FetchError("foo") self.mock_cache().is_virtual_package.return_value = False project_options = snapcraft.ProjectOptions() ubuntu = repo.Ubuntu(self.tempdir, project_options=project_options) raised = self.assertRaises(errors.PackageFetchError, ubuntu.get, ["fake-package"]) self.assertThat(str(raised), Equals("Package fetch error: foo"))
def test_cache_update_failed(self, mock_apt_pkg, mock_fetch_binary): fake_package_path = os.path.join(self.path, "fake-package.deb") open(fake_package_path, "w").close() mock_fetch_binary.return_value = fake_package_path self.mock_cache().is_virtual_package.return_value = False self.mock_cache().update.side_effect = apt.cache.FetchFailedException() project_options = snapcraft.ProjectOptions() ubuntu = repo.Ubuntu(self.tempdir, project_options=project_options) self.assertRaises(errors.CacheUpdateFailedError, ubuntu.get, ["fake-package"])
def test_cache_hashsum_mismatch(self, mock_apt_pkg, mock_rmtree): self.mock_cache().is_virtual_package.return_value = False self.mock_cache().update.side_effect = [ apt.cache.FetchFailedException( "E:Failed to fetch copy:foo Hash Sum mismatch" ), DEFAULT, ] ubuntu = repo.Ubuntu(self.tempdir) ubuntu.get(["fake-package"])
def test_get_package_fetch_error(self, mock_apt_pkg): self.mock_package.candidate.fetch_binary.side_effect = apt.package.FetchError( "foo" ) self.mock_cache().is_virtual_package.return_value = False ubuntu = repo.Ubuntu(self.tempdir) raised = self.assertRaises( errors.PackageFetchError, ubuntu.get, ["fake-package"] ) self.assertThat(str(raised), Equals("Package fetch error: foo"))
def test_autokeep(self): self.fake_apt_cache = fixture_setup.FakeAptCache() self.useFixture(self.fake_apt_cache) self.test_packages = ( "main-package", "dependency", "sub-dependency", "conflicting-dependency", ) self.fake_apt_cache.add_packages(self.test_packages) self.fake_apt_cache.cache["main-package"].dependencies = [ [ fixture_setup.FakeAptBaseDependency( "dependency", [self.fake_apt_cache.cache["dependency"]] ), fixture_setup.FakeAptBaseDependency( "conflicting-dependency", [self.fake_apt_cache.cache["conflicting-dependency"]], ), ] ] self.fake_apt_cache.cache["dependency"].dependencies = [ [ fixture_setup.FakeAptBaseDependency( "sub-dependency", [self.fake_apt_cache.cache["sub-dependency"]] ) ] ] self.fake_apt_cache.cache["conflicting-dependency"].conflicts = [ self.fake_apt_cache.cache["dependency"] ] project_options = snapcraft.ProjectOptions() ubuntu = repo.Ubuntu(self.tempdir, project_options=project_options) ubuntu.get(["main-package", "conflicting-dependency"]) # Verify that the package was actually fetched and copied into the # requested location. self.assertThat( os.path.join(self.tempdir, "download", "main-package.deb"), FileExists() ) self.assertThat( os.path.join(self.tempdir, "download", "conflicting-dependency.deb"), FileExists(), ) self.assertThat( os.path.join(self.tempdir, "download", "dependency.deb"), Not(FileExists()), "Dependency should not have been fetched", ) self.assertThat( os.path.join(self.tempdir, "download", "sub-dependency.deb"), Not(FileExists()), "Sub-dependency should not have been fetched", )
def setup(self): os.makedirs(self._catkin_install_path, exist_ok=True) # With the introduction of an underlay, we no longer know where Catkin # is. Let's just fetch/unpack our own, and use it. logger.info("Preparing to fetch catkin...") ubuntu = repo.Ubuntu(self._catkin_path) logger.info("Fetching catkin...") ubuntu.get(["ros-{}-catkin".format(self._ros_distro)]) logger.info("Installing catkin...") ubuntu.unpack(self._catkin_install_path)
def test_cache_hashsum_mismatch(self, mock_apt_pkg, mock_fetch_binary, mock_rmtree): fake_package_path = os.path.join(self.path, "fake-package.deb") open(fake_package_path, "w").close() mock_fetch_binary.return_value = fake_package_path self.mock_cache().is_virtual_package.return_value = False self.mock_cache().update.side_effect = [ apt.cache.FetchFailedException( "E:Failed to fetch copy:foo Hash Sum mismatch" ), DEFAULT, ] project_options = snapcraft.ProjectOptions() ubuntu = repo.Ubuntu(self.tempdir, project_options=project_options) ubuntu.get(["fake-package"])
def _setup_apt_dependencies(self, apt_dependencies): if apt_dependencies: ubuntudir = os.path.join(self.partdir, "ubuntu") os.makedirs(ubuntudir, exist_ok=True) logger.info("Preparing to fetch apt dependencies...") ubuntu = repo.Ubuntu(ubuntudir) logger.info("Fetching apt dependencies...") try: ubuntu.get(apt_dependencies) except repo.errors.PackageNotFoundError as e: raise ColconAptDependencyFetchError(e.message) logger.info("Installing apt dependencies...") ubuntu.unpack(self.installdir)
def test_get_package_trusted_parts_already_imported(self, mock_apt_pkg): self.mock_cache().is_virtual_package.return_value = False def _fake_find_file(key: str): if key == "Dir::Etc::TrustedParts": return os.path.join(ubuntu._cache.base_dir, "trusted") else: return DEFAULT mock_apt_pkg.config.find_file.side_effect = _fake_find_file ubuntu = repo.Ubuntu(self.tempdir) ubuntu.get(["fake-package"]) mock_apt_pkg.assert_has_calls( [ call.config.set("Apt::Install-Recommends", "False"), call.config.set("Acquire::AllowInsecureRepositories", "False"), call.config.find_file("Dir::Etc::Trusted"), call.config.set("Dir::Etc::Trusted", ANY), call.config.find_file("Dir::Etc::TrustedParts"), call.config.clear("APT::Update::Post-Invoke-Success"), ] ) self.mock_cache.assert_has_calls( [ call(memonly=True, rootdir=ANY), call().update(fetch_progress=ANY, sources_list=ANY), call().open(), ] ) # __getitem__ is tricky self.assertThat( self.mock_cache.return_value.__getitem__.call_args_list, Contains(call("fake-package")), ) # Verify that the package was actually fetched and copied into the # requested location. self.assertThat( os.path.join(self.tempdir, "download", "fake-package.deb"), FileExists() )
def setup(self): # Make sure we can run multiple times without error, while leaving the # capability to re-initialize, by making sure we clear the sources. if os.path.exists(self._rosdep_sources_path): shutil.rmtree(self._rosdep_sources_path) os.makedirs(self._rosdep_sources_path) os.makedirs(self._rosdep_install_path, exist_ok=True) os.makedirs(self._rosdep_cache_path, exist_ok=True) # rosdep isn't necessarily a dependency of the project, so we'll unpack # it off to the side and use it from there. logger.info("Preparing to fetch rosdep...") ubuntu = repo.Ubuntu( self._rosdep_path, sources=self._ubuntu_sources, keyrings=self._ubuntu_keyrings, project_options=self._project, ) logger.info("Fetching rosdep...") ubuntu.get(["python-rosdep"]) logger.info("Installing rosdep...") ubuntu.unpack(self._rosdep_install_path) logger.info("Initializing rosdep database...") try: self._run(["init"]) except subprocess.CalledProcessError as e: output = e.output.decode(sys.getfilesystemencoding()).strip() raise RosdepInitializationError( "Error initializing rosdep database:\n{}".format(output)) logger.info("Updating rosdep database...") try: self._run(["update"]) except subprocess.CalledProcessError as e: output = e.output.decode(sys.getfilesystemencoding()).strip() raise RosdepInitializationError( "Error updating rosdep database:\n{}".format(output))
def test_get_package(self, mock_apt_pkg, mock_fetch_binary): fake_package_path = os.path.join(self.path, "fake-package.deb") open(fake_package_path, "w").close() mock_fetch_binary.return_value = fake_package_path self.mock_cache().is_virtual_package.return_value = False project_options = snapcraft.ProjectOptions(use_geoip=False) ubuntu = repo.Ubuntu(self.tempdir, project_options=project_options) ubuntu.get(["fake-package"]) mock_apt_pkg.assert_has_calls( [ call.config.set("Apt::Install-Recommends", "False"), call.config.find_file("Dir::Etc::Trusted"), call.config.set("Dir::Etc::Trusted", ANY), call.config.find_file("Dir::Etc::TrustedParts"), call.config.set("Dir::Etc::TrustedParts", ANY), call.config.clear("APT::Update::Post-Invoke-Success"), ] ) self.mock_cache.assert_has_calls( [ call(memonly=True, rootdir=ANY), call().update(fetch_progress=ANY, sources_list=ANY), call().open(), ] ) # __getitem__ is tricky self.assertThat( self.mock_cache.return_value.__getitem__.call_args_list, Contains(call("fake-package")), ) # Verify that the package was actually fetched and copied into the # requested location. self.assertThat( os.path.join(self.tempdir, "download", "fake-package.deb"), FileExists() )
def test_autokeep(self): self.fake_apt_cache = fixture_setup.FakeAptCache() self.useFixture(self.fake_apt_cache) self.test_packages = ('main-package', 'dependency', 'sub-dependency', 'conflicting-dependency') self.fake_apt_cache.add_packages(self.test_packages) self.fake_apt_cache.cache['main-package'].dependencies = [[ fixture_setup.FakeAptBaseDependency( 'dependency', [self.fake_apt_cache.cache['dependency']]), fixture_setup.FakeAptBaseDependency( 'conflicting-dependency', [self.fake_apt_cache.cache['conflicting-dependency']]), ]] self.fake_apt_cache.cache['dependency'].dependencies = [[ fixture_setup.FakeAptBaseDependency( 'sub-dependency', [self.fake_apt_cache.cache['sub-dependency']]), ]] self.fake_apt_cache.cache['conflicting-dependency'].conflicts = [ self.fake_apt_cache.cache['dependency'] ] project_options = snapcraft.ProjectOptions() ubuntu = repo.Ubuntu(self.tempdir, project_options=project_options) ubuntu.get(['main-package', 'conflicting-dependency']) # Verify that the package was actually fetched and copied into the # requested location. self.assertThat( os.path.join(self.tempdir, 'download', 'main-package.deb'), FileExists()) self.assertThat( os.path.join(self.tempdir, 'download', 'conflicting-dependency.deb'), FileExists()) self.assertThat( os.path.join(self.tempdir, 'download', 'dependency.deb'), Not(FileExists()), 'Dependency should not have been fetched') self.assertThat( os.path.join(self.tempdir, 'download', 'sub-dependency.deb'), Not(FileExists()), 'Sub-dependency should not have been fetched')
def setup(self) -> None: os.makedirs(self._wstool_install_path, exist_ok=True) # wstool isn't a dependency of the project, so we'll unpack it # somewhere else, and use it from there. logger.info('Preparing to fetch wstool...') ubuntu = repo.Ubuntu(self._wstool_path, sources=self._ubuntu_sources, project_options=self._project) logger.info('Fetching wstool...') ubuntu.get(['python-wstool']) logger.info('Installing wstool...') ubuntu.unpack(self._wstool_install_path) logger.info('Initializing workspace (if necessary)...') try: self._run(['init', self._ros_package_path, '-j{}'.format( self._project.parallel_build_count)]) except subprocess.CalledProcessError as e: output = e.output.decode(sys.getfilesystemencoding()).strip() if 'already is a workspace' not in output: stderr = e.stderr.decode(sys.getfilesystemencoding()).strip() raise WorkspaceInitializationError(stderr)
def test_cache_update_failed(self, mock_apt_pkg): self.mock_cache().is_virtual_package.return_value = False self.mock_cache().update.side_effect = apt.cache.FetchFailedException() ubuntu = repo.Ubuntu(self.tempdir) self.assertRaises(errors.CacheUpdateFailedError, ubuntu.get, ["fake-package"])