Skip to content

BB-692 Fix errors when deprovisioning resources that has been already deprovisioned.

Josue Balandrano Coronel requested to merge josuebc/BB-692 into master
  • Add flags to ignore errors when deleting an OpenEDX Instance.
  • Add log messages to show what's going on when deleting an instance.
  • Add unit test for deleting an instance ignoring errors.
  • Fix some deprovision tests.
  • Update responses library to mock response with 'reason' attribute.

When this task was created we thought the issue was that OpenEDXInstance.delete() was trying to deprovision resources that were already deprovisioned before. This is partially true because the delete() method was trying to get rid of things that were not there anymore, but those resources were not "correctly" deprovisioned. Meaning, checking for self.<resource>_provisioned would not give us the correct state if the resource was deleted manually or using another method. Also, the class methods implemented currently in the codebase they do check if the <resouce>_provisioned flag is False and if it so then the codebase do not try to delete that resource, e.g. MySQL, Mongo, Swift, RabbitMQ

This PR implements a few flags to ignore errors raised when using OpenEdxInstance.delete(). Errors will be logged but not raised.

Test instructions:

  1. ssh to ocim stage and apply patch.
  2. Create an instance using Django's shell:
from instance.models.openedx_instance import OpenEdXInstance

instance = OpenEdXInstance.objects.create(
    name='Dogwood sandbox',
    sub_domain='dogwood',
    # The rest of the parameters are all optional:
    email='myname@opencraft.com',
    openedx_release='named-release/dogwood',
    configuration_version='named-release/dogwood',
    configuration_source_repo_url='https://github.com/edx/configuration.git',
    configuration_extra_settings='',
)
  1. Manually delete resources:
instance.deprovision_mysql()
instance.deprovision_mongo()
instance.deprovision_rabbitmq()
  1. Set <resource>_provisioned flag to True.
instance.mysql_provisioned = True
instance.mongo_provisioned = True
instance.rabbitmq_provisioned = True
instance.save()
  1. Delete instance:
instance.delete(ignore_errors=True)

Expected behavior:

Every other resource/config should be deleted correctly (e.g. DNS records) as well as database records. There should be a few MySQL, Mongo and RabbitMQ messages printed to the output since the code will try to delete databases and/or users that are no longer there but the delete() method should not exit with an error.

Merge request reports