def assertEnvironmentOverrideExistsButBroken(self, environment, identifier, desired): base_path = "%s/%s" % (self.settings.ENVIRONMENTSDIR, environment) partition, element = identifier.split('/') links = [] links.append("%s/%s/%s" % (base_path, partition, element)) if partition == 'modules': links.append("%s/hieradata/module_names/%s" % (base_path, element)) if partition == 'hostgroups': canonical_name = element.replace('hg_', '') links.append("%s/hieradata/hostgroups/%s" % \ (base_path, canonical_name)) links.append("%s/hieradata/fqdns/%s" % \ (base_path, canonical_name)) for link in links: # Override created if not os.path.lexists(link): raise AssertionError("Env '%s' -- '%s' -- '%s' does not exist" % \ (environment, identifier, link)) target = os.readlink(link) dirname = refname_to_dirname(desired) link_parent = os.path.abspath(os.path.join(link, os.pardir)) # Link broken if self._verify_link(link_parent, link): raise AssertionError("Env '%s' -- '%s' -- '%s' is not broken" % \ (environment, identifier, link))
def _compose_clone_repository_path(name, partition, refname=None): settings = Settings() path = settings.CLONEDIR + "/%s/%s" % (partition, name) if refname is not None: dirname = refname_to_dirname(refname) path = "%s/%s" % (path, dirname) return path
def assertEnvironmentOverride(self, environment, identifier, desired): base_path = "%s/%s" % (self.settings.ENVIRONMENTSDIR, environment) partition, element = identifier.split('/') links = [] links.append("%s/%s/%s" % (base_path, partition, element)) if partition == 'modules': links.append("%s/hieradata/module_names/%s" % (base_path, element)) if partition == 'hostgroups': canonical_name = element.replace('hg_', '') links.append("%s/hieradata/hostgroups/%s" % \ (base_path, canonical_name)) links.append("%s/hieradata/fqdns/%s" % \ (base_path, canonical_name)) for link in links: # Override created if not os.path.lexists(link): raise AssertionError("Env '%s' -- '%s' -- '%s' does not exist" % \ (environment, identifier, link)) target = os.readlink(link) dirname = refname_to_dirname(desired) # Link not broken link_parent = os.path.abspath(os.path.join(link, os.pardir)) if not self._verify_link(link_parent, link): raise AssertionError("Env '%s' -- '%s' -- '%s' is broken" % \ (environment, identifier, link)) # And points to the correct clone link_type = 'data' if re.match(r'^%s/hieradata/.+' % \ base_path, link) else 'code' if not re.match(r".+/%s/%s.*" % (dirname, link_type), target): raise AssertionError("Env '%s' '%s' // '%s' -> '%s' not to '%s' (%s)" % \ (environment, identifier, link, target, dirname, desired))
def assertEnvironmentOverrideExistsButBroken(self, environment, identifier, desired): base_path = "%s/%s" % (self.settings.ENVIRONMENTSDIR, environment) partition, element = identifier.split('/') links = [] links.append("%s/%s/%s" % (base_path, partition, element)) if partition == 'modules': links.append("%s/hieradata/module_names/%s" % (base_path, element)) if partition == 'hostgroups': canonical_name = element.replace('hg_', '') links.append("%s/hieradata/hostgroups/%s" % \ (base_path, canonical_name)) links.append("%s/hieradata/fqdns/%s" % \ (base_path, canonical_name)) for link in links: # Override created if not os.path.lexists(link): raise AssertionError("Env '%s' -- '%s' -- '%s' does not exist" % \ (environment, identifier, link)) target = os.readlink(link) dirname = refname_to_dirname(self.settings, desired) link_parent = os.path.abspath(os.path.join(link, os.pardir)) # Link broken if self._verify_link(link_parent, link): raise AssertionError("Env '%s' -- '%s' -- '%s' is not broken" % \ (environment, identifier, link))
def assertEnvironmentOverride(self, environment, identifier, desired): base_path = "%s/%s" % (self.settings.ENVIRONMENTSDIR, environment) partition, element = identifier.split('/') links = [] links.append("%s/%s/%s" % (base_path, partition, element)) if partition == 'modules': links.append("%s/hieradata/module_names/%s" % (base_path, element)) if partition == 'hostgroups': canonical_name = element.replace('hg_', '') links.append("%s/hieradata/hostgroups/%s" % \ (base_path, canonical_name)) links.append("%s/hieradata/fqdns/%s" % \ (base_path, canonical_name)) for link in links: # Override created if not os.path.lexists(link): raise AssertionError("Env '%s' -- '%s' -- '%s' does not exist" % \ (environment, identifier, link)) target = os.readlink(link) dirname = refname_to_dirname(self.settings, desired) # Link not broken link_parent = os.path.abspath(os.path.join(link, os.pardir)) if not self._verify_link(link_parent, link): raise AssertionError("Env '%s' -- '%s' -- '%s' is broken" % \ (environment, identifier, link)) # And points to the correct clone link_type = 'data' if re.match(r'^%s/hieradata/.+' % \ base_path, link) else 'code' if not re.match(r".+/%s/%s.*" % (dirname, link_type), target): raise AssertionError("Env '%s' '%s' // '%s' -> '%s' not to '%s' (%s)" % \ (environment, identifier, link, target, dirname, desired))
def _resolve_branch(partition, element, definition): overridden = False branch = 'master' if 'overrides' in definition: if partition in definition['overrides']: if element in list(definition['overrides'][partition].keys()): branch = definition['overrides'][partition][element] logging.info("%s '%s' overridden to use treeish '%s'", partition, element, branch) overridden = True if not overridden and 'default' in definition: branch = definition['default'] return (refname_to_dirname(branch), overridden)
def _resolve_branch(partition, element, definition): overridden = False branch = 'master' if 'overrides' in definition: if partition in definition['overrides']: if element in definition['overrides'][partition].keys(): branch = definition['overrides'][partition][element] logging.info("%s '%s' overridden to use treeish '%s'", partition, element, branch) overridden = True if not overridden and 'default' in definition: branch = definition['default'] return (refname_to_dirname(branch), overridden)