Skip to content

Commit

Permalink
[vstest]: reuse dvs setReadOnlyAttr in test_crm.py
Browse files Browse the repository at this point in the history
Signed-off-by: Guohan Lu <lguohan@gmail.com>
  • Loading branch information
lguohan committed Jul 7, 2020
1 parent 8807b40 commit c90b281
Showing 1 changed file with 27 additions and 51 deletions.
78 changes: 27 additions & 51 deletions tests/test_crm.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import re
import time
import json
import redis
import pytest

from swsscommon import swsscommon
Expand Down Expand Up @@ -37,29 +36,6 @@ def getCrmConfigStr(dvs, key, counter):
return k[1]
return ""

def setReadOnlyAttr(dvs, obj, attr, val):

db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0)
tbl = swsscommon.Table(db, "ASIC_STATE:{0}".format(obj))
keys = tbl.getKeys()

assert len(keys) == 1

swVid = keys[0]
r = redis.Redis(unix_socket_path=dvs.redis_sock, db=swsscommon.ASIC_DB,
encoding="utf-8", decode_responses=True)
swRid = r.hget("VIDTORID", swVid)

assert swRid is not None

ntf = swsscommon.NotificationProducer(db, "SAI_VS_UNITTEST_CHANNEL")
fvp = swsscommon.FieldValuePairs()
ntf.send("enable_unittests", "true", fvp)
fvp = swsscommon.FieldValuePairs([(attr, val)])
key = "SAI_OBJECT_TYPE_SWITCH:" + swRid

ntf.send("set_ro", key, fvp)

def check_syslog(dvs, marker, err_log, expected_cnt):
(exitcode, num) = dvs.runcmd(['sh', '-c', "awk \'/%s/,ENDFILE {print;}\' /var/log/syslog | grep \"%s\" | wc -l" % (marker, err_log)])
assert num.strip() >= str(expected_cnt)
Expand All @@ -74,7 +50,7 @@ def test_CrmFdbEntry(self, dvs, testlog):
dvs.servers[2].runcmd("sysctl -w net.ipv6.conf.eth0.disable_ipv6=1")
dvs.runcmd("crm config polling interval 1")

setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_FDB_ENTRY', '1000')
dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_FDB_ENTRY', '1000')

time.sleep(2)

Expand All @@ -101,7 +77,7 @@ def test_CrmFdbEntry(self, dvs, testlog):
tbl.set("Vlan2|Ethernet8", fvs)

# update available counter
setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_FDB_ENTRY', '999')
dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_FDB_ENTRY', '999')

time.sleep(2)

Expand All @@ -113,7 +89,7 @@ def test_CrmFdbEntry(self, dvs, testlog):
assert avail_counter - new_avail_counter == 1

# update available counter
setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_FDB_ENTRY', '1000')
dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_FDB_ENTRY', '1000')

time.sleep(2)

Expand Down Expand Up @@ -143,7 +119,7 @@ def test_CrmIpv4Route(self, dvs, testlog):

dvs.runcmd("crm config polling interval 1")

setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_ROUTE_ENTRY', '1000')
dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_ROUTE_ENTRY', '1000')

# add static neighbor
dvs.runcmd("ip neigh replace 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0")
Expand All @@ -160,7 +136,7 @@ def test_CrmIpv4Route(self, dvs, testlog):

# add route and update available counter
ps.set("2.2.2.0/24", fvs)
setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_ROUTE_ENTRY', '999')
dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_ROUTE_ENTRY', '999')

time.sleep(2)

Expand All @@ -174,7 +150,7 @@ def test_CrmIpv4Route(self, dvs, testlog):
# remove route and update available counter
ps._del("2.2.2.0/24")
dvs.runcmd("ip neigh del 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0")
setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_ROUTE_ENTRY', '1000')
dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_ROUTE_ENTRY', '1000')

time.sleep(2)

Expand Down Expand Up @@ -213,7 +189,7 @@ def test_CrmIpv6Route(self, dvs, testlog):

dvs.runcmd("crm config polling interval 1")

setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_ROUTE_ENTRY', '1000')
dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_ROUTE_ENTRY', '1000')

# get neighbor and arp entry
dvs.servers[0].runcmd("ping6 -c 4 fc00::1")
Expand All @@ -230,7 +206,7 @@ def test_CrmIpv6Route(self, dvs, testlog):

# add route and update available counter
ps.set("2001::/64", fvs)
setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_ROUTE_ENTRY', '999')
dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_ROUTE_ENTRY', '999')

time.sleep(2)

Expand All @@ -244,7 +220,7 @@ def test_CrmIpv6Route(self, dvs, testlog):
# remove route and update available counter
ps._del("2001::/64")
dvs.runcmd("ip -6 neigh del fc00::2 lladdr 11:22:33:44:55:66 dev Ethernet0")
setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_ROUTE_ENTRY', '1000')
dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_ROUTE_ENTRY', '1000')

time.sleep(2)

Expand Down Expand Up @@ -276,7 +252,7 @@ def test_CrmIpv4Nexthop(self, dvs, testlog):

dvs.runcmd("crm config polling interval 1")

setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEXTHOP_ENTRY', '1000')
dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEXTHOP_ENTRY', '1000')

time.sleep(2)

Expand All @@ -286,7 +262,7 @@ def test_CrmIpv4Nexthop(self, dvs, testlog):

# add nexthop and update available counter
dvs.runcmd("ip neigh replace 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0")
setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEXTHOP_ENTRY', '999')
dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEXTHOP_ENTRY', '999')

time.sleep(2)

Expand All @@ -299,7 +275,7 @@ def test_CrmIpv4Nexthop(self, dvs, testlog):

# remove nexthop and update available counter
dvs.runcmd("ip neigh del 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0")
setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEXTHOP_ENTRY', '1000')
dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEXTHOP_ENTRY', '1000')

time.sleep(2)

Expand Down Expand Up @@ -335,7 +311,7 @@ def test_CrmIpv6Nexthop(self, dvs, testlog):

dvs.runcmd("crm config polling interval 1")

setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEXTHOP_ENTRY', '1000')
dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEXTHOP_ENTRY', '1000')

time.sleep(2)

Expand All @@ -345,7 +321,7 @@ def test_CrmIpv6Nexthop(self, dvs, testlog):

# add nexthop and update available counter
dvs.runcmd("ip -6 neigh replace fc00::2 lladdr 11:22:33:44:55:66 dev Ethernet0")
setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEXTHOP_ENTRY', '999')
dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEXTHOP_ENTRY', '999')

time.sleep(2)

Expand All @@ -358,7 +334,7 @@ def test_CrmIpv6Nexthop(self, dvs, testlog):

# remove nexthop and update available counter
dvs.runcmd("ip -6 neigh del fc00::2 lladdr 11:22:33:44:55:66 dev Ethernet0")
setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEXTHOP_ENTRY', '1000')
dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEXTHOP_ENTRY', '1000')

time.sleep(2)

Expand Down Expand Up @@ -390,7 +366,7 @@ def test_CrmIpv4Neighbor(self, dvs, testlog):

dvs.runcmd("crm config polling interval 1")

setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEIGHBOR_ENTRY', '1000')
dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEIGHBOR_ENTRY', '1000')

time.sleep(2)

Expand All @@ -400,7 +376,7 @@ def test_CrmIpv4Neighbor(self, dvs, testlog):

# add neighbor and update available counter
dvs.runcmd("ip neigh replace 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0")
setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEIGHBOR_ENTRY', '999')
dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEIGHBOR_ENTRY', '999')

time.sleep(2)

Expand All @@ -413,7 +389,7 @@ def test_CrmIpv4Neighbor(self, dvs, testlog):

# remove neighbor and update available counter
dvs.runcmd("ip neigh del 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0")
setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEIGHBOR_ENTRY', '1000')
dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEIGHBOR_ENTRY', '1000')

time.sleep(2)

Expand Down Expand Up @@ -449,7 +425,7 @@ def test_CrmIpv6Neighbor(self, dvs, testlog):

dvs.runcmd("crm config polling interval 1")

setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEIGHBOR_ENTRY', '1000')
dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEIGHBOR_ENTRY', '1000')

time.sleep(2)

Expand All @@ -459,7 +435,7 @@ def test_CrmIpv6Neighbor(self, dvs, testlog):

# add neighbor and update available counter
dvs.runcmd("ip -6 neigh replace fc00::2 lladdr 11:22:33:44:55:66 dev Ethernet0")
setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEIGHBOR_ENTRY', '999')
dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEIGHBOR_ENTRY', '999')

time.sleep(2)

Expand All @@ -472,7 +448,7 @@ def test_CrmIpv6Neighbor(self, dvs, testlog):

# remove neighbor and update available counter
dvs.runcmd("ip -6 neigh del fc00::2 lladdr 11:22:33:44:55:66 dev Ethernet0")
setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEIGHBOR_ENTRY', '1000')
dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEIGHBOR_ENTRY', '1000')

time.sleep(2)

Expand Down Expand Up @@ -507,7 +483,7 @@ def test_CrmNexthopGroup(self, dvs, testlog):

dvs.runcmd("crm config polling interval 1")

setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_ENTRY', '1000')
dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_ENTRY', '1000')

# add neighbors
dvs.runcmd("ip neigh replace 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0")
Expand All @@ -525,7 +501,7 @@ def test_CrmNexthopGroup(self, dvs, testlog):

# add route and update available counter
ps.set("2.2.2.0/24", fvs)
setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_ENTRY', '999')
dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_ENTRY', '999')

time.sleep(2)

Expand All @@ -540,7 +516,7 @@ def test_CrmNexthopGroup(self, dvs, testlog):
ps._del("2.2.2.0/24")
dvs.runcmd("ip neigh del 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0")
dvs.runcmd("ip neigh del 10.0.0.3 lladdr 11:22:33:44:55:66 dev Ethernet4")
setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_ENTRY', '1000')
dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_ENTRY', '1000')

time.sleep(2)

Expand Down Expand Up @@ -582,7 +558,7 @@ def test_CrmNexthopGroupMember(self, dvs, testlog):

dvs.runcmd("crm config polling interval 1")

setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_MEMBER_ENTRY', '1000')
dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_MEMBER_ENTRY', '1000')

# add neighbors
dvs.runcmd("ip neigh replace 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0")
Expand All @@ -600,7 +576,7 @@ def test_CrmNexthopGroupMember(self, dvs, testlog):

# add route and update available counter
ps.set("2.2.2.0/24", fvs)
setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_MEMBER_ENTRY', '998')
dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_MEMBER_ENTRY', '998')

time.sleep(2)

Expand All @@ -615,7 +591,7 @@ def test_CrmNexthopGroupMember(self, dvs, testlog):
ps._del("2.2.2.0/24")
dvs.runcmd("ip neigh del 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0")
dvs.runcmd("ip neigh del 10.0.0.3 lladdr 11:22:33:44:55:66 dev Ethernet4")
setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_MEMBER_ENTRY', '1000')
dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_MEMBER_ENTRY', '1000')

time.sleep(2)

Expand Down

0 comments on commit c90b281

Please sign in to comment.