Skip to content
This repository was archived by the owner on Nov 14, 2022. It is now read-only.

Commit 41e3bf9

Browse files
author
Dimitar Tasev
authored
Merge pull request #1261 from ISISScientificComputing/1260_reduction_host
2 parents b0a6ee1 + e9058a6 commit 41e3bf9

File tree

12 files changed

+59
-31
lines changed

12 files changed

+59
-31
lines changed

WebApp/autoreduce_webapp/autoreduce_webapp/fixtures/run_with_one_variable.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
[
2-
{
1+
[{
32
"model": "reduction_viewer.reductionrun",
43
"pk": 1,
54
"fields": {
@@ -14,7 +13,8 @@
1413
"hidden_in_failviewer": 0,
1514
"experiment_id": 1,
1615
"instrument_id": 1,
17-
"started_by": -1
16+
"started_by": -1,
17+
"reduction_host": "test-host-123"
1818
}
1919
},
2020
{
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 3.1.2 on 2021-03-29 09:39
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('reduction_viewer', '0005_auto_20210326_1628'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='reductionrun',
15+
name='reduction_host',
16+
field=models.TextField(blank=True, default='', verbose_name='Reduction hostname'),
17+
),
18+
]

WebApp/autoreduce_webapp/reduction_viewer/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ class ReductionRun(models.Model):
107107
graph = models.TextField(null=True, blank=True)
108108
message = models.TextField(null=True, blank=True)
109109
reduction_log = models.TextField(blank=True)
110+
reduction_host = models.TextField(default="", blank=True, verbose_name="Reduction hostname")
110111
# Scripts should be 100,000 chars or less. The DB supports up to 4GB strings here
111112
script = models.TextField(blank=False, validators=[MaxLengthValidator(100000)])
112113

WebApp/autoreduce_webapp/selenium_tests/pages/run_summary_page.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ def last_updated_text(self) -> str:
117117
"""
118118
return self.driver.find_element_by_id("last_updated").text
119119

120+
def reduction_host_text(self) -> WebElement:
121+
"""
122+
Returns the reduction host text
123+
"""
124+
return self.driver.find_element_by_id("reduction_host").text
125+
120126
def images(self) -> List[WebElement]:
121127
"""
122128
Returns all image elements on the page.

WebApp/autoreduce_webapp/selenium_tests/tests/test_run_summary.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ def test_reduction_job_panel_displayed(self):
101101
assert self.page.instrument_text() == f"Instrument: {run.instrument.name}"
102102
assert self.page.rb_number_text() == f"RB Number: {run.experiment.reference_number}"
103103
assert self.page.last_updated_text() == "Last Updated: 19 Oct 2020, 6:35 p.m."
104+
assert self.page.reduction_host_text() == "Host:test-host-123"
104105

105106
def test_reduction_job_panel_reset_to_values_first_used_for_run(self):
106107
"""Test that the button to reset the variables to the values first used for the run works"""

WebApp/autoreduce_webapp/templates/run_summary.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ <h2>Reduction Job #{{ run.title }}</h2>
142142
<em>No software data found</em>
143143
{% endif %}
144144
</div>
145+
<div id="reduction_host"><strong>Host:</strong>{{ run.reduction_host }}</div>
145146
</div>
146147
</div>
147148
<div class="row">

model/database/records.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,22 @@
99
Contains various helper methods for managing or creating ORM records
1010
"""
1111

12-
import datetime
13-
import model.database.access
12+
import socket
13+
from django.utils import timezone
1414

1515

16-
def create_reduction_run_record(experiment, instrument, message, run_version, script_text, status):
16+
def create_reduction_run_record(experiment, instrument, message, run_version, script_text, status, db_handle=None):
1717
"""
1818
Creates an ORM record for the given reduction run and returns
1919
this record without saving it to the DB
2020
"""
21-
db_handle = model.database.access.start_database()
21+
if not db_handle:
22+
# pylint:disable=import-outside-toplevel
23+
import model.database.access
24+
db_handle = model.database.access.start_database()
25+
2226
data_model = db_handle.data_model
23-
time_now = datetime.datetime.utcnow()
27+
time_now = timezone.now()
2428
reduction_run = data_model.ReductionRun(run_number=message.run_number,
2529
run_version=run_version,
2630
run_description=message.description,
@@ -33,5 +37,6 @@ def create_reduction_run_record(experiment, instrument, message, run_version, sc
3337
instrument=instrument,
3438
status_id=status.id,
3539
script=script_text,
36-
started_by=message.started_by)
40+
started_by=message.started_by,
41+
reduction_host=socket.getfqdn())
3742
return reduction_run

model/database/tests/test_records.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
Unit tests for the record helper module
1010
"""
1111

12+
import socket
1213
from unittest import TestCase, mock
1314
import model.database.records as records
1415

@@ -32,9 +33,8 @@ def test_create_reduction_record_starts_db(db_layer):
3233
db_layer.start_database.return_value.data_model\
3334
.ReductionRun.assert_called_once()
3435

35-
@mock.patch("model.database.access")
36-
@mock.patch("datetime.datetime")
37-
def test_create_reduction_record_forwards_correctly(self, datetime_patch, db_layer):
36+
@mock.patch("model.database.records.timezone")
37+
def test_create_reduction_record_forwards_correctly(self, timezone_mock):
3838
"""
3939
Test: Reduction Record uses args correctly.
4040
Any fields which are hard-coded are mocked with ANY to prevent
@@ -50,22 +50,23 @@ def test_create_reduction_record_forwards_correctly(self, datetime_patch, db_lay
5050
mock_script_text = mock.NonCallableMock()
5151
mock_status = mock.NonCallableMock()
5252

53-
returned = records.create_reduction_run_record(experiment=mock_experiment,
54-
instrument=mock_inst,
55-
message=mock_msg,
56-
run_version=mock_run_version,
57-
script_text=mock_script_text,
58-
status=mock_status)
53+
with mock.patch("model.database") as db_layer:
54+
returned = records.create_reduction_run_record(experiment=mock_experiment,
55+
instrument=mock_inst,
56+
message=mock_msg,
57+
run_version=mock_run_version,
58+
script_text=mock_script_text,
59+
status=mock_status)
5960

60-
mock_record_orm = db_layer.start_database.return_value.data_model
61+
mock_record_orm = db_layer.access.start_database.return_value.data_model
6162

6263
self.assertEqual(mock_record_orm.ReductionRun.return_value, returned)
6364

6465
mock_record_orm.ReductionRun.assert_called_once_with(
6566
run_number=mock_msg.run_number,
6667
run_version=mock_run_version,
67-
created=datetime_patch.utcnow.return_value,
68-
last_updated=datetime_patch.utcnow.return_value,
68+
created=timezone_mock.now.return_value,
69+
last_updated=timezone_mock.now.return_value,
6970
experiment=mock_experiment,
7071
instrument=mock_inst,
7172
status_id=mock_status.id,
@@ -75,4 +76,5 @@ def test_create_reduction_record_forwards_correctly(self, datetime_patch, db_lay
7576
run_description=mock.ANY,
7677
hidden_in_failviewer=mock.ANY,
7778
admin_log=mock.ANY,
78-
reduction_log=mock.ANY)
79+
reduction_log=mock.ANY,
80+
reduction_host=socket.getfqdn())

queue_processors/queue_processor/handle_message.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
update relevant DB fields or logging out the status.
1414
"""
1515
import logging
16-
import socket
1716
from contextlib import contextmanager
1817
from typing import Optional
1918
from django.db import transaction
@@ -133,7 +132,8 @@ def do_create_reduction_record(self, message: Message, experiment, instrument):
133132
message=message,
134133
run_version=message.run_version,
135134
script_text=script_text,
136-
status=self.status.get_queued())
135+
status=self.status.get_queued(),
136+
db_handle=self.database)
137137
reduction_run.save()
138138

139139
# Create a new data location entry which has a foreign key linking it to the current
@@ -277,7 +277,6 @@ def _common_reduction_run_update(reduction_run, status, message):
277277
reduction_run.finished = timezone.now()
278278
reduction_run.message = message.message
279279
reduction_run.reduction_log = message.reduction_log
280-
message.admin_log += "Running on host: %s" % socket.getfqdn()
281280
reduction_run.admin_log = message.admin_log
282281

283282
@staticmethod

queue_processors/queue_processor/reduction/runner.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import io
1111
import logging
12-
import socket
1312
import sys
1413
import traceback
1514

@@ -61,7 +60,6 @@ def reduce(self):
6160
def _do_reduce(self):
6261
"""Actually do the reduction job."""
6362
self.message.software = self._get_mantid_version()
64-
logger.info("Running on host: %s", socket.gethostname())
6563
if self.message.description is not None:
6664
logger.info("DESCRIPTION: %s", self.message.description)
6765

0 commit comments

Comments
 (0)