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)
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
def lv_resource(self): try: name = self.lv_name() except ex.Error: return vg = self.oget("vg") size = self.oget("size") try: mod = driver_import("resource", "disk", "lv") if mod is None: return except ImportError: return res = mod.DiskLv(rid="disk#", name=name, vg=vg, size=size) res.svc = self.svc return res
def pg(self): """ A lazy property to import the system-specific process group module on-demand and expose it as self.pg """ try: mod = driver_import("pg", fallback=False) except ImportError: return except Exception as exc: print(exc) raise try: mod.DRIVER_BASENAME except AttributeError: return return mod
def ip_class(request, mock_sysname): mock_sysname(request.param) return driver_class(driver_import('resource', 'ip', 'Host'))
# coding: utf-8 from __future__ import print_function import core.status from core.node import Node from drivers.pool.directory import Pool from utilities.naming import factory from core.objects.svc import Svc import core.exceptions as ex import pytest from utilities.drivers import driver_import ContainerDocker = driver_import('res', 'container.docker').ContainerDocker Volume = driver_import('res', 'volume').Volume @pytest.mark.ci class TestVolumeOptions: @staticmethod @pytest.mark.parametrize('options, expected_options', (('ro', 'ro'), ('rw', 'rw'))) def test_it_return_correct_mount_options_when_source_is_os_dir( tmpdir, osvc_path_tests, options, expected_options): svc1 = Svc('test-service') container = ContainerDocker( rid='#docker0', volume_mounts=[str(tmpdir) + ':/dst:' + options]) svc1 += container res = container.volume_options() assert res == [str(tmpdir) + ':/dst:' + expected_options]
import pytest from utilities.drivers import driver_import Fs = driver_import('res', 'fs.linux').Fs LIB_PATH = 'drivers.resource.fs.linux' @pytest.fixture(scope='function') def log(mocker): return mocker.patch.object(Fs, 'log', autospec=True) @pytest.fixture(scope='function') def rc_mounts_mounts(mocker): return mocker.patch(LIB_PATH + '.Mounts') @pytest.fixture(scope='function') def label(mocker): return mocker.patch.object(Fs, 'label', autospec=True) @pytest.fixture(scope='function') def remove_deeper_mounts(mocker): return mocker.patch.object(Fs, 'remove_deeper_mounts', autospec=True) @pytest.fixture(scope='function') def is_up(mocker):
def test_raise_import_error_when_driver_not_found(python_site_opensvc, ): with pytest.raises(ImportError): driver_import('resource', 'nogrp', 'flag')
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'