Add say hello into steth agent

Change-Id: I2e434ba112928e425ad47e5380af4baec7b44d7d
This commit is contained in:
changzhi1990 2016-03-09 11:00:24 +08:00
parent 2bc7b90781
commit 8e1dc35124
3 changed files with 22 additions and 2 deletions

View File

@ -235,3 +235,6 @@ class AgentApi(object):
for packet in listener.readpkts():
data[listener.name].append(scapy.get_arp_op(str(packet[1])))
return agent_utils.make_response(code=0, data=data)
def say_hello(self):
return agent_utils.make_response(code=0)

View File

@ -23,6 +23,8 @@ from steth.stethclient.utils import Logger
from steth.stethclient.utils import setup_server
SETUP_LINK_IP_PRE = "192.168.100."
ACTIVE = ':-)'
DOWN = 'XXX'
class TearDownLink(Command):
@ -274,6 +276,15 @@ class PrintAgentsInfo(Lister):
parser = super(PrintAgentsInfo, self).get_parser(prog_name)
return parser
def is_agent_active(self, agent):
server = setup_server(agent)
try:
server.say_hello()
return 0
except:
# If this agent is down, "Connection refused" will happen.
return 1
def take_action(self, parsed_args):
try:
from steth.stethclient.constants import MGMT_AGENTS_INFOS
@ -290,6 +301,8 @@ class PrintAgentsInfo(Lister):
r.append(MGMT_AGENTS_INFOS[agent])
r.append(NET_AGENTS_INFOS[agent])
r.append(STORAGE_AGENTS_INFOS[agent])
agent_status = ACTIVE if self.is_agent_active(agent) else DOWN
r.append(agent_status)
results.append(r)
return (('Agent Name', 'Management IP', 'Network IP', 'Storage IP'),
results)
return (('Agent Name', 'Management IP', 'Network IP', 'Storage IP',
'Alive'), results)

View File

@ -106,3 +106,7 @@ class TestApi(unittest.TestCase):
self.agent_api.check_dhcp_on_comp(port_id, port_mac,
phy_iface, net_type)
self.assertRaises(Exception())
def test_say_hello(self):
self.agent_api.say_hello()
self.assertEqual(agent_utils.make_response.called, True)