diff --git a/doc/source/backwards-incompatible.rst b/doc/source/backwards-incompatible.rst index da3c1b6417..4f38aa540d 100644 --- a/doc/source/backwards-incompatible.rst +++ b/doc/source/backwards-incompatible.rst @@ -170,6 +170,19 @@ Releases Before 3.0 * Bug: https://bugs.launchpad.net/python-openstackclient/+bug/1546065 * Commit: https://review.openstack.org/#/c/281088/ +12. should be optional for command `openstack compute agent set` + + Previously, the command was `openstack compute agent set `, + whereas now it is: `openstack compute agent set --version + --url + --md5hash `. + + * In favor of: making optional. + * As of: NA + * Removed in: NA + * Bug: NA + * Commit: https://review.openstack.org/#/c/328819/ + 13. `aggregate set` commands will no longer return the modified resource Previously, modifying an aggregate would result in the new aggregate being diff --git a/doc/source/command-objects/compute-agent.rst b/doc/source/command-objects/compute-agent.rst index ae057dc96e..562947705f 100644 --- a/doc/source/command-objects/compute-agent.rst +++ b/doc/source/command-objects/compute-agent.rst @@ -80,21 +80,24 @@ Set compute agent properties .. code:: bash os compute agent set - + [--agent-version ] + [--url ] + .. _compute_agent-set: -.. describe:: - - ID of the agent - -.. describe:: +.. option:: --agent-version Version of the agent -.. describe:: +.. option:: --url - URL + URL of the agent -.. describe:: +.. option:: --md5hash - MD5 hash + MD5 hash of the agent + +.. describe:: + + Agent to modify (ID only) diff --git a/functional/tests/compute/v2/test_agent.py b/functional/tests/compute/v2/test_agent.py index 2d7ea21615..9622c1bfb1 100644 --- a/functional/tests/compute/v2/test_agent.py +++ b/functional/tests/compute/v2/test_agent.py @@ -64,10 +64,11 @@ class ComputeAgentTests(test.TestCase): url = "http://openstack" md5hash = hashlib.md5().hexdigest() - raw_output = self.openstack('compute agent set ' + - self.ID + ' ' + ver + ' ' + - url + ' ' + md5hash) - self.assertEqual('', raw_output) + self.openstack('compute agent set ' + + self.ID + + ' --agent-version ' + ver + + ' --url ' + url + + ' --md5hash ' + md5hash) raw_output = self.openstack('compute agent list') self.assertIn(self.ID, raw_output) diff --git a/openstackclient/compute/v2/agent.py b/openstackclient/compute/v2/agent.py index 4d92395511..76c1b3b756 100644 --- a/openstackclient/compute/v2/agent.py +++ b/openstackclient/compute/v2/agent.py @@ -152,28 +152,48 @@ class SetAgent(command.Command): help=_("ID of the agent") ) parser.add_argument( - "version", + "--agent-version", + dest="version", metavar="", help=_("Version of the agent") ) parser.add_argument( - "url", + "--url", metavar="", - help=_("URL") + help=_("URL of the agent") ) parser.add_argument( - "md5hash", + "--md5hash", metavar="", - help=_("MD5 hash") + help=_("MD5 hash of the agent") ) return parser def take_action(self, parsed_args): compute_client = self.app.client_manager.compute + data = compute_client.agents.list(hypervisor=None) + agent = {} + + for s in data: + if s.agent_id == int(parsed_args.id): + agent['version'] = s.version + agent['url'] = s.url + agent['md5hash'] = s.md5hash + if agent == {}: + msg = _("No agent with a ID of '%(id)s' exists.") + raise exceptions.CommandError(msg % parsed_args.id) + + if parsed_args.version: + agent['version'] = parsed_args.version + if parsed_args.url: + agent['url'] = parsed_args.url + if parsed_args.md5hash: + agent['md5hash'] = parsed_args.md5hash + args = ( parsed_args.id, - parsed_args.version, - parsed_args.url, - parsed_args.md5hash + agent['version'], + agent['url'], + agent['md5hash'], ) compute_client.agents.update(*args) diff --git a/openstackclient/tests/compute/v2/test_agent.py b/openstackclient/tests/compute/v2/test_agent.py index da32972890..7695ee4107 100644 --- a/openstackclient/tests/compute/v2/test_agent.py +++ b/openstackclient/tests/compute/v2/test_agent.py @@ -25,7 +25,9 @@ from openstackclient.tests import utils as tests_utils class TestAgent(compute_fakes.TestComputev2): - fake_agent = compute_fakes.FakeAgent.create_one_agent() + attr = {} + attr['agent_id'] = 1 + fake_agent = compute_fakes.FakeAgent.create_one_agent(attr) columns = ( 'agent_id', @@ -238,21 +240,34 @@ class TestAgentSet(TestAgent): super(TestAgentSet, self).setUp() self.agents_mock.update.return_value = self.fake_agent + self.agents_mock.list.return_value = [self.fake_agent] self.cmd = agent.SetAgent(self.app, None) - def test_agent_set(self): + def test_agent_set_nothing(self): arglist = [ - 'id', - 'new-version', - 'new-url', - 'new-md5hash', + '1', + ] + verifylist = [ + ('id', '1'), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + result = self.cmd.take_action(parsed_args) + + self.agents_mock.update.assert_called_with(parsed_args.id, + self.fake_agent.version, + self.fake_agent.url, + self.fake_agent.md5hash) + self.assertIsNone(result) + + def test_agent_set_version(self): + arglist = [ + '1', + '--agent-version', 'new-version', ] verifylist = [ - ('id', 'id'), + ('id', '1'), ('version', 'new-version'), - ('url', 'new-url'), - ('md5hash', 'new-md5hash'), ] parsed_args = self.check_parser(self.cmd, arglist, verifylist) @@ -260,6 +275,46 @@ class TestAgentSet(TestAgent): self.agents_mock.update.assert_called_with(parsed_args.id, parsed_args.version, + self.fake_agent.url, + self.fake_agent.md5hash) + self.assertIsNone(result) + + def test_agent_set_url(self): + arglist = [ + '1', + '--url', 'new-url', + ] + + verifylist = [ + ('id', '1'), + ('url', 'new-url'), + ] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + result = self.cmd.take_action(parsed_args) + + self.agents_mock.update.assert_called_with(parsed_args.id, + self.fake_agent.version, parsed_args.url, + self.fake_agent.md5hash) + self.assertIsNone(result) + + def test_agent_set_md5hash(self): + arglist = [ + '1', + '--md5hash', 'new-md5hash', + ] + + verifylist = [ + ('id', '1'), + ('md5hash', 'new-md5hash'), + ] + + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + result = self.cmd.take_action(parsed_args) + + self.agents_mock.update.assert_called_with(parsed_args.id, + self.fake_agent.version, + self.fake_agent.url, parsed_args.md5hash) self.assertIsNone(result) diff --git a/releasenotes/notes/modify-compute-agent-set-77ff894ef62ebbc7.yaml b/releasenotes/notes/modify-compute-agent-set-77ff894ef62ebbc7.yaml new file mode 100644 index 0000000000..28ab36241d --- /dev/null +++ b/releasenotes/notes/modify-compute-agent-set-77ff894ef62ebbc7.yaml @@ -0,0 +1,3 @@ +--- +upgrade: + - Migrate command ``compute agent set`` arguments to be optional.