def manage_ssh_key(nova_client=None): """Create basic flavors. :param nova_client: Authenticated nova client :type nova_client: novaclient.v2.client.Client """ if not nova_client: keystone_session = openstack_utils.get_overcloud_keystone_session() nova_client = openstack_utils.get_nova_session_client(keystone_session) cli_utils.setup_logging() if not openstack_utils.valid_key_exists(nova_client, nova_utils.KEYPAIR_NAME): key = openstack_utils.create_ssh_key(nova_client, nova_utils.KEYPAIR_NAME, replace=True) openstack_utils.write_private_key(nova_utils.KEYPAIR_NAME, key.private_key)
def test_create_ssh_key_existing_replace(self): nova_mock = mock.MagicMock() nova_mock.keypairs.findall.return_value = ['key1'] openstack_utils.create_ssh_key(nova_mock, 'mykeys', replace=True), nova_mock.keypairs.delete.assert_called_once_with('key1') nova_mock.keypairs.create.assert_called_once_with(name='mykeys')
def test_create_ssh_key_existing(self): nova_mock = mock.MagicMock() nova_mock.keypairs.findall.return_value = ['akey'] self.assertEqual(openstack_utils.create_ssh_key(nova_mock, 'mykeys'), 'akey') self.assertFalse(nova_mock.keypairs.create.called)
def test_create_ssh_key(self): nova_mock = mock.MagicMock() nova_mock.keypairs.findall.return_value = [] openstack_utils.create_ssh_key(nova_mock, 'mykeys') nova_mock.keypairs.create.assert_called_once_with(name='mykeys')