From 59b020c0d4f301cbd7c38286d1dd5acc06f7efe9 Mon Sep 17 00:00:00 2001 From: PCoder Date: Wed, 25 Jul 2018 21:41:05 +0200 Subject: [PATCH 01/11] Replace all occurrences of logger.info with logger.error --- hosting/views.py | 2 +- opennebula_api/models.py | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/hosting/views.py b/hosting/views.py index 6af1885b..f2c51cf5 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -1394,7 +1394,7 @@ class VirtualMachineView(LoginRequiredMixin, View): terminated = manager.delete_vm(vm.id) if not terminated: - logger.debug( + logger.error( "manager.delete_vm returned False. Hence, error making " "xml-rpc call to delete vm failed." ) diff --git a/opennebula_api/models.py b/opennebula_api/models.py index 29632009..611a0712 100644 --- a/opennebula_api/models.py +++ b/opennebula_api/models.py @@ -110,7 +110,7 @@ class OpenNebulaManager(): raise UserExistsError() except OpenNebulaException as err: logger.error('OpenNebulaException error: {0}'.format(err)) - logger.debug('User exists but password is wrong') + logger.error('User exists but password is wrong') raise UserCredentialError() except WrongNameError: @@ -148,7 +148,7 @@ class OpenNebulaManager(): ) return opennebula_user except ConnectionRefusedError: - logger.info( + logger.error( 'Could not connect to host: {host} via protocol {protocol}'.format( host=settings.OPENNEBULA_DOMAIN, protocol=settings.OPENNEBULA_PROTOCOL) @@ -160,7 +160,7 @@ class OpenNebulaManager(): user_pool = oca.UserPool(self.oneadmin_client) user_pool.info() except ConnectionRefusedError: - logger.info( + logger.error( 'Could not connect to host: {host} via protocol {protocol}'.format( host=settings.OPENNEBULA_DOMAIN, protocol=settings.OPENNEBULA_PROTOCOL) @@ -174,7 +174,7 @@ class OpenNebulaManager(): vm_pool.info() return vm_pool except AttributeError: - logger.info('Could not connect via client, using oneadmin instead') + logger.error('Could not connect via client, using oneadmin instead') try: vm_pool = oca.VirtualMachinePool(self.oneadmin_client) vm_pool.info(filter=-2) @@ -183,7 +183,7 @@ class OpenNebulaManager(): raise ConnectionRefusedError except ConnectionRefusedError: - logger.info( + logger.error( 'Could not connect to host: {host} via protocol {protocol}'.format( host=settings.OPENNEBULA_DOMAIN, protocol=settings.OPENNEBULA_PROTOCOL) @@ -325,14 +325,14 @@ class OpenNebulaManager(): ) vm_terminated = True except socket.timeout as socket_err: - logger.info("Socket timeout error: {0}".format(socket_err)) + logger.error("Socket timeout error: {0}".format(socket_err)) except OpenNebulaException as opennebula_err: - logger.info( + logger.error( "OpenNebulaException error: {0}".format(opennebula_err)) except OSError as os_err: - logger.info("OSError : {0}".format(os_err)) + logger.error("OSError : {0}".format(os_err)) except ValueError as value_err: - logger.info("ValueError : {0}".format(value_err)) + logger.error("ValueError : {0}".format(value_err)) return vm_terminated @@ -342,7 +342,7 @@ class OpenNebulaManager(): template_pool.info() return template_pool except ConnectionRefusedError: - logger.info( + logger.error( """Could not connect to host: {host} via protocol {protocol}""".format( host=settings.OPENNEBULA_DOMAIN, From a5cdfab306e86f44ae3c9ba1d0f9e1eaed0051fe Mon Sep 17 00:00:00 2001 From: PCoder Date: Wed, 25 Jul 2018 21:53:33 +0200 Subject: [PATCH 02/11] Send an email to admin if the VM is still there after 30 seconds of the VM terminate calll --- hosting/views.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/hosting/views.py b/hosting/views.py index f2c51cf5..476c62ff 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -1404,6 +1404,9 @@ class VirtualMachineView(LoginRequiredMixin, View): try: manager.get_vm(vm.id) except WrongIdError: + logger.error( + "VM {} not found. So, its terminated.".format(vm.id) + ) response['status'] = True response['text'] = ugettext('Terminated') vm_detail_obj = VMDetail.objects.filter( @@ -1421,6 +1424,19 @@ class VirtualMachineView(LoginRequiredMixin, View): break else: sleep(2) + if 'status' not in response: + vm_msg = "VM {} has not terminated yet!".format(vm.id) + admin_email_body['status'] = vm_msg + logger.error(vm_msg) + err_email_data = { + 'subject': vm_msg, + 'from_email': settings.DCL_SUPPORT_FROM_ADDRESS, + 'to': ['info@ungleich.ch'], + 'body': "Called VM terminate xml-rpc and waited for over " + "30 seconds for the VM to disappear. But, it did " + "not happen. So, please verify!", + } + send_plain_email_task.delay(err_email_data) context = { 'vm_name': vm_name, 'base_url': "{0}://{1}".format( From df10e8441892d715e0137874e694d909d5bc5162 Mon Sep 17 00:00:00 2001 From: PCoder Date: Wed, 25 Jul 2018 22:04:44 +0200 Subject: [PATCH 03/11] Add owner's email to the subject --- hosting/views.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hosting/views.py b/hosting/views.py index 476c62ff..d256115d 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -1425,7 +1425,9 @@ class VirtualMachineView(LoginRequiredMixin, View): else: sleep(2) if 'status' not in response: - vm_msg = "VM {} has not terminated yet!".format(vm.id) + vm_msg = "VM {} of user {} has not terminated yet!".format( + vm.id, owner.email + ) admin_email_body['status'] = vm_msg logger.error(vm_msg) err_email_data = { From 7d4cf5c3c28332cde769a313d9e74e0459f5d53d Mon Sep 17 00:00:00 2001 From: PCoder Date: Fri, 7 Sep 2018 22:46:18 +0200 Subject: [PATCH 04/11] Fix flake8 error --- utils/hosting_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/hosting_utils.py b/utils/hosting_utils.py index 2918deb3..8354f485 100644 --- a/utils/hosting_utils.py +++ b/utils/hosting_utils.py @@ -127,7 +127,7 @@ def get_vm_price_with_vat(cpu, memory, ssd_size, hdd_size=0, vat = vat.quantize(cents, decimal.ROUND_HALF_UP) discount = { 'name': pricing.discount_name, - 'amount': round(float(pricing.discount_amount),2) + 'amount': round(float(pricing.discount_amount), 2) } return (round(float(price), 2), round(float(vat), 2), round(float(vat_percent)), discount) From ff6df8cd58804016e29df51f20eed752a35a359e Mon Sep 17 00:00:00 2001 From: PCoder Date: Fri, 7 Sep 2018 23:11:46 +0200 Subject: [PATCH 05/11] Simplify logic --- hosting/views.py | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/hosting/views.py b/hosting/views.py index 09d3ae66..8435a9c6 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -1430,21 +1430,12 @@ class VirtualMachineView(LoginRequiredMixin, View): break else: sleep(2) - if 'status' not in response: - vm_msg = "VM {} of user {} has not terminated yet!".format( - vm.id, owner.email + if not response['status']: + response['details'] = ( + "Called VM terminate xml-rpc and waited for over " + "30 seconds for the VM to disappear. But, it did " + "not happen. So, please verify!" ) - admin_email_body['status'] = vm_msg - logger.error(vm_msg) - err_email_data = { - 'subject': vm_msg, - 'from_email': settings.DCL_SUPPORT_FROM_ADDRESS, - 'to': ['info@ungleich.ch'], - 'body': "Called VM terminate xml-rpc and waited for over " - "30 seconds for the VM to disappear. But, it did " - "not happen. So, please verify!", - } - send_plain_email_task.delay(err_email_data) context = { 'vm_name': vm_name, 'base_url': "{0}://{1}".format( @@ -1465,11 +1456,13 @@ class VirtualMachineView(LoginRequiredMixin, View): email = BaseEmail(**email_data) email.send() admin_email_body.update(response) + admin_msg_sub = "VM and Subscription for VM {} and user: {}".format( + vm.id, + owner.email + ) email_to_admin_data = { - 'subject': "Deleted VM and Subscription for VM {vm_id} and " - "user: {user}".format( - vm_id=vm.id, user=owner.email - ), + 'subject': ("Deleted " if response['status'] + else "ERROR deleting ") + admin_msg_sub, 'from_email': settings.DCL_SUPPORT_FROM_ADDRESS, 'to': ['info@ungleich.ch'], 'body': "\n".join( From a7afbec5b4ee296ddf52e2ee56d26d7d676e2147 Mon Sep 17 00:00:00 2001 From: PCoder Date: Fri, 7 Sep 2018 23:14:57 +0200 Subject: [PATCH 06/11] Fix flake8 error --- hosting/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hosting/views.py b/hosting/views.py index 8435a9c6..c16b6d07 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -1462,7 +1462,7 @@ class VirtualMachineView(LoginRequiredMixin, View): ) email_to_admin_data = { 'subject': ("Deleted " if response['status'] - else "ERROR deleting ") + admin_msg_sub, + else "ERROR deleting ") + admin_msg_sub, 'from_email': settings.DCL_SUPPORT_FROM_ADDRESS, 'to': ['info@ungleich.ch'], 'body': "\n".join( From ce2d34350ff06e60a1169382c3ed7142186a115e Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 8 Sep 2018 00:15:44 +0200 Subject: [PATCH 07/11] Update Changelog --- Changelog | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Changelog b/Changelog index 8906d48b..d373a4e8 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,5 @@ +Next: + * bugfix: Log opennebula errors and send proper message when vm terminate is not completed in the stipulated time (PR #648) 2.2: 2018-09-06 * bugfix: Include price in the Stripe plan name to make it distinct and to correct pricing since version 1.9 2.1.2: 2018-08-30 From 49142808681c9f1ea29394a2cdc504ad851e7596 Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 8 Sep 2018 10:14:57 +0200 Subject: [PATCH 08/11] Set text for vm terminate timeout --- hosting/views.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/hosting/views.py b/hosting/views.py index c16b6d07..4e010b3e 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -1431,10 +1431,12 @@ class VirtualMachineView(LoginRequiredMixin, View): else: sleep(2) if not response['status']: - response['details'] = ( - "Called VM terminate xml-rpc and waited for over " - "30 seconds for the VM to disappear. But, it did " - "not happen. So, please verify!" + response['text'] = _( + ("VM terminate action timed-out. Please contact support " + "{support_email}" + "for further information.").format( + support_email=settings.DCL_SUPPORT_FROM_ADDRESS + ) ) context = { 'vm_name': vm_name, From 84dae639686a9b99c624f66a60ae0a08127cd57b Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 8 Sep 2018 10:29:47 +0200 Subject: [PATCH 09/11] Fix: ugettext_lazy doesn't like string format --- hosting/views.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/hosting/views.py b/hosting/views.py index 4e010b3e..33cfc2d8 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -1431,13 +1431,11 @@ class VirtualMachineView(LoginRequiredMixin, View): else: sleep(2) if not response['status']: - response['text'] = _( - ("VM terminate action timed-out. Please contact support " - "{support_email}" - "for further information.").format( - support_email=settings.DCL_SUPPORT_FROM_ADDRESS - ) - ) + response['text'] = _("VM terminate action timed-out. Please " + "contact support %(support_email)s for " + "further information.") % { + 'support_email': settings.DCL_SUPPORT_FROM_ADDRESS + } context = { 'vm_name': vm_name, 'base_url': "{0}://{1}".format( From e376f38baadba4464cf3bb8bf879857cea084a97 Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 8 Sep 2018 10:33:00 +0200 Subject: [PATCH 10/11] Correct text --- hosting/locale/de/LC_MESSAGES/django.po | 8 +++++++- hosting/views.py | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/hosting/locale/de/LC_MESSAGES/django.po b/hosting/locale/de/LC_MESSAGES/django.po index a9e33644..beea43f2 100644 --- a/hosting/locale/de/LC_MESSAGES/django.po +++ b/hosting/locale/de/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-08-24 09:56+0000\n" +"POT-Creation-Date: 2018-09-08 08:31+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -807,6 +807,12 @@ msgstr "" msgid "Error terminating VM" msgstr "Fehler beenden VM" +#, python-format +msgid "" +"VM terminate action timed out. Please contact support %(support_email)s for " +"further information." +msgstr "" + #, python-format msgid "Virtual Machine %(vm_name)s Cancelled" msgstr "Virtuelle Maschine %(vm_name)s Kündigung" diff --git a/hosting/views.py b/hosting/views.py index 33cfc2d8..2ee0cd0e 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -1431,7 +1431,7 @@ class VirtualMachineView(LoginRequiredMixin, View): else: sleep(2) if not response['status']: - response['text'] = _("VM terminate action timed-out. Please " + response['text'] = _("VM terminate action timed out. Please " "contact support %(support_email)s for " "further information.") % { 'support_email': settings.DCL_SUPPORT_FROM_ADDRESS From 304feb4f7b90b74a1e909c13705f145c06f713ba Mon Sep 17 00:00:00 2001 From: PCoder Date: Sat, 8 Sep 2018 10:46:07 +0200 Subject: [PATCH 11/11] Update text --- hosting/locale/de/LC_MESSAGES/django.po | 5 ++--- hosting/views.py | 6 ++---- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/hosting/locale/de/LC_MESSAGES/django.po b/hosting/locale/de/LC_MESSAGES/django.po index beea43f2..afd3cef3 100644 --- a/hosting/locale/de/LC_MESSAGES/django.po +++ b/hosting/locale/de/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-09-08 08:31+0000\n" +"POT-Creation-Date: 2018-09-08 08:45+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -807,9 +807,8 @@ msgstr "" msgid "Error terminating VM" msgstr "Fehler beenden VM" -#, python-format msgid "" -"VM terminate action timed out. Please contact support %(support_email)s for " +"VM terminate action timed out. Please contact support@datacenterlight.ch for " "further information." msgstr "" diff --git a/hosting/views.py b/hosting/views.py index 2ee0cd0e..68142a38 100644 --- a/hosting/views.py +++ b/hosting/views.py @@ -1432,10 +1432,8 @@ class VirtualMachineView(LoginRequiredMixin, View): sleep(2) if not response['status']: response['text'] = _("VM terminate action timed out. Please " - "contact support %(support_email)s for " - "further information.") % { - 'support_email': settings.DCL_SUPPORT_FROM_ADDRESS - } + "contact support@datacenterlight.ch for " + "further information.") context = { 'vm_name': vm_name, 'base_url': "{0}://{1}".format(