forked from sonic-net/sonic-buildimage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sonic-host-services and sonic-host-services-data packages (sonic-…
…net#5694) **- Why I did it** Install all host services and their data files in package format rather than file-by-file **- How I did it** - Create sonic-host-services Python wheel package, currently including procdockerstatsd - Also add the framework for unit tests by adding one simple procdockerstatsd test case - Create sonic-host-services-data Debian package which is responsible for installing the related systemd unit files to control the services in the Python wheel. This package will also be responsible for installing any Jinja2 templates and other data files needed by the host services.
- Loading branch information
1 parent
2b38225
commit 0f7b68d
Showing
25 changed files
with
247 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
SPATH := $($(SONIC_HOST_SERVICES_DATA)_SRC_PATH) | ||
DEP_FILES := $(SONIC_COMMON_FILES_LIST) rules/sonic-host-services-data.mk rules/sonic-host-services-data.dep | ||
DEP_FILES += $(SONIC_COMMON_BASE_FILES_LIST) | ||
DEP_FILES += $(shell git ls-files $(SPATH)) | ||
|
||
$(SONIC_HOST_SERVICES_DATA)_CACHE_MODE := GIT_CONTENT_SHA | ||
$(SONIC_HOST_SERVICES_DATA)_DEP_FLAGS := $(SONIC_COMMON_FLAGS_LIST) | ||
$(SONIC_HOST_SERVICES_DATA)_DEP_FILES := $(DEP_FILES) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# SONiC host services data package | ||
|
||
SONIC_HOST_SERVICES_DATA = sonic-host-services-data_1.0-1_all.deb | ||
$(SONIC_HOST_SERVICES_DATA)_SRC_PATH = $(SRC_PATH)/sonic-host-services-data | ||
SONIC_DPKG_DEBS += $(SONIC_HOST_SERVICES_DATA) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
SPATH := $($(SONIC_HOST_SERVICES_PY3)_SRC_PATH) | ||
DEP_FILES := $(SONIC_COMMON_FILES_LIST) rules/sonic-host-services.mk rules/sonic-host-services.dep | ||
DEP_FILES += $(SONIC_COMMON_BASE_FILES_LIST) | ||
SMDEP_FILES := $(addprefix $(SPATH)/,$(shell cd $(SPATH) && git ls-files)) | ||
|
||
$(SONIC_HOST_SERVICES_PY3)_CACHE_MODE := GIT_CONTENT_SHA | ||
$(SONIC_HOST_SERVICES_PY3)_DEP_FLAGS := $(SONIC_COMMON_FLAGS_LIST) | ||
$(SONIC_HOST_SERVICES_PY3)_DEP_FILES := $(DEP_FILES) | ||
$(SONIC_HOST_SERVICES_PY3)_SMDEP_FILES := $(SMDEP_FILES) | ||
$(SONIC_HOST_SERVICES_PY3)_SMDEP_PATHS := $(SPATH) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# SONiC host services package | ||
|
||
SONIC_HOST_SERVICES_PY3 = sonic_host_services-1.0-py3-none-any.whl | ||
$(SONIC_HOST_SERVICES_PY3)_SRC_PATH = $(SRC_PATH)/sonic-host-services | ||
$(SONIC_HOST_SERVICES_PY3)_PYTHON_VERSION = 3 | ||
$(SONIC_HOST_SERVICES_PY3)_DEPENDS += $(SONIC_PY_COMMON_PY3) \ | ||
$(SWSSSDK_PY3) | ||
SONIC_PYTHON_WHEELS += $(SONIC_HOST_SERVICES_PY3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
debian/*.debhelper | ||
debian/debhelper-build-stamp | ||
debian/sonic-host-services-data/ | ||
sonic-host-services-data_*.buildinfo | ||
sonic-host-services-data_*.changes | ||
sonic-host-services-data_*.deb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Copyright (C) 2020 Microsoft | ||
|
||
This program is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU General Public License | ||
as published by the Free Software Foundation; either version 2 | ||
of the License, or (at your option) any later version. | ||
|
||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
|
||
You should have received a copy of the GNU General Public License | ||
along with this program; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# This file describes the maintainers for sonic-device-data | ||
# See the SONiC project governance document for more information | ||
|
||
Name = "Joe LeVeque" | ||
Email = "jolevequ@microsoft.com" | ||
Github = jleveque | ||
Mailinglist = sonicproject@googlegroups.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# sonic-host-services-data | ||
Data files required for SONiC host services | ||
|
||
|
||
## To build | ||
|
||
``` | ||
dpkg-buildpackage -rfakeroot -b -us -uc | ||
``` | ||
|
||
## To clean | ||
|
||
``` | ||
dpkg-buildpackage -rfakeroot -Tclean | ||
``` | ||
|
||
--- | ||
|
||
See the [SONiC Website](http://azure.github.io/SONiC/) for more information about the SONiC project. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
sonic-host-services-data (1.0-1) UNRELEASED; urgency=low | ||
|
||
* Initial release | ||
|
||
-- Joe LeVeque <jolevequ@microsoft.com> Tue, 20 Oct 2020 02:35:43 +0000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
11 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Source: sonic-host-services-data | ||
Maintainer: Joe LeVeque <jolevequ@microsoft.com> | ||
Section: misc | ||
Priority: optional | ||
Standards-Version: 0.1 | ||
Build-Depends: debhelper (>=11) | ||
|
||
Package: sonic-host-services-data | ||
Architecture: all | ||
Depends: ${misc:Depends} | ||
Description: Data files required for SONiC host services |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/make -f | ||
|
||
build: | ||
|
||
%: | ||
dh $@ | ||
|
||
override_dh_installsystemd: | ||
dh_installsystemd --no-start --name=procdockerstatsd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Compiled Python files | ||
*.pyc | ||
scripts/procdockerstatsdc | ||
|
||
# Generated by packaging | ||
*.egg-info/ | ||
.eggs/ | ||
build/ | ||
dist/ | ||
|
||
# Unit test coverage | ||
.coverage | ||
coverage.xml | ||
htmlcov/ |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[aliases] | ||
test=pytest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from setuptools import setup | ||
|
||
setup( | ||
name = 'sonic-host-services', | ||
version = '1.0', | ||
description = 'Python services which run in the SONiC host OS', | ||
license = 'Apache 2.0', | ||
author = 'SONiC Team', | ||
author_email = 'linuxnetdev@microsoft.com', | ||
url = 'https://github.com/Azure/sonic-buildimage', | ||
maintainer = 'Joe LeVeque', | ||
maintainer_email = 'jolevequ@microsoft.com', | ||
scripts = [ | ||
'scripts/procdockerstatsd', | ||
], | ||
install_requires = [ | ||
'sonic-py-common', | ||
'swsssdk>=2.0.1', | ||
], | ||
setup_requires = [ | ||
'pytest-runner', | ||
'wheel' | ||
], | ||
tests_require = [ | ||
'pytest', | ||
], | ||
classifiers = [ | ||
'Development Status :: 3 - Alpha', | ||
'Environment :: Console', | ||
'Intended Audience :: Developers', | ||
'Intended Audience :: Information Technology', | ||
'Intended Audience :: System Administrators', | ||
'License :: OSI Approved :: Apache Software License', | ||
'Natural Language :: English', | ||
'Operating System :: POSIX :: Linux', | ||
'Programming Language :: Python :: 3.7', | ||
'Topic :: System', | ||
], | ||
keywords = 'sonic SONiC host services', | ||
test_suite = 'setup.get_test_suite' | ||
) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
class MockConnector(object): | ||
STATE_DB = None | ||
data = {} | ||
|
||
def __init__(self, host): | ||
pass | ||
|
||
def connect(self, db_id): | ||
pass | ||
|
||
def get(self, db_id, key, field): | ||
return MockConnector.data[key][field] | ||
|
||
def keys(self, db_id, pattern): | ||
match = pattern.split('*')[0] | ||
ret = [] | ||
for key in MockConnector.data.keys(): | ||
if match in key: | ||
ret.append(key) | ||
|
||
return ret | ||
|
||
def get_all(self, db_id, key): | ||
return MockConnector.data[key] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import imp | ||
import sys | ||
import os | ||
import pytest | ||
|
||
import swsssdk | ||
|
||
from .mock_connector import MockConnector | ||
|
||
swsssdk.SonicV2Connector = MockConnector | ||
|
||
test_path = os.path.dirname(os.path.abspath(__file__)) | ||
modules_path = os.path.dirname(test_path) | ||
scripts_path = os.path.join(modules_path, "scripts") | ||
sys.path.insert(0, modules_path) | ||
|
||
imp.load_source('procdockerstatsd', scripts_path + '/procdockerstatsd') | ||
from procdockerstatsd import * | ||
|
||
class TestProcDockerStatsDaemon(object): | ||
def test_convert_to_bytes(self): | ||
test_data = [ | ||
('1B', 1), | ||
('500B', 500), | ||
('1KB', 1000), | ||
('500KB', 500000), | ||
('1MB', 1000000), | ||
('500MB', 500000000), | ||
('1MiB', 1048576), | ||
('500MiB', 524288000), | ||
('66.41MiB', 69635932), | ||
('333.6MiB', 349804954), | ||
('1GiB', 1073741824), | ||
('500GiB', 536870912000), | ||
('7.751GiB', 8322572878) | ||
] | ||
|
||
pdstatsd = ProcDockerStats(SYSLOG_IDENTIFIER) | ||
|
||
for test_input, expected_output in test_data: | ||
res = pdstatsd.convert_to_bytes(test_input) | ||
assert res == expected_output |