[admin_user]: More cleanups. Remove uneeded tests.

Signed-off-by: Manoj Srivastava <srivasta@golden-gryphon.com>
This commit is contained in:
Manoj Srivastava 2016-02-06 02:15:52 -08:00
parent efeddc43a8
commit 32ef6fc571
No known key found for this signature in database
GPG key ID: 36BD720F6F576472
2 changed files with 11 additions and 14 deletions

View file

@ -7,10 +7,11 @@ def validate_manifest(data, validator, error):
if ('password' in data['plugins']['admin_user'] and 'pubkey' in data['plugins']['admin_user']): if ('password' in data['plugins']['admin_user'] and 'pubkey' in data['plugins']['admin_user']):
msg = 'passwd and pubkey are mutually exclusive.' msg = 'passwd and pubkey are mutually exclusive.'
error(msg, ['plugins', 'admin_user']) error(msg, ['plugins', 'admin_user'])
full_path = data['plugins']['admin_user']['pubkey'] if 'pubkey' in data['plugins']['admin_user']:
if not os.path.exists(full_path): full_path = data['plugins']['admin_user']['pubkey']
msg = 'Could not find public key at %s' % full_path if not os.path.exists(full_path):
error(msg, ['plugins', 'admin_user']) msg = 'Could not find public key at %s' % full_path
error(msg, ['plugins', 'admin_user'])
def resolve_tasks(taskset, manifest): def resolve_tasks(taskset, manifest):

View file

@ -90,10 +90,10 @@ class AdminUserCredentialsPublicKey(Task):
username = info.manifest.plugins['admin_user']['username'] username = info.manifest.plugins['admin_user']['username']
ssh_file = os.path.join('/home/', username, '.ssh/authorized_keys') ssh_file = os.path.join('/home/', username, '.ssh/authorized_keys')
rel_ssh_file = os.path.realpath(info.root + '/%s' % ssh_file) rel_ssh_file = os.path.join(info.root, ssh_file)
ssh_dir = os.path.dirname(ssh_file) ssh_dir = os.path.dirname(ssh_file)
rel_ssh_dir = os.path.realpath(info.root + '/%s' % ssh_dir) rel_ssh_dir = os.path.join(info.root, ssh_dir)
if not os.path.exists(rel_ssh_dir): if not os.path.exists(rel_ssh_dir):
log.debug('Creating %s.' % rel_ssh_dir) log.debug('Creating %s.' % rel_ssh_dir)
os.mkdir(rel_ssh_dir) os.mkdir(rel_ssh_dir)
@ -118,15 +118,11 @@ class AdminUserCredentialsEC2(Task):
@classmethod @classmethod
def run(cls, info): def run(cls, info):
from bootstrapvz.common.exceptions import TaskError
from bootstrapvz.common.tools import sed_i from bootstrapvz.common.tools import sed_i
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
getcreds_path = os.path.join(info.root, 'etc/init.d/ec2-get-credentials') getcreds_path = os.path.join(info.root, 'etc/init.d/ec2-get-credentials')
if os.path.exists(getcreds_path): log.debug('Updating EC2 get credentials script.')
log.debug('Updating EC2 get credentials script.') username = info.manifest.plugins['admin_user']['username']
username = info.manifest.plugins['admin_user']['username'] sed_i(getcreds_path, "username='root'",
sed_i(getcreds_path, "username='root'", "username='{username}'".format(username=username))
"username='{username}'".format(username=username))
else:
raise TaskError('Could not find EC2 get credentials script.')