Merge "Use public and unified method get_console_url()"

This commit is contained in:
Jenkins 2017-02-20 19:46:15 +00:00 committed by Gerrit Code Review
commit 477694db49
2 changed files with 13 additions and 28 deletions

View File

@ -126,18 +126,7 @@ class ShowConsoleURL(command.ShowOne):
parsed_args.server, parsed_args.server,
) )
data = None data = server.get_console_url(parsed_args.url_type)
if parsed_args.url_type in ['novnc', 'xvpvnc']:
data = server.get_vnc_console(parsed_args.url_type)
if parsed_args.url_type in ['spice-html5']:
data = server.get_spice_console(parsed_args.url_type)
if parsed_args.url_type in ['rdp-html5']:
data = server.get_rdp_console(parsed_args.url_type)
if parsed_args.url_type in ['serial']:
data = server.get_serial_console(parsed_args.url_type)
if parsed_args.url_type in ['webmks']:
data = server.get_mks_console()
if not data: if not data:
return ({}, {}) return ({}, {})

View File

@ -35,11 +35,7 @@ class TestConsoleUrlShow(TestConsole):
'protocol': 'fake_protocol', 'protocol': 'fake_protocol',
'type': 'fake_type'}} 'type': 'fake_type'}}
methods = { methods = {
'get_vnc_console': fake_console_data, 'get_console_url': fake_console_data
'get_spice_console': fake_console_data,
'get_serial_console': fake_console_data,
'get_rdp_console': fake_console_data,
'get_mks_console': fake_console_data,
} }
self.fake_server = compute_fakes.FakeServer.create_one_server( self.fake_server = compute_fakes.FakeServer.create_one_server(
methods=methods) methods=methods)
@ -68,7 +64,7 @@ class TestConsoleUrlShow(TestConsole):
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args) columns, data = self.cmd.take_action(parsed_args)
self.fake_server.get_vnc_console.assert_called_once_with('novnc') self.fake_server.get_console_url.assert_called_once_with('novnc')
self.assertEqual(self.columns, columns) self.assertEqual(self.columns, columns)
self.assertEqual(self.data, data) self.assertEqual(self.data, data)
@ -83,7 +79,7 @@ class TestConsoleUrlShow(TestConsole):
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args) columns, data = self.cmd.take_action(parsed_args)
self.fake_server.get_vnc_console.assert_called_once_with('novnc') self.fake_server.get_console_url.assert_called_once_with('novnc')
self.assertEqual(self.columns, columns) self.assertEqual(self.columns, columns)
self.assertEqual(self.data, data) self.assertEqual(self.data, data)
@ -98,7 +94,7 @@ class TestConsoleUrlShow(TestConsole):
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args) columns, data = self.cmd.take_action(parsed_args)
self.fake_server.get_vnc_console.assert_called_once_with('xvpvnc') self.fake_server.get_console_url.assert_called_once_with('xvpvnc')
self.assertEqual(self.columns, columns) self.assertEqual(self.columns, columns)
self.assertEqual(self.data, data) self.assertEqual(self.data, data)
@ -113,14 +109,14 @@ class TestConsoleUrlShow(TestConsole):
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args) columns, data = self.cmd.take_action(parsed_args)
self.fake_server.get_spice_console.assert_called_once_with( self.fake_server.get_console_url.assert_called_once_with(
'spice-html5') 'spice-html5')
self.assertEqual(self.columns, columns) self.assertEqual(self.columns, columns)
self.assertEqual(self.data, data) self.assertEqual(self.data, data)
def test_console_url_show_compatible(self): def test_console_url_show_compatible(self):
methods = { methods = {
'get_vnc_console': {'console': {'url': 'http://localhost', 'get_console_url': {'console': {'url': 'http://localhost',
'type': 'fake_type'}}, 'type': 'fake_type'}},
} }
old_fake_server = compute_fakes.FakeServer.create_one_server( old_fake_server = compute_fakes.FakeServer.create_one_server(
@ -130,8 +126,8 @@ class TestConsoleUrlShow(TestConsole):
'url', 'url',
) )
old_data = ( old_data = (
methods['get_vnc_console']['console']['type'], methods['get_console_url']['console']['type'],
methods['get_vnc_console']['console']['url'] methods['get_console_url']['console']['url']
) )
arglist = [ arglist = [
'foo_vm', 'foo_vm',
@ -144,7 +140,7 @@ class TestConsoleUrlShow(TestConsole):
with mock.patch.object(self.servers_mock, 'get', with mock.patch.object(self.servers_mock, 'get',
return_value=old_fake_server): return_value=old_fake_server):
columns, data = self.cmd.take_action(parsed_args) columns, data = self.cmd.take_action(parsed_args)
old_fake_server.get_vnc_console.assert_called_once_with('novnc') old_fake_server.get_console_url.assert_called_once_with('novnc')
self.assertEqual(old_columns, columns) self.assertEqual(old_columns, columns)
self.assertEqual(old_data, data) self.assertEqual(old_data, data)
@ -159,7 +155,7 @@ class TestConsoleUrlShow(TestConsole):
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args) columns, data = self.cmd.take_action(parsed_args)
self.fake_server.get_rdp_console.assert_called_once_with( self.fake_server.get_console_url.assert_called_once_with(
'rdp-html5') 'rdp-html5')
self.assertEqual(self.columns, columns) self.assertEqual(self.columns, columns)
self.assertEqual(self.data, data) self.assertEqual(self.data, data)
@ -175,7 +171,7 @@ class TestConsoleUrlShow(TestConsole):
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args) columns, data = self.cmd.take_action(parsed_args)
self.fake_server.get_serial_console.assert_called_once_with( self.fake_server.get_console_url.assert_called_once_with(
'serial') 'serial')
self.assertEqual(self.columns, columns) self.assertEqual(self.columns, columns)
self.assertEqual(self.data, data) self.assertEqual(self.data, data)
@ -191,6 +187,6 @@ class TestConsoleUrlShow(TestConsole):
] ]
parsed_args = self.check_parser(self.cmd, arglist, verifylist) parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args) columns, data = self.cmd.take_action(parsed_args)
self.fake_server.get_mks_console.assert_called_once_with() self.fake_server.get_console_url.assert_called_once_with('webmks')
self.assertEqual(self.columns, columns) self.assertEqual(self.columns, columns)
self.assertEqual(self.data, data) self.assertEqual(self.data, data)