Add specific unit tests for various ssh helper functions
This commit is contained in:
parent
a2a0645a16
commit
cd8fd0a142
@ -364,7 +364,7 @@ def ssh_known_host_key(host, user=None):
|
||||
|
||||
def remove_known_host(host, user=None):
|
||||
log('Removing SSH known host entry for compute host at %s' % host)
|
||||
cmd = ['ssh-kegen', '-f', known_hosts(user), '-R', host]
|
||||
cmd = ['ssh-keygen', '-f', known_hosts(user), '-R', host]
|
||||
subprocess.check_call(cmd)
|
||||
|
||||
|
||||
|
@ -348,7 +348,7 @@ class NovaCCUtilsTests(CharmTestCase):
|
||||
known_hosts.return_value = '/tmp/known_hosts'
|
||||
utils.remove_known_host('foo')
|
||||
check_call.assert_called_with([
|
||||
'ssh-kegen', '-f', known_hosts(), '-R', 'foo'])
|
||||
'ssh-keygen', '-f', known_hosts(), '-R', 'foo'])
|
||||
|
||||
@patch.object(utils, 'authorized_keys')
|
||||
def test_ssh_authorized_key_exists(self, keys):
|
||||
@ -424,3 +424,44 @@ class NovaCCUtilsTests(CharmTestCase):
|
||||
'quantum_service': 'quantum'})
|
||||
self.assertEquals(
|
||||
endpoints, utils.determine_endpoints('http://foohost.com'))
|
||||
|
||||
@patch.object(utils, 'ssh_directory_for_unit')
|
||||
def test_known_hosts(self, _directory):
|
||||
_directory.return_value = '/foo'
|
||||
self.assertTrue(utils.known_hosts(), '/foo/known_hosts')
|
||||
_directory.assert_called_with(None)
|
||||
_directory.return_value = '/bar_foo'
|
||||
self.assertTrue(utils.known_hosts(user='bar'), '/bar_foo/known_hosts')
|
||||
_directory.assert_called_with('bar')
|
||||
|
||||
@patch.object(utils, 'ssh_directory_for_unit')
|
||||
def test_authorized_keys(self, _directory):
|
||||
_directory.return_value = '/foo'
|
||||
self.assertTrue(utils.authorized_keys(), '/foo/authorized_keys')
|
||||
_directory.assert_called_with(None)
|
||||
_directory.return_value = '/bar_foo'
|
||||
self.assertTrue(utils.authorized_keys(user='bar'), '/bar_foo/authorized_keys')
|
||||
_directory.assert_called_with('bar')
|
||||
|
||||
@patch.object(utils, 'known_hosts')
|
||||
@patch('subprocess.check_output')
|
||||
def test_ssh_known_host_key(self, _check_output, _known_hosts):
|
||||
_known_hosts.return_value = '/foo/known_hosts'
|
||||
utils.ssh_known_host_key('test')
|
||||
_check_output.assert_called_with(['ssh-keygen', '-f', '/foo/known_hosts',
|
||||
'-H', '-F', 'test'])
|
||||
_known_hosts.assert_called_with(None)
|
||||
utils.ssh_known_host_key('test', 'bar')
|
||||
_known_hosts.assert_called_with('bar')
|
||||
|
||||
@patch.object(utils, 'known_hosts')
|
||||
@patch('subprocess.check_call')
|
||||
def test_remove_known_host(self, _check_call, _known_hosts):
|
||||
_known_hosts.return_value = '/foo/known_hosts'
|
||||
utils.remove_known_host('test')
|
||||
_check_call.assert_called_with(['ssh-keygen', '-f' , '/foo/known_hosts',
|
||||
'-R', 'test'])
|
||||
_known_hosts.assert_called_with(None)
|
||||
utils.remove_known_host('test', 'bar')
|
||||
_known_hosts.assert_called_with('bar')
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user