Skip to content

Commit b5e5d51

Browse files
Added more unit tests and removed config_update methods
1 parent f474d1c commit b5e5d51

5 files changed

Lines changed: 326 additions & 105 deletions

File tree

linode_api4/groups/database.py

Lines changed: 0 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -238,54 +238,6 @@ def mysql_fork(self, source, restore_time, **kwargs):
238238
d = MySQLDatabase(self.client, result["id"], result)
239239
return d
240240

241-
def mysql_update_config(
242-
self,
243-
engine_config: Union[MySQLDatabaseConfigOptions, Dict[str, Any]] = None,
244-
**kwargs,
245-
):
246-
"""
247-
Updates the config of :any:`MySQLDatabase` on this account with
248-
the given engine_config.
249-
For example::
250-
251-
client = LinodeClient(TOKEN)
252-
253-
db_to_update_config = client.database.mysql_instances()[0]
254-
255-
new_engine_config = MySQLDatabaseConfigOptions(
256-
mysql=MySQLDatabaseConfigMySQLOptions(connect_timeout=20),
257-
service_log=True
258-
)
259-
260-
db_with_new_config = client.database.mysql_update_config(
261-
new_engine_config
262-
)
263-
264-
API Documentation: https://techdocs.akamai.com/linode-api/reference/post-databases-mysql-instances
265-
266-
:param engine_config: The configuration options for this MySQL cluster
267-
:type engine_config: Dict[str, Any] or MySQLDatabaseConfigOptions
268-
"""
269-
270-
params = {
271-
"engine_config": engine_config,
272-
}
273-
params.update(kwargs)
274-
275-
result = self.client.post(
276-
"/databases/mysql/instances",
277-
data=_flatten_request_body_recursive(drop_null_keys(params)),
278-
)
279-
280-
if "id" not in result:
281-
raise UnexpectedResponseError(
282-
"Unexpected response when updating MySQL Database config",
283-
json=result,
284-
)
285-
286-
d = MySQLDatabase(self.client, result["id"], result)
287-
return d
288-
289241
def postgresql_instances(self, *filters):
290242
"""
291243
Returns a list of Managed PostgreSQL Databases active on this account.
@@ -423,53 +375,3 @@ def postgresql_fork(self, source, restore_time, **kwargs):
423375

424376
d = PostgreSQLDatabase(self.client, result["id"], result)
425377
return d
426-
427-
def postgresql_update_config(
428-
self,
429-
engine_config: Union[
430-
PostgreSQLDatabaseConfigOptions, Dict[str, Any]
431-
] = None,
432-
**kwargs,
433-
):
434-
"""
435-
Updates the config of :any:`PostgreSQLDatabase` on this account with
436-
the given engine_config.
437-
For example::
438-
439-
client = LinodeClient(TOKEN)
440-
441-
db_to_update_config = client.database.postgresql_instances()[0]
442-
443-
new_engine_config = PostgreSQLDatabaseConfigOptions(
444-
pg=PostgreSQLDatabaseConfigPGOptions(log_temp_files=200),
445-
service_log=True
446-
)
447-
448-
db_with_new_config = client.database.postgresql_update_config(
449-
new_engine_config
450-
)
451-
452-
API Documentation: https://techdocs.akamai.com/linode-api/reference/post-databases-postgresql-instances
453-
454-
:param engine_config: The configuration options for this PostgreSQL cluster
455-
:type engine_config: Dict[str, Any] or PostgreSQLDatabaseConfigOptions
456-
"""
457-
458-
params = {
459-
"engine_config": engine_config,
460-
}
461-
params.update(kwargs)
462-
463-
result = self.client.post(
464-
"/databases/postgresql/instances",
465-
data=_flatten_request_body_recursive(drop_null_keys(params)),
466-
)
467-
468-
if "id" not in result:
469-
raise UnexpectedResponseError(
470-
"Unexpected response when updating PostgreSQL Database config",
471-
json=result,
472-
)
473-
474-
d = PostgreSQLDatabase(self.client, result["id"], result)
475-
return d

linode_api4/objects/database.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ class MySQLDatabaseConfigOptions(JSONObject):
190190

191191

192192
@dataclass
193-
class PostgreSQLDatabasePGLookoutConfigOptions(JSONObject):
193+
class PostgreSQLDatabaseConfigPGLookoutOptions(JSONObject):
194194
"""
195195
PostgreSQLDatabasePGLookoutConfigOptions represents the fields in the pglookout
196196
field of the PostgreSQLDatabasePGConfigOptions class
@@ -200,7 +200,7 @@ class PostgreSQLDatabasePGLookoutConfigOptions(JSONObject):
200200

201201

202202
@dataclass
203-
class PostgreSQLDatabasePGConfigOptions(JSONObject):
203+
class PostgreSQLDatabaseConfigPGOptions(JSONObject):
204204
"""
205205
PostgreSQLDatabasePGConfigOptions represents the fields in the pg
206206
field of the PostgreSQLDatabasePGConfigOptions class
@@ -265,9 +265,9 @@ class PostgreSQLDatabaseConfigOptions(JSONObject):
265265
a PostgreSQL Database Cluster's configuration options during its creation.
266266
"""
267267

268-
pg: Optional[PostgreSQLDatabasePGConfigOptions] = None
268+
pg: Optional[PostgreSQLDatabaseConfigPGOptions] = None
269269
pg_stat_monitor_enable: Optional[bool] = None
270-
pglookout: Optional[PostgreSQLDatabasePGLookoutConfigOptions] = None
270+
pglookout: Optional[PostgreSQLDatabaseConfigPGLookoutOptions] = None
271271
service_log: Optional[bool] = None
272272
shared_buffers_percentage: Optional[float] = None
273273
synchronous_replication: Optional[str] = None

test/fixtures/databases_mysql_instances.json

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,44 @@
2929
"hour_of_day": 0,
3030
"week_of_month": null
3131
},
32-
"version": "8.0.26"
32+
"version": "8.0.26",
33+
"engine_config": {
34+
"binlog_retention_period": 600,
35+
"service_log": true,
36+
"mysql": {
37+
"connect_timeout": 10,
38+
"default_time_zone": "+03:00",
39+
"group_concat_max_len": 1024,
40+
"information_schema_stats_expiry": 86400,
41+
"innodb_change_buffer_max_size": 30,
42+
"innodb_flush_neighbors": 0,
43+
"innodb_ft_min_token_size": 3,
44+
"innodb_ft_server_stopword_table": "db_name/table_name",
45+
"innodb_lock_wait_timeout": 50,
46+
"innodb_log_buffer_size": 16777216,
47+
"innodb_online_alter_log_max_size": 134217728,
48+
"innodb_print_all_deadlocks": true,
49+
"innodb_read_io_threads": 10,
50+
"innodb_rollback_on_timeout": true,
51+
"innodb_thread_concurrency": 10,
52+
"innodb_write_io_threads": 10,
53+
"interactive_timeout": 3600,
54+
"internal_tmp_mem_storage_engine": "TempTable",
55+
"log_output": "INSIGHTS",
56+
"long_query_time": 10,
57+
"max_allowed_packet": 67108864,
58+
"max_heap_table_size": 16777216,
59+
"net_buffer_length": 16384,
60+
"net_read_timeout": 30,
61+
"net_write_timeout": 30,
62+
"slow_query_log": true,
63+
"sort_buffer_size": 262144,
64+
"sql_mode": "ANSI,TRADITIONAL",
65+
"sql_require_primary_key": true,
66+
"tmp_table_size": 16777216,
67+
"wait_timeout": 28800
68+
}
69+
}
3370
}
3471
],
3572
"page": 1,

test/fixtures/databases_postgresql_instances.json

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,69 @@
3030
"hour_of_day": 0,
3131
"week_of_month": null
3232
},
33-
"version": "13.2"
33+
"version": "13.2",
34+
"engine_config": {
35+
"pg": {
36+
"autovacuum_analyze_scale_factor": 0.5,
37+
"autovacuum_analyze_threshold": 100,
38+
"autovacuum_freeze_max_age": 400000000,
39+
"autovacuum_max_workers": 10,
40+
"autovacuum_naptime": 100,
41+
"autovacuum_vacuum_cost_delay": 50,
42+
"autovacuum_vacuum_cost_limit": 100,
43+
"autovacuum_vacuum_scale_factor": 0.5,
44+
"autovacuum_vacuum_threshold": 100,
45+
"bgwriter_delay": 200,
46+
"bgwriter_flush_after": 512,
47+
"bgwriter_lru_maxpages": 100,
48+
"bgwriter_lru_multiplier": 2.0,
49+
"deadlock_timeout": 1000,
50+
"default_toast_compression": "lz4",
51+
"idle_in_transaction_session_timeout": 100,
52+
"jit": true,
53+
"log_autovacuum_min_duration": 100,
54+
"log_error_verbosity": "DEFAULT",
55+
"log_line_prefix": "'pid=%p,user=%u,db=%d,app=%a,client=%h '",
56+
"log_min_duration_statement": 100,
57+
"log_temp_files": 100,
58+
"max_files_per_process": 100,
59+
"max_locks_per_transaction": 100,
60+
"max_logical_replication_workers": 32,
61+
"max_parallel_workers": 64,
62+
"max_parallel_workers_per_gather": 64,
63+
"max_pred_locks_per_transaction": 1000,
64+
"max_prepared_transactions": 5000,
65+
"max_replication_slots": 32,
66+
"max_slot_wal_keep_size": 100,
67+
"max_stack_depth": 3507152,
68+
"max_standby_archive_delay": 1000,
69+
"max_standby_streaming_delay": 1000,
70+
"max_wal_senders": 32,
71+
"max_worker_processes": 64,
72+
"password_encryption": "scram-sha-256",
73+
"pg_partman_bgw.interval": 3600,
74+
"pg_partman_bgw.role": "myrolename",
75+
"pg_stat_monitor.pgsm_enable_query_plan": false,
76+
"pg_stat_monitor.pgsm_max_buckets": 10,
77+
"pg_stat_statements.track": "top",
78+
"temp_file_limit": 5000000,
79+
"timezone": "Europe/Helsinki",
80+
"track_activity_query_size": 1024,
81+
"track_commit_timestamp": "off",
82+
"track_functions": "all",
83+
"track_io_timing": "off",
84+
"wal_sender_timeout": 60000,
85+
"wal_writer_delay": 50
86+
},
87+
"pg_stat_monitor_enable": true,
88+
"pglookout": {
89+
"max_failover_replication_time_lag": 1000
90+
},
91+
"service_log": false,
92+
"shared_buffers_percentage": 41.5,
93+
"synchronous_replication": "off",
94+
"work_mem": 4
95+
}
3496
}
3597
],
3698
"page": 1,

0 commit comments

Comments
 (0)