Skip to content

Instantly share code, notes, and snippets.

@bmbouter
Created February 3, 2020 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmbouter/4c3cae55e67c3229ba07e3089128d8ff to your computer and use it in GitHub Desktop.
Save bmbouter/4c3cae55e67c3229ba07e3089128d8ff to your computer and use it in GitHub Desktop.
from os import path
import pdb
import subprocess
import tempfile
from pulpcore.client.pulp_ansible import (
DistributionsAnsibleApi,
RepositoriesAnsibleApi,
RepositorySyncURL,
RemotesCollectionApi,
)
from pulp_smash.pulp3.utils import gen_distribution, gen_repo
from pulp_ansible.tests.functional.constants import (
ANSIBLE_COLLECTION_TESTING_URL_V2,
COLLECTION_WHITELIST,
)
from pulp_ansible.tests.functional.utils import (
gen_ansible_client,
gen_ansible_remote,
monitor_task,
)
client = gen_ansible_client()
repo_api = RepositoriesAnsibleApi(client)
remote_collection_api = RemotesCollectionApi(client)
distributions_api = DistributionsAnsibleApi(client)
repo = repo_api.create(gen_repo())
pdb.set_trace()
# Create a distribution.
body = gen_distribution()
body["repository"] = repo.pulp_href
distribution_create = distributions_api.create(body)
distribution_url = monitor_task(distribution_create.task)
distribution = distributions_api.read(distribution_url[0])
pdb.set_trace()
body = gen_ansible_remote(url=ANSIBLE_COLLECTION_TESTING_URL_V2)
remote = remote_collection_api.create(body)
pdb.set_trace()
# Sync the repository.
repository_sync_data = RepositorySyncURL(remote=remote.pulp_href)
sync_response = repo_api.sync(repo.pulp_href, repository_sync_data)
monitor_task(sync_response.task)
repo = repo_api.read(repo.pulp_href)
with tempfile.TemporaryDirectory() as temp_dir:
cmd = "ansible-galaxy collection install {} -c -s {} -p {}".format(
COLLECTION_WHITELIST, distribution.client_url, temp_dir
)
print(cmd)
directory = "{}/ansible_collections/{}".format(
temp_dir, COLLECTION_WHITELIST.replace(".", "/")
)
pdb.set_trace()
subprocess.run(cmd.split())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment