Ejemplo n.º 1
0
    def test_boot_runcommand_delete(self):
        with log.LogCatcher(utils.LOG) as catcher:
            self.scenario.boot_runcommand_delete(
                "foo_image", "foo_flavor",
                script="foo_script", interpreter="foo_interpreter",
                username="******",
                password="******",
                use_floating_ip="use_fip",
                floating_network="ext_network",
                force_delete="foo_force",
                volume_args={"size": 16},
                foo_arg="foo_value")

        catcher.assertInLogs(
            "Use `command' argument instead (args `script', `interpreter' "
            "deprecated in Rally v0.0.5)")

        self.scenario._create_volume.assert_called_once_with(
            16, imageRef=None)
        self.scenario._boot_server_with_fip.assert_called_once_with(
            "foo_image", "foo_flavor", use_floating_ip="use_fip",
            floating_network="ext_network", key_name="keypair_name",
            block_device_mapping={"vdrally": "foo_volume:::1"},
            foo_arg="foo_value")

        self.scenario._run_command.assert_called_once_with(
            "foo_ip", 22, "foo_username", "foo_password",
            command={"script_file": "foo_script",
                     "interpreter": "foo_interpreter"})
        self.scenario._delete_server_with_fip.assert_called_once_with(
            "foo_server", self.ip, force_delete="foo_force")
Ejemplo n.º 2
0
    def test_assertInLogs_contains(self):
        catcher = log.LogCatcher(self.logger)

        record_mock = mock.MagicMock()
        self.catcher_handler.return_value.buffer = [record_mock]
        record_mock.msg.__contains__.return_value = True
        self.assertEqual([record_mock.msg], catcher.assertInLogs("foo"))

        record_mock.msg.__contains__.assert_called_once_with("foo")
Ejemplo n.º 3
0
    def test_logcatcher(self):
        LOG = log.getLogger("testlogger")
        LOG.logger.setLevel(log.INFO)

        with log.LogCatcher(LOG) as catcher:
            LOG.warning("Warning")
            LOG.info("Info")
            LOG.debug("Debug")

        catcher.assertInLogs("Warning")
        self.assertRaises(AssertionError, catcher.assertInLogs, "Error")

        self.assertEqual(["Warning", "Info"], catcher.fetchLogs())
        self.assertEqual(2, len(catcher.fetchLogRecords()))
Ejemplo n.º 4
0
    def test_fetchLogs(self):
        catcher = log.LogCatcher(self.logger)

        self.assertEqual(
            [r.msg for r in self.catcher_handler.return_value.buffer],
            catcher.fetchLogs())
Ejemplo n.º 5
0
    def test_fetchLogRecords(self):
        catcher = log.LogCatcher(self.logger)

        self.assertEqual(self.catcher_handler.return_value.buffer,
                         catcher.fetchLogRecords())
Ejemplo n.º 6
0
    def test_assertInLogs(self):
        catcher = log.LogCatcher(self.logger)

        self.assertEqual(["foo"], catcher.assertInLogs("foo"))
        self.assertEqual(["bar"], catcher.assertInLogs("bar"))
        self.assertRaises(AssertionError, catcher.assertInLogs, "foobar")
Ejemplo n.º 7
0
    def test_exit(self):
        catcher = log.LogCatcher(self.logger)

        catcher.__exit__(None, None, None)
        self.logger.logger.removeHandler.assert_called_once_with(
            self.catcher_handler.return_value)
Ejemplo n.º 8
0
    def test_enter(self):
        catcher = log.LogCatcher(self.logger)

        self.assertEqual(catcher, catcher.__enter__())
        self.logger.logger.addHandler.assert_called_once_with(
            self.catcher_handler.return_value)
Ejemplo n.º 9
0
    def test_init(self):
        catcher = log.LogCatcher(self.logger)

        self.assertEqual(self.logger.logger, catcher.logger)
        self.assertEqual(self.catcher_handler.return_value, catcher.handler)
        self.catcher_handler.assert_called_once_with()