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

New k8s #1524

Merged
merged 30 commits into from
Feb 15, 2024
Merged

New k8s #1524

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
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
5 changes: 2 additions & 3 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ jobs:
- name: Check code style
run: pycodestyle --max-line-length=120 --ignore=E402,W504,W605,E722 . --exclude=doc

- name: Test with nose
#run: nosetests test/unit/connectors/*.py test/unit/*.py test/functional/*.py -v --stop --with-xunit --with-coverage --cover-erase --cover-xml --cover-package=IM,contextualization
run: python -m coverage run --source=. -m unittest discover -s test/unit -p '*.py'
- name: Unit tests
run: python -m coverage run --source=. -m unittest discover -v -s test/unit -p '*.py'

- name: Generate XML coverage report
run: python -m coverage xml
Expand Down
4 changes: 2 additions & 2 deletions IM/ConfManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import time
import tempfile
import shutil
from distutils.version import LooseVersion
from packaging.version import Version

try:
from StringIO import StringIO
Expand Down Expand Up @@ -758,7 +758,7 @@ def get_vault_editor(vault_password):
"""
Get the correct VaultEditor object in different Ansible versions
"""
if LooseVersion(ansible_version) >= LooseVersion("2.4.0"):
if Version(ansible_version) >= Version("2.4.0"):
# for Ansible version 2.4.0 or higher
vault_secrets = [('default', VaultSecret(_bytes=to_bytes(vault_password)))]
return VaultEditor(VaultLib(vault_secrets))
Expand Down
6 changes: 3 additions & 3 deletions IM/ansible_utils/ansible_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import psutil
import signal
import logging
from distutils.version import LooseVersion
from packaging.version import Version
from collections import namedtuple
from ansible import errors
from ansible import __version__ as ansible_version
Expand Down Expand Up @@ -137,7 +137,7 @@ def run(self):
self._kill_childs()

def get_play_prereqs(self, options):
if LooseVersion(ansible_version) >= LooseVersion("2.4.0"):
if Version(ansible_version) >= Version("2.4.0"):
# for Ansible version 2.4.0 or higher
return self.get_play_prereqs_2_4(options)
else:
Expand Down Expand Up @@ -208,7 +208,7 @@ def version_info(ansible_version_string):
'revision': ansible_versions[2]}

def _gen_options(self):
if LooseVersion(ansible_version) >= LooseVersion("2.8.0"):
if Version(ansible_version) >= Version("2.8.0"):
from ansible.module_utils.common.collections import ImmutableDict
from ansible import context
context.CLIARGS = ImmutableDict(connection='ssh',
Expand Down
19 changes: 19 additions & 0 deletions IM/connectors/CloudConnector.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import time
import yaml
import uuid
import re

from radl.radl import Feature, outport
from IM.config import Config
Expand Down Expand Up @@ -751,3 +752,21 @@ def manage_dns_entries(self, op, vm, auth_data, extra_args=None):
self.error_messages += "Error in %s DNS entries %s.\n" % (op, str(ex))
self.log_exception("Error in %s DNS entries" % op)
return False

@staticmethod
def convert_memory_unit(memory, unit="M"):
unit_dict = {'B': 1, 'K': 1000, 'Ki': 1024,
'M': 1000000, 'Mi': 1048576,
'G': 1000000000, 'Gi': 1073741824,
'T': 1000000000000, 'Ti': 1099511627776}
regex = re.compile(r'([0-9.]+)\s*([a-zA-Z]+)')
result = regex.match(str(memory)).groups()
value = float(result[0])
orig_unit = result[1]
if len(orig_unit) > 1 and orig_unit[-1] == 'B':
orig_unit = orig_unit[:-1]

converted = (value * unit_dict[orig_unit] / unit_dict[unit])
if converted - int(converted) < 0.0000000000001:
converted = int(converted)
return converted
Loading