예제 #1
0
 def create(sysname, scenario):
     driver_name, kwargs, expected_type = scenario
     mock_sysname(sysname)
     from utilities.drivers import driver_import, driver_class
     args = ["resource"] + driver_name.split(".")
     driver = driver_import(*args)
     return driver_class(driver)(**kwargs)
예제 #2
0
def ip_class(mocker, mock_sysname):
    mock_sysname('SunOS')
    klass = driver_class(driver_import('resource', 'ip', 'Host'))
    from utilities.ifconfig.sunos import Ifconfig
    ifconfig = Ifconfig(ifconfig=str(IFCONFIG))
    log = mocker.Mock('log',
                      info=mocker.Mock('info'),
                      debug=mocker.Mock('debug'))
    mocker.patch.object(klass, 'vcall', mocker.Mock('vcall'))
    mocker.patch.object(klass, 'log', log)
    mocker.patch.object(klass, 'get_ifconfig',
                        mocker.Mock('get_ifconfig', return_value=ifconfig))
    return klass
예제 #3
0
def ip_class(request, mock_sysname):
    mock_sysname(request.param)
    return driver_class(driver_import('resource', 'ip', 'Host'))
예제 #4
0
파일: builder.py 프로젝트: sherlant/opensvc
def add_resource(svc, driver_group, s):
    if s == "sync#i0":
        return
    if driver_group == "pool":
        driver_group = "zpool"
        match = "[z]{0,1}pool#"
    else:
        match = driver_group + "#"

    if driver_group in ("disk", "vg", "zpool") and re.match(
            match + ".+pr$", s, re.I) is not None:
        # persistent reserv resource are declared by their peer resource:
        # don't add them from here
        return

    try:
        driver_basename = svc.oget(s, "type")
    except Exception:
        driver_basename = ""

    try:
        mod = svc.load_driver(driver_group, driver_basename)
    except Exception:
        return

    tags = get_tags(svc, s)
    encap = get_encap(svc, s)

    if svc.encap and "encap" not in tags and not encap:
        return

    if not svc.encap and (encap or "encap" in tags):
        svc.has_encap_resources = True
        try:
            enode = list(svc.encapnodes)[0]
        except IndexError:
            return
        svc.encap_resources[s] = Storage({
            "rid":
            s,
            "tags":
            tags,
            "encap":
            encap,
            "subset":
            svc.oget(s, "subset", impersonate=enode),
            "nb_restart":
            get_restart(svc, s, impersonate=enode),
            "monitor":
            get_monitor(svc, s, impersonate=enode),
            "disabled":
            get_disabled(svc, s, impersonate=enode),
        })
        svc.encap_resources[s].is_disabled = lambda: svc.encap_resources[
            s].disabled
        return

    if s in svc.resources_by_id:
        return

    kwargs = svc.section_kwargs(s)
    kwargs.update(svc.section_kwargs(s, rtype=mod.DRIVER_BASENAME))
    kwargs["rid"] = s
    try:
        del kwargs["type"]
    except KeyError:
        pass
    svc += driver_class(mod)(**kwargs)
예제 #5
0
 def test_import_correct_driver(python_site_opensvc, args, expected_type):
     mod = driver_import('resource', *args)
     custom_resource = driver_class(mod)(rid="#12")
     assert custom_resource.type == expected_type
     assert custom_resource.rid == '#12'