Skip to content

Commit

Permalink
fix(remove_security_groups): adjusted function names
Browse files Browse the repository at this point in the history
  • Loading branch information
qqmok committed Dec 12, 2024
1 parent 0a4ff40 commit f2963b1
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 49 deletions.
2 changes: 1 addition & 1 deletion portal_client.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ service VirtualMachineService {

void delete_security_group_rule(1:string openstack_id) throws (1:SecurityGroupRuleNotFoundException e,2:DefaultException f)

void delete_server_security_groups(1:string openstack_id) throws (1:SecurityGroupRuleNotFoundException e,2:DefaultException f)
void remove_security_groups_from_server(1:string openstack_id) throws (1:SecurityGroupRuleNotFoundException e,2:OpenStackConflictException f)


/**
Expand Down
4 changes: 2 additions & 2 deletions simple_vm_client/VirtualMachineHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,8 @@ def delete_security_group_rule(self, openstack_id):
openstack_id=openstack_id
)

def delete_server_security_groups(self, openstack_id):
return self.openstack_connector.delete_server_security_groups(
def remove_security_groups_from_server(self, openstack_id):
return self.openstack_connector.remove_security_groups_from_server(
openstack_id=openstack_id
)

Expand Down
8 changes: 4 additions & 4 deletions simple_vm_client/VirtualMachineService-remote
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ if len(sys.argv) <= 1 or sys.argv[1] == '--help':
print(' void resize_volume(string volume_id, int size)')
print(' string open_port_range_for_vm_in_project(int range_start, int range_stop, string openstack_id, string ethertype, string protocol)')
print(' void delete_security_group_rule(string openstack_id)')
print(' void delete_server_security_groups(string openstack_id)')
print(' void remove_security_groups_from_server(string openstack_id)')
print(' void delete_server(string openstack_id)')
print(' void rescue_server(string openstack_id, string admin_pass, string image_ref)')
print(' void unrescue_server(string openstack_id)')
Expand Down Expand Up @@ -300,11 +300,11 @@ elif cmd == 'delete_security_group_rule':
sys.exit(1)
pp.pprint(client.delete_security_group_rule(args[0],))

elif cmd == 'delete_server_security_groups':
elif cmd == 'remove_security_groups_from_server':
if len(args) != 1:
print('delete_server_security_groups requires 1 args')
print('remove_security_groups_from_server requires 1 args')
sys.exit(1)
pp.pprint(client.delete_server_security_groups(args[0],))
pp.pprint(client.remove_security_groups_from_server(args[0],))

elif cmd == 'delete_server':
if len(args) != 1:
Expand Down
52 changes: 26 additions & 26 deletions simple_vm_client/VirtualMachineService.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions simple_vm_client/openstack_connector/openstack_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -909,15 +909,6 @@ def delete_security_group_rule(self, openstack_id):
raise DefaultException(
message=f"Could not delete security group rule - {openstack_id}"
)

def delete_server_security_groups(self, openstack_id):
logger.info(f"Delete Security Groups for {openstack_id}")
try:
server: Server = self.get_server(openstack_id=openstack_id)
self._remove_security_groups_from_server(server)
except ConflictException as e:
logger.error(f"Delete Security Groups for {openstack_id} failed!")
raise OpenStackConflictException(message=e.message)

def open_port_range_for_vm_in_project(
self, range_start, range_stop, openstack_id, ethertype="IPv4", protocol="TCP"
Expand Down Expand Up @@ -1350,6 +1341,15 @@ def _remove_security_groups_from_server(self, server: Server) -> None:
logger.info(
f"Could not remoeve security group {sec.id} from server"
)

def remove_security_groups_from_server(self, openstack_id):
logger.info(f"Delete Security Groups for {openstack_id}")
try:
server: Server = self.get_server(openstack_id=openstack_id)
self._remove_security_groups_from_server(server)
except ConflictException as e:
logger.error(f"Delete Security Groups for {openstack_id} failed!")
raise OpenStackConflictException(message=e.message)

def _validate_server_for_deletion(self, server: Server) -> None:
task_state = server.task_state
Expand Down
8 changes: 4 additions & 4 deletions simple_vm_client/test_openstack_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -2925,25 +2925,25 @@ def test_delete_security_group_rule_failure(self):
)

@patch.object(OpenStackConnector, "get_server")
def test_delete_server_security_groups_sucess(self, mock_get_server):
def test_remove_security_groups_from_server_sucess(self, mock_get_server):
server_mock = fakes.generate_fake_resource(server.Server)
mock_get_server.return_value = server_mock

self.openstack_connector.delete_server_security_groups(server_mock.id)
self.openstack_connector.remove_security_groups_from_server(server_mock.id)
self.openstack_connector.openstack_connection.remove_server_security_groups.assert_called_once_with(
server_mock, server_mock.security_groups
)

@patch.object(OpenStackConnector, "get_server")
def test_delete_server_security_groups_failure(self, mock_get_server):
def test_remove_security_groups_from_server_failure(self, mock_get_server):
server_mock = fakes.generate_fake_resource(server.Server)
mock_get_server.return_value = server_mock

self.openstack_connector.openstack_connection.remove_server_security_groups.return_value = (
False
)
with self.assertRaises(DefaultException):
self.openstack_connector.delete_server_security_groups(server_mock.id)
self.openstack_connector.remove_security_groups_from_server(server_mock.id)
self.openstack_connector.openstack_connection.remove_server_security_groups.assert_called_once_with(
server_mock, server_mock.security_groups
)
Expand Down
6 changes: 3 additions & 3 deletions simple_vm_client/test_virtualmachinehandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,9 @@ def test_delete_security_group_rule(self):
openstack_id=OPENSTACK_ID
)

def test_delete_server_security_groups(self):
self.handler.delete_server_security_groups(openstack_id=OPENSTACK_ID)
self.handler.openstack_connector.delete_server_security_groups.assert_called_once_with(
def test_remove_security_groups_from_server(self):
self.handler.remove_security_groups_from_server(openstack_id=OPENSTACK_ID)
self.handler.openstack_connector.remove_security_groups_from_server.assert_called_once_with(
openstack_id=OPENSTACK_ID
)

Expand Down

0 comments on commit f2963b1

Please sign in to comment.