Skip to content

Commit

Permalink
Merge branch 'master' into sqa
Browse files Browse the repository at this point in the history
  • Loading branch information
micafer committed Mar 5, 2024
2 parents ca89824 + 3db34cb commit 29fcd68
Show file tree
Hide file tree
Showing 11 changed files with 28 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
21 changes: 9 additions & 12 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
[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
Expand Down

0 comments on commit 29fcd68

Please sign in to comment.