Skip to content

Commit 25bdf68

Browse files
sunyajingHuanxuan Ao
andcommitted
Modify compute agent set command
Migrate ``compute agent set`` arguments: version, url, md5hash to be optional. BackwardsIncompatibleImpact Change-Id: I092b7ed24274bafa548f0537c4586504be3a2825 Co-Authored-By: Huanxuan Ao <huanxuan.ao@easystack.cn>
1 parent 4b61efe commit 25bdf68

6 files changed

Lines changed: 125 additions & 30 deletions

File tree

doc/source/backwards-incompatible.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,19 @@ Releases Before 3.0
170170
* Bug: https://bugs.launchpad.net/python-openstackclient/+bug/1546065
171171
* Commit: https://review.openstack.org/#/c/281088/
172172

173+
12. <version> <url> <md5hash> should be optional for command `openstack compute agent set`
174+
175+
Previously, the command was `openstack compute agent set <id> <version> <url> <md5hash>`,
176+
whereas now it is: `openstack compute agent set <id> --version <version>
177+
--url <url>
178+
--md5hash <md5hash>`.
179+
180+
* In favor of: making <version> <url> <md5hash> optional.
181+
* As of: NA
182+
* Removed in: NA
183+
* Bug: NA
184+
* Commit: https://review.openstack.org/#/c/328819/
185+
173186
13. `aggregate set` commands will no longer return the modified resource
174187

175188
Previously, modifying an aggregate would result in the new aggregate being

doc/source/command-objects/compute-agent.rst

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,21 +80,24 @@ Set compute agent properties
8080
.. code:: bash
8181
8282
os compute agent set
83-
<id> <version> <url> <md5hash>
83+
[--agent-version <version>]
84+
[--url <url]
85+
[--md5hash <md5hash>]
86+
<id>
8487
8588
.. _compute_agent-set:
86-
.. describe:: <id>
89+
.. option:: --agent-version <version>
8790

88-
ID of the agent
91+
Version of the agent
8992

90-
.. describe:: <version>
93+
.. option:: --url <url>
9194

92-
Version of the agent
95+
URL of the agent
9396

94-
.. describe:: <url>
97+
.. option:: --md5hash <md5hash>
9598

96-
URL
99+
MD5 hash of the agent
97100

98-
.. describe:: <md5hash>
101+
.. describe:: <id>
99102

100-
MD5 hash
103+
Agent to modify (ID only)

functional/tests/compute/v2/test_agent.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,11 @@ def test_agent_set(self):
6464
url = "http://openstack"
6565
md5hash = hashlib.md5().hexdigest()
6666

67-
raw_output = self.openstack('compute agent set ' +
68-
self.ID + ' ' + ver + ' ' +
69-
url + ' ' + md5hash)
70-
self.assertEqual('', raw_output)
67+
self.openstack('compute agent set '
68+
+ self.ID
69+
+ ' --agent-version ' + ver
70+
+ ' --url ' + url
71+
+ ' --md5hash ' + md5hash)
7172

7273
raw_output = self.openstack('compute agent list')
7374
self.assertIn(self.ID, raw_output)

openstackclient/compute/v2/agent.py

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,28 +152,48 @@ def get_parser(self, prog_name):
152152
help=_("ID of the agent")
153153
)
154154
parser.add_argument(
155-
"version",
155+
"--agent-version",
156+
dest="version",
156157
metavar="<version>",
157158
help=_("Version of the agent")
158159
)
159160
parser.add_argument(
160-
"url",
161+
"--url",
161162
metavar="<url>",
162-
help=_("URL")
163+
help=_("URL of the agent")
163164
)
164165
parser.add_argument(
165-
"md5hash",
166+
"--md5hash",
166167
metavar="<md5hash>",
167-
help=_("MD5 hash")
168+
help=_("MD5 hash of the agent")
168169
)
169170
return parser
170171

171172
def take_action(self, parsed_args):
172173
compute_client = self.app.client_manager.compute
174+
data = compute_client.agents.list(hypervisor=None)
175+
agent = {}
176+
177+
for s in data:
178+
if s.agent_id == int(parsed_args.id):
179+
agent['version'] = s.version
180+
agent['url'] = s.url
181+
agent['md5hash'] = s.md5hash
182+
if agent == {}:
183+
msg = _("No agent with a ID of '%(id)s' exists.")
184+
raise exceptions.CommandError(msg % parsed_args.id)
185+
186+
if parsed_args.version:
187+
agent['version'] = parsed_args.version
188+
if parsed_args.url:
189+
agent['url'] = parsed_args.url
190+
if parsed_args.md5hash:
191+
agent['md5hash'] = parsed_args.md5hash
192+
173193
args = (
174194
parsed_args.id,
175-
parsed_args.version,
176-
parsed_args.url,
177-
parsed_args.md5hash
195+
agent['version'],
196+
agent['url'],
197+
agent['md5hash'],
178198
)
179199
compute_client.agents.update(*args)

openstackclient/tests/compute/v2/test_agent.py

Lines changed: 64 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525

2626
class TestAgent(compute_fakes.TestComputev2):
2727

28-
fake_agent = compute_fakes.FakeAgent.create_one_agent()
28+
attr = {}
29+
attr['agent_id'] = 1
30+
fake_agent = compute_fakes.FakeAgent.create_one_agent(attr)
2931

3032
columns = (
3133
'agent_id',
@@ -238,28 +240,81 @@ def setUp(self):
238240
super(TestAgentSet, self).setUp()
239241

240242
self.agents_mock.update.return_value = self.fake_agent
243+
self.agents_mock.list.return_value = [self.fake_agent]
241244
self.cmd = agent.SetAgent(self.app, None)
242245

243-
def test_agent_set(self):
246+
def test_agent_set_nothing(self):
244247
arglist = [
245-
'id',
246-
'new-version',
247-
'new-url',
248-
'new-md5hash',
248+
'1',
249+
]
250+
verifylist = [
251+
('id', '1'),
252+
]
253+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
254+
result = self.cmd.take_action(parsed_args)
255+
256+
self.agents_mock.update.assert_called_with(parsed_args.id,
257+
self.fake_agent.version,
258+
self.fake_agent.url,
259+
self.fake_agent.md5hash)
260+
self.assertIsNone(result)
261+
262+
def test_agent_set_version(self):
263+
arglist = [
264+
'1',
265+
'--agent-version', 'new-version',
249266
]
250267

251268
verifylist = [
252-
('id', 'id'),
269+
('id', '1'),
253270
('version', 'new-version'),
254-
('url', 'new-url'),
255-
('md5hash', 'new-md5hash'),
256271
]
257272

258273
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
259274
result = self.cmd.take_action(parsed_args)
260275

261276
self.agents_mock.update.assert_called_with(parsed_args.id,
262277
parsed_args.version,
278+
self.fake_agent.url,
279+
self.fake_agent.md5hash)
280+
self.assertIsNone(result)
281+
282+
def test_agent_set_url(self):
283+
arglist = [
284+
'1',
285+
'--url', 'new-url',
286+
]
287+
288+
verifylist = [
289+
('id', '1'),
290+
('url', 'new-url'),
291+
]
292+
293+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
294+
result = self.cmd.take_action(parsed_args)
295+
296+
self.agents_mock.update.assert_called_with(parsed_args.id,
297+
self.fake_agent.version,
263298
parsed_args.url,
299+
self.fake_agent.md5hash)
300+
self.assertIsNone(result)
301+
302+
def test_agent_set_md5hash(self):
303+
arglist = [
304+
'1',
305+
'--md5hash', 'new-md5hash',
306+
]
307+
308+
verifylist = [
309+
('id', '1'),
310+
('md5hash', 'new-md5hash'),
311+
]
312+
313+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
314+
result = self.cmd.take_action(parsed_args)
315+
316+
self.agents_mock.update.assert_called_with(parsed_args.id,
317+
self.fake_agent.version,
318+
self.fake_agent.url,
264319
parsed_args.md5hash)
265320
self.assertIsNone(result)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
upgrade:
3+
- Migrate command ``compute agent set`` arguments to be optional.

0 commit comments

Comments
 (0)