Skip to content

Commit

Permalink
Merge branch 'master' into front_panel_port_name_regex
Browse files Browse the repository at this point in the history
  • Loading branch information
itamar-talmon authored Jan 12, 2023
2 parents aed191b + c7411ff commit 5a065c2
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 152 deletions.
4 changes: 4 additions & 0 deletions .github/codeql/codeql-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name: "CodeQL config"
queries:
- uses: security-and-quality
- uses: security-extended
43 changes: 43 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# For more infomation, please visit: https://github.com/github/codeql-action

name: "CodeQL"

on:
push:
branches:
- 'master'
- '202[0-9][0-9][0-9]'
pull_request_target:
branches:
- 'master'
- '202[0-9][0-9][0-9]'

jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write

strategy:
fail-fast: false
matrix:
language: [ 'python' ]

steps:
- name: Checkout repository
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
config-file: ./.github/codeql/codeql-config.yml
languages: ${{ matrix.language }}

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
with:
category: "/language:${{matrix.language}}"
20 changes: 19 additions & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,31 @@ pr:
- master

stages:
- ${{ if eq(variables['Build.Reason'], 'PullRequest') }}:
- stage: Analysis
dependsOn: []
jobs:
- job:
displayName: "Semgrep"
pool:
vmImage: ubuntu-latest
steps:
- script: |
set -ex
target_branch=origin/$(System.PullRequest.TargetBranch)
files_changed=$(git --no-pager diff $target_branch..HEAD --name-only --diff-filter=d)
python -m pip install --upgrade pip
pip install semgrep
semgrep --config "p/default" --error $files_changed
displayName: 'Run Semgrep'
- stage: Build
jobs:
- job:
displayName: "build"
timeoutInMinutes: 60
variables:
DIFF_COVER_CHECK_THRESHOLD: 50
DIFF_COVER_CHECK_THRESHOLD: 80
DIFF_COVER_ENABLE: 'true'
pool:
vmImage: ubuntu-20.04
Expand Down
14 changes: 7 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@
'hiredis>=0.1.4'
]

console_scripts={
'sonic-db-load = swsssdk:sonic_db_dump_load',
'sonic-db-dump = swsssdk:sonic_db_dump_load',
}

setup(
name='swsssdk',
version='2.0.1',
package_dir={'swsssdk': 'src/swsssdk'},
packages=['swsssdk'],
package_data={'swsssdk': ['config/*.json']},
scripts=['src/swsssdk/scripts/sonic-db-cli'],
scripts=[],
license='Apache 2.0',
author='SONiC Team',
author_email='linuxnetdev@microsoft.com',
Expand All @@ -26,12 +31,7 @@
extras_require={
'high_perf': high_performance_deps
},
entry_points={
'console_scripts': [
'sonic-db-load = swsssdk:sonic_db_dump_load',
'sonic-db-dump = swsssdk:sonic_db_dump_load',
],
},
entry_points={},
classifiers=[
'Intended Audience :: Developers',
'Operating System :: Linux',
Expand Down
8 changes: 8 additions & 0 deletions src/swsssdk/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
"""
Utility library for Switch-state Redis database access and syslog reporting.
"""
import sys
import logging

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
logger.addHandler(logging.NullHandler())

if ('unittest' not in sys.modules.keys() and
'mockredis' not in sys.modules.keys() and
'mock' not in sys.modules.keys()):
msg = "sonic-py-swsssdk been deprecated, please switch to sonic-swss-common."
logger.exception(msg)
raise ImportError("sonic-py-swsssdk been deprecated, please switch to sonic-swss-common.")

try:
from .dbconnector import SonicDBConfig, SonicV2Connector
from .configdb import ConfigDBConnector, ConfigDBPipeConnector
Expand Down
5 changes: 0 additions & 5 deletions src/swsssdk/config/database_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@
"separator": ":",
"instance" : "redis"
},
"LOGLEVEL_DB" : {
"id" : 3,
"separator": ":",
"instance" : "redis"
},
"CONFIG_DB" : {
"id" : 4,
"separator": "|",
Expand Down
2 changes: 1 addition & 1 deletion src/swsssdk/dbconnector.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def __init__(self, use_unix_socket_path=False, namespace=None, decode_responses=
kwargs['decode_responses'] = True

self.dbintf = DBInterface(**kwargs)
self.use_unix_socket_path = use_unix_socket_path
self.use_unix_socket_path = True if use_unix_socket_path and os.getuid() == 0 else False

"""If the user don't give the namespace as input, it refers to the local namespace
where this application is run. (It could be a network namespace or linux host namesapce)
Expand Down
131 changes: 0 additions & 131 deletions src/swsssdk/scripts/sonic-db-cli

This file was deleted.

2 changes: 1 addition & 1 deletion src/swsssdk/sonic_db_dump_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def do_load(options, args):
parser.add_option('-A', '--use-expireat', help='use EXPIREAT rather than TTL/EXPIRE', action='store_true')
else:
parser.add_option('-l', '--load', help='load data into redis (default is to dump data from redis)', action='store_true')
parser.add_option('-n', '--dbname', help='dump DATABASE (APPL_DB/ASIC_DB/COUNTERS_DB/LOGLEVEL_DB/CONFIG_DB...)')
parser.add_option('-n', '--dbname', help='dump DATABASE (APPL_DB/ASIC_DB/COUNTERS_DB/CONFIG_DB...)')
parser.add_option('-t', '--conntype', help='indicate redis connection type (tcp[default] or unix_socket)', default='tcp')
parser.add_option('-k', '--keys', help='dump only keys matching specified glob-style pattern')
parser.add_option('-o', '--output', help='write to OUTPUT instead of stdout (dump mode only)')
Expand Down
5 changes: 0 additions & 5 deletions test/config/database_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@
"separator": ":",
"instance" : "redis"
},
"LOGLEVEL_DB" : {
"id" : 3,
"separator": ":",
"instance" : "redis"
},
"CONFIG_DB" : {
"id" : 4,
"separator": "|",
Expand Down
18 changes: 17 additions & 1 deletion test/test_moduleLoad.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
sys.path.insert(0, os.path.join(modules_path, 'src'))

from unittest import TestCase

import subprocess

class Test_load_sonic_db_config(TestCase):
def test__db_map_attributes(self):
Expand Down Expand Up @@ -34,3 +34,19 @@ def test__dbConfig(self):
for namespace in list(dbConfig.get_ns_list()):
self.assertEqual(dbConfig.get_dbid('PFC_WD_DB', namespace), 5)
self.assertEqual(dbConfig.get_dbid('APPL_DB', namespace), 0)

def test_BlockUseSwsssdk():
# Import swsssdk will throw exception with deprecated message.
swsssdk_path = os.path.join(modules_path, 'src')
result = None
python_command = "python"

if sys.version_info.major == 3:
python_command = "python3"

try:
subprocess.check_output([python_command, "-c", "import swsssdk;exit()"], stderr=subprocess.STDOUT, cwd=swsssdk_path)
except subprocess.CalledProcessError as e:
result = e.output.decode("utf-8")

assert "deprecated" in result

0 comments on commit 5a065c2

Please sign in to comment.