Merge "Fix discard changes to remove node from a cluster"
This commit is contained in:
commit
9d8b3ba659
@ -94,6 +94,7 @@ class NodeHandler(BaseHandler):
|
||||
if data["cluster_id"] is None and node.cluster:
|
||||
node.cluster.clear_pending_changes(node_id=node.id)
|
||||
node.roles = node.pending_roles = []
|
||||
node.reset_name_to_default()
|
||||
node.cluster_id = data["cluster_id"]
|
||||
if node.cluster_id != old_cluster_id:
|
||||
if old_cluster_id:
|
||||
@ -350,6 +351,7 @@ class NodeCollectionHandler(BaseHandler):
|
||||
if nd["cluster_id"] is None and node.cluster:
|
||||
node.cluster.clear_pending_changes(node_id=node.id)
|
||||
node.roles = node.pending_roles = []
|
||||
node.reset_name_to_default()
|
||||
node.cluster_id = nd["cluster_id"]
|
||||
|
||||
regenerate_volumes = any((
|
||||
|
@ -270,6 +270,13 @@ class Node(Base):
|
||||
data["interfaces"] = result
|
||||
self.meta = data
|
||||
|
||||
def reset_name_to_default(self):
|
||||
"""Reset name to default
|
||||
TODO(el): move to node REST object which
|
||||
will be introduced in 5.0 release
|
||||
"""
|
||||
self.name = u'Untitled ({0})'.format(self.mac[-5:])
|
||||
|
||||
|
||||
class NodeAttributes(Base):
|
||||
__tablename__ = 'node_attributes'
|
||||
|
@ -374,3 +374,27 @@ class TestHandlers(BaseIntegrationTest):
|
||||
headers=self.default_headers,
|
||||
expect_errors=True)
|
||||
self.assertEquals(resp.status, 403)
|
||||
|
||||
def test_reset_cluster_name_when_unassign_node(self):
|
||||
self.env.create(
|
||||
nodes_kwargs=[
|
||||
{'pending_roles': ['controller'],
|
||||
'pending_addition': True,
|
||||
'name': 'new_node'}])
|
||||
|
||||
node = self.env.nodes[0]
|
||||
default_name = 'Untitled ({0})'.format(node.mac[-5:])
|
||||
|
||||
resp = self.app.put(
|
||||
reverse('NodeCollectionHandler'),
|
||||
json.dumps([{'id': node.id,
|
||||
'cluster_id': None,
|
||||
'pending_roles': []}]),
|
||||
headers=self.default_headers)
|
||||
self.assertEquals(200, resp.status)
|
||||
response = json.loads(resp.body)
|
||||
self.assertEquals(1, len(response))
|
||||
self.assertEquals(node.id, response[0]['id'])
|
||||
self.assertEquals(node.name, default_name)
|
||||
self.assertEquals(node.cluster, None)
|
||||
self.assertEquals(node.pending_roles, [])
|
||||
|
@ -31,8 +31,7 @@ class TestHandlers(BaseIntegrationTest):
|
||||
self.assertEquals(200, resp.status)
|
||||
response = json.loads(resp.body)
|
||||
self.assertEquals(node.id, response['id'])
|
||||
# todo: decide None output format
|
||||
# self.assertEquals(node.name, response['name'])
|
||||
self.assertEquals(node.name, response['name'])
|
||||
self.assertEquals(node.mac, response['mac'])
|
||||
self.assertEquals(
|
||||
node.pending_addition, response['pending_addition'])
|
||||
|
@ -918,7 +918,7 @@ function(utils, models, commonViews, dialogViews, nodesManagementPanelTemplate,
|
||||
discardAddition: function(e) {
|
||||
e.preventDefault();
|
||||
this.updateNode({
|
||||
cluster: null,
|
||||
cluster_id: null,
|
||||
pending_addition: false,
|
||||
pending_roles: []
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user