def test_ssh_directory_for_unit(self): self.setup_mocks_ssh_directory_for_unit('nova-compute-lxd', ssh_dir_exists=True, app_dir_exists=True, auth_keys_exists=True, known_hosts_exists=True) self.assertEqual( ssh_migrations.ssh_directory_for_unit('nova-compute-lxd'), '/etc/nova/compute_ssh/nova-compute-lxd') self.assertFalse(self.mkdir.called)
def test_ssh_directory_missing_file(self, _open): self.setup_mocks_ssh_directory_for_unit('nova-compute-lxd', ssh_dir_exists=True, app_dir_exists=True, auth_keys_exists=False, known_hosts_exists=True) self.assertEqual( ssh_migrations.ssh_directory_for_unit('nova-compute-lxd'), '/etc/nova/compute_ssh/nova-compute-lxd') _open.assert_called_once_with( '/etc/nova/compute_ssh/nova-compute-lxd/authorized_keys', 'w') self.assertFalse(self.mkdir.called)
def test_ssh_directory_missing_dirs(self): self.setup_mocks_ssh_directory_for_unit('nova-compute-lxd', ssh_dir_exists=False, app_dir_exists=False, auth_keys_exists=True, known_hosts_exists=True) self.assertEqual( ssh_migrations.ssh_directory_for_unit('nova-compute-lxd'), '/etc/nova/compute_ssh/nova-compute-lxd') mkdir_calls = [ mock.call('/etc/nova/compute_ssh/'), mock.call('/etc/nova/compute_ssh/nova-compute-lxd') ] self.mkdir.assert_has_calls(mkdir_calls)
def test_ssh_directory_missing_files(self, _open): self.setup_mocks_ssh_directory_for_unit('nova-compute-lxd', ssh_dir_exists=True, app_dir_exists=True, auth_keys_exists=False, known_hosts_exists=False) self.assertEqual( ssh_migrations.ssh_directory_for_unit('nova-compute-lxd'), '/etc/nova/compute_ssh/nova-compute-lxd') open_calls = [ mock.call('/etc/nova/compute_ssh/nova-compute-lxd/authorized_keys', 'w'), mock.call().close(), mock.call('/etc/nova/compute_ssh/nova-compute-lxd/known_hosts', 'w'), mock.call().close() ] _open.assert_has_calls(open_calls) self.assertFalse(self.mkdir.called)