Merge ~mitchdz/ubuntu/+source/hibagent:mitch/lunar-imdsv2 into ubuntu/+source/hibagent:ubuntu/lunar-devel

Proposed by Mitchell Dzurick
Status: Merged
Merge reported by: Mitchell Dzurick
Merged at revision: b39ef9e02e0bfc36b5eac7ee437676a063f7fd92
Proposed branch: ~mitchdz/ubuntu/+source/hibagent:mitch/lunar-imdsv2
Merge into: ubuntu/+source/hibagent:ubuntu/lunar-devel
Diff against target: 121 lines (+88/-0)
4 files modified
debian/changelog (+9/-0)
debian/control (+1/-0)
debian/patches/do-nothing-if-ODH-is-configured.patch (+77/-0)
debian/patches/series (+1/-0)
Reviewer Review Type Date Requested Status
git-ubuntu import Pending
Review via email: mp+455811@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/debian/changelog b/debian/changelog
2index 3c8851c..d07d2fa 100644
3--- a/debian/changelog
4+++ b/debian/changelog
5@@ -1,3 +1,12 @@
6+hibagent (1.0.1+git20230216.9ac1209f7-0ubuntu1.23.04.1) lunar; urgency=medium
7+
8+ * d/p/do-nothing-if-ODH-is-configured.patch: do nothing if ODH is configured,
9+ this fixes an issue when this package and ec2-hibinit-agent are installed
10+ and configured at the same time (LP: #2043739).
11+ * d/control: add python3-requests as Depends.
12+
13+ -- Mitchell Dzurick <mitchell.dzurick@canonical.com> Thu, 16 Nov 2023 15:35:33 -0700
14+
15 hibagent (1.0.1+git20230216.9ac1209f7-0ubuntu1) lunar; urgency=medium
16
17 * New upstream snapshot from their `ubuntu` branch (LP: #1896638)
18diff --git a/debian/control b/debian/control
19index 60fac58..eb13a13 100644
20--- a/debian/control
21+++ b/debian/control
22@@ -7,6 +7,7 @@ Build-Depends: debhelper (>= 9),
23 dh-python,
24 python3-all,
25 python3-pytest,
26+ python3-requests,
27 python3-setuptools
28 Standards-Version: 3.9.6
29
30diff --git a/debian/patches/do-nothing-if-ODH-is-configured.patch b/debian/patches/do-nothing-if-ODH-is-configured.patch
31new file mode 100644
32index 0000000..8be4ec2
33--- /dev/null
34+++ b/debian/patches/do-nothing-if-ODH-is-configured.patch
35@@ -0,0 +1,77 @@
36+Description: Update the Spot hibernate agent to do nothing if ODH is configured
37+Author: Jeongin Cho <achojeon@amazon.com>
38+Origin: upstream, https://github.com/aws/ec2-hibernate-linux-agent/commit/2ee4ae3fd1333fb3c9aab25bf02b109c3b7b8d9f
39+Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/hibagent/+bug/2043739
40+Last-Update: 2023-11-16
41+---
42+This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
43+--- a/agent/hibagent
44++++ b/agent/hibagent
45+@@ -18,6 +18,7 @@
46+ import struct
47+ import sys
48+ import syslog
49++import requests
50+ from subprocess import check_call, check_output
51+ from threading import Thread
52+ from math import ceil
53+@@ -39,6 +40,9 @@
54+ log_to_syslog = True
55+ log_to_stderr = True
56+
57++IMDS_BASEURL = 'http://169.254.169.254'
58++IMDS_API_TOKEN_PATH = 'latest/api/token'
59++IMDS_SPOT_ACTION_PATH = 'latest/meta-data/hibernation/configured'
60+
61+ def log(message):
62+ if log_to_syslog:
63+@@ -511,6 +515,37 @@
64+ log("Failed to adjust pm_freeze_timeout to %d. Error: %s" % (timeout, str(e)))
65+ exit(1)
66+
67++def get_imds_token(seconds=21600):
68++ """ Get a token to access instance metadata. """
69++ log("Requesting new IMDSv2 token.")
70++ request_header = {'X-aws-ec2-metadata-token-ttl-seconds': '{}'.format(seconds)}
71++ token_url = '{}/{}'.format(IMDS_BASEURL, IMDS_API_TOKEN_PATH)
72++ response = requests.put(token_url, headers=request_header)
73++ response.close()
74++ if response.status_code != requests.codes.ok:
75++ return None
76++
77++ return response.text
78++
79++def hibernation_enabled():
80++ """Returns a boolean indicating whether hibernation-option.configured is enabled or not."""
81++
82++ imds_token = get_imds_token()
83++ if imds_token is None:
84++ log("IMDS_V2 http endpoint is disabled")
85++ # IMDS http endpoint is disabled
86++ return False
87++
88++ request_header = {'X-aws-ec2-metadata-token': imds_token}
89++ response = requests.get("{}/{}".format(IMDS_BASEURL, IMDS_SPOT_ACTION_PATH),
90++ headers=request_header)
91++ response.close()
92++ if response.status_code != requests.codes.ok or response.text.lower() == "false":
93++ return False
94++
95++ log("Hibernation Configured Flag found")
96++
97++ return True
98+
99+ def main():
100+ # Parse arguments
101+@@ -550,6 +585,11 @@
102+
103+ log("Effective config: %s" % config)
104+
105++ # Let's first check if we need to kill the Spot Hibernate Agent
106++ if hibernation_enabled():
107++ log("Spot Instance Launch has enabled Hibernation Configured Flag. hibagent exiting!!")
108++ exit(0)
109++
110+ target_swap_size = config.swap_mb * 1024 * 1024
111+ ram_bytes = os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES')
112+ swap_percentage_size = ram_bytes * config.swap_percentage // 100
113diff --git a/debian/patches/series b/debian/patches/series
114index 5568008..0b9774f 100644
115--- a/debian/patches/series
116+++ b/debian/patches/series
117@@ -9,3 +9,4 @@ fix-enable-ec2-spot-hibernation.patch
118 0009-Use-Thread.is_alive-for-Python-3.9-compatibility.patch
119 setuptools-fix-package-discovery.patch
120 disable-hibernate-test.patch
121+do-nothing-if-ODH-is-configured.patch

Subscribers

People subscribed via source and target branches