def test_galaxy_content_frozen(): content_meta = content.GalaxyContentMeta(namespace='somenamespace', name='some_content', version='1.0.0', src='some_src', scm='some_scm', content_type='role', content_dir='roles', path='/dev/null/roles') with pytest.raises(attr.exceptions.FrozenInstanceError): content_meta.namespace = 'adiffnamespace' with pytest.raises(attr.exceptions.FrozenInstanceError): content_meta.name = 'somenewname' with pytest.raises(attr.exceptions.FrozenInstanceError): content_meta.version = '0.0.0' with pytest.raises(attr.exceptions.FrozenInstanceError): content_meta.src = 'anewsrc' with pytest.raises(attr.exceptions.FrozenInstanceError): content_meta.scm = 'anewscm' with pytest.raises(attr.exceptions.FrozenInstanceError): content_meta.content_type = 'notrole' with pytest.raises(attr.exceptions.FrozenInstanceError): content_meta.content_dir = 'notroles' with pytest.raises(attr.exceptions.FrozenInstanceError): content_meta.path = '/dev/null/notroles'
def test_galaxy_content_equality(): content_meta = content.GalaxyContentMeta(name='some_content', version='1.0.0', content_type='role') content_meta_newer = content.GalaxyContentMeta(name='some_content', version='2.3.4', content_type='role') content_meta_newer_dupe = content.GalaxyContentMeta(name='some_content', version='2.3.4', content_type='role') assert content_meta != content_meta_newer assert content_meta_newer != content_meta assert content_meta_newer == content_meta_newer_dupe
def test_galaxy_content_meta_no_args(): try: content.GalaxyContentMeta() except TypeError as e: log.exception(e) return assert False, 'GalaxyContentMeta() with no args should raise a TypeError but did not'
def test_galaxy_content_meta(): content_meta = content.GalaxyContentMeta(name='some_content', version='1.0.0', src='some_src', scm='some_scm', content_type='role', content_dir='roles', path='/dev/null/roles') assert content_meta.name == 'some_content' assert content_meta.content_type == 'role'
def install_dep_by_galaxy_metadata(content_dep, parent_content_meta, display_callback=None): display_callback = display_callback or null_display_callback # FIXME - Should we assume this to be true for module deps? # FIXME: ContentSpec object? # TODO: classmethod for GalaxyContentMeta.from_galaxy_metadata_dep() content_meta = content.GalaxyContentMeta(src=yaml_parse(content_dep['src']), content_type=content_dep.get('type', None), scm=content_dep.get('scm', None), path=parent_content_meta.path, version=content_dep.get('version', None), # needs map content_dir=content_dep.get('type', None)) display_callback('- processing dependency (skipping FIXME): %s' % content_meta.src) # This is an external dep, treat it as such if content_meta.scm: log.debug('need to install a content dep %s from remote, but skipping FIXME', content_meta) # TODO: add a GalaxyContent.from_content_metadata() classmethod constructor # dep_content = GalaxyContent(self.galaxy, **content_meta.data) # try: # installed = dep_content.install() # except exceptions.GalaxyClientError as e: # display_callback("- dependency %s was NOT installed successfully: %s " % # (dep_content.name, str(e)), level='warning') # return else: # the dep is also in the content repo the galaxy_metadata is from, so just # extract it (or better, add it to the accumulated list of things to extract) log.debug('looks like the dep %s is a dep from the same repo, skipping for now FIXME', content_meta) pass return [(content_meta, [])]
def install_from_galaxy_metadata(content_tar_file, archive_parent_dir, galaxy_metadata, content_meta, display_callback=None, force_overwrite=False): installed = [] content_sections = [] display_callback = display_callback or null_display_callback # find the sections that define how content will be installed for galaxy_metadata_section in galaxy_metadata: log.debug('galaxy_metadata_section=%s', galaxy_metadata_section) if galaxy_metadata_section in ('meta_version', 'repo_name', 'namespace'): log.debug('nothing to do for galaxy_metadata_section=%s', galaxy_metadata_section) continue content_sections.append(galaxy_metadata_section) # just the content sections for content_section in content_sections: log.debug('content_section=%s', content_section) # TODO: should be default behavior of content type specific ContentMeta subclasses # default behaviors for the type of content references by this section _content_dir = content.CONTENT_TYPE_DIR_MAP.get(content_section, None) _content_type = content_section if content_section == 'modules': _content_dir = 'library' _content_type = 'module' log.debug('content_section=%s, _contend_dir=%s, _content_type=%s', content_section, _content_dir, _content_type) # TODO/FIXME: really need ContentType classes for the defaults for each content type # ie, ModuleContentType, CallbackPluginsContentType, etc # # FIXME: this is creating a ContentMeta for the general content type we are dealing with _content_meta = content.GalaxyContentMeta(name=content_meta.name, src=content_meta.src, version=content_meta.version, scm=content_meta.scm, path=content_meta.path, content_type=_content_type, content_dir=_content_dir, requires_meta_main=False) res = install_by_galaxy_metadata(content_tar_file, archive_parent_dir, _content_meta, galaxy_metadata, content_section, display_callback=display_callback, force_overwrite=force_overwrite) log.debug('res=%s', res) installed.extend(res) return installed
def test_galaxy_content_meta_no_args(): content_meta = content.GalaxyContentMeta() assert isinstance(content_meta, content.GalaxyContentMeta) assert content_meta.name is None assert content_meta.content_type is None
def __init__(self, galaxy, name, src=None, version=None, scm=None, path=None, type="role", content_meta=None, sub_name=None, display_callback=None): """ The GalaxyContent type is meant to supercede the old GalaxyRole type, supporting all Galaxy Content Types as per the Galaxy Repository Metadata specification. The "content_type" is default to "role" in order to maintain backward compatibility as a drop-in replacement for GalaxyRole :param galaxy: Galaxy object from ansible.galaxy :param name: str, name of Galaxy Content desired :kw src: str, source uri :kw version: str, version required/requested :kw scm: str, scm type :kw path: str, local path to Galaxy Content :kw content_type: str, Galaxy Content type """ # what we are installing 'as', or what content subset we want to install self.content_install_type = type content_type = type self._metadata = None self._install_info = None self.log = logging.getLogger(__name__ + '.' + self.__class__.__name__) self.display_callback = display_callback or self._display_callback # self.options = galaxy.options self.galaxy = galaxy # FIXME: validate_certs is an option for two different things, # the connection to the galaxy_server (eg, galaxy.ansible.com) # and to where archives are downloaded (eg, github) self._validate_certs = not galaxy.server['ignore_certs'] # FIXME self.sub_name = sub_name # self.galaxy.content_roots['default']['content_path'] primary_galaxy_content_path = self.galaxy.content_path # If the content requires a meta/main.yml file ala roles requires_meta_main = False if content_type in self.REQUIRES_META_MAIN: requires_meta_main = True self.content_meta = content_meta or \ content.GalaxyContentMeta(name=name, src=src, version=version, scm=scm, path=primary_galaxy_content_path, requires_meta_main=requires_meta_main, content_type=content_type, content_dir=CONTENT_TYPE_DIR_MAP.get(content_type, None)) if content_type not in CONTENT_TYPES and content_type != "all": raise exceptions.GalaxyClientError( "%s is not a valid Galaxy Content Type" % content_type) # Set original path, needed to determine what action to take in order to # maintain backwards compat with legacy roles self._orig_path = path
def __init__(self, galaxy, name, src=None, version=None, scm=None, path=None, content_type=None, content_meta=None, content_spec=None, sub_name=None, namespace=None, # metadata is the info in roles meta/main.yml for ex metadata=None, # install_info is info in meta/.galaxy_install_info for installed content packages install_info=None, display_callback=None): """ The GalaxyContent type is meant to supercede the old GalaxyRole type, supporting all Galaxy Content Types as per the Galaxy Repository Metadata specification. The "content_type" is default to "role" in order to maintain backward compatibility as a drop-in replacement for GalaxyRole :param galaxy: Galaxy object from ansible.galaxy :param name: str, name of Galaxy Content desired :kw src: str, source uri :kw version: str, version required/requested :kw scm: str, scm type :kw path: str, local path to Galaxy Content :kw content_type: str, Galaxy Content type """ # what we are installing 'as', or what content subset we want to install self.content_install_type = 'all' if not content_type: content_type = 'role' self._content_type = content_type self._metadata = metadata self._install_info = install_info self.log = logging.getLogger(__name__ + '.' + self.__class__.__name__) self.display_callback = display_callback or display.display_callback # self.options = galaxy.options self.galaxy = galaxy # FIXME: validate_certs is an option for two different things, # the connection to the galaxy_server (eg, galaxy.ansible.com) # and to where archives are downloaded (eg, github) self._validate_certs = not galaxy.server['ignore_certs'] # FIXME self.sub_name = sub_name self.content_spec = content_spec # self.galaxy.content_roots['default']['content_path'] primary_galaxy_content_path = self.galaxy.content_path # If the content requires a meta/main.yml file ala roles # requires_meta_main = False # if content_type in self.REQUIRES_META_MAIN: # requires_meta_main = True self.content_meta = content_meta or \ content.GalaxyContentMeta(namespace=namespace, name=name, version=version, src=src, scm=scm, content_type=self._content_type, content_dir=CONTENT_TYPE_DIR_MAP.get(content_type, None), path=primary_galaxy_content_path) # TODO: factory? metaclass? if content_type not in CONTENT_TYPES and content_type != "all": raise exceptions.GalaxyClientError("%s is not a valid Galaxy Content Type" % content_type) # Set original path, needed to determine what action to take in order to # maintain backwards compat with legacy roles self._orig_path = path # TODO: state machine for find->fetch->install # data from fetch.find() where we find, discover, and resolve info about the content # (ie, via asking the galaxy api) self._find_results = None