def test_os_release_with_blank_lines(self): with open('os-release', 'w') as release_file: print(dedent("""\ NAME="Arch Linux" PRETTY_NAME="Arch Linux" ID=arch ID_LIKE=archlinux ANSI_COLOR="0;36" HOME_URL="https://www.archlinux.org/" SUPPORT_URL="https://bbs.archlinux.org/" BUG_REPORT_URL="https://bugs.archlinux.org/" """), file=release_file) release_info = common.get_os_release_info(os_release_file='os-release') expected_release_info = dict( NAME='Arch Linux', PRETTY_NAME='Arch Linux', ID='arch', ID_LIKE='archlinux', ANSI_COLOR='0;36', HOME_URL='https://www.archlinux.org/', SUPPORT_URL='https://bbs.archlinux.org/', BUG_REPORT_URL='https://bugs.archlinux.org/', ) self.assertThat(release_info, Equals(expected_release_info))
class SharedROSTestCase(snaps_tests.SnapsTestCase): snap_content_dir = 'shared-ros' @skipUnless(get_os_release_info()['VERSION_CODENAME'] == 'xenial', 'This test fails on yakkety LP: #1614476') def test_shared_ros(self): ros_base_path = os.path.join(self.snap_content_dir, 'ros-base') ros_app_path = os.path.join(self.snap_content_dir, 'ros-app') base_snap_path = self.build_snap(ros_base_path, timeout=1800) # Now tar up its staging area to be used to build ros-app subprocess.check_call([ 'tar', 'czf', os.path.join(ros_app_path, 'ros-base.tar.bz2'), '-C', os.path.dirname(base_snap_path), 'stage'], cwd=self.src_dir) # Now build ros-app app_snap_path = self.build_snap(ros_app_path, timeout=1800) # Install both snaps self.install_snap(base_snap_path, 'ros-base', '1.0') self.install_snap(app_snap_path, 'ros-app', '1.0') # Connect the content sharing interface self.run_command_in_snappy_testbed( 'sudo snap connect ros-app:ros-base ros-base:ros-base') # Run the ROS system. By default this will never exit, but the demo # supports an `exit-after-receive` parameter that, if true, will cause # the system to shutdown after the listener has successfully received # a message. self.assert_command_in_snappy_testbed_with_regex([ '/snap/bin/ros-app.launch-project', 'exit-after-receive:=true'], r'.*I heard Hello world.*', re.DOTALL)
def setUp(self): super().setUp() if os.getenv('SNAPCRAFT_FROM_INSTALLED', False): self.snapcraft_command = 'snapcraft' self.snapcraft_parser_command = 'snapcraft-parser' else: self.snapcraft_command = os.path.join(os.getcwd(), 'bin', 'snapcraft') self.snapcraft_parser_command = os.path.join( os.getcwd(), 'bin', 'snapcraft-parser') self.snaps_dir = os.path.join(os.path.dirname(__file__), 'snaps') temp_cwd_fixture = fixture_setup.TempCWD() self.useFixture(temp_cwd_fixture) self.path = temp_cwd_fixture.path self.useFixture( fixtures.EnvironmentVariable('XDG_CONFIG_HOME', os.path.join(self.path, '.config'))) self.useFixture( fixtures.EnvironmentVariable('XDG_CACHE_HOME', os.path.join(self.path, '.cache'))) self.useFixture( fixtures.EnvironmentVariable('XDG_DATA_HOME', os.path.join(self.path, 'data'))) self.useFixture(fixtures.EnvironmentVariable('TERM', 'dumb')) patcher = mock.patch('xdg.BaseDirectory.xdg_config_home', new=os.path.join(self.path, '.config')) patcher.start() self.addCleanup(patcher.stop) patcher = mock.patch('xdg.BaseDirectory.xdg_data_home', new=os.path.join(self.path, 'data')) patcher.start() self.addCleanup(patcher.stop) patcher = mock.patch('xdg.BaseDirectory.xdg_cache_home', new=os.path.join(self.path, '.cache')) patcher.start() self.addCleanup(patcher.stop) patcher_dirs = mock.patch('xdg.BaseDirectory.xdg_config_dirs', new=[xdg.BaseDirectory.xdg_config_home]) patcher_dirs.start() self.addCleanup(patcher_dirs.stop) patcher_dirs = mock.patch('xdg.BaseDirectory.xdg_data_dirs', new=[xdg.BaseDirectory.xdg_data_home]) patcher_dirs.start() self.addCleanup(patcher_dirs.stop) # Note that these directories won't exist when the test starts, # they might be created after calling the snapcraft command on the # project dir. self.parts_dir = 'parts' self.stage_dir = 'stage' self.prime_dir = 'prime' self.deb_arch = _ProjectOptions().deb_arch self.distro_series = get_os_release_info()['VERSION_CODENAME']
def _get_repo_for_platform(): distro = get_os_release_info()['ID'] if _is_deb_based(distro): from ._deb import Ubuntu return Ubuntu else: from ._base import DummyRepo return DummyRepo
def _collected_sources_list(self): if self._use_geoip or self._sources_list: release = common.get_os_release_info()['VERSION_CODENAME'] return _format_sources_list( self._sources_list, deb_arch=self._deb_arch, use_geoip=self._use_geoip, release=release) return _get_local_sources_list()
def _collected_sources_list(self): if self._use_geoip or self._sources_list: release = common.get_os_release_info()['VERSION_CODENAME'] return _format_sources_list(self._sources_list, deb_arch=self._deb_arch, use_geoip=self._use_geoip, release=release) return _get_local_sources_list()
def message(self): message = 'The package {!r} was not found.'.format(self.package_name) # If the package was multiarch, try to help. distro = get_os_release_info()['ID'] if _is_deb_based(distro) and ':' in self.package_name: (name, arch) = self.package_name.split(':', 2) if arch: message += ( '\nYou may need to add support for this architecture with ' "'dpkg --add-architecture {}'.".format(arch)) return message
def message(self): message = 'The package {!r} was not found.'.format( self.package_name) # If the package was multiarch, try to help. distro = get_os_release_info()['ID'] if _is_deb_based(distro) and ':' in self.package_name: (name, arch) = self.package_name.split(':', 2) if arch: message += ( '\nYou may need to add support for this architecture with ' "'dpkg --add-architecture {}'.".format(arch)) return message
class CatkinTestCase(integration_tests.SnapdIntegrationTestCase): @skipUnless(get_os_release_info().get('VERSION_CODENAME') == 'xenial', 'ROS Kinetic only targets Ubuntu Xenial') def test_catkin_pip_support(self): with fixture_setup.WithoutSnapInstalled('ros-pip-example'): self.run_snapcraft(project_dir='ros-pip') self.install_snap() # If pip support didn't work properly, the import should fail. self.assertThat( subprocess.check_output(['ros-pip-example.launch-project'], universal_newlines=True, stderr=subprocess.STDOUT), Contains("Local timezone:"))
def _get_system_libs(): global _libraries if _libraries: return _libraries release = common.get_os_release_info()['VERSION_ID'] lib_path = os.path.join(common.get_librariesdir(), release) if not os.path.exists(lib_path): logger.debug('No libraries to exclude from this release') # Always exclude libc.so.6 return frozenset(['libc.so.6']) with open(lib_path) as fn: _libraries = frozenset(fn.read().split()) return _libraries
class RosinstallTestCase(snaps_tests.SnapsTestCase): snap_content_dir = 'rosinstall' @skipUnless(get_os_release_info()['VERSION_CODENAME'] == 'xenial', 'This test fails on yakkety LP: #1614476') def test_rosinstall(self): snap_path = self.build_snap(self.snap_content_dir, timeout=1800) self.install_snap(snap_path, 'rosinstall-demo', '1.0') # Run the ROS system. By default this will never exit, but the demo # supports an `exit-after-receive` parameter that, if true, will cause # the system to shutdown after the listener has successfully received # a message. self.assert_command_in_snappy_testbed_with_regex( ['/snap/bin/rosinstall-demo.run', 'exit-after-receive:=true'], r'.*I heard hello world.*', re.DOTALL)
def setUp(self): super().setUp() if os.getenv('SNAPCRAFT_FROM_INSTALLED', False): self.snapcraft_command = 'snapcraft' self.snapcraft_parser_command = 'snapcraft-parser' else: self.snapcraft_command = os.path.join( os.getcwd(), 'bin', 'snapcraft') self.snapcraft_parser_command = os.path.join( os.getcwd(), 'bin', 'snapcraft-parser') self.snaps_dir = os.path.join(os.path.dirname(__file__), 'snaps') temp_cwd_fixture = fixture_setup.TempCWD() self.useFixture(temp_cwd_fixture) self.path = temp_cwd_fixture.path self.useFixture(fixtures.EnvironmentVariable( 'XDG_CONFIG_HOME', os.path.join(self.path, '.config'))) self.useFixture(fixtures.EnvironmentVariable( 'XDG_CACHE_HOME', os.path.join(self.path, '.cache'))) self.useFixture(fixtures.EnvironmentVariable( 'XDG_DATA_HOME', os.path.join(self.path, 'data'))) self.useFixture(fixtures.EnvironmentVariable('TERM', 'dumb')) patcher = mock.patch( 'xdg.BaseDirectory.xdg_config_home', new=os.path.join(self.path, '.config')) patcher.start() self.addCleanup(patcher.stop) patcher = mock.patch( 'xdg.BaseDirectory.xdg_data_home', new=os.path.join(self.path, 'data')) patcher.start() self.addCleanup(patcher.stop) patcher = mock.patch( 'xdg.BaseDirectory.xdg_cache_home', new=os.path.join(self.path, '.cache')) patcher.start() self.addCleanup(patcher.stop) patcher_dirs = mock.patch( 'xdg.BaseDirectory.xdg_config_dirs', new=[xdg.BaseDirectory.xdg_config_home]) patcher_dirs.start() self.addCleanup(patcher_dirs.stop) patcher_dirs = mock.patch( 'xdg.BaseDirectory.xdg_data_dirs', new=[xdg.BaseDirectory.xdg_data_home]) patcher_dirs.start() self.addCleanup(patcher_dirs.stop) # Note that these directories won't exist when the test starts, # they might be created after calling the snapcraft command on the # project dir. self.parts_dir = 'parts' self.stage_dir = 'stage' self.prime_dir = 'prime' self.deb_arch = _ProjectOptions().deb_arch self.distro_series = get_os_release_info()['VERSION_CODENAME']
def _is_deb_based(distro=None): if not distro: distro = get_os_release_info()['ID'] return distro in _DEB_BASED_PLATFORM
def __init__(self): super().__init__(distro=get_os_release_info()['NAME'])