def test_search_keys(self):
     curConfig = dict(configDbJson)
     self.writeJson(curConfig, config_mgmt.CONFIG_DB_JSON_FILE)
     cmdpb = config_mgmt.ConfigMgmtDPB(source=config_mgmt.CONFIG_DB_JSON_FILE)
     out = cmdpb.configWithKeys(portBreakOutConfigDbJson, \
         ["Ethernet8","Ethernet9"])
     assert "VLAN" not in out
     assert "INTERFACE" not in out
     for k in out['ACL_TABLE']:
         # only ports must be chosen
         len(out['ACL_TABLE'][k]) == 1
     out = cmdpb.configWithKeys(portBreakOutConfigDbJson, \
         ["Ethernet10","Ethernet11"])
     assert "INTERFACE" in out
     for k in out['ACL_TABLE']:
         # only ports must be chosen
         len(out['ACL_TABLE'][k]) == 1
     return
    def config_mgmt_dpb(self, curConfig):
        '''
        config_mgmt.ConfigMgmtDPB class instance with mocked functions. Not using
        pytest fixture, because it is used in non test funcs.

        Parameter:
            curConfig (dict): Config to start with.

        Return:
            cmdpb (ConfigMgmtDPB): Class instance of ConfigMgmtDPB.
        '''
        # create object
        self.writeJson(curConfig, config_mgmt.CONFIG_DB_JSON_FILE)
        cmdpb = config_mgmt.ConfigMgmtDPB(source=config_mgmt.CONFIG_DB_JSON_FILE)
        # mock funcs
        cmdpb.writeConfigDB = MagicMock(return_value=True)
        cmdpb._verifyAsicDB = MagicMock(return_value=True)
        from .mock_tables import dbconnector
        return cmdpb
Exemple #3
0
def config_mgmt_dpb(cfgdb):
    '''
    config_mgmt. ConfigMgmtDPB class instance with mocked functions. Not using
    pytest fixture, because it is used in mocked funcs.
    @param: cfgdb -> configDb.
    @return:
    cmdpb (ConfigMgmtDPB): Class instance of ConfigMgmtDPB with mocked funcs.
    '''
    curConfig = read_config_db(cfgdb)
    # create object
    config_mgmt.CONFIG_DB_JSON_FILE = "/tmp/startConfigDb.json"
    config_mgmt.DEFAULT_CONFIG_DB_JSON_FILE = "/tmp/portBreakOutConfigDb.json"
    # write in temp file
    writeJson(curConfig, config_mgmt.CONFIG_DB_JSON_FILE)
    writeJson(portBreakOutConfigDbJson, config_mgmt.DEFAULT_CONFIG_DB_JSON_FILE)
    cmdpb = config_mgmt.ConfigMgmtDPB(source=config_mgmt.CONFIG_DB_JSON_FILE)
    # mock funcs
    cmdpb.writeConfigDB = mock.MagicMock(return_value=True)
    cmdpb._verifyAsicDB = mock.MagicMock(return_value=True)
    return cmdpb