Martin Packman has proposed merging 
lp:~gz/maas/accept_float_constraints_1061286 into lp:maas.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #1061286 in MAAS: "juju bootstrap returned ERROR Invalid 'cpu_count' 
constraint '1.0'"
  https://bugs.launchpad.net/maas/+bug/1061286

For more details, see:
https://code.launchpad.net/~gz/maas/accept_float_constraints_1061286/+merge/127983

Simple change to make acquire work when a decimal is given for one of the 
integer constraints.

The default value juju uses for the 'cpu' constraint is 1.0 as EC2 has compute 
unit measures, and int() does not like stringified floats. There's no reason 
not to be a little more liberal here, even though float values don't make much 
sense for the current definitions of mem and cpu.
-- 
https://code.launchpad.net/~gz/maas/accept_float_constraints_1061286/+merge/127983
Your team Launchpad code reviewers is requested to review the proposed merge of 
lp:~gz/maas/accept_float_constraints_1061286 into lp:maas.
=== modified file 'src/maasserver/models/node_constraint_filter.py'
--- src/maasserver/models/node_constraint_filter.py	2012-09-28 11:07:48 +0000
+++ src/maasserver/models/node_constraint_filter.py	2012-10-04 10:59:23 +0000
@@ -12,6 +12,8 @@
     'constrain_nodes',
     ]
 
+import math
+
 from maasserver.exceptions import (
     InvalidConstraint,
     )
@@ -31,7 +33,7 @@
         as an invalid constraint.
     """
     try:
-        int_value = int(str_value)
+        int_value = int(math.ceil(float(str_value)))
     except ValueError as e:
         raise InvalidConstraint(key, str_value, e)
     return nodes.filter(**{'%s__gte' % (key,): int_value})

=== modified file 'src/maasserver/tests/test_api.py'
--- src/maasserver/tests/test_api.py	2012-10-04 10:08:26 +0000
+++ src/maasserver/tests/test_api.py	2012-10-04 10:59:23 +0000
@@ -1796,6 +1796,17 @@
         response_json = json.loads(response.content)
         self.assertEqual(node.system_id, response_json['system_id'])
 
+    def test_POST_acquire_allocates_node_by_float_cpu(self):
+        # Asking for a needlessly precise number of cpus works.
+        node = factory.make_node(status=NODE_STATUS.READY, cpu_count=1)
+        response = self.client.post(self.get_uri('nodes/'), {
+            'op': 'acquire',
+            'cpu_count': '1.0',
+        })
+        self.assertResponseCode(httplib.OK, response)
+        response_json = json.loads(response.content)
+        self.assertEqual(node.system_id, response_json['system_id'])
+
     def test_POST_acquire_fails_with_invalid_cpu(self):
         # Asking for an invalid amount of cpu returns a bad request.
         factory.make_node(status=NODE_STATUS.READY)

=== modified file 'src/maasserver/tests/test_node_constraint_filter.py'
--- src/maasserver/tests/test_node_constraint_filter.py	2012-09-28 17:01:26 +0000
+++ src/maasserver/tests/test_node_constraint_filter.py	2012-10-04 10:59:23 +0000
@@ -55,6 +55,8 @@
         self.assertConstrainedNodes([node1, node2], {'cpu_count': '1'})
         self.assertConstrainedNodes([node2], {'cpu_count': '2'})
         self.assertConstrainedNodes([], {'cpu_count': '4'})
+        self.assertConstrainedNodes([node2], {'cpu_count': '2.0'})
+        self.assertConstrainedNodes([node2], {'cpu_count': '1.2'})
         self.assertRaises(InvalidConstraint,
             self.assertConstrainedNodes, [], {'cpu_count': 'notint'})
 
@@ -66,6 +68,7 @@
         self.assertConstrainedNodes([node2], {'memory': '2048'})
         self.assertConstrainedNodes([node2], {'memory': '4096'})
         self.assertConstrainedNodes([], {'memory': '8192'})
+        self.assertConstrainedNodes([node2], {'memory': '4096.0'})
         self.assertRaises(InvalidConstraint,
             self.assertConstrainedNodes, [], {'memory': 'notint'})
 

_______________________________________________
Mailing list: https://launchpad.net/~launchpad-reviewers
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~launchpad-reviewers
More help   : https://help.launchpad.net/ListHelp

Reply via email to