Skip to content

Commit

Permalink
Merge pull request #456 from deNBI/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
dweinholz authored Jan 17, 2024
2 parents 41c54bb + 3d40665 commit 1cb0518
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v4

- name: Set up Python 3.11
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: 3.11

Expand Down
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
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
setuptools==69.0.3
thrift==0.16.0
python-keystoneclient==5.2.0
openstacksdk==2.0.0
python-keystoneclient==5.3.0
openstacksdk==2.1.0
deprecated==1.2.14
Click==8.1.7
ansible==5.1.0
Expand Down
20 changes: 11 additions & 9 deletions scripts/gateway/gateway_UDP.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@

# get local ip from meta data server
LOCALIP=$(curl http://169.254.169.254/latest/meta-data/local-ipv4)
LOCALNET=$( echo ${LOCALIP} | cut -f 1-3 -d".")
LOCALNET=$( echo ${LOCALIP} | cut -f 1-2 -d".")

#ip forwarding rules
for ((base=0; base <=8; base++))
{
for ((n=1; n <=254; n++))
{
MOSH_BASE=$((30000+$n*10))
MOSH_BASE=$((30000+$n + base *256))


MOSH_PORT=$(($MOSH_BASE))
echo ${MOSH_PORT}
iptables -t nat -A PREROUTING -i ens3 -p udp -m udp --dport ${MOSH_PORT} -j DNAT --to-destination ${LOCALNET}.${base}.${n}:${MOSH_PORT}
iptables -t nat -A POSTROUTING -d ${LOCALNET}.${base}.${n}/32 -p udp -m udp --dport ${MOSH_PORT} -j SNAT --to-source ${LOCALIP}

for ((m=0; m<=9; m++))
{
MOSH_PORT=$(($MOSH_BASE+$m))
#$echo ${MOSH_PORT}
iptables -t nat -A PREROUTING -i ens3 -p udp -m udp --dport ${MOSH_PORT} -j DNAT --to-destination ${LOCALNET}.${n}:${MOSH_PORT}
iptables -t nat -A POSTROUTING -d ${LOCALNET}.${n}/32 -p udp -m udp --dport ${MOSH_PORT} -j SNAT --to-source ${LOCALIP}
}

}
}
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 1cb0518

Please sign in to comment.