Skip to content

Commit 9c91c1d

Browse files
author
Tang Chen
committed
Make SetAgent inherit from cliff.Command
set/unset command classes should inherit from cliff.Command class. Also, this patch adds functional tests for compute agent. Change-Id: I25eafffd1167f82aa0d430628c22dee7516b1e19 Partial-Bug: 1546065
1 parent 859bfaf commit 9c91c1d

4 files changed

Lines changed: 92 additions & 3 deletions

File tree

doc/source/backwards-incompatible.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,18 @@ List of Backwards Incompatible Changes
138138
* Bug: https://bugs.launchpad.net/python-openstackclient/+bug/1546065
139139
* Commit: https://review.openstack.org/#/c/281087/
140140

141+
11. `compute agent set` commands will no longer return the modified resource
142+
143+
Previously, modifying an agent would result in the new agent being displayed
144+
to the user. To keep things consistent with other `set` commands, we will
145+
no longer be showing the modified resource.
146+
147+
* In favor of: Use `set` then `show`
148+
* As of: NA
149+
* Removed in: NA
150+
* Bug: https://bugs.launchpad.net/python-openstackclient/+bug/1546065
151+
* Commit: https://review.openstack.org/#/c/281088/
152+
141153
For Developers
142154
==============
143155

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
2+
# not use this file except in compliance with the License. You may obtain
3+
# a copy of the License at
4+
#
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
#
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10+
# License for the specific language governing permissions and limitations
11+
# under the License.
12+
13+
import hashlib
14+
15+
from functional.common import test
16+
17+
18+
class ComputeAgentTests(test.TestCase):
19+
"""Functional tests for compute agent. """
20+
21+
ID = None
22+
MD5HASH = hashlib.md5().hexdigest()
23+
URL = "http://localhost"
24+
VER = "v1"
25+
OS = "TEST_OS"
26+
ARCH = "x86_64"
27+
HYPER = "kvm"
28+
29+
HEADERS = ['agent_id', 'md5hash']
30+
FIELDS = ['agent_id', 'md5hash']
31+
32+
@classmethod
33+
def setUpClass(cls):
34+
opts = cls.get_show_opts(cls.HEADERS)
35+
raw_output = cls.openstack('compute agent create '
36+
+ cls.OS + ' ' + cls.ARCH + ' '
37+
+ cls.VER + ' ' + cls.URL + ' '
38+
+ cls.MD5HASH + ' ' + cls.HYPER + ' '
39+
+ opts)
40+
41+
# Get agent id because agent can only be deleted by ID
42+
output_list = raw_output.split('\n', 1)
43+
cls.ID = output_list[0]
44+
45+
cls.assertOutput(cls.MD5HASH + '\n', output_list[1])
46+
47+
@classmethod
48+
def tearDownClass(cls):
49+
raw_output = cls.openstack('compute agent delete ' + cls.ID)
50+
cls.assertOutput('', raw_output)
51+
52+
def test_agent_list(self):
53+
raw_output = self.openstack('compute agent list')
54+
self.assertIn(self.ID, raw_output)
55+
self.assertIn(self.OS, raw_output)
56+
self.assertIn(self.ARCH, raw_output)
57+
self.assertIn(self.VER, raw_output)
58+
self.assertIn(self.URL, raw_output)
59+
self.assertIn(self.MD5HASH, raw_output)
60+
self.assertIn(self.HYPER, raw_output)
61+
62+
def test_agent_set(self):
63+
ver = 'v2'
64+
url = "http://openstack"
65+
md5hash = hashlib.md5().hexdigest()
66+
67+
raw_output = self.openstack('compute agent set '
68+
+ self.ID + ' ' + ver + ' '
69+
+ url + ' ' + md5hash)
70+
self.assertEqual('', raw_output)
71+
72+
raw_output = self.openstack('compute agent list')
73+
self.assertIn(self.ID, raw_output)
74+
self.assertIn(ver, raw_output)
75+
self.assertIn(url, raw_output)
76+
self.assertIn(md5hash, raw_output)

openstackclient/compute/v2/agent.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def take_action(self, parsed_args):
112112
) for s in data))
113113

114114

115-
class SetAgent(command.ShowOne):
115+
class SetAgent(command.Command):
116116
"""Set compute agent command"""
117117

118118
def get_parser(self, prog_name):
@@ -143,5 +143,4 @@ def take_action(self, parsed_args):
143143
parsed_args.url,
144144
parsed_args.md5hash
145145
)
146-
agent = compute_client.agents.update(*args)._info.copy()
147-
return zip(*sorted(six.iteritems(agent)))
146+
compute_client.agents.update(*args)

releasenotes/notes/bug-1546065-41d09ffbd8606513.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ fixes:
44
[Bug `1546065 <https://bugs.launchpad.net/python-openstackclient/+bug/1546065>`_]
55
- Command ``security group set`` now outputs nothing.
66
[Bug `1546065 <https://bugs.launchpad.net/python-openstackclient/+bug/1546065>`_]
7+
- Command ``compute agent set`` now outputs nothing.
8+
[Bug `1546065 <https://bugs.launchpad.net/python-openstackclient/+bug/1546065>`_]

0 commit comments

Comments
 (0)