Merge ~hemanth-n/maas:lp1906212 into maas:master

Proposed by Hemanth Nakkina
Status: Merged
Approved by: Lee Trager
Approved revision: 229679bc3c599cd0be1d0e93c514072aff7e0789
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~hemanth-n/maas:lp1906212
Merge into: maas:master
Diff against target: 145 lines (+58/-9)
2 files modified
src/metadataserver/api.py (+4/-2)
src/metadataserver/tests/test_api.py (+54/-7)
Reviewer Review Type Date Requested Status
Lee Trager (community) Approve
MAAS Lander Approve
Hemanth Nakkina (community) Needs Resubmitting
Dougal Matthews (community) Needs Fixing
Review via email: mp+394615@code.launchpad.net

Commit message

improper conversion of timeout to seconds

Description of the change

In commissiong/testing scripts, timeout_seconds is derived from the timeout datetime object. The conversion gathered just the seconds and ignored the days.

Using the function timeout_seconds() of the datetime object resolves the problem.

To post a comment you must log in.
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b lp1906212 lp:~hemanth-n/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/8783/console
COMMIT: 0e4a5512852ed1cbf956643b7fd37d1897f96927

review: Needs Fixing
Revision history for this message
Adam Collard (adam-collard) wrote :

jenkins: !test

Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b lp1906212 lp:~hemanth-n/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 0e4a5512852ed1cbf956643b7fd37d1897f96927

review: Approve
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b lp1906212 lp:~hemanth-n/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: b4630a193b89faf4baf7c81edaa038e7063a75ef

review: Approve
Revision history for this message
Adam Collard (adam-collard) wrote :

Can you please add a test for this? The change looks good (thank you!) just needs an example in the tests where timeout > 24h

Revision history for this message
Dougal Matthews (d0ugal) wrote :

Agreed, a test for this would be good.

review: Needs Fixing
Revision history for this message
Hemanth Nakkina (hemanth-n) wrote :

Added test cases. Modified commissioning script under src/metadataserver/builtin_scripts/ with an assumption the scripts are only used for unit/functional tests. Correct me if i am wrong.

review: Needs Resubmitting
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b lp1906212 lp:~hemanth-n/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: FAILED
LOG: http://maas-ci.internal:8080/job/maas/job/branch-tester/8892/console
COMMIT: 464a7436c2320731f21807a7b16644152dbbd9b6

review: Needs Fixing
Revision history for this message
Hemanth Nakkina (hemanth-n) wrote :

Reverted back previous patch since the builtin scripts should not be changed for unit/functional tests

Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b lp1906212 lp:~hemanth-n/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: e00de0d52a067bae08b3eb68a9fb3855a83669a7

review: Approve
Revision history for this message
Hemanth Nakkina (hemanth-n) wrote :

Test case added, please review

review: Needs Resubmitting
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b lp1906212 lp:~hemanth-n/maas/+git/maas into -b master lp:~maas-committers/maas

STATUS: SUCCESS
COMMIT: 229679bc3c599cd0be1d0e93c514072aff7e0789

review: Approve
Revision history for this message
Lee Trager (ltrager) wrote :

Thanks for the fix!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/metadataserver/api.py b/src/metadataserver/api.py
2index f3e82c9..f59f973 100644
3--- a/src/metadataserver/api.py
4+++ b/src/metadataserver/api.py
5@@ -1197,7 +1197,7 @@ class AnonMAASScriptsHandler(AnonymousOperationsHandler):
6 "name": script.name,
7 "path": path,
8 "script_version_id": script.script.id,
9- "timeout_seconds": script.timeout.seconds,
10+ "timeout_seconds": script.timeout.total_seconds(),
11 "parallel": script.parallel,
12 "hardware_type": script.hardware_type,
13 "parameters": parameters,
14@@ -1248,7 +1248,9 @@ class MAASScriptsHandler(OperationsHandler):
15 "path": path,
16 "script_result_id": script_result.id,
17 "script_version_id": script_result.script.script.id,
18- "timeout_seconds": script_result.script.timeout.seconds,
19+ "timeout_seconds": (
20+ script_result.script.timeout.total_seconds()
21+ ),
22 "parallel": script_result.script.parallel,
23 "hardware_type": script_result.script.hardware_type,
24 "parameters": script_result.parameters,
25diff --git a/src/metadataserver/tests/test_api.py b/src/metadataserver/tests/test_api.py
26index 85bc9fa..62cd333 100644
27--- a/src/metadataserver/tests/test_api.py
28+++ b/src/metadataserver/tests/test_api.py
29@@ -6,7 +6,7 @@
30
31 import base64
32 from collections import namedtuple
33-from datetime import datetime
34+from datetime import datetime, timedelta
35 import http.client
36 from io import BytesIO
37 import json
38@@ -1446,7 +1446,7 @@ class TestMAASScripts(MAASServerTestCase):
39 if script_result.script is None:
40 script = NODE_INFO_SCRIPTS[script_result.name]
41 content = script["content"]
42- md_item["timeout_seconds"] = script["timeout"].seconds
43+ md_item["timeout_seconds"] = script["timeout"].total_seconds()
44 md_item["parallel"] = script.get(
45 "parallel", SCRIPT_PARALLEL.DISABLED
46 )
47@@ -1463,7 +1463,7 @@ class TestMAASScripts(MAASServerTestCase):
48 md_item["script_version_id"] = script_result.script.script.id
49 md_item[
50 "timeout_seconds"
51- ] = script_result.script.timeout.seconds
52+ ] = script_result.script.timeout.total_seconds()
53 md_item["parallel"] = script_result.script.parallel
54 md_item["hardware_type"] = script_result.script.hardware_type
55 md_item["parameters"] = script_result.parameters
56@@ -1581,7 +1581,7 @@ class TestMAASScripts(MAASServerTestCase):
57 "name": script.name,
58 "path": path,
59 "script_version_id": script.script.id,
60- "timeout_seconds": script.timeout.seconds,
61+ "timeout_seconds": script.timeout.total_seconds(),
62 "parallel": script.parallel,
63 "hardware_type": script.hardware_type,
64 "parameters": parameters,
65@@ -1635,7 +1635,7 @@ class TestMAASScripts(MAASServerTestCase):
66 "name": script.name,
67 "path": path,
68 "script_version_id": script.script.id,
69- "timeout_seconds": script.timeout.seconds,
70+ "timeout_seconds": script.timeout.total_seconds(),
71 "parallel": script.parallel,
72 "hardware_type": script.hardware_type,
73 "parameters": parameters,
74@@ -1707,7 +1707,7 @@ class TestMAASScripts(MAASServerTestCase):
75 "name": script.name,
76 "path": path,
77 "script_version_id": script.script.id,
78- "timeout_seconds": script.timeout.seconds,
79+ "timeout_seconds": script.timeout.total_seconds(),
80 "parallel": script.parallel,
81 "hardware_type": script.hardware_type,
82 "parameters": parameters,
83@@ -2049,7 +2049,9 @@ class TestMAASScripts(MAASServerTestCase):
84 ),
85 "script_result_id": script_result.id,
86 "script_version_id": script_result.script.script.id,
87- "timeout_seconds": script_result.script.timeout.seconds,
88+ "timeout_seconds": (
89+ script_result.script.timeout.total_seconds()
90+ ),
91 "parallel": script_result.script.parallel,
92 "hardware_type": script_result.script.hardware_type,
93 "parameters": script_result.parameters,
94@@ -2262,6 +2264,51 @@ class TestMAASScripts(MAASServerTestCase):
95 % (response.status_code, response.content),
96 )
97
98+ def test_scripts_with_timeout_greater_than_24_hours(self):
99+ start_time = floor(time.time())
100+ node = factory.make_Node(
101+ status=NODE_STATUS.TESTING, with_empty_script_sets=True
102+ )
103+ # Make script timeout value to 24:05:00
104+ timeout = timedelta(days=1, seconds=600)
105+ script = factory.make_Script(
106+ script_type=SCRIPT_TYPE.TESTING, timeout=timeout
107+ )
108+ factory.make_ScriptResult(
109+ script_set=node.current_testing_script_set,
110+ script=script,
111+ status=SCRIPT_STATUS.PENDING,
112+ )
113+ response = make_node_client(node=node).get(
114+ reverse("maas-scripts", args=["latest"])
115+ )
116+
117+ tar = tarfile.open(mode="r", fileobj=BytesIO(response.content))
118+ end_time = ceil(time.time())
119+
120+ testing_meta_data = self.validate_scripts(
121+ node.current_testing_script_set,
122+ "testing",
123+ tar,
124+ start_time,
125+ end_time,
126+ )
127+ meta_data = json.loads(
128+ tar.extractfile("index.json").read().decode("utf-8")
129+ )
130+ # Assertion should fail if timeout conversions are improper
131+ self.assertDictEqual(
132+ {
133+ "1.0": {
134+ "testing_scripts": sorted(
135+ testing_meta_data,
136+ key=itemgetter("name", "script_result_id"),
137+ ),
138+ }
139+ },
140+ meta_data,
141+ )
142+
143
144 class TestCommissioningAPI(MAASServerTestCase):
145 def setUp(self):

Subscribers

People subscribed via source and target branches