Skip to content

Commit

Permalink
Add tests for new APIs for chassis and convert existing API tests to …
Browse files Browse the repository at this point in the history
…run on chassis (#2985)

What is the motivation for this PR?
Add new test cases for api for test plan introduced by PR #2695 #2695 (refer to sections 2 to 6)
Need to run existing api tests against a Sonice chassis but all of the tests were using duthost and hence will always run one of duthost of chassis i.e supervisor or line card. Converted these tests to use the enum_* fixture per hwsku for dut selection. Instead of running gather facts as fixture get facts within compare function for selected duthost.

How did you do it?
Following changes made to api helper files in folder sonic-mgmt/tests/common/helpers/platform_api/
chassis.py:
add new api calls: get_module_index, get_supervisor_slot, get_my_slot, is_modular_chassis

fan_drawer.py:
add new api call: get_maximum_consumed_power

module.py:
add new api calls: get_description,	get_slot, get_type,	get_oper_status, get_midplane_ip, 
is_midplane_reachable, get_maximum_consumed_power, reboot, set_admin_state

psu.py:
add new api calls: get_maximum_supplied_power, set_status_master_led, get_status_master_led

thermal.py:
add new api calls: get_minimum_recorded, get_maximum_recorded
changes maded to api tests to support Sonic Chassis and add tests for new apis:

conftest.py:
changes to run tests on  Sonic chassis
change  plaftorm_api_conn to support multidut by using duthosts and enum_rand_one_per_hwsku_hostname to select dut at function level, 
change from getting ip from eth0 to duthost.mgp_ip to extract ip address for DUT 

change start_platform_service  to support multidut by using duthosts and enum_rand_one_per_hwsku_hostname to select dut at function level,
change from getting ip from eth0 to duthost.mgp_ip to extract ip address for DUT 

change in stop_platform_api_service: to support on all duts where the service was started
for all test modules under api these are common changes :
Remove gather_facts fixture and get facts within compare_value_with_platform_facts per duthost from test
changes changes to run tests on Sonic chassis, Replace duthost with duthosts and enum_rand_one_per_hwsku_hostname for multidut environment for all tests

other changes per module:

test_chassis.py:
add tests for new apis for chassis: get_module_index, get_supervisor_slot, get_my_slot, is_modular_chassis

test_component.py:
remove range since image_list is list for image in range(image_list) 

test_fan_drawer.py:
add test for new apis for fan_drawer: get_maximum_consumed_power

test_module.py
add tests for new apis for module_base: get_description,	get_slot, get_type,	get_oper_status, get_midplane_ip, 
is_midplane_reachable, get_maximum_consumed_power, reboot, set_admin_state

test_psu.py
changes changes to run tests on  Sonic chassis,
add tests for new apis: get_maximum_supplied_power, set_status_master_led, get_status_master_led

test_thermal.py
changes changes to run tests on  Sonic chassis, 
add tests for new apis for thermal: get_minimum_recorded, get_maximum_recorded

How did you verify/test it?
Validated the modified tests against chassis.
  • Loading branch information
rawal01 authored Apr 1, 2021
1 parent c91f693 commit a10093c
Show file tree
Hide file tree
Showing 17 changed files with 636 additions and 351 deletions.
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])


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')


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')


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):
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])


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

0 comments on commit a10093c

Please sign in to comment.