Last active
January 13, 2023 12:16
-
-
Save sayan3296/0f765e21eaec0651b0e9a6ae078a7dea to your computer and use it in GitHub Desktop.
Script to recreate https://bugzilla.redhat.com/show_bug.cgi?id=2107701
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
## Assuming that, this is a fresh satellite 6.10 or 6.11 with a subscription manifest imported ( having a valid RHEL sub ) and no repos are enabled at present | |
## Also assuming that the organization name is RedHat or else replace "--organization RedHat" with "--organization-id 1" | |
## Refresh manifest once | |
hammer subscription refresh-manifest --organization RedHat | |
## Setup the repo and CV in satellite | |
hammer repository-set enable --name "Red Hat Satellite Tools 6.9 (for RHEL 7 Server) (RPMs)" --product "Red Hat Enterprise Linux Server" --basearch x86_64 --releasever 7Server --organization RedHat | |
hammer repository-set enable --name "Red Hat Ansible Engine 2.9 RPMs for Red Hat Enterprise Linux 7 Server" --product "Red Hat Ansible Engine" --basearch x86_64 --organization RedHat | |
hammer repository update --name "Red Hat Ansible Engine 2.9 RPMs for Red Hat Enterprise Linux 7 Server x86_64" --product "Red Hat Ansible Engine" --organization RedHat --download-policy immediate | |
hammer repository update --name "Red Hat Satellite Tools 6.9 for RHEL 7 Server RPMs x86_64" --product "Red Hat Enterprise Linux Server" --organization RedHat --download-policy immediate | |
hammer repository synchronize --name "Red Hat Ansible Engine 2.9 RPMs for Red Hat Enterprise Linux 7 Server x86_64" --product "Red Hat Ansible Engine" --organization RedHat | |
hammer repository synchronize --name "Red Hat Satellite Tools 6.9 for RHEL 7 Server RPMs x86_64" --product "Red Hat Enterprise Linux Server" --organization RedHat | |
REPO_IDS=$(hammer --no-headers repository list --organization RedHat --fields Id | xargs | tr " " ",") | |
hammer lifecycle-environment create --name QA --prior Library --organization RedHat | |
hammer content-view create --name TestCV --organization RedHat --repository-ids $REPO_IDS | |
hammer content-view publish --name TestCV --organization RedHat | |
hammer content-view version promote --from-lifecycle-environment Library --to-lifecycle-environment QA --content-view TestCV --organization RedHat | |
hammer repository-set enable --name "Red Hat Satellite Utils 6.11 for RHEL 8 x86_64 (RPMs)" --product "Red Hat Enterprise Linux for x86_64" --basearch x86_64 --organization RedHat | |
hammer repository update --name "Red Hat Satellite Utils 6.11 for RHEL 8 x86_64 RPMs" --product "Red Hat Enterprise Linux for x86_64" --organization RedHat --download-policy immediate | |
hammer repository synchronize --name "Red Hat Satellite Utils 6.11 for RHEL 8 x86_64 RPMs" --product "Red Hat Enterprise Linux for x86_64" --organization RedHat | |
hammer content-view add-repository --repository "Red Hat Satellite Utils 6.11 for RHEL 8 x86_64 RPMs" --product "Red Hat Enterprise Linux for x86_64" --name TestCV --organization RedHat | |
hammer content-view publish --name TestCV --organization RedHat | |
hammer content-view version promote --from-lifecycle-environment Library --to-lifecycle-environment QA --content-view TestCV --organization RedHat | |
## Find out the modulmd artifacts to be deleted and delete them | |
echo "COPY(select ca.file from core_artifact ca LEFT JOIN core_contentartifact cca on cca.artifact_id = ca.pulp_id where cca.relative_path like '%snippet') TO STDOUT;" | su - postgres -c "psql pulpcore" &> /tmp/modules_to_delete | |
for i in `cat /tmp/modules_to_delete`; do FILE="/var/lib/pulp/media/$i"; if test -f $FILE; then echo "Deleting $FILE"; rm -f $FILE; else echo "$FILE is absent"; fi; done | |
rm -rf /tmp/modules_to_delete | |
## Find out the rpm artifacts to be deleted and delete them | |
echo "COPY(select ca.file from core_artifact ca LEFT JOIN core_contentartifact cca on cca.artifact_id = ca.pulp_id where cca.relative_path like '%katello%' or cca.relative_path like '%ansible-test%') TO STDOUT;" | su - postgres -c "psql pulpcore" &> /tmp/rpms_to_delete | |
for i in `cat /tmp/rpms_to_delete`; do FILE="/var/lib/pulp/media/$i"; if test -f $FILE; then echo "Deleting $FILE"; rm -f $FILE; else echo "$FILE is absent"; fi; done | |
rm -f /tmp/rpms_to_delete | |
## Find out the repodata artifacts to be deleted and delete them | |
echo "COPY(select ca.file from core_artifact ca LEFT JOIN core_contentartifact cca on cca.artifact_id = ca.pulp_id where cca.relative_path like '%repomd.xml' or cca.relative_path like '%primary.xml.gz') TO STDOUT;" | su - postgres -c "psql pulpcore" &> /tmp/repodata_to_delete | |
for i in `cat /tmp/repodata_to_delete`; do FILE="/var/lib/pulp/media/$i"; if test -f $FILE; then echo "Deleting $FILE"; rm -f $FILE; else echo "$FILE is absent"; fi; done | |
rm -f /tmp/repodata_to_delete | |
## Create and confiugre an activation key | |
hammer activation-key create --name AK --lifecycle-environment Library --content-view TestCV --auto-attach true --unlimited-hosts --organization RedHat | |
for i in `echo "COPY (select distinct kc.label as repo_label from katello_root_repositories krr, katello_contents as kc where krr.content_id=kc.cp_content_id and kc.label like '%rhel-7%') TO STDOUT WITH CSV;" | su - postgres -c "psql foreman"`; do echo "Enabling $i in the AK"; hammer activation-key content-override --name AK --content-label $i --override-name 'enabled' --value 1 --organization RedHat; done | |
## Try exporting any of the repos: | |
hammer content-export complete repository --name "Red Hat Satellite Utils 6.11 for RHEL 8 x86_64 RPMs" --product "Red Hat Enterprise Linux for x86_64" --organization RedHat | |
## Try exporting any CV version: | |
hammer content-export complete version --content-view TestCV --lifecycle-environment Library --organization RedHat | |
echo "Done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Results:
The repository export will fail with this error:
The CV version export will fail with this error:
Connect an RHEL 7 client system with the satellite, and associate with TestCV content-view and Library environment. Then
yum clean all && yum repolist
fails with the following error: