Skip to content

Instantly share code, notes, and snippets.

@sayan3296
Last active January 13, 2023 12:16
Show Gist options
  • Save sayan3296/0f765e21eaec0651b0e9a6ae078a7dea to your computer and use it in GitHub Desktop.
Save sayan3296/0f765e21eaec0651b0e9a6ae078a7dea to your computer and use it in GitHub Desktop.
#!/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"
@sayan3296
Copy link
Author

sayan3296 commented Oct 11, 2022

Results:

The repository export will fail with this error:

# 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
[................................................................................................................................................................] [100%]
Error: [Errno 2] No such file or directory: '/var/lib/pulp/media/artifact/5b/222199341380f1665e59edde94bd199079e687581a782526264ad1a2358711'
undefined method `first' for nil:NilClass

The CV version export will fail with this error:

# hammer content-export complete version --content-view TestCV --lifecycle-environment Library --organization RedHat
[................................................................................................................................................................] [100%]
Error: [Errno 2] No such file or directory: '/var/lib/pulp/media/artifact/33/40cb25558cdc483a49ecc907f411cd235c0701046bb61618909e6781f3740c'
undefined method `first' for nil:NilClass

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:

# yum repolist
Loaded plugins: enabled_repos_upload, package_upload, product-id, search-disabled-repos, subscription-manager, tracer_upload
https://satellite.example.com/pulp/content/RedHat/Library/TestCV/content/dist/rhel/server/7/7Server/x86_64/ansible/2.9/os/repodata/repomd.xml: [Errno 14] HTTPS Error 502 - Bad Gateway
Trying other mirror.
https://satellite.example.com/pulp/content/RedHat/Library/TestCV/content/dist/rhel/server/7/7Server/x86_64/ansible/2.9/os/repodata/repomd.xml: [Errno 14] HTTPS Error 502 - Bad Gateway
Trying other mirror.
https://satellite.example.com/pulp/content/RedHat/Library/TestCV/content/dist/rhel/server/7/7Server/x86_64/sat-tools/6.9/os/repodata/repomd.xml: [Errno 14] HTTPS Error 502 - Bad Gateway
Trying other mirror.
repo id                                                              repo name                                                                                     status
rhel-7-server-ansible-2.9-rpms/x86_64                                Red Hat Ansible Engine 2.9 RPMs for Red Hat Enterprise Linux 7 Server                         0
rhel-7-server-satellite-tools-6.9-rpms/x86_64                        Red Hat Satellite Tools 6.9 (for RHEL 7 Server) (RPMs)                                        0
repolist: 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment