예제 #1
0
def setup_validator():
    """
    Perform setup of AnyofValidator, definitions, field, and value
    """

    global validator
    global topo

    lpc = LinchpinContext()
    lpc.load_config()
    lpc.load_global_evars()
    lpa = LinchpinAPI(lpc)

    schema_file = 'schema.json'
    base_path = '{0}'.format(os.path.dirname(os.path.realpath(__file__)))\
        .rstrip('/')
    lib_path = os.path.realpath(os.path.join(base_path, os.pardir))
    sp = '{0}/{1}/{2}'.format(lib_path, 'mockdata/general', schema_file)
    schema = json.load(open(sp))

    validator = AnyofValidator(schema)

    topo_name = 'libvirt-new.yml'
    topo_file = '{0}/{1}/{2}'.format(lib_path, 'mockdata/libvirt', topo_name)
    topo = yaml.load(open(topo_file), Loader=yaml.FullLoader)
예제 #2
0
def setup_validator():
    """
    Perform setup of Validator,
    """

    global validator
    global pinfile

    lpc = LinchpinContext()
    lpc.load_config()
    lpc.load_global_evars()
    lpa = LinchpinAPI(lpc)
    validator = Validator(lpa.ctx, lpa.role_path, lpa.pb_ext)

    schema_file = 'schema.json'
    base_path = '{0}'.format(os.path.dirname(os.path.realpath(__file__)))\
        .rstrip('/')
    lib_path = os.path.realpath(os.path.join(base_path, os.pardir))
    sp = '{0}/{1}/{2}'.format(lib_path, '../provision/roles/dummy/files',
                              schema_file)
    schema = json.load(open(sp))

    pf_name = 'PinFile-complete.yml'
    pf_file = '{0}/{1}/{2}'.format(lib_path, 'mockdata/dummy', pf_name)
    pinfile = yaml.load(open(pf_file), Loader=yaml.FullLoader)
def setup_generic_inventory_filter():
    global filter
    global res_output

    cd = ContextData()
    cd.load_config_data()
    config_path = cd.get_temp_filename()
    config_data = cd.cfg_data
    cd.write_config_file(config_path)
    lpc = LinchpinContext()
    lpc.load_config(search_path=[config_path])
    lpc.load_global_evars()
    lpc.setup_logging()

    lpa = LinchpinAPI(lpc)

    filter = GenericInventory.GenericInventory(role_path=lpa.role_path)

    provider = 'general-inventory'
    base_path = '{0}'.format(os.path.dirname(
        os.path.realpath(__file__))).rstrip('/')
    lib_path = os.path.realpath(os.path.join(base_path, os.pardir))
    mock_path = '{0}/{1}/{2}'.format(lib_path, 'mockdata', provider)

    res_output = 'linchpin.benchmark'
    res_file = open(mock_path + '/' + res_output)
    res_output = json.load(res_file)['17']['targets'][0]['general-inventory'][
        'outputs']['resources']
    res_file.close()
예제 #4
0
    def __init__(self,
                 pinfile={},
                 config="linchpin.conf",
                 workspace_path=None):

        """
        Linchpin api Pinfile constructor

        :param pinfile: dictionary object of pinfile
        :param config: configuration path to linchpin.conf, defaults to
                       current working directory
        :param workspace_path: path to workspace directory. if not provided
                               workspace would be generated in /tmp/
        """

        # if workspace is not provided
        if workspace_path:
            self.workspace_path = workspace_path
        else:
            self.workspace_path = tempfile.mkdtemp()
        # generate a workspace name based on Pinfile_contents
        # write contents to workspace
        open(self.workspace_path + "/PinFile", "w").write(json.dumps(pinfile))
        self.pinfile = pinfile
        self.config = config
        self.context = LinchpinContext()
        self.context.setup_logging()
        self.context.load_config(workspace=self.workspace_path)
        self.context.load_global_evars()
        # check where the workspace is being created
        self.context.set_cfg('lp', 'workspace', self.workspace_path)
        self.context.set_evar('workspace', self.workspace_path)
        self.context.set_evar('debug_mode', True)
        self.context.set_evar('auth_debug', True)
예제 #5
0
def test_api_create():

    lpc = LinchpinContext()
    lpc.load_config()
    lpc.load_global_evars()
    lpa = LinchpinAPI(lpc)

    assert_equal(isinstance(lpa, LinchpinAPI), True)
예제 #6
0
def setup_lp_api():

    """
    Perform setup of LinchpinContext, lpc.load_config, and LinchPinAPI
    """

    global lpc
    global lpa
    global pf_data
    global target
    global provision_data

    setup_load_config()

    lpc = LinchpinContext()
    lpc.load_config(search_path=[config_path])
    lpc.load_global_evars()
    lpc.setup_logging()

    lpa = LinchpinAPI(lpc)

    pinfile = lpc.get_cfg('init', 'pinfile', default='PinFile')

    base_path = '{0}'.format(os.path.dirname(
        os.path.realpath(__file__))).rstrip('/')
    mock_path = '{0}/{1}/{2}'.format(base_path, 'mockdata', provider)

    if not lpa.workspace:
        lpa.workspace = mock_path

    lpa.set_evar('workspace', mock_path)

    pf_w_path = '{0}/PinFile'.format(mock_path, pinfile)

    parser = DataParser()
    pf_d = None
    pf_data = parser.process(pf_w_path)

    topo_folder = lpc.get_evar('topologies_folder')
    topo_file = pf_data[provider]["topology"]
    topo_path = '{0}/{1}/{2}'.format(mock_path, topo_folder, topo_file)
    with open(topo_path, 'r') as topo_stream:
        topology_data = parser.parse_json_yaml(topo_stream)
        provision_data = {provider: {'topology': topology_data}}
예제 #7
0
    def __init__(self,
                 path=None):

        """
        Linchpin api workspace constructor

        :param path: path to workspace directory
        """

        self.workspace_path = path
        self.context = LinchpinContext()
        self.context.setup_logging()
        self.context.load_config(workspace=path)
        self.context.load_global_evars()
        self.pindict = {}
        # check where the workspace is being created
        self.context.set_cfg('lp', 'workspace', self.workspace_path)
        self.context.set_evar('workspace', self.workspace_path)
        self.context.set_evar('debug_mode', True)