示例#1
0
    def test_override_bundle(self):
        sys1 = system.Package('wget')
        sys2 = system.Repository('epel', 'http://internet.com')
        sys3 = system.SystemService('network')

        sys4 = system.Package('ip')
        sys5 = system.Repository('epel-universe', 'http://internet.com')
        sys6 = system.SystemService('NetworkManager')

        net1 = network.EthernetInterface('eth1', '00:11:22:33:44:55:66')
        net2 = network.EthernetInterface('eth1', '00:11:22:33:44:55:66')
        net3 = network.TeamMasterInterface('team1')

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

        net_bundle = bundles.Bundle().add_multiple_components(net2, net3)
        sys_bundle = bundles.Bundle().add_multiple_components(sys2, sys3)
        new_sys_bundle = bundles.Bundle().add_multiple_components(sys4, sys5, sys6)

        main_bundle.intf = net_bundle
        main_bundle.sys = sys_bundle

        # Overwriting original sys bundle
        main_bundle.sys = new_sys_bundle

        test_items = [sys1, sys4, sys5, sys6, net1, net2, net3]
        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.')
示例#2
0
    def test_new_hierarchical_bundles(self):
        sys1 = system.Package('wget')
        sys2 = system.Repository('epel', 'http://internet.com')
        sys3 = system.SystemService('network')

        net1 = network.EthernetInterface('eth1', '00:11:22:33:44:55:66')
        net2 = network.EthernetInterface('eth1', '00:11:22:33:44:55:66')
        net3 = network.TeamMasterInterface('team1')

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

        net_bundle = bundles.Bundle().add_multiple_components(net2, net3)
        sys_bundle = bundles.Bundle()
        sys_bundle.sys2 = sys2
        sys_bundle.sys3 = sys3

        main_bundle.intf = net_bundle
        main_bundle.sys = sys_bundle

        self.assertEqual(main_bundle.intf, net_bundle)
        self.assertEqual(main_bundle.sys, sys_bundle)

        test_items = [sys1, sys2, sys3, net1, net2, net3]
        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.')

        self.assertIs(sys2, main_bundle.sys.sys2, 'Cannot access correct model.')
        self.assertIs(sys3, main_bundle.sys.sys3, 'Cannot access correct model.')
        self.assertEqual(len(main_bundle), len(test_items), 'There are more/less models than shoudl be!')
示例#3
0
    def test_delete_local_bundle(self):
        sys1 = system.Package('wget')
        sys2 = system.Repository('epel', 'http://internet.com')
        sys3 = system.SystemService('network')

        net1 = network.EthernetInterface('eth1', '00:11:22:33:44:55:66')
        net2 = network.EthernetInterface('eth1', '00:11:22:33:44:55:66')
        net3 = network.TeamMasterInterface('team1')

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

        net_bundle = bundles.Bundle().add_multiple_components(net2, net3)
        sys_bundle = bundles.Bundle().add_multiple_components(sys2, sys3)

        main_bundle.intf = net_bundle
        main_bundle.sys = sys_bundle
        main_bundle.sys2 = sys_bundle

        test_items = [sys1, net1, net2, net3]
        main_bundle.sys = sys_bundle
        del main_bundle.sys
        del main_bundle.sys2

        self.assertNotIn(sys_bundle, main_bundle._parents)
        self.assertNotIn(sys_bundle, main_bundle._bundles.values())

        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.')
示例#4
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.')
示例#5
0
    def test_bundle_basic_iterator(self):
        b1 = bundles.Bundle()

        sys1 = system.Package('wget')
        sys2 = system.Repository('epel', 'http://internet.com')
        sys3 = system.SystemService('network')

        net1 = network.EthernetInterface('eth1', '00:11:22:33:44:55:66')
        net2 = network.EthernetInterface('eth1', '00:11:22:33:44:55:66')
        net3 = network.TeamMasterInterface('team1')

        b1.add_multiple_components(sys1, sys2, sys3, net1, net2, net3)
        ordered_items = [sys1, sys2, sys3, net1, net2, net3]

        for tested, verify in zip(ordered_items, b1):
            self.assertIs(tested, verify)
示例#6
0
    def test_bundle_flush(self):
        sys1 = system.Package('wget')
        sys2 = system.Repository('epel', 'http://internet.com')
        sys3 = system.SystemService('network')

        net1 = network.EthernetInterface('eth1', '00:11:22:33:44:55:66')
        net2 = network.EthernetInterface('eth1', '00:11:22:33:44:55:66')
        net3 = network.TeamMasterInterface('team1')

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

        net_bundle = bundles.Bundle().add_multiple_components(net2, net3)
        sys_bundle = bundles.Bundle().add_multiple_components(sys2, sys3)

        main_bundle.intf = net_bundle
        main_bundle.sys = sys_bundle

        # delete all components
        main_bundle.flush_components()

        self.assertEqual(len(main_bundle), 0)
示例#7
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.')
示例#8
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')