How to use the bundlewrap.repo.Repository function in bundlewrap

To help you get started, we’ve selected a few bundlewrap examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bundlewrap / bundlewrap / tests_legacy / unit / repo_tests.py View on Github external
def test_no_members(self):
        def _get_group(group_name):
            group = MagicMock()
            if group_name == "group1":
                group.nodes = ["node1", "node2", "node3"]
            if group_name == "group2":
                group.nodes = ["node4"]
            if group_name == "group3":
                group.nodes = ["node2", "node3"]
            return group
        r = Repository()
        r.get_group = _get_group

        self.assertEqual(
            r.nodes_in_all_groups(["group1", "group2", "group3"]),
            [],
        )
github bundlewrap / bundlewrap / tests_legacy / unit / repo_tests.py View on Github external
def test_some_members(self):
        def _get_group(group_name):
            group = MagicMock()
            if group_name == "group1":
                group.nodes = ["node1", "node2", "node3"]
            if group_name == "group2":
                group.nodes = ["node2", "node3"]
            if group_name == "group3":
                group.nodes = ["node2", "node3", "node4"]
            return group
        r = Repository()
        r.get_group = _get_group

        self.assertEqual(
            r.nodes_in_all_groups(["group1", "group2", "group3"]),
            ["node2", "node3"],
        )
github bundlewrap / bundlewrap / tests / integration / tomlfiles.py View on Github external
def test_toml_conversion(tmpdir):
    make_repo(
        tmpdir,
        nodes={
            'node1': {
                'os': 'ubuntu',
                'metadata': {
                    "foo": {
                        "bar": "baz",
                    },
                },
            },
        },
    )
    repo = Repository(tmpdir)
    node = repo.get_node("node1")
    node.toml_save()

    assert get_file_contents(join(tmpdir, "nodes", "node1.toml")) == \
        b"""os = "ubuntu"
github bundlewrap / bundlewrap / tests_legacy / unit / node_tests.py View on Github external
def test_apply(self, apply_items, NodeLock, ApplyResult):
        repo = Repository()
        n = Node("node1", {})
        repo.add_node(n)
        result = MagicMock()
        ApplyResult.return_value = result
        NodeLock.__enter__ = lambda x: x
        NodeLock.__exit__ = lambda x: x
        self.assertEqual(n.apply(), result)
        self.assertEqual(apply_items.call_count, 1)
        assert ApplyResult.call_count == 1
github bundlewrap / bundlewrap / tests_legacy / unit / group_tests.py View on Github external
def test_nested_subgroup_loop(self):
        repo = Repository()
        repo.add_group(Group("group1", {'subgroups': ["group2"]}))
        repo.add_group(Group("group2", {'subgroups': ["group1"]}))
        group = repo.get_group("group1")
        with self.assertRaises(RepositoryError):
            list(group.subgroups)
github bundlewrap / bundlewrap / tests_legacy / unit / node_tests.py View on Github external
def test_bundles(self):
        repo = Repository()
        repo.bundle_names = ("bundle1", "bundle2", "bundle3")
        n = Node("node1", {})
        repo.add_node(n)
        g1 = Group("group1", {'bundles': ("bundle1", "bundle2")})
        repo.add_group(g1)
        g2 = Group("group2", {'bundles': ("bundle3",)})
        repo.add_group(g2)
        with patch('tests.unit.node_tests.Node.groups', new=(g1, g2)):
            self.assertEqual(
                tuple(names(n.bundles)),
                ("bundle1", "bundle2", "bundle3"),
            )
github bundlewrap / bundlewrap / tests_legacy / unit / group_tests.py View on Github external
def test_simple_subgroup_loop(self):
        repo = Repository()
        repo.add_group(Group("group1", {'subgroups': ["group1"]}))
        group = repo.get_group("group1")
        with self.assertRaises(RepositoryError):
            list(group.subgroups)
github bundlewrap / bundlewrap / tests_legacy / unit / bundle_tests.py View on Github external
if item.ITEM_TYPE_NAME == 'user':
                file_path = "/home/{}/.screenrc".format(item.name)
                generated_items['files'][file_path] = {
                    'content': "foo",
                }
            return generated_items

        get_all_attrs_from_file.return_value = {
            'item_generators': [
                'test.generator',
            ],
            'users': {
                'jdoe': {},
            },
        }
        repo = Repository()
        repo.bundle_names = ["generatingbundle"]
        repo.libs = MagicMock()
        repo.libs.test.generator = my_item_generator
        node = Node("node1", {'bundles': ["generatingbundle"]})
        repo.add_node(node)
        self.assertEqual(len(node.bundles[0]._generated_items), 1)
        generated_item = node.bundles[0]._generated_items[0]
        self.assertEqual(generated_item.id, "file:/home/jdoe/.screenrc")
github bundlewrap / bundlewrap / bundlewrap / cmdline / diff.py View on Github external
def hooked_diff_config_multiple_nodes(repo, nodes, intermissions, epilogues):
    nodes_config_before = {}
    for node in nodes:
        if QUIT_EVENT.is_set():
            exit(1)
        nodes_config_before[node.name] = node.hash()

    for intermission in intermissions:
        intermission()

    after_repo = Repository(repo.path)
    nodes_config_after = {}
    for node_name in nodes_config_before:
        if QUIT_EVENT.is_set():
            exit(1)
        nodes_config_after[node_name] = \
            after_repo.get_node(node_name).hash()

    node_hashes_before = sorted(
        ["{}\t{}".format(i, h) for i, h in nodes_config_before.items()]
    )
    node_hashes_after = sorted(
        ["{}\t{}".format(i, h) for i, h in nodes_config_after.items()]
    )
    io.stdout("\n".join(
        filter(
            lambda line: line.startswith("+") or line.startswith("-"),
github bundlewrap / bundlewrap / bundlewrap / cmdline / diff.py View on Github external
def hooked_diff_metadata_single_node(repo, node, intermissions, epilogues):
    node_before_metadata = metadata_to_json(node.metadata).splitlines()

    for intermission in intermissions:
        intermission()

    after_repo = Repository(repo.path)
    node_after = after_repo.get_node(node.name)
    node_after_metadata = metadata_to_json(node_after.metadata).splitlines()
    io.stdout("\n".join(unified_diff(
        node_before_metadata,
        node_after_metadata,
        fromfile=_("before"),
        tofile=_("after"),
        lineterm='',
    )))

    for epilogue in epilogues:
        epilogue()