OLD | NEW |
1 # Copyright 2012 Canonical Ltd. This software is licensed under the | 1 # Copyright 2012 Canonical Ltd. This software is licensed under the |
2 # GNU Affero General Public License version 3 (see the file LICENSE). | 2 # GNU Affero General Public License version 3 (see the file LICENSE). |
3 | 3 |
4 """Test cases for juju.providers.maas.maas""" | 4 """Test cases for juju.providers.maas.maas""" |
5 | 5 |
6 import json | 6 import json |
7 from textwrap import dedent | 7 from textwrap import dedent |
8 from urlparse import urlparse | 8 from urlparse import urlparse |
9 | 9 |
10 from twisted.internet.defer import inlineCallbacks, fail, succeed | 10 from twisted.internet.defer import inlineCallbacks, fail, succeed |
11 from twisted.web.error import Error | 11 from twisted.web.error import Error |
12 | 12 |
13 from juju.errors import ProviderError | 13 from juju.errors import ProviderError |
| 14 from juju.providers.maas import MachineProvider |
14 from juju.providers.maas.maas import extract_system_id, MAASClient | 15 from juju.providers.maas.maas import extract_system_id, MAASClient |
15 from juju.providers.maas.tests.testing import ( | 16 from juju.providers.maas.tests.testing import ( |
16 CONFIG, FakeMAASHTTPConnection, | 17 CONFIG, FakeMAASHTTPConnection, |
17 FakeMAASHTTPConnectionWithNoAvailableNodes, NODE_JSON, TestCase) | 18 FakeMAASHTTPConnectionWithNoAvailableNodes, NODE_JSON, TestCase) |
18 | 19 |
19 | 20 |
20 class FakeMAASHTTPConnectionWithNoTags(FakeMAASHTTPConnection): | 21 class FakeMAASHTTPConnectionWithNoTags(FakeMAASHTTPConnection): |
21 """Fake client that raises Not Found on tag listing""" | 22 """Fake client that raises Not Found on tag listing""" |
22 | 23 |
23 def list_tags(self): | 24 def list_tags(self): |
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 self.assertEqual("2", cpu_count) | 377 self.assertEqual("2", cpu_count) |
377 | 378 |
378 def test_acquire_node_handles_mem_constraint(self): | 379 def test_acquire_node_handles_mem_constraint(self): |
379 client = self.set_up_client_with_fake() | 380 client = self.set_up_client_with_fake() |
380 constraints = {"mem": 2048.0} | 381 constraints = {"mem": 2048.0} |
381 client.acquire_node(constraints) | 382 client.acquire_node(constraints) |
382 | 383 |
383 mem = client.post.params_used.get("mem") | 384 mem = client.post.params_used.get("mem") |
384 self.assertEqual("2048", mem) | 385 self.assertEqual("2048", mem) |
385 | 386 |
| 387 @inlineCallbacks |
386 def test_acquire_node_handles_arbitrary_tag_query(self): | 388 def test_acquire_node_handles_arbitrary_tag_query(self): |
| 389 mock_client = self.mocker.patch(MAASClient(CONFIG)) |
| 390 mock_client.list_tags() |
| 391 self.mocker.result(succeed([ |
| 392 {'name': 'red', 'definition': '', 'comment': ''}, |
| 393 {'name': 'white', 'definition': '', 'comment': ''}, |
| 394 {'name': 'blue', 'definition': '', 'comment': ''}])) |
| 395 self.mocker.replay() |
| 396 |
| 397 provider = MachineProvider("mymaas", CONFIG) |
| 398 provider.maas_client = mock_client |
| 399 cs = yield provider.get_constraint_set() |
| 400 constraints = cs.parse(["maas-tags=red&!white|blue"]) |
| 401 constraints = constraints.with_series('splendid') |
| 402 |
387 client = self.set_up_client_with_fake() | 403 client = self.set_up_client_with_fake() |
388 constraints = {"maas-tags": "red&!white|blue"} | |
389 client.acquire_node(constraints) | 404 client.acquire_node(constraints) |
390 | 405 |
391 tags = client.post.params_used.get("tags") | 406 tags = client.post.params_used.get("tags") |
392 self.assertEqual("red&!white|blue", tags) | 407 self.assertEqual("red&!white|blue", tags) |
OLD | NEW |