Skip to content

Commit

Permalink
Merge branch 'dev' into deps/openstacksdk-2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
dweinholz committed Jan 17, 2024
2 parents 20d62ef + d46c36b commit 7227f5c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ wheels/
*.egg-info/
.installed.cfg
*.egg
.env.dsi
.env.*
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
Expand Down
17 changes: 11 additions & 6 deletions simple_vm_client/openstack_connector/openstack_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ def __init__(self, config_file: str):
self.APPLICATION_CREDENTIAL_ID = ""
self.APPLICATION_CREDENTIAL_SECRET = ""
self.USE_APPLICATION_CREDENTIALS: bool = False
self.NOVA_MICROVERSION = '2.1'
self.NOVA_MICROVERSION = "2.1"

self.load_env_config()
print("loading config file")
logger.info(f"Loading config file -- {config_file}")
self.load_config_yml(config_file)

try:
Expand All @@ -102,9 +102,11 @@ def __init__(self, config_file: str):
project_name=self.PROJECT_NAME,
user_domain_name=self.USER_DOMAIN_NAME,
project_domain_id=self.PROJECT_DOMAIN_ID,
compute_api_version=self.NOVA_MICROVERSION
compute_api_version=self.NOVA_MICROVERSION,
)
self.openstack_connection.authorize()
self.get_network()

logger.info("Connected to Openstack")
self.create_or_get_default_ssh_security_group()
except Exception:
Expand Down Expand Up @@ -392,10 +394,13 @@ def create_volume(
raise ResourceNotAvailableException(message=e.message)

def get_network(self) -> Network:
network: Network = self.openstack_connection.network.find_network(self.NETWORK)
logger.info(f"Getting Network: {self.NETWORK}")
network: Network = self.openstack_connection.get_network(
name_or_id=self.NETWORK
)
if network is None:
logger.exception(f"Network {network} not found!")
raise Exception(f"Network {network} not found!")
logger.exception(f"Network {self.NETWORK} not found!")
raise Exception(f"Network {self.NETWORK} not found!")
return network

def import_keypair(self, keyname: str, public_key: str) -> dict[str, str]:
Expand Down
19 changes: 8 additions & 11 deletions simple_vm_client/test_openstack_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -956,9 +956,7 @@ def test_create_volume(self, mock_logger_info, mock_logger_exception):
)

def test_network_not_found(self):
self.openstack_connector.openstack_connection.network.find_network.return_value = (
None
)
self.openstack_connector.openstack_connection.get_network.return_value = None
with self.assertRaises(Exception):
self.openstack_connector.get_network()

Expand All @@ -969,20 +967,19 @@ def test_get_network(self, mock_logger_exception):

# Call the load_config_yml method with the temporary file path
self.openstack_connector.load_config_yml(temp_file.name)
network = fakes.generate_fake_resource(Network)

# Mock the find_network method
self.mock_openstack_connection.network.find_network.return_value = Network(
id="my_network"
)
self.mock_openstack_connection.get_network.return_value = network

# Call the get_network method
result_network = self.openstack_connector.get_network()

# Assertions
self.assertIsInstance(result_network, Network)
self.assertEqual(result_network.id, "my_network")
self.mock_openstack_connection.network.find_network.assert_called_once_with(
self.openstack_connector.NETWORK
self.assertEqual(result_network.id, network.id)
self.mock_openstack_connection.get_network.assert_called_once_with(
name_or_id=self.openstack_connector.NETWORK
)
mock_logger_exception.assert_not_called() # Ensure no exception is logged

Expand Down Expand Up @@ -1509,7 +1506,7 @@ def test_start_server_with_playbook(
self.openstack_connector.openstack_connection.get_flavor.return_value = (
fake_flavor
)
self.openstack_connector.openstack_connection.network.find_network.return_value = (
self.openstack_connector.openstack_connection.get_network.return_value = (
fake_network
)
mock_get_volumes.return_value = ["volume1", "volume2"]
Expand Down Expand Up @@ -1787,7 +1784,7 @@ def test_start_server(
self.openstack_connector.openstack_connection.get_flavor.return_value = (
fake_flavor
)
self.openstack_connector.openstack_connection.network.find_network.return_value = (
self.openstack_connector.openstack_connection.get_network.return_value = (
fake_network
)
self.openstack_connector.openstack_connection.compute.find_keypair.return_value = (
Expand Down
2 changes: 1 addition & 1 deletion simple_vm_client/util/thrift_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def os_to_thrift_volume(openstack_volume: OpenStack_Volume) -> Volume:
device = openstack_volume.attachments[0]["device"]
server_id = openstack_volume.attachments[0]["server_id"]
except Exception as e:
logger.log(f"Exception on os_to_thrift_volume:\n{e}")
logger.error(f"Exception on os_to_thrift_volume:\n{e}")
volume = Volume(
status=openstack_volume.status,
id=openstack_volume.id,
Expand Down

0 comments on commit 7227f5c

Please sign in to comment.