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

Galaxy server clean-up script along with some changes to galaxykit to support it #95

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ironfroggy
Copy link
Contributor

@ironfroggy ironfroggy commented Jun 27, 2023

Changes to galaxykit include:

  • The collection list command gains repository, limit, offset, keywords parameters
    • repository: Can specify multiple repositories to list from. Default: "published"
    • `limit': How many collections to return at maximum.
    • offset: How many collections to skip, to allow paging.
    • keywords: Filter results with a keyword search.
  • Added a new flag to all http methods: include_response. Causes to return both the parsed JSON and the original HttpResponse object.
  • get() can take a keyword argument "params" to pass querystring parameters easily.
  • delete_collection() has many changes to support the cleanup script:
    • Takes a repositories parameter instead of a repository parameter.
    • Takes a boolean dependencies parameter to recursively delete dependencies of the collection before deleting the collection itself.

Finally, of course, added the actual clean up script in scripts/galaxy-cleaner.sh.

galaxy-cleaner.sh
script usage: ./cleanup.sh [-l LIMIT] [-b BATCH_SIZE] [-d]

    -l          Limit. Number of collections to remove.
    -b          Batch size. Number of collections to fetch in each batch
                to then delete. Adjust this for performance and/or rate limit
                problems.
    -d          Debug flag. Enables bash -xv flags and displays extra debug
                information while running.
    -t          Token file. Path to a file to read the access token from.
    -T          Token. Directly pass the access token as a parameter.
    -p          Proxy. Set the HTTP_PROXY value to access the Galaxy API via.
    -w          Wait. Pause between steps to reduce server impact or avoid rate
                limiting.galaxy-cleaner.sh

include_response = kwargs.pop("include_response", False)

if include_response and not parse_json:
raise ValueError("GalaxyClient._http() called with include_response=True only valid when parse_json=True!")
Copy link
Contributor

Choose a reason for hiding this comment

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

[black] reported by reviewdog 🐶

Suggested change
raise ValueError("GalaxyClient._http() called with include_response=True only valid when parse_json=True!")
raise ValueError(
"GalaxyClient._http() called with include_response=True only valid when parse_json=True!"
)

def get_collection_list(client):
url = "_ui/v1/collection-versions/?limit=999999"
return client.get(url)
def get_collection_list(client, repo="published", limit=None, offset=None, keywords=None):
Copy link
Contributor

Choose a reason for hiding this comment

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

[black] reported by reviewdog 🐶

Suggested change
def get_collection_list(client, repo="published", limit=None, offset=None, keywords=None):
def get_collection_list(
client, repo="published", limit=None, offset=None, keywords=None
):

@@ -201,19 +216,75 @@ def move_or_copy_collection(


def delete_collection(
client, namespace, collection, version=None, repository="published"
client, namespace, collection, version=None, repositories=("published",), dependents=False
Copy link
Contributor

Choose a reason for hiding this comment

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

[black] reported by reviewdog 🐶

Suggested change
client, namespace, collection, version=None, repositories=("published",), dependents=False
client,
namespace,
collection,
version=None,
repositories=("published",),
dependents=False,

resp = client.delete(delete_url)
except GalaxyClientError as e:
if e.response.status_code == 404:
logger.debug(f"Ignoring (maybe) already deleted {coll_name}", file=sys.stderr)
Copy link
Contributor

Choose a reason for hiding this comment

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

[black] reported by reviewdog 🐶

Suggested change
logger.debug(f"Ignoring (maybe) already deleted {coll_name}", file=sys.stderr)
logger.debug(
f"Ignoring (maybe) already deleted {coll_name}", file=sys.stderr
)

Comment on lines +264 to +267
combined = {
"original": None,
"dependents": []
}
Copy link
Contributor

Choose a reason for hiding this comment

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

[black] reported by reviewdog 🐶

Suggested change
combined = {
"original": None,
"dependents": []
}
combined = {"original": None, "dependents": []}

for dep in resp["dependent_collection_versions"]:
dep_coll, dep_ver = dep.split(" ")
dep_ns, dep_name = dep_coll.split(".")
dep_resp = delete_collection(client, dep_ns, dep_name, dep_ver, repositories, dependents=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

[black] reported by reviewdog 🐶

Suggested change
dep_resp = delete_collection(client, dep_ns, dep_name, dep_ver, repositories, dependents=True)
dep_resp = delete_collection(
client,
dep_ns,
dep_name,
dep_ver,
repositories,
dependents=True,
)

Comment on lines +283 to +286
final_resp["responses"].append({
"collection": coll_name,
"response": resp,
})
Copy link
Contributor

Choose a reason for hiding this comment

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

[black] reported by reviewdog 🐶

Suggested change
final_resp["responses"].append({
"collection": coll_name,
"response": resp,
})
final_resp["responses"].append(
{
"collection": coll_name,
"response": resp,
}
)

@@ -489,7 +526,15 @@ def report_error(resp):

def parse_args(parser, args):
for arg in args:
parser.add_argument(arg, **(args[arg]))
flag_args=[]
Copy link
Contributor

Choose a reason for hiding this comment

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

[black] reported by reviewdog 🐶

Suggested change
flag_args=[]
flag_args = []

flag_args.append("--" + args[arg].pop("long").strip("-"))
if not flag_args:
flag_args.append(arg)

Copy link
Contributor

Choose a reason for hiding this comment

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

[black] reported by reviewdog 🐶

Suggested change

args.namespace,
args.collection,
args.version,
args.repository or "published",
args.repository.split(","),
args.dependents
Copy link
Contributor

Choose a reason for hiding this comment

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

[black] reported by reviewdog 🐶

Suggested change
args.dependents
args.dependents,

@himdel
Copy link
Collaborator

himdel commented Jul 21, 2023

This is causing a lot of failures in UI tests (https://github.com/ansible/ansible-hub-ui/actions/runs/5617442384/job/15221548810?pr=4013#step:30:464)

but looks like the primary cause is the change to galaxykit collection list:

  • changes data from list of latest collection versions to a list of collections with a latest_version
  • no longer includes repository_list
  • no longer includes collections from other repositories (such as rejected)
  • default page_size went from 100 to 10

Which makes collection list less straightforward to use for finding and cleaning up all collections.

Is that an intentional change?
(If so, updating tests in ansible/ansible-hub-ui#4013)

(Also, if the goal is to update the API endpoint, shouldn't this be using v3/plugin/ansible/search/collection-versions/?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants