Skip to content

Commit f8c714a

Browse files
committed
Migrate postgresql operations & tests to use explicit fact imports.
1 parent ad0ecfc commit f8c714a

14 files changed

+57
-24
lines changed

pyinfra/operations/postgresql.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@
1414
'''
1515

1616
from pyinfra.api import MaskString, operation, StringCommand
17-
from pyinfra.facts.postgresql import make_execute_psql_command, make_psql_command
17+
from pyinfra.facts.postgresql import (
18+
make_execute_psql_command,
19+
make_psql_command,
20+
PostgresqlDatabases,
21+
PostgresqlRoles,
22+
)
1823

1924

2025
@operation(is_idempotent=False)
@@ -90,9 +95,12 @@ def role(
9095
9196
'''
9297

93-
roles = host.fact.postgresql_roles(
94-
postgresql_user, postgresql_password,
95-
postgresql_host, postgresql_port,
98+
roles = host.get_fact(
99+
PostgresqlRoles,
100+
postgresql_user=postgresql_user,
101+
postgresql_password=postgresql_password,
102+
postgresql_host=postgresql_host,
103+
postgresql_port=postgresql_port,
96104
)
97105

98106
is_present = role in roles
@@ -188,9 +196,12 @@ def database(
188196
189197
'''
190198

191-
current_databases = host.fact.postgresql_databases(
192-
postgresql_user, postgresql_password,
193-
postgresql_host, postgresql_port,
199+
current_databases = host.get_fact(
200+
PostgresqlDatabases,
201+
postgresql_user=postgresql_user,
202+
postgresql_password=postgresql_password,
203+
postgresql_host=postgresql_host,
204+
postgresql_port=postgresql_port,
194205
)
195206

196207
is_present = database in current_databases

tests/operations/postgresql.database/add_database.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
{
22
"args": ["somedb"],
33
"facts" :{
4-
"postgresql_databases": {}
4+
"postgresql.PostgresqlDatabases": {
5+
"postgresql_user=None, postgresql_password=None, postgresql_host=None, postgresql_port=None": {}
6+
}
57
},
68
"commands": [
79
"psql -Ac 'CREATE DATABASE \"somedb\"'"

tests/operations/postgresql.database/add_database_noop.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
{
22
"args": ["somedb"],
33
"facts" :{
4-
"postgresql_databases": {
5-
"somedb": {}
4+
"postgresql.PostgresqlDatabases": {
5+
"postgresql_user=None, postgresql_password=None, postgresql_host=None, postgresql_port=None": {
6+
"somedb": {}
7+
}
68
}
79
},
810
"commands": [],

tests/operations/postgresql.database/add_database_owner.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
"owner": "someowner"
55
},
66
"facts" :{
7-
"postgresql_databases": {}
7+
"postgresql.PostgresqlDatabases": {
8+
"postgresql_user=None, postgresql_password=None, postgresql_host=None, postgresql_port=None": {}
9+
}
810
},
911
"commands": [
1012
"psql -Ac 'CREATE DATABASE \"somedb\" OWNER \"someowner\"'"

tests/operations/postgresql.database/remove_database.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
"present": false
55
},
66
"facts" :{
7-
"postgresql_databases": {
8-
"somedb": {}
7+
"postgresql.PostgresqlDatabases": {
8+
"postgresql_user=None, postgresql_password=None, postgresql_host=None, postgresql_port=None": {
9+
"somedb": {}
10+
}
911
}
1012
},
1113
"commands": [

tests/operations/postgresql.database/remove_database_noop.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
"present": false
55
},
66
"facts" :{
7-
"postgresql_databases": {}
7+
"postgresql.PostgresqlDatabases": {
8+
"postgresql_user=None, postgresql_password=None, postgresql_host=None, postgresql_port=None": {}
9+
}
810
},
911
"commands": [],
1012
"noop_description": "postgresql database somedb does not exist"

tests/operations/postgresql.role/role_add_noop.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
{
22
"args": ["testuser"],
33
"facts": {
4-
"postgresql_roles": {
5-
"testuser": {}
4+
"postgresql.PostgresqlRoles": {
5+
"postgresql_user=None, postgresql_password=None, postgresql_host=None, postgresql_port=None": {
6+
"testuser": {}
7+
}
68
}
79
},
810
"commands": [],

tests/operations/postgresql.role/role_remove_noop.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
"present": false
55
},
66
"facts": {
7-
"postgresql_roles": {}
7+
"postgresql.PostgresqlRoles": {
8+
"postgresql_user=None, postgresql_password=None, postgresql_host=None, postgresql_port=None": {}
9+
}
810
},
911
"commands": [],
1012
"noop_description": "postgresql role testuser does not exist"

tests/operations/postgresql.role/user_add.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
"password": "abc"
66
},
77
"facts": {
8-
"postgresql_roles": {}
8+
"postgresql.PostgresqlRoles": {
9+
"postgresql_user=None, postgresql_password=None, postgresql_host=None, postgresql_port=None": {}
10+
}
911
},
1012
"commands": [
1113
[

tests/operations/postgresql.role/user_add_no_login.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"login": false
55
},
66
"facts": {
7-
"postgresql_roles": {
7+
"postgresql.PostgresqlRoles": {
8+
"postgresql_user=None, postgresql_password=None, postgresql_host=None, postgresql_port=None": {}
89
}
910
},
1011
"commands": [

0 commit comments

Comments
 (0)