Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 0 additions & 115 deletions linode_api4/objects/database.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
from dataclasses import dataclass, field
from typing import Optional

from deprecated import deprecated

from linode_api4.objects import (
Base,
DerivedBase,
JSONObject,
MappedObject,
Property,
Expand Down Expand Up @@ -86,69 +83,6 @@ class DatabasePrivateNetwork(JSONObject):
public_access: Optional[bool] = None


@deprecated(
reason="Backups are not supported for non-legacy database clusters."
)
class DatabaseBackup(DerivedBase):
"""
A generic Managed Database backup.

This class is not intended to be used on its own.
Use the appropriate subclasses for the corresponding database engine. (e.g. MySQLDatabaseBackup)
"""

api_endpoint = ""
derived_url_path = "backups"
parent_id_name = "database_id"

properties = {
"created": Property(is_datetime=True),
"id": Property(identifier=True),
"label": Property(),
"type": Property(),
}

def restore(self):
"""
Restore a backup to a Managed Database on your Account.

API Documentation:

- MySQL: https://techdocs.akamai.com/linode-api/reference/post-databases-mysql-instance-backup-restore
- PostgreSQL: https://techdocs.akamai.com/linode-api/reference/post-databases-postgre-sql-instance-backup-restore
"""

return self._client.post(
"{}/restore".format(self.api_endpoint), model=self
)


@deprecated(
reason="Backups are not supported for non-legacy database clusters."
)
class MySQLDatabaseBackup(DatabaseBackup):
"""
A backup for an accessible Managed MySQL Database.

API Documentation: https://techdocs.akamai.com/linode-api/reference/get-databases-mysql-instance-backup
"""

api_endpoint = "/databases/mysql/instances/{database_id}/backups/{id}"


@deprecated(
reason="Backups are not supported for non-legacy database clusters."
)
class PostgreSQLDatabaseBackup(DatabaseBackup):
"""
A backup for an accessible Managed PostgreSQL Database.

API Documentation: https://techdocs.akamai.com/linode-api/reference/get-databases-postgresql-instance-backup
"""

api_endpoint = "/databases/postgresql/instances/{database_id}/backups/{id}"


@dataclass
class MySQLDatabaseConfigMySQLOptions(JSONObject):
"""
Expand Down Expand Up @@ -296,15 +230,13 @@ class MySQLDatabase(Base):
"id": Property(identifier=True),
"label": Property(mutable=True),
"allow_list": Property(mutable=True, unordered=True),
"backups": Property(derived_class=MySQLDatabaseBackup),
"cluster_size": Property(mutable=True),
"created": Property(is_datetime=True),
"encrypted": Property(),
"engine": Property(),
"hosts": Property(),
"port": Property(),
"region": Property(),
"replication_type": Property(),
"ssl_connection": Property(),
"status": Property(volatile=True),
"type": Property(mutable=True),
Expand Down Expand Up @@ -393,28 +325,6 @@ def patch(self):
"{}/patch".format(MySQLDatabase.api_endpoint), model=self
)

@deprecated(
reason="Backups are not supported for non-legacy database clusters."
)
def backup_create(self, label, **kwargs):
"""
Creates a snapshot backup of a Managed MySQL Database.

API Documentation: https://techdocs.akamai.com/linode-api/reference/post-databases-mysql-instance-backup
"""

params = {
"label": label,
}
params.update(kwargs)

self._client.post(
"{}/backups".format(MySQLDatabase.api_endpoint),
model=self,
data=params,
)
self.invalidate()

def invalidate(self):
"""
Clear out cached properties.
Expand Down Expand Up @@ -464,16 +374,13 @@ class PostgreSQLDatabase(Base):
"id": Property(identifier=True),
"label": Property(mutable=True),
"allow_list": Property(mutable=True, unordered=True),
"backups": Property(derived_class=PostgreSQLDatabaseBackup),
"cluster_size": Property(mutable=True),
"created": Property(is_datetime=True),
"encrypted": Property(),
"engine": Property(),
"hosts": Property(),
"port": Property(),
"region": Property(),
"replication_commit_type": Property(),
"replication_type": Property(),
"ssl_connection": Property(),
"status": Property(volatile=True),
"type": Property(mutable=True),
Expand Down Expand Up @@ -563,28 +470,6 @@ def patch(self):
"{}/patch".format(PostgreSQLDatabase.api_endpoint), model=self
)

@deprecated(
reason="Backups are not supported for non-legacy database clusters."
)
def backup_create(self, label, **kwargs):
"""
Creates a snapshot backup of a Managed PostgreSQL Database.

API Documentation: https://techdocs.akamai.com/linode-api/reference/post-databases-postgre-sql-instance-backup
"""

params = {
"label": label,
}
params.update(kwargs)

self._client.post(
"{}/backups".format(PostgreSQLDatabase.api_endpoint),
model=self,
data=params,
)
self.invalidate()

def invalidate(self):
"""
Clear out cached properties.
Expand Down
13 changes: 0 additions & 13 deletions test/fixtures/databases_mysql_instances_123_backups.json

This file was deleted.

This file was deleted.

13 changes: 0 additions & 13 deletions test/fixtures/databases_postgresql_instances_123_backups.json

This file was deleted.

This file was deleted.

115 changes: 0 additions & 115 deletions test/unit/objects/database_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,63 +116,6 @@ def test_update(self):
m.call_data["private_network"]["public_access"], True
)

def test_list_backups(self):
"""
Test that MySQL backups list properly
"""

db = MySQLDatabase(self.client, 123)
backups = db.backups

self.assertEqual(len(backups), 1)

self.assertEqual(backups[0].id, 456)
self.assertEqual(
backups[0].label, "Scheduled - 02/04/22 11:11 UTC-XcCRmI"
)
self.assertEqual(backups[0].type, "auto")

def test_create_backup(self):
"""
Test that MySQL database backups can be updated
"""

with self.mock_post("/databases/mysql/instances/123/backups") as m:
db = MySQLDatabase(self.client, 123)

# We don't care about errors here; we just want to
# validate the request.
try:
db.backup_create("mybackup", target="standby")
except Exception as e:
logger.warning(
"An error occurred while validating the request: %s", e
)

self.assertEqual(m.method, "post")
self.assertEqual(
m.call_url, "/databases/mysql/instances/123/backups"
)
self.assertEqual(m.call_data["label"], "mybackup")
self.assertEqual(m.call_data["target"], "standby")

def test_backup_restore(self):
"""
Test that MySQL database backups can be restored
"""

with self.mock_post(
"/databases/mysql/instances/123/backups/456/restore"
) as m:
db = MySQLDatabase(self.client, 123)

db.backups[0].restore()

self.assertEqual(m.method, "post")
self.assertEqual(
m.call_url, "/databases/mysql/instances/123/backups/456/restore"
)

def test_patch(self):
"""
Test MySQL Database patching logic.
Expand Down Expand Up @@ -383,64 +326,6 @@ def test_update(self):
m.call_data["private_network"]["public_access"], True
)

def test_list_backups(self):
"""
Test that PostgreSQL backups list properly
"""

db = PostgreSQLDatabase(self.client, 123)
backups = db.backups

self.assertEqual(len(backups), 1)

self.assertEqual(backups[0].id, 456)
self.assertEqual(
backups[0].label, "Scheduled - 02/04/22 11:11 UTC-XcCRmI"
)
self.assertEqual(backups[0].type, "auto")

def test_create_backup(self):
"""
Test that PostgreSQL database backups can be created
"""

with self.mock_post("/databases/postgresql/instances/123/backups") as m:
db = PostgreSQLDatabase(self.client, 123)

# We don't care about errors here; we just want to
# validate the request.
try:
db.backup_create("mybackup", target="standby")
except Exception as e:
logger.warning(
"An error occurred while validating the request: %s", e
)

self.assertEqual(m.method, "post")
self.assertEqual(
m.call_url, "/databases/postgresql/instances/123/backups"
)
self.assertEqual(m.call_data["label"], "mybackup")
self.assertEqual(m.call_data["target"], "standby")

def test_backup_restore(self):
"""
Test that PostgreSQL database backups can be restored
"""

with self.mock_post(
"/databases/postgresql/instances/123/backups/456/restore"
) as m:
db = PostgreSQLDatabase(self.client, 123)

db.backups[0].restore()

self.assertEqual(m.method, "post")
self.assertEqual(
m.call_url,
"/databases/postgresql/instances/123/backups/456/restore",
)

def test_patch(self):
"""
Test PostgreSQL Database patching logic.
Expand Down