Produce an error when extra arguments are present
Currently `parse_known_args` method is used which does not produce an error when extra arguments are present. In this patch `parse_args` is used which produces an error when extra arguments are present. Change-Id: Iefbf221d912cce2b2af536f471c89f4a7a49693d Closes-Bug: #1460572 Closes-Bug: #1496967
This commit is contained in:
@@ -129,7 +129,7 @@ class Parser(object):
|
||||
if len(self.args) < 2:
|
||||
self.parser.print_help()
|
||||
sys.exit(0)
|
||||
parsed_params, _ = self.parser.parse_known_args(self.args[1:])
|
||||
parsed_params = self.parser.parse_args(self.args[1:])
|
||||
if parsed_params.action not in actions:
|
||||
self.parser.print_help()
|
||||
sys.exit(0)
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
import json
|
||||
|
||||
import mock
|
||||
from six import moves
|
||||
import yaml
|
||||
|
||||
from fuelclient.cli.actions import base
|
||||
@@ -95,3 +96,16 @@ class TestFuelVersion(base_tests.UnitTestCase):
|
||||
['fuel', '--fuel-version', '--json'])
|
||||
args, _ = mstdout.write.call_args_list[0]
|
||||
self.assertEqual(self.VERSION, json.loads(args[0]))
|
||||
|
||||
|
||||
class TestExtraArguments(base_tests.UnitTestCase):
|
||||
|
||||
def test_error_on_extra_arguments(self):
|
||||
err_msg = 'unrecognized arguments: extraarg1 extraarg2\n'
|
||||
|
||||
with mock.patch('sys.stderr', new=moves.cStringIO()) as m_stderr:
|
||||
self.assertRaises(
|
||||
SystemExit, self.execute,
|
||||
['fuel', 'nodegroup', '--delete', 'extraarg1', 'extraarg2'])
|
||||
|
||||
self.assertIn(err_msg, m_stderr.getvalue())
|
||||
|
||||
@@ -59,7 +59,7 @@ class TestNetworkActions(base.UnitTestCase):
|
||||
mneutron_put = self.m_request.put(
|
||||
'/api/v1/clusters/1/network_configuration/neutron',
|
||||
json=NETWORK_CONFIG_OK_OUTPUT)
|
||||
self.execute(['fuel', 'network', '--env', '1', '--upload', 'smth'])
|
||||
self.execute(['fuel', 'network', '--env', '1', '--upload'])
|
||||
self.assertEqual(mneutron_put.call_count, 1)
|
||||
url = mneutron_put.request_history[0].url
|
||||
self.assertIn('clusters/1/network_configuration/neutron', url)
|
||||
@@ -74,7 +74,7 @@ class TestNetworkActions(base.UnitTestCase):
|
||||
with patch("sys.stderr") as m_stderr:
|
||||
self.assertRaises(
|
||||
SystemExit, self.execute,
|
||||
['fuel', 'network', '--env', '1', '--upload', 'smth'])
|
||||
['fuel', 'network', '--env', '1', '--upload'])
|
||||
|
||||
self.assertIn("400 Client Error", m_stderr.write.call_args[0][0])
|
||||
self.assertIn(NETWORK_CONFIG_ERROR_OUTPUT['message'],
|
||||
|
||||
@@ -109,7 +109,7 @@ class TestNodeGroupActions(base.UnitTestCase):
|
||||
err_msg = '"--group" required!\n'
|
||||
self._check_required_message_for_commands(
|
||||
err_msg,
|
||||
(['fuel', 'nodegroup', '--delete', '--default'],)
|
||||
(['fuel', 'nodegroup', '--delete'],)
|
||||
)
|
||||
|
||||
def test_assign_nodegroup_fails_w_multiple_groups(self):
|
||||
|
||||
Reference in New Issue
Block a user