diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 05e646d..aef2862 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -1,22 +1,33 @@ -name: 'coverage' +# This workflow will install dependencies, create coverage tests and run Pytest Coverage Comment +# For more information see: https://github.com/MishaKav/pytest-coverage-comment/ +name: pytest-coverage-comment on: - pull_request: - workflow_dispatch: + pull_request: + branches: + - '*' +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Python 3.11 + uses: actions/setup-python@v2 + with: + python-version: 3.11 -jobs: - coverage: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4.1.1 - - name: Install coverage - run: pip install coverage + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install flake8 pytest pytest-cov + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - - name: Run Coverage - run: cd simple_vm_client && coverage xml coverage.xml + - name: Build coverage file + run: | + pytest --junitxml=pytest.xml --cov-report=term-missing:skip-covered --cov=simple_vm_client | tee pytest-coverage.txt - - name: Get Cover - uses: orgoro/coverage@v3.1 - with: - coverageFile: simple_vm_client/coverage.xml - token: ${{ secrets.GITHUB_TOKEN }} + - name: Pytest coverage comment + uses: MishaKav/pytest-coverage-comment@main + with: + pytest-coverage-path: ./pytest-coverage.txt + junitxml-path: ./pytest.xml diff --git a/simple_vm_client/VirtualMachineHandler.py b/simple_vm_client/VirtualMachineHandler.py index 547fd58..4920a92 100644 --- a/simple_vm_client/VirtualMachineHandler.py +++ b/simple_vm_client/VirtualMachineHandler.py @@ -7,12 +7,13 @@ from typing import TYPE_CHECKING -from bibigrid_connector.bibigrid_connector import BibigridConnector -from forc_connector.forc_connector import ForcConnector -from openstack_connector.openstack_connector import OpenStackConnector -from util import thrift_converter -from util.logger import setup_custom_logger -from VirtualMachineService import Iface +from simple_vm_client.bibigrid_connector.bibigrid_connector import BibigridConnector +from simple_vm_client.forc_connector.forc_connector import ForcConnector +from simple_vm_client.openstack_connector.openstack_connector import OpenStackConnector +from simple_vm_client.util import thrift_converter +from simple_vm_client.util.logger import setup_custom_logger + +from .VirtualMachineService import Iface if TYPE_CHECKING: from ttypes import ( diff --git a/simple_vm_client/VirtualMachineServer.py b/simple_vm_client/VirtualMachineServer.py index 1c57ff6..c797e2e 100644 --- a/simple_vm_client/VirtualMachineServer.py +++ b/simple_vm_client/VirtualMachineServer.py @@ -8,8 +8,9 @@ from thrift.protocol import TBinaryProtocol from thrift.server import TServer from thrift.transport import TSocket, TSSLSocket, TTransport -from VirtualMachineHandler import VirtualMachineHandler -from VirtualMachineService import Processor + +from simple_vm_client.VirtualMachineHandler import VirtualMachineHandler +from simple_vm_client.VirtualMachineService import Processor USERNAME = "OS_USERNAME" PASSWORD = "OS_PASSWORD" diff --git a/simple_vm_client/VirtualMachineService.py b/simple_vm_client/VirtualMachineService.py index 461f7e0..2ad7457 100644 --- a/simple_vm_client/VirtualMachineService.py +++ b/simple_vm_client/VirtualMachineService.py @@ -12,7 +12,8 @@ from thrift.Thrift import TApplicationException, TMessageType, TProcessor, TType from thrift.transport import TTransport from thrift.TRecursive import fix_spec -from ttypes import * + +from simple_vm_client.ttypes import * all_structs = [] diff --git a/simple_vm_client/bibigrid_connector/bibigrid_connector.py b/simple_vm_client/bibigrid_connector/bibigrid_connector.py index 24417ed..5c0d8d9 100644 --- a/simple_vm_client/bibigrid_connector/bibigrid_connector.py +++ b/simple_vm_client/bibigrid_connector/bibigrid_connector.py @@ -1,7 +1,8 @@ import requests import yaml -from ttypes import ClusterInfo, ClusterInstance -from util.logger import setup_custom_logger + +from simple_vm_client.ttypes import ClusterInfo, ClusterInstance +from simple_vm_client.util.logger import setup_custom_logger logger = setup_custom_logger(__name__) diff --git a/simple_vm_client/constants.py b/simple_vm_client/constants.py index 6a03e2f..50f402c 100644 --- a/simple_vm_client/constants.py +++ b/simple_vm_client/constants.py @@ -6,10 +6,5 @@ # options string: py # -from thrift.Thrift import TType, TMessageType, TFrozenDict, TException, TApplicationException -from thrift.protocol.TProtocol import TProtocolException -from thrift.TRecursive import fix_spec -import sys -from ttypes import * VERSION = "1.0.0" diff --git a/simple_vm_client/forc_connector/forc_connector.py b/simple_vm_client/forc_connector/forc_connector.py index 1873cb8..78e035e 100644 --- a/simple_vm_client/forc_connector/forc_connector.py +++ b/simple_vm_client/forc_connector/forc_connector.py @@ -7,7 +7,8 @@ import requests import yaml from openstack.compute.v2.server import Server -from ttypes import ( + +from simple_vm_client.ttypes import ( Backend, BackendNotFoundException, CondaPackage, @@ -16,8 +17,8 @@ PlaybookResult, TemplateNotFoundException, ) -from util.logger import setup_custom_logger -from util.state_enums import VmTaskStates +from simple_vm_client.util.logger import setup_custom_logger +from simple_vm_client.util.state_enums import VmTaskStates from .playbook.playbook import Playbook from .template.template import ResearchEnvironmentMetadata, Template diff --git a/simple_vm_client/forc_connector/playbook/playbook.py b/simple_vm_client/forc_connector/playbook/playbook.py index 0852e95..e2f3fe4 100644 --- a/simple_vm_client/forc_connector/playbook/playbook.py +++ b/simple_vm_client/forc_connector/playbook/playbook.py @@ -6,9 +6,10 @@ import redis import ruamel.yaml -from ttypes import CondaPackage -from util.logger import setup_custom_logger -from util.state_enums import VmTaskStates + +from simple_vm_client.ttypes import CondaPackage +from simple_vm_client.util.logger import setup_custom_logger +from simple_vm_client.util.state_enums import VmTaskStates CONDA = "conda" MOSH = "mosh" diff --git a/simple_vm_client/util/thrift_converter.py b/simple_vm_client/util/thrift_converter.py index 98ca070..5b03259 100644 --- a/simple_vm_client/util/thrift_converter.py +++ b/simple_vm_client/util/thrift_converter.py @@ -7,9 +7,10 @@ from openstack.compute.v2.flavor import Flavor as OpenStack_Flavor from openstack.compute.v2.image import Image as OpenStack_Image from openstack.compute.v2.server import Server as OpenStack_Server -from ttypes import VM, Flavor, Image, Snapshot, Volume -from util.logger import setup_custom_logger -from util.state_enums import VmStates + +from simple_vm_client.ttypes import VM, Flavor, Image, Snapshot, Volume +from simple_vm_client.util.logger import setup_custom_logger +from simple_vm_client.util.state_enums import VmStates logger = setup_custom_logger(__name__) @@ -110,7 +111,6 @@ def os_to_thrift_server(openstack_server: OpenStack_Server) -> VM: image = None for values in openstack_server.addresses.values(): for address in values: - if address["OS-EXT-IPS:type"] == "floating": floating_ip = address["addr"] elif address["OS-EXT-IPS:type"] == "fixed":