Browse Source

[11.0][MIG] Migrate dead_mans_switch_client to 11.0

- Model ir.cron has changed slightly
- urllib2 no longer exists in Python 3
- Strings given to urllib.requests.Request must be encoded as bytes
pull/1277/head
Atte Isopuro 7 years ago
committed by Miku Laitinen
parent
commit
a748e4a9cc
  1. 1
      dead_mans_switch_client/__init__.py
  2. 2
      dead_mans_switch_client/__manifest__.py
  3. 1
      dead_mans_switch_client/data/ir_actions.xml
  4. 5
      dead_mans_switch_client/data/ir_cron.xml
  5. 15
      dead_mans_switch_client/models/dead_mans_switch_client.py
  6. 1
      dead_mans_switch_client/tests/test_dead_mans_switch_client.py

1
dead_mans_switch_client/__init__.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# © 2015 Therp BV <http://therp.nl> # © 2015 Therp BV <http://therp.nl>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import models from . import models

2
dead_mans_switch_client/__manifest__.py

@ -4,7 +4,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{ {
"name": "Dead man's switch (client)", "name": "Dead man's switch (client)",
"version": "10.0.1.0.0",
"version": "11.0.1.0.0",
"author": "Therp BV, Odoo Community Association (OCA)", "author": "Therp BV, Odoo Community Association (OCA)",
"license": "AGPL-3", "license": "AGPL-3",
"category": "Monitoring", "category": "Monitoring",

1
dead_mans_switch_client/data/ir_actions.xml

@ -5,7 +5,6 @@
context="{'default_key': 'dead_mans_switch_client.url'}"/> context="{'default_key': 'dead_mans_switch_client.url'}"/>
<record id="todo_setup" model="ir.actions.todo"> <record id="todo_setup" model="ir.actions.todo">
<field name="name">Configure the dead man's switch server</field> <field name="name">Configure the dead man's switch server</field>
<field name="type">automatic</field>
<field name="action_id" ref="action_setup"/> <field name="action_id" ref="action_setup"/>
</record> </record>
</odoo> </odoo>

5
dead_mans_switch_client/data/ir_cron.xml

@ -5,7 +5,8 @@
<field name="interval_number">5</field> <field name="interval_number">5</field>
<field name="interval_type">minutes</field> <field name="interval_type">minutes</field>
<field name="numbercall">-1</field> <field name="numbercall">-1</field>
<field name="model">dead.mans.switch.client</field>
<field name="function">alive</field>
<field name="model_id" ref="dead_mans_switch_client.model_dead_mans_switch_client"/>
<field name="state">code</field>
<field name="code">model.alive()</field>
</record> </record>
</odoo> </odoo>

15
dead_mans_switch_client/models/dead_mans_switch_client.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# © 2015-2016 Therp BV <http://therp.nl> # © 2015-2016 Therp BV <http://therp.nl>
# © 2015 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis # © 2015 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis
# © 2017 Avoin.Systems - Miku Laitinen # © 2017 Avoin.Systems - Miku Laitinen
@ -10,7 +9,7 @@ try:
import psutil import psutil
except ImportError: # pragma: no cover except ImportError: # pragma: no cover
psutil = None psutil = None
import urllib2
import urllib
from odoo import api, models from odoo import api, models
from odoo.tools.config import config from odoo.tools.config import config
@ -72,15 +71,15 @@ class DeadMansSwitchClient(models.AbstractModel):
'dead_mans_switch_client.send_timeout', SEND_TIMEOUT) 'dead_mans_switch_client.send_timeout', SEND_TIMEOUT)
data = self._get_data() data = self._get_data()
logger.debug('sending %s', data) logger.debug('sending %s', data)
urllib2.urlopen(
urllib2.Request(
url,
json.dumps({
urllib.request.urlopen(
urllib.request.Request(
url=url,
data=json.dumps({
'jsonrpc': '2.0', 'jsonrpc': '2.0',
'method': 'call', 'method': 'call',
'params': data, 'params': data,
}),
{
}).encode('utf-8'),
headers={
'Content-Type': 'application/json', 'Content-Type': 'application/json',
}), }),
timeout=timeout) timeout=timeout)

1
dead_mans_switch_client/tests/test_dead_mans_switch_client.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# © 2015 Therp BV <http://therp.nl> # © 2015 Therp BV <http://therp.nl>
# © 2017 Avoin.Systems - Miku Laitinen # © 2017 Avoin.Systems - Miku Laitinen
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

Loading…
Cancel
Save