mirror of
https://github.com/ansible/awx.git
synced 2024-11-01 08:21:15 +03:00
testable playbook w/ state wanted pattern
* remove complicated redis config assembly * backup and restore discover credentials rather than requiring * backup strategy no longer drops the db. This allows awx user to restore without creatdb persmission. * removed mongo from backup/restore * added password change support for redis, pg, munin * added update_password command and respective tests * tests for munin, pg, redis password change * unit tests for munin, redis password change * tests for postgres host (ip and socket) change * tests for postgres backup/restore on remote db
This commit is contained in:
parent
abecbb3ed1
commit
fe91c73fd2
45
awx/main/management/commands/update_password.py
Normal file
45
awx/main/management/commands/update_password.py
Normal file
@ -0,0 +1,45 @@
|
||||
# Copyright (c) 2016 Ansible, Inc.
|
||||
# All Rights Reserved
|
||||
|
||||
# Python
|
||||
from optparse import make_option
|
||||
|
||||
# Django
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.core.management.base import CommandError
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
class UpdatePassword(object):
|
||||
def update_password(self, username, password):
|
||||
changed = False
|
||||
u = User.objects.get(username=username)
|
||||
if not u:
|
||||
raise RuntimeError("User not found")
|
||||
check = u.check_password(password)
|
||||
if not check:
|
||||
u.set_password(password)
|
||||
u.save()
|
||||
changed = True
|
||||
return changed
|
||||
|
||||
class Command(BaseCommand):
|
||||
option_list = BaseCommand.option_list + (
|
||||
make_option('--username', dest='username', action='store', type='string', default=None,
|
||||
help='username to change the password for'),
|
||||
make_option('--password', dest='password', action='store', type='string', default=None,
|
||||
help='new password for user'),
|
||||
)
|
||||
|
||||
def handle(self, *args, **options):
|
||||
if not options['username']:
|
||||
raise CommandError('username required')
|
||||
if not options['password']:
|
||||
raise CommandError('password required')
|
||||
|
||||
cp = UpdatePassword()
|
||||
res = cp.update_password(options['username'], options['password'])
|
||||
if res:
|
||||
return "Password updated"
|
||||
return "Password not updated"
|
||||
|
||||
|
@ -9,4 +9,5 @@ from .cleanup_facts import * # noqa
|
||||
from .age_deleted import * # noqa
|
||||
from .remove_instance import * # noqa
|
||||
from .run_socketio_service import * # noqa
|
||||
from .update_password import * # noqa
|
||||
|
||||
|
37
awx/main/tests/commands/update_password.py
Normal file
37
awx/main/tests/commands/update_password.py
Normal file
@ -0,0 +1,37 @@
|
||||
# Copyright (c) 2015 Ansible, Inc.
|
||||
# All Rights Reserved
|
||||
|
||||
# AWX
|
||||
from awx.main.tests.base import BaseTest
|
||||
from awx.main.tests.commands.base import BaseCommandMixin
|
||||
|
||||
# Django
|
||||
from django.core.management.base import CommandError
|
||||
|
||||
__all__ = ['UpdatePasswordCommandFunctionalTest']
|
||||
|
||||
class UpdatePasswordCommandFunctionalTest(BaseCommandMixin, BaseTest):
|
||||
def setUp(self):
|
||||
super(UpdatePasswordCommandFunctionalTest, self).setUp()
|
||||
self.create_test_license_file()
|
||||
self.setup_instances()
|
||||
self.setup_users()
|
||||
|
||||
def test_updated_ok(self):
|
||||
result, stdout, stderr = self.run_command('update_password', username='admin', password='dingleberry')
|
||||
self.assertEqual(stdout, 'Password updated\n')
|
||||
|
||||
def test_same_password(self):
|
||||
result, stdout, stderr = self.run_command('update_password', username='admin', password='admin')
|
||||
self.assertEqual(stdout, 'Password not updated\n')
|
||||
|
||||
def test_error_username_required(self):
|
||||
result, stdout, stderr = self.run_command('update_password', password='foo')
|
||||
self.assertIsInstance(result, CommandError)
|
||||
self.assertEqual(str(result), 'username required')
|
||||
|
||||
def test_error_password_required(self):
|
||||
result, stdout, stderr = self.run_command('update_password', username='admin')
|
||||
self.assertIsInstance(result, CommandError)
|
||||
self.assertEqual(str(result), 'password required')
|
||||
|
Loading…
Reference in New Issue
Block a user