Skip to content

Commit

Permalink
test: fix unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
yanksyoon committed Apr 15, 2024
1 parent c48f37e commit e4d699f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src-docs/openstack_manager.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Create an instance config from charm data.

---

<a href="../src/openstack_cloud/openstack_manager.py#L437"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/utilities.py#L436"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

## <kbd>function</kbd> `create_instance`

Expand Down
6 changes: 3 additions & 3 deletions src/openstack_cloud/openstack_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ def _generate_cloud_init_userdata(
)


# @retry(tries=5, delay=5, max_delay=60, backoff=2, local_logger=logger)
@retry(tries=5, delay=5, max_delay=60, backoff=2, local_logger=logger)
def create_instance(
cloud_config: dict[str, dict],
instance_config: InstanceConfig,
Expand Down Expand Up @@ -477,6 +477,6 @@ def create_instance(
timeout=1200,
)
except OpenStackCloudException as exc:
# if not conn.delete_server(instance_config.name):
# logger.error("Failed to delete server %s", instance_config.name)
if not conn.delete_server(instance_config.name):
logger.error("Failed to delete server %s", instance_config.name)
raise OpenstackInstanceLaunchError("Failed to launch instance.") from exc
16 changes: 14 additions & 2 deletions tests/unit/test_openstack_manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.
import secrets
import textwrap
from typing import Optional
from unittest.mock import MagicMock

Expand Down Expand Up @@ -350,8 +351,19 @@ def test__build_image_command():
Environment="NO_PROXY={test_no_proxy}"
""",
f"""{{"proxies": {{"default": {{"httpProxy": "{test_http_proxy}", \
"httpsProxy": "{test_https_proxy}", "noProxy": "{test_no_proxy}"}}}}}}""",
textwrap.dedent(
f"""
{{
"proxies": {{
"default": {{
"httpProxy": "{test_http_proxy}",
"httpsProxy": "{test_https_proxy}",
"noProxy": "{test_no_proxy}"
}}
}}
}}
"""
).strip(),
test_base_image.value,
], "Unexpected build image command."

Expand Down

0 comments on commit e4d699f

Please sign in to comment.