Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix tests #142

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cloud_level_testing/features/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

DEFAULT_PROMETHEUS_BATCH_NAME = "SCS-Health-Monitor"
DEFAULT_CLOUD_NAME = "gx"
DEFAULT_PROVIDER_NETWORK_INTERFACE="public"
DEFAULT_LOG_LEVEL = os.environ.get("LOGLEVEL", "INFO")


Expand Down Expand Up @@ -95,6 +96,7 @@ def before_all(context):
cloud_name = context.env.get("CLOUD_NAME")
context.test_name = context.env.get("TESTS_NAME_IDENTIFICATION")
context.vm_image = context.env.get("VM_IMAGE")
context.provider_network_name = context.env.get("PROVIDER_NETWORK_INTERFACE", DEFAULT_PROVIDER_NETWORK_INTERFACE)
context.flavor_name = context.env.get("FLAVOR_NAME")
context.client = openstack.connect(cloud=cloud_name)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Feature: Build benchmark infrastructure

Given I have a private key at <keypair_name> for <username>
Given I want to build the benchmark infrastructure by using resources having the infix <test_infix>
Then I should be able to create a router connected to the external network named <ext_net>
Then I should be able to create a router connected to the globally configured public provider network
Then I should be able to fetch availability zones
Then I should be able to create networks for both the jump hosts and for each availability zone
Then I should be able to create subnets for both the jump hosts and vms
Expand All @@ -23,5 +23,5 @@ Feature: Build benchmark infrastructure
Then I can pass the context to another feature

Examples: Build benchmark infrastructure
| test_infix | ext_net | keypair_name | quantity_vms | port_start | port_end |username|
| infra | ext01 | infra-keypair | 2 | 222 | 229 | ubuntu |
| test_infix | keypair_name | quantity_vms | port_start | port_end |username|
| infra | infra-keypair | 2 | 222 | 229 | ubuntu |
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
@create
Feature: OpenStack floating ip deletion

Scenario Outline: Connect to OpenStack and create a floating ip
Scenario Outline: Connect to OpenStack and create and delete a plain floating ip
Given I connect to OpenStack
Then I should be able to delete all floating ip with

Examples:


Then I should be able to create a plain floating ip which is not associated to something
Then I should be able to delete all previously created plain floating ips
8 changes: 5 additions & 3 deletions cloud_level_testing/features/steps/benchmark_infra.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,18 @@ def calculate_jh_name_by_az(context, az):
return f"{context.test_name}jh{context.azs.index(az)}"

@then(
"I should be able to create a router connected to the external network named {ext_net}"
"I should be able to create a router connected to the globally configured public provider network"
)
def infra_create_router(context, ext_net):
nets = tools.list_networks(context.client, filter={"name": ext_net})
def infra_create_router(context):
nets = tools.list_networks(context.client, filter={"name": context.provider_network_name})
assert len(nets) == 1, "Expecting to find exactly one external network."

context.collector.create_router(
name=context.lb_router_name,
external_gateway_info={"network_id": nets[0].id},
)
context.logger.log_info(f"Router {context.lb_router_name} connected to "
f"{context.provider_network_name} provider network was created")

@then("I should be able to fetch availability zones")
def infra_get_azs(context):
Expand Down
34 changes: 33 additions & 1 deletion cloud_level_testing/features/steps/definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def given_i_connect_to_openstack(context):
context.test_name = context.env.get("TESTS_NAME_IDENTIFICATION")
context.vm_image = context.env.get("VM_IMAGE")
context.flavor_name = context.env.get("FLAVOR_NAME")
context.provider_network_name = context.env.get("PROVIDER_NETWORK_INTERFACE")
context.client = openstack.connect(cloud=cloud_name)

@when("A router with name {router_name} exists")
Expand Down Expand Up @@ -473,6 +474,23 @@ def delete_availability_zone(context, name):
if zone.name == name:
context.compute.delete_availability_zone(name=zone.name)

@then(
"Then I should be able to create a plain floating ip which is not associated to something"
)
def create_floating_ip_plain(
context,
wait=False,
timeout=60,
):
ip = FloatingIPCloudMixin.create_floating_ip(
network=context.provider_network_name,
wait=wait,
timeout=timeout,
)
floating_ip = FloatingIPCloudMixin.get_floating_ip(ip.id)
context.collector.plain_floating_ips.append(floating_ip.id)
assert floating_ip is None, f"plain floating ip was not created"

@then(
"I should be able to create a floating ip on {subnet}, on {server}, with {fixed_address}, for {nat_destination}"
"on {port}"
Expand Down Expand Up @@ -513,6 +531,20 @@ def delete_floating_ip(context, floating_ip_id):
len(context.collector.floating_ips) == 0
), f"Failed to delete floating IPs"

@then("I should be able to delete all previously plain floating ips")
def delete_all_plain_floating_ip(context):
for ip_id in context.collector.plain_floating_ips[:]:
FloatingIPCloudMixin.delete_floating_ip(floating_ip_id=ip_id)
floating_ip = FloatingIPCloudMixin.get_floating_ip(ip_id)
context.logger.log_info(f"Deleting plain floating ip with {ip_id}")
assert (
floating_ip is not None
), f"floating ip with id {ip_id} was not deleted"
context.collector.floating_ips.remove(ip_id)
assert (
len(context.collector.floating_ips) == 0
), f"Failed to delete floating IPs"

@then("I should be able to create {vms_quantity:d} VMs")
def create_vm(context, vms_quantity: int):
# config
Expand Down Expand Up @@ -629,7 +661,7 @@ def create_a_jumphost(
ping_sec_group_name = "ping-sg"
ping_sec_group_description = "Ping security group - allow ICMP"
security_groups = ["ssh", "default", ping_sec_group_name]
keypair_filename = f"{context.keypair_name}-private"
keypair_filename = f"{keypair_name}-private"
user_data = f"""#cloud-config
packages:
- iperf3
Expand Down
10 changes: 6 additions & 4 deletions cloud_level_testing/features/steps/tools.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ipaddress
import textwrap
import time
import datetime
from functools import wraps
Expand Down Expand Up @@ -27,6 +28,7 @@ def __init__(self, client: openstack.connection.Connection = None):
self.routers: list = list()
self.jumphosts: list = list()
self.floating_ips: list = list()
self.plain_floating_ips: list = list()
self.security_groups: list = list()
self.security_groups_rules: list = list()
self.virtual_machines: list = list()
Expand Down Expand Up @@ -813,18 +815,18 @@ def create_wait_script(conn_test, testname):
if "iperf" in conn_test:
secondary = "iperf"

script_content = f"""
script_content = textwrap.dedent('''
#!/bin/bash
let MAXW=100
if test ! -f /var/lib/cloud/instance/boot-finished; then sleep 5; sync; fi
while test \$MAXW -ge 1; do
if type -p "{conn_test}">/dev/null || type -p "{secondary}">/dev/null; then exit 0; fi
while test $MAXW -ge 1; do
if type -p "%s">/dev/null || type -p "%s">/dev/null; then exit 0; fi
let MAXW-=1
sleep 1
if test ! -f /var/lib/cloud/instance/boot-finished; then sleep 1; fi
done
exit 1
"""
''') % (conn_test, secondary)
try:
with open(script_path, "w") as file:
file.write(script_content)
Expand Down
Loading