Exemple #1
0
    def test_add_merge_with_key_over_lap(self):
        b2 = bundles.Bundle()
        b2.repo.ovs = system.Repository('ovs', 'https://ovs.repo')
        b2.attch.url.google = attachments.Url('www.google.com')
        b2.attch.url.dsl = attachments.Url('www.dsl.sk')
        b2.attch.cmd.ipx = attachments.Command('ip x sta')
        cmd1 = attachments.Command('ip l')
        b2.attch.cmd.add_component(cmd1)

        b3 = bundles.Bundle()
        b3.repo.brctl = system.Repository('brctl', 'https://brctl.com')
        b3.attch.dir.dir1 = attachments.Directory('/var/log/')
        b3.attch.dir.dir2 = attachments.Directory('/etc/sysconfig/')
        b3.attch.file.file1 = attachments.File('.bashrc')
        f2 = attachments.File('/bool/config')
        b3.attch.file.add_component(f2)

        b4 = b2 + b3
        self.assertTrue(hasattr(b4, 'attch'))
        self.assertTrue(hasattr(b4, 'repo'))
        self.assertTrue(hasattr(b4.attch, 'dir'))
        self.assertTrue(hasattr(b4.attch, 'url'))

        for model in b2:
            self.assertIn(model, b4)
        for model in b3:
            self.assertIn(model, b4)

        b2 += b3
        self.assertTrue(hasattr(b2.attch, 'dir'))
        self.assertTrue(hasattr(b2.attch, 'file'))

        for model in b3:
            self.assertIn(model, b2)
Exemple #2
0
    def test_cycle_in_hierarchical_bundles(self):
        sys1 = system.Package('wget')
        sys2 = system.Repository('epel', 'http://internet.com')
        sys3 = system.SystemService('network')

        p1 = system.Package('python3')
        p2 = system.Package('gcc')

        a1 = attachments.Command('ip l')
        a2 = attachments.Directory('/var/')

        net1 = network.EthernetInterface('eth1', '00:11:22:33:44:55:66')
        net2 = network.EthernetInterface('eth2', '00:11:22:33:44:55:67')
        net3 = network.EthernetInterface('eth3', '00:11:22:33:44:55:68')
        net4 = network.EthernetInterface('eth4', '00:11:22:33:44:55:69')

        net5 = network.TeamMasterInterface('team1')
        net6 = network.TeamMasterInterface('team1')

        main_bundle = bundles.Bundle()
        main_bundle.add_multiple_components(sys1)

        intf_bundle = bundles.Bundle().add_multiple_components(net1, net2, net3, net4)
        team_master_bundle = bundles.Bundle().add_multiple_components(net5, net6)
        sys_bundle = bundles.Bundle().add_multiple_components(sys2, sys3)

        # creating tree of bundles
        pckg_bundle = bundles.Bundle().add_multiple_components(p1, p2)
        attch_bundle = bundles.Bundle().add_multiple_components(a1, a2)
        sys_bundle.pckg = pckg_bundle
        sys_bundle.attch = attch_bundle

        main_bundle.intf = intf_bundle
        main_bundle.team_master = team_master_bundle
        main_bundle.sys = sys_bundle

        # creating bypass
        team_master_bundle.intf = intf_bundle

        # creating cycle
        intf_bundle.team = team_master_bundle

        # creating cycle to tree root
        attch_bundle.main = main_bundle

        # verify !!
        test_items = [sys1, sys2, sys3, p1, p2, a1, a2, net1, net2, net3, net4, net5, net6]

        self.assertEqual(len(main_bundle), len(test_items), 'There are more/less models than shoudl be!')
        for item in main_bundle:
            self.assertIn(item, test_items, 'There are more objects than is specified.')

        for item in test_items:
            self.assertIn(item, main_bundle.get_all_components(), 'There are missing some specified objects.')
Exemple #3
0
    def test_filter_exclude(self):
        sys1 = system.Package('wget')
        sys2 = system.Repository('epel', 'http://internet.com')
        sys3 = system.SystemService('network')

        p1 = system.Package('python3')
        p2 = system.Package('gcc')

        a1 = attachments.Command('ip l')
        a2 = attachments.Directory('/var/')

        net1 = network.EthernetInterface('eth1', '00:11:22:33:44:55:66')
        net2 = network.EthernetInterface('eth2', '00:11:22:33:44:55:67')
        net3 = network.EthernetInterface('eth3', '00:11:22:33:44:55:68')
        net4 = network.EthernetInterface('eth4', '00:11:22:33:44:55:69')

        net5 = network.TeamMasterInterface('team1')
        net6 = network.TeamMasterInterface('team1')

        main_bundle = bundles.Bundle()
        main_bundle.add_multiple_components(sys1)

        intf_bundle = bundles.Bundle().add_multiple_components(net1, net2, net3, net4)
        team_master_bundle = bundles.Bundle()
        team_master_bundle.team0 = net5
        team_master_bundle.team1 = net6
        sys_bundle = bundles.Bundle().add_multiple_components(sys2, sys3)

        # creating tree of bundles
        pckg_bundle = bundles.Bundle().add_component(p1)
        pckg_bundle.p2 = p2
        attch_bundle = bundles.Bundle().add_multiple_components(a1, a2)
        sys_bundle.pckg = pckg_bundle
        sys_bundle.attch = attch_bundle

        main_bundle.intf = intf_bundle
        main_bundle.team_master = team_master_bundle
        main_bundle.sys = sys_bundle

        # creating bypass
        team_master_bundle.intf = intf_bundle

        # creating cycle
        intf_bundle.team = team_master_bundle

        test_interfaces = [net1, net2, net3, net4, net5, net6]
        main_withou_intf = main_bundle.get_subset(m_class=network.Interface, exclude=True)
        test_pckgs = [sys1, p1, p2]
        without_pckgs = main_bundle.get_subset(m_type=system.Package, exclude=True)

        self.assertIsNot(main_bundle.intf, main_withou_intf.intf, 'Deep copy uses shallow copy in subtrees.')
        self.assertIsNot(main_bundle.sys.pckg, without_pckgs.sys.pckg, 'Deep copy uses shallow copy in subtrees.')

        for item in main_withou_intf:
            self.assertNotIn(item, test_interfaces, 'There are more objects than is specified.')

        for item in test_interfaces:
            self.assertNotIn(item, main_withou_intf.get_all_components(), 'There are wrong objects.')
            self.assertIn(item, without_pckgs.get_all_components(), 'There are missing some specified objects.')

        for item in without_pckgs:
            self.assertNotIn(item, test_pckgs, 'There are more objects than is specified.')

        for item in test_pckgs:
            self.assertNotIn(item, without_pckgs.get_all_components(), 'There are wrongobjects.')
            self.assertIn(item, main_withou_intf.get_all_components(), 'There are missing some specified objects.')
Exemple #4
0
    def test_filter(self):
        sys1 = system.Package('wget')
        sys2 = system.Repository('epel', 'http://internet.com')
        sys3 = system.SystemService('network')

        p1 = system.Package('python3')
        p2 = system.Package('gcc')

        a1 = attachments.Command('ip l')
        a2 = attachments.Directory('/var/')

        net1 = network.EthernetInterface('eth1', '00:11:22:33:44:55:66')
        net2 = network.EthernetInterface('eth2', '00:11:22:33:44:55:67')
        net3 = network.EthernetInterface('eth3', '00:11:22:33:44:55:68')
        net4 = network.EthernetInterface('eth4', '00:11:22:33:44:55:69')

        net5 = network.TeamMasterInterface('team1')
        net6 = network.TeamMasterInterface('team1')

        r1 = network.Route4(ia.IPv4Network('10.0.0.0/24'), net5, ia.IPv4Address('8.8.8.8'))
        r2 = network.Route4(ia.IPv4Network('10.1.0.0/24'), net6, ia.IPv4Address('8.8.8.8'))
        r3 = network.Route4(ia.IPv4Network('10.2.0.0/24'), net6, ia.IPv4Address('8.8.8.8'))

        main_bundle = bundles.Bundle()
        main_bundle.add_multiple_components(sys1)

        intf_bundle = bundles.Bundle().add_multiple_components(net1, net2, net3, net4)
        team_master_bundle = bundles.Bundle()
        team_master_bundle.team0 = net5
        team_master_bundle.team1 = net6
        sys_bundle = bundles.Bundle().add_multiple_components(sys2, sys3)
        route_bundle = bundles.Bundle().add_multiple_components(r1, r2)
        route_bundle.r2 = [r3]

        # creating tree of bundles
        pckg_bundle = bundles.Bundle().add_component(p1)
        pckg_bundle.p2 = p2
        attch_bundle = bundles.Bundle().add_multiple_components(a1, a2)
        sys_bundle.pckg = pckg_bundle
        sys_bundle.attch = attch_bundle

        main_bundle.intf = intf_bundle
        main_bundle.team_master = team_master_bundle
        main_bundle.sys = sys_bundle
        main_bundle.routes = route_bundle

        # creating bypass
        team_master_bundle.intf = intf_bundle

        # creating cycle
        intf_bundle.team = team_master_bundle

        test_interfaces = [net1, net2, net3, net4, net5, net6]
        interfaces = main_bundle.get_subset(m_class=network.Interface)
        test_pckgs = [sys1, p1, p2]
        pckgs = main_bundle.get_subset(m_type=system.Package)
        routes = main_bundle.get_subset(m_class=network.Route4)

        self.assertIsNot(main_bundle.intf, interfaces.intf, 'Deep copy uses shallow copy in subtrees.')
        self.assertIsNot(main_bundle.sys.pckg, pckgs.sys.pckg, 'Deep copy uses shallow copy in subtrees.')
        self.assertIn(net1, interfaces.intf, 'Tree has different structure.')
        self.assertIn(p1, pckgs.sys.pckg, 'Tree has different structure.')

        for item in interfaces:
            self.assertIn(item, test_interfaces, 'There are more objects than is specified.')

        for item in test_interfaces:
            self.assertIn(item, interfaces.get_all_components(), 'There are missing some specified objects.')

        for item in pckgs:
            self.assertIn(item, test_pckgs, 'There are more objects than is specified.')

        for item in test_pckgs:
            self.assertIn(item, pckgs.get_all_components(), 'There are missing some specified objects.')

        for route in [r1, r2, r3]:
            self.assertIn(route, routes, f'{route} is missing in configuration bundle')
Exemple #5
0
from nepta.core import model
from nepta.core.model import attachments
from nepta.core.model.system import Package as Pckg

host_settings = model.bundles.Bundle()

host_settings.packages.vim = Pckg('vim')
host_settings.packages.tmux = Pckg('tmux')

host_settings.attachments.cmd.ip_a = attachments.Command('ip a')
host_settings.attachments.cmd.lscpu = attachments.Command('lscpu')
host_settings.attachments.dir.log = attachments.Directory('/var/log')