Merged PR 380: #2561 - Set the DatabaseServer service to automatically install the FTPClient

## Summary
- Set the DatabaseServer service to automatically install the upon install to enable backup. Added some defensive statements that gracefully handle backup/restore requests when FTPClient is not installed.

## Test process
Added test that installs `DatabaseServer` on a new node then checks for an installed `FTPClient`.

## Checklist
- [ ] PR is linked to a **work item**
- [ ] **acceptance criteria** of linked ticket are met
- [ ] performed **self-review** of the code
- [ ] written **tests** for any new functionality added with this PR
- [ ] updated the **documentation** if this PR changes or adds functionality
- [ ] written/updated **design docs** if this PR implements new functionality
- [ ] updated the **change log**
- [ ] ran **pre-commit** checks for code style
- [ ] attended to any **TO-DOs** left in the code

#2561 - Set the DatabaseServer service to automatically install the  upon install to enable backup. Added some defensive statements that gracefully handle backup/restore requests when FTPClient is not

Related work items: #2561, #2570
This commit is contained in:
Christopher McCarthy
2024-05-21 08:56:50 +00:00
3 changed files with 33 additions and 3 deletions

View File

@@ -177,9 +177,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.11"
"version": "3.8.10"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}

View File

@@ -42,6 +42,18 @@ class DatabaseService(Service):
super().__init__(**kwargs)
self._create_db_file()
def install(self):
"""
Perform first-time setup of the DatabaseService.
Installs an instance of FTPClient on the Node to enable database backup if it isn't installed already.
"""
super().install()
if not self.parent.software_manager.software.get("FTPClient"):
self.parent.sys_log.info(f"{self.name}: Installing FTPClient to enable database backups")
self.parent.software_manager.install(FTPClient)
def configure_backup(self, backup_server: IPv4Address):
"""
Set up the database backup.
@@ -64,9 +76,15 @@ class DatabaseService(Service):
software_manager: SoftwareManager = self.software_manager
ftp_client_service: FTPClient = software_manager.software.get("FTPClient")
if not ftp_client_service:
self.sys_log.error(
f"{self.name}: Failed to perform database backup as the FTPClient software is not installed"
)
return False
# send backup copy of database file to FTP server
if not self.db_file:
self.sys_log.error("Attempted to backup database file but it doesn't exist.")
self.sys_log.error(f"{self.name}: Attempted to backup database file but it doesn't exist.")
return False
response = ftp_client_service.send_file(
@@ -92,6 +110,12 @@ class DatabaseService(Service):
software_manager: SoftwareManager = self.software_manager
ftp_client_service: FTPClient = software_manager.software.get("FTPClient")
if not ftp_client_service:
self.sys_log.error(
f"{self.name}: Failed to restore database backup as the FTPClient software is not installed"
)
return False
# retrieve backup file from backup server
response = ftp_client_service.request_file(
src_folder_name=str(self.uuid),

View File

@@ -356,3 +356,9 @@ def test_client_connection_terminate_does_not_terminate_another_clients_connecti
assert db_connection_b.query("SELECT")
assert len(db_service.connections) == 1
def test_database_server_install_ftp_client():
server = Server(hostname="db_server", ip_address="192.168.1.2", subnet_mask="255.255.255.0", start_up_duration=0)
server.software_manager.install(DatabaseService)
assert server.software_manager.software.get("FTPClient")