Pass security group id to novaclient while adding security
group to server In AddServerSecurityGroup, we currently pass the security group name to novaclient. If multiple security groups with same name exist, then even while passing secuity group using id to command 'openstack server add security group <server> <group>' it results in error 'Multiple security_group matches found'. Added unit test case to test the command. Change-Id: I6097eb36e1545c85209cfd767c477e10f82c6999 Closes-Bug: 1604076
This commit is contained in:
parent
0181709222
commit
e26eecc12f
@ -260,7 +260,7 @@ class AddServerSecurityGroup(command.Command):
|
|||||||
parsed_args.group,
|
parsed_args.group,
|
||||||
)
|
)
|
||||||
|
|
||||||
server.add_security_group(security_group.name)
|
server.add_security_group(security_group.id)
|
||||||
|
|
||||||
|
|
||||||
class AddServerVolume(command.Command):
|
class AddServerVolume(command.Command):
|
||||||
|
@ -168,6 +168,54 @@ class TestServerAddFloatingIP(TestServer):
|
|||||||
self.assertIsNone(result)
|
self.assertIsNone(result)
|
||||||
|
|
||||||
|
|
||||||
|
class TestServerAddSecurityGroup(TestServer):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(TestServerAddSecurityGroup, self).setUp()
|
||||||
|
|
||||||
|
self.security_group = \
|
||||||
|
compute_fakes.FakeSecurityGroup.create_one_security_group()
|
||||||
|
# This is the return value for utils.find_resource() for security group
|
||||||
|
self.security_groups_mock.get.return_value = self.security_group
|
||||||
|
|
||||||
|
attrs = {
|
||||||
|
'security_groups': [{'name': self.security_group.id}]
|
||||||
|
}
|
||||||
|
methods = {
|
||||||
|
'add_security_group': None,
|
||||||
|
}
|
||||||
|
|
||||||
|
self.server = compute_fakes.FakeServer.create_one_server(
|
||||||
|
attrs=attrs,
|
||||||
|
methods=methods
|
||||||
|
)
|
||||||
|
# This is the return value for utils.find_resource() for server
|
||||||
|
self.servers_mock.get.return_value = self.server
|
||||||
|
|
||||||
|
# Get the command object to test
|
||||||
|
self.cmd = server.AddServerSecurityGroup(self.app, None)
|
||||||
|
|
||||||
|
def test_server_add_security_group(self):
|
||||||
|
arglist = [
|
||||||
|
self.server.id,
|
||||||
|
self.security_group.id
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('server', self.server.id),
|
||||||
|
('group', self.security_group.id),
|
||||||
|
]
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
result = self.cmd.take_action(parsed_args)
|
||||||
|
self.security_groups_mock.get.assert_called_with(
|
||||||
|
self.security_group.id,
|
||||||
|
)
|
||||||
|
self.servers_mock.get.assert_called_with(self.server.id)
|
||||||
|
self.server.add_security_group.assert_called_with(
|
||||||
|
self.security_group.id,
|
||||||
|
)
|
||||||
|
self.assertIsNone(result)
|
||||||
|
|
||||||
|
|
||||||
class TestServerCreate(TestServer):
|
class TestServerCreate(TestServer):
|
||||||
|
|
||||||
columns = (
|
columns = (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user