Commit 644de9d1 by sanshi

优化主机接口模块用例

parent df81db82
......@@ -33,6 +33,7 @@ class TestHostInterfaceCreate(object):
base_host_name = "SS TEST HOST"
base_description = "SS TEST HOST-interface"
base_groupid = 101
base_name = "SS测试主机接口"
base_ip = "10.0.0.28"
......@@ -172,8 +173,14 @@ class TestHostInterfaceCreate(object):
}])
self.check_code(response=response, code=0)
self.hostid = UtilsResponse().get_result(response=response)["hostids"][0]
self.delete_interfaces()
return self.hostid
@allure.step("删除所有已存在的接口")
def delete_interfaces(self):
session = UtilsDataBase().conn_mysql(db_url=self.db_url, db_port=self.db_port, db_base=self.db_base, db_user=self.db_user, db_pw=self.db_pw)
DataInterface().delete_hostid(session=session, hostid=self.hostid)
@allure.title("hostinterface.create:IP地址相应信息")
@allure.story("创建主机接口:IP地址相应信息")
@allure.severity("blocker")
......@@ -226,7 +233,7 @@ class TestHostInterfaceCreate(object):
self.case_create(num="05")
response = self.hostinterface_create(ip=self.base_ip, dns="", hostid=self.hostid, main=0, port=self.base_port, _type=5, useip=1, bulk=1)
self.check_code(response=response, code=100)
self.check_msg(response=response, msg="主机11的类型[Unknown interface type]没有默认接口")
self.check_msg(response=response, msg="主机SS TEST HOST05的类型[Unknown interface type]没有默认接口")
@allure.title("hostinterface.create:useip=0, bulk=1")
@allure.story("创建主机接口:useip=0, bulk=1")
......
......@@ -6,6 +6,7 @@
from __future__ import division
from WorkApi.API.Host.host_create import HostCreate
from WorkCase import CaseBase
from WorkUtils.UtilsLog import UtilsLog
from WorkUtils.UtilsDataBase import UtilsDataBase
......@@ -14,6 +15,8 @@ from WorkApi.API.HostInterface.hostInterface_create import HostInterfaceCreate
from WorkApi.API.HostInterface.hostInterface_delete import HostInterfaceDelete
from WorkData.Zabbix.interface import DataInterface
from WorkData.Zabbix.hosts import DataHosts
from WorkData.Zabbix.items import DataItems
import allure
......@@ -36,6 +39,10 @@ class TestHostInterfaceDelete(object):
base_dns = "sanshi.zmops.cn"
base_port = "127"
base_host_name = "SS TEST HOST"
base_description = "SS TEST HOST-interface"
base_groupid = 101
new_ip = "192.168.1.28"
new_port = "721"
......@@ -43,7 +50,14 @@ class TestHostInterfaceDelete(object):
def setup_class(cls):
cls.log.debug("开始执行测试套件.......")
session = UtilsDataBase().conn_mysql(db_url=cls.db_url, db_port=cls.db_port, db_base=cls.db_base, db_user=cls.db_user, db_pw=cls.db_pw)
DataInterface().delete_hostid(session=session, hostid=cls.base_hostid)
sql = DataHosts().select_like_name(session=session, name=cls.base_host_name)
for x, y in enumerate(sql):
session = UtilsDataBase().conn_mysql(db_url=cls.db_url, db_port=cls.db_port, db_base=cls.db_base, db_user=cls.db_user, db_pw=cls.db_pw)
DataItems().delete_hostid(session=session, hostid=y.hostid)
session = UtilsDataBase().conn_mysql(db_url=cls.db_url, db_port=cls.db_port, db_base=cls.db_base, db_user=cls.db_user, db_pw=cls.db_pw)
DataHosts().delete_like_name(session=session, name=cls.base_host_name)
@classmethod
def teardown_class(cls):
......@@ -124,11 +138,65 @@ class TestHostInterfaceDelete(object):
_status = UtilsResponse().get_status(response=response)
assert _status == status
@allure.step("调用接口:host.create")
def host_create(self, host=None, name=None, description=None, groupids=None, interfaces=None, tags=None, templateids=None, macros=None,
inventory=None, status=None, inventory_mode=None):
api = HostCreate(_host=self.host)
api.host = host
api.name = name
api.description = description
api.groupids = groupids
api.interfaces = interfaces
api.tags = tags
api.templateids = templateids
api.macros = macros
api.inventory = inventory
api.status = status
api.inventory_mode = inventory_mode
api.tls_connect = 1
api.tls_accept = 1
api.tls_psk_identity = "Test"
api.tls_psk = "Test"
api.get_response()
return api.response
@allure.step("创建测试数据")
def case_host_create(self, num):
templateid = 10001
host = self.base_host_name + num
description = self.base_description + num
interfaces = {
"type": 2,
"main": 1,
"useip": 1,
"ip": self.base_ip,
"dns": "",
"port": 100,
"bulk": 1
}
response = self.host_create(host=host, description=description, groupids=[self.base_groupid],
interfaces=[interfaces], status=0, templateids=[templateid],
macros=[{
"macro": "{$SNMP_COMMUNITY}",
"value": "public"
}])
self.check_code(response=response, code=0)
self.hostid = UtilsResponse().get_result(response=response)["hostids"][0]
self.delete_interfaces()
return self.hostid
@allure.step("删除所有已存在的接口")
def delete_interfaces(self):
session = UtilsDataBase().conn_mysql(db_url=self.db_url, db_port=self.db_port, db_base=self.db_base, db_user=self.db_user, db_pw=self.db_pw)
DataInterface().delete_hostid(session=session, hostid=self.hostid)
@allure.title("hostinterface.delete:删除的ID存在")
@allure.story("删除主机接口:删除的ID存在")
@allure.severity("blocker")
def test_case_01(self):
interfaceid = self.case_create(ip=self.base_ip, dns="", hostid=self.base_hostid, main=1, port=self.base_port, _type=1, useip=1, bulk=1)
self.case_host_create(num="01")
interfaceid = self.case_create(ip=self.base_ip, dns="", hostid=self.hostid, main=1, port=self.base_port, _type=1, useip=1, bulk=1)
response = self.hostinterface_delete(interfaceids=[interfaceid])
self.check_code(response=response, code=0)
......@@ -137,7 +205,8 @@ class TestHostInterfaceDelete(object):
@allure.title("hostinterface.delete:删除的ID不存在 500")
@allure.story("删除主机接口:删除的ID不存在 500")
def test_case_02(self):
interfaceid = self.case_create(ip=self.base_ip, dns="", hostid=self.base_hostid, main=1, port=self.base_port, _type=2, useip=1, bulk=1)
self.case_host_create(num="02")
interfaceid = self.case_create(ip=self.base_ip, dns="", hostid=self.hostid, main=1, port=self.base_port, _type=2, useip=1, bulk=1)
response = self.hostinterface_delete(interfaceids=[interfaceid])
self.check_code(response=response, code=0)
......@@ -149,9 +218,10 @@ class TestHostInterfaceDelete(object):
@allure.title("hostinterface.delete:删除多个ID")
@allure.story("删除主机接口:删除多个ID")
def test_case_03(self):
interfaceid_1 = self.case_create(ip=self.base_ip, dns="", hostid=self.base_hostid, main=1, port=self.base_port, _type=2, useip=1, bulk=1)
interfaceid_2 = self.case_create(ip=self.base_ip, dns="", hostid=self.base_hostid, main=0, port=self.base_port, _type=2, useip=1, bulk=1)
interfaceid_3 = self.case_create(ip=self.base_ip, dns="", hostid=self.base_hostid, main=0, port=self.base_port, _type=2, useip=1, bulk=1)
self.case_host_create(num="03")
interfaceid_1 = self.case_create(ip=self.base_ip, dns="", hostid=self.hostid, main=1, port=self.base_port, _type=2, useip=1, bulk=1)
interfaceid_2 = self.case_create(ip=self.base_ip, dns="", hostid=self.hostid, main=0, port=self.base_port, _type=2, useip=1, bulk=1)
interfaceid_3 = self.case_create(ip=self.base_ip, dns="", hostid=self.hostid, main=0, port=self.base_port, _type=2, useip=1, bulk=1)
response = self.hostinterface_delete(interfaceids=[interfaceid_1, interfaceid_2, interfaceid_3])
self.check_code(response=response, code=0)
......
......@@ -5,6 +5,8 @@
from __future__ import division
from WorkApi.API.Host.host_create import HostCreate
from WorkUtils.UtilsLog import UtilsLog
from WorkUtils.UtilsDataBase import UtilsDataBase
from WorkUtils.UtilsResponse import UtilsResponse
......@@ -12,13 +14,13 @@ from WorkApi.API.HostInterface.hostInterface_create import HostInterfaceCreate
from WorkApi.API.HostInterface.hostInterface_get import HostInterfaceGet
from WorkData.Zabbix.interface import DataInterface
from WorkData.Zabbix.hosts import DataHosts
from WorkData.Zabbix.items import DataItems
from WorkCase import CaseBase
import allure
# allure.label("")
@allure.feature("测试模块:hostinterface.get")
class TestHostInterfaceGet(object):
......@@ -36,11 +38,22 @@ class TestHostInterfaceGet(object):
base_dns = "sanshi.zmops.cn"
base_port = "127"
base_host_name = "SS TEST HOST"
base_description = "SS TEST HOST-interface"
base_groupid = 101
@classmethod
def setup_class(cls):
cls.log.debug("开始执行测试套件.......")
session = UtilsDataBase().conn_mysql(db_url=cls.db_url, db_port=cls.db_port, db_base=cls.db_base, db_user=cls.db_user, db_pw=cls.db_pw)
DataInterface().delete_hostid(session=session, hostid=cls.base_hostid)
sql = DataHosts().select_like_name(session=session, name=cls.base_host_name)
for x, y in enumerate(sql):
session = UtilsDataBase().conn_mysql(db_url=cls.db_url, db_port=cls.db_port, db_base=cls.db_base, db_user=cls.db_user, db_pw=cls.db_pw)
DataItems().delete_hostid(session=session, hostid=y.hostid)
session = UtilsDataBase().conn_mysql(db_url=cls.db_url, db_port=cls.db_port, db_base=cls.db_base, db_user=cls.db_user, db_pw=cls.db_pw)
DataHosts().delete_like_name(session=session, name=cls.base_host_name)
@classmethod
def teardown_class(cls):
......@@ -149,6 +162,59 @@ class TestHostInterfaceGet(object):
assert y["useip"] in UtilsResponse().get_values_from_sql(_sql=sql, key="useip")
assert y["bulk"] in UtilsResponse().get_values_from_sql(_sql=sql, key="bulk")
@allure.step("调用接口:host.create")
def host_create(self, host=None, name=None, description=None, groupids=None, interfaces=None, tags=None, templateids=None, macros=None,
inventory=None, status=None, inventory_mode=None):
api = HostCreate(_host=self.host)
api.host = host
api.name = name
api.description = description
api.groupids = groupids
api.interfaces = interfaces
api.tags = tags
api.templateids = templateids
api.macros = macros
api.inventory = inventory
api.status = status
api.inventory_mode = inventory_mode
api.tls_connect = 1
api.tls_accept = 1
api.tls_psk_identity = "Test"
api.tls_psk = "Test"
api.get_response()
return api.response
@allure.step("创建测试数据")
def case_host_create(self, num):
templateid = 10001
host = self.base_host_name + num
description = self.base_description + num
interfaces = {
"type": 2,
"main": 1,
"useip": 1,
"ip": self.base_ip,
"dns": "",
"port": 100,
"bulk": 1
}
response = self.host_create(host=host, description=description, groupids=[self.base_groupid],
interfaces=[interfaces], status=0, templateids=[templateid],
macros=[{
"macro": "{$SNMP_COMMUNITY}",
"value": "public"
}])
self.check_code(response=response, code=0)
self.hostid = UtilsResponse().get_result(response=response)["hostids"][0]
self.delete_interfaces()
return self.hostid
@allure.step("删除所有已存在的接口")
def delete_interfaces(self):
session = UtilsDataBase().conn_mysql(db_url=self.db_url, db_port=self.db_port, db_base=self.db_base, db_user=self.db_user, db_pw=self.db_pw)
DataInterface().delete_hostid(session=session, hostid=self.hostid)
@allure.title("hostinterface.get:无参数调用")
@allure.story("查询主机接口:无参数调用")
@allure.severity("blocker")
......@@ -165,19 +231,22 @@ class TestHostInterfaceGet(object):
@allure.title("hostinterface.get:hostids=特定IDs")
@allure.story("查询主机接口:hostids=特定IDs")
def test_case_03(self):
response = self.hostinterface_get(hostids=[self.base_hostid])
self.case_host_create(num="03")
response = self.hostinterface_get(hostids=[self.hostid])
self.check_code(response=response, code=0)
@allure.title("hostinterface.get:output=[ip]")
@allure.story("查询主机接口:output=[ip]")
def test_case_04(self):
self.case_host_create(num="04")
response = self.hostinterface_get(output=["ip"])
self.check_code(response=response, code=0)
@allure.title("hostinterface.get:interfaceids=特定IDs, output=[ip, port, type, main, useip, bulk]")
@allure.story("查询主机接口:interfaceids=特定IDs, output=[ip, port, type, main, useip, bulk]")
def test_case_05(self):
interfaceid = self.case_create(ip=self.base_ip, dns="", hostid=self.base_hostid, main=1, port=self.base_port, _type=1, useip=1, bulk=1)
self.case_host_create(num="05")
interfaceid = self.case_create(ip=self.base_ip, dns="", hostid=self.hostid, main=1, port=self.base_port, _type=1, useip=1, bulk=1)
response = self.hostinterface_get(interfaceids=[interfaceid], output=["ip", "port", "type", "main", "useip", "bulk"])
self.check_code(response=response, code=0)
......@@ -186,7 +255,8 @@ class TestHostInterfaceGet(object):
@allure.title("hostinterface.get:limit=1")
@allure.story("查询主机接口:limit=1")
def test_case_06(self):
self.case_create(ip=self.base_ip, dns="", hostid=self.base_hostid, main=1, port=self.base_port, _type=2, useip=1, bulk=1)
self.case_host_create(num="06")
self.case_create(ip=self.base_ip, dns="", hostid=self.hostid, main=1, port=self.base_port, _type=2, useip=1, bulk=1)
response = self.hostinterface_get(limit=1)
self.check_code(response=response, code=0)
......
......@@ -6,6 +6,7 @@
from __future__ import division
from WorkApi.API.Host.host_create import HostCreate
from WorkCase import CaseBase
from WorkUtils.UtilsLog import UtilsLog
from WorkUtils.UtilsDataBase import UtilsDataBase
......@@ -14,11 +15,11 @@ from WorkApi.API.HostInterface.hostInterface_create import HostInterfaceCreate
from WorkApi.API.HostInterface.hostInterface_update import HostInterfaceUpdate
from WorkData.Zabbix.interface import DataInterface
from WorkData.Zabbix.items import DataItems
from WorkData.Zabbix.hosts import DataHosts
import allure
# allure.label("")
@allure.feature("测试模块:hostinterface.update")
class TestHostInterfaceUpdate(object):
......@@ -36,6 +37,10 @@ class TestHostInterfaceUpdate(object):
base_dns = "sanshi.zmops.cn"
base_port = "127"
base_host_name = "SS TEST HOST"
base_description = "SS TEST HOST-interface"
base_groupid = 101
new_ip = "192.168.1.28"
new_port = "721"
......@@ -43,7 +48,14 @@ class TestHostInterfaceUpdate(object):
def setup_class(cls):
cls.log.debug("开始执行测试套件.......")
session = UtilsDataBase().conn_mysql(db_url=cls.db_url, db_port=cls.db_port, db_base=cls.db_base, db_user=cls.db_user, db_pw=cls.db_pw)
DataInterface().delete_hostid(session=session, hostid=cls.base_hostid)
sql = DataHosts().select_like_name(session=session, name=cls.base_host_name)
for x, y in enumerate(sql):
session = UtilsDataBase().conn_mysql(db_url=cls.db_url, db_port=cls.db_port, db_base=cls.db_base, db_user=cls.db_user, db_pw=cls.db_pw)
DataItems().delete_hostid(session=session, hostid=y.hostid)
session = UtilsDataBase().conn_mysql(db_url=cls.db_url, db_port=cls.db_port, db_base=cls.db_base, db_user=cls.db_user, db_pw=cls.db_pw)
DataHosts().delete_like_name(session=session, name=cls.base_host_name)
@classmethod
def teardown_class(cls):
......@@ -142,57 +154,115 @@ class TestHostInterfaceUpdate(object):
_status = UtilsResponse().get_status(response=response)
assert _status == status
@allure.step("调用接口:host.create")
def host_create(self, host=None, name=None, description=None, groupids=None, interfaces=None, tags=None, templateids=None, macros=None,
inventory=None, status=None, inventory_mode=None):
api = HostCreate(_host=self.host)
api.host = host
api.name = name
api.description = description
api.groupids = groupids
api.interfaces = interfaces
api.tags = tags
api.templateids = templateids
api.macros = macros
api.inventory = inventory
api.status = status
api.inventory_mode = inventory_mode
api.tls_connect = 1
api.tls_accept = 1
api.tls_psk_identity = "Test"
api.tls_psk = "Test"
api.get_response()
return api.response
@allure.step("创建测试数据")
def case_host_create(self, num):
templateid = 10001
host = self.base_host_name + num
description = self.base_description + num
interfaces = {
"type": 2,
"main": 1,
"useip": 1,
"ip": self.base_ip,
"dns": "",
"port": 100,
"bulk": 1
}
response = self.host_create(host=host, description=description, groupids=[self.base_groupid],
interfaces=[interfaces], status=0, templateids=[templateid],
macros=[{
"macro": "{$SNMP_COMMUNITY}",
"value": "public"
}])
self.check_code(response=response, code=0)
self.hostid = UtilsResponse().get_result(response=response)["hostids"][0]
self.delete_interfaces()
return self.hostid
@allure.step("删除所有已存在的接口")
def delete_interfaces(self):
session = UtilsDataBase().conn_mysql(db_url=self.db_url, db_port=self.db_port, db_base=self.db_base, db_user=self.db_user, db_pw=self.db_pw)
DataInterface().delete_hostid(session=session, hostid=self.hostid)
@allure.title("hostinterface.update:修改ip, port")
@allure.story("更新主机接口:修改ip, port")
@allure.severity("blocker")
def test_case_01(self):
interfaceid = self.case_create(ip=self.base_ip, dns="", hostid=self.base_hostid, main=1, port=self.base_port, _type=1, useip=1, bulk=1)
self.case_host_create(num="01")
interfaceid = self.case_create(ip=self.base_ip, dns="", hostid=self.hostid, main=1, port=self.base_port, _type=1, useip=1, bulk=1)
response = self.hostinterface_update(interfaceid=interfaceid, ip=self.new_ip, dns="", hostid=self.base_hostid, main=1, port=self.new_port, _type=1,
response = self.hostinterface_update(interfaceid=interfaceid, ip=self.new_ip, dns="", hostid=self.hostid, main=1, port=self.new_port, _type=1,
useip=1, bulk=1)
self.check_code(response=response, code=0)
self.check_select(interfaceid=interfaceid, ip=self.new_ip, dns="", hostid=self.base_hostid, main=1, port=self.new_port, _type=1, useip=1, bulk=1)
self.check_select(interfaceid=interfaceid, ip=self.new_ip, dns="", hostid=self.hostid, main=1, port=self.new_port, _type=1, useip=1, bulk=1)
@allure.title("hostinterface.update:修改dns")
@allure.story("更新主机接口:修改dns")
def test_case_02(self):
interfaceid = self.case_create(ip=self.base_ip, dns="", hostid=self.base_hostid, main=1, port=self.base_port, _type=2, useip=1, bulk=1)
self.case_host_create(num="02")
interfaceid = self.case_create(ip=self.base_ip, dns="", hostid=self.hostid, main=1, port=self.base_port, _type=2, useip=1, bulk=1)
response = self.hostinterface_update(interfaceid=interfaceid, ip="", dns=self.base_dns, hostid=self.base_hostid, main=1, port=self.new_port, _type=2,
response = self.hostinterface_update(interfaceid=interfaceid, ip="", dns=self.base_dns, hostid=self.hostid, main=1, port=self.new_port, _type=2,
useip=1, bulk=1)
self.check_code(response=response, code=0)
self.check_select(interfaceid=interfaceid, ip="", dns=self.base_dns, hostid=self.base_hostid, main=1, port=self.new_port, _type=2, useip=1, bulk=1)
self.check_select(interfaceid=interfaceid, ip="", dns=self.base_dns, hostid=self.hostid, main=1, port=self.new_port, _type=2, useip=1, bulk=1)
@allure.title("hostinterface.update:默认接口无法修改成非默认接口")
@allure.story("更新主机接口:默认接口无法修改成非默认接口")
def test_case_03(self):
interfaceid = self.case_create(ip=self.base_ip, dns="", hostid=self.base_hostid, main=1, port=self.base_port, _type=3, useip=1, bulk=1)
self.case_host_create(num="03")
interfaceid = self.case_create(ip=self.base_ip, dns="", hostid=self.hostid, main=1, port=self.base_port, _type=3, useip=1, bulk=1)
response = self.hostinterface_update(interfaceid=interfaceid, ip=self.new_ip, dns="", hostid=self.base_hostid, main=0, port=self.new_port, _type=3,
response = self.hostinterface_update(interfaceid=interfaceid, ip=self.new_ip, dns="", hostid=self.hostid, main=0, port=self.new_port, _type=3,
useip=1, bulk=1)
self.check_code(response=response, code=100)
self.check_select(interfaceid=interfaceid, ip=self.base_ip, dns="", hostid=self.base_hostid, main=1, port=self.base_port, _type=3, useip=1, bulk=1)
self.check_select(interfaceid=interfaceid, ip=self.base_ip, dns="", hostid=self.hostid, main=1, port=self.base_port, _type=3, useip=1, bulk=1)
@allure.title("hostinterface.update:非默认接口无法修改成默认接口")
@allure.story("更新主机接口:非默认接口无法修改成默认接口")
def test_case_04(self):
self.case_create(ip=self.base_ip, dns="", hostid=self.base_hostid, main=1, port=self.base_port, _type=4, useip=1, bulk=1)
interfaceid = self.case_create(ip=self.base_ip, dns="", hostid=self.base_hostid, main=0, port=self.base_port, _type=4, useip=1, bulk=1)
self.case_host_create(num="04")
self.case_create(ip=self.base_ip, dns="", hostid=self.hostid, main=1, port=self.base_port, _type=4, useip=1, bulk=1)
interfaceid = self.case_create(ip=self.base_ip, dns="", hostid=self.hostid, main=0, port=self.base_port, _type=4, useip=1, bulk=1)
response = self.hostinterface_update(interfaceid=interfaceid, ip=self.new_ip, dns="", hostid=self.base_hostid, main=1, port=self.new_port, _type=4,
response = self.hostinterface_update(interfaceid=interfaceid, ip=self.new_ip, dns="", hostid=self.hostid, main=1, port=self.new_port, _type=4,
useip=1, bulk=1)
self.check_code(response=response, code=100)
self.check_select(interfaceid=interfaceid, ip=self.base_ip, dns="", hostid=self.base_hostid, main=0, port=self.base_port, _type=4, useip=1, bulk=1)
self.check_select(interfaceid=interfaceid, ip=self.base_ip, dns="", hostid=self.hostid, main=0, port=self.base_port, _type=4, useip=1, bulk=1)
@allure.title("hostinterface.update:修改useip, bulk")
@allure.story("更新主机接口:修改useip, bulk")
def test_case_05(self):
interfaceid = self.case_create(ip=self.base_ip, dns="", hostid=self.base_hostid, main=1, port=self.base_port, _type=5, useip=1, bulk=1)
self.case_host_create(num="05")
interfaceid = self.case_create(ip=self.base_ip, dns="", hostid=self.hostid, main=1, port=self.base_port, _type=5, useip=1, bulk=1)
response = self.hostinterface_update(interfaceid=interfaceid, ip=self.base_ip, dns="", hostid=self.base_hostid, main=1, port=self.base_port, _type=5,
response = self.hostinterface_update(interfaceid=interfaceid, ip=self.base_ip, dns="", hostid=self.hostid, main=1, port=self.base_port, _type=5,
useip=0, bulk=0)
self.check_code(response=response, code=0)
self.check_select(interfaceid=interfaceid, ip=self.base_ip, dns="", hostid=self.base_hostid, main=1, port=self.base_port, _type=5, useip=0, bulk=0)
self.check_select(interfaceid=interfaceid, ip=self.base_ip, dns="", hostid=self.hostid, main=1, port=self.base_port, _type=5, useip=0, bulk=0)
if __name__ == "__main__":
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment