From f2963b1ad9314da6051fea296f21928f4af58bfa Mon Sep 17 00:00:00 2001 From: qqmok Date: Thu, 12 Dec 2024 16:27:16 +0100 Subject: [PATCH] fix(remove_security_groups): adjusted function names --- portal_client.thrift | 2 +- simple_vm_client/VirtualMachineHandler.py | 4 +- simple_vm_client/VirtualMachineService-remote | 8 +-- simple_vm_client/VirtualMachineService.py | 52 +++++++++---------- .../openstack_connector.py | 18 +++---- simple_vm_client/test_openstack_connector.py | 8 +-- .../test_virtualmachinehandler.py | 6 +-- 7 files changed, 49 insertions(+), 49 deletions(-) diff --git a/portal_client.thrift b/portal_client.thrift index f4fc65a..ab6185f 100644 --- a/portal_client.thrift +++ b/portal_client.thrift @@ -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) /** diff --git a/simple_vm_client/VirtualMachineHandler.py b/simple_vm_client/VirtualMachineHandler.py index 5f9a555..4bf2f8e 100644 --- a/simple_vm_client/VirtualMachineHandler.py +++ b/simple_vm_client/VirtualMachineHandler.py @@ -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 ) diff --git a/simple_vm_client/VirtualMachineService-remote b/simple_vm_client/VirtualMachineService-remote index 5b50dcf..b71b4ef 100755 --- a/simple_vm_client/VirtualMachineService-remote +++ b/simple_vm_client/VirtualMachineService-remote @@ -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)') @@ -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: diff --git a/simple_vm_client/VirtualMachineService.py b/simple_vm_client/VirtualMachineService.py index 5cfd1ef..09f673f 100644 --- a/simple_vm_client/VirtualMachineService.py +++ b/simple_vm_client/VirtualMachineService.py @@ -205,7 +205,7 @@ def delete_security_group_rule(self, openstack_id): """ pass - def delete_server_security_groups(self, openstack_id): + def remove_security_groups_from_server(self, openstack_id): """ Parameters: - openstack_id @@ -1484,24 +1484,24 @@ def recv_delete_security_group_rule(self): raise result.f return - def delete_server_security_groups(self, openstack_id): + def remove_security_groups_from_server(self, openstack_id): """ Parameters: - openstack_id """ - self.send_delete_server_security_groups(openstack_id) - self.recv_delete_server_security_groups() + self.send_remove_security_groups_from_server(openstack_id) + self.recv_remove_security_groups_from_server() - def send_delete_server_security_groups(self, openstack_id): - self._oprot.writeMessageBegin('delete_server_security_groups', TMessageType.CALL, self._seqid) - args = delete_server_security_groups_args() + def send_remove_security_groups_from_server(self, openstack_id): + self._oprot.writeMessageBegin('remove_security_groups_from_server', TMessageType.CALL, self._seqid) + args = remove_security_groups_from_server_args() args.openstack_id = openstack_id args.write(self._oprot) self._oprot.writeMessageEnd() self._oprot.trans.flush() - def recv_delete_server_security_groups(self): + def recv_remove_security_groups_from_server(self): iprot = self._iprot (fname, mtype, rseqid) = iprot.readMessageBegin() if mtype == TMessageType.EXCEPTION: @@ -1509,7 +1509,7 @@ def recv_delete_server_security_groups(self): x.read(iprot) iprot.readMessageEnd() raise x - result = delete_server_security_groups_result() + result = remove_security_groups_from_server_result() result.read(iprot) iprot.readMessageEnd() if result.e is not None: @@ -3628,7 +3628,7 @@ def __init__(self, handler): self._processMap["resize_volume"] = Processor.process_resize_volume self._processMap["open_port_range_for_vm_in_project"] = Processor.process_open_port_range_for_vm_in_project self._processMap["delete_security_group_rule"] = Processor.process_delete_security_group_rule - self._processMap["delete_server_security_groups"] = Processor.process_delete_server_security_groups + self._processMap["remove_security_groups_from_server"] = Processor.process_remove_security_groups_from_server self._processMap["delete_server"] = Processor.process_delete_server self._processMap["rescue_server"] = Processor.process_rescue_server self._processMap["unrescue_server"] = Processor.process_unrescue_server @@ -4218,20 +4218,20 @@ def process_delete_security_group_rule(self, seqid, iprot, oprot): oprot.writeMessageEnd() oprot.trans.flush() - def process_delete_server_security_groups(self, seqid, iprot, oprot): - args = delete_server_security_groups_args() + def process_remove_security_groups_from_server(self, seqid, iprot, oprot): + args = remove_security_groups_from_server_args() args.read(iprot) iprot.readMessageEnd() - result = delete_server_security_groups_result() + result = remove_security_groups_from_server_result() try: - self._handler.delete_server_security_groups(args.openstack_id) + self._handler.remove_security_groups_from_server(args.openstack_id) msg_type = TMessageType.REPLY except TTransport.TTransportException: raise except SecurityGroupRuleNotFoundException as e: msg_type = TMessageType.REPLY result.e = e - except DefaultException as f: + except OpenStackConflictException as f: msg_type = TMessageType.REPLY result.f = f except TApplicationException as ex: @@ -4242,7 +4242,7 @@ def process_delete_server_security_groups(self, seqid, iprot, oprot): logging.exception('Unexpected exception in handler') msg_type = TMessageType.EXCEPTION result = TApplicationException(TApplicationException.INTERNAL_ERROR, 'Internal error') - oprot.writeMessageBegin("delete_server_security_groups", msg_type, seqid) + oprot.writeMessageBegin("remove_security_groups_from_server", msg_type, seqid) result.write(oprot) oprot.writeMessageEnd() oprot.trans.flush() @@ -8446,7 +8446,7 @@ def __ne__(self, other): ) -class delete_server_security_groups_args(object): +class remove_security_groups_from_server_args(object): """ Attributes: - openstack_id @@ -8480,7 +8480,7 @@ def write(self, oprot): if oprot._fast_encode is not None and self.thrift_spec is not None: oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec])) return - oprot.writeStructBegin('delete_server_security_groups_args') + oprot.writeStructBegin('remove_security_groups_from_server_args') if self.openstack_id is not None: oprot.writeFieldBegin('openstack_id', TType.STRING, 1) oprot.writeString(self.openstack_id.encode('utf-8') if sys.version_info[0] == 2 else self.openstack_id) @@ -8501,14 +8501,14 @@ def __eq__(self, other): def __ne__(self, other): return not (self == other) -all_structs.append(delete_server_security_groups_args) -delete_server_security_groups_args.thrift_spec = ( +all_structs.append(remove_security_groups_from_server_args) +remove_security_groups_from_server_args.thrift_spec = ( None, # 0 (1, TType.STRING, 'openstack_id', 'UTF8', None, ), # 1 ) -class delete_server_security_groups_result(object): +class remove_security_groups_from_server_result(object): """ Attributes: - e @@ -8537,7 +8537,7 @@ def read(self, iprot): iprot.skip(ftype) elif fid == 2: if ftype == TType.STRUCT: - self.f = DefaultException.read(iprot) + self.f = OpenStackConflictException.read(iprot) else: iprot.skip(ftype) else: @@ -8549,7 +8549,7 @@ def write(self, oprot): if oprot._fast_encode is not None and self.thrift_spec is not None: oprot.trans.write(oprot._fast_encode(self, [self.__class__, self.thrift_spec])) return - oprot.writeStructBegin('delete_server_security_groups_result') + oprot.writeStructBegin('remove_security_groups_from_server_result') if self.e is not None: oprot.writeFieldBegin('e', TType.STRUCT, 1) self.e.write(oprot) @@ -8574,11 +8574,11 @@ def __eq__(self, other): def __ne__(self, other): return not (self == other) -all_structs.append(delete_server_security_groups_result) -delete_server_security_groups_result.thrift_spec = ( +all_structs.append(remove_security_groups_from_server_result) +remove_security_groups_from_server_result.thrift_spec = ( None, # 0 (1, TType.STRUCT, 'e', [SecurityGroupRuleNotFoundException, None], None, ), # 1 - (2, TType.STRUCT, 'f', [DefaultException, None], None, ), # 2 + (2, TType.STRUCT, 'f', [OpenStackConflictException, None], None, ), # 2 ) diff --git a/simple_vm_client/openstack_connector/openstack_connector.py b/simple_vm_client/openstack_connector/openstack_connector.py index 2c09185..fa2f074 100644 --- a/simple_vm_client/openstack_connector/openstack_connector.py +++ b/simple_vm_client/openstack_connector/openstack_connector.py @@ -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" @@ -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 diff --git a/simple_vm_client/test_openstack_connector.py b/simple_vm_client/test_openstack_connector.py index f65ac09..bb03cce 100644 --- a/simple_vm_client/test_openstack_connector.py +++ b/simple_vm_client/test_openstack_connector.py @@ -2925,17 +2925,17 @@ 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 @@ -2943,7 +2943,7 @@ def test_delete_server_security_groups_failure(self, mock_get_server): 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 ) diff --git a/simple_vm_client/test_virtualmachinehandler.py b/simple_vm_client/test_virtualmachinehandler.py index be57f6d..94b5813 100644 --- a/simple_vm_client/test_virtualmachinehandler.py +++ b/simple_vm_client/test_virtualmachinehandler.py @@ -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 )