Skip to content

Commit

Permalink
Support for dbaas v2 (#479)
Browse files Browse the repository at this point in the history
## 📝 Description

**What does this PR do and why is this change necessary?**

Adds new fields for dbaas 2 as well as a mehod for forking.

## ✔️ How to Test

**How do I run the relevant unit/integration tests?**

```bash
RUN_DB_FORK_TESTS=yes make testint TEST_SUITE=database
```

the tests are still very long so i left the skips in

---------

Co-authored-by: ykim-1 <[email protected]>
Co-authored-by: Youjung Kim <[email protected]>
  • Loading branch information
3 people authored Feb 4, 2025
1 parent d3de874 commit 761734b
Show file tree
Hide file tree
Showing 5 changed files with 290 additions and 255 deletions.
18 changes: 17 additions & 1 deletion .github/workflows/e2e-test-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@ on:
pull_request:
workflow_dispatch:
inputs:
run_db_fork_tests:
description: 'Set this parameter to "true" to run fork database related test cases'
required: false
default: 'false'
type: choice
options:
- 'true'
- 'false'
run_db_tests:
description: 'Set this parameter to "true" to run database related test cases'
required: false
default: 'false'
type: choice
options:
- 'true'
- 'false'
test_suite:
description: 'Enter specific test suite. E.g. domain, linode_client'
required: false
Expand Down Expand Up @@ -80,7 +96,7 @@ jobs:
run: |
timestamp=$(date +'%Y%m%d%H%M')
report_filename="${timestamp}_sdk_test_report.xml"
make test-int TEST_ARGS="--junitxml=${report_filename}" TEST_SUITE="${{ github.event.inputs.test_suite }}"
make test-int RUN_DB_FORK_TESTS=${{ github.event.inputs.run_db_fork_tests }} RUN_DB_TESTS=${{ github.event.inputs.run_db_tests }} TEST_ARGS="--junitxml=${report_filename}" TEST_SUITE="${{ github.event.inputs.test_suite }}"
env:
LINODE_TOKEN: ${{ secrets.LINODE_TOKEN }}

Expand Down
21 changes: 20 additions & 1 deletion .github/workflows/e2e-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,25 @@ name: Integration Tests
on:
workflow_dispatch:
inputs:
run_db_fork_tests:
description: 'Set this parameter to "true" to run fork database related test cases'
required: false
default: 'false'
type: choice
options:
- 'true'
- 'false'
run_db_tests:
description: 'Set this parameter to "true" to run database related test cases'
required: false
default: 'false'
type: choice
options:
- 'true'
- 'false'
test_suite:
description: 'Enter specific test suite. E.g. domain, linode_client'
required: false
use_minimal_test_account:
description: 'Indicate whether to use a minimal test account with limited resources for testing. Defaults to "false"'
required: false
Expand Down Expand Up @@ -72,7 +91,7 @@ jobs:
run: |
timestamp=$(date +'%Y%m%d%H%M')
report_filename="${timestamp}_sdk_test_report.xml"
make test-int TEST_ARGS="--junitxml=${report_filename}"
make test-int RUN_DB_FORK_TESTS=${{ github.event.inputs.run_db_fork_tests }} RUN_DB_TESTS=${{ github.event.inputs.run_db_tests }} TEST_SUITE="${{ github.event.inputs.test_suite }}" TEST_ARGS="--junitxml=${report_filename}"
env:
LINODE_TOKEN: ${{ env.LINODE_TOKEN }}

Expand Down
134 changes: 125 additions & 9 deletions linode_api4/groups/database.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from linode_api4.errors import UnexpectedResponseError
from linode_api4.groups import Group
from linode_api4.objects import (
Base,
Database,
DatabaseEngine,
DatabaseType,
MySQLDatabase,
PostgreSQLDatabase,
drop_null_keys,
)
from linode_api4.objects.base import _flatten_request_body_recursive


class DatabaseGroup(Group):
Expand Down Expand Up @@ -126,13 +127,71 @@ def mysql_create(self, label, region, engine, ltype, **kwargs):

params = {
"label": label,
"region": region.id if issubclass(type(region), Base) else region,
"engine": engine.id if issubclass(type(engine), Base) else engine,
"type": ltype.id if issubclass(type(ltype), Base) else ltype,
"region": region,
"engine": engine,
"type": ltype,
}
params.update(kwargs)

result = self.client.post("/databases/mysql/instances", data=params)
result = self.client.post(
"/databases/mysql/instances",
data=_flatten_request_body_recursive(drop_null_keys(params)),
)

if "id" not in result:
raise UnexpectedResponseError(
"Unexpected response when creating MySQL Database", json=result
)

d = MySQLDatabase(self.client, result["id"], result)
return d

def mysql_fork(self, source, restore_time, **kwargs):
"""
Forks an :any:`MySQLDatabase` on this account with
the given restore_time. label, region, engine, and ltype are optional.
For example::
client = LinodeClient(TOKEN)
db_to_fork = client.database.mysql_instances()[0]
new_fork = client.database.mysql_fork(
db_to_fork.id,
db_to_fork.updated,
label="new-fresh-label"
)
API Documentation: https://techdocs.akamai.com/linode-api/reference/post-databases-mysql-instances
:param source: The id of the source database
:type source: int
:param restore_time: The timestamp for the fork
:type restore_time: datetime
:param label: The name for this cluster
:type label: str
:param region: The region to deploy this cluster in
:type region: str | Region
:param engine: The engine to deploy this cluster with
:type engine: str | Engine
:param ltype: The Linode Type to use for this cluster
:type ltype: str | Type
"""

params = {
"fork": {
"source": source,
"restore_time": restore_time.strftime("%Y-%m-%dT%H:%M:%S"),
}
}
if "ltype" in kwargs:
params["type"] = kwargs["ltype"]
params.update(kwargs)

result = self.client.post(
"/databases/mysql/instances",
data=_flatten_request_body_recursive(drop_null_keys(params)),
)

if "id" not in result:
raise UnexpectedResponseError(
Expand Down Expand Up @@ -191,14 +250,71 @@ def postgresql_create(self, label, region, engine, ltype, **kwargs):

params = {
"label": label,
"region": region.id if issubclass(type(region), Base) else region,
"engine": engine.id if issubclass(type(engine), Base) else engine,
"type": ltype.id if issubclass(type(ltype), Base) else ltype,
"region": region,
"engine": engine,
"type": ltype,
}
params.update(kwargs)

result = self.client.post(
"/databases/postgresql/instances",
data=_flatten_request_body_recursive(drop_null_keys(params)),
)

if "id" not in result:
raise UnexpectedResponseError(
"Unexpected response when creating PostgreSQL Database",
json=result,
)

d = PostgreSQLDatabase(self.client, result["id"], result)
return d

def postgresql_fork(self, source, restore_time, **kwargs):
"""
Forks an :any:`PostgreSQLDatabase` on this account with
the given restore_time. label, region, engine, and ltype are optional.
For example::
client = LinodeClient(TOKEN)
db_to_fork = client.database.postgresql_instances()[0]
new_fork = client.database.postgresql_fork(
db_to_fork.id,
db_to_fork.updated,
label="new-fresh-label"
)
API Documentation: https://techdocs.akamai.com/linode-api/reference/post-databases-postgresql-instances
:param source: The id of the source database
:type source: int
:param restore_time: The timestamp for the fork
:type restore_time: datetime
:param label: The name for this cluster
:type label: str
:param region: The region to deploy this cluster in
:type region: str | Region
:param engine: The engine to deploy this cluster with
:type engine: str | Engine
:param ltype: The Linode Type to use for this cluster
:type ltype: str | Type
"""

params = {
"fork": {
"source": source,
"restore_time": restore_time.strftime("%Y-%m-%dT%H:%M:%S"),
}
}
if "ltype" in kwargs:
params["type"] = kwargs["ltype"]
params.update(kwargs)

result = self.client.post(
"/databases/postgresql/instances", data=params
"/databases/postgresql/instances",
data=_flatten_request_body_recursive(drop_null_keys(params)),
)

if "id" not in result:
Expand Down
13 changes: 9 additions & 4 deletions linode_api4/objects/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class MySQLDatabase(Base):
"label": Property(mutable=True),
"allow_list": Property(mutable=True, unordered=True),
"backups": Property(derived_class=MySQLDatabaseBackup),
"cluster_size": Property(),
"cluster_size": Property(mutable=True),
"created": Property(is_datetime=True),
"encrypted": Property(),
"engine": Property(),
Expand All @@ -141,7 +141,9 @@ class MySQLDatabase(Base):
"replication_type": Property(),
"ssl_connection": Property(),
"status": Property(volatile=True),
"type": Property(),
"type": Property(mutable=True),
"fork": Property(),
"oldest_restore_time": Property(is_datetime=True),
"updated": Property(volatile=True, is_datetime=True),
"updates": Property(mutable=True),
"version": Property(),
Expand Down Expand Up @@ -264,7 +266,7 @@ class PostgreSQLDatabase(Base):
"label": Property(mutable=True),
"allow_list": Property(mutable=True, unordered=True),
"backups": Property(derived_class=PostgreSQLDatabaseBackup),
"cluster_size": Property(),
"cluster_size": Property(mutable=True),
"created": Property(is_datetime=True),
"encrypted": Property(),
"engine": Property(),
Expand All @@ -275,7 +277,9 @@ class PostgreSQLDatabase(Base):
"replication_type": Property(),
"ssl_connection": Property(),
"status": Property(volatile=True),
"type": Property(),
"type": Property(mutable=True),
"fork": Property(),
"oldest_restore_time": Property(is_datetime=True),
"updated": Property(volatile=True, is_datetime=True),
"updates": Property(mutable=True),
"version": Property(),
Expand Down Expand Up @@ -414,6 +418,7 @@ class Database(Base):
"region": Property(),
"status": Property(),
"type": Property(),
"fork": Property(),
"updated": Property(),
"updates": Property(),
"version": Property(),
Expand Down
Loading

0 comments on commit 761734b

Please sign in to comment.