def test_regenerate_inplace(self): # take a generated example where a base layer has changed # regenerate in place # make some assertions bu = build.Builder() bu.log_level = "WARNING" bu.output_dir = "out" bu.series = "trusty" bu.name = "foo" bu.charm = "trusty/b" bu.hide_metrics = True bu() base = path("out/trusty/foo") self.assertTrue(base.exists()) # verify the 1st gen worked self.assertTrue((base / "a").exists()) self.assertTrue((base / "README.md").exists()) # now regenerate from the target with utils.cd("out/trusty/foo"): bu = build.Builder() bu.log_level = "WARNING" bu.output_dir = path(os.getcwd()) bu.series = "trusty" # The generate target and source are now the same bu.name = "foo" bu.charm = "." bu.hide_metrics = True bu() base = bu.output_dir self.assertTrue(base.exists()) # Check that the generated layer.yaml makes sense cy = base / "layer.yaml" config = yaml.load(cy.open()) self.assertEquals(config["includes"], ["trusty/a", "interface:mysql"]) self.assertEquals(config["is"], "foo") # We can even run it more than once bu() cy = base / "layer.yaml" config = yaml.load(cy.open()) self.assertEquals(config["includes"], ["trusty/a", "interface:mysql"]) self.assertEquals(config["is"], "foo") # We included an interface, we should be able to assert things about it # in its final form as well provides = base / "hooks/relations/mysql/provides.py" requires = base / "hooks/relations/mysql/requires.py" self.assertTrue(provides.exists()) self.assertTrue(requires.exists()) # and that we generated the hooks themselves for kind in ["joined", "changed", "broken", "departed"]: self.assertTrue((base / "hooks" / "mysql-relation-{}".format(kind)).exists()) # and ensure we have an init file (the interface doesn't its added) init = base / "hooks/relations/mysql/__init__.py" self.assertTrue(init.exists())
def _try_to_get_current_sha(self): cmds = ( ('git', 'describe', '--dirty', '--always'), ('bzr', 'version-info'), ('hg', 'id', '-n'), ) with utils.cd(str(self.charm)): for cmd in cmds: try: sha = utils.Process(cmd)() if sha: return sha.output except FileNotFoundError as e: log.debug(e) continue return ""
def _try_to_get_current_sha(self): with utils.cd(str(self.charm)): for cmd in self.CMDS: try: log.debug('Trying to determine version with: ' '{}'.format(cmd[0])) sha = utils.Process(cmd)() if sha and sha.exit_code == 0 and sha.output: log.debug('Got version: {}'.format(sha.output)) return sha.output else: log.debug('Failed to get version{}'.format( ': {}'.format(sha.output) if sha else '')) continue except OSError as e: if e.errno != errno.ENOENT: raise log.debug(e) continue return ""
def _try_to_get_current_sha(self): with utils.cd(str(self.charm)): for cmd in self.CMDS: try: log.debug('Trying to determine version with: ' '{}'.format(cmd[0])) sha = utils.Process(cmd)() if sha and sha.exit_code == 0 and sha.output: log.debug('Got version: {}'.format(sha.output)) return sha.output else: log.debug('Failed to get version{}'.format( ': {}'.format(sha.output) if sha else '' )) continue except OSError as e: if e.errno != errno.ENOENT: raise log.debug(e) continue return ""
def test_regenerate_inplace(self): # take a generated example where a base layer has changed # regenerate in place # make some assertions bu = build.Builder() bu.log_level = "WARNING" bu.output_dir = "out" bu.series = "trusty" bu.name = "foo" bu.charm = "trusty/b" bu.hide_metrics = True bu.report = False bu() base = path('out/trusty/foo') self.assertTrue(base.exists()) # verify the 1st gen worked self.assertTrue((base / "a").exists()) self.assertTrue((base / "README.md").exists()) # now regenerate from the target with utils.cd("out/trusty/foo"): bu = build.Builder() bu.log_level = "WARNING" bu.output_dir = path(os.getcwd()) bu.series = "trusty" # The generate target and source are now the same bu.name = "foo" bu.charm = "." bu.hide_metrics = True bu.report = False bu() base = bu.output_dir self.assertTrue(base.exists()) # Check that the generated layer.yaml makes sense cy = base / "layer.yaml" config = yaml.load(cy.open()) self.assertEquals(config["includes"], ["trusty/a", "interface:mysql"]) self.assertEquals(config["is"], "foo") # We can even run it more than once bu() cy = base / "layer.yaml" config = yaml.load(cy.open()) self.assertEquals(config["includes"], ["trusty/a", "interface:mysql"]) self.assertEquals(config["is"], "foo") # We included an interface, we should be able to assert things about it # in its final form as well provides = base / "hooks/relations/mysql/provides.py" requires = base / "hooks/relations/mysql/requires.py" self.assertTrue(provides.exists()) self.assertTrue(requires.exists()) # and that we generated the hooks themselves for kind in ["joined", "changed", "broken", "departed"]: self.assertTrue((base / "hooks" / "mysql-relation-{}".format(kind)).exists()) # and ensure we have an init file (the interface doesn't its added) init = base / "hooks/relations/mysql/__init__.py" self.assertTrue(init.exists())