Beispiel #1
0
    def runTest(self):
        wan = self.dev.wan
        lan = self.dev.lan

        from boardfarm.lib.installers import install_snmp, install_snmpd
        from boardfarm.lib.common import snmp_mib_get

        wrong_mibs = ['PsysDescr', 'sys123ObjectID', 'sysServiceS']
        linux_mibs = ['sysDescr',\
                      'sysObjectID',\
                      'sysServices',\
                      'sysName',\
                      'sysServices',\
                      'sysUpTime']

        test_mibs = [linux_mibs[0], wrong_mibs[0],\
                     linux_mibs[1], wrong_mibs[1],\
                     linux_mibs[2], wrong_mibs[2]]

        unit_test = SnmpMibsUnitTest(mibs_location=os.path.abspath(
            os.path.join(os.path.dirname(os.path.realpath(__file__)),
                         os.pardir, 'resources', 'mibs')),
                                     files=['SNMPv2-MIB'],
                                     mibs=test_mibs,
                                     err_mibs=wrong_mibs)
        assert (unit_test.unitTest())

        install_snmpd(wan)

        lan.sendline('echo "nameserver 8.8.8.8" >> /etc/resolv.conf')
        lan.expect(lan.prompt)

        install_snmp(lan)
        wan_iface_ip = wan.get_interface_ipaddr(wan.iface_dut)

        for mib in linux_mibs:
            try:
                result = snmp_mib_get(lan,
                                      unit_test.snmp_obj,
                                      str(wan_iface_ip),
                                      mib,
                                      '0',
                                      community='public')

                print('snmpget({})@{}={}'.format(mib, wan_iface_ip, result))
                print("Trying with snmp_v2 as well")

                value = SnmpHelper.snmp_v2(lan,
                                           str(wan_iface_ip),
                                           mib,
                                           community='public')

                print("Snmpget via snmpv2 on %s: %s" % (mib, value))

            except Exception as e:
                print('Failed on snmpget {} '.format(mib))
                print(e)
                raise e

        print("Test passed")
Beispiel #2
0
    def is_erouter_honouring_config(self, method="snmp"):
        """Checks if the ErouterInitModeControl is set to honour what is stated
        in the boot file. This check can be performed via snmp or dmcli.

        :param method: one of "snmp"(default) or "dmcli"
        :type method: string

        :return: True if ErouterInitModeControl is set to follow the bootfile,
        False otherwise
        :rtype: bool
        """
        if "snmp" == method:
            ip = self.dev.cmts.get_cmip(self.cm_mac)
            if ip == "None":
                raise CodeError("Failed to get cm ip")
            out = SnmpHelper.snmp_v2(self.dev.wan, ip,
                                     "esafeErouterInitModeControl")
            return "5" == out
        elif "dmcli" == method:
            param = "Device.X_LGI-COM_Gateway.ErouterModeControl"
            out = self.dmcli.GPV(param)
            return "honoreRouterInitMode" == out.rval
        else:
            raise CodeError(
                f"Failed to get esafeErouterInitModeControl via {method}")
Beispiel #3
0
    def __init__(self, start=None, fname=None):
        """
        Creates a default basic mta  cfg file for modification
        """
        if type(start) is str:
            # OLD fashined: this is a file name, load the contents from the file
            self.original_file = start
            self.original_fname = os.path.split(start)[1]
            self.encoded_fname = self.original_fname.replace(
                ".txt", self.encoded_suffix
            )
            self.load(start)
        elif isinstance(start, CfgGenerator):
            if fname is None:
                # create a name and add some sha256 digits
                fname = "mta-config-" + self.shortname(10) + ".txt"
            self.txt = (
                start.gen_mta_cfg()
            )  # the derived class already created the skeleton

            high, low = [], []
            for line in self.txt.splitlines():
                if "pktcSigDevCIDFskAfterRing" in line:
                    low.append(line)
                else:
                    high.append(line)
            self.txt = "\n".join(high + low)
            new_list = (
                self.txt.replace("SnmpMibObject", "")
                .replace(";", "")
                .replace(" ", "")
                .split("\n")
            )
            final_list = []
            for val in new_list:
                if val != "":
                    mib_name = val.split()[0].split(".")[0]
                    mib_oid = SnmpHelper.get_mib_oid(mib_name)
                    new_val = val.replace(mib_name, "." + mib_oid)
                    final_list.append(new_val)
            self.txt = "\n".join(final_list)
            logger.info("Config name created: %s" % fname)
            self.original_fname = fname
            self.encoded_fname = self.original_fname.replace(
                ".txt", self.encoded_suffix
            )
        else:
            raise Exception("Wrong type %s received" % type(start))
    def __init__(self,
                 mibs_location=None,
                 files=None,
                 mibs=None,
                 err_mibs=None):
        """
        Takes:
            mibs_location:  where the .mib files are located (can be a list of dirs)
            files:          the name of the .mib/.txt files (without the extension)
            mibs:           e.g. sysDescr, sysObjectID, etc
            err_mibs:       wrong mibs (just for testing that the compiler rejects invalid mibs)
        """

        # where the .mib files are located
        if mibs_location:
            self.srcDirectories = mibs_location

        if type(self.srcDirectories) != list:
            self.srcDirectories = [self.srcDirectories]

        for d in self.srcDirectories:
            if not os.path.exists(str(d)):
                msg = 'No mibs directory {} found test_SnmpHelper.'.format(
                    str(self.srcDirectories))
                raise Exception(msg)

        if files:
            self.mib_files = files

        self.snmp_obj = SnmpHelper.SnmpMibs(self.mib_files,
                                            self.srcDirectories)

        if mibs:
            self.mibs = mibs
            self.error_mibs = err_mibs

        if type(self.mibs) != list:
            self.mibs = [self.mibs]
Beispiel #5
0
    def test_main(self):
        """Start testing the SnmpHelper module."""
        wan = self.dev.wan
        lan = self.dev.lan

        from boardfarm.lib.common import snmp_mib_get
        from boardfarm.lib.installers import install_snmp, install_snmpd

        wrong_mibs = ["PsysDescr", "sys123ObjectID", "sysServiceS"]
        linux_mibs = [
            "sysDescr",
            "sysObjectID",
            "sysServices",
            "sysName",
            "sysServices",
            "sysUpTime",
        ]

        test_mibs = [
            linux_mibs[0],
            wrong_mibs[0],
            linux_mibs[1],
            wrong_mibs[1],
            linux_mibs[2],
            wrong_mibs[2],
        ]

        unit_test = SnmpMibsUnitTest(
            mibs_location=os.path.abspath(
                os.path.join(
                    os.path.dirname(os.path.realpath(__file__)),
                    os.pardir,
                    "resources",
                    "mibs",
                )),
            files=["SNMPv2-MIB"],
            mibs=test_mibs,
            err_mibs=wrong_mibs,
        )
        assert unit_test.unitTest()

        install_snmpd(wan)

        lan.sendline('echo "nameserver 8.8.8.8" >> /etc/resolv.conf')
        lan.expect(lan.prompt)

        install_snmp(lan)
        wan_iface_ip = wan.get_interface_ipaddr(wan.iface_dut)

        for mib in linux_mibs:
            try:
                result = snmp_mib_get(
                    lan,
                    unit_test.snmp_obj,
                    str(wan_iface_ip),
                    mib,
                    "0",
                    community="public",
                )

                print("snmpget({})@{}={}".format(mib, wan_iface_ip, result))
                print("Trying with snmp_v2 as well")

                value = SnmpHelper.snmp_v2(lan,
                                           str(wan_iface_ip),
                                           mib,
                                           community="public")

                print("Snmpget via snmpv2 on %s: %s" % (mib, value))

            except Exception as e:
                print("Failed on snmpget {} ".format(mib))
                print(e)
                raise e

        print("Test passed")