Skip to content

Commit 6f6a47c

Browse files
Merge branch 'master' into add-debug-drop-monitor-table
2 parents 88f8e73 + 1484a85 commit 6f6a47c

File tree

16 files changed

+344
-169
lines changed

16 files changed

+344
-169
lines changed

.azure-pipelines/build-template.yml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,33 @@ jobs:
8484
patterns: |
8585
target/debs/${{ parameters.debian_version }}/libyang-*_1.0*.deb
8686
target/debs/${{ parameters.debian_version }}/libyang_1.0*.deb
87+
target/debs/${{ parameters.debian_version }}/libyang-cpp_*.deb
88+
target/debs/${{ parameters.debian_version }}/python3-yang_*.deb
8789
displayName: "Download libyang from ${{ parameters.arch }} common lib"
8890
- script: |
8991
set -ex
9092
sudo dpkg -i $(find ./download -name *.deb)
9193
workingDirectory: $(Build.ArtifactStagingDirectory)
9294
displayName: "Install libyang from common lib"
95+
- task: DownloadPipelineArtifact@2
96+
inputs:
97+
source: specific
98+
project: build
99+
pipeline: 142
100+
artifact: sonic-buildimage.vs
101+
runVersion: 'latestFromBranch'
102+
runBranch: 'refs/heads/$(BUILD_BRANCH)'
103+
path: $(Build.ArtifactStagingDirectory)/download
104+
patterns: |
105+
target/python-wheels/${{ parameters.debian_version }}/sonic_yang_mgmt-1.0-py3-none-any.whl
106+
target/python-wheels/${{ parameters.debian_version }}/sonic_yang_models-1.0-py3-none-any.whl
107+
displayName: "Download yang wheel from latest sonic-buildimage build"
108+
- script: |
109+
set -ex
110+
sudo pip3 install ./download/target/python-wheels/${{ parameters.debian_version }}/sonic_yang_mgmt-1.0-py3-none-any.whl \
111+
./download/target/python-wheels/${{ parameters.debian_version }}/sonic_yang_models-1.0-py3-none-any.whl
112+
workingDirectory: $(Build.ArtifactStagingDirectory)
113+
displayName: "Install yang wheel from common lib"
93114
- script: |
94115
set -ex
95116
rm ../*.deb || true
@@ -115,7 +136,7 @@ jobs:
115136
sudo sed -ri 's/^unixsocketperm .../unixsocketperm 777/' /etc/redis/redis.conf
116137
sudo sed -ri 's/redis-server.sock/redis.sock/' /etc/redis/redis.conf
117138
sudo service redis-server restart
118-
sudo mkdir /usr/local/yang-models
139+
sudo mkdir -p /usr/local/yang-models
119140
120141
./tests/tests
121142
redis-cli FLUSHALL

.azure-pipelines/test-docker-sonic-vs-template.yml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,21 @@ jobs:
3939
artifact: sonic-swss-common.amd64.ubuntu22_04
4040
path: $(Build.ArtifactStagingDirectory)/download
4141
displayName: "Download pre-stage built sonic-swss-common.amd64.ubuntu22_04"
42+
- task: DownloadPipelineArtifact@2
43+
inputs:
44+
source: specific
45+
project: build
46+
pipeline: Azure.sonic-buildimage.common_libs
47+
runVersion: 'latestFromBranch'
48+
runBranch: 'refs/heads/$(BUILD_BRANCH)'
49+
path: $(Build.ArtifactStagingDirectory)/download
50+
artifact: common-lib
51+
patterns: |
52+
target/debs/bookworm/libyang-*_1.0*.deb
53+
target/debs/bookworm/libyang_1.0*.deb
54+
target/debs/bookworm/libyang-cpp_*.deb
55+
target/debs/bookworm/python3-yang_*.deb
56+
displayName: "Download libyang from common lib"
4257
- task: DownloadPipelineArtifact@2
4358
inputs:
4459
source: specific
@@ -69,14 +84,20 @@ jobs:
6984
libboost1.74-dev \
7085
libboost-dev \
7186
libhiredis0.14 \
72-
libyang-dev \
87+
libpcre3-dev \
7388
uuid-dev \
7489
net-tools \
7590
bridge-utils \
7691
vlan
7792
7893
sudo sonic-swss-common/.azure-pipelines/build_and_install_module.sh
7994
95+
# Install libyang packages from downloaded artifacts
96+
sudo dpkg -i $(Build.ArtifactStagingDirectory)/download/target/debs/bookworm/libyang-*_1.0*.deb \
97+
$(Build.ArtifactStagingDirectory)/download/target/debs/bookworm/libyang_1.0*.deb \
98+
$(Build.ArtifactStagingDirectory)/download/target/debs/bookworm/libyang-cpp_*.deb \
99+
$(Build.ArtifactStagingDirectory)/download/target/debs/bookworm/python3-yang_*.deb
100+
80101
sudo dpkg -i $(Build.ArtifactStagingDirectory)/download/libprotobuf*_amd64.deb $(Build.ArtifactStagingDirectory)/download/libprotobuf-lite*_amd64.deb $(Build.ArtifactStagingDirectory)/download/python3-protobuf*_amd64.deb
81102
sudo dpkg -i $(Build.ArtifactStagingDirectory)/download/libdashapi*.deb
82103
sudo dpkg -i --force-confask,confnew $(Build.ArtifactStagingDirectory)/download/libswsscommon_1.0.0_amd64.deb || apt-get install -f

azure-pipelines.yml

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,25 @@ stages:
7777
https://github.com/bazelbuild/bazelisk/releases/latest/download/bazelisk-linux-${ARCH}
7878
sudo chmod 755 /usr/local/bin/bazel
7979
displayName: "Install dependencies"
80+
- task: DownloadPipelineArtifact@2
81+
inputs:
82+
source: specific
83+
project: build
84+
pipeline: 142
85+
artifact: sonic-buildimage.vs
86+
runVersion: 'latestFromBranch'
87+
runBranch: 'refs/heads/$(BUILD_BRANCH)'
88+
path: $(Build.ArtifactStagingDirectory)/download
89+
patterns: |
90+
target/python-wheels/${{ parameters.debian_version }}/sonic_yang_mgmt-1.0-py3-none-any.whl
91+
target/python-wheels/${{ parameters.debian_version }}/sonic_yang_models-1.0-py3-none-any.whl
92+
displayName: "Download yang wheel from latest sonic-buildimage build"
93+
- script: |
94+
set -ex
95+
sudo pip3 install ./download/target/python-wheels/${{ parameters.debian_version }}/sonic_yang_mgmt-1.0-py3-none-any.whl \
96+
./download/target/python-wheels/${{ parameters.debian_version }}/sonic_yang_models-1.0-py3-none-any.whl
97+
workingDirectory: $(Build.ArtifactStagingDirectory)
98+
displayName: "Install yang wheel"
8099
- script: |
81100
./autogen.sh
82101
dpkg-buildpackage -rfakeroot -us -uc -b -j$(nproc) && cp ../*.deb .
@@ -105,14 +124,56 @@ stages:
105124
sudo apt-get install -y python3-pip
106125
sudo pip3 install pytest
107126
sudo apt-get install -y python
108-
sudo apt-get install cmake libgtest-dev libgmock-dev libyang-dev
127+
sudo apt-get install cmake libgtest-dev libgmock-dev
109128
cd /usr/src/gtest && sudo cmake . && sudo make
110129
ARCH=$(dpkg --print-architecture)
111130
set -x
112131
sudo curl -fsSL -o /usr/local/bin/bazel \
113132
https://github.com/bazelbuild/bazelisk/releases/latest/download/bazelisk-linux-${ARCH}
114133
sudo chmod 755 /usr/local/bin/bazel
115134
displayName: "Install dependencies"
135+
- task: DownloadPipelineArtifact@2
136+
inputs:
137+
source: specific
138+
project: build
139+
pipeline: Azure.sonic-buildimage.common_libs
140+
runVersion: 'latestFromBranch'
141+
runBranch: 'refs/heads/$(BUILD_BRANCH)'
142+
path: $(Build.ArtifactStagingDirectory)/download
143+
artifact: common-lib
144+
patterns: |
145+
target/debs/${{ parameters.debian_version }}/libyang-*_1.0*.deb
146+
target/debs/${{ parameters.debian_version }}/libyang_1.0*.deb
147+
target/debs/${{ parameters.debian_version }}/libyang-cpp_*.deb
148+
target/debs/${{ parameters.debian_version }}/python3-yang_*.deb
149+
displayName: "Download yang deb from amd64 common lib"
150+
- script: |
151+
set -ex
152+
sudo dpkg -i $(Build.ArtifactStagingDirectory)/download/target/debs/${{ parameters.debian_version }}/libyang_1.0*.deb \
153+
$(Build.ArtifactStagingDirectory)/download/target/debs/${{ parameters.debian_version }}/libyang-*_1.0*.deb \
154+
$(Build.ArtifactStagingDirectory)/download/target/debs/${{ parameters.debian_version }}/libyang-cpp_*.deb \
155+
$(Build.ArtifactStagingDirectory)/download/target/debs/${{ parameters.debian_version }}/python3-yang_*.deb
156+
workingDirectory: $(Build.ArtifactStagingDirectory)
157+
displayName: "Install yang deb from common lib"
158+
- task: DownloadPipelineArtifact@2
159+
inputs:
160+
source: specific
161+
project: build
162+
pipeline: 142
163+
artifact: sonic-buildimage.vs
164+
runVersion: 'latestFromBranch'
165+
runBranch: 'refs/heads/$(BUILD_BRANCH)'
166+
path: $(Build.ArtifactStagingDirectory)/download
167+
patterns: |
168+
target/python-wheels/${{ parameters.debian_version }}/sonic_yang_mgmt-1.0-py3-none-any.whl
169+
target/python-wheels/${{ parameters.debian_version }}/sonic_yang_models-1.0-py3-none-any.whl
170+
displayName: "Download yang wheel from latest sonic-buildimage build"
171+
- script: |
172+
set -ex
173+
sudo pip3 install ./download/target/python-wheels/${{ parameters.debian_version }}/sonic_yang_mgmt-1.0-py3-none-any.whl \
174+
./download/target/python-wheels/${{ parameters.debian_version }}/sonic_yang_models-1.0-py3-none-any.whl
175+
workingDirectory: $(Build.ArtifactStagingDirectory)
176+
displayName: "Install yang wheel"
116177
- script: |
117178
./autogen.sh
118179
dpkg-buildpackage -rfakeroot -us -uc -Pnopython2 -b -j$(nproc) && cp ../*.deb .

common/Makefile.am

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
lib_LTLIBRARIES += common/libswsscommon.la
32

43
dist_swss_DATA = \
@@ -17,6 +16,34 @@ swsscommondir = /var/run/redis/sonic-db
1716

1817
bin_PROGRAMS += common/swssloglevel
1918

19+
# Generate cfg_schema.h before building the library
20+
BUILT_SOURCES = common/cfg_schema.h
21+
22+
if YANGMODS
23+
# Generate schema dynamically when yang modules are enabled
24+
common/cfg_schema.h: FORCE
25+
$(AM_V_GEN)$(PYTHON) $(srcdir)/gen_cfg_schema.py -o $@
26+
else
27+
# Generate minimal static schema when yang modules are disabled
28+
common/cfg_schema.h: FORCE
29+
$(AM_V_GEN)echo '#ifndef CFG_SCHEMA_H' > $@; \
30+
echo '#define CFG_SCHEMA_H' >> $@; \
31+
echo '' >> $@; \
32+
echo '// Minimal cfg_schema.h generated when YANG modules are disabled' >> $@; \
33+
echo '#ifdef __cplusplus' >> $@; \
34+
echo 'namespace swss {' >> $@; \
35+
echo '#endif' >> $@; \
36+
echo '' >> $@; \
37+
echo '#ifdef __cplusplus' >> $@; \
38+
echo '}' >> $@; \
39+
echo '#endif' >> $@; \
40+
echo '#endif' >> $@
41+
endif
42+
43+
# FORCE target to ensure cfg_schema.h is always regenerated
44+
.PHONY: FORCE
45+
FORCE:
46+
2047
common_libswsscommon_la_SOURCES = \
2148
common/events_common.cpp \
2249
common/events_service.cpp \

common/c-api/dbconnector.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ SWSSResult SWSSSonicDBConfig_initialize(const char *path) {
1313
SWSSTry(SonicDBConfig::initialize(path));
1414
}
1515

16-
SWSSResult SWSSSonicDBConfig_initializeGlobalConfig(const char *path) {
17-
SWSSTry(SonicDBConfig::initializeGlobalConfig(path));
16+
SWSSResult SWSSSonicDBConfig_initializeGlobalConfig(const char *path, uint8_t ignore_nonexistent) {
17+
SWSSTry(SonicDBConfig::initializeGlobalConfig(path, ignore_nonexistent));
1818
}
1919

2020
SWSSResult SWSSDBConnector_new_tcp(int32_t dbId, const char *hostname, uint16_t port,

common/c-api/dbconnector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ extern "C" {
1212

1313
SWSSResult SWSSSonicDBConfig_initialize(const char *path);
1414

15-
SWSSResult SWSSSonicDBConfig_initializeGlobalConfig(const char *path);
15+
SWSSResult SWSSSonicDBConfig_initializeGlobalConfig(const char *path, uint8_t ignore_nonexistent);
1616

1717
typedef struct SWSSDBConnectorOpaque *SWSSDBConnector;
1818

common/dbconnector.cpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <fstream>
88
#include <nlohmann/json.hpp>
99
#include <set>
10+
#include <unistd.h>
1011
#include "logger.h"
1112

1213
#include "common/dbconnector.h"
@@ -22,8 +23,14 @@ using namespace swss;
2223
void SonicDBConfig::parseDatabaseConfig(const string &file,
2324
std::map<std::string, RedisInstInfo> &inst_entry,
2425
std::unordered_map<std::string, SonicDBInfo> &db_entry,
25-
std::unordered_map<int, std::string> &separator_entry)
26+
std::unordered_map<int, std::string> &separator_entry,
27+
bool ignore_nonexistent)
2628
{
29+
if (ignore_nonexistent && access(file.c_str(), F_OK) == -1) {
30+
SWSS_LOG_NOTICE("Sonic database config file doesn't exist at %s\n", file.c_str());
31+
return;
32+
}
33+
2734
ifstream i(file);
2835
if (i.good())
2936
{
@@ -75,7 +82,7 @@ void SonicDBConfig::parseDatabaseConfig(const string &file,
7582
}
7683
}
7784

78-
void SonicDBConfig::initializeGlobalConfig(const string &file)
85+
void SonicDBConfig::initializeGlobalConfig(const string &file, bool ignore_nonexistent)
7986
{
8087
std::string dir_name;
8188
std::lock_guard<std::recursive_mutex> guard(m_db_info_mutex);
@@ -128,10 +135,16 @@ void SonicDBConfig::initializeGlobalConfig(const string &file)
128135
continue;
129136
}
130137

131-
parseDatabaseConfig(local_file, inst_entry, db_entry, separator_entry);
132-
m_inst_info[key] = inst_entry;
133-
m_db_info[key] = db_entry;
134-
m_db_separator[key] = separator_entry;
138+
parseDatabaseConfig(local_file, inst_entry, db_entry, separator_entry, ignore_nonexistent);
139+
// all the entries are empty, then don't add them to the map. It may happen if the included
140+
// config doesn't exist. For example, dash-ha container will only mount the redis instance
141+
// config file for the dpu it is managing.
142+
if (!inst_entry.empty() || !db_entry.empty() || !separator_entry.empty())
143+
{
144+
m_inst_info[key] = inst_entry;
145+
m_db_info[key] = db_entry;
146+
m_db_separator[key] = separator_entry;
147+
}
135148

136149
if(key.isEmpty())
137150
{

common/dbconnector.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ struct SonicDBKey
4545
* In our design, we allow multiple containers to share a same namespace.
4646
* So, this combination of container name and namespace is used to uniquely identify a DB instance.
4747
* If the namespace is empty, it means the DB instance is running in the default(host) namespace.
48-
* If the container name is empty, it for adapting the old design that only one DB instance is
48+
* If the container name is empty, it for adapting the old design that only one DB instance is
4949
* running in a namespace.
5050
*/
5151
std::string containerName;
@@ -99,13 +99,13 @@ class SonicDBConfig
9999
%}
100100
#endif
101101

102-
static void initializeGlobalConfig(const std::string &file = DEFAULT_SONIC_DB_GLOBAL_CONFIG_FILE);
102+
static void initializeGlobalConfig(const std::string &file = DEFAULT_SONIC_DB_GLOBAL_CONFIG_FILE, bool ignore_nonexistent = false);
103103
#if defined(SWIG) && defined(SWIGPYTHON)
104104
%pythoncode %{
105105
## TODO: the python function and C++ one is not on-par
106106
@staticmethod
107-
def load_sonic_global_db_config(global_db_file_path=DEFAULT_SONIC_DB_GLOBAL_CONFIG_FILE, namespace=None):
108-
SonicDBConfig.initializeGlobalConfig(global_db_file_path)
107+
def load_sonic_global_db_config(global_db_file_path=DEFAULT_SONIC_DB_GLOBAL_CONFIG_FILE, namespace=None, ignore_nonexistent=False):
108+
SonicDBConfig.initializeGlobalConfig(global_db_file_path, ignore_nonexistent)
109109
%}
110110
#endif
111111
static void reset();
@@ -157,7 +157,8 @@ class SonicDBConfig
157157
static void parseDatabaseConfig(const std::string &file,
158158
std::map<std::string, RedisInstInfo> &inst_entry,
159159
std::unordered_map<std::string, SonicDBInfo> &db_entry,
160-
std::unordered_map<int, std::string> &separator_entry);
160+
std::unordered_map<int, std::string> &separator_entry,
161+
bool ignore_nonexistent = false);
161162
static RedisInstInfo& getRedisInfo(const std::string &dbName, const SonicDBKey &key);
162163
static SonicDBInfo& getDbInfo(const std::string &dbName, const SonicDBKey &key);
163164
};

0 commit comments

Comments
 (0)