[Bug 2024505] Re: Change encoding to use the system locale instead of ascii
Lena Voytek
2024505 at bugs.launchpad.net
Tue Jun 20 22:41:05 UTC 2023
** Also affects: ec2-hibinit-agent (Ubuntu Mantic)
Importance: Undecided
Status: New
** Also affects: ec2-hibinit-agent (Ubuntu Lunar)
Importance: Undecided
Status: New
** Also affects: ec2-hibinit-agent (Ubuntu Jammy)
Importance: Undecided
Status: New
** Also affects: ec2-hibinit-agent (Ubuntu Focal)
Importance: Undecided
Status: New
** Also affects: ec2-hibinit-agent (Ubuntu Kinetic)
Importance: Undecided
Status: New
--
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to ec2-hibinit-agent in Ubuntu.
https://bugs.launchpad.net/bugs/2024505
Title:
Change encoding to use the system locale instead of ascii
Status in ec2-hibinit-agent package in Ubuntu:
New
Status in ec2-hibinit-agent source package in Focal:
New
Status in ec2-hibinit-agent source package in Jammy:
New
Status in ec2-hibinit-agent source package in Kinetic:
New
Status in ec2-hibinit-agent source package in Lunar:
New
Status in ec2-hibinit-agent source package in Mantic:
New
Bug description:
[Impact]
Some Locale will cause hibinit-agent to error out because the script tries to decode using ASCII. An example would be the russian locale ru_RU.UTF-8
[Fix]
One line fix from upstream - https://github.com/aws/amazon-ec2-hibinit-agent/commit/2392e860c7a75c2b61baef749bb90e79a2a3e81e
[Test Case]
1. Create an EC2 instance
AWS_REGION="eu-north-1"
AWS_AMI="ami-07ca74b1a97901682"
AWS_KEY="your key name"
AWS_SECURITY_GROUP="security instance that allows ssh from anywhere"
aws ec2 run-instances \
--region ${AWS_REGION} \
--image-id ${AWS_AMI} \
--count 1 \
--instance-type t3.micro \
--key-name ${AWS_KEY} \
--metadata-options "HttpTokens=required" \
--security-group-ids ${AWS_SECURITY_GROUP} \
--tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=focal-test-hibinit}]' \
--block-device-mappings '[{"DeviceName":"/dev/sda1","Ebs":{"Encrypted":true,"DeleteOnTermination":true,"VolumeSize":8,"VolumeType":"gp2"}}]' \
--hibernation-options 'Configured=true'
2. SSH into instance
3. install russian language and set locale
$ sudo apt install -y language-pack-ru
$ export LC_ALL=ru_RU.UTF-8
4. Attempt to use hibinit-agent
$ sudo /usr/bin/hibinit-agent
Traceback (most recent call last):
File "/usr/bin/hibinit-agent", line 269, in swap_needs_touch
dev = find_device_for_file(swap_place)
File "/usr/bin/hibinit-agent", line 148, in find_device_for_file
df_out = check_output(['df', '-P', filename]).decode('ascii')
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 0: ordinal not in range(128)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/bin/hibinit-agent", line 480, in <module>
main()
File "/usr/bin/hibinit-agent", line 413, in main
config = Config(config_file, args)
File "/usr/bin/hibinit-agent", line 309, in __init__
swap_needs_touch(SWAP_FILE))
File "/usr/bin/hibinit-agent", line 273, in swap_needs_touch
raise Exception("Failed to find the filesystem type of /")
Exception: Failed to find the filesystem type of /
When fixed, the results should look like:
$ sudo /usr/bin/hibinit-agent
Effective config: {'log_to_syslog': True, 'log_to_stderr': True, 'mkswap': 'mkswap {swapfile}', 'swapon': 'swapon {swapfile}', 'swapoff': 'swapoff {swapfile}', 'touch_swap': False, 'grub_update': True, 'swap_percentage': 100, 'swap_mb': 4000, 'state_dir': '/var/lib/hibinit-agent'}
Requesting new IMDSv2 token.
Hibernation Configured Flag found
Will check if swap is at least: 4000 megabytes
There's sufficient swap available (have 4194304000, need 4194304000)
Running: swapon /swap-hibinit
Updating the kernel offset for the swapfile: /swap-hibinit
Setting swap device to 66305 with offset 1017856
Done updating the swap offset. Turning swapoff
Running: swapoff /swap-hibinit
[ Where things can go wrong ]
This now relies on the Python sys.getfilesystemencoding() to provide the correct value. However this is a standard library function so it is most likely very robust.
To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/ec2-hibinit-agent/+bug/2024505/+subscriptions
More information about the foundations-bugs
mailing list