コード例 #1
0
 def setUp(self):
     super(ProcessesTest, self).setUp()
     self.fake_proc = self.makeDir()
     self.processes = Processes(proc_dir=self.fake_proc)
     self.sysinfo = SysInfoPluginRegistry()
     self.sysinfo.add(self.processes)
     self.builder = ProcessDataBuilder(self.fake_proc)
コード例 #2
0
 def setUp(self):
     super(SysInfoPluginRegistryTest, self).setUp()
     self.sysinfo = SysInfoPluginRegistry()
     self.sysinfo_logfile = StringIO()
     self.handler = StreamHandler(self.sysinfo_logfile)
     self.logger = getLogger("landscape-sysinfo")
     self.logger.addHandler(self.handler)
コード例 #3
0
    def setUp(self):
        super(DiskTest, self).setUp()
        self.mount_file = self.makeFile("")
        self.stat_results = {}

        self.disk = Disk(mounts_file=self.mount_file,
                         statvfs=self.stat_results.get)
        self.sysinfo = SysInfoPluginRegistry()
        self.sysinfo.add(self.disk)
コード例 #4
0
def run(args, reactor=None, sysinfo=None):
    """
    @param reactor: The reactor to (optionally) run the sysinfo plugins in.
    """
    try:
        setup_logging()
    except IOError as e:
        sys.exit("Unable to setup logging. %s" % e)

    if sysinfo is None:
        sysinfo = SysInfoPluginRegistry()
    config = SysInfoConfiguration()
    # landscape-sysinfo needs to work where there's no
    # /etc/landscape/client.conf See lp:1293990
    config.load(args, accept_nonexistent_default_config=True)
    for plugin in config.get_plugins():
        sysinfo.add(plugin)

    def show_output(result):
        print(
            format_sysinfo(sysinfo.get_headers(),
                           sysinfo.get_notes(),
                           sysinfo.get_footnotes(),
                           indent="  "))

    def run_sysinfo():
        return sysinfo.run().addCallback(show_output)

    if reactor is not None:
        # In case any plugins run processes or do other things that require the
        # reactor to already be started, we delay them until the reactor is
        # running.
        done = Deferred()
        reactor.callWhenRunning(
            lambda: maybeDeferred(run_sysinfo).chainDeferred(done))

        def stop_reactor(result):
            # We won't need to use callLater here once we use Twisted >8.
            # tm:3011
            reactor.callLater(0, reactor.stop)
            return result

        done.addBoth(stop_reactor)
        reactor.run()
    else:
        done = run_sysinfo()
    return done
コード例 #5
0
    def test_stop_reactor_even_when_sync_exception_from_sysinfo_run(self):
        """
        Even when there's a synchronous exception from run_sysinfo, the reactor
        should be stopped.
        """
        self.log_helper.ignore_errors(ZeroDivisionError)
        reactor = FakeReactor()
        sysinfo = SysInfoPluginRegistry()
        sysinfo.run = lambda: 1 / 0
        d = run(["--sysinfo-plugins", "TestPlugin"], reactor=reactor,
                sysinfo=sysinfo)

        for x in reactor.queued_calls:
            x()

        self.assertEqual(reactor.scheduled_calls, [(0, reactor.stop, (), {})])
        return self.assertFailure(d, ZeroDivisionError)
コード例 #6
0
    def test_output_is_only_displayed_once_deferred_fires(self):
        deferred = Deferred()

        # We mock the sysinfo.run() to return a Deferred but still
        # run the actual sysinfo.run() to gather the results from all
        # the plugins.  We cannot easily combine return_value and
        # side_effect because side_effect operates on the return_value,
        # thus firing the callback and writing sysinfo out to stdout.
        sysinfo = SysInfoPluginRegistry()
        original_sysinfo_run = sysinfo.run

        def wrapped_sysinfo_run(*args, **kwargs):
            original_sysinfo_run(*args, **kwargs)
            return deferred
        sysinfo.run = mock.Mock(side_effect=wrapped_sysinfo_run)

        run(["--sysinfo-plugins", "TestPlugin"], sysinfo=sysinfo)

        sysinfo.run.assert_called_once_with()

        self.assertNotIn("Test note", self.stdout.getvalue())
        deferred.callback(None)
        self.assertIn("Test note", self.stdout.getvalue())
コード例 #7
0
 def setUp(self):
     super(NetworkTest, self).setUp()
     self.result = []
     self.network = Network(lambda: self.result)
     self.sysinfo = SysInfoPluginRegistry()
     self.sysinfo.add(self.network)
コード例 #8
0
 def setUp(self):
     super(TemperatureTest, self).setUp()
     self.temperature = Temperature(self.thermal_zone_path)
     self.sysinfo = SysInfoPluginRegistry()
     self.sysinfo.add(self.temperature)
コード例 #9
0
 def setUp(self):
     super(LoggedInUsersTest, self).setUp()
     self.logged_users = LoggedInUsers()
     self.sysinfo = SysInfoPluginRegistry()
     self.sysinfo.add(self.logged_users)
コード例 #10
0
 def setUp(self):
     super(MemoryTest, self).setUp()
     self.memory = Memory(self.makeFile(MEMINFO_SAMPLE))
     self.sysinfo = SysInfoPluginRegistry()
     self.sysinfo.add(self.memory)
コード例 #11
0
 def setUp(self):
     super(LandscapeLinkTest, self).setUp()
     self.landscape_link = LandscapeLink()
     self.sysinfo = SysInfoPluginRegistry()
     self.sysinfo.add(self.landscape_link)
コード例 #12
0
                                  maxBytes=500 * 1024, backupCount=1)
    logger.addHandler(handler)
    handler.setFormatter(Formatter("%(asctime)s %(levelname)-8s %(message)s"))


def run(args, reactor=None, sysinfo=None):
    """
    @param reactor: The reactor to (optionally) run the sysinfo plugins in.
    """
    try:
        setup_logging()
    except IOError, e:
        sys.exit("Unable to setup logging. %s" % e)

    if sysinfo is None:
        sysinfo = SysInfoPluginRegistry()
    config = SysInfoConfiguration()
    # landscape-sysinfo needs to work where there's no
    # /etc/landscape/client.conf See lp:1293990
    config.load(args, accept_nonexistent_default_config=True)
    for plugin in config.get_plugins():
        sysinfo.add(plugin)

    def show_output(result):
        print format_sysinfo(sysinfo.get_headers(), sysinfo.get_notes(),
                             sysinfo.get_footnotes(), indent="  ")

    def run_sysinfo():
        return sysinfo.run().addCallback(show_output)

    if reactor is not None: