1
=== modified file 'maas_deployer/tests/test_engine.py'
2
--- a/maas_deployer/tests/test_engine.py 2015-09-22 21:03:59 +0000
3
+++ b/maas_deployer/tests/test_engine.py 2015-11-18 17:56:50 +0000
5
self.assertRaises(exception.MAASDeployerConfigError,
6
e.update_nodegroup, mock_client, nodegroup,
9
+ @patch.object(engine, 'MAASClient')
10
+ def test_get_nodegroup(self, mock_client):
11
+ nodegroups = [{"cluster_name": "Cluster master",
14
+ "uuid": "d3e2db45-b5fb-4a25-a45e-7319b03a1ff5"},
15
+ {"cluster_name": "Alt",
18
+ "uuid": "c1575955-a6ca-43d8-a5dc-a2dc2c52e3ef"}]
20
+ mock_client.get_nodegroups.return_value = nodegroups
21
+ e = engine.DeploymentEngine({}, 'test-env')
23
+ maas_config = {'node_group': {'name': 'maas.demo'}}
24
+ nodegroup = e.get_nodegroup(mock_client, maas_config)
25
+ self.assertEqual(nodegroup['uuid'], nodegroups[0]['uuid'])
27
+ maas_config = {'node_group': {'name': 'maas.demo', 'uuid':
28
+ nodegroups[1]['uuid']}}
29
+ nodegroup = e.get_nodegroup(mock_client, maas_config)
30
+ self.assertEqual(nodegroup['uuid'], nodegroups[1]['uuid'])
32
+ maas_config = {'node_group': {'name': 'maas.demo', 'uuid': 'foo'}}
33
+ self.assertRaises(exception.MAASDeployerValueError, e.get_nodegroup,
34
+ mock_client, maas_config)
36
=== modified file 'maas_deployer/vmaas/engine.py'
37
--- a/maas_deployer/vmaas/engine.py 2015-09-22 21:03:59 +0000
38
+++ b/maas_deployer/vmaas/engine.py 2015-11-18 17:56:50 +0000
45
from subprocess import CalledProcessError
48
from maas_deployer.vmaas.exception import (
49
MAASDeployerClientError,
50
MAASDeployerConfigError,
51
+ MAASDeployerValueError,
53
from maas_deployer.vmaas.maasclient import (
56
log.error("Unable to set %s to %s", key, value)
58
def update_nodegroup(self, client, nodegroup, maas_config):
59
+ """Update node group settings."""
60
node_group_config = maas_config.get('node_group')
61
if not node_group_config:
62
+ log.debug("Did not find any node group settings in config")
65
supported_keys = ['name', 'cluster_name']
68
client.update_nodegroup(nodegroup, **node_group_config)
70
+ def get_nodegroup(self, client, maas_config):
73
+ We will get node group corresponding to uuid from config. If uuid not
74
+ provided we will pick the first from the list returned by MAAS.
77
+ node_group_config = maas_config.get('node_group')
78
+ if not node_group_config:
79
+ log.info("Node group config not provided")
81
+ cfg_uuid = node_group_config.get('uuid')
84
+ log.debug("Using node group uuid '%s'" % (cfg_uuid))
86
+ log.info("Node group uuid not provided")
91
+ nodegroups = client.get_nodegroups()
92
+ for nodegroup in nodegroups:
93
+ # NOTE: for some reason there is period of time after which a
94
+ # node group is created that the uuid is set to a string like
95
+ # "master". If we wait a bit it eventually gets set to a valid
98
+ uuid.UUID(nodegroup['uuid'])
100
+ log.warning("Re-querying nodegroup list since one or more "
101
+ "nodegroups does not have a valid uuid")
109
+ if nodegroup['uuid'] == cfg_uuid:
112
+ raise MAASDeployerValueError("Could not find nodegroup with uuid "
113
+ "'%s'" % (cfg_uuid))
115
def configure_maas(self, client, maas_config):
116
"""Configures the MAAS instance."""
117
- # FIXME: we currently pick the first node group out of the default
118
- # list which will cause problems if new node groups are added
119
- # and the order changes.
120
- nodegroup = client.get_nodegroups()[0]
121
+ nodegroup = self.get_nodegroup(client, maas_config)
122
self.update_nodegroup(client, nodegroup, maas_config)
123
self.create_nodegroup_interfaces(client, nodegroup, maas_config)
126
=== modified file 'maas_deployer/vmaas/exception.py'
127
--- a/maas_deployer/vmaas/exception.py 2015-10-27 21:51:32 +0000
128
+++ b/maas_deployer/vmaas/exception.py 2015-11-18 17:56:50 +0000
130
class MAASDeployerConfigError(MAASDeployerBaseException):
131
def __init__(self, msg):
132
super(MAASDeployerConfigError, self).__init__(msg)
135
+class MAASDeployerValueError(MAASDeployerBaseException):
136
+ def __init__(self, msg):
137
+ super(MAASDeployerValueError, self).__init__(msg)
139
=== modified file 'maas_deployer/vmaas/maasclient/driver.py'
140
--- a/maas_deployer/vmaas/maasclient/driver.py 2015-09-02 14:32:52 +0000
141
+++ b/maas_deployer/vmaas/maasclient/driver.py 2015-11-18 17:56:50 +0000
144
# Copyright 2015, Canonical Ltd
148
+log = logging.getLogger('vmaas.main')
151
class Response(object):
154
if hasattr(obj, 'uuid'):
157
+ log.warning("Attr 'uuid' not found in %s" % obj)
161
###########################################################################