Regex bug in galaxy-importer

I have a similar problem to Unable to manage roles in the new Galaxy-ng portal?
The import via the CLI does not work:

ansible-galaxy import --token=$(cat ~/.ansible_galaxy_token) bodsch ansible-glauth --role-name glauth  --verbose --branch=1.4.1
Using /home/bodsch/.ansible.cfg as config file
Successfully submitted import request ...
unknown field in galaxy_info
  File "/venv/lib64/python3.11/site-packages/pulpcore/tasking/tasks.py", line 66, in _execute_task
    result = func(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^
  File "/app/galaxy_ng/app/api/v1/tasks.py", line 127, in legacy_role_import
    result = import_legacy_role(checkout_path, namespace.name, importer_config, logger)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib64/python3.11/site-packages/galaxy_importer/legacy_role.py", line 51, in import_legacy_role
    return _import_legacy_role(dirname, namespace, cfg, logger)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib64/python3.11/site-packages/galaxy_importer/legacy_role.py", line 57, in _import_legacy_role
    data = LegacyRoleLoader(dirname, namespace, cfg, logger).load()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib64/python3.11/site-packages/galaxy_importer/loaders/legacy_role.py", line 41, in load
    self.metadata = self._load_metadata()
                    ^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib64/python3.11/site-packages/galaxy_importer/loaders/legacy_role.py", line 77, in _load_metadata
    return schema.LegacyMetadata.parse(meta_path)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib64/python3.11/site-packages/galaxy_importer/schema.py", line 522, in parse
    raise exc.LegacyRoleSchemaError("unknown field in galaxy_info") from e

But it looks like a server-side problem to me.

2 Likes

Does ansible-lint have any warnings on the Galaxy metadata for the role?

ansible-lint does not find any errors.

ansible-lint .

Passed: 0 failure(s), 0 warning(s) on 24 files. Last profile that met the validation criteria was 'production'.

The lint config is simple:

cat .ansible-lint 
---

skip_list:
  - name[casing]
  - name[template]

The import has also worked without any problems so far.

1 Like

Comparing the schema in galaxy-importer (https://github.com/ansible/galaxy-importer/blob/master/galaxy_importer/schema.py#L387-L400) with your galaxy_info (https://github.com/bodsch/ansible-glauth/blob/main/meta/main.yml), it looks like the offender is the namespace field.

That field was apparently introduced by ansible-lint, but it could be that galaxy-importer got stricter some time ago (the old community Galaxy used an older version of it) and this now clashes with that field. CC @ssbarnea.

1 Like

I couldn’t import Ansible roles without this field for a long time.

In the workflow history you can also see that the automatic import always worked, until the current update of the Galaxy.

It would be massively helpful to upgrade the import error message accordingly!

With an “unknown field in galaxy_info” you are pretty helpless.

And unfortunately namespace is not the cause! :frowning:

2 Likes

I’m wondering if the “-” in https://github.com/bodsch/ansible-glauth/ is messing you up.

In the galaxy-importer, galaxy-importer/constants.py line 61, there’s a broken regex introduced about 3 months ago:

# Matches role names with any combination of lowercase letters,
# uppercase letters, numbers, underscores, and hyphens with
# a length in the inclusive range [1, 55].
LEGACY_ROLE_NAME_REGEXP = re.compile("^[a-zA-Z0-9-_]{1,55}$")

It’s supposed to accept underscores and hyphens, but it doesn’t. Rather it accepts '9' through '_'. It should be

LEGACY_ROLE_NAME_REGEXP = re.compile("^[a-zA-Z0-9_-]{1,55}$")
2 Likes

Sleep on it once and more coffee and I understand my problem.

I guess I need to fix all my roles.

@utoddl does it make sense to move this point about regexes to a new topic? The original request is solved but I think you might have something worth discussing there…

Makes sense to me, moving this regex issue to a new topic. That has to be done by a moderator I suppose? I don’t see a way to do it myself.

Note: this is being worked on:

a17f996 Change regexp for legacy role name to correcly match underscore or hyphen

1 Like

Yes, it’s a moderator action. Once the forum has settled in I hope to promote some additional moderators :wink:

I’ve moved the posts, but it sounds like it’s already in hand. Is there also a case for that error message to improve?

Hard to say. I was searching “upstream” from the “unknown field” message trying to ferret out what field could be the issue, and frankly I didn’t see justification for that wording. Emphasis on “didn’t see” — it could be spot on, but I’d never looked at that code before and wouldn’t bet dessert on what it’s actually doing. When I spotted that regex issue I quit looking.

1 Like