diff --git a/fuelclient/commands/node.py b/fuelclient/commands/node.py index 3e140a8b..f65c19ba 100644 --- a/fuelclient/commands/node.py +++ b/fuelclient/commands/node.py @@ -26,6 +26,19 @@ from fuelclient import utils class NodeMixIn(object): entity_name = 'node' + numa_fields = ( + 'numa_nodes', + 'supported_hugepages', + 'distances') + + @classmethod + def get_numa_topology_info(cls, data): + numa_topology_info = {} + numa_topology = data['meta'].get('numa_topology', {}) + for key in cls.numa_fields: + numa_topology_info[key] = numa_topology.get(key) + return numa_topology_info + class NodeList(NodeMixIn, base.BaseListCommand): """Show list of all available nodes.""" @@ -69,10 +82,6 @@ class NodeList(NodeMixIn, base.BaseListCommand): class NodeShow(NodeMixIn, base.BaseShowCommand): """Show info about node with given id.""" - numa_fields = ( - 'numa_nodes', - 'supported_hugepages', - 'distances') columns = ('id', 'name', @@ -96,15 +105,12 @@ class NodeShow(NodeMixIn, base.BaseShowCommand): # TODO(romcheg): network_data mostly never fits the screen # 'network_data', 'manufacturer') - columns += numa_fields + columns += NodeMixIn.numa_fields def take_action(self, parsed_args): data = self.client.get_by_id(parsed_args.id) - - numa_topology = data['meta'].get('numa_topology', {}) - for key in self.numa_fields: - data[key] = numa_topology.get(key) - + numa_topology = self.get_numa_topology_info(data) + data.update(numa_topology) data = data_utils.get_display_data_single(self.columns, data) return self.columns, data @@ -140,10 +146,12 @@ class NodeUpdate(NodeMixIn, base.BaseShowCommand): updated_node = self.client.update( parsed_args.id, **updates) + numa_topology = self.get_numa_topology_info(updated_node) + updated_node.update(numa_topology) updated_node = data_utils.get_display_data_single( self.columns, updated_node) - return (self.columns, updated_node) + return self.columns, updated_node class NodeVmsList(NodeMixIn, base.BaseShowCommand): diff --git a/fuelclient/tests/unit/v2/cli/test_node.py b/fuelclient/tests/unit/v2/cli/test_node.py index f1a6858b..565fd22f 100644 --- a/fuelclient/tests/unit/v2/cli/test_node.py +++ b/fuelclient/tests/unit/v2/cli/test_node.py @@ -19,6 +19,7 @@ import io import mock import six +from fuelclient.commands import node as cmd_node from fuelclient import main as main_mod from fuelclient.tests.unit.v2.cli import test_engine from fuelclient.tests.utils import fake_node @@ -161,11 +162,13 @@ node-4 ansible_host=10.20.0.5 self.m_get_client.assert_called_once_with('node', mock.ANY) self.m_client.node_vms_create.assert_called_once_with(node_id, config) - def test_node_set_hostname(self): + @mock.patch('cliff.formatters.table.TableFormatter.emit_one') + def test_node_set_hostname(self, m_emit_one): self.m_client._updatable_attributes = \ node.NodeClient._updatable_attributes node_id = 42 hostname = 'test-name' + expected_field_data = cmd_node.NodeShow.columns self.m_client.update.return_value = \ fake_node.get_fake_node(node_id=node_id, @@ -175,15 +178,21 @@ node-4 ansible_host=10.20.0.5 .format(node_id=node_id, hostname=hostname) self.exec_command(args) + m_emit_one.assert_called_once_with(expected_field_data, + mock.ANY, + mock.ANY, + mock.ANY) self.m_get_client.assert_called_once_with('node', mock.ANY) self.m_client.update.assert_called_once_with( node_id, hostname=hostname) - def test_node_set_name(self): + @mock.patch('cliff.formatters.table.TableFormatter.emit_one') + def test_node_set_name(self, m_emit_one): self.m_client._updatable_attributes = \ node.NodeClient._updatable_attributes node_id = 37 + expected_field_data = cmd_node.NodeShow.columns test_cases = ('new-name', 'New Name', 'śćż∑ Pó', '你一定是无聊') for name in test_cases: @@ -199,6 +208,10 @@ node-4 ansible_host=10.20.0.5 if six.PY2: name = name.decode('utf-8') + m_emit_one.assert_called_with(expected_field_data, + mock.ANY, + mock.ANY, + mock.ANY) self.m_get_client.assert_called_once_with('node', mock.ANY) self.m_client.update.assert_called_once_with( node_id, name=name)