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

Support azure pipelines diff coverage #112

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 20 additions & 4 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ stages:
clean: true
submodules: recursive
displayName: 'Checkout code'
- script: |
set -x
wget https://packages.microsoft.com/config/debian/10/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
sudo apt-get update
sudo apt-get install -y dotnet-sdk-5.0
sudo pip3 install pytest pytest-azurepipelines
sudo pip3 install pytest-cov
displayName: "Install build tools"
- script: |
set -ex

Expand All @@ -41,21 +50,28 @@ stages:
set -ex

sudo python3 -m pip install dist/swsssdk-2.0.1-py3-none-any.whl
python3 setup.py test
python3 -m pytest --doctest-modules --junitxml=junit/test-results.xml --cov=. --cov-report=xml
displayName: "Unit tests"
- script: |
sudo pip3 install diff-cover
target_branch=$(System.PullRequest.TargetBranch)
compare_branch=origin/${target_branch#refs/heads/}
diff-cover coverage.xml --compare-branch=$compare_branch
condition: eq(variables['Build.Reason'], 'PullRequest')
displayName: "Diff coverage"
- publish: $(Build.ArtifactStagingDirectory)
artifact: sonic-py-swsssdk
displayName: "Archive artifacts"
- task: PublishTestResults@2
inputs:
testResultsFiles: '$(System.DefaultWorkingDirectory)/test-results.xml'
testResultsFiles: '**/test-*.xml'
testRunTitle: Python 3
failTaskOnFailedTests: true
condition: succeededOrFailed()
displayName: 'Publish Python 3 test results'
- task: PublishCodeCoverageResults@1
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: '$(System.DefaultWorkingDirectory)/coverage.xml'
reportDirectory: '$(System.DefaultWorkingDirectory)/htmlcov/'
summaryFileLocation: '$(System.DefaultWorkingDirectory)/**/coverage.xml'
additionalCodeCoverageFiles: '$(System.DefaultWorkingDirectory)/**/*.coverage'
displayName: 'Publish Python 3 test coverage'
1 change: 1 addition & 0 deletions src/swsssdk/configdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def __init__(self, decode_responses=True, **kwargs):
self.TABLE_NAME_SEPARATOR = '|'
self.KEY_SEPARATOR = '|'
self.handlers = {}
self.test_cover = ''

def __wait_for_db_init(self):
client = self.get_redis_client(self.db_name)
Expand Down
4 changes: 4 additions & 0 deletions src/swsssdk/dbconnector.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ def load_sonic_global_db_config(global_db_file_path=SONIC_DB_GLOBAL_CONFIG_FILE,

if os.path.isfile(global_db_file_path):
global_db_config_dir = os.path.dirname(global_db_file_path)
if global_db_file_path is None:
global_db_file_path = None
with open(global_db_file_path, "r") as read_file:
all_ns_dbs = json.load(read_file)
for entry in all_ns_dbs['INCLUDES']:
Expand Down Expand Up @@ -209,6 +211,8 @@ def get_socket(db_name, namespace=None):
@staticmethod
def get_hostname(db_name, namespace=None):
namespace = SonicDBConfig.EMPTY_NAMESPACE(namespace)
if namespace == None:
namespace = None
if not SonicDBConfig._sonic_db_config_init:
SonicDBConfig.load_sonic_db_config()
return SonicDBConfig.get_instance(db_name, namespace)["hostname"]
Expand Down