Merge lp:~hopem/maas-deployer/lp1479023 into lp:~maas-deployers/maas-deployer/next

Proposed by Edward Hope-Morley
Status: Merged
Merged at revision: 48
Proposed branch: lp:~hopem/maas-deployer/lp1479023
Merge into: lp:~maas-deployers/maas-deployer/next
Diff against target: 185 lines (+82/-16)
5 files modified
examples/deployment.yaml (+9/-0)
maas_deployer/tests/test_engine.py (+17/-1)
maas_deployer/vmaas/engine.py (+38/-15)
maas_deployer/vmaas/maasclient/__init__.py (+10/-0)
maas_deployer/vmaas/maasclient/clidriver.py (+8/-0)
To merge this branch: bzr merge lp:~hopem/maas-deployer/lp1479023
Reviewer Review Type Date Requested Status
Billy Olsen Approve
Review via email: mp+272032@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Billy Olsen (billy-olsen) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'examples/deployment.yaml'
2--- examples/deployment.yaml 2015-09-11 08:06:40 +0000
3+++ examples/deployment.yaml 2015-09-22 21:06:04 +0000
4@@ -83,6 +83,15 @@
5 gateway 192.168.122.1
6 dns-nameservers 192.168.122.1 127.0.0.1
7
8+ # See https://maas.ubuntu.com/docs/maascli.html#node-groups for
9+ # description and full list of supported options.
10+ # NOTE: interfaces are added using the node_group_interfaces section
11+ # and only one node_group can be created by this bundle.
12+ # Additional node groups can be added post deployment.
13+ #node_group:
14+ # # This is the cluster DNS name.
15+ # name: maas
16+
17 # The node-group-interfaces section is used to configure the MAAS
18 # network interfaces. Basic configuration is supported, such as which
19 # device should be bound, the range of IP addresses, etc.
20
21=== modified file 'maas_deployer/tests/test_engine.py'
22--- maas_deployer/tests/test_engine.py 2015-08-21 17:12:13 +0000
23+++ maas_deployer/tests/test_engine.py 2015-09-22 21:06:04 +0000
24@@ -14,7 +14,10 @@
25 )
26
27 sys.modules['apiclient'] = MagicMock()
28-from maas_deployer.vmaas import engine
29+from maas_deployer.vmaas import (
30+ engine,
31+ exception,
32+)
33
34
35 class TestEngine(unittest.TestCase):
36@@ -80,3 +83,16 @@
37 e._create_maas_tags(mock_client, nodes)
38 self.assertTrue(mock_client.create_tag.called)
39 self.assertTrue(mock_client.get_tags.called)
40+
41+ @patch.object(engine, 'MAASClient')
42+ def test_update_nodegroup(self, mock_client):
43+ e = engine.DeploymentEngine({}, 'test-env')
44+ nodegroup = {'uuid': 'fd623c43-6f5b-44fa-bc16-0f58a531063f'}
45+ maas_config = {'node_group': {'name': 'maas.demo'}}
46+ e.update_nodegroup(mock_client, nodegroup, maas_config)
47+ self.assertTrue(mock_client.update_nodegroup.called)
48+
49+ maas_config = {'node_group': {'name': 'maas.demo', 'blah': 123}}
50+ self.assertRaises(exception.MAASDeployerConfigError,
51+ e.update_nodegroup, mock_client, nodegroup,
52+ maas_config)
53
54=== modified file 'maas_deployer/vmaas/engine.py'
55--- maas_deployer/vmaas/engine.py 2015-09-11 08:07:58 +0000
56+++ maas_deployer/vmaas/engine.py 2015-09-22 21:06:04 +0000
57@@ -21,6 +21,7 @@
58 )
59 from maas_deployer.vmaas.exception import (
60 MAASDeployerClientError,
61+ MAASDeployerConfigError,
62 )
63 from maas_deployer.vmaas.maasclient import (
64 bootimages,
65@@ -422,17 +423,27 @@
66 if not succ:
67 log.error("Unable to set %s to %s", key, value)
68
69+ def update_nodegroup(self, client, nodegroup, maas_config):
70+ node_group_config = maas_config.get('node_group')
71+ if not node_group_config:
72+ return
73+
74+ supported_keys = ['name', 'cluster_name']
75+ if not set(node_group_config.keys()).issubset(supported_keys):
76+ msg = ("node_group config contains unsupported settings: %s" %
77+ node_group_config.keys())
78+ raise MAASDeployerConfigError(msg)
79+
80+ client.update_nodegroup(nodegroup, **node_group_config)
81+
82 def configure_maas(self, client, maas_config):
83- """
84- Configures the MAAS instance.
85- """
86+ """Configures the MAAS instance."""
87+ # FIXME: we currently pick the first node group out of the default
88+ # list which will cause problems if new node groups are added
89+ # and the order changes.
90 nodegroup = client.get_nodegroups()[0]
91- log.debug("Creating the nodegroup interfaces...")
92- node_group_interfaces = copy.deepcopy(maas_config['node_group_ifaces'])
93- for iface in node_group_interfaces:
94- if not self.create_nodegroup_interface(client, nodegroup, iface):
95- msg = "Unable to create nodegroup interface: %s" % iface
96- raise MAASDeployerClientError(msg)
97+ self.update_nodegroup(client, nodegroup, maas_config)
98+ self.create_nodegroup_interfaces(client, nodegroup, maas_config)
99
100 nodes = maas_config.get('nodes', [])
101 self._create_maas_nodes(client, nodes)
102@@ -577,10 +588,7 @@
103 return json.dumps(power_parameters)
104
105 def create_nodegroup_interface(self, client, nodegroup, properties):
106- """
107- Creates a NodegroupInterface object from the dictionary of attributes
108- passed in.
109- """
110+ """Add/update node group interface."""
111 # Note: for compatibility with current revisions of the deployment.yaml
112 # file we'll need to flatten the resulting dict from the yaml and then
113 # remap some of the resulting keys to meet what the MAAS API is looking
114@@ -599,10 +607,13 @@
115 properties[name_map[key]] = properties[key]
116 del properties[key]
117
118- if not properties.get('name', None):
119+ if not properties.get('name'):
120 properties['name'] = properties['interface']
121
122- if not properties.get('management', None):
123+ log.debug("Creating interface '%s' in node group '%s'",
124+ properties['name'], nodegroup.name)
125+
126+ if not properties.get('management'):
127 properties['management'] = '2' # Default to dhcp and dns
128
129 existing_iface = client.get_nodegroup_interface(nodegroup,
130@@ -614,3 +625,15 @@
131 success = client.create_nodegroup_interface(nodegroup, properties)
132
133 return success
134+
135+ def create_nodegroup_interfaces(self, client, nodegroup, maas_config):
136+ """
137+ Creates a NodegroupInterface object from the dictionary of attributes
138+ passed in.
139+ """
140+ log.debug("Creating node group '%s' interfaces" % (nodegroup.name))
141+ node_group_interfaces = copy.deepcopy(maas_config['node_group_ifaces'])
142+ for iface in node_group_interfaces:
143+ if not self.create_nodegroup_interface(client, nodegroup, iface):
144+ msg = "Unable to create nodegroup interface: %s" % iface
145+ raise MAASDeployerClientError(msg)
146
147=== modified file 'maas_deployer/vmaas/maasclient/__init__.py'
148--- maas_deployer/vmaas/maasclient/__init__.py 2015-08-11 08:55:09 +0000
149+++ maas_deployer/vmaas/maasclient/__init__.py 2015-09-22 21:06:04 +0000
150@@ -94,6 +94,16 @@
151 ###########################################################################
152 # Nodegroup API - http://maas.ubuntu.com/docs/api.html#nodegroups
153 ###########################################################################
154+ def update_nodegroup(self, nodegroup, **settings):
155+ """
156+ Update nodegroup.
157+ http://maas.ubuntu.com/docs/api.html#nodegroups
158+ """
159+ resp = self.driver.update_nodegroup(nodegroup, **settings)
160+ if resp.ok:
161+ return True
162+ return False
163+
164 def get_nodegroups(self):
165 """
166 Returns the nodegroups.
167
168=== modified file 'maas_deployer/vmaas/maasclient/clidriver.py'
169--- maas_deployer/vmaas/maasclient/clidriver.py 2015-09-10 15:52:50 +0000
170+++ maas_deployer/vmaas/maasclient/clidriver.py 2015-09-22 21:06:04 +0000
171@@ -139,6 +139,14 @@
172 ###########################################################################
173 # Nodegroup API - http://maas.ubuntu.com/docs/api.html#nodegroups
174 ###########################################################################
175+ def update_nodegroup(self, nodegroup, **settings):
176+ """
177+ Returns the nodegroups.
178+ http://maas.ubuntu.com/docs/api.html#nodegroups
179+ """
180+ return self._maas_execute('node-group', 'update', nodegroup.uuid,
181+ **settings)
182+
183 def get_nodegroups(self):
184 """
185 Returns the nodegroups.

Subscribers

People subscribed via source and target branches