46
54
triggers = cursor.fetchall()
48
56
self.assertEqual(1, len(triggers), "Trigger was not created.")
59
class TestTriggersUsed(MAASServerTestCase):
60
"""Tests relating to those triggers the MAAS application uses."""
63
"config_sys_dhcp_config_ntp_servers_delete",
64
"config_sys_dhcp_config_ntp_servers_insert",
65
"config_sys_dhcp_config_ntp_servers_update",
66
"config_sys_dns_config_insert",
67
"config_sys_dns_config_update",
68
"dhcpsnippet_sys_dhcp_snippet_delete",
69
"dhcpsnippet_sys_dhcp_snippet_insert",
70
"dhcpsnippet_sys_dhcp_snippet_update",
71
"dnsdata_sys_dns_dnsdata_delete",
72
"dnsdata_sys_dns_dnsdata_insert",
73
"dnsdata_sys_dns_dnsdata_update",
74
"dnspublication_sys_dns_publish",
75
"dnsresource_ip_addresses_sys_dns_dnsresource_ip_link",
76
"dnsresource_ip_addresses_sys_dns_dnsresource_ip_unlink",
77
"dnsresource_sys_dns_dnsresource_delete",
78
"dnsresource_sys_dns_dnsresource_insert",
79
"dnsresource_sys_dns_dnsresource_update",
80
"domain_sys_dns_domain_delete",
81
"domain_sys_dns_domain_insert",
82
"domain_sys_dns_domain_update",
83
"interface_ip_addresses_sys_dns_nic_ip_link",
84
"interface_ip_addresses_sys_dns_nic_ip_unlink",
85
"interface_sys_dhcp_interface_update",
86
"interface_sys_dns_interface_update",
87
"iprange_sys_dhcp_iprange_delete",
88
"iprange_sys_dhcp_iprange_insert",
89
"iprange_sys_dhcp_iprange_update",
90
"node_sys_dhcp_node_update",
91
"node_sys_dns_node_delete",
92
"node_sys_dns_node_update",
93
"regionrackrpcconnection_sys_core_rpc_delete",
94
"regionrackrpcconnection_sys_core_rpc_insert",
95
"staticipaddress_sys_dhcp_staticipaddress_delete",
96
"staticipaddress_sys_dhcp_staticipaddress_insert",
97
"staticipaddress_sys_dhcp_staticipaddress_update",
98
"staticipaddress_sys_dns_staticipaddress_update",
99
"subnet_sys_dhcp_subnet_delete",
100
"subnet_sys_dhcp_subnet_update",
101
"subnet_sys_dns_subnet_delete",
102
"subnet_sys_dns_subnet_insert",
103
"subnet_sys_dns_subnet_update",
104
"subnet_sys_proxy_subnet_delete",
105
"subnet_sys_proxy_subnet_insert",
106
"subnet_sys_proxy_subnet_update",
107
"vlan_sys_dhcp_vlan_update",
110
triggers_websocket = {
111
"auth_user_user_create_notify",
112
"auth_user_user_delete_notify",
113
"auth_user_user_update_notify",
114
"blockdevice_nd_blockdevice_link_notify",
115
"blockdevice_nd_blockdevice_unlink_notify",
116
"blockdevice_nd_blockdevice_update_notify",
117
"cacheset_nd_cacheset_link_notify",
118
"cacheset_nd_cacheset_unlink_notify",
119
"cacheset_nd_cacheset_update_notify",
120
"config_config_create_notify",
121
"config_config_delete_notify",
122
"config_config_update_notify",
123
"dhcpsnippet_dhcpsnippet_create_notify",
124
"dhcpsnippet_dhcpsnippet_delete_notify",
125
"dhcpsnippet_dhcpsnippet_update_notify",
126
"dnsdata_dnsdata_domain_delete_notify",
127
"dnsdata_dnsdata_domain_insert_notify",
128
"dnsdata_dnsdata_domain_update_notify",
129
"dnsresource_dnsresource_domain_delete_notify",
130
"dnsresource_dnsresource_domain_insert_notify",
131
"dnsresource_dnsresource_domain_update_notify",
132
"dnsresource_ip_addresses_rrset_sipaddress_link_notify",
133
"dnsresource_ip_addresses_rrset_sipaddress_unlink_notify",
134
"domain_domain_create_notify",
135
"domain_domain_delete_notify",
136
"domain_domain_node_update_notify",
137
"domain_domain_update_notify",
138
"event_event_create_machine_device_notify",
139
"event_event_create_notify",
140
"fabric_fabric_create_notify",
141
"fabric_fabric_delete_notify",
142
"fabric_fabric_machine_update_notify",
143
"fabric_fabric_update_notify",
144
"filesystem_nd_filesystem_link_notify",
145
"filesystem_nd_filesystem_unlink_notify",
146
"filesystem_nd_filesystem_update_notify",
147
"filesystemgroup_nd_filesystemgroup_link_notify",
148
"filesystemgroup_nd_filesystemgroup_unlink_notify",
149
"filesystemgroup_nd_filesystemgroup_update_notify",
150
"interface_ip_addresses_nd_sipaddress_dns_link_notify",
151
"interface_ip_addresses_nd_sipaddress_dns_unlink_notify",
152
"interface_ip_addresses_nd_sipaddress_link_notify",
153
"interface_ip_addresses_nd_sipaddress_unlink_notify",
154
"interface_nd_interface_link_notify",
155
"interface_nd_interface_unlink_notify",
156
"interface_nd_interface_update_notify",
157
"iprange_iprange_create_notify",
158
"iprange_iprange_delete_notify",
159
"iprange_iprange_subnet_delete_notify",
160
"iprange_iprange_subnet_insert_notify",
161
"iprange_iprange_subnet_update_notify",
162
"iprange_iprange_update_notify",
163
"metadataserver_noderesult_nd_noderesult_link_notify",
164
"metadataserver_noderesult_nd_noderesult_unlink_notify",
165
"neighbour_neighbour_create_notify",
166
"neighbour_neighbour_delete_notify",
167
"neighbour_neighbour_update_notify",
168
"node_device_create_notify",
169
"node_device_delete_notify",
170
"node_device_update_notify",
171
"node_machine_create_notify",
172
"node_machine_delete_notify",
173
"node_machine_update_notify",
174
"node_node_type_change_notify",
175
"node_rack_controller_create_notify",
176
"node_rack_controller_delete_notify",
177
"node_rack_controller_update_notify",
178
"node_region_and_rack_controller_create_notify",
179
"node_region_and_rack_controller_delete_notify",
180
"node_region_and_rack_controller_update_notify",
181
"node_region_controller_create_notify",
182
"node_region_controller_delete_notify",
183
"node_region_controller_update_notify",
184
"node_tags_machine_device_tag_link_notify",
185
"node_tags_machine_device_tag_unlink_notify",
186
"packagerepository_packagerepository_create_notify",
187
"packagerepository_packagerepository_delete_notify",
188
"packagerepository_packagerepository_update_notify",
189
"partition_nd_partition_link_notify",
190
"partition_nd_partition_unlink_notify",
191
"partition_nd_partition_update_notify",
192
"partitiontable_nd_partitiontable_link_notify",
193
"partitiontable_nd_partitiontable_unlink_notify",
194
"partitiontable_nd_partitiontable_update_notify",
195
"physicalblockdevice_nd_physblockdevice_update_notify",
196
"service_service_create_notify",
197
"service_service_delete_notify",
198
"service_service_update_notify",
199
"space_space_create_notify",
200
"space_space_delete_notify",
201
"space_space_machine_update_notify",
202
"space_space_update_notify",
203
"sshkey_sshkey_create_notify",
204
"sshkey_sshkey_delete_notify",
205
"sshkey_sshkey_update_notify",
206
"sshkey_user_sshkey_link_notify",
207
"sshkey_user_sshkey_unlink_notify",
208
"sslkey_user_sslkey_link_notify",
209
"sslkey_user_sslkey_unlink_notify",
210
"staticipaddress_ipaddress_domain_delete_notify",
211
"staticipaddress_ipaddress_domain_insert_notify",
212
"staticipaddress_ipaddress_domain_update_notify",
213
"staticipaddress_ipaddress_machine_update_notify",
214
"staticipaddress_ipaddress_subnet_update_notify",
215
"staticroute_staticroute_create_notify",
216
"staticroute_staticroute_delete_notify",
217
"staticroute_staticroute_update_notify",
218
"subnet_subnet_create_notify",
219
"subnet_subnet_delete_notify",
220
"subnet_subnet_machine_update_notify",
221
"subnet_subnet_update_notify",
222
"tag_tag_create_notify",
223
"tag_tag_delete_notify",
224
"tag_tag_update_machine_device_notify",
225
"tag_tag_update_notify",
226
"virtualblockdevice_nd_virtblockdevice_update_notify",
227
"vlan_vlan_create_notify",
228
"vlan_vlan_delete_notify",
229
"vlan_vlan_machine_update_notify",
230
"vlan_vlan_update_notify",
231
"zone_zone_create_notify",
232
"zone_zone_delete_notify",
233
"zone_zone_update_notify",
236
triggers_all = triggers_system | triggers_websocket
238
def find_triggers_in_database(self):
239
with connection.cursor() as cursor:
241
"SELECT tgname::text FROM pg_trigger "
242
"WHERE NOT tgisinternal")
243
return {tgname for tgname, in cursor.fetchall()}
245
def check_triggers_in_database(self):
246
# Note: if this test fails, a trigger may have been added, but not
247
# added to the list of expected triggers.
248
triggers_found = self.find_triggers_in_database()
250
(self.triggers_all - triggers_found), Equals(EMPTY_SET),
251
"Some triggers were expected but not found.")
253
(triggers_found - self.triggers_all), Equals(EMPTY_SET),
254
"Some triggers were unexpected.")
256
def test_all_triggers_present_and_correct(self):
257
# Running in a fully migrated database means all triggers should be
258
# present from the get go.
259
self.check_triggers_in_database()
261
def test_register_system_triggers_does_not_introduce_more(self):
262
register_system_triggers()
263
self.check_triggers_in_database()
265
def test_register_websocket_triggers_does_not_introduce_more(self):
266
register_websocket_triggers()
267
self.check_triggers_in_database()