From 0809a09e153324546af5115d4b3cd68abf8882de Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 8 Feb 2021 05:04:12 +0000 Subject: [PATCH 1/9] feat(deps): bump setuptools from 52.0.0 to 53.0.0 Bumps [setuptools](https://github.com/pypa/setuptools) from 52.0.0 to 53.0.0. - [Release notes](https://github.com/pypa/setuptools/releases) - [Changelog](https://github.com/pypa/setuptools/blob/main/CHANGES.rst) - [Commits](https://github.com/pypa/setuptools/compare/v52.0.0...v53.0.0) Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 5bf8f1bc..71382fa5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -setuptools==52.0.0 +setuptools==53.0.0 thrift >= 0.11.0,<0.20.0 python-keystoneclient openstacksdk ==0.53.0 From dce51fe18cb4ce27b523e8a95c1b43e4d17c3d42 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 15 Feb 2021 05:04:14 +0000 Subject: [PATCH 2/9] feat(deps): bump ansible from 2.10.6 to 2.10.7 Bumps [ansible](https://github.com/ansible/ansible) from 2.10.6 to 2.10.7. - [Release notes](https://github.com/ansible/ansible/releases) - [Commits](https://github.com/ansible/ansible/commits) Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 71382fa5..d3984010 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,7 +5,7 @@ openstacksdk ==0.53.0 deprecated == 1.2.11 Click==7.1.2 flake8==3.8.4 -ansible==2.10.6 +ansible==2.10.7 ruamel.yaml<0.17.0 paramiko==2.7.2 pyvim==3.0.2 From 5ea3ea5bc558ebef575189ce72e2987d03cc0533 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 22 Feb 2021 05:03:47 +0000 Subject: [PATCH 3/9] feat(deps): bump ansible from 2.10.7 to 3.0.0 Bumps [ansible](https://github.com/ansible/ansible) from 2.10.7 to 3.0.0. - [Release notes](https://github.com/ansible/ansible/releases) - [Commits](https://github.com/ansible/ansible/commits) Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index d3984010..0de83f95 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,7 +5,7 @@ openstacksdk ==0.53.0 deprecated == 1.2.11 Click==7.1.2 flake8==3.8.4 -ansible==2.10.7 +ansible==3.0.0 ruamel.yaml<0.17.0 paramiko==2.7.2 pyvim==3.0.2 From 38a74c533f2b33cbea785b8d14ab3d6cefb6275e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 22 Feb 2021 06:07:07 +0000 Subject: [PATCH 4/9] feat(deps): bump python from 3.9.1-buster to 3.9.2-buster Bumps python from 3.9.1-buster to 3.9.2-buster. Signed-off-by: dependabot[bot] --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 15ee7b2b..eb7835e6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.9.1-buster +FROM python:3.9.2-buster RUN apt-get update -y RUN apt-get install -y build-essential WORKDIR /code From 853bff1d9e038579c3eb26c274671cc6f79560f8 Mon Sep 17 00:00:00 2001 From: David Weinholz Date: Mon, 22 Feb 2021 13:42:40 +0100 Subject: [PATCH 5/9] delete backend catch exception --- VirtualMachineService/VirtualMachineHandler.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/VirtualMachineService/VirtualMachineHandler.py b/VirtualMachineService/VirtualMachineHandler.py index d5e8743a..6d90b0e9 100644 --- a/VirtualMachineService/VirtualMachineHandler.py +++ b/VirtualMachineService/VirtualMachineHandler.py @@ -40,14 +40,14 @@ import datetime import json import logging -from distutils.version import LooseVersion +import os import parser import socket import time import urllib from contextlib import closing +from distutils.version import LooseVersion -import os import redis import requests as req import yaml @@ -1440,7 +1440,10 @@ def delete_backend(self, id): verify=True, ) if response.status_code != 200: - return str(response.json()) + try: + return str(response.json()) + except json.JSONDecodeError: + return response.content elif response.status_code == 200: return str(True) except Timeout as e: From 32ec28cf91415d3bae8d8264283ce1f063caca7d Mon Sep 17 00:00:00 2001 From: David Weinholz Date: Mon, 22 Feb 2021 16:57:20 +0100 Subject: [PATCH 6/9] import and delte everytime --- VirtualMachineService/VirtualMachineHandler.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/VirtualMachineService/VirtualMachineHandler.py b/VirtualMachineService/VirtualMachineHandler.py index 6d90b0e9..f1b210c9 100644 --- a/VirtualMachineService/VirtualMachineHandler.py +++ b/VirtualMachineService/VirtualMachineHandler.py @@ -933,6 +933,8 @@ def volume_ids( security_groups=self.DEFAULT_SECURITY_GROUPS + custom_security_groups, ) openstack_id = server["id"] + self.delete_keypair(key_name) + return {"openstack_id": openstack_id} @@ -1065,6 +1067,7 @@ def start_server_without_playbook( ) openstack_id = server["id"] + self.delete_keypair(key_name) return {"openstack_id": openstack_id} except Exception as e: @@ -1126,6 +1129,8 @@ def start_server( ) openstack_id = server["id"] + self.delete_keypair(key_name) + return {"openstack_id": openstack_id} except Exception as e: From 9de5f898f9dbea1e6b4a0b14bd82743674ce9f9b Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 22 Feb 2021 15:58:28 +0000 Subject: [PATCH 7/9] fix(Linting):blacked code --- VirtualMachineService/VirtualMachineHandler.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/VirtualMachineService/VirtualMachineHandler.py b/VirtualMachineService/VirtualMachineHandler.py index f1b210c9..9eeb774f 100644 --- a/VirtualMachineService/VirtualMachineHandler.py +++ b/VirtualMachineService/VirtualMachineHandler.py @@ -935,7 +935,6 @@ def volume_ids( openstack_id = server["id"] self.delete_keypair(key_name) - return {"openstack_id": openstack_id} except Exception as e: @@ -1131,7 +1130,6 @@ def start_server( openstack_id = server["id"] self.delete_keypair(key_name) - return {"openstack_id": openstack_id} except Exception as e: for security_group in custom_security_groups: From 68524b086a433d376cc99415ef2c0353107d6f4e Mon Sep 17 00:00:00 2001 From: David Weinholz Date: Tue, 23 Feb 2021 09:11:07 +0100 Subject: [PATCH 8/9] create unique name for key --- .../VirtualMachineHandler.py | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/VirtualMachineService/VirtualMachineHandler.py b/VirtualMachineService/VirtualMachineHandler.py index f1b210c9..c9a8c0e4 100644 --- a/VirtualMachineService/VirtualMachineHandler.py +++ b/VirtualMachineService/VirtualMachineHandler.py @@ -3,6 +3,8 @@ Which can be used for the PortalClient. """ +from uuid import uuid4 + try: from VirtualMachineService import Iface from ttypes import serverNotFoundException @@ -909,7 +911,7 @@ def volume_ids( image = self.get_image(image=image) flavor = self.get_flavor(flavor=flavor) network = self.get_network() - key_name = metadata.get("elixir_id")[:-18] + key_name = f"{metadata.get('elixir_id')[:-18]}{str(uuid4())[0:5]}" public_key = urllib.parse.unquote(public_key) key_pair = self.import_keypair(key_name, public_key) init_script = self.create_mount_init_script( @@ -939,6 +941,7 @@ def volume_ids( return {"openstack_id": openstack_id} except Exception as e: + self.delete_keypair(key_name) for security_group in custom_security_groups: self.conn.network.delete_security_group(security_group) LOG.exception("Start Server {1} error:{0}".format(e, servername)) @@ -1015,12 +1018,13 @@ def start_server_without_playbook( custom_security_groups = self.prepare_security_groups_new_server( resenv=resenv, servername=servername, http=http, https=https ) - + key_name = None try: image = self.get_image(image=image) flavor = self.get_flavor(flavor=flavor) network = self.get_network() - key_name = metadata.get("elixir_id")[:-18] + key_name = f"{metadata.get('elixir_id')[:-18]}{str(uuid4())[0:5]}" + public_key = urllib.parse.unquote(public_key) key_pair = self.import_keypair(key_name, public_key) volume_ids = [] @@ -1034,7 +1038,6 @@ def start_server_without_playbook( ) for id in volume_ids: volumes.append(self.conn.get_volume_by_id(id=id)) - LOG.info(volumes) init_script = self.create_mount_init_script( volume_ids_path_new=volume_ids_path_new, volume_ids_path_attach=volume_ids_path_attach, @@ -1051,7 +1054,6 @@ def start_server_without_playbook( else: init_script = self.create_add_keys_script(keys=additional_keys) - LOG.info(init_script) server = self.conn.create_server( name=servername, @@ -1071,6 +1073,9 @@ def start_server_without_playbook( return {"openstack_id": openstack_id} except Exception as e: + if key_name: + self.delete_keypair(key_name) + for security_group in custom_security_groups: self.conn.network.delete_security_group(security_group) LOG.exception("Start Server {1} error:{0}".format(e, servername)) @@ -1108,12 +1113,12 @@ def start_server( custom_security_groups = self.prepare_security_groups_new_server( resenv=resenv, servername=servername, http=http, https=https ) - + key_name = None try: image = self.get_image(image=image) flavor = self.get_flavor(flavor=flavor) network = self.get_network() - key_name = metadata.get("elixir_id")[:-18] + key_name = f"{metadata.get('elixir_id')[:-18]}{str(uuid4())[0:5]}" public_key = urllib.parse.unquote(public_key) key_pair = self.import_keypair(key_name, public_key) @@ -1131,9 +1136,10 @@ def start_server( openstack_id = server["id"] self.delete_keypair(key_name) - return {"openstack_id": openstack_id} except Exception as e: + if key_name: + self.delete_keypair(key_name) for security_group in custom_security_groups: self.conn.network.delete_security_group(security_group) LOG.exception("Start Server {1} error:{0}".format(e, servername)) @@ -1609,10 +1615,13 @@ def check_template(self, template_name, template_version): def get_playbook_logs(self, openstack_id): global active_playbooks + LOG.info(f"Get Playbook logs {openstack_id}") if self.redis.exists(openstack_id) == 1 and openstack_id in active_playbooks: key_name = self.redis.hget(openstack_id, "name").decode("utf-8") playbook = active_playbooks.pop(openstack_id) status, stdout, stderr = playbook.get_logs() + LOG.info(f" Playbook logs{openstack_id} stattus: {status}") + playbook.cleanup(openstack_id) self.delete_keypair(key_name=key_name) return PlaybookResult(status=status, stdout=stdout, stderr=stderr) From 3497d10e557716fcde5cd9866f141ca7f0690668 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 23 Feb 2021 08:12:41 +0000 Subject: [PATCH 9/9] fix(Linting):blacked code --- VirtualMachineService/VirtualMachineHandler.py | 1 - 1 file changed, 1 deletion(-) diff --git a/VirtualMachineService/VirtualMachineHandler.py b/VirtualMachineService/VirtualMachineHandler.py index 2398b513..baa2c183 100644 --- a/VirtualMachineService/VirtualMachineHandler.py +++ b/VirtualMachineService/VirtualMachineHandler.py @@ -1053,7 +1053,6 @@ def start_server_without_playbook( else: init_script = self.create_add_keys_script(keys=additional_keys) - server = self.conn.create_server( name=servername, image=image.id,