Switch openstack console log show operation to use OpenStackSDK
A short switch onto SDK for fetching console logs of the server Change-Id: I3f750ea4f13a4e72272aa67ea4506bd7182b13f9
This commit is contained in:
parent
99b5adf9c6
commit
74db8dd65d
@ -44,19 +44,18 @@ class ShowConsoleLog(command.Command):
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
compute_client = self.app.client_manager.compute
|
||||
compute_client = self.app.client_manager.sdk_connection.compute
|
||||
|
||||
server = utils.find_resource(
|
||||
compute_client.servers,
|
||||
parsed_args.server,
|
||||
server = compute_client.find_server(
|
||||
name_or_id=parsed_args.server,
|
||||
ignore_missing=False
|
||||
)
|
||||
length = parsed_args.lines
|
||||
if length:
|
||||
# NOTE(dtroyer): get_console_output() appears to shortchange the
|
||||
# output by one line
|
||||
length += 1
|
||||
|
||||
data = server.get_console_output(length=length)
|
||||
output = compute_client.get_server_console_output(
|
||||
server.id, length=parsed_args.lines)
|
||||
data = None
|
||||
if output:
|
||||
data = output.get('output', None)
|
||||
|
||||
if data and data[-1] != '\n':
|
||||
data += '\n'
|
||||
|
@ -17,16 +17,95 @@ from unittest import mock
|
||||
|
||||
from openstackclient.compute.v2 import console
|
||||
from openstackclient.tests.unit.compute.v2 import fakes as compute_fakes
|
||||
from openstackclient.tests.unit import utils
|
||||
|
||||
|
||||
class TestConsole(compute_fakes.TestComputev2):
|
||||
|
||||
def setUp(self):
|
||||
super(TestConsole, self).setUp()
|
||||
|
||||
# SDK mock
|
||||
self.app.client_manager.sdk_connection = mock.Mock()
|
||||
self.app.client_manager.sdk_connection.compute = mock.Mock()
|
||||
self.sdk_client = self.app.client_manager.sdk_connection.compute
|
||||
self.sdk_client.find_server = mock.Mock()
|
||||
self.sdk_client.get_server_console_output = mock.Mock()
|
||||
|
||||
self.servers_mock = self.app.client_manager.compute.servers
|
||||
self.servers_mock.reset_mock()
|
||||
|
||||
|
||||
class TestConsoleLog(TestConsole):
|
||||
_server = compute_fakes.FakeServer.create_one_server()
|
||||
|
||||
def setUp(self):
|
||||
super(TestConsoleLog, self).setUp()
|
||||
|
||||
self.sdk_client.find_server.return_value = self._server
|
||||
|
||||
self.cmd = console.ShowConsoleLog(self.app, None)
|
||||
|
||||
def test_show_no_args(self):
|
||||
arglist = [
|
||||
]
|
||||
verifylist = [
|
||||
]
|
||||
self.assertRaises(utils.ParserException,
|
||||
self.check_parser,
|
||||
self.cmd,
|
||||
arglist,
|
||||
verifylist)
|
||||
|
||||
def test_show(self):
|
||||
arglist = [
|
||||
'fake_server'
|
||||
]
|
||||
verifylist = [
|
||||
('server', 'fake_server')
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
output = {
|
||||
'output': '1st line\n2nd line\n'
|
||||
}
|
||||
self.sdk_client.get_server_console_output.return_value = output
|
||||
self.cmd.take_action(parsed_args)
|
||||
|
||||
self.sdk_client.find_server.assert_called_with(
|
||||
name_or_id='fake_server', ignore_missing=False)
|
||||
self.sdk_client.get_server_console_output.assert_called_with(
|
||||
self._server.id,
|
||||
length=None
|
||||
)
|
||||
stdout = self.app.stdout.content
|
||||
self.assertEqual(stdout[0], output['output'])
|
||||
|
||||
def test_show_lines(self):
|
||||
arglist = [
|
||||
'fake_server',
|
||||
'--lines', '15'
|
||||
]
|
||||
verifylist = [
|
||||
('server', 'fake_server'),
|
||||
('lines', 15)
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
output = {
|
||||
'output': '1st line\n2nd line'
|
||||
}
|
||||
self.sdk_client.get_server_console_output.return_value = output
|
||||
self.cmd.take_action(parsed_args)
|
||||
|
||||
self.sdk_client.find_server.assert_called_with(
|
||||
name_or_id='fake_server', ignore_missing=False)
|
||||
self.sdk_client.get_server_console_output.assert_called_with(
|
||||
self._server.id,
|
||||
length=15
|
||||
)
|
||||
|
||||
|
||||
class TestConsoleUrlShow(TestConsole):
|
||||
|
||||
def setUp(self):
|
||||
|
@ -0,0 +1,4 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Switch console logs operation to use SDK
|
Loading…
Reference in New Issue
Block a user