Merge lp:~javier.collado/utah/bug1068664 into lp:utah

Proposed by Javier Collado
Status: Rejected
Rejected by: Javier Collado
Proposed branch: lp:~javier.collado/utah/bug1068664
Merge into: lp:utah
Diff against target: 79 lines (+19/-5)
3 files modified
utah/config.py (+1/-0)
utah/provisioning/provisioning.py (+17/-4)
utah/run.py (+1/-1)
To merge this branch: bzr merge lp:~javier.collado/utah/bug1068664
Reviewer Review Type Date Requested Status
Javier Collado (community) Disapprove
Joe Talbott (community) Needs Information
Review via email: mp+130601@code.launchpad.net

Description of the change

This branch changes the utah client command string to execute is as root as
it's required now.

Additional information:
- The way to use as root is to prepend "sudo -S".
- The -S tells sudo to read the password from stdin.
- SSHMixin.run takes care of writing the password to stdin when needed.
  (basically when the paramiko channel is still open after running the command).
- A new configuration variable (config.password) is used to store the password value.
- Support to overwrite the password in the preseed has been added so that the
  password in the preseed is in sync with the code.

To post a comment you must log in.
Revision history for this message
Joe Talbott (joetalbott) wrote :

It seems to me that keeping the method name '_rewrite_passwd_username' is more descriptive since it's setting both the password and username.

Other than that looks good to me.

review: Needs Information
lp:~javier.collado/utah/bug1068664 updated
718. By Javier Collado

Renamed _rewrite_passwd as suggested by joetalbott

Final name is: _rewrite_username_and_passwd

719. By Javier Collado

Changed username and passwd lines changed if any of them exists

The username and password lines in the preseed were changed only
if 'passwd/username' was present. Now, all of them are changed
just if any of the following is available:
- 'passwd/username'
- 'passwd/user-password'
- 'passwd/user-password-again'

Revision history for this message
Max Brustkern (nuclearbob) wrote :

We also install ssh keys under the root user, so we can call the run method of the machine class with root=True to use root instead of using sudo. I think we'd just need to make that change in run.py on line 43. That would mean we wouldn't need to rewrite the password either, since we don't need the password for that. At some point I'd like to move to using an encypted password in the default or rewritten preseed, but I haven't worked on that in a while since it hasn't been high priority.

Revision history for this message
Javier Collado (javier.collado) wrote :

@Max

Looking at the alternative that you suggested.

Revision history for this message
Javier Collado (javier.collado) wrote :

I've created a new merge request with the one line change suggested by Max.

I'm rejecting this proposal, since all the complexity to write root password
to stdin so that sudo receives it isn't needed at all.

review: Disapprove

Unmerged revisions

719. By Javier Collado

Changed username and passwd lines changed if any of them exists

The username and password lines in the preseed were changed only
if 'passwd/username' was present. Now, all of them are changed
just if any of the following is available:
- 'passwd/username'
- 'passwd/user-password'
- 'passwd/user-password-again'

718. By Javier Collado

Renamed _rewrite_passwd as suggested by joetalbott

Final name is: _rewrite_username_and_passwd

717. By Javier Collado

Added password rewritting to the preseed

Given that the previous commit adds a new password field to the configuration
file, this commit adds support to use that value in the preseed as well.

716. By Javier Collado

Updated utah client command to use "sudo -S"

Additional information:
- This is needed because the client needs to be executed as root.
- The -S tells sudo to read the password from stdin.
- A new configuration variable `password` is used to get the password to be
  used.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'utah/config.py'
2--- utah/config.py 2012-10-16 10:46:10 +0000
3+++ utah/config.py 2012-10-22 08:38:22 +0000
4@@ -46,6 +46,7 @@
5 nfscommand=['sudo', os.path.join('/', 'etc', 'init.d', 'nfs-kernel-server'), 'reload'],
6 nfsconfigfile=os.path.join('/', 'etc', 'exports'),
7 nfsoptions='*(ro,async,no_root_squash,no_subtree_check)',
8+ password='!ubuntu123',
9 powertimeout=5,
10 preseed=None,
11 qemupath='qemu:///system',
12
13=== modified file 'utah/provisioning/provisioning.py'
14--- utah/provisioning/provisioning.py 2012-10-16 10:46:10 +0000
15+++ utah/provisioning/provisioning.py 2012-10-22 08:38:22 +0000
16@@ -518,10 +518,14 @@
17 channel = self.ssh_client.get_transport().open_session()
18
19 self.logger.info('Running command through SSH: ' + commandstring)
20+ stdin = channel.makefile('wb')
21 stdout = channel.makefile('rb')
22 stderr = channel.makefile_stderr('rb')
23 if timeout is None:
24 channel.exec_command(commandstring)
25+ if not channel.closed:
26+ stdin.write('{}\n'.format(config.password))
27+ stdin.flush()
28 else:
29 utah.timeout.timeout(timeout, channel.exec_command, commandstring)
30 retval = channel.recv_exit_status()
31@@ -820,8 +824,13 @@
32 self._rewrite_pkgsel_include(preseed)
33 if 'netcfg/get_hostname' in preseed:
34 self._rewrite_get_hostname(preseed)
35- if 'passwd/username' in preseed:
36- self._rewrite_passwd_username(preseed)
37+
38+ username_and_passwd_qnames = ['passwd/username',
39+ 'passwd/user-password',
40+ 'passwd/user-password-again']
41+ if any(qname in preseed
42+ for qname in username_and_passwd_qnames):
43+ self._rewrite_username_and_passwd(preseed)
44
45 output_preseed_filename = os.path.join(tmpdir,
46 'initrd.d', 'preseed.cfg')
47@@ -896,13 +905,17 @@
48 question = preseed['netcfg/get_hostname']
49 question.value = self.name
50
51- def _rewrite_passwd_username(self, preseed):
52+ def _rewrite_username_and_passwd(self, preseed):
53 """
54- Set password properly in the preseed
55+ Set username and password properly in the preseed
56 """
57 self.logger.info('Rewriting username to ' + config.user)
58 question = preseed['passwd/username']
59 question.value = config.user
60+ question = preseed['passwd/user-password']
61+ question.value = config.password
62+ question = preseed['passwd/user-password-again']
63+ question.value = config.password
64
65 def _preseedcasper(self, tmpdir=None):
66 """
67
68=== modified file 'utah/run.py'
69--- utah/run.py 2012-10-16 10:46:10 +0000
70+++ utah/run.py 2012-10-22 08:38:22 +0000
71@@ -38,7 +38,7 @@
72 machine.uploadfiles([locallist], os.path.normpath('/tmp'))
73
74 options = ' -r /tmp/' + os.path.basename(locallist)
75- utah_command = 'utah' + extraopts + options
76+ utah_command = 'sudo -S utah' + extraopts + options
77 try:
78 _returncode, stdout, _stderr = machine.run(utah_command)
79 # TODO: Decide which returncode means utah client failure

Subscribers

People subscribed via source and target branches