Beispiel #1
0
 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()
Beispiel #2
0
 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 __init__(self):
     self.protocol_util = get_protocol_util()
     self.protocol = None
     self.ext_handlers = None
     self.last_etag = None
     self.log_report = False
     self.log_etag = True
    def test_detect_protocol(self, WireProtocol, MetadataProtocol, _):
        WireProtocol.return_value = MagicMock()
        MetadataProtocol.return_value = MagicMock()

        protocol_util = get_protocol_util()

        protocol_util.dhcp_handler = MagicMock()
        protocol_util.dhcp_handler.endpoint = "foo.bar"

        #Test wire protocol is available
        protocol = protocol_util.get_protocol()
        self.assertEquals(WireProtocol.return_value, protocol)

        #Test wire protocol is not available
        protocol_util.clear_protocol()
        WireProtocol.return_value.detect.side_effect = ProtocolError()

        protocol = protocol_util.get_protocol()
        self.assertEquals(MetadataProtocol.return_value, protocol)

        #Test no protocol is available
        protocol_util.clear_protocol()
        WireProtocol.return_value.detect.side_effect = ProtocolError()

        MetadataProtocol.return_value.detect.side_effect = ProtocolError()
        self.assertRaises(ProtocolError, protocol_util.get_protocol)
    def __init__(self):
        self.osutil = get_osutil()
        self.protocol_util = get_protocol_util()
        self.imds_client = get_imds_client()

        self.event_thread = None
        self.last_reset_loggers_time = None
        self.last_event_collection = None
        self.last_telemetry_heartbeat = None
        self.last_cgroup_polling_telemetry = None
        self.last_cgroup_report_telemetry = None
        self.last_host_plugin_heartbeat = None
        self.last_imds_heartbeat = None
        self.protocol = None
        self.health_service = None
        self.last_route_table_hash = b''
        self.last_nic_state = {}

        self.counter = 0
        self.sysinfo = []
        self.should_run = True
        self.heartbeat_id = str(uuid.uuid4()).upper()
        self.host_plugin_errorstate = ErrorState(
            min_timedelta=MonitorHandler.HOST_PLUGIN_HEALTH_PERIOD)
        self.imds_errorstate = ErrorState(
            min_timedelta=MonitorHandler.IMDS_HEALTH_PERIOD)
    def test_detect_wire_protocol_no_dhcp(self, WireProtocol, mock_get_lib_dir,
                                          _):
        WireProtocol.return_value.detect = Mock()
        mock_get_lib_dir.return_value = self.tmp_dir

        protocol_util = get_protocol_util()

        protocol_util.osutil = MagicMock()
        protocol_util.osutil.is_dhcp_available.return_value = False

        protocol_util.dhcp_handler = MagicMock()
        protocol_util.dhcp_handler.endpoint = None
        protocol_util.dhcp_handler.run = Mock()

        endpoint_file = protocol_util._get_wireserver_endpoint_file_path()

        # Test wire protocol when no endpoint file has been written
        protocol_util._detect_wire_protocol()
        self.assertEqual(KNOWN_WIRESERVER_IP,
                         protocol_util.get_wireserver_endpoint())

        # Test wire protocol when endpoint was previously detected
        protocol_util.clear_protocol()
        with open(endpoint_file, "w+") as endpoint_fd:
            endpoint_fd.write("baz.qux")

        protocol_util._detect_wire_protocol()
        self.assertEqual("baz.qux", protocol_util.get_wireserver_endpoint())

        # Test wire protocol on dhcp failure
        protocol_util.clear_protocol()
        protocol_util.osutil.is_dhcp_available.return_value = True
        protocol_util.dhcp_handler.run.side_effect = DhcpError()

        self.assertRaises(ProtocolError, protocol_util._detect_wire_protocol)
    def test_protocol_file_states(self, _):
        protocol_util = get_protocol_util()
        protocol_util._clear_wireserver_endpoint = Mock()

        protocol_file = protocol_util._get_protocol_file_path()

        # Test clear protocol for io error
        with open(protocol_file, "w+") as proto_fd:
            proto_fd.write("")

        with patch('os.remove') as mock_remove:
            protocol_util.clear_protocol()
            self.assertEqual(
                1, protocol_util._clear_wireserver_endpoint.call_count)
            self.assertEqual(1, mock_remove.call_count)
            self.assertEqual(protocol_file,
                             mock_remove.call_args_list[0][0][0])

        # Test clear protocol when file not found
        protocol_util._clear_wireserver_endpoint.reset_mock()

        with patch('os.remove') as mock_remove:
            protocol_util.clear_protocol()
            self.assertEqual(
                1, protocol_util._clear_wireserver_endpoint.call_count)
            self.assertEqual(1, mock_remove.call_count)
            self.assertEqual(protocol_file,
                             mock_remove.call_args_list[0][0][0])
 def __init__(self):
     self.os_util = get_osutil()
     self.protocol_util = get_protocol_util()
     self.protocol = None
     self.cryptUtil = CryptUtil(conf.get_openssl_cmd())
     self.remote_access = None
     self.incarnation = 0
    def test_detect_protocol(self, WireProtocol, MetadataProtocol, _):
        WireProtocol.return_value = MagicMock()
        MetadataProtocol.return_value = MagicMock()

        protocol_util = get_protocol_util()
        
        protocol_util.dhcp_handler = MagicMock()
        protocol_util.dhcp_handler.endpoint = "foo.bar"

        #Test wire protocol is available
        protocol = protocol_util.get_protocol()
        self.assertEquals(WireProtocol.return_value, protocol)

        #Test wire protocol is not available
        protocol_util.clear_protocol()
        WireProtocol.return_value.detect.side_effect = ProtocolError()

        protocol = protocol_util.get_protocol()
        self.assertEquals(MetadataProtocol.return_value, protocol)

        #Test no protocol is available
        protocol_util.clear_protocol()
        WireProtocol.return_value.detect.side_effect = ProtocolError()

        MetadataProtocol.return_value.detect.side_effect = ProtocolError()
        self.assertRaises(ProtocolError, protocol_util.get_protocol)
Beispiel #10
0
 def __init__(self):
     self.protocol_util = get_protocol_util()
     self.protocol = None
     self.ext_handlers = None
     self.last_etag = None
     self.log_report = False
     self.log_etag = True
Beispiel #11
0
 def __init__(self):
     self.os_util = get_osutil()
     self.protocol_util = get_protocol_util()
     self.protocol = None
     self.cryptUtil = CryptUtil(conf.get_openssl_cmd())
     self.remote_access = None
     self.incarnation = 0
Beispiel #12
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
Beispiel #13
0
    def __init__(self):
        self.protocol_util = get_protocol_util()
        self.protocol = None
        self.ext_handlers = None
        self.last_etag = None
        self.last_upgrade_guids = {}
        self.log_report = False
        self.log_etag = True

        self.report_status_error_state = ErrorState()
Beispiel #14
0
    def __init__(self):
        self.protocol_util = get_protocol_util()
        self.protocol = None
        self.ext_handlers = None
        self.last_etag = None
        self.log_report = False
        self.log_etag = True
        self.log_process = False

        self.report_status_error_state = ErrorState()
        self.get_artifact_error_state = ErrorState(min_timedelta=ERROR_STATE_DELTA_INSTALL)
 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())
Beispiel #16
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())
Beispiel #17
0
    def __init__(self):
        self.protocol_util = get_protocol_util()
        self.protocol = None
        self.ext_handlers = None
        self.last_etag = None
        self.log_report = False
        self.log_etag = True
        self.log_process = False

        self.report_status_error_state = ErrorState()
        self.get_artifact_error_state = ErrorState(min_timedelta=ERROR_STATE_DELTA_INSTALL)
Beispiel #18
0
    def daemon(self, child_args=None):
        logger.info("Run daemon")

        self.protocol_util = get_protocol_util()
        self.scvmm_handler = get_scvmm_handler()
        self.resourcedisk_handler = get_resourcedisk_handler()
        self.rdma_handler = get_rdma_handler()
        self.provision_handler = get_provision_handler()
        self.update_handler = get_update_handler()

        # Create lib dir
        if not os.path.isdir(conf.get_lib_dir()):
            fileutil.mkdir(conf.get_lib_dir(), mode=0o700)
            os.chdir(conf.get_lib_dir())

        if conf.get_detect_scvmm_env():
            self.scvmm_handler.run()

        if conf.get_resourcedisk_format():
            self.resourcedisk_handler.run()

        # Always redetermine the protocol start (e.g., wireserver vs.
        # on-premise) since a VHD can move between environments        
        self.protocol_util.clear_protocol()

        self.provision_handler.run()

        # Enable RDMA, continue in errors
        if conf.enable_rdma():
            self.rdma_handler.install_driver()

            logger.info("RDMA capabilities are enabled in configuration")
            try:
                # Ensure the most recent SharedConfig is available
                # - Changes to RDMA state may not increment the goal state
                #   incarnation number. A forced update ensures the most
                #   current values.
                protocol = self.protocol_util.get_protocol()
                client = protocol.client
                if client is None or type(client) is not WireClient:
                    raise Exception("Attempt to setup RDMA without Wireserver")
                client.update_goal_state(forced=True)

                setup_rdma_device()
            except Exception as e:
                logger.error("Error setting up rdma device: %s" % e)
        else:
            logger.info("RDMA capabilities are not enabled, skipping")

        while self.running:
            self.update_handler.run_latest(child_args=child_args)
Beispiel #19
0
    def daemon(self, child_args=None):
        logger.info("Run daemon")

        self.protocol_util = get_protocol_util()
        self.scvmm_handler = get_scvmm_handler()
        self.resourcedisk_handler = get_resourcedisk_handler()
        self.rdma_handler = get_rdma_handler()
        self.provision_handler = get_provision_handler()
        self.update_handler = get_update_handler()

        # Create lib dir
        if not os.path.isdir(conf.get_lib_dir()):
            fileutil.mkdir(conf.get_lib_dir(), mode=0o700)
            os.chdir(conf.get_lib_dir())

        if conf.get_detect_scvmm_env():
            self.scvmm_handler.run()

        if conf.get_resourcedisk_format():
            self.resourcedisk_handler.run()

        # Always redetermine the protocol start (e.g., wireserver vs.
        # on-premise) since a VHD can move between environments        
        self.protocol_util.clear_protocol()

        self.provision_handler.run()

        # Enable RDMA, continue in errors
        if conf.enable_rdma():
            self.rdma_handler.install_driver()

            logger.info("RDMA capabilities are enabled in configuration")
            try:
                # Ensure the most recent SharedConfig is available
                # - Changes to RDMA state may not increment the goal state
                #   incarnation number. A forced update ensures the most
                #   current values.
                protocol = self.protocol_util.get_protocol()
                client = protocol.client
                if client is None or type(client) is not WireClient:
                    raise Exception("Attempt to setup RDMA without Wireserver")
                client.update_goal_state(forced=True)

                setup_rdma_device()
            except Exception as e:
                logger.error("Error setting up rdma device: %s" % e)
        else:
            logger.info("RDMA capabilities are not enabled, skipping")

        while self.running:
            self.update_handler.run_latest(child_args=child_args)
Beispiel #20
0
    def __init__(self):
        self.osutil = get_osutil()
        self.protocol_util = get_protocol_util()

        self.running = True
        self.last_attempt_time = None

        self.agents = []

        self.child_agent = None
        self.child_launch_time = None
        self.child_launch_attempts = 0
        self.child_process = None

        self.signal_handler = None
Beispiel #21
0
    def __init__(self):
        self.osutil = get_osutil()
        self.protocol_util = get_protocol_util()

        self.running = True
        self.last_attempt_time = None

        self.agents = []

        self.child_agent = None
        self.child_launch_time = None
        self.child_launch_attempts = 0
        self.child_process = None

        self.signal_handler = None
    def test_endpoint_file_states(self, mock_get_lib_dir, mock_fileutil, _):
        mock_get_lib_dir.return_value = self.tmp_dir
        mock_fileutil = MagicMock()

        protocol_util = get_protocol_util()
        endpoint_file = protocol_util._get_wireserver_endpoint_file_path()

        # Test get endpoint for io error
        mock_fileutil.read_file.side_effect = IOError()

        ep = protocol_util.get_wireserver_endpoint()
        self.assertEquals(ep, KNOWN_WIRESERVER_IP)

        # Test get endpoint when file not found
        mock_fileutil.read_file.side_effect = IOError(ENOENT, 'File not found')

        ep = protocol_util.get_wireserver_endpoint()
        self.assertEquals(ep, KNOWN_WIRESERVER_IP)

        # Test get endpoint for empty file
        mock_fileutil.read_file.return_value = ""

        ep = protocol_util.get_wireserver_endpoint()
        self.assertEquals(ep, KNOWN_WIRESERVER_IP)

        # Test set endpoint for io error
        mock_fileutil.write_file.side_effect = IOError()

        ep = protocol_util.get_wireserver_endpoint()
        self.assertRaises(OSUtilError,
                          protocol_util._set_wireserver_endpoint('abc'))

        # Test clear endpoint for io error
        with open(endpoint_file, "w+") as ep_fd:
            ep_fd.write("")

        with patch('os.remove') as mock_remove:
            protocol_util._clear_wireserver_endpoint()
            self.assertEqual(1, mock_remove.call_count)
            self.assertEqual(endpoint_file,
                             mock_remove.call_args_list[0][0][0])

        # Test clear endpoint when file not found
        with patch('os.remove') as mock_remove:
            mock_remove = Mock(side_effect=IOError(ENOENT, 'File not found'))
            protocol_util._clear_wireserver_endpoint()
            mock_remove.assert_not_called()
Beispiel #23
0
    def __init__(self):
        self.osutil = get_osutil()
        self.protocol_util = get_protocol_util()
        self.imds_client = get_imds_client()

        self.event_thread = None
        self.last_event_collection = None
        self.last_telemetry_heartbeat = None
        self.last_host_plugin_heartbeat = None
        self.protocol = None
        self.health_service = None

        self.counter = 0
        self.sysinfo = []
        self.should_run = True
        self.heartbeat_id = str(uuid.uuid4()).upper()
        self.host_plugin_errorstate = ErrorState(min_timedelta=MonitorHandler.HOST_PLUGIN_HEALTH_PERIOD)
Beispiel #24
0
    def daemon(self):
        logger.info("Run daemon")

        self.protocol_util = get_protocol_util()
        self.scvmm_handler = get_scvmm_handler()
        self.resourcedisk_handler = get_resourcedisk_handler()
        self.rdma_handler = get_rdma_handler()
        self.provision_handler = get_provision_handler()
        self.update_handler = get_update_handler()

        # Create lib dir
        if not os.path.isdir(conf.get_lib_dir()):
            fileutil.mkdir(conf.get_lib_dir(), mode=0o700)
            os.chdir(conf.get_lib_dir())

        if conf.get_detect_scvmm_env():
            self.scvmm_handler.run()

        if conf.get_resourcedisk_format():
            self.resourcedisk_handler.run()

        # Always redetermine the protocol start (e.g., wireserver vs.
        # on-premise) since a VHD can move between environments        
        self.protocol_util.clear_protocol()

        self.provision_handler.run()

        # Enable RDMA, continue in errors
        if conf.enable_rdma():
            self.rdma_handler.install_driver()

            logger.info("RDMA capabilities are enabled in configuration")
            try:
                setup_rdma_device()
            except Exception as e:
                logger.error("Error setting up rdma device: %s" % e)
        else:
            logger.info("RDMA capabilities are not enabled, skipping")

        while self.running:
            self.update_handler.run_latest()
Beispiel #25
0
    def daemon(self):
        logger.info("Run daemon")

        self.protocol_util = get_protocol_util()
        self.scvmm_handler = get_scvmm_handler()
        self.resourcedisk_handler = get_resourcedisk_handler()
        self.rdma_handler = get_rdma_handler()
        self.provision_handler = get_provision_handler()
        self.update_handler = get_update_handler()

        # Create lib dir
        if not os.path.isdir(conf.get_lib_dir()):
            fileutil.mkdir(conf.get_lib_dir(), mode=0o700)
            os.chdir(conf.get_lib_dir())

        if conf.get_detect_scvmm_env():
            self.scvmm_handler.run()

        if conf.get_resourcedisk_format():
            self.resourcedisk_handler.run()

        # Always redetermine the protocol start (e.g., wireserver vs.
        # on-premise) since a VHD can move between environments
        self.protocol_util.clear_protocol()

        self.provision_handler.run()

        # Enable RDMA, continue in errors
        if conf.enable_rdma():
            self.rdma_handler.install_driver()

            logger.info("RDMA capabilities are enabled in configuration")
            try:
                setup_rdma_device()
            except Exception as e:
                logger.error("Error setting up rdma device: %s" % e)
        else:
            logger.info("RDMA capabilities are not enabled, skipping")

        while self.running:
            self.update_handler.run_latest()
Beispiel #26
0
    def __init__(self):
        self.osutil = get_osutil()
        self.protocol_util = get_protocol_util()
        self.imds_client = get_imds_client()

        self.event_thread = None
        self.last_event_collection = None
        self.last_telemetry_heartbeat = None
        self.last_cgroup_telemetry = None
        self.last_host_plugin_heartbeat = None
        self.last_imds_heartbeat = None
        self.protocol = None
        self.health_service = None
        self.last_route_table_hash = b''

        self.counter = 0
        self.sysinfo = []
        self.should_run = True
        self.heartbeat_id = str(uuid.uuid4()).upper()
        self.host_plugin_errorstate = ErrorState(min_timedelta=MonitorHandler.HOST_PLUGIN_HEALTH_PERIOD)
        self.imds_errorstate = ErrorState(min_timedelta=MonitorHandler.IMDS_HEALTH_PERIOD)
    def test_detect_protocol_by_file(self, _):
        protocol_util = get_protocol_util()
        protocol_util._detect_wire_protocol = Mock()
        protocol_util._detect_metadata_protocol = Mock()

        tag_file = os.path.join(self.tmp_dir, TAG_FILE_NAME)

        #Test tag file doesn't exist
        protocol_util.get_protocol(by_file=True)
        protocol_util._detect_wire_protocol.assert_any_call()
        protocol_util._detect_metadata_protocol.assert_not_called()

        #Test tag file exists
        protocol_util.clear_protocol()
        protocol_util._detect_wire_protocol.reset_mock()
        protocol_util._detect_metadata_protocol.reset_mock()
        with open(tag_file, "w+") as tag_fd:
            tag_fd.write("")

        protocol_util.get_protocol(by_file=True)
        protocol_util._detect_metadata_protocol.assert_any_call()
        protocol_util._detect_wire_protocol.assert_not_called()
    def test_detect_protocol_by_file(self, _):
        protocol_util = get_protocol_util()
        protocol_util._detect_wire_protocol = Mock()
        protocol_util._detect_metadata_protocol = Mock()

        tag_file = os.path.join(self.tmp_dir, TAG_FILE_NAME)

        #Test tag file doesn't exist
        protocol_util.get_protocol(by_file=True)
        protocol_util._detect_wire_protocol.assert_any_call()
        protocol_util._detect_metadata_protocol.assert_not_called()

        #Test tag file exists
        protocol_util.clear_protocol()
        protocol_util._detect_wire_protocol.reset_mock()
        protocol_util._detect_metadata_protocol.reset_mock()
        with open(tag_file, "w+") as tag_fd:
            tag_fd.write("")

        protocol_util.get_protocol(by_file=True)
        protocol_util._detect_metadata_protocol.assert_any_call()
        protocol_util._detect_wire_protocol.assert_not_called()
    def test_get_protocol(self, WireProtocol, MetadataProtocol, _):
        WireProtocol.return_value = MagicMock()
        MetadataProtocol.return_value = MagicMock()

        protocol_util = get_protocol_util()
        protocol_util.get_wireserver_endpoint = Mock()
        protocol_util._detect_protocol = MagicMock()

        # Test for wire protocol
        protocol_util._save_protocol("WireProtocol")

        protocol = protocol_util.get_protocol()
        self.assertEquals(WireProtocol.return_value, protocol)
        protocol_util.get_wireserver_endpoint.assert_any_call()

        # Test to ensure protocol persists
        protocol_util.get_wireserver_endpoint.reset_mock()
        protocol_util._save_protocol("MetadataProtocol")

        protocol = protocol_util.get_protocol()
        self.assertEquals(WireProtocol.return_value, protocol)
        protocol_util.get_wireserver_endpoint.assert_not_called()

        # Test for metadata protocol
        protocol_util.clear_protocol()
        protocol_util._save_protocol("MetadataProtocol")

        protocol = protocol_util.get_protocol()
        self.assertEquals(MetadataProtocol.return_value, protocol)
        protocol_util.get_wireserver_endpoint.assert_not_called()

        # Test for unknown protocol
        protocol_util.clear_protocol()
        protocol_util._save_protocol("Not_a_Protocol")
        protocol_util._detect_protocol.side_effect = NotImplementedError()

        self.assertRaises(NotImplementedError, protocol_util.get_protocol)
        protocol_util.get_wireserver_endpoint.assert_not_called()
Beispiel #30
0
 def __init__(self):
     self.osutil = get_osutil()
     self.protocol_util = get_protocol_util()
     self.actions_running = False
     signal.signal(signal.SIGINT, self.handle_interrupt_signal)
Beispiel #31
0
 def __init__(self):
     self.osutil = get_osutil()
     self.protocol_util = get_protocol_util()
     signal.signal(signal.SIGINT, self.handle_interrupt_signal)
Beispiel #32
0
 def __init__(self):
     self.osutil = get_osutil()
     self.protocol_util = get_protocol_util()
     self.actions_running = False
     signal.signal(signal.SIGINT, self.handle_interrupt_signal)
Beispiel #33
0
 def __init__(self):
     self.osutil = get_osutil()
     self.protocol_util = get_protocol_util()
     self.sysinfo = []
Beispiel #34
0
 def __init__(self):
     self.osutil = get_osutil()
     self.protocol_util = get_protocol_util()
Beispiel #35
0
 def __init__(self):
     self.osutil = get_osutil()
     self.protocol_util = get_protocol_util()
     self.sysinfo = []
     self.event_thread = None