Merge "Modify compute agent set command"

This commit is contained in:
Jenkins 2016-07-14 09:22:20 +00:00 committed by Gerrit Code Review
commit 52cb503fb0
6 changed files with 126 additions and 31 deletions

View File

@ -170,6 +170,19 @@ Releases Before 3.0
* Bug: https://bugs.launchpad.net/python-openstackclient/+bug/1546065 * Bug: https://bugs.launchpad.net/python-openstackclient/+bug/1546065
* Commit: https://review.openstack.org/#/c/281088/ * Commit: https://review.openstack.org/#/c/281088/
12. <version> <url> <md5hash> should be optional for command `openstack compute agent set`
Previously, the command was `openstack compute agent set <id> <version> <url> <md5hash>`,
whereas now it is: `openstack compute agent set <id> --version <version>
--url <url>
--md5hash <md5hash>`.
* In favor of: making <version> <url> <md5hash> 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 13. `aggregate set` commands will no longer return the modified resource
Previously, modifying an aggregate would result in the new aggregate being Previously, modifying an aggregate would result in the new aggregate being

View File

@ -79,21 +79,24 @@ Set compute agent properties
.. code:: bash .. code:: bash
os compute agent set os compute agent set
<id> <version> <url> <md5hash> [--agent-version <version>]
[--url <url]
[--md5hash <md5hash>]
<id>
.. _compute_agent-set: .. _compute_agent-set:
.. describe:: <id> .. option:: --agent-version <version>
ID of the agent
.. describe:: <version>
Version of the agent Version of the agent
.. describe:: <url> .. option:: --url <url>
URL URL of the agent
.. describe:: <md5hash> .. option:: --md5hash <md5hash>
MD5 hash MD5 hash of the agent
.. describe:: <id>
Agent to modify (ID only)

View File

@ -64,10 +64,11 @@ class ComputeAgentTests(test.TestCase):
url = "http://openstack" url = "http://openstack"
md5hash = hashlib.md5().hexdigest() md5hash = hashlib.md5().hexdigest()
raw_output = self.openstack('compute agent set ' + self.openstack('compute agent set '
self.ID + ' ' + ver + ' ' + + self.ID
url + ' ' + md5hash) + ' --agent-version ' + ver
self.assertEqual('', raw_output) + ' --url ' + url
+ ' --md5hash ' + md5hash)
raw_output = self.openstack('compute agent list') raw_output = self.openstack('compute agent list')
self.assertIn(self.ID, raw_output) self.assertIn(self.ID, raw_output)

View File

@ -152,28 +152,48 @@ class SetAgent(command.Command):
help=_("ID of the agent") help=_("ID of the agent")
) )
parser.add_argument( parser.add_argument(
"version", "--agent-version",
dest="version",
metavar="<version>", metavar="<version>",
help=_("Version of the agent") help=_("Version of the agent")
) )
parser.add_argument( parser.add_argument(
"url", "--url",
metavar="<url>", metavar="<url>",
help=_("URL") help=_("URL of the agent")
) )
parser.add_argument( parser.add_argument(
"md5hash", "--md5hash",
metavar="<md5hash>", metavar="<md5hash>",
help=_("MD5 hash") help=_("MD5 hash of the agent")
) )
return parser return parser
def take_action(self, parsed_args): def take_action(self, parsed_args):
compute_client = self.app.client_manager.compute 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 = ( args = (
parsed_args.id, parsed_args.id,
parsed_args.version, agent['version'],
parsed_args.url, agent['url'],
parsed_args.md5hash agent['md5hash'],
) )
compute_client.agents.update(*args) compute_client.agents.update(*args)

View File

@ -25,7 +25,9 @@ from openstackclient.tests import utils as tests_utils
class TestAgent(compute_fakes.TestComputev2): 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 = ( columns = (
'agent_id', 'agent_id',
@ -238,21 +240,34 @@ class TestAgentSet(TestAgent):
super(TestAgentSet, self).setUp() super(TestAgentSet, self).setUp()
self.agents_mock.update.return_value = self.fake_agent 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) self.cmd = agent.SetAgent(self.app, None)
def test_agent_set(self): def test_agent_set_nothing(self):
arglist = [ arglist = [
'id', '1',
'new-version', ]
'new-url', verifylist = [
'new-md5hash', ('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 = [ verifylist = [
('id', 'id'), ('id', '1'),
('version', 'new-version'), ('version', 'new-version'),
('url', 'new-url'),
('md5hash', 'new-md5hash'),
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) 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, self.agents_mock.update.assert_called_with(parsed_args.id,
parsed_args.version, 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, 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) parsed_args.md5hash)
self.assertIsNone(result) self.assertIsNone(result)

View File

@ -0,0 +1,3 @@
---
upgrade:
- Migrate command ``compute agent set`` arguments to be optional.