takashi kadono / Mbed OS Nucleo_446

Dependencies:   ssd1331

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers interface.py Source File

interface.py

00001 """
00002 Copyright 2018 ARM Limited
00003 Licensed under the Apache License, Version 2.0 (the "License");
00004 you may not use this file except in compliance with the License.
00005 You may obtain a copy of the License at
00006 
00007     http://www.apache.org/licenses/LICENSE-2.0
00008 
00009 Unless required by applicable law or agreed to in writing, software
00010 distributed under the License is distributed on an "AS IS" BASIS,
00011 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00012 See the License for the specific language governing permissions and
00013 limitations under the License.
00014 """
00015 from icetea_lib.TestStepError import TestStepFail
00016 
00017 '''
00018 This interface script is intended to be a common library to be used in testcase scripts by testers.
00019 It delegates setUp and tearDown functions with different provided network interface types using setUp() and tearDown() methods.
00020 '''
00021 
00022 
00023 def interfaceUp(tc, duts):
00024     interfaces = {}
00025     for dut in duts:
00026         interface = {dut: {"ipv4": None, "ipv6": None}}
00027 
00028         resp = tc.command("%s" % dut, "ifup")
00029 
00030         ip = interface[dut]["ip"] = interface[dut]["ipv4"] = resp.parsed["address"]["ipv4"]
00031         if not ip:
00032             if resp.parsed["address"]["ipv6"]:
00033                 ip = interface[dut]["ip"] = interface[dut]["ipv6"] = resp.parsed["address"]["ipv6"][0]
00034         if not ip:
00035             raise TestStepFail("Failed to parse IP address")
00036 
00037         interfaces.update(interface)
00038     return interfaces
00039 
00040 
00041 def interfaceDown(tc, duts):
00042     for dut in duts:
00043         tc.command(dut, "ifdown")