~freyes/maas-deployer/packaging.fix-maintainer

« back to all changes in this revision

Viewing changes to debian/patches/fix-node-group-selection.patch

  • Committer: Edward Hope-Morley
  • Date: 2015-11-18 18:19:45 UTC
  • Revision ID: edward.hope-morley@canonical.com-20151118181945-pemfv5vg5wxfyasn
0.0.4-0ubuntu4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
4
@@ -96,3 +96,30 @@
 
5
         self.assertRaises(exception.MAASDeployerConfigError,
 
6
                           e.update_nodegroup, mock_client, nodegroup,
 
7
                           maas_config)
 
8
+
 
9
+    @patch.object(engine, 'MAASClient')
 
10
+    def test_get_nodegroup(self, mock_client):
 
11
+        nodegroups = [{"cluster_name": "Cluster master",
 
12
+                       "status": 1,
 
13
+                       "name": "maas",
 
14
+                       "uuid": "d3e2db45-b5fb-4a25-a45e-7319b03a1ff5"},
 
15
+                      {"cluster_name": "Alt",
 
16
+                       "status": 1,
 
17
+                       "name": "maas2",
 
18
+                       "uuid": "c1575955-a6ca-43d8-a5dc-a2dc2c52e3ef"}]
 
19
+
 
20
+        mock_client.get_nodegroups.return_value = nodegroups
 
21
+        e = engine.DeploymentEngine({}, 'test-env')
 
22
+
 
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'])
 
26
+
 
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'])
 
31
+
 
32
+        maas_config = {'node_group': {'name': 'maas.demo', 'uuid': 'foo'}}
 
33
+        self.assertRaises(exception.MAASDeployerValueError, e.get_nodegroup,
 
34
+                          mock_client, maas_config)
 
35
 
 
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
 
39
@@ -11,6 +11,7 @@
 
40
 import os
 
41
 import sys
 
42
 import time
 
43
+import uuid
 
44
 
 
45
 from subprocess import CalledProcessError
 
46
 
 
47
@@ -22,6 +23,7 @@
 
48
 from maas_deployer.vmaas.exception import (
 
49
     MAASDeployerClientError,
 
50
     MAASDeployerConfigError,
 
51
+    MAASDeployerValueError,
 
52
 )
 
53
 from maas_deployer.vmaas.maasclient import (
 
54
     bootimages,
 
55
@@ -424,8 +426,10 @@
 
56
                 log.error("Unable to set %s to %s", key, value)
 
57
 
 
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")
 
63
             return
 
64
 
 
65
         supported_keys = ['name', 'cluster_name']
 
66
@@ -436,12 +440,54 @@
 
67
 
 
68
         client.update_nodegroup(nodegroup, **node_group_config)
 
69
 
 
70
+    def get_nodegroup(self, client, maas_config):
 
71
+        """Get node group.
 
72
+
 
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.
 
75
+        """
 
76
+        cfg_uuid = None
 
77
+        node_group_config = maas_config.get('node_group')
 
78
+        if not node_group_config:
 
79
+            log.info("Node group config not provided")
 
80
+        else:
 
81
+            cfg_uuid = node_group_config.get('uuid')
 
82
+
 
83
+        if cfg_uuid:
 
84
+            log.debug("Using node group uuid '%s'" % (cfg_uuid))
 
85
+        else:
 
86
+            log.info("Node group uuid not provided")
 
87
+
 
88
+        try_again = True
 
89
+        while try_again:
 
90
+            try_again = False
 
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
 
96
+                # uuid.
 
97
+                try:
 
98
+                    uuid.UUID(nodegroup['uuid'])
 
99
+                except ValueError:
 
100
+                    log.warning("Re-querying nodegroup list since one or more "
 
101
+                                "nodegroups does not have a valid uuid")
 
102
+                    try_again = True
 
103
+                    time.sleep(2)
 
104
+                    break
 
105
+
 
106
+                if not cfg_uuid:
 
107
+                    return nodegroup
 
108
+
 
109
+                if nodegroup['uuid'] == cfg_uuid:
 
110
+                    return nodegroup
 
111
+
 
112
+        raise MAASDeployerValueError("Could not find nodegroup with uuid "
 
113
+                                     "'%s'" % (cfg_uuid))
 
114
+
 
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)
 
124
 
 
125
 
 
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
 
129
@@ -40,3 +40,8 @@
 
130
 class MAASDeployerConfigError(MAASDeployerBaseException):
 
131
     def __init__(self, msg):
 
132
         super(MAASDeployerConfigError, self).__init__(msg)
 
133
+
 
134
+
 
135
+class MAASDeployerValueError(MAASDeployerBaseException):
 
136
+    def __init__(self, msg):
 
137
+        super(MAASDeployerValueError, self).__init__(msg)
 
138
 
 
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
 
142
@@ -1,6 +1,9 @@
 
143
 #
 
144
 # Copyright 2015, Canonical Ltd
 
145
 #
 
146
+import logging
 
147
+
 
148
+log = logging.getLogger('vmaas.main')
 
149
 
 
150
 
 
151
 class Response(object):
 
152
@@ -43,6 +46,9 @@
 
153
         """
 
154
         if hasattr(obj, 'uuid'):
 
155
             return obj.uuid
 
156
+        else:
 
157
+            log.warning("Attr 'uuid' not found in %s" % obj)
 
158
+
 
159
         return obj
 
160
 
 
161
     ###########################################################################
 
162