Skip to content
This repository was archived by the owner on Jan 24, 2018. It is now read-only.

Commit 92cafec

Browse files
author
Ted Salmon
committed
[IMP] sale_clouder: Finish module
* Fix docstrings * Implement unimplemented methods * Fix bugs found * Add test coverage * Add README [IMP] clouder_metric: Finish module * Fix/Add docstrings * Add test coverage * Fix logic * Add README
1 parent c3760f7 commit 92cafec

26 files changed

+407
-34
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ addons:
1717
- python-simplejson
1818
- python-serial
1919
- python-yaml
20+
- unixodbc-dev
2021

2122
env:
2223
global:

clouder_metric/README.md

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
.. image:: https://img.shields.io/badge/licence-LGPL--3-blue.svg
2+
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
3+
:alt: License: AGPL-3
4+
5+
==============
6+
Clouder Metric
7+
==============
8+
9+
This module provides models to ingest and store usage metrics from ELK about
10+
running instances.
11+
12+
Installation
13+
============
14+
15+
* Install module as normal
16+
17+
18+
Bug Tracker
19+
===========
20+
21+
Bugs are tracked on `GitHub Issues
22+
<https://github.com/clouder/clouder/issues>`_.
23+
24+
Contributors
25+
------------
26+
27+
* Dave Lasley <dave@laslabs.com>
28+
* Ted Salmon <tsalmon@laslabs.com>

clouder_metric/__init__.py

100755100644
File mode changed.

clouder_metric/__manifest__.py

100755100644
+3
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717
"contract_variable_quantity",
1818
"sale",
1919
],
20+
"data": [
21+
"security/ir.model.access.csv",
22+
],
2023
}

clouder_metric/models/__init__.py

100755100644
+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
# Copyright 2016 LasLabs Inc.
33
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
44

5-
from . import clouder_metric_interface
65
from . import clouder_metric_type
6+
from . import clouder_metric_interface
77
from . import clouder_metric_value

clouder_metric/models/clouder_metric_interface.py

100755100644
+3-5
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class ClouderMetricInterface(models.Model):
4343
domain="[('model', '=', _name)]",
4444
context="""{
4545
'default_model': _name,
46-
'default_name': '[Clouder Metric] %s' % display_name,
46+
'default_name': '[Clouder Metric] %s' % display_name,
4747
}""",
4848
)
4949
interval_number = fields.Integer(
@@ -52,9 +52,7 @@ class ClouderMetricInterface(models.Model):
5252
interval_type = fields.Selection(
5353
related='cron_id.interval_type',
5454
)
55-
query_code = fields.Text(
56-
# default=lambda s: s._default_query_code()
57-
)
55+
query_code = fields.Text()
5856

5957
@property
6058
@api.multi
@@ -67,5 +65,5 @@ def metric_id(self):
6765
@api.multi
6866
def name_get(self):
6967
return [
70-
(r.id, '%s - %s' % (r.type_id.name, r.metric_id)) for r in self
68+
(r.id, '%s - %s' % (r.type_id.name, r.metric_ref)) for r in self
7169
]

clouder_metric/models/clouder_metric_type.py

100755100644
+20-2
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,23 @@ def _default_query_code(self):
4848

4949
@api.model
5050
def _get_metric_models(self):
51+
""" Returns a selection of available metric models
52+
Returns:
53+
(list): Additional metric models
54+
"""
5155
return [
5256
('clouder.base', 'Base'),
5357
('clouder.service', 'Service'),
5458
]
5559

5660
@api.multi
5761
def _get_query_code_context(self, interface):
62+
""" Returns a query context for use
63+
Args:
64+
interface (clouder.metric.interface): The interface to use
65+
Returns:
66+
(dict): Dict with the context for the given iface and model
67+
"""
5868
self.ensure_one()
5969
return {
6070
'interface': interface,
@@ -64,6 +74,12 @@ def _get_query_code_context(self, interface):
6474

6575
@api.model
6676
def save_metric_value(self, metric_interfaces):
77+
""" Saves a metric value from the given interface
78+
Args:
79+
metric_interfaces (clouder.metric.interface): The interface to use
80+
Returns:
81+
None
82+
"""
6783
for iface in metric_interfaces:
6884
eval_context = iface.type_id._get_query_code_context(iface)
6985
try:
@@ -84,10 +100,12 @@ def save_metric_value(self, metric_interfaces):
84100
'is used to indicate the value that should be saved for '
85101
'the query.',
86102
))
87-
uom = eval_context.get('uom') or iface.uom_id
103+
uom = eval_context.get('uom') or iface.uom_id
88104
iface.write({
89105
'metric_value_ids': [(0, 0, {
90106
'value': eval_context['value'],
91-
'uom_id': uom.id,
107+
'date_start': eval_context.get('date_start'),
108+
'date_end': eval_context.get('date_end'),
109+
'uom_id': uom.id
92110
})],
93111
})

clouder_metric/models/clouder_metric_value.py

100755100644
+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Copyright 2016 LasLabs Inc.
33
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
44

5-
from odoo import api, fields, models
5+
from odoo import fields, models
66

77

88
class ClouderMetricValue(models.Model):
@@ -30,5 +30,5 @@ class ClouderMetricValue(models.Model):
3030
)
3131
date_create = fields.Datetime(
3232
string='Creation Time',
33-
default=lambda s: field.Datetime.now(),
33+
default=lambda s: fields.Datetime.now(),
3434
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
2+
access_clouder_metric_type,access_clouder_metric_type,model_clouder_metric_type,clouder.group_clouder_user,1,0,0,0
3+
access_clouder_metric_interface,access_clouder_metric_interface,model_clouder_metric_interface,clouder.group_clouder_user,1,0,0,0
4+
access_clouder_metric_value,access_clouder_metric_value,model_clouder_metric_value,clouder.group_clouder_user,1,0,0,0

clouder_metric/tests/__init__.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2017 LasLabs Inc.
3+
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
4+
5+
from . import test_clouder_metric_interface
6+
from . import test_clouder_metric_type

clouder_metric/tests/common.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2017 LasLabs Inc.
3+
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
4+
5+
from odoo.tests.common import TransactionCase
6+
7+
8+
class TestCommon(TransactionCase):
9+
10+
def setUp(self):
11+
super(TestCommon, self).setUp()
12+
self.metric_type = self.env['clouder.metric.type'].create({
13+
'name': 'Test Metric',
14+
'code': 'TEST',
15+
'metric_model': 'clouder.base',
16+
'uom_id': self.env.ref('product.uom_categ_wtime').id,
17+
})
18+
self.metric_interface = self.env['clouder.metric.interface'].create({
19+
'type_id': self.metric_type.id,
20+
'metric_ref': 7,
21+
'source_id': self.env.ref(
22+
'base_external_dbsource.demo_postgre').id,
23+
'query_code': 'print True',
24+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2017 LasLabs Inc.
3+
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
4+
5+
from .common import TestCommon
6+
7+
8+
class TestClouderMetricInterface(TestCommon):
9+
10+
def test_metric_id(self):
11+
""" It should test to see that at least one metric_id is returned """
12+
self.assertTrue(len(self.metric_interface.metric_id) == 1)
13+
14+
def test_name_get(self):
15+
""" It should return the right name """
16+
exp = [
17+
(self.metric_interface.id, 'Test Metric - 7')
18+
]
19+
self.assertEqual(exp, self.metric_interface.name_get())
20+
21+
def test_save_metric_value(self):
22+
""" It should verify """
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# -*- coding: utf-8 -*-
2+
# Copyright 2017 LasLabs Inc.
3+
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
4+
5+
from odoo.exceptions import UserError, ValidationError
6+
7+
from .common import TestCommon
8+
9+
10+
class TestClouderMetricType(TestCommon):
11+
12+
def test_get_metric_models(self):
13+
""" It should have the correct metric model types """
14+
exp = [
15+
('clouder.base', 'Base'),
16+
('clouder.service', 'Service'),
17+
]
18+
self.assertEquals(exp, self.metric_type._get_metric_models())
19+
20+
def test_save_metric_value_usererror(self):
21+
""" It should raise UserError when a bad query is supplied """
22+
with self.assertRaises(UserError):
23+
self.metric_type.save_metric_value(self.metric_interface)
24+
25+
def test_save_metric_value_validationerror(self):
26+
""" It should raise ValidationError when no value is supplied """
27+
self.metric_interface.query_code = 'test = 0'
28+
with self.assertRaises(ValidationError):
29+
self.metric_type.save_metric_value(self.metric_interface)
30+
31+
def test_save_metric_value(self):
32+
""" It should verify that the right metric values are saved """
33+
self.metric_interface.query_code = 'value = 100'
34+
self.metric_type.save_metric_value(self.metric_interface)
35+
self.assertTrue(
36+
self.metric_interface.metric_value_ids.mapped('value') == [100.0]
37+
)

oca_dependencies.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Pending https://github.com/OCA/contract/pull/44
2-
contract https://github.com/laslabs/contract release/10.0/contract_variable_quantity
3-
# Pending https://github.com/OCA/server-tools/pull/645
4-
server-tools https://github.com/laslabs/server-tools feature/10.0/base_external_dbsource_elasticsearch
1+
connector
2+
contract
3+
# Pending https://github.com/OCA/server-tools/pull/660
4+
server-tools https://github.com/laslabs/server-tools feature/10.0/base_external_dbsource_elasticsearch-v10

sale_clouder/README.md

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
.. image:: https://img.shields.io/badge/licence-LGPL--3-blue.svg
2+
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
3+
:alt: License: AGPL-3
4+
5+
============
6+
Sale Clouder
7+
============
8+
9+
This module extends contracts to provide Clouder-specific functionality such
10+
as allowing usage and threshold based contracts.
11+
12+
Installation
13+
============
14+
15+
* Install module as normal
16+
17+
18+
Bug Tracker
19+
===========
20+
21+
Bugs are tracked on `GitHub Issues
22+
<https://github.com/clouder/clouder/issues>`_.
23+
24+
Contributors
25+
------------
26+
27+
* Dave Lasley <dave@laslabs.com>
28+
* Ted Salmon <tsalmon@laslabs.com>

sale_clouder/__init__.py

100755100644
File mode changed.

sale_clouder/__openerp__.py sale_clouder/__manifest__.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{
55
"name": "Sale - Clouder",
66
"summary": "Provides the ability to sell Clouder instances.",
7-
"version": "9.0.1.0.0",
7+
"version": "10.0.1.0.0",
88
"category": "Clouder",
99
"website": "https://github.com/clouder-community/clouder",
1010
"author": "LasLabs",
@@ -15,8 +15,11 @@
1515
"clouder",
1616
"contract",
1717
"sale",
18+
"clouder_metric",
1819
],
1920
"data": [
21+
"data/sale_clouder.xml", # Must be created before formula
2022
"data/contract_line_qty_formula.xml",
23+
"security/ir.model.access.csv",
2124
],
2225
}

sale_clouder/data/sale_clouder.xml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Copyright 2016 LasLabs Inc.
3+
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). -->
4+
5+
<odoo>
6+
<data noupdate="1">
7+
8+
<record id="seq_clouder_contract" model="ir.sequence">
9+
<field name="name">Clouder Contract</field>
10+
<field name="code">clouder.contract</field>
11+
<field name="prefix">CLOUD</field>
12+
<field name="padding">8</field>
13+
</record>
14+
15+
</data>
16+
17+
</odoo>

sale_clouder/models/__init__.py

100755100644
File mode changed.

0 commit comments

Comments
 (0)