!11 modify args of register func, add register file template
From: @rabbitali Reviewed-by: @Lostwayzxc Signed-off-by: @Lostwayzxc
This commit is contained in:
commit
55fde3eed2
465
0001-update-register.patch
Normal file
465
0001-update-register.patch
Normal file
@ -0,0 +1,465 @@
|
||||
From 52c2b0e3b5c0db7c4369ec06d6f9a78d146ab3cd Mon Sep 17 00:00:00 2001
|
||||
From: wenxin <shusheng.wen@outlook.com>
|
||||
Date: Tue, 6 Dec 2022 14:50:57 +0800
|
||||
Subject: [PATCH] update register
|
||||
|
||||
---
|
||||
aops-ceres.spec | 1 +
|
||||
ceres/__main__.py | 2 +-
|
||||
ceres/conf/constant.py | 26 +++---
|
||||
ceres/function/register.py | 28 +++---
|
||||
ceres/function/schema.py | 18 ++--
|
||||
ceres/tests/function/test_register.py | 126 +++++++++++++-------------
|
||||
conf/register_example.json | 10 ++
|
||||
setup.py | 1 +
|
||||
8 files changed, 112 insertions(+), 100 deletions(-)
|
||||
create mode 100644 conf/register_example.json
|
||||
|
||||
diff --git a/aops-ceres.spec b/aops-ceres.spec
|
||||
index 230c983..196bc96 100644
|
||||
--- a/aops-ceres.spec
|
||||
+++ b/aops-ceres.spec
|
||||
@@ -34,6 +34,7 @@ An agent which needs to be adopted in client, it managers some plugins, such as
|
||||
%files
|
||||
%doc README.*
|
||||
%attr(0644,root,root) %{_sysconfdir}/aops/ceres.conf
|
||||
+%attr(0644,root,root) /opt/aops/register_example.json
|
||||
%attr(0755,root,root) %{_unitdir}/aops-ceres.service
|
||||
%{python3_sitelib}/aops_ceres*.egg-info
|
||||
%{python3_sitelib}/ceres/*
|
||||
diff --git a/ceres/__main__.py b/ceres/__main__.py
|
||||
index 0b3c37e..080eb64 100644
|
||||
--- a/ceres/__main__.py
|
||||
+++ b/ceres/__main__.py
|
||||
@@ -40,7 +40,7 @@ def register_on_manager(args: argparse.Namespace) -> NoReturn:
|
||||
args(argparse.Namespace): args parser
|
||||
|
||||
Returns:
|
||||
- dict: token or error message
|
||||
+ NoReturn
|
||||
"""
|
||||
if args.data:
|
||||
register_info = register_info_to_dict(args.data)
|
||||
diff --git a/ceres/conf/constant.py b/ceres/conf/constant.py
|
||||
index 6e1e1de..bb1c643 100644
|
||||
--- a/ceres/conf/constant.py
|
||||
+++ b/ceres/conf/constant.py
|
||||
@@ -45,25 +45,25 @@ REGISTER_HELP_INFO = """
|
||||
Required parameter: All information cannot be empty
|
||||
host_name type: string
|
||||
host_group_name type: string
|
||||
- web_username type: string
|
||||
- web_password type: string
|
||||
+ username type: string
|
||||
+ password type: string
|
||||
management type: boolean,only True or False
|
||||
- manager_ip type: string
|
||||
- manager_port type: string
|
||||
+ zeus_ip type: string
|
||||
+ zeus_port type: string
|
||||
|
||||
optional parameter:
|
||||
- agent_port type: string
|
||||
+ ceres_port type: string
|
||||
|
||||
for example:
|
||||
{
|
||||
- "web_username":"xxx",
|
||||
- "web_password": "xxx",
|
||||
- "host_name": "xxx",
|
||||
- "host_group_name": "xxx",
|
||||
- "manager_ip":"192.168.xx.xx",
|
||||
- "management":false,
|
||||
- "manager_port":"11111",
|
||||
- "agent_port":"12000"
|
||||
+ "username":"xxx",
|
||||
+ "password": "xxx",
|
||||
+ "host_name": "xxx",
|
||||
+ "host_group_name": "xxx",
|
||||
+ "zeus_ip":"192.168.xx.xx",
|
||||
+ "management":false,
|
||||
+ "zeus_port":"11111",
|
||||
+ "ceres_port":"12000"
|
||||
}
|
||||
|
||||
"""
|
||||
diff --git a/ceres/function/register.py b/ceres/function/register.py
|
||||
index e4e7fe1..1f02252 100644
|
||||
--- a/ceres/function/register.py
|
||||
+++ b/ceres/function/register.py
|
||||
@@ -52,14 +52,14 @@ def register(register_info: dict) -> int:
|
||||
register_info(dict): It contains the necessary information to register an account
|
||||
for example:
|
||||
{
|
||||
- "web_username": "string",
|
||||
- "web_password": "string",
|
||||
- "manager_ip": "string",
|
||||
- "manager_port": "string",
|
||||
- "host_name": "string",
|
||||
- "host_group_name": "string",
|
||||
+ "username": "admin",
|
||||
+ "password": "admin",
|
||||
+ "zeus_ip": "127.0.0.1",
|
||||
+ "zeus_port": "11111",
|
||||
+ "host_name": "host_name",
|
||||
+ "host_group_name": "host_group_name",
|
||||
"management": true,
|
||||
- "agent_port": "12000"
|
||||
+ "ceres_port": "12000"
|
||||
}
|
||||
Returns:
|
||||
str: status code
|
||||
@@ -71,21 +71,21 @@ def register(register_info: dict) -> int:
|
||||
data['host_name'] = register_info.get('host_name')
|
||||
data['host_group_name'] = register_info.get('host_group_name')
|
||||
data['management'] = register_info.get('management') or False
|
||||
- data['username'] = register_info.get('web_username')
|
||||
- data['password'] = register_info.get('web_password')
|
||||
+ data['username'] = register_info.get('username')
|
||||
+ data['password'] = register_info.get('password')
|
||||
data['host_id'] = Collect.get_uuid()
|
||||
data['public_ip'] = Collect.get_host_ip()
|
||||
- data['agent_port'] = register_info.get('agent_port') or \
|
||||
+ data['agent_port'] = register_info.get('ceres_port') or \
|
||||
configuration.ceres.get('PORT')
|
||||
data["os_version"] = Collect.get_system_info()
|
||||
|
||||
- manager_ip = register_info.get('manager_ip')
|
||||
- manager_port = register_info.get('manager_port')
|
||||
- url = f'http://{manager_ip}:{manager_port}/manage/host/add'
|
||||
+ zeus_ip = register_info.get('zeus_ip')
|
||||
+ zeus_port = register_info.get('zeus_port')
|
||||
+ url = f'http://{zeus_ip}:{zeus_port}/manage/host/add'
|
||||
try:
|
||||
ret = requests.post(url, data=json.dumps(data),
|
||||
headers={'content-type': 'application/json'}, timeout=5)
|
||||
- except requests.exceptions.ConnectionError as e:
|
||||
+ except requests.exceptions.RequestException as e:
|
||||
LOGGER.error(e)
|
||||
return HTTP_CONNECT_ERROR
|
||||
ret_data = json.loads(ret.text)
|
||||
diff --git a/ceres/function/schema.py b/ceres/function/schema.py
|
||||
index 409c831..fc994b8 100644
|
||||
--- a/ceres/function/schema.py
|
||||
+++ b/ceres/function/schema.py
|
||||
@@ -32,21 +32,21 @@ REGISTER_SCHEMA = {
|
||||
"required": [
|
||||
"host_name",
|
||||
"host_group_name",
|
||||
- "web_username",
|
||||
- "web_password",
|
||||
+ "username",
|
||||
+ "password",
|
||||
"management",
|
||||
- "manager_ip",
|
||||
- "manager_port"
|
||||
+ "zeus_ip",
|
||||
+ "zeus_port"
|
||||
],
|
||||
"properties": {
|
||||
"host_name": {"type": "string", "minLength": 1},
|
||||
"host_group_name": {"type": "string", "minLength": 1},
|
||||
- "web_username": {"type": "string", "minLength": 1},
|
||||
- "web_password": {"type": "string", "minLength": 1},
|
||||
+ "username": {"type": "string", "minLength": 1},
|
||||
+ "password": {"type": "string", "minLength": 1},
|
||||
"management": {"enum": [True, False]},
|
||||
- "manager_ip": {"type": "string", "minLength": 8},
|
||||
- "manager_port": {"type": "string", "minLength": 2},
|
||||
- "agent_port": {"type": "string", "minLength": 1}
|
||||
+ "zeus_ip": {"type": "string", "minLength": 8},
|
||||
+ "zeus_port": {"type": "string", "minLength": 2},
|
||||
+ "ceres_port": {"type": "string", "minLength": 1}
|
||||
}
|
||||
}
|
||||
|
||||
diff --git a/ceres/tests/function/test_register.py b/ceres/tests/function/test_register.py
|
||||
index 96c4a2d..d60a6c4 100644
|
||||
--- a/ceres/tests/function/test_register.py
|
||||
+++ b/ceres/tests/function/test_register.py
|
||||
@@ -18,190 +18,190 @@ from ceres.function.status import PARAM_ERROR
|
||||
|
||||
class TestRegister(unittest.TestCase):
|
||||
|
||||
- def test_register_should_return_param_error_when_input_web_username_is_null(self):
|
||||
+ def test_register_should_return_param_error_when_input_username_is_null(self):
|
||||
input_data = {
|
||||
- "web_password": "changeme",
|
||||
+ "password": "changeme",
|
||||
"host_name": "host01",
|
||||
"host_group_name": "2333",
|
||||
"management": False,
|
||||
- "manager_ip": "127.0.0.1",
|
||||
- "manager_port": "11111"
|
||||
+ "zeus_ip": "127.0.0.1",
|
||||
+ "zeus_port": "11111"
|
||||
}
|
||||
data = register(input_data)
|
||||
self.assertEqual(PARAM_ERROR, data)
|
||||
|
||||
- def test_register_should_return_param_error_when_input_web_username_is_not_string(self):
|
||||
+ def test_register_should_return_param_error_when_input_username_is_not_string(self):
|
||||
input_data = {
|
||||
- "web_username": 12345,
|
||||
- "web_password": "changeme",
|
||||
+ "username": 12345,
|
||||
+ "password": "changeme",
|
||||
"host_name": "host01",
|
||||
"host_group_name": "2333",
|
||||
"management": False,
|
||||
- "manager_ip": "127.0.0.1",
|
||||
- "manager_port": "11111"
|
||||
+ "zeus_ip": "127.0.0.1",
|
||||
+ "zeus_port": "11111"
|
||||
}
|
||||
data = register(input_data)
|
||||
self.assertEqual(PARAM_ERROR, data)
|
||||
|
||||
- def test_register_should_return_param_error_when_input_web_password_is_null(self):
|
||||
+ def test_register_should_return_param_error_when_input_password_is_null(self):
|
||||
input_data = {
|
||||
- "web_username": "admin",
|
||||
+ "username": "admin",
|
||||
"host_name": "host01",
|
||||
"host_group_name": "2333",
|
||||
"management": False,
|
||||
- "manager_ip": "127.0.0.1",
|
||||
- "manager_port": "11111"
|
||||
+ "zeus_ip": "127.0.0.1",
|
||||
+ "zeus_port": "11111"
|
||||
}
|
||||
data = register(input_data)
|
||||
self.assertEqual(PARAM_ERROR, data)
|
||||
|
||||
- def test_register_should_return_param_error_when_input_web_password_is_not_string(self):
|
||||
+ def test_register_should_return_param_error_when_input_password_is_not_string(self):
|
||||
input_data = {
|
||||
- "web_username": "admin",
|
||||
- "web_password": 123456,
|
||||
+ "username": "admin",
|
||||
+ "password": 123456,
|
||||
"host_name": "host01",
|
||||
"host_group_name": "2333",
|
||||
"management": False,
|
||||
- "manager_ip": "127.0.0.1",
|
||||
- "manager_port": "11111"
|
||||
+ "zeus_ip": "127.0.0.1",
|
||||
+ "zeus_port": "11111"
|
||||
}
|
||||
data = register(input_data)
|
||||
self.assertEqual(PARAM_ERROR, data)
|
||||
|
||||
def test_register_should_return_param_error_when_input_host_name_is_null(self):
|
||||
input_data = {
|
||||
- "web_username": "admin",
|
||||
- "web_password": "changeme",
|
||||
+ "username": "admin",
|
||||
+ "password": "changeme",
|
||||
"host_group_name": "2333",
|
||||
"management": False,
|
||||
- "manager_ip": "127.0.0.1",
|
||||
- "manager_port": "11111"
|
||||
+ "zeus_ip": "127.0.0.1",
|
||||
+ "zeus_port": "11111"
|
||||
}
|
||||
data = register(input_data)
|
||||
self.assertEqual(PARAM_ERROR, data)
|
||||
|
||||
def test_register_should_return_param_error_when_input_host_name_is_not_string(self):
|
||||
input_data = {
|
||||
- "web_username": "admin",
|
||||
- "web_password": "changeme",
|
||||
+ "username": "admin",
|
||||
+ "password": "changeme",
|
||||
"host_name": 12345,
|
||||
"host_group_name": "2333",
|
||||
"management": False,
|
||||
- "manager_ip": "127.0.0.1",
|
||||
- "manager_port": "11111"
|
||||
+ "zeus_ip": "127.0.0.1",
|
||||
+ "zeus_port": "11111"
|
||||
}
|
||||
data = register(input_data)
|
||||
self.assertEqual(PARAM_ERROR, data)
|
||||
|
||||
def test_register_should_return_param_error_when_input_host_group_name_is_null(self):
|
||||
input_data = {
|
||||
- "web_username": "admin",
|
||||
- "web_password": "changeme",
|
||||
+ "username": "admin",
|
||||
+ "password": "changeme",
|
||||
"host_name": "host01",
|
||||
"management": False,
|
||||
- "manager_ip": "127.0.0.1",
|
||||
- "manager_port": "11111"
|
||||
+ "zeus_ip": "127.0.0.1",
|
||||
+ "zeus_port": "11111"
|
||||
}
|
||||
data = register(input_data)
|
||||
self.assertEqual(PARAM_ERROR, data)
|
||||
|
||||
def test_register_should_return_param_error_when_input_host_group_name_is_not_string(self):
|
||||
input_data = {
|
||||
- "web_username": "admin",
|
||||
- "web_password": "changeme",
|
||||
+ "username": "admin",
|
||||
+ "password": "changeme",
|
||||
"host_name": "host01",
|
||||
"host_group_name": True,
|
||||
"management": False,
|
||||
- "manager_ip": "127.0.0.1",
|
||||
- "manager_port": "11111"
|
||||
+ "zeus_ip": "127.0.0.1",
|
||||
+ "zeus_port": "11111"
|
||||
}
|
||||
data = register(input_data)
|
||||
self.assertEqual(PARAM_ERROR, data)
|
||||
|
||||
def test_register_should_return_param_error_when_input_management_is_null(self):
|
||||
input_data = {
|
||||
- "web_username": "admin",
|
||||
- "web_password": "changeme",
|
||||
+ "username": "admin",
|
||||
+ "password": "changeme",
|
||||
"host_name": "host01",
|
||||
"host_group_name": "2333",
|
||||
- "manager_ip": "127.0.0.1",
|
||||
- "manager_port": "11111"
|
||||
+ "zeus_ip": "127.0.0.1",
|
||||
+ "zeus_port": "11111"
|
||||
}
|
||||
data = register(input_data)
|
||||
self.assertEqual(PARAM_ERROR, data)
|
||||
|
||||
def test_register_should_return_param_error_when_input_management_is_not_boolean(self):
|
||||
input_data = {
|
||||
- "web_username": "admin",
|
||||
- "web_password": "changeme",
|
||||
+ "username": "admin",
|
||||
+ "password": "changeme",
|
||||
"host_name": "host01",
|
||||
"host_group_name": "2333",
|
||||
"management": "string",
|
||||
- "manager_ip": "127.0.0.1",
|
||||
- "manager_port": "11111"
|
||||
+ "zeus_ip": "127.0.0.1",
|
||||
+ "zeus_port": "11111"
|
||||
}
|
||||
data = register(input_data)
|
||||
self.assertEqual(PARAM_ERROR, data)
|
||||
|
||||
- def test_register_should_return_param_error_when_input_manager_ip_is_null(self):
|
||||
+ def test_register_should_return_param_error_when_input_zeus_ip_is_null(self):
|
||||
input_data = {
|
||||
- "web_username": "admin",
|
||||
- "web_password": "changeme",
|
||||
+ "username": "admin",
|
||||
+ "password": "changeme",
|
||||
"host_name": "host01",
|
||||
"host_group_name": "2333",
|
||||
"management": False,
|
||||
- "manager_port": "11111"
|
||||
+ "zeus_port": "11111"
|
||||
}
|
||||
data = register(input_data)
|
||||
self.assertEqual(PARAM_ERROR, data)
|
||||
|
||||
- def test_register_should_return_param_error_when_input_manager_ip_is_not_string(self):
|
||||
+ def test_register_should_return_param_error_when_input_zeus_ip_is_not_string(self):
|
||||
input_data = {
|
||||
- "web_username": "admin",
|
||||
- "web_password": "changeme",
|
||||
+ "username": "admin",
|
||||
+ "password": "changeme",
|
||||
"host_name": "host01",
|
||||
"host_group_name": "2333",
|
||||
"management": False,
|
||||
- "manager_port": "11111"
|
||||
+ "zeus_port": "11111"
|
||||
}
|
||||
data = register(input_data)
|
||||
self.assertEqual(PARAM_ERROR, data)
|
||||
|
||||
- def test_register_should_return_param_error_when_input_manager_port_is_null(self):
|
||||
+ def test_register_should_return_param_error_when_input_zeus_port_is_null(self):
|
||||
input_data = {
|
||||
"web_username": "admin",
|
||||
"web_password": "changeme",
|
||||
"host_name": "host01",
|
||||
"host_group_name": "2333",
|
||||
"management": False,
|
||||
- "manager_ip": "127.0.0.1",
|
||||
+ "zeus_ip": "127.0.0.1",
|
||||
}
|
||||
data = register(input_data)
|
||||
self.assertEqual(PARAM_ERROR, data)
|
||||
|
||||
- def test_register_should_return_param_error_when_input_manager_port_is_not_string(self):
|
||||
+ def test_register_should_return_param_error_when_input_zeus_port_is_not_string(self):
|
||||
input_data = {
|
||||
- "web_username": "admin",
|
||||
- "web_password": "changeme",
|
||||
+ "username": "admin",
|
||||
+ "password": "changeme",
|
||||
"host_name": "host01",
|
||||
"host_group_name": "2333",
|
||||
"management": False,
|
||||
- "manager_ip": "127.0.0.1",
|
||||
- "manager_port": 80
|
||||
+ "zeus_ip": "127.0.0.1",
|
||||
+ "zeus_port": 80
|
||||
}
|
||||
data = register(input_data)
|
||||
self.assertEqual(PARAM_ERROR, data)
|
||||
|
||||
- def test_register_should_return_param_error_when_input_agent_port_is_not_string(self):
|
||||
+ def test_register_should_return_param_error_when_input_ceres_port_is_not_string(self):
|
||||
input_data = {
|
||||
- "web_username": "admin",
|
||||
- "web_password": "changeme",
|
||||
+ "username": "admin",
|
||||
+ "password": "changeme",
|
||||
"host_name": "host01",
|
||||
"host_group_name": "2333",
|
||||
"management": False,
|
||||
- "manager_ip": "127.0.0.1",
|
||||
- "manager_port": "11111",
|
||||
- "agent_port": 11000
|
||||
+ "zeus_ip": "127.0.0.1",
|
||||
+ "zeus_port": "11111",
|
||||
+ "ceres_port": 11000
|
||||
}
|
||||
data = register(input_data)
|
||||
self.assertEqual(data, PARAM_ERROR)
|
||||
diff --git a/conf/register_example.json b/conf/register_example.json
|
||||
new file mode 100644
|
||||
index 0000000..1f3c12f
|
||||
--- /dev/null
|
||||
+++ b/conf/register_example.json
|
||||
@@ -0,0 +1,10 @@
|
||||
+{
|
||||
+ "username": "admin",
|
||||
+ "password": "admin",
|
||||
+ "zeus_ip": "127.0.0.1",
|
||||
+ "zeus_port": "11111",
|
||||
+ "host_name": "host_name",
|
||||
+ "host_group_name": "host_group_name",
|
||||
+ "management": true,
|
||||
+ "ceres_port": "12000"
|
||||
+}
|
||||
\ No newline at end of file
|
||||
diff --git a/setup.py b/setup.py
|
||||
index 645def0..4edb4ef 100644
|
||||
--- a/setup.py
|
||||
+++ b/setup.py
|
||||
@@ -28,6 +28,7 @@ setup(
|
||||
packages=find_packages(),
|
||||
data_files=[
|
||||
('/etc/aops', ['conf/ceres.conf']),
|
||||
+ ('/opt/aops', ['conf/register_example.json']),
|
||||
('/usr/lib/systemd/system', ['aops-ceres.service']),
|
||||
],
|
||||
package_data={'': ['swagger/swagger.yaml']},
|
||||
--
|
||||
2.37.1.windows.1
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
Name: aops-ceres
|
||||
Version: v1.1.0
|
||||
Release: 1
|
||||
Release: 2
|
||||
Summary: An agent which needs to be adopted in client, it managers some plugins, such as gala-gopher(kpi collection), fluentd(log collection) and so on.
|
||||
License: MulanPSL2
|
||||
URL: https://gitee.com/openeuler/%{name}
|
||||
Source0: %{name}-%{version}.tar.gz
|
||||
Patch0001: 0001-update-register.patch
|
||||
|
||||
BuildRequires: python3-setuptools
|
||||
Requires: python3-requests python3-flask python3-connexion python3-configparser python3-jsonschema
|
||||
@ -19,7 +20,7 @@ An agent which needs to be adopted in client, it managers some plugins, such as
|
||||
|
||||
|
||||
%prep
|
||||
%autosetup -n %{name}-%{version}
|
||||
%autosetup -n %{name}-%{version} -p1
|
||||
|
||||
|
||||
# build for aops-ceres
|
||||
@ -33,6 +34,7 @@ An agent which needs to be adopted in client, it managers some plugins, such as
|
||||
%files
|
||||
%doc README.*
|
||||
%attr(0644,root,root) %{_sysconfdir}/aops/ceres.conf
|
||||
%attr(0644,root,root) /opt/aops/register_example.json
|
||||
%attr(0755,root,root) /usr/lib/systemd/system/aops-ceres.service
|
||||
%{python3_sitelib}/aops_ceres*.egg-info
|
||||
%{python3_sitelib}/ceres/*
|
||||
@ -40,6 +42,9 @@ An agent which needs to be adopted in client, it managers some plugins, such as
|
||||
|
||||
|
||||
%changelog
|
||||
* Wed Dec 07 2022 wenxin<shusheng.wen@outlook.com> - v1.1.0-2
|
||||
- modify args of register func, add register file template
|
||||
|
||||
* Fri Nov 25 2022 wenxin<shusheng.wen@outlook.com> - v1.1.0-1
|
||||
- remove test cases that use the responses module
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user