Skip to content

Commit

Permalink
test: revert function openstack fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
yanksyoon committed Apr 10, 2024
1 parent a324e45 commit 8e66028
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import zipfile
from pathlib import Path
from time import sleep
from typing import Any, AsyncGenerator, AsyncIterator, Generator, Iterator, Optional
from typing import Any, AsyncIterator, Iterator, Optional

import openstack
import openstack.connection
Expand All @@ -22,7 +22,6 @@
from juju.application import Application
from juju.client._definitions import FullStatus, UnitStatus
from juju.model import Model
from openstack.compute.v2.server import Server
from pytest_operator.plugin import OpsTest

from charm_state import (
Expand Down Expand Up @@ -164,23 +163,18 @@ def openstack_clouds_yaml(pytestconfig: pytest.Config) -> Optional[str]:
return Path(clouds_yaml).read_text(encoding="utf-8") if clouds_yaml else None


@pytest.fixture(scope="function", name="openstack_connection")
@pytest.fixture(scope="module", name="openstack_connection")
def openstack_connection_fixture(
openstack_clouds_yaml: Optional[str],
) -> Generator[openstack.connection.Connection, None, None]:
) -> openstack.connection.Connection:
"""The openstack connection instance."""
assert openstack_clouds_yaml, "Openstack clouds yaml was not provided."

openstack_clouds_yaml_yaml = yaml.safe_load(openstack_clouds_yaml)
clouds_yaml_path = Path.cwd() / "clouds.yaml"
clouds_yaml_path.write_text(data=openstack_clouds_yaml, encoding="utf-8")
first_cloud = next(iter(openstack_clouds_yaml_yaml["clouds"].keys()))
with openstack.connect(first_cloud) as conn:
yield conn

server: Server
for server in conn.list_servers():
conn.delete_server(server.name)
return openstack.connect(first_cloud)


@pytest.fixture(scope="module")
Expand Down Expand Up @@ -223,22 +217,23 @@ async def app_no_runner(
return application


@pytest_asyncio.fixture(scope="function", name="app_openstack_runner")
@pytest_asyncio.fixture(scope="module", name="app_openstack_runner")
async def app_openstack_runner_fixture(
model: Model,
charm_file: str,
app_name: str,
path: str,
token: str,
http_proxy: str,
https_proxy: str,
no_proxy: str,
openstack_clouds_yaml: str,
) -> AsyncGenerator[Application, None]:
) -> AsyncIterator[Application]:
"""Application launching VMs and no runners."""
application = await deploy_github_runner_charm(
model=model,
app_name=f"integration-id{secrets.token_hex(2)}",
charm_file=charm_file,
app_name=app_name,
path=path,
token=token,
runner_storage="juju-storage",
Expand All @@ -255,9 +250,7 @@ async def app_openstack_runner_fixture(
config={OPENSTACK_CLOUDS_YAML_CONFIG_NAME: openstack_clouds_yaml},
wait_idle=False,
)
yield application

model.remove_application(application.name)
return application


@pytest_asyncio.fixture(scope="module")
Expand Down

0 comments on commit 8e66028

Please sign in to comment.