示例#1
0
文件: plugin.py 项目: tjjh89017/maas
    def makeService(self, options, clock=reactor):
        """Construct the MAAS Cluster service."""
        register_sigusr1_toggle_cprofile('rackd')
        register_sigusr2_thread_dump_handler()
        clean_prometheus_dir()
        add_patches_to_txtftp()
        add_patches_to_twisted()

        self._loadSettings()
        self._configureCrochet()
        if settings.DEBUG:
            # Always log at debug level in debug mode.
            self._configureLogging(3)
        else:
            self._configureLogging(options["verbosity"])

        with ClusterConfiguration.open() as config:
            tftp_root = config.tftp_root
            tftp_port = config.tftp_port

        from provisioningserver import services
        for service in self._makeServices(tftp_root, tftp_port, clock=clock):
            service.setServiceParent(services)

        return services
示例#2
0
    def makeService(self, options):
        """Construct the MAAS Region service."""
        register_sigusr1_toggle_cprofile("regiond-master")
        register_sigusr2_thread_dump_handler()
        clean_prometheus_dir()

        self._configureThreads()
        self._configureLogging(options["verbosity"])
        self._configureDjango()
        self._configurePservSettings()
        self._configureReactor()
        self._configureCrochet()
        self._ensureConnection()

        # Reconfigure the logging if required.
        self._reconfigureLogging()

        # Populate the region's event-loop with services.
        from maasserver import eventloop

        eventloop.loop.populate(master=True)

        # Return the eventloop's services to twistd, which will then be
        # responsible for starting them all.
        return eventloop.loop.services
示例#3
0
 def test_delete_for_nonexistent_processes(self):
     tmpdir = Path(self.useFixture(TempDirectory()).path)
     pid = os.getpid()
     file1 = tmpdir / 'histogram_1.db'
     file1.touch()
     file2 = tmpdir / 'histogram_{}.db'.format(pid)
     file2.touch()
     file3 = tmpdir / 'histogram_{}.db'.format(self.get_unused_pid())
     file3.touch()
     file4 = tmpdir / 'histogram_{}.db'.format(self.get_unused_pid())
     file4.touch()
     clean_prometheus_dir(str(tmpdir))
     self.assertTrue(file1.exists())
     self.assertTrue(file2.exists())
     self.assertFalse(file3.exists())
     self.assertFalse(file4.exists())
示例#4
0
    def test_delete_file_disappeared(self):
        real_os_remove = os.remove

        def mock_os_remove(path):
            # remove it twice, so that FileNotFoundError is raised
            real_os_remove(path)
            real_os_remove(path)

        self.patch(os, 'remove', mock_os_remove)
        tmpdir = Path(self.useFixture(TempDirectory()).path)
        file1 = tmpdir / 'histogram_{}.db'.format(self.get_unused_pid())
        file1.touch()
        self.assertIsNone(clean_prometheus_dir(str(tmpdir)))
示例#5
0
    def makeService(self, options, clock=reactor, sleep=sleep):
        """Construct the MAAS Cluster service."""
        register_sigusr1_toggle_cprofile("rackd")
        register_sigusr2_thread_dump_handler()
        clean_prometheus_dir()
        add_patches_to_txtftp()
        add_patches_to_twisted()

        self._loadSettings()
        self._configureCrochet()
        if settings.DEBUG:
            # Always log at debug level in debug mode.
            self._configureLogging(3)
        else:
            self._configureLogging(options["verbosity"])

        with ClusterConfiguration.open() as config:
            tftp_root = config.tftp_root
            tftp_port = config.tftp_port

        from provisioningserver import services

        secret = None
        for elapsed, remaining, wait in retries(timeout=5 * 60, clock=clock):
            secret = get_shared_secret_from_filesystem()
            if secret is not None:
                break
            sleep(wait)
        if secret is not None:
            # only setup services if the shared secret is configured
            for service in self._makeServices(tftp_root,
                                              tftp_port,
                                              clock=clock):
                service.setServiceParent(services)

            reactor.callInThread(generate_certificate_if_needed)

        return services
示例#6
0
 def test_env_dir_not_existent(self):
     self.useFixture(
         EnvironmentVariable('prometheus_multiproc_dir', '/not/here'))
     self.assertIsNone(clean_prometheus_dir())
示例#7
0
 def test_env_not_specified(self):
     self.useFixture(EnvironmentVariable('prometheus_multiproc_dir', None))
     self.assertIsNone(clean_prometheus_dir())
示例#8
0
 def test_dir_not_existent(self):
     self.assertIsNone(clean_prometheus_dir('/not/here'))