Merge ~pwlars/testflinger-agent:handle-other-offline-files into testflinger-agent:master

Proposed by Paul Larson
Status: Merged
Approved by: Paul Larson
Approved revision: c28be47a5b21408d504f9d21e23fdcd6117da261
Merged at revision: be132357925074940c86bdc6cfd3edbed9a60cb8
Proposed branch: ~pwlars/testflinger-agent:handle-other-offline-files
Merge into: testflinger-agent:master
Diff against target: 105 lines (+30/-16)
4 files modified
.gitignore (+7/-1)
testflinger_agent/__init__.py (+3/-3)
testflinger_agent/agent.py (+19/-11)
testflinger_agent/tests/test_agent.py (+1/-1)
Reviewer Review Type Date Requested Status
Paul Larson Approve
Devices Certification Bot Needs Fixing
Maciej Kisielewski (community) Approve
Review via email: mp+391006@code.launchpad.net

Commit message

handle offline files correctly, regardless of whether they look like "rpi3001" or "rpi3-001" because now sometimes the unit name may be different from the device name

To post a comment you must log in.
Revision history for this message
Maciej Kisielewski (kissiel) wrote :

LGTM, +1

review: Approve
Revision history for this message
Devices Certification Bot (ce-certification-qa) wrote :
Download full text (22.5 KiB)

The merge was fine but running tests failed.

Already using interpreter /usr/bin/python3
running pytest
Searching for voluptuous
Reading https://pypi.org/simple/voluptuous/
Downloading https://files.pythonhosted.org/packages/d3/e9/861cec3f4da0728d9d085db9c338b598351cbacb10521c25f0857f55c6d4/voluptuous-0.12.0-py3-none-any.whl#sha256=0fff348a097c9a74f9f4a991d2cf01a6185780e997ad953bde49cb3efbb411be
Best match: voluptuous 0.12.0
Processing voluptuous-0.12.0-py3-none-any.whl
Installing voluptuous-0.12.0-py3-none-any.whl to /tmp/tmpBXdXTe/.eggs

Installed /tmp/tmpBXdXTe/.eggs/voluptuous-0.12.0-py3.5.egg
Searching for requests
Reading https://pypi.org/simple/requests/
Downloading https://files.pythonhosted.org/packages/45/1e/0c169c6a5381e241ba7404532c16a21d86ab872c9bed8bdcd4c423954103/requests-2.24.0-py2.py3-none-any.whl#sha256=fe75cc94a9443b9246fc7049224f75604b113c36acb93f87b80ed42c44cbb898
Best match: requests 2.24.0
Processing requests-2.24.0-py2.py3-none-any.whl
Installing requests-2.24.0-py2.py3-none-any.whl to /tmp/tmpBXdXTe/.eggs

Installed /tmp/tmpBXdXTe/.eggs/requests-2.24.0-py3.5.egg
Searching for PyYAML
Reading https://pypi.org/simple/PyYAML/
Downloading https://files.pythonhosted.org/packages/64/c2/b80047c7ac2478f9501676c988a5411ed5572f35d1beff9cae07d321512c/PyYAML-5.3.1.tar.gz#sha256=b8eac752c5e14d3eca0e6dd9199cd627518cb5ec06add0de9d32baeee6fe645d
Best match: PyYAML 5.3.1
Processing PyYAML-5.3.1.tar.gz
Writing /tmp/easy_install-rqzk5elf/PyYAML-5.3.1/setup.cfg
Running PyYAML-5.3.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-rqzk5elf/PyYAML-5.3.1/egg-dist-tmp-qudy2ri7
Moving PyYAML-5.3.1-py3.5-linux-x86_64.egg to /tmp/tmpBXdXTe/.eggs

Installed /tmp/tmpBXdXTe/.eggs/PyYAML-5.3.1-py3.5-linux-x86_64.egg
Searching for urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1
Reading https://pypi.org/simple/urllib3/
Downloading https://files.pythonhosted.org/packages/9f/f0/a391d1463ebb1b233795cabfc0ef38d3db4442339de68f847026199e69d7/urllib3-1.25.10-py2.py3-none-any.whl#sha256=e7983572181f5e1522d9c98453462384ee92a0be7fac5f1413a1e35c56cc0461
Best match: urllib3 1.25.10
Processing urllib3-1.25.10-py2.py3-none-any.whl
Installing urllib3-1.25.10-py2.py3-none-any.whl to /tmp/tmpBXdXTe/.eggs

Installed /tmp/tmpBXdXTe/.eggs/urllib3-1.25.10-py3.5.egg
Searching for idna<3,>=2.5
Reading https://pypi.org/simple/idna/
Downloading https://files.pythonhosted.org/packages/a2/38/928ddce2273eaa564f6f50de919327bf3a00f091b5baba8dfa9460f3a8a8/idna-2.10-py2.py3-none-any.whl#sha256=b97d804b1e9b523befed77c48dacec60e6dcb0b5391d57af6a65a312a90648c0
Best match: idna 2.10
Processing idna-2.10-py2.py3-none-any.whl
Installing idna-2.10-py2.py3-none-any.whl to /tmp/tmpBXdXTe/.eggs

Installed /tmp/tmpBXdXTe/.eggs/idna-2.10-py3.5.egg
Searching for chardet<4,>=3.0.2
Reading https://pypi.org/simple/chardet/
Downloading https://files.pythonhosted.org/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl#sha256=fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691
Best match: chardet 3.0.4
Processing chardet-3.0.4-py2.py3-none-any.whl
Installing chardet-3.0.4-py2.py3-none-any.whl to /tmp/tmpBXdXTe/.eggs

Installed /tmp/tmpB...

review: Needs Fixing
Revision history for this message
Paul Larson (pwlars) wrote :

Minor test fix needed since we change from real boolean return from check_offline to implied (now returns the offline file if it is marked offline, or '' if not)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/.gitignore b/.gitignore
2index c26700c..da344c1 100644
3--- a/.gitignore
4+++ b/.gitignore
5@@ -1,6 +1,12 @@
6+*~
7+.coverage
8+.vscode/
9+build/
10+env/
11 __pycache__/
12 *.py[cod]
13 *$py.class
14-env/
15 *.conf
16 *.egg*
17+*.bak
18+.swp
19diff --git a/testflinger_agent/__init__.py b/testflinger_agent/__init__.py
20index 230cffe..8cdf7ea 100644
21--- a/testflinger_agent/__init__.py
22+++ b/testflinger_agent/__init__.py
23@@ -34,11 +34,11 @@ def main():
24 client = TestflingerClient(config)
25 agent = TestflingerAgent(client)
26 while True:
27- if agent.check_offline():
28+ offline_file = agent.check_offline
29+ if offline_file:
30 logger.error("Agent %s is offline, not processing jobs! "
31 "Remove %s to resume processing" %
32- (config.get('agent_id'),
33- agent.get_offline_file()))
34+ (config.get('agent_id'), offline_file))
35 while agent.check_offline():
36 time.sleep(check_interval)
37 logger.info("Checking jobs")
38diff --git a/testflinger_agent/agent.py b/testflinger_agent/agent.py
39index f989a6f..659df63 100644
40--- a/testflinger_agent/agent.py
41+++ b/testflinger_agent/agent.py
42@@ -52,10 +52,17 @@ class TestflingerAgent:
43 def set_state(self, state):
44 self._state.value = state.encode('utf-8')
45
46- def get_offline_file(self):
47- return os.path.join(
48- '/tmp', 'TESTFLINGER-DEVICE-OFFLINE-{}'.format(
49- self.client.config.get('agent_id')))
50+ def get_offline_files(self):
51+ # Return possible restart filenames with and without dashes
52+ # i.e. support both:
53+ # TESTFLINGER-DEVICE-OFFLINE-devname-001
54+ # TESTFLINGER-DEVICE-OFFLINE-devname001
55+ agent = self.client.config.get('agent_id')
56+ files = [
57+ '/tmp/TESTFLINGER-DEVICE-OFFLINE-{}'.format(agent),
58+ '/tmp/TESTFLINGER-DEVICE-OFFLINE-{}'.format(agent.replace('-', ''))
59+ ]
60+ return files
61
62 def get_restart_files(self):
63 # Return possible restart filenames with and without dashes
64@@ -70,12 +77,13 @@ class TestflingerAgent:
65 return files
66
67 def check_offline(self):
68- if os.path.exists(self.get_offline_file()):
69- self.set_state('offline')
70- return True
71- else:
72- self.set_state('waiting')
73- return False
74+ possible_files = self.get_offline_files()
75+ for offline_file in possible_files:
76+ if os.path.exists(offline_file):
77+ self.set_state('offline')
78+ return offline_file
79+ self.set_state('waiting')
80+ return ''
81
82 def check_restart(self):
83 possible_files = self.get_restart_files()
84@@ -98,7 +106,7 @@ class TestflingerAgent:
85
86 def mark_device_offline(self):
87 # Create the offline file, this should work even if it exists
88- open(self.get_offline_file(), 'w').close()
89+ open(self.get_offline_files()[0], 'w').close()
90
91 def process_jobs(self):
92 """Coordinate checking for new jobs and handling them if they exists"""
93diff --git a/testflinger_agent/tests/test_agent.py b/testflinger_agent/tests/test_agent.py
94index 72cbfb3..496dbe3 100644
95--- a/testflinger_agent/tests/test_agent.py
96+++ b/testflinger_agent/tests/test_agent.py
97@@ -166,7 +166,7 @@ class TestClient:
98 text='{}')
99 m.post('http://127.0.0.1:8000/v1/job', json={'job_id': job_id})
100 agent.process_jobs()
101- assert(agent.check_offline() is True)
102+ assert(agent.check_offline())
103 # These are the args we would expect when it reposts the job
104 assert(m.last_request.json() == fake_job_data)
105 if os.path.exists(OFFLINE_FILE):

Subscribers

People subscribed via source and target branches