Browse Source

Make resource class required

Allocation API requires a resource class, so we have to require it now.

Change-Id: Ic3729fb8aa02c82379eceb2a2555fc9c0ba9bc57
Dmitry Tantsur 1 month ago
parent
commit
d64e020fd0

+ 1
- 1
metalsmith/_cmd.py View File

@@ -164,7 +164,7 @@ def _parse_args(args, config):
164 164
     deploy.add_argument('--ssh-public-key', help='SSH public key to load')
165 165
     deploy.add_argument('--hostname', help='Host name to use, defaults to '
166 166
                         'Node\'s name or UUID')
167
-    deploy.add_argument('--resource-class',
167
+    deploy.add_argument('--resource-class', required=True,
168 168
                         help='node resource class to deploy')
169 169
     deploy.add_argument('--conductor-group',
170 170
                         help='conductor group to pick the node from')

+ 1
- 5
metalsmith/_provisioner.py View File

@@ -64,7 +64,7 @@ class Provisioner(_utils.GetNodeMixin):
64 64
 
65 65
         self._dry_run = dry_run
66 66
 
67
-    def reserve_node(self, resource_class=None, conductor_group=None,
67
+    def reserve_node(self, resource_class, conductor_group=None,
68 68
                      capabilities=None, traits=None, candidates=None,
69 69
                      predicate=None):
70 70
         """Find and reserve a suitable node.
@@ -91,10 +91,6 @@ class Provisioner(_utils.GetNodeMixin):
91 91
         :raises: :py:class:`metalsmith.exceptions.ReservationFailed`
92 92
         """
93 93
         capabilities = capabilities or {}
94
-        if resource_class is None:
95
-            warnings.warn("Not providing resource_class is deprecated as it's "
96
-                          "not compatible with the proposed allocation API",
97
-                          DeprecationWarning)
98 94
 
99 95
         if candidates:
100 96
             nodes = [self._get_node(node) for node in candidates]

+ 14
- 19
metalsmith/test/test_provisioner.py View File

@@ -94,36 +94,29 @@ class Base(testtools.TestCase):
94 94
 
95 95
 class TestReserveNode(Base):
96 96
 
97
+    RSC = 'baremetal'
98
+
97 99
     def _node(self, **kwargs):
98 100
         kwargs.setdefault('id', '000')
99 101
         kwargs.setdefault('properties', {'local_gb': 100})
100 102
         kwargs.setdefault('instance_info', {})
101 103
         kwargs.setdefault('instance_id', None)
102 104
         kwargs.setdefault('is_maintenance', False)
105
+        kwargs.setdefault('resource_class', self.RSC)
103 106
         return mock.Mock(spec=NODE_FIELDS, **kwargs)
104 107
 
105 108
     def test_no_nodes(self):
106 109
         self.api.baremetal.nodes.return_value = []
107 110
 
108 111
         self.assertRaises(exceptions.NodesNotFound,
109
-                          self.pr.reserve_node, resource_class='control')
112
+                          self.pr.reserve_node, self.RSC)
110 113
         self.assertFalse(self.api.baremetal.update_node.called)
111 114
 
112 115
     def test_simple_ok(self):
113
-        nodes = [self._node(resource_class='control')]
114
-        self.api.baremetal.nodes.return_value = nodes
115
-
116
-        node = self.pr.reserve_node('control')
117
-
118
-        self.assertIn(node, nodes)
119
-        self.api.baremetal.update_node.assert_called_once_with(
120
-            node, instance_id=node.id, instance_info={})
121
-
122
-    def test_any_resource_class(self):
123 116
         nodes = [self._node()]
124 117
         self.api.baremetal.nodes.return_value = nodes
125 118
 
126
-        node = self.pr.reserve_node()
119
+        node = self.pr.reserve_node(self.RSC)
127 120
 
128 121
         self.assertIn(node, nodes)
129 122
         self.api.baremetal.update_node.assert_called_once_with(
@@ -131,14 +124,13 @@ class TestReserveNode(Base):
131 124
 
132 125
     def test_with_capabilities(self):
133 126
         nodes = [
134
-            self._node(properties={'local_gb': 100, 'capabilities': caps},
135
-                       resource_class='control')
127
+            self._node(properties={'local_gb': 100, 'capabilities': caps})
136 128
             for caps in ['answer:1', 'answer:42', None]
137 129
         ]
138 130
         expected = nodes[1]
139 131
         self.api.baremetal.nodes.return_value = nodes
140 132
 
141
-        node = self.pr.reserve_node('control', capabilities={'answer': '42'})
133
+        node = self.pr.reserve_node(self.RSC, capabilities={'answer': '42'})
142 134
 
143 135
         self.assertIs(node, expected)
144 136
         self.api.baremetal.update_node.assert_called_once_with(
@@ -152,7 +144,7 @@ class TestReserveNode(Base):
152 144
         expected = nodes[1]
153 145
         self.api.baremetal.nodes.return_value = nodes
154 146
 
155
-        node = self.pr.reserve_node(traits=['foo', 'answer:42'])
147
+        node = self.pr.reserve_node(self.RSC, traits=['foo', 'answer:42'])
156 148
 
157 149
         self.assertIs(node, expected)
158 150
         self.api.baremetal.update_node.assert_called_once_with(
@@ -165,6 +157,7 @@ class TestReserveNode(Base):
165 157
         self.api.baremetal.nodes.return_value = nodes[:]
166 158
 
167 159
         node = self.pr.reserve_node(
160
+            self.RSC,
168 161
             predicate=lambda node: 100 < node.properties['local_gb'] < 200)
169 162
 
170 163
         self.assertEqual(node, nodes[1])
@@ -178,6 +171,7 @@ class TestReserveNode(Base):
178 171
         self.assertRaisesRegex(exceptions.CustomPredicateFailed,
179 172
                                'custom predicate',
180 173
                                self.pr.reserve_node,
174
+                               self.RSC,
181 175
                                predicate=lambda node: False)
182 176
 
183 177
         self.assertFalse(self.api.baremetal.update_node.called)
@@ -185,7 +179,7 @@ class TestReserveNode(Base):
185 179
     def test_provided_node(self):
186 180
         nodes = [self._node()]
187 181
 
188
-        node = self.pr.reserve_node(candidates=nodes)
182
+        node = self.pr.reserve_node(self.RSC, candidates=nodes)
189 183
 
190 184
         self.assertEqual(node, nodes[0])
191 185
         self.assertFalse(self.api.baremetal.nodes.called)
@@ -195,7 +189,7 @@ class TestReserveNode(Base):
195 189
     def test_provided_nodes(self):
196 190
         nodes = [self._node(), self._node()]
197 191
 
198
-        node = self.pr.reserve_node(candidates=nodes)
192
+        node = self.pr.reserve_node(self.RSC, candidates=nodes)
199 193
 
200 194
         self.assertEqual(node, nodes[0])
201 195
         self.assertFalse(self.api.baremetal.nodes.called)
@@ -227,7 +221,8 @@ class TestReserveNode(Base):
227 221
                                         'capabilities': 'cat:meow'},
228 222
                             conductor_group='loc1')]
229 223
 
230
-        node = self.pr.reserve_node(conductor_group='loc1',
224
+        node = self.pr.reserve_node(self.RSC,
225
+                                    conductor_group='loc1',
231 226
                                     candidates=nodes,
232 227
                                     capabilities={'cat': 'meow'})
233 228
 

+ 5
- 0
releasenotes/notes/resource-class-1957e83fa8235641.yaml View File

@@ -0,0 +1,5 @@
1
+---
2
+upgrade:
3
+  - |
4
+    The ``resource_class`` argument to ``reserve_node``, as well as the
5
+    ``--resource-class`` CLI argument, are now required.

+ 1
- 1
roles/metalsmith_deployment/README.rst View File

@@ -115,7 +115,7 @@ Each instances has the following attributes:
115 115
               - subnet: private-subnet1
116 116
 
117 117
 ``resource_class`` (defaults to ``metalsmith_resource_class``)
118
-    requested node's resource class.
118
+    requested node's resource class. Mandatory.
119 119
 ``root_size`` (defaults to ``metalsmith_root_size``)
120 120
     size of the root partition (in GiB), if partition images are used.
121 121
 

Loading…
Cancel
Save