Change node name from CLI (fuel2)

Added new updatable attribute to NodeUpdate action:
`fuel2 node update 1 --name NewName`

Also test added.

Change-Id: If1174ede30b849ab1fc357823e9624b98ca7ec7e
Partial-Bug: #1498523
This commit is contained in:
Sylwester Brzeczkowski
2015-09-24 16:10:45 +02:00
parent 0558778f08
commit 3cc0700d7f
3 changed files with 35 additions and 2 deletions

View File

@@ -12,6 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import six
from fuelclient.commands import base
from fuelclient.common import data_utils
@@ -103,6 +104,12 @@ class NodeUpdate(NodeMixIn, base.BaseShowCommand):
default=None,
help='New hostname for node')
parser.add_argument(
'--name',
type=lambda x: x.decode('utf-8') if six.PY2 else x,
default=None,
help='New name for node')
return parser
def take_action(self, parsed_args):

View File

@@ -17,6 +17,7 @@
import mock
import six
from fuelclient import main as main_mod
from fuelclient.tests.unit.v2.cli import test_engine
from fuelclient.tests.utils import fake_node
from fuelclient.v1 import node
@@ -125,7 +126,32 @@ class TestNodeCommand(test_engine.BaseCLITest):
self.m_get_client.assert_called_once_with('node', mock.ANY)
self.m_client.update.assert_called_once_with(
node_id, **{"hostname": hostname})
node_id, hostname=hostname)
def test_node_set_name(self):
self.m_client._updatable_attributes = \
node.NodeClient._updatable_attributes
node_id = 37
test_cases = ('new-name', 'New Name', 'śćż∑ Pó', '你一定是无聊')
for name in test_cases:
self.m_client.update.return_value = fake_node.get_fake_node(
node_id=node_id, node_name=name)
cmd = ['node', 'update', str(node_id), '--name', name]
# NOTE(sbrzeczkowski): due to shlex inability to accept
# unicode arguments prior to python 2.7.3
main_mod.main(argv=cmd)
if six.PY2:
name = name.decode('utf-8')
self.m_get_client.assert_called_once_with('node', mock.ANY)
self.m_client.update.assert_called_once_with(
node_id, name=name)
self.m_get_client.reset_mock()
self.m_client.reset_mock()
def test_node_label_list_for_all_nodes(self):
args = 'node label list'

View File

@@ -26,7 +26,7 @@ SplittedLabel = namedtuple('SplittedLabel', ['key', 'value', 'has_separator'])
class NodeClient(base_v1.BaseV1Client):
_entity_wrapper = objects.Node
_updatable_attributes = ('hostname', 'labels')
_updatable_attributes = ('hostname', 'labels', 'name')
def get_all(self, environment_id=None, labels=None):
"""Get nodes by specific environment or labels