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

feat(Dependencies): Update dependency openstacksdk to v3 #475

Merged
merged 5 commits into from
Mar 25, 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
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM python:3.11.4-buster

FROM python:3.12.0
RUN echo "deb https://deb.debian.org/debian/ stable main" > /etc/apt/sources.list
RUN apt-get update -y \
&& apt-get install -y build-essential \
&& apt-get clean \
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
setuptools==69.2.0
thrift==0.16.0
thrift==0.20.0
python-keystoneclient==5.4.0
openstacksdk==2.1.0
openstacksdk==3.0.0
deprecated==1.2.14
Click==8.1.7
ansible==9.3.0
Expand Down
2 changes: 0 additions & 2 deletions simple_vm_client/VirtualMachineService.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion simple_vm_client/forc_connector/playbook/playbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,6 @@ def add_always_tasks_only(self, playbook_name: str) -> None:
)

def run_it(self) -> None:
logger.info("RUN ITTT")
command_string = f"/usr/local/bin/ansible-playbook -v -i {self.inventory.name} {self.directory.name}/{self.playbook_exec_name}"
command_string = shlex.split(command_string) # type: ignore
logger.info(f"Run Playbook for {self.playbook_exec_name} - [{command_string}]")
Expand Down
4 changes: 4 additions & 0 deletions simple_vm_client/openstack_connector/openstack_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -1426,6 +1426,10 @@ def add_udp_security_group(self, server_id):
if self._is_security_group_already_added_to_server(
server=server, security_group_name=sec_name
):
logger.info(
f"UDP Security group with name {sec_name} already added to server."
)

return

self.openstack_connection.compute.add_security_group_to_server(
Expand Down
33 changes: 12 additions & 21 deletions simple_vm_client/test_openstack_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -1098,7 +1098,12 @@ def test_create_add_keys_script(self, mock_logger_info):
result_script = self.openstack_connector.create_add_keys_script(keys)

# Assertions
expected_script_content = '#!/bin/bash\ndeclare -a keys_to_add=("key1" "key2" "key3" )\necho "Found keys: ${#keys_to_add[*]}"\nfor ix in ${!keys_to_add[*]}\ndo\n printf "\\n%s" "${keys_to_add[$ix]}" >> /home/ubuntu/.ssh/authorized_keys\n\ndone\n'
expected_script_content = (
'#!/bin/bash\ndeclare -a keys_to_add=("key1" "key2" "key3" )'
'\necho "Found keys: ${#keys_to_add[*]}"\nfor ix in ${!keys_to_add[*]}'
'\ndo\n printf "\\n%s" "${keys_to_add[$ix]}" >> /home/ubuntu/.ssh/authorized_keys'
"\n\ndone\n"
)
expected_script_content = encodeutils.safe_encode(
expected_script_content.encode("utf-8")
)
Expand Down Expand Up @@ -2166,21 +2171,6 @@ def test_reboot_server_success(self, mock_get_server):
server_mock, "SOFT"
)

@patch.object(OpenStackConnector, "get_server")
@patch("simple_vm_client.openstack_connector.openstack_connector.logger.exception")
def test_reboot_server_conflict_exception(
self, mock_logger_exception, mock_get_server
):
self.openstack_connector.openstack_connection.compute.reboot_server.side_effect = ConflictException(
"Unit Test"
)
# Act
with self.assertRaises(OpenStackConflictException):
self.openstack_connector.reboot_server("some_openstack_id", "SOFT")
mock_logger_exception.assert_called_once_with(
"Reboot Server some_openstack_id failed!"
)

@patch.object(OpenStackConnector, "get_server")
def test_reboot_soft_server(self, mock_get_server):
# Arrange
Expand Down Expand Up @@ -2271,7 +2261,9 @@ def test_get_server(
ignore_not_active=True,
ignore_not_found=True,
)
mock_get_flavor.assert_called_once_with(name_or_id=flavor_mock.id)
mock_get_flavor.assert_called_once_with(
name_or_id=flavor_mock.id, ignore_error=True
)
mock_netcat.return_value = False # Assuming SSH connection is successful
# Act
result_server = self.openstack_connector.get_server(openstack_id)
Expand Down Expand Up @@ -2335,7 +2327,7 @@ def test_reboot_server_conflict_exception(
with self.assertRaises(OpenStackConflictException):
self.openstack_connector.reboot_server("some_openstack_id", "SOFT")
mock_logger_exception.assert_called_once_with(
f"Reboot Server some_openstack_id failed!"
"Reboot Server some_openstack_id failed!"
)

def test_exist_server_true(self):
Expand Down Expand Up @@ -2514,7 +2506,6 @@ def test_is_security_group_in_use_ports(self):

def test_is_security_group_in_use_load_balancers(self):
# Mock the network.load_balancers method to simulate load balancers associated with the security group
load_balancers = [{"id": "lb_id", "name": "lb_name"}]
self.openstack_connector.openstack_connection.compute.servers.return_value = []
self.openstack_connector.openstack_connection.network.ports.return_value = []

Expand Down Expand Up @@ -2668,7 +2659,7 @@ def test_open_port_range_for_vm_in_project_conflict_exception(
range_start=1000, range_stop=1000, openstack_id="test"
)
mock_logger_exception.assert_called_once_with(
f"Could not create security group rule for instance test"
"Could not create security group rule for instance test"
)

@patch.object(OpenStackConnector, "get_or_create_project_security_group")
Expand Down Expand Up @@ -2707,7 +2698,7 @@ def test_open_port_range_for_vm_in_project(
)

# Call the method
result = self.openstack_connector.open_port_range_for_vm_in_project(
self.openstack_connector.open_port_range_for_vm_in_project(
range_start=1000,
range_stop=2000,
openstack_id=fake_server.id,
Expand Down