When deleting New Relic monitors, don't fail if monitor can't be found.
Created by: itsjeyd
Follow-up to #143.
Makes sure that the process for shutting down an instance does not fail if the New Relic monitors associated with the instance no longer exist.
Test instructions
-
Temporarily set
NEWRELIC_LICENSE_KEY
andNEWRELIC_ADMIN_USER_API_KEY
in your.env
(check OC IM prod config for appropriate values). This is to make sure that theDELETE
request performed bydelete_synthetics_monitor
does not fail with authentication errors. -
Start the shell via
make shell
. -
Create a new instance:
from instance.factories import instance_factory instance = instance_factory(name="Instance with fake monitors", sub_domain="instance-fake-monitors")
-
Associate a single running app server with the instance. This is to make sure that
is_shut_down
does not short-circuit later on:appserver = instance._create_owned_appserver() appserver._status_to_waiting_for_server() appserver._status_to_configuring_server() appserver._status_to_running()
-
Associate fake New Relics monitors with it:
monitor_ids = ["fake-monitor-id-{}".format(i) for i in range(3)] for monitor_id in monitor_ids: instance.new_relic_availability_monitors.create(pk=monitor_id) # Precondition check assert instance.new_relic_availability_monitors.count() == 3 assert instance.is_shut_down == False
-
Shut down instance:
instance.shut_down()
-
Verify that monitors have been deleted and instance manager considers instance to be shut down:
assert instance.new_relic_availability_monitors.count() == 0 assert instance.is_shut_down == True
Reviewers
-
@haikuginger