def test_manifest_dont_overwrite(tmp_path): """Don't overwrite the already-existing file.""" (tmp_path / 'manifest.yaml').touch() with pytest.raises(CommandError) as cm: create_manifest(tmp_path, datetime.datetime.now()) assert str(cm.value) == ( "Cannot write the manifest as there is already a 'manifest.yaml' in disk." )
def _pack_bundle(self): """Pack a bundle.""" # get the config files bundle_filepath = self.config.project.dirpath / "bundle.yaml" bundle_config = load_yaml(bundle_filepath) if bundle_config is None: raise CommandError( "Missing or invalid main bundle file: '{}'.".format( bundle_filepath)) bundle_name = bundle_config.get("name") if not bundle_name: raise CommandError( "Invalid bundle config; missing a 'name' field indicating the bundle's name in " "file '{}'.".format(bundle_filepath)) # so far 'pack' works for bundles only (later this will operate also on charms) if self.config.type != "bundle": raise CommandError( "Bad config: 'type' field in charmcraft.yaml must be 'bundle' for this command." ) # pack everything project = self.config.project manifest_filepath = create_manifest(project.dirpath, project.started_at) try: paths = get_paths_to_include(self.config) zipname = project.dirpath / (bundle_name + ".zip") build_zip(zipname, project.dirpath, paths) finally: manifest_filepath.unlink() logger.info("Created '%s'.", zipname)
def run(self): """Build the charm.""" logger.debug("Building charm in '%s'", self.buildpath) if self.buildpath.exists(): shutil.rmtree(str(self.buildpath)) self.buildpath.mkdir() create_manifest(self.buildpath, self.config.project.started_at) linked_entrypoint = self.handle_generic_paths() self.handle_dispatcher(linked_entrypoint) self.handle_dependencies() zipname = self.handle_package() logger.info("Created '%s'.", zipname) return zipname
def test_manifest_architecture_translated(tmp_path, monkeypatch): """All known architectures must be translated.""" monkeypatch.setitem(ARCH_TRANSLATIONS, 'weird_arch', 'nice_arch') os_platform = OSPlatform(system='Ubuntu', release='40.10', machine='weird_arch') with patch('charmcraft.utils.get_os_platform', return_value=os_platform): result_filepath = create_manifest(tmp_path, datetime.datetime.now()) saved = yaml.safe_load(result_filepath.read_text()) assert saved['bases'][0]['architectures'] == ['nice_arch']
def test_manifest_architecture_translated(tmp_path, monkeypatch): """All known architectures must be translated.""" monkeypatch.setitem(ARCH_TRANSLATIONS, "weird_arch", "nice_arch") os_platform = OSPlatform(system="Ubuntu", release="40.10", machine="weird_arch") with patch("charmcraft.utils.get_os_platform", return_value=os_platform): result_filepath = create_manifest(tmp_path, datetime.datetime.now()) saved = yaml.safe_load(result_filepath.read_text()) assert saved["bases"][0]["architectures"] == ["nice_arch"]
def test_manifest_fields_from_strict_snap(tmp_path, monkeypatch): """Fields found in a strict snap must be translated.""" os_platform = OSPlatform(system="ubuntu-core", release="20", machine="amd64") with patch("charmcraft.utils.get_os_platform", return_value=os_platform): result_filepath = create_manifest(tmp_path, datetime.datetime.now()) saved = yaml.safe_load(result_filepath.read_text()) base = saved["bases"][0] assert base["name"] == "ubuntu" assert base["channel"] == "20.04"
def test_manifest_simple_ok(tmp_path): """Simple construct.""" tstamp = datetime.datetime(2020, 2, 1, 15, 40, 33) os_platform = OSPlatform(system='SuperUbuntu', release='40.10', machine='SomeRISC') with patch('charmcraft.utils.get_os_platform', return_value=os_platform): result_filepath = create_manifest(tmp_path, tstamp) assert result_filepath == tmp_path / 'manifest.yaml' saved = yaml.safe_load(result_filepath.read_text()) expected = { 'charmcraft-started-at': '2020-02-01T15:40:33Z', 'charmcraft-version': __version__, 'bases': [{ 'name': 'SuperUbuntu', 'channel': '40.10', 'architectures': ['SomeRISC'], }], } assert saved == expected
def test_manifest_simple_ok(tmp_path): """Simple construct.""" tstamp = datetime.datetime(2020, 2, 1, 15, 40, 33) os_platform = OSPlatform(system="SuperUbuntu", release="40.10", machine="SomeRISC") with patch("charmcraft.utils.get_os_platform", return_value=os_platform): result_filepath = create_manifest(tmp_path, tstamp) assert result_filepath == tmp_path / "manifest.yaml" saved = yaml.safe_load(result_filepath.read_text()) expected = { "charmcraft-started-at": "2020-02-01T15:40:33Z", "charmcraft-version": __version__, "bases": [{ "name": "superubuntu", "channel": "40.10", "architectures": ["SomeRISC"], }], } assert saved == expected