|
@@ -14,7 +14,7 @@ from sentry.tasks.integrations.migrate_opsgenie_plugins import (
|
|
ALERT_LEGACY_INTEGRATIONS_WITH_NAME,
|
|
ALERT_LEGACY_INTEGRATIONS_WITH_NAME,
|
|
)
|
|
)
|
|
from sentry.testutils.cases import APITestCase, IntegrationTestCase
|
|
from sentry.testutils.cases import APITestCase, IntegrationTestCase
|
|
-from sentry.testutils.silo import control_silo_test
|
|
|
|
|
|
+from sentry.testutils.silo import assume_test_silo_mode_of, control_silo_test, region_silo_test
|
|
from sentry_plugins.opsgenie.plugin import OpsGeniePlugin
|
|
from sentry_plugins.opsgenie.plugin import OpsGeniePlugin
|
|
|
|
|
|
EXTERNAL_ID = "test-app"
|
|
EXTERNAL_ID = "test-app"
|
|
@@ -174,6 +174,7 @@ class OpsgenieIntegrationTest(IntegrationTestCase):
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+@region_silo_test
|
|
class OpsgenieMigrationIntegrationTest(APITestCase):
|
|
class OpsgenieMigrationIntegrationTest(APITestCase):
|
|
@cached_property
|
|
@cached_property
|
|
def integration(self):
|
|
def integration(self):
|
|
@@ -192,7 +193,8 @@ class OpsgenieMigrationIntegrationTest(APITestCase):
|
|
self.plugin.set_option("enabled", True, self.project)
|
|
self.plugin.set_option("enabled", True, self.project)
|
|
self.plugin.set_option("alert_url", "https://api.opsgenie.com/v2/alerts/", self.project)
|
|
self.plugin.set_option("alert_url", "https://api.opsgenie.com/v2/alerts/", self.project)
|
|
self.plugin.set_option("api_key", "123-key", self.project)
|
|
self.plugin.set_option("api_key", "123-key", self.project)
|
|
- self.installation = self.integration.get_installation(self.organization.id)
|
|
|
|
|
|
+ with assume_test_silo_mode_of(Integration):
|
|
|
|
+ self.installation = self.integration.get_installation(self.organization.id)
|
|
self.login_as(self.user)
|
|
self.login_as(self.user)
|
|
|
|
|
|
@patch("sentry.tasks.integrations.migrate_opsgenie_plugins.metrics")
|
|
@patch("sentry.tasks.integrations.migrate_opsgenie_plugins.metrics")
|
|
@@ -201,9 +203,12 @@ class OpsgenieMigrationIntegrationTest(APITestCase):
|
|
Test that 2 projects with the Opsgenie plugin activated that have one alert rule each
|
|
Test that 2 projects with the Opsgenie plugin activated that have one alert rule each
|
|
and distinct API keys are successfully migrated.
|
|
and distinct API keys are successfully migrated.
|
|
"""
|
|
"""
|
|
- org_integration = OrganizationIntegration.objects.get(integration_id=self.integration.id)
|
|
|
|
- org_integration.config = {"team_table": []}
|
|
|
|
- org_integration.save()
|
|
|
|
|
|
+ with assume_test_silo_mode_of(OrganizationIntegration):
|
|
|
|
+ org_integration = OrganizationIntegration.objects.get(
|
|
|
|
+ integration_id=self.integration.id
|
|
|
|
+ )
|
|
|
|
+ org_integration.config = {"team_table": []}
|
|
|
|
+ org_integration.save()
|
|
|
|
|
|
project2 = self.create_project(
|
|
project2 = self.create_project(
|
|
name="thinkies", organization=self.organization, teams=[self.team]
|
|
name="thinkies", organization=self.organization, teams=[self.team]
|
|
@@ -228,7 +233,10 @@ class OpsgenieMigrationIntegrationTest(APITestCase):
|
|
with self.tasks():
|
|
with self.tasks():
|
|
self.installation.schedule_migrate_opsgenie_plugin()
|
|
self.installation.schedule_migrate_opsgenie_plugin()
|
|
|
|
|
|
- org_integration = OrganizationIntegration.objects.get(integration_id=self.integration.id)
|
|
|
|
|
|
+ with assume_test_silo_mode_of(OrganizationIntegration):
|
|
|
|
+ org_integration = OrganizationIntegration.objects.get(
|
|
|
|
+ integration_id=self.integration.id
|
|
|
|
+ )
|
|
id1 = str(self.organization_integration.id) + "-thonk"
|
|
id1 = str(self.organization_integration.id) + "-thonk"
|
|
id2 = str(self.organization_integration.id) + "-thinkies"
|
|
id2 = str(self.organization_integration.id) + "-thinkies"
|
|
assert org_integration.config == {
|
|
assert org_integration.config == {
|
|
@@ -275,9 +283,12 @@ class OpsgenieMigrationIntegrationTest(APITestCase):
|
|
"""
|
|
"""
|
|
Keys should not be migrated twice.
|
|
Keys should not be migrated twice.
|
|
"""
|
|
"""
|
|
- org_integration = OrganizationIntegration.objects.get(integration_id=self.integration.id)
|
|
|
|
- org_integration.config = {"team_table": []}
|
|
|
|
- org_integration.save()
|
|
|
|
|
|
+ with assume_test_silo_mode_of(OrganizationIntegration):
|
|
|
|
+ org_integration = OrganizationIntegration.objects.get(
|
|
|
|
+ integration_id=self.integration.id
|
|
|
|
+ )
|
|
|
|
+ org_integration.config = {"team_table": []}
|
|
|
|
+ org_integration.save()
|
|
|
|
|
|
project2 = self.create_project(
|
|
project2 = self.create_project(
|
|
name="thinkies", organization=self.organization, teams=[self.team]
|
|
name="thinkies", organization=self.organization, teams=[self.team]
|
|
@@ -290,7 +301,10 @@ class OpsgenieMigrationIntegrationTest(APITestCase):
|
|
with self.tasks():
|
|
with self.tasks():
|
|
self.installation.schedule_migrate_opsgenie_plugin()
|
|
self.installation.schedule_migrate_opsgenie_plugin()
|
|
|
|
|
|
- org_integration = OrganizationIntegration.objects.get(integration_id=self.integration.id)
|
|
|
|
|
|
+ with assume_test_silo_mode_of(OrganizationIntegration):
|
|
|
|
+ org_integration = OrganizationIntegration.objects.get(
|
|
|
|
+ integration_id=self.integration.id
|
|
|
|
+ )
|
|
id1 = str(self.organization_integration.id) + "-thonk"
|
|
id1 = str(self.organization_integration.id) + "-thonk"
|
|
|
|
|
|
assert org_integration.config == {
|
|
assert org_integration.config == {
|
|
@@ -303,17 +317,20 @@ class OpsgenieMigrationIntegrationTest(APITestCase):
|
|
"""
|
|
"""
|
|
Test that migration works if a key has already been added to config.
|
|
Test that migration works if a key has already been added to config.
|
|
"""
|
|
"""
|
|
- org_integration = OrganizationIntegration.objects.get(integration_id=self.integration.id)
|
|
|
|
- org_integration.config = {
|
|
|
|
- "team_table": [
|
|
|
|
- {
|
|
|
|
- "id": str(self.organization_integration.id) + "-pikachu",
|
|
|
|
- "team": "pikachu",
|
|
|
|
- "integration_key": "123-key",
|
|
|
|
- },
|
|
|
|
- ]
|
|
|
|
- }
|
|
|
|
- org_integration.save()
|
|
|
|
|
|
+ with assume_test_silo_mode_of(OrganizationIntegration):
|
|
|
|
+ org_integration = OrganizationIntegration.objects.get(
|
|
|
|
+ integration_id=self.integration.id
|
|
|
|
+ )
|
|
|
|
+ org_integration.config = {
|
|
|
|
+ "team_table": [
|
|
|
|
+ {
|
|
|
|
+ "id": str(self.organization_integration.id) + "-pikachu",
|
|
|
|
+ "team": "pikachu",
|
|
|
|
+ "integration_key": "123-key",
|
|
|
|
+ },
|
|
|
|
+ ]
|
|
|
|
+ }
|
|
|
|
+ org_integration.save()
|
|
|
|
|
|
Rule.objects.create(
|
|
Rule.objects.create(
|
|
label="rule",
|
|
label="rule",
|
|
@@ -323,7 +340,10 @@ class OpsgenieMigrationIntegrationTest(APITestCase):
|
|
with self.tasks():
|
|
with self.tasks():
|
|
self.installation.schedule_migrate_opsgenie_plugin()
|
|
self.installation.schedule_migrate_opsgenie_plugin()
|
|
|
|
|
|
- org_integration = OrganizationIntegration.objects.get(integration_id=self.integration.id)
|
|
|
|
|
|
+ with assume_test_silo_mode_of(OrganizationIntegration):
|
|
|
|
+ org_integration = OrganizationIntegration.objects.get(
|
|
|
|
+ integration_id=self.integration.id
|
|
|
|
+ )
|
|
assert org_integration.config == {
|
|
assert org_integration.config == {
|
|
"team_table": [
|
|
"team_table": [
|
|
{
|
|
{
|
|
@@ -352,9 +372,12 @@ class OpsgenieMigrationIntegrationTest(APITestCase):
|
|
"""
|
|
"""
|
|
Test multiple rules, some of which send notifications to legacy integrations.
|
|
Test multiple rules, some of which send notifications to legacy integrations.
|
|
"""
|
|
"""
|
|
- org_integration = OrganizationIntegration.objects.get(integration_id=self.integration.id)
|
|
|
|
- org_integration.config = {"team_table": []}
|
|
|
|
- org_integration.save()
|
|
|
|
|
|
+ with assume_test_silo_mode_of(OrganizationIntegration):
|
|
|
|
+ org_integration = OrganizationIntegration.objects.get(
|
|
|
|
+ integration_id=self.integration.id
|
|
|
|
+ )
|
|
|
|
+ org_integration.config = {"team_table": []}
|
|
|
|
+ org_integration.save()
|
|
|
|
|
|
Rule.objects.create(
|
|
Rule.objects.create(
|
|
label="rule",
|
|
label="rule",
|
|
@@ -371,8 +394,11 @@ class OpsgenieMigrationIntegrationTest(APITestCase):
|
|
with self.tasks():
|
|
with self.tasks():
|
|
self.installation.schedule_migrate_opsgenie_plugin()
|
|
self.installation.schedule_migrate_opsgenie_plugin()
|
|
|
|
|
|
- org_integration = OrganizationIntegration.objects.get(integration_id=self.integration.id)
|
|
|
|
- id1 = str(self.organization_integration.id) + "-thonk"
|
|
|
|
|
|
+ with assume_test_silo_mode_of(OrganizationIntegration):
|
|
|
|
+ org_integration = OrganizationIntegration.objects.get(
|
|
|
|
+ integration_id=self.integration.id
|
|
|
|
+ )
|
|
|
|
+ id1 = str(org_integration.id) + "-thonk"
|
|
rule_updated = Rule.objects.get(
|
|
rule_updated = Rule.objects.get(
|
|
label="rule",
|
|
label="rule",
|
|
project=self.project,
|
|
project=self.project,
|
|
@@ -398,17 +424,20 @@ class OpsgenieMigrationIntegrationTest(APITestCase):
|
|
"""
|
|
"""
|
|
Don't add a new recipient from an API key if the recipient already exists.
|
|
Don't add a new recipient from an API key if the recipient already exists.
|
|
"""
|
|
"""
|
|
- org_integration = OrganizationIntegration.objects.get(integration_id=self.integration.id)
|
|
|
|
- org_integration.config = {
|
|
|
|
- "team_table": [
|
|
|
|
- {
|
|
|
|
- "id": str(self.organization_integration.id) + "-pikachu",
|
|
|
|
- "team": "pikachu",
|
|
|
|
- "integration_key": "123-key",
|
|
|
|
- },
|
|
|
|
- ]
|
|
|
|
- }
|
|
|
|
- org_integration.save()
|
|
|
|
|
|
+ with assume_test_silo_mode_of(OrganizationIntegration):
|
|
|
|
+ org_integration = OrganizationIntegration.objects.get(
|
|
|
|
+ integration_id=self.integration.id
|
|
|
|
+ )
|
|
|
|
+ org_integration.config = {
|
|
|
|
+ "team_table": [
|
|
|
|
+ {
|
|
|
|
+ "id": str(self.organization_integration.id) + "-pikachu",
|
|
|
|
+ "team": "pikachu",
|
|
|
|
+ "integration_key": "123-key",
|
|
|
|
+ },
|
|
|
|
+ ]
|
|
|
|
+ }
|
|
|
|
+ org_integration.save()
|
|
|
|
|
|
Rule.objects.create(
|
|
Rule.objects.create(
|
|
label="rule",
|
|
label="rule",
|
|
@@ -428,7 +457,10 @@ class OpsgenieMigrationIntegrationTest(APITestCase):
|
|
with self.tasks():
|
|
with self.tasks():
|
|
self.installation.schedule_migrate_opsgenie_plugin()
|
|
self.installation.schedule_migrate_opsgenie_plugin()
|
|
|
|
|
|
- org_integration = OrganizationIntegration.objects.get(integration_id=self.integration.id)
|
|
|
|
|
|
+ with assume_test_silo_mode_of(OrganizationIntegration):
|
|
|
|
+ org_integration = OrganizationIntegration.objects.get(
|
|
|
|
+ integration_id=self.integration.id
|
|
|
|
+ )
|
|
assert org_integration.config == {
|
|
assert org_integration.config == {
|
|
"team_table": [
|
|
"team_table": [
|
|
{
|
|
{
|
|
@@ -457,9 +489,12 @@ class OpsgenieMigrationIntegrationTest(APITestCase):
|
|
"""
|
|
"""
|
|
Test that the Opsgenie plugin is migrated correctly if the legacy alert action has a name field.
|
|
Test that the Opsgenie plugin is migrated correctly if the legacy alert action has a name field.
|
|
"""
|
|
"""
|
|
- org_integration = OrganizationIntegration.objects.get(integration_id=self.integration.id)
|
|
|
|
- org_integration.config = {"team_table": []}
|
|
|
|
- org_integration.save()
|
|
|
|
|
|
+ with assume_test_silo_mode_of(OrganizationIntegration):
|
|
|
|
+ org_integration = OrganizationIntegration.objects.get(
|
|
|
|
+ integration_id=self.integration.id
|
|
|
|
+ )
|
|
|
|
+ org_integration.config = {"team_table": []}
|
|
|
|
+ org_integration.save()
|
|
|
|
|
|
Rule.objects.create(
|
|
Rule.objects.create(
|
|
label="rule",
|
|
label="rule",
|
|
@@ -470,7 +505,10 @@ class OpsgenieMigrationIntegrationTest(APITestCase):
|
|
with self.tasks():
|
|
with self.tasks():
|
|
self.installation.schedule_migrate_opsgenie_plugin()
|
|
self.installation.schedule_migrate_opsgenie_plugin()
|
|
|
|
|
|
- org_integration = OrganizationIntegration.objects.get(integration_id=self.integration.id)
|
|
|
|
|
|
+ with assume_test_silo_mode_of(OrganizationIntegration):
|
|
|
|
+ org_integration = OrganizationIntegration.objects.get(
|
|
|
|
+ integration_id=self.integration.id
|
|
|
|
+ )
|
|
id1 = str(self.organization_integration.id) + "-thonk"
|
|
id1 = str(self.organization_integration.id) + "-thonk"
|
|
assert org_integration.config == {
|
|
assert org_integration.config == {
|
|
"team_table": [
|
|
"team_table": [
|