Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes 4293: add support for upload only repos #728

Merged
merged 3 commits into from
Jul 15, 2024

Conversation

jlsherrill
Copy link
Member

@jlsherrill jlsherrill commented Jul 2, 2024

Summary

Testing steps

Create an upload repo:

PATCH http://localhost:8000/api/content-sources/v1.0/repositories/c06a0512-0954-4b11-9b13-3358afe77f46
x-rh-identity: eyJpZGVudGl0eSI6eyJvcmdfaWQiOiI5IiwgInR5cGUiOiJVc2VyIiwidXNlciI6eyJ1c2VybmFtZSI6ImZvbyJ9LCJhY2NvdW50X251bWJlciI6ImZvbyIsImludGVybmFsIjp7Im9yZ19pZCI6IjkifX19Cg==
//x-Rh-Insights-Request-Id: 9d229d34-7219-405d-ba3d-8f99cf7c36ae
Content-Type: application/json

{
  "name": "arg",
  "origin": "upload"
}

with batch:

POST http://localhost:8000/api/content-sources/v1.0/repositories/bulk_create/
x-rh-identity: eyJpZGVudGl0eSI6eyJvcmdfaWQiOiI5IiwgInR5cGUiOiJVc2VyIiwidXNlciI6eyJ1c2VybmFtZSI6ImZvbyJ9LCJhY2NvdW50X251bWJlciI6ImZvbyIsImludGVybmFsIjp7Im9yZ19pZCI6IjkifX19Cg==

[{
  "name": "test5",
  "gpg_key": "",
  "snapshot": true,
  "origin": "upload",
  "url": ""
},
  {
    "name": "test6",
    "gpg_key": "",
    "snapshot": true,
    "origin": "upload",
    "url": ""
  }]

try to:

  1. create/update an upload repo with a url, this should fail
  2. try to change the origin of a repo, this should not succeed
  3. try to introspect an upload repo, this should be rejected
  4. try to snapshot an upload repo, this should be rejected
  5. run go run cmd/external-repos/main.go nightly-jobs and verify no errors, that things work as expected

Checklist

  • Tested with snapshotting feature disabled and pulp server URL not configured if appropriate

@jlsherrill
Copy link
Member Author

@jlsherrill jlsherrill marked this pull request as ready for review July 5, 2024 14:38
@rverdile rverdile self-assigned this Jul 8, 2024
Snapshot *bool `json:"snapshot"` // Enable snapshotting and hosting of this repository
}

type RepositoryUpdateRequest struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not saying I'm opposed, just curious, why separate the update request struct? I guess one benefit might be making the API more readable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While making the origin parameter available for create, i didn't want it available for update. There's no way in openapi to indicate that a parameter is only for creation, and i saw some discussion mentioning that using different structs was the correct way to handle it. We also did it this way for template.

That said, it complicates and duplicates the code quite a bit. I tried using inheritance and that reduced the duplication a bit, but increased complexity and i didn't think was an improvement.

Copy link
Contributor

@rverdile rverdile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found these two issues. Everything else seems to be working well.

Comment on lines +99 to +104
} else if newRepo.URL != "" {
cleanedUrl := models.CleanupURL(newRepo.URL)
// Repo configs with the same URL share a repository object
if err := r.db.WithContext(ctx).Where("url = ?", cleanedUrl).FirstOrCreate(&newRepo).Error; err != nil {
return api.RepositoryResponse{}, DBErrorToApi(err)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a repository exists (not a repository config) and I create an upload repo with the URL of the existing repository, I get no error, because it fetches the existing repository (which would have a non-upload origin). If the repository does not exist, I get a 400 error because "an upload repo cannot contain a URL". I think I'd expect to get the same 400 in the first scenario.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated and add a test for create and update for this situation

Comment on lines +1 to +3
BEGIN;
alter table repositories alter column URL set not null;
COMMIT;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get this error running the down migration

{"level":"error","error":"2 errors occurred:\n\t* migration failed: column \"url\" of relation \"repositories\" contains null values in line 0: BEGIN;\nalter table repositories alter column URL set not null;\nCOMMIT;\n (details: pq: column \"url\" of relation \"repositories\" contains null values)\n\t* pq: current transaction is aborted, commands ignored until end of transaction block in line 0: SELECT pg_advisory_unlock($1)\n\n","time":"2024-07-09T13:29:07-04:00","message":"Failed to migrate:"}
{"level":"fatal","error":"database locked","time":"2024-07-09T13:29:07-04:00","message":"Failed to migrate"}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had an upload repository created when I ran it

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so i'm not sure exactly what to do about this. I guess this may be considered a migration that can't be reverted. We can't flip that column back to 'not null' whith a null value. We could delete all repositories (and repo configs, and associated rpms, etc....) in the migration, but thats not a great solution. Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true. I can't think of a better way to do it. I guess we can consider it an un-revertable migration.

Copy link
Contributor

@rverdile rverdile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good!

@swadeley
Copy link
Member

/retest

@swadeley
Copy link
Member

Hi

I can create an upload repo:


In [7]:     repo_dict_3 = dict(
   ...:         name="test_upload_repo_2",
   ...:         origin="upload",
   ...:         snapshot=True,
   ...:      )

In [8]: created_repo3 = app.content_sources.rest_client.repositories_api.create_repository(repo_dict_3)
2024-07-15 15:10:58.648 [    INFO] [iqe.base.rest_client] REST: METHOD=POST, request_id=<>, params=[]

In [9]: created_repo3
Out[9]: 
{'account_id': '0369233',
 'content_type': 'rpm',
 'distribution_arch': 'any',
 'distribution_versions': ['any'],
 'failed_introspections_count': 0,
 'gpg_key': '',
 'label': 'test_upload_repo_2',
 'last_introspection_error': '',
 'last_introspection_status': 'Pending',
 'last_introspection_time': '',
 'last_success_introspection_time': '',
 'last_update_introspection_time': '',
 'metadata_verification': False,
 'module_hotfixes': False,
 'name': 'test_upload_repo_2',
 'org_id': '3340851',
 'origin': 'upload',
 'package_count': 0,
 'snapshot': True,
 'status': 'Pending',
 'url': '',
 'uuid': 'be85f598-62a2-427a-bfaa-e14becd4b4c0'}

To list upload repos at present it is required to use origin='upload':

In [20]: app.content_sources.rest_client.repositories_api.list_repositories(origin='upload')
2024-07-15 16:00:51.627 [    INFO] [iqe.base.rest_client] REST: METHOD=GET, request_id=<>, params=[('origin', 'upload')]
Out[20]: 
{'data': [{'account_id': '0369233',
           'content_type': 'rpm',
           'distribution_arch': 'any',
           'distribution_versions': ['any'],
           'failed_introspections_count': 0,
           'gpg_key': '',
           'label': 'test_upload_repo_1',
           'last_introspection_error': '',
           'last_introspection_status': 'Pending',
           'last_introspection_time': '',
           'last_success_introspection_time': '',
           'last_update_introspection_time': '',
           'metadata_verification': False,
           'module_hotfixes': False,
           'name': 'test_upload_repo_1',
           'org_id': '3340851',
           'origin': 'upload',
           'package_count': 0,
           'snapshot': False,
           'status': 'Pending',
           'url': '',
           'uuid': 'e1474a4a-c4ba-48d8-8bbf-9b513d240711'},
          {'account_id': '0369233',
           'content_type': 'rpm',
           'distribution_arch': 'any',
           'distribution_versions': ['any'],
           'failed_introspections_count': 0,
           'gpg_key': '',
           'label': 'test_upload_repo_2',
           'last_introspection_error': '',
           'last_introspection_status': 'Pending',
           'last_introspection_time': '',
           'last_success_introspection_time': '',
           'last_update_introspection_time': '',
           'metadata_verification': False,
           'module_hotfixes': False,
           'name': 'test_upload_repo_3',
           'org_id': '3340851',
           'origin': 'upload',
           'package_count': 0,
           'snapshot': True,
           'status': 'Pending',
           'url': '',
           'uuid': 'be85f598-62a2-427a-bfaa-e14becd4b4c0'}],
 'links': {'first': '/api/content-sources/v1/repositories/?limit=100&offset=0&origin=upload',
           'last': '/api/content-sources/v1/repositories/?limit=100&offset=0&origin=upload'},
 'meta': {'count': 2, 'limit': 100, 'offset': 0}}

In [21]: 

@swadeley swadeley merged commit 8873452 into content-services:main Jul 15, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants