def reload_dut_config(request, duthost, define_sub_ports_configuration): """ DUT's configuration reload on teardown Args: request: pytest request object duthost: DUT host object define_sub_ports_configuration: Dictonary of parameters for configuration DUT """ yield sub_ports = define_sub_ports_configuration['sub_ports'] dut_ports = define_sub_ports_configuration['dut_ports'] cfg_facts = duthost.config_facts(host=duthost.hostname, source="running")['ansible_facts'] existing_sub_ports = cfg_facts.get("VLAN_SUB_INTERFACE", {}) for sub_port in sub_ports: if sub_port in existing_sub_ports: remove_sub_port(duthost, sub_port, sub_ports[sub_port]['ip']) py_assert(check_sub_port(duthost, sub_ports.keys(), True), "Some sub-port were not deleted") if 'port_in_lag' in request.node.name: for lag_port in dut_ports.values(): remove_lag_port(duthost, cfg_facts, lag_port) duthost.shell('sudo config load -y /etc/sonic/config_db.json')
def apply_config_on_the_dut(define_sub_ports_configuration, duthost, reload_dut_config): """ Apply Sub-ports configuration on the DUT and remove after tests Args: define_sub_ports_configuration: Dictonary of parameters for configuration DUT duthost: DUT host object reload_dut_config: fixture for teardown of DUT Yields: Dictonary of parameters for configuration DUT and PTF host """ sub_ports_vars = { 'sub_ports': define_sub_ports_configuration['sub_ports'] } parent_port_list = [sub_port.split('.')[0] for sub_port in define_sub_ports_configuration['sub_ports'].keys()] for port in set(parent_port_list): remove_member_from_vlan(duthost, '1000', port) sub_ports_config_path = os.path.join(DUT_TMP_DIR, SUB_PORTS_TEMPLATE) config_template = jinja2.Template(open(os.path.join(TEMPLATE_DIR, SUB_PORTS_TEMPLATE)).read()) duthost.command("mkdir -p {}".format(DUT_TMP_DIR)) duthost.copy(content=config_template.render(sub_ports_vars), dest=sub_ports_config_path) duthost.command('sonic-cfggen -j {} --write-to-db'.format(sub_ports_config_path)) py_assert(wait_until(3, 1, 0, check_sub_port, duthost, sub_ports_vars['sub_ports'].keys()), "Some sub-ports were not created") yield sub_ports_vars
def verify_crm_nexthop_counter_not_increased(lower_tor_host): """ A function level fixture to verify crm nexthop counter not increased """ original_counter = get_crm_nexthop_counter(lower_tor_host) yield diff = get_crm_nexthop_counter(lower_tor_host) - original_counter py_assert(diff == 0, "crm nexthop counter is increased by {}.".format(diff))
def verify_crm_nexthop_counter_not_increased(rand_selected_dut, set_crm_polling_interval): """ A function level fixture to verify crm nexthop counter not increased """ original_counter = get_crm_nexthop_counter(rand_selected_dut) logging.info( "Before test: crm nexthop counter = {}".format(original_counter)) yield time.sleep(CRM_POLL_INTERVAL) diff = get_crm_nexthop_counter(rand_selected_dut) - original_counter logging.info( "Before test: crm nexthop counter = {}".format(original_counter + diff)) py_assert(diff <= 0, "crm nexthop counter is increased by {}.".format(diff))