def test_classic_with_conflicting_build_id(self): # TODO find a faster test to verify LP: #1736861 if os.environ.get("ADT_TEST") and self.deb_arch == "armhf": self.skipTest("The autopkgtest armhf runners can't install snaps") self.copy_project_to_cwd("go-gotty") if os_release.get_version_codename() != "xenial": snapcraft_yaml_file = "snapcraft.yaml" with open(snapcraft_yaml_file) as f: snapcraft_yaml = yaml.load(f) snapcraft_yaml["parts"]["gotty"]["stage-packages"] = ["libc6"] with open(snapcraft_yaml_file, "w") as f: yaml.dump(snapcraft_yaml, f) self.run_snapcraft("prime") bin_path = os.path.join(self.prime_dir, "bin", "gotty") self.assertThat(bin_path, FileExists()) interpreter = subprocess.check_output( [self.patchelf_command, "--print-interpreter", bin_path]).decode() # On anything greater than xenial we will have a libc6 discrepancy if os_release.get_version_codename() == "xenial": expected_interpreter = r"^/snap/core/current/.*" else: expected_interpreter = r"^/snap/gotty/current/.*" self.assertThat(interpreter, MatchesRegex(expected_interpreter))
def test_classic_with_conflicting_build_id(self): # TODO find a faster test to verify LP: #1736861 if os.environ.get('ADT_TEST') and self.deb_arch == 'armhf': self.skipTest("The autopkgtest armhf runners can't install snaps") self.copy_project_to_cwd('go-gotty') if os_release.get_version_codename() != 'xenial': snapcraft_yaml_file = 'snapcraft.yaml' with open(snapcraft_yaml_file) as f: snapcraft_yaml = yaml.load(f) snapcraft_yaml['parts']['gotty']['stage-packages'] = ['libc6'] with open(snapcraft_yaml_file, 'w') as f: yaml.dump(snapcraft_yaml, f) self.run_snapcraft('prime') bin_path = os.path.join(self.prime_dir, 'bin', 'gotty') self.assertThat(bin_path, FileExists()) interpreter = subprocess.check_output( [self.patchelf_command, '--print-interpreter', bin_path]).decode() # On anything greater than xenial we will have a libc6 discrepancy if os_release.get_version_codename() == 'xenial': expected_interpreter = r'^/snap/core/current/.*' else: expected_interpreter = r'^/snap/gotty/current/.*' self.assertThat(interpreter, MatchesRegex(expected_interpreter))
def assert_review_passes(self, snap_file: str) -> None: # See https://forum.snapcraft.io/t/7339 for more info on why review verification # is skipped on non xenial environments. if os_release.get_version_codename() != "xenial": return # review-tools do not really have access to tmp, let's assume it can look # in its own snap directory and that that does not change as we cannot # query what the data store is for a given snap. review_tools_common_dir = os.path.expanduser( os.path.join("~", "snap", "review-tools", "common") ) os.makedirs(review_tools_common_dir, exist_ok=True) with tempfile.NamedTemporaryFile(dir=review_tools_common_dir) as temp_snap_file: shutil.copyfile(snap_file, temp_snap_file.name) try: subprocess.check_output( ["review-tools.snap-review", temp_snap_file.name] ) except subprocess.CalledProcessError as call_error: self.fail( "{!r} does not pass the review:\n{}".format( snap_file, call_error.stdout.decode() ) )
def _wrap(func: Callable[..., None]) -> Callable[..., None]: actual_codename = os_release.get_version_codename() @functools.wraps(func) @skipUnless(actual_codename in codename, message) def _skip_test(*args: Any, **kwargs: Any) -> None: func(*args, **kwargs) return _skip_test
def _wrap(func: Callable[..., None]) -> Callable[..., None]: actual_codename = os_release.get_version_codename() @functools.wraps(func) @skipUnless(actual_codename == codename, message) def _skip_test(*args: Any, **kwargs: Any) -> None: func(*args, **kwargs) return _skip_test
def test_install_and_execution(self): self.copy_project_to_cwd('python-hello') if os_release.get_version_codename() != 'xenial': integration.add_stage_packages(part_name='python-part', stage_packages=['libc6']) with fixture_setup.WithoutSnapInstalled('python-hello'): self.run_snapcraft() self.install_snap() self.assertThat( subprocess.check_output( ['python-hello'], universal_newlines=True), Equals('Hello world!\n'))
def test_install_and_execution(self): self.copy_project_to_cwd("python-hello") if os_release.get_version_codename() != "xenial": integration.add_stage_packages(part_name="python-part", stage_packages=["libc6"]) with fixture_setup.WithoutSnapInstalled("python-hello"): self.run_snapcraft() self.install_snap() self.assertThat( subprocess.check_output(["python-hello"], universal_newlines=True), Equals("Hello world!\n"), )
def test_install_and_execution(self): self.copy_project_to_cwd("ruby-hello") if os_release.get_version_codename() != "xenial": integration.add_stage_packages( part_name="ruby-part", stage_packages=["libc6"] ) with fixture_setup.WithoutSnapInstalled("ruby-hello"): self.run_snapcraft() self.install_snap() self.assertThat( subprocess.check_output(["ruby-hello"], universal_newlines=True), Equals("Hello world!\n"), )
def setUp(self): super().setUp() self.patchelf_command = "patchelf" self.execstack_command = "execstack" package_type = os.getenv("SNAPCRAFT_PACKAGE_TYPE") if package_type == "snap": self.snapcraft_command = "/snap/bin/snapcraft" self.patchelf_command = "/snap/snapcraft/current/usr/bin/patchelf" self.execstack_command = "/snap/snapcraft/current/usr/sbin/execstack" elif package_type == "deb": self.snapcraft_command = "/usr/bin/snapcraft" self.snapcraft_parser_command = "/usr/bin/snapcraft-parser" elif os.getenv("VIRTUAL_ENV") and sys.platform == "win32": self.snapcraft_command = ["python", "-m", "snapcraft.cli.__main__"] self.snapcraft_parser_command = os.path.join( os.getenv("VIRTUAL_ENV"), "bin", "snapcraft-parser") elif os.getenv("VIRTUAL_ENV"): self.snapcraft_command = os.path.join(os.getenv("VIRTUAL_ENV"), "bin", "snapcraft") self.snapcraft_parser_command = os.path.join( os.getenv("VIRTUAL_ENV"), "bin", "snapcraft-parser") elif package_type == "brew": self.snapcraft_command = "/usr/local/bin/snapcraft" else: raise EnvironmentError( "snapcraft is not setup correctly for testing. Either set " "SNAPCRAFT_PACKAGE_TYPE to 'snap', 'deb' or 'brew', to run from " "either the snap, deb or homebrew or make sure your venv is properly " "setup as described in HACKING.md.") 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 # Use a separate path for XDG dirs, or changes there may be detected as # source changes. self.xdg_path = self.useFixture(fixtures.TempDir()).path self.useFixture(fixture_setup.TempXDG(self.xdg_path)) # Use this host to run through the lifecycle tests self.useFixture( fixtures.EnvironmentVariable("SNAPCRAFT_BUILD_ENVIRONMENT", "host")) # Use a dumb terminal for tests self.useFixture(fixtures.EnvironmentVariable("TERM", "dumb")) # Disable Sentry reporting for tests, otherwise they'll hang waiting # for input self.useFixture( fixtures.EnvironmentVariable("SNAPCRAFT_ENABLE_ERROR_REPORTING", "false")) # Don't let the managed host variable leak into tests self.useFixture(fixtures.EnvironmentVariable("SNAPCRAFT_MANAGED_HOST")) # 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 = platform.get_deb_arch() self.arch_triplet = platform.get_arch_triplet() self.distro_series = os_release.get_version_codename()
def setUp(self): super().setUp() if os.getenv("SNAPCRAFT_FROM_SNAP", False): self.snapcraft_command = "/snap/bin/snapcraft" elif os.getenv("SNAPCRAFT_FROM_DEB", False): self.snapcraft_command = "/usr/bin/snapcraft" self.snapcraft_parser_command = "/usr/bin/snapcraft-parser" elif os.getenv("VIRTUAL_ENV") and sys.platform == "win32": self.snapcraft_command = ["python", "-m", "snapcraft.cli.__main__"] self.snapcraft_parser_command = os.path.join( os.getenv("VIRTUAL_ENV"), "bin", "snapcraft-parser") elif os.getenv("VIRTUAL_ENV"): self.snapcraft_command = os.path.join(os.getenv("VIRTUAL_ENV"), "bin", "snapcraft") self.snapcraft_parser_command = os.path.join( os.getenv("VIRTUAL_ENV"), "bin", "snapcraft-parser") elif os.getenv("SNAPCRAFT_FROM_BREW", False): self.snapcraft_command = "/usr/local/bin/snapcraft" else: raise EnvironmentError( "snapcraft is not setup correctly for testing. Either set " "SNAPCRAFT_FROM_SNAP, SNAPCRAFT_FROM_DEB or " "SNAPCRAFT_FROM_BREW to run from either the snap, deb or " "brew, or make sure your venv is properly setup as described " "in HACKING.md.") if os.getenv("SNAPCRAFT_FROM_SNAP", False): self.patchelf_command = "/snap/snapcraft/current/usr/bin/patchelf" self.execstack_command = "/snap/snapcraft/current/usr/sbin/execstack" else: self.patchelf_command = "patchelf" self.execstack_command = "execstack" 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 # Use a separate path for XDG dirs, or changes there may be detected as # source changes. self.xdg_path = self.useFixture(fixtures.TempDir()).path self.useFixture(fixture_setup.TempXDG(self.xdg_path)) # Use a dumb terminal for tests self.useFixture(fixtures.EnvironmentVariable("TERM", "dumb")) # Disable Sentry reporting for tests, otherwise they'll hang waiting # for input self.useFixture( fixtures.EnvironmentVariable("SNAPCRAFT_ENABLE_SENTRY", "false")) # 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 = platform.get_deb_arch() self.arch_triplet = platform.get_arch_triplet() self.distro_series = os_release.get_version_codename()
def setUp(self): super().setUp() if os.getenv('SNAPCRAFT_FROM_SNAP', False): self.snapcraft_command = '/snap/bin/snapcraft' elif os.getenv('SNAPCRAFT_FROM_DEB', False): self.snapcraft_command = '/usr/bin/snapcraft' self.snapcraft_parser_command = '/usr/bin/snapcraft-parser' elif os.getenv('VIRTUAL_ENV') and sys.platform == 'win32': self.snapcraft_command = ['python', '-m', 'snapcraft.cli.__main__'] self.snapcraft_parser_command = os.path.join( os.getenv('VIRTUAL_ENV'), 'bin', 'snapcraft-parser') elif os.getenv('VIRTUAL_ENV'): self.snapcraft_command = os.path.join(os.getenv('VIRTUAL_ENV'), 'bin', 'snapcraft') self.snapcraft_parser_command = os.path.join( os.getenv('VIRTUAL_ENV'), 'bin', 'snapcraft-parser') elif os.getenv('SNAPCRAFT_FROM_BREW', False): self.snapcraft_command = '/usr/local/bin/snapcraft' else: raise EnvironmentError( 'snapcraft is not setup correctly for testing. Either set ' 'SNAPCRAFT_FROM_SNAP, SNAPCRAFT_FROM_DEB or ' 'SNAPCRAFT_FROM_BREW to run from either the snap, deb or ' 'brew, or make sure your venv is properly setup as described ' 'in HACKING.md.') if os.getenv('SNAPCRAFT_FROM_SNAP', False): self.patchelf_command = '/snap/snapcraft/current/usr/bin/patchelf' self.execstack_command = ( '/snap/snapcraft/current/usr/sbin/execstack') else: self.patchelf_command = 'patchelf' self.execstack_command = 'execstack' 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_DATA_HOME', os.path.join(self.path, 'data'))) self.useFixture(fixtures.EnvironmentVariable('TERM', 'dumb')) # Disable Sentry reporting for tests, otherwise they'll hang waiting # for input self.useFixture( fixtures.EnvironmentVariable('SNAPCRAFT_ENABLE_SENTRY', 'false')) 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_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 = platform.get_deb_arch() self.arch_triplet = platform.get_arch_triplet() self.distro_series = os_release.get_version_codename()
def setUp(self): super().setUp() if os.getenv("SNAPCRAFT_FROM_SNAP", False): self.snapcraft_command = "/snap/bin/snapcraft" elif os.getenv("SNAPCRAFT_FROM_DEB", False): self.snapcraft_command = "/usr/bin/snapcraft" self.snapcraft_parser_command = "/usr/bin/snapcraft-parser" elif os.getenv("VIRTUAL_ENV") and sys.platform == "win32": self.snapcraft_command = ["python", "-m", "snapcraft.cli.__main__"] self.snapcraft_parser_command = os.path.join( os.getenv("VIRTUAL_ENV"), "bin", "snapcraft-parser" ) elif os.getenv("VIRTUAL_ENV"): self.snapcraft_command = os.path.join( os.getenv("VIRTUAL_ENV"), "bin", "snapcraft" ) self.snapcraft_parser_command = os.path.join( os.getenv("VIRTUAL_ENV"), "bin", "snapcraft-parser" ) elif os.getenv("SNAPCRAFT_FROM_BREW", False): self.snapcraft_command = "/usr/local/bin/snapcraft" else: raise EnvironmentError( "snapcraft is not setup correctly for testing. Either set " "SNAPCRAFT_FROM_SNAP, SNAPCRAFT_FROM_DEB or " "SNAPCRAFT_FROM_BREW to run from either the snap, deb or " "brew, or make sure your venv is properly setup as described " "in HACKING.md." ) if os.getenv("SNAPCRAFT_FROM_SNAP", False): self.patchelf_command = "/snap/snapcraft/current/usr/bin/patchelf" self.execstack_command = "/snap/snapcraft/current/usr/sbin/execstack" else: self.patchelf_command = "patchelf" self.execstack_command = "execstack" 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 # Use a separate path for XDG dirs, or changes there may be detected as # source changes. self.xdg_path = self.useFixture(fixtures.TempDir()).path self.useFixture(fixture_setup.TempXDG(self.xdg_path)) # Use a dumb terminal for tests self.useFixture(fixtures.EnvironmentVariable("TERM", "dumb")) # Disable Sentry reporting for tests, otherwise they'll hang waiting # for input self.useFixture( fixtures.EnvironmentVariable("SNAPCRAFT_ENABLE_SENTRY", "false") ) # 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 = platform.get_deb_arch() self.arch_triplet = platform.get_arch_triplet() self.distro_series = os_release.get_version_codename()