Skip to content

Commit

Permalink
Merge pull request #1537 from grycap/devel
Browse files Browse the repository at this point in the history
Devel
  • Loading branch information
micafer authored Feb 28, 2024
2 parents 62ea29a + efa8700 commit 3db34cb
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 28 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,13 @@ jobs:
python-version: '3.10'

- name: Install dependencies
run: python -m pip install -r requirements-tests.txt
run: python -m pip install tox

- name: Check code style
run: pycodestyle --max-line-length=120 --ignore=E402,W504,W605,E722 . --exclude=doc
run: tox -e style

- 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
run: tox -e coverage

- name: Report coverage
uses: codacy/codacy-coverage-reporter-action@v1
Expand Down
2 changes: 1 addition & 1 deletion IM/AppDB.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def get_image_id(site_id, image_name, vo_name):
images.append((image_basename, image['@vmiversion']))
except Exception:
# in case of error ignore image
pass
continue

image = None
if len(images) == 1:
Expand Down
2 changes: 1 addition & 1 deletion IM/connectors/EC2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1608,7 +1608,7 @@ def get_all_instance_types(self, retries=3, delay=5):
cont += 1
try:
info_url = "https://raw.githubusercontent.com/grycap/im/master/scripts/instances.json"
resp = requests.get(info_url)
resp = requests.get(info_url, timeout=10)
if resp.status_code == 200:
data = resp.json()
else:
Expand Down
2 changes: 1 addition & 1 deletion IM/connectors/OpenNebula.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
try:
from xmlrpclib import ServerProxy # nosec
except ImportError:
from xmlrpc.client import ServerProxy
from xmlrpc.client import ServerProxy # nosec

import os.path
import time
Expand Down
2 changes: 1 addition & 1 deletion IM/connectors/OpenStack.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ def add_dns_entry(self, hostname, domain, ip, auth_data, extra_args=None):
domain[:-1],
ip)
try:
resp = requests.get(url, headers=headers)
resp = requests.get(url, headers=headers, timeout=10)
resp.raise_for_status()
except Exception as ex:
self.error_messages += "Error creating DNS entries %s.\n" % str(ex)
Expand Down
4 changes: 2 additions & 2 deletions IM/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
except ImportError:
from queue import Queue, Empty
try:
from SimpleXMLRPCServer import SimpleXMLRPCServer
from SimpleXMLRPCServer import SimpleXMLRPCServer # nosec
except ImportError:
from xmlrpc.server import SimpleXMLRPCServer
from xmlrpc.server import SimpleXMLRPCServer # nosec
try:
from SocketServer import ThreadingMixIn
except ImportError:
Expand Down
4 changes: 2 additions & 2 deletions IM/xmlrpcssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

import ssl
try:
from SimpleXMLRPCServer import SimpleXMLRPCServer
from SimpleXMLRPCServer import SimpleXMLRPCServer # nosec
except ImportError:
from xmlrpc.server import SimpleXMLRPCServer
from xmlrpc.server import SimpleXMLRPCServer # nosec


class SSLSimpleXMLRPCServer(SimpleXMLRPCServer, object):
Expand Down
3 changes: 1 addition & 2 deletions requirements-tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ scp
tosca-parser
defusedxml
urllib3>=1.23,<2.0
pycodestyle
suds-py3
xmltodict
mysqlclient
PyMySQL
pywinrm
pymongo
msrest
Expand Down
5 changes: 5 additions & 0 deletions test/files/tosca_k8s.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ topology_template:
content: |
[im]
REST_API = True
my_secret:
deploy_path: /etc/secret
type: tosca.artifacts.File
properties:
content: c29tZSBlbmNvZGVkIGNvbnRlbnQ=

# The properties of the runtime to host the container
im_runtime:
Expand Down
2 changes: 2 additions & 0 deletions test/unit/Tosca.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,8 @@ def test_tosca_k8s(self):
self.assertEqual(net.getValue("outbound"), 'yes')
self.assertEqual(node.getValue("disk.1.content"), '[im]\nREST_API = True\n')
self.assertEqual(node.getValue("disk.1.mount_path"), '/etc/im/im.cfg')
self.assertEqual(node.getValue("disk.2.content"), 'c29tZSBlbmNvZGVkIGNvbnRlbnQ=')
self.assertEqual(node.getValue("disk.2.mount_path"), '/etc/secret')
self.assertEqual(node.getValue("environment.variables"),
'IM_DATA_DB=mysql://root:my-secret@mysql-container:3306/im-db')
self.assertEqual(node.getValue("net_interface.0.connection"), 'im_container_pub')
Expand Down
2 changes: 2 additions & 0 deletions test/unit/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import sys
sys.path.append(".")
25 changes: 13 additions & 12 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
[tox]
envlist = py3,style,coverage,bandit
envlist = style,py3,coverage,bandit
skipsdist = true

[testenv]
deps = nose
mock
bandit
-r{toxinidir}/requirements-tests.txt
deps = -r{toxinidir}/requirements-tests.txt
basepython =
{py3,style,coverage,bandit}: python3
whitelist_externals = bash
commands = bash -c "nosetests -v test/unit/*.py test/unit/connectors/*.py"
commands = python -m unittest discover -v -s test/unit -p '*.py'

[testenv:style]
deps = pycodestyle
commands = pycodestyle --max-line-length=120 --ignore=E402,W504,W605 IM --exclude=doc
pycodestyle --max-line-length=120 --ignore=E402,W504,W605 contextualization --exclude=doc
pycodestyle --max-line-length=120 --ignore=E402,W504,W605 test
commands = pycodestyle --max-line-length=120 --ignore=E402,W504,W605 . --exclude=doc,.tox,scripts

[testenv:coverage]
commands = bash -c "nosetests -v test/unit/*.py test/unit/connectors/*.py -v --stop --with-xunit --with-coverage --cover-erase --cover-xml --cover-package=IM,contextualization"
deps = -r{toxinidir}/requirements-tests.txt
commands = python -m coverage run --source=. -m unittest discover -v -s test/unit -p '*.py'
python -m coverage xml -o coverage.xml

[testenv:bandit]
commands = bandit IM -r -f html -o bandit.html -s B108,B601,B104 --severity-level medium
deps = bandit
commands = bandit IM -r -f html -o bandit.html -s B108,B601,B608,B507,B104 -ll

[flake8]
ignore = E402,E265,W605,W504,F811
max-line-length = 120
exclude = doc,scripts

[pytest]
python_files = *.py
testpaths =
test/unit

0 comments on commit 3db34cb

Please sign in to comment.