def test_metadata_fallback(self): metadata = MetaData() self.assertEquals(get_revision(None, metadata, None), None) metadata.parse( yaml.dump({ "name": "x", "summary": "y", "description": "z", "revision": 33 })) self.assertEquals(get_revision(None, metadata, None), 33)
class CharmBundle(CharmBase): """ZIP-archive that contains charm directory content.""" def __init__(self, path): self.path = isinstance(path, file) and path.name or path try: zf = ZipFile(path, 'r') except BadZipfile, exc: raise CharmError(path, "must be a zip file (%s)" % exc) if "metadata.yaml" not in zf.namelist(): raise CharmError( path, "charm does not contain required file 'metadata.yaml'") self.metadata = MetaData() self.metadata.parse(zf.read("metadata.yaml")) try: revision_content = zf.read("revision") except KeyError: revision_content = None self._revision = get_revision( revision_content, self.metadata, self.path) if self._revision is None: raise CharmError(self.path, "has no revision") self.config = ConfigOptions() if "config.yaml" in zf.namelist(): self.config.parse(zf.read("config.yaml"))
def __init__(self, path): self.path = path self.metadata = MetaData(os.path.join(path, "metadata.yaml")) revision_content = None revision_path = os.path.join(self.path, "revision") if os.path.exists(revision_path): with open(revision_path) as f: revision_content = f.read() self._revision = get_revision(revision_content, self.metadata, self.path) if self._revision is None: self.set_revision(0) elif revision_content is None: self.set_revision(self._revision) self.config = ConfigOptions() self.config.load(os.path.join(path, "config.yaml")) self._temp_bundle = None self._temp_bundle_file = None
def assert_good_content(self, content, value): self.assertEquals(get_revision(content, None, None), value)
def test_metadata_fallback(self): metadata = MetaData() self.assertEquals(get_revision(None, metadata, None), None) metadata.parse(yaml.dump({ "name": "x", "summary": "y", "description": "z","revision": 33})) self.assertEquals(get_revision(None, metadata, None), 33)