Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for new APIs for chassis and convert existing API tests to run on chassis #2985

Merged
merged 9 commits into from
Apr 1, 2021
17 changes: 17 additions & 0 deletions tests/common/helpers/platform_api/chassis.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def is_replaceable(conn):
# NOTE: The get_change_event() method is not represented here because there is no reliable way
# to test this method in an automated fashion.


def get_base_mac(conn):
return chassis_api(conn, 'get_base_mac')

Expand Down Expand Up @@ -91,6 +92,10 @@ def get_module(conn, index):
return chassis_api(conn, 'get_module', [index])


def get_module_index(conn, mod_name):
return chassis_api(conn, 'get_module_index', [mod_name])
rawal01 marked this conversation as resolved.
Show resolved Hide resolved


def get_num_fans(conn):
return chassis_api(conn, 'get_num_fans')

Expand Down Expand Up @@ -169,3 +174,15 @@ def get_watchdog(conn):

def get_eeprom(conn):
return chassis_api(conn, 'get_eeprom')


def get_supervisor_slot(conn):
return chassis_api(conn, 'get_supervisor_slot')


def get_my_slot(conn):
return chassis_api(conn, 'get_my_slot')

rawal01 marked this conversation as resolved.
Show resolved Hide resolved

def is_modular_chassis(conn):
return chassis_api(conn, 'is_modular_chassis')
4 changes: 4 additions & 0 deletions tests/common/helpers/platform_api/fan_drawer.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,7 @@ def set_status_led(conn, index, color):

def get_status_led(conn, index):
return fan_drawer_api(conn, index, 'get_status_led')

rawal01 marked this conversation as resolved.
Show resolved Hide resolved

def get_maximum_consumed_power(conn, index):
return fan_drawer_api(conn, index, 'get_maximum_consumed_power')
32 changes: 32 additions & 0 deletions tests/common/helpers/platform_api/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,35 @@ def get_all_sfps(conn, mod_idx):

def get_sfp(conn, mod_idx, sfp_idx):
return module_api(conn, mod_idx, 'get_sfp', [sfp_idx])


def get_description(conn, mod_idx):
return module_api(conn, mod_idx, 'get_description')


def get_slot(conn, mod_idx):
return module_api(conn, mod_idx, 'get_slot')


def get_type(conn, mod_idx):
return module_api(conn, mod_idx, 'get_type')


def get_oper_status(conn, mod_idx):
return module_api(conn, mod_idx, 'get_oper_status')


def get_midplane_ip(conn, mod_idx):
return module_api(conn, mod_idx, 'get_midplane_ip')


def is_midplane_reachable(conn, mod_idx):
return module_api(conn, mod_idx, 'is_midplane_reachable')


def get_maximum_consumed_power(conn, mod_idx):
return module_api(conn, mod_idx, 'get_maximum_consumed_power')


def reboot(conn, mod_idx, reboot_type):
return module_api(conn, mod_idx, 'reboot', [reboot_type])
12 changes: 12 additions & 0 deletions tests/common/helpers/platform_api/psu.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ def get_power(conn, psu_id):
return psu_api(conn, psu_id, 'get_power')


def get_maximum_supplied_power(conn, psu_id):
rawal01 marked this conversation as resolved.
Show resolved Hide resolved
return psu_api(conn, psu_id, 'get_maximum_supplied_power')


def get_powergood_status(conn, psu_id):
return psu_api(conn, psu_id, 'get_powergood_status')

Expand Down Expand Up @@ -117,3 +121,11 @@ def get_all_thermals(conn, psu_id):

def get_thermal(conn, psu_id, index):
return psu_api(conn, psu_id, 'get_thermal', [index])

rawal01 marked this conversation as resolved.
Show resolved Hide resolved

def set_status_master_led(conn, psu_id, color):
return psu_api(conn, psu_id, 'set_status_master_led', [color])


def get_status_master_led(conn, psu_id):
return psu_api(conn, psu_id, 'get_status_master_led')
8 changes: 8 additions & 0 deletions tests/common/helpers/platform_api/thermal.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,11 @@ def get_high_critical_threshold(conn, index):

def get_low_critical_threshold(conn, index):
return thermal_api(conn, index, 'get_low_critical_threshold')


def get_minimum_recorded(conn, index):
return thermal_api(conn, index, 'get_minimum_recorded')


def get_maximum_recorded(conn, index):
return thermal_api(conn, index, 'get_maximum_recorded')
43 changes: 26 additions & 17 deletions tests/platform_tests/api/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
IPTABLES_DELETE_RULE_CMD = 'iptables -D INPUT -p tcp -m tcp --dport {} -j ACCEPT'.format(SERVER_PORT)

@pytest.fixture(scope='function')
def start_platform_api_service(duthost, localhost, request):
dut_ip = duthost.setup()['ansible_facts']['ansible_eth0']['ipv4']['address']
def start_platform_api_service(duthosts, enum_rand_one_per_hwsku_hostname, localhost, request):
duthost = duthosts[enum_rand_one_per_hwsku_hostname]
dut_ip = duthost.mgmt_ip

res = localhost.wait_for(host=dut_ip,
port=SERVER_PORT,
Expand Down Expand Up @@ -60,27 +61,35 @@ def start_platform_api_service(duthost, localhost, request):


@pytest.fixture(scope='module', autouse=True)
def stop_platform_api_service(duthost):
def stop_platform_api_service(duthosts):
try:
yield
finally:
# Stop the server and remove our supervisor config changes
pmon_path_supervisor = os.path.join(os.sep, 'etc', 'supervisor', 'conf.d', 'platform_api_server.conf')
pmon_path_script = os.path.join(os.sep, 'opt', SERVER_FILE)
duthost.command('docker exec -i pmon supervisorctl stop platform_api_server')
duthost.command('docker exec -i pmon rm -f {}'.format(pmon_path_supervisor))
duthost.command('docker exec -i pmon rm -f {}'.format(pmon_path_script))
duthost.command('docker exec -i pmon supervisorctl reread')
duthost.command('docker exec -i pmon supervisorctl update')
for duthost in duthosts:
# Stop the server and remove our supervisor config changes
pmon_path_supervisor = os.path.join(os.sep, 'etc', 'supervisor', 'conf.d', 'platform_api_server.conf')
pmon_path_script = os.path.join(os.sep, 'opt', SERVER_FILE)

# Check if platform_api_server running in the pmon docker and only then stop it. Else we would fail,
# and not stop on other DUT's
out = duthost.shell('docker exec pmon supervisorctl status platform_api_server',
module_ignore_errors=True)['stdout_lines']
platform_api_service_state = [line.strip().split()[1] for line in out][0]
if platform_api_service_state == 'RUNNING':
duthost.command('docker exec -i pmon supervisorctl stop platform_api_server')
duthost.command('docker exec -i pmon rm -f {}'.format(pmon_path_supervisor))
duthost.command('docker exec -i pmon rm -f {}'.format(pmon_path_script))
duthost.command('docker exec -i pmon supervisorctl reread')
duthost.command('docker exec -i pmon supervisorctl update')

# Delete the iptables rule we added
duthost.command(IPTABLES_DELETE_RULE_CMD)

# Delete the iptables rule we added
# We ignore errors here because after a watchdog test, the DuT will have power-cycled and will
# no longer have the rule we added in the start_platform_api_service fixture
duthost.command(IPTABLES_DELETE_RULE_CMD, module_ignore_errors=True)

@pytest.fixture(scope='function')
def platform_api_conn(duthost, start_platform_api_service):
dut_ip = duthost.setup()['ansible_facts']['ansible_eth0']['ipv4']['address']
def platform_api_conn(duthosts, enum_rand_one_per_hwsku_hostname, start_platform_api_service):
duthost = duthosts[enum_rand_one_per_hwsku_hostname]
dut_ip = duthost.mgmt_ip

conn = httplib.HTTPConnection(dut_ip, SERVER_PORT)
try:
Expand Down
Loading