From 51592b7f2eb578f5552a0d591312b3e8f866345c Mon Sep 17 00:00:00 2001 From: Tobias Fischer Date: Fri, 9 Jul 2021 16:30:21 +0200 Subject: [PATCH 1/2] Better handling of the security group for testing --- src/manage.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/manage.py b/src/manage.py index 3342eeed..38f0a237 100644 --- a/src/manage.py +++ b/src/manage.py @@ -28,6 +28,7 @@ cfg.BoolOpt('test-latest-image', help='Test the latest uploaded image', default=False), cfg.StrOpt('network', help='Network which should be used for the test instances', default='floating-IPv4'), cfg.StrOpt('flavor', help='Flavor which should be used for the test instances', default='S'), + cfg.StrOpt('security-group', help='Security group which should used for the test instance', default='ssh'), cfg.StrOpt('cloud', help='Cloud name in clouds.yaml', default='images'), cfg.StrOpt('name', help='Image name to process', default=None), cfg.StrOpt('images', help='Path to the images.yml file', default='etc/images.yml'), @@ -75,6 +76,14 @@ def create_keypair(conn, keypair_name): return keypair +def create_security_group(conn, security_group_name, port, protocol): + security_group = conn.create_security_group(name=security_group_name, + description="sg for login into a test instance") + conn.create_security_group_rule(security_group.id, protocol=protocol, + port_range_min=port, port_range_max=port) + return security_group + + def delete_keypair(conn, keypair_name): keypair = conn.compute.find_keypair(keypair_name) keypair_file = str(pathlib.Path.cwd() / keypair_name) @@ -97,7 +106,11 @@ def test_image(conn, image, name): keypair_name = 'test_key' keypair_file = str(pathlib.Path.cwd() / keypair_name) keypair = create_keypair(conn, keypair_name) - security_group = conn.network.find_security_group('ssh') + security_group = conn.network.find_security_group(CONF.security_group) + + if not security_group: + # create a fallback security_group + security_group = create_security_group(conn, CONF.security_group, 22, 'tcp') server = conn.compute.create_server( name='test instance', image_id=image.id, flavor_id=flavor.id, From 0f5a6d2aa53888eb8000130b6ccc4fc2ab116bfd Mon Sep 17 00:00:00 2001 From: Tobias Fischer Date: Fri, 9 Jul 2021 11:23:38 +0200 Subject: [PATCH 2/2] Attach floating ip to test instance --- src/manage.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/manage.py b/src/manage.py index 38f0a237..3c664947 100644 --- a/src/manage.py +++ b/src/manage.py @@ -26,6 +26,7 @@ cfg.BoolOpt('yes-i-really-know-what-i-do', help='Really delete images', default=False), cfg.BoolOpt('use-os-hidden', help='Use the os_hidden property', default=False), cfg.BoolOpt('test-latest-image', help='Test the latest uploaded image', default=False), + cfg.BoolOpt('use-floating-ip', help='Attach a floating IP to the test image', default=True), cfg.StrOpt('network', help='Network which should be used for the test instances', default='floating-IPv4'), cfg.StrOpt('flavor', help='Flavor which should be used for the test instances', default='S'), cfg.StrOpt('security-group', help='Security group which should used for the test instance', default='ssh'), @@ -125,13 +126,16 @@ def test_image(conn, image, name): return 'failure' conn.compute.add_security_group_to_server(server, security_group) - server_ip = server.addresses[CONF.network][0]['addr'] + if CONF.use_floating_ip: + server_ip = conn.add_auto_ip(server) + else: + server_ip = server.addresses[CONF.network][0]['addr'] time.sleep(60.0) test_process = subprocess.run(["ssh", "-o", "StrictHostKeyChecking no", "-i", keypair_file, login+"@"+server_ip, "ls"]) - conn.compute.delete_server(server) + conn.compute.delete_server(server.id, delete_ips=True) delete_keypair(conn, keypair_name) if test_process.returncode == 0: