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

Create last_update_export.py #23

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

Conversation

josephoaks
Copy link

This script is designed for use in a "disconnect" environment. The host server is to do daily exports based on last build of a channel. This script looks at the list of channels, gets the ChannelLastBuildByID and checks if the date is the current date or prior and then exports that channel.

Logging is provided as well to show which channels were updated in that export.

The target server can then rsync the /mnt/export directory and run another script to execute the inter-server-sync import of the exported data.

This script is designed for use in a "disconnect" environment. The host server is to do daily exports based on last build of a channel. This script looks at the list of channels, gets the ChannelLastBuildByID and checks if the date is the current date or prior and then exports that channel.

Logging is provided as well to show which channels were updated in that export. 

The target server can then rsync the `/mnt/export` directory and run another script to execute the inter-server-sync import of the exported data.
@juliogonzalez juliogonzalez requested review from a team and meaksh and removed request for a team April 12, 2024 07:55
Copy link
Member

@meaksh meaksh left a comment

Choose a reason for hiding this comment

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

Thanks for this contribution!

I've added few comments that I hope it helps to get the script in shape to get merged.

uyuni-tools/last_update_export.py Show resolved Hide resolved
uyuni-tools/last_update_export.py Outdated Show resolved Hide resolved
uyuni-tools/last_update_export.py Outdated Show resolved Hide resolved
uyuni-tools/last_update_export.py Outdated Show resolved Hide resolved
Updates from the source since uploading to uyuni-tools, multiple iterations to streamline have occured.

Updates include fixes from comments and further use, which include...
1) script header
2) better path management and configurable parameters
3) use of shutil.rmtree avoiding extra calls to subprocess
4) configurable days for export
5) configurable user/group
6) added the use of mgr-sycn credentials file instead of using username/password in the script.
Copy link
Member

@meaksh meaksh left a comment

Choose a reason for hiding this comment

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

Thanks for the changes! This is looking better now! Still I added some comments after your latest changes, maybe you can have a look.

Comment on lines 63 to 70
# Configuration Variables
base_dir = "/mnt" # Define base directory where the exports will be.
output_dir = os.path.join(base_dir, "export/updates")
log_dir = os.path.join(base_dir, "logs")
today = datetime.date.today()
target_date = today - datetime.timedelta(days=1) # Define the number of days back for export, 1 day by default
rsync_user = "rsyncuser" # Define rsync user
rsync_group = "users" # Define rsync group
Copy link
Member

Choose a reason for hiding this comment

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

OTOH these ones I would move them to the top of the file (below imports statements and before functions definition), as user is expected to modify them.

I'd also suggest to use uppercase notation (constants) for those.

Comment on lines 55 to 61
MANAGER_LOGIN = config.get('DEFAULT', 'mgrsync.user')
MANAGER_PASSWORD = config.get('DEFAULT', 'mgrsync.password')
SUMA_FQDN = socket.getfqdn()
MANAGER_URL = f"https://{SUMA_FQDN}/rpc/api"
context = ssl.create_default_context()
client = ServerProxy(MANAGER_URL, context=context)
return client, client.auth.login(MANAGER_LOGIN, MANAGER_PASSWORD)
Copy link
Member

Choose a reason for hiding this comment

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

I would suggest to not use the uppercase notation here, as these values are not hardcoded anymore, and contants are usually defined at the top level of the file.

Maybe just go with something like:

Suggested change
MANAGER_LOGIN = config.get('DEFAULT', 'mgrsync.user')
MANAGER_PASSWORD = config.get('DEFAULT', 'mgrsync.password')
SUMA_FQDN = socket.getfqdn()
MANAGER_URL = f"https://{SUMA_FQDN}/rpc/api"
context = ssl.create_default_context()
client = ServerProxy(MANAGER_URL, context=context)
return client, client.auth.login(MANAGER_LOGIN, MANAGER_PASSWORD)
manager_login = config.get('DEFAULT', 'mgrsync.user')
manager_password = config.get('DEFAULT', 'mgrsync.password')
suma_fqdn = socket.getfqdn()
manager_url = f"https://{suma_fqdn}/rpc/api"
context = ssl.create_default_context()
client = ServerProxy(manager_url, context=context)
return client, client.auth.login(manager_login, manager_password)

Choose a reason for hiding this comment

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

modified.

updated the constants and variables, and changed the order they appear in the script
caught the datetime.date.today()
uyuni-tools/last_update_export.py Outdated Show resolved Hide resolved
uyuni-tools/last_update_export.py Outdated Show resolved Hide resolved
josephoaks and others added 3 commits April 19, 2024 07:09
Co-authored-by: Pablo Suárez Hernández <[email protected]>
removed the shell=True from the subprocess.run command, missed that from the last commit after updating the command
Fixed the shebang line
uyuni-tools/last_update_export.py Outdated Show resolved Hide resolved
fixed the command execution
updated script header to be better formatted and easier to read.
This file is part of the last_update_export.py script put forward. 
This file is for the initial export using the ISSv2 used in a disconnected or air-gapped environment, to do a full export instead of an incremental export as the last_update_export.py, it can also be used to add a new product channel to an air-gapped system.
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.

3 participants