def test_get_handler(self):
     osutil.get_osutil()
     protocol.get_protocol_util()
     dhcp.get_dhcp_handler()
     provision.get_provision_handler()
     deprovision.get_deprovision_handler()
     daemon.get_daemon_handler()
     resourcedisk.get_resourcedisk_handler()
     scvmm.get_scvmm_handler()
     monitor.get_monitor_handler()
     update.get_update_handler()
     exthandlers.get_exthandlers_handler()
 def test_get_handler(self):
     osutil.get_osutil()
     protocol.get_protocol_util()
     dhcp.get_dhcp_handler()
     provision.get_provision_handler()
     deprovision.get_deprovision_handler()
     daemon.get_daemon_handler()
     resourcedisk.get_resourcedisk_handler()
     scvmm.get_scvmm_handler()
     monitor.get_monitor_handler()
     update.get_update_handler()
     exthandlers.get_exthandlers_handler()
Exemple #3
0
 def __init__(self):
     self._lock = threading.RLock(
     )  # protects the files on disk created during protocol detection
     self._protocol = None
     self.endpoint = None
     self.osutil = get_osutil()
     self.dhcp_handler = get_dhcp_handler()
Exemple #4
0
    def test_dhcp_skip_cache(self):
        handler = dhcp.get_dhcp_handler()
        handler.osutil = osutil.DefaultOSUtil()
        with patch('os.path.exists', return_value=False):
            with patch.object(osutil.DefaultOSUtil, 'get_dhcp_lease_endpoint')\
                    as patch_dhcp_cache:
                with patch.object(dhcp.DhcpHandler, 'send_dhcp_req') \
                        as patch_dhcp_send:

                    endpoint = 'foo'
                    patch_dhcp_cache.return_value = endpoint

                    # endpoint comes from cache
                    self.assertFalse(handler.skip_cache)
                    handler.run()
                    self.assertTrue(patch_dhcp_cache.call_count == 1)
                    self.assertTrue(patch_dhcp_send.call_count == 0)
                    self.assertTrue(handler.endpoint == endpoint)

                    # reset
                    handler.skip_cache = True
                    handler.endpoint = None

                    # endpoint comes from dhcp request
                    self.assertTrue(handler.skip_cache)
                    handler.run()
                    self.assertTrue(patch_dhcp_cache.call_count == 1)
                    self.assertTrue(patch_dhcp_send.call_count == 1)
Exemple #5
0
 def __init__(self):
     self.osutil = get_osutil()
     self.dhcp_handler = get_dhcp_handler()
     self.stopped = True
     self.hostname = None
     self.dhcpid = None
     self.server_thread=None
Exemple #6
0
    def test_dhcp_skip_cache(self):
        handler = dhcp.get_dhcp_handler()
        handler.osutil = osutil.DefaultOSUtil()
        with patch('os.path.exists', return_value=False):
            with patch.object(osutil.DefaultOSUtil, 'get_dhcp_lease_endpoint')\
                    as patch_dhcp_cache:
                with patch.object(dhcp.DhcpHandler, 'send_dhcp_req') \
                        as patch_dhcp_send:

                    endpoint = 'foo'
                    patch_dhcp_cache.return_value = endpoint

                    # endpoint comes from cache
                    self.assertFalse(handler.skip_cache)
                    handler.run()
                    self.assertTrue(patch_dhcp_cache.call_count == 1)
                    self.assertTrue(patch_dhcp_send.call_count == 0)
                    self.assertTrue(handler.endpoint == endpoint)

                    # reset
                    handler.skip_cache = True
                    handler.endpoint = None

                    # endpoint comes from dhcp request
                    self.assertTrue(handler.skip_cache)
                    handler.run()
                    self.assertTrue(patch_dhcp_cache.call_count == 1)
                    self.assertTrue(patch_dhcp_send.call_count == 1)
Exemple #7
0
 def __init__(self):
     self.lock = threading.Lock()
     self.lock_wireserver_endpoint = threading.Lock()
     self.protocol = None
     self.endpoint = None
     self.osutil = get_osutil()
     self.dhcp_handler = get_dhcp_handler()
Exemple #8
0
    def test_wireserver_route_exists(self):
        # setup
        dhcp_handler = dhcp.get_dhcp_handler()
        self.assertTrue(dhcp_handler.endpoint is None)
        self.assertTrue(dhcp_handler.routes is None)
        self.assertTrue(dhcp_handler.gateway is None)

        # execute
        routing_table = "\
            Iface	Destination	Gateway 	Flags	RefCnt	Use	Metric	" \
                        "Mask		MTU	Window	IRTT \n\
            eth0	00000000	10813FA8	0003	0	    0	5	" \
                        "00000000	0	0	0   \n\
            eth0	00345B0A	00000000	0001	0	    0	5	" \
                        "00000000	0	0	0   \n\
            lo	    00000000	01345B0A	0003	0	    0	1	" \
                        "00FCFFFF	0	0	0   \n"

        with patch("os.path.exists", return_value=True):
            mo = mock.mock_open(read_data=routing_table)
            with patch(open_patch(), mo):
                self.assertTrue(dhcp_handler.wireserver_route_exists)

        # test
        self.assertTrue(dhcp_handler.endpoint is not None)
        self.assertTrue(dhcp_handler.routes is None)
        self.assertTrue(dhcp_handler.gateway is None)
Exemple #9
0
    def test_wireserver_route_exists(self):
        # setup
        dhcp_handler = dhcp.get_dhcp_handler()
        self.assertTrue(dhcp_handler.endpoint is None)
        self.assertTrue(dhcp_handler.routes is None)
        self.assertTrue(dhcp_handler.gateway is None)

        # execute
        routing_table = "\
            Iface	Destination	Gateway 	Flags	RefCnt	Use	Metric	" \
                        "Mask		MTU	Window	IRTT \n\
            eth0	00000000	10813FA8	0003	0	    0	5	" \
                        "00000000	0	0	0   \n\
            eth0	00345B0A	00000000	0001	0	    0	5	" \
                        "00000000	0	0	0   \n\
            lo	    00000000	01345B0A	0003	0	    0	1	" \
                        "00FCFFFF	0	0	0   \n"

        with patch("os.path.exists", return_value=True):
            mo = mock.mock_open(read_data=routing_table)
            with patch(open_patch(), mo):
                self.assertTrue(dhcp_handler.wireserver_route_exists)

        # test
        self.assertTrue(dhcp_handler.endpoint is not None)
        self.assertTrue(dhcp_handler.routes is None)
        self.assertTrue(dhcp_handler.gateway is None)
Exemple #10
0
 def __init__(self, osutil):
     super(MonitorDhcpClientRestart,
           self).__init__(conf.get_monitor_dhcp_client_restart_period())
     self.osutil = osutil
     self.dhcp_handler = get_dhcp_handler()
     self.dhcp_handler.conf_routes()
     self.dhcp_warning_enabled = True
     self.dhcp_id_list = []
Exemple #11
0
 def __init__(self):
     self.osutil = get_osutil()
     self.dhcp_handler = get_dhcp_handler()
     self.protocol_util = get_protocol_util()
     self.stopped = True
     self.hostname = None
     self.dhcpid = None
     self.server_thread = None
     self.dhcp_warning_enabled = True
Exemple #12
0
 def test_dhcp_cache_exists(self):
     dhcp_handler = dhcp.get_dhcp_handler()
     dhcp_handler.osutil = osutil.DefaultOSUtil()
     with patch.object(osutil.DefaultOSUtil, 'get_dhcp_lease_endpoint',
                       return_value=None):
         self.assertFalse(dhcp_handler.dhcp_cache_exists)
         self.assertEqual(dhcp_handler.endpoint, None)
     with patch.object(osutil.DefaultOSUtil, 'get_dhcp_lease_endpoint',
                       return_value="foo"):
         self.assertTrue(dhcp_handler.dhcp_cache_exists)
         self.assertEqual(dhcp_handler.endpoint, "foo")
 def __init__(self):
     self.osutil = get_osutil()
     self.dhcp_handler = get_dhcp_handler()
     self.protocol_util = get_protocol_util()
     self.stopped = True
     self.hostname = None
     self.dhcp_id_list = []
     self.server_thread = None
     self.dhcp_warning_enabled = True
     self.last_archive = None
     self.archiver = StateArchiver(conf.get_lib_dir())
Exemple #14
0
 def __init__(self):
     self.osutil = get_osutil()
     self.dhcp_handler = get_dhcp_handler()
     self.protocol_util = get_protocol_util()
     self.stopped = True
     self.hostname = None
     self.dhcp_id = None
     self.server_thread = None
     self.dhcp_warning_enabled = True
     self.last_archive = None
     self.archiver = StateArchiver(conf.get_lib_dir())
Exemple #15
0
 def test_dhcp_cache_exists(self):
     dhcp_handler = dhcp.get_dhcp_handler()
     dhcp_handler.osutil = osutil.DefaultOSUtil()
     with patch.object(osutil.DefaultOSUtil, 'get_dhcp_lease_endpoint',
                       return_value=None):
         self.assertFalse(dhcp_handler.dhcp_cache_exists)
         self.assertEqual(dhcp_handler.endpoint, None)
     with patch.object(osutil.DefaultOSUtil, 'get_dhcp_lease_endpoint',
                       return_value="foo"):
         self.assertTrue(dhcp_handler.dhcp_cache_exists)
         self.assertEqual(dhcp_handler.endpoint, "foo")
Exemple #16
0
    def test_wireserver_route_not_exists(self):
        # setup
        dhcp_handler = dhcp.get_dhcp_handler()
        self.assertTrue(dhcp_handler.endpoint is None)
        self.assertTrue(dhcp_handler.routes is None)
        self.assertTrue(dhcp_handler.gateway is None)

        # execute
        self.assertFalse(dhcp_handler.wireserver_route_exists)

        # test
        self.assertTrue(dhcp_handler.endpoint is None)
        self.assertTrue(dhcp_handler.routes is None)
        self.assertTrue(dhcp_handler.gateway is None)
Exemple #17
0
    def test_wireserver_route_not_exists(self):
        # setup
        dhcp_handler = dhcp.get_dhcp_handler()
        self.assertTrue(dhcp_handler.endpoint is None)
        self.assertTrue(dhcp_handler.routes is None)
        self.assertTrue(dhcp_handler.gateway is None)

        # execute
        self.assertFalse(dhcp_handler.wireserver_route_exists)

        # test
        self.assertTrue(dhcp_handler.endpoint is None)
        self.assertTrue(dhcp_handler.routes is None)
        self.assertTrue(dhcp_handler.gateway is None)
Exemple #18
0
    def test_wireserver_route_not_exists(self):
        # setup
        dhcp_handler = dhcp.get_dhcp_handler()
        self.assertTrue(dhcp_handler.endpoint is None)
        self.assertTrue(dhcp_handler.routes is None)
        self.assertTrue(dhcp_handler.gateway is None)

        # execute

        with patch("os.path.exists", return_value=True):
            open_file_mock = mock.mock_open(read_data=TestDHCP.DEFAULT_ROUTING_TABLE) 
            with patch(open_patch(), open_file_mock):
                self.assertFalse(dhcp_handler.wireserver_route_exists)

        # test
        self.assertTrue(dhcp_handler.endpoint is None)
        self.assertTrue(dhcp_handler.routes is None)
        self.assertTrue(dhcp_handler.gateway is None)
Exemple #19
0
    def test_wireserver_route_exists(self):
        # setup
        dhcp_handler = dhcp.get_dhcp_handler()
        self.assertTrue(dhcp_handler.endpoint is None)
        self.assertTrue(dhcp_handler.routes is None)
        self.assertTrue(dhcp_handler.gateway is None)

        # execute
        routing_table_with_wireserver_route = TestDHCP.DEFAULT_ROUTING_TABLE + \
            "eth0	00000000	10813FA8	0003	0	    0	5	00000000	0	0	0   \n"

        with patch("os.path.exists", return_value=True):
            open_file_mock = mock.mock_open(read_data=routing_table_with_wireserver_route) 
            with patch(open_patch(), open_file_mock):
                self.assertTrue(dhcp_handler.wireserver_route_exists)

        # test
        self.assertTrue(dhcp_handler.endpoint is not None)
        self.assertTrue(dhcp_handler.routes is None)
        self.assertTrue(dhcp_handler.gateway is None)
Exemple #20
0
    def test_dhcp_skip_cache(self):
        handler = dhcp.get_dhcp_handler()
        handler.osutil = osutil.DefaultOSUtil()

        open_file_mock = mock.mock_open(read_data=TestDHCP.DEFAULT_ROUTING_TABLE) 

        with patch('os.path.exists', return_value=False):
            with patch.object(osutil.DefaultOSUtil, 'get_dhcp_lease_endpoint')\
                    as patch_dhcp_cache:
                with patch.object(dhcp.DhcpHandler, 'send_dhcp_req') \
                        as patch_dhcp_send:

                    endpoint = 'foo'
                    patch_dhcp_cache.return_value = endpoint

                    # endpoint comes from cache
                    self.assertFalse(handler.skip_cache)

                    with patch("os.path.exists", return_value=True):
                        with patch(open_patch(), open_file_mock):
                            handler.run()
                    
                    self.assertTrue(patch_dhcp_cache.call_count == 1)
                    self.assertTrue(patch_dhcp_send.call_count == 0)
                    self.assertTrue(handler.endpoint == endpoint)

                    # reset
                    handler.skip_cache = True
                    handler.endpoint = None

                    # endpoint comes from dhcp request
                    self.assertTrue(handler.skip_cache)

                    with patch("os.path.exists", return_value=True):
                        with patch(open_patch(), open_file_mock):
                            handler.run()
                    
                    self.assertTrue(patch_dhcp_cache.call_count == 1)
                    self.assertTrue(patch_dhcp_send.call_count == 1)
Exemple #21
0
    def __init__(self):
        self.osutil = get_osutil()
        self.dhcp_handler = get_dhcp_handler()
        self.protocol_util = None
        self._protocol = None
        self.stopped = True
        self.hostname = None
        self.dhcp_id_list = []
        self.server_thread = None
        self.dhcp_warning_enabled = True
        self.archiver = StateArchiver(conf.get_lib_dir())
        self._reset_firewall_rules = False

        self._periodic_operations = [
            PeriodicOperation("_remove_persistent_net_rules", self._remove_persistent_net_rules_period, conf.get_remove_persistent_net_rules_period()),
            PeriodicOperation("_monitor_dhcp_client_restart", self._monitor_dhcp_client_restart, conf.get_monitor_dhcp_client_restart_period()),
            PeriodicOperation("_cleanup_goal_state_history", self._cleanup_goal_state_history, conf.get_goal_state_history_cleanup_period())
        ]
        if conf.enable_firewall():
            self._periodic_operations.append(PeriodicOperation("_enable_firewall", self._enable_firewall, conf.get_enable_firewall_period()))
        if conf.get_root_device_scsi_timeout() is not None:
            self._periodic_operations.append(PeriodicOperation("_set_root_device_scsi_timeout", self._set_root_device_scsi_timeout, conf.get_root_device_scsi_timeout_period()))
        if conf.get_monitor_hostname():
            self._periodic_operations.append(PeriodicOperation("_monitor_hostname", self._monitor_hostname_changes, conf.get_monitor_hostname_period()))
Exemple #22
0
 def __init__(self):
     self.lock = threading.Lock()
     self.protocol = None
     self.osutil = get_osutil()
     self.dhcp_handler = get_dhcp_handler()
Exemple #23
0
 def __init__(self):
     self.lock = threading.Lock()
     self.protocol = None
     self.osutil = get_osutil()
     self.dhcp_handler = get_dhcp_handler()